From patchwork Mon Sep 2 17:54:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 272056 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 02F2C2C0084 for ; Tue, 3 Sep 2013 05:10:26 +1000 (EST) Received: from localhost ([::1]:41472 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGYXs-0004va-Mo for incoming@patchwork.ozlabs.org; Mon, 02 Sep 2013 14:08:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGYLt-00065e-8f for qemu-devel@nongnu.org; Mon, 02 Sep 2013 13:55:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VGYLn-0001CT-0I for qemu-devel@nongnu.org; Mon, 02 Sep 2013 13:55:49 -0400 Received: from mail-pb0-x22c.google.com ([2607:f8b0:400e:c01::22c]:63217) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VGYLm-0001CA-Eh for qemu-devel@nongnu.org; Mon, 02 Sep 2013 13:55:42 -0400 Received: by mail-pb0-f44.google.com with SMTP id xa7so4989503pbc.3 for ; Mon, 02 Sep 2013 10:55:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=CuBVIaQ0DLTZFdeYNI8JJupPvq9mUTigwWZRJrWJOjM=; b=pdbGQKLM3mTdLwRqKnnIxLp0kEgQptZsNjuyS7yrGGuqnJKVHcRRMKp3qEROOf/+XY zI/uPb3h4HjsTKR7GXX4Bmu9bMiWidvhc7uKYr0uG3Y3nXDzp6i6iLmKz14aCG5LgFZw pyZURLXgV/f/F9EBRL2WrRaQ0gPw5+gV6eeNyQaYelNCw0i72KIkB/NIpn995iYHRQyU NpKDjrFuSkY/aFUR3aL1Y0sVfXNf+mJQPjXwVwm4kiUMJKlYhbeQXKpsUcbaXGj+tz4y jam1MkVXkfJ2u59K6zBJkiyfb3PA5Jw0GfIk17b6cvUcuh7srMiJud14lnmYnpd4s62F x7CA== X-Received: by 10.66.192.8 with SMTP id hc8mr27325178pac.66.1378144541512; Mon, 02 Sep 2013 10:55:41 -0700 (PDT) Received: from pebble.twiddle.net (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPSA id tr10sm17218114pbc.22.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 02 Sep 2013 10:55:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 2 Sep 2013 10:54:54 -0700 Message-Id: <1378144503-15808-21-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1378144503-15808-1-git-send-email-rth@twiddle.net> References: <1378144503-15808-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c01::22c Cc: claudio.fontana@huawei.com, Richard Henderson Subject: [Qemu-devel] [PATCH v3 20/29] tcg-aarch64: Improve tcg_out_movi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Handle small positive and negative numbers early. Check for logical immediates. Check if using MOVN for the first set helps. Signed-off-by: Richard Henderson --- tcg/aarch64/tcg-target.c | 61 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/tcg/aarch64/tcg-target.c b/tcg/aarch64/tcg-target.c index 59e5026..54f5ce8 100644 --- a/tcg/aarch64/tcg-target.c +++ b/tcg/aarch64/tcg-target.c @@ -534,20 +534,65 @@ static inline void tcg_out_movr_sp(TCGContext *s, bool ext, } static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd, - tcg_target_long value) + tcg_target_long svalue) { - AArch64Insn insn = INSN_MOVZ; + tcg_target_ulong value = svalue; + AArch64Insn insn; + bool ext = true; + int wantinv, shift; if (type == TCG_TYPE_I32) { - value = (uint32_t)value; + value = (uint32_t)svalue; + svalue = (int32_t)svalue; + ext = false; + } else if ((value & ~0xffffffffull) == 0) { + svalue = (int32_t)svalue; + ext = false; + } + + /* Check small positive values. */ + if ((value & ~0xffffull) == 0) { + tcg_fmt_Rd_uimm_s(s, INSN_MOVZ, 0, rd, value, 0); + return; + } + /* Check small negative values. */ + if ((~svalue & 0xffffull) == 0) { + tcg_fmt_Rd_uimm_s(s, INSN_MOVN, ext, rd, ~svalue, 0); + return; } + /* Check for bitfield immediates. */ + if (is_limm(svalue)) { + tcg_fmt_Rdn_limm(s, INSN_ORRI, ext, rd, TCG_REG_XZR, svalue); + return; + } + + /* Would it take fewer insns to begin with MOVN? */ + insn = INSN_MOVZ; + wantinv = 0; + wantinv += (value & 0x000000000000ffffull) == 0; + wantinv += (value & 0x00000000ffff0000ull) == 0; + wantinv += (value & 0x0000ffff00000000ull) == 0; + wantinv += (value & 0xffff000000000000ull) == 0; + wantinv = -wantinv; + wantinv += (~value & 0x000000000000ffffull) == 0; + wantinv += (~value & 0x00000000ffff0000ull) == 0; + wantinv += (~value & 0x0000ffff00000000ull) == 0; + wantinv += (~value & 0xffff000000000000ull) == 0; + if (wantinv > 0) { + insn = INSN_MOVN; + value = ~value; + } + + shift = ctz64(value) & (63 & -16); + tcg_fmt_Rd_uimm_s(s, insn, ext, rd, value >> shift, shift); + value &= ~(0xffffUL << shift); - do { - unsigned shift = ctz64(value) & (63 & -16); - tcg_fmt_Rd_uimm_s(s, insn, shift >= 32, rd, value >> shift, shift); + while (value) { + shift = ctz64(value) & (63 & -16); + tcg_fmt_Rd_uimm_s(s, INSN_MOVK, ext, rd, + (value ^ -(wantinv > 0)) >> shift, shift); value &= ~(0xffffUL << shift); - insn = INSN_MOVK; - } while (value); + } } static inline void tcg_out_ldst_r(TCGContext *s,