From patchwork Sat Sep 14 21:54:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 274972 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 D6A2B2C014B for ; Sun, 15 Sep 2013 08:08:22 +1000 (EST) Received: from localhost ([::1]:54766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKy0q-0003HS-SB for incoming@patchwork.ozlabs.org; Sat, 14 Sep 2013 18:08:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKxoZ-0001qh-Sj for qemu-devel@nongnu.org; Sat, 14 Sep 2013 17:55:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VKxoS-0004A0-S2 for qemu-devel@nongnu.org; Sat, 14 Sep 2013 17:55:39 -0400 Received: from mail-pa0-x22f.google.com ([2607:f8b0:400e:c03::22f]:37300) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKxoS-00049p-LI for qemu-devel@nongnu.org; Sat, 14 Sep 2013 17:55:32 -0400 Received: by mail-pa0-f47.google.com with SMTP id kl13so3873662pab.20 for ; Sat, 14 Sep 2013 14:55:31 -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=Oo46wPDDOXzYhSUS1E4v5BKBYTAmpM9E4f+WyFBOysQ=; b=k6dIWNcKsYGu/LabaPDRmAC8zIkDlH1PTYFuuwcZGuOIC8KeH1fC5Pu6oL8qK+NxLu VL+5HzJ/oQIMgzFm6lpXpKcWJkehRB8Avy+z0TosGSmapOuCNEKzJePCArQsrzCs5rbZ 7vX+Svhfu1RbFLNwBVRZM2ONXh6Dp16B0pF3Ko2DxHpmjASHjby8YO4/9RUY/2uLq8vv WAdZuL7On5clJsBXoSog1JOfQj2ipJSJteQikGtQ+/v4QVN8+2jl7vky0X+fU3A5TivW 7dST10muB2oQhJssJh/gXIzCbij0DRUaUKfLaEQjXmaQyX5n+BlEHJK0FCFKgzHnXAAp 0+Pg== X-Received: by 10.66.152.102 with SMTP id ux6mr22181347pab.79.1379195731680; Sat, 14 Sep 2013 14:55:31 -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 gg10sm20458962pbc.46.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 14 Sep 2013 14:55:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 14 Sep 2013 14:54:42 -0700 Message-Id: <1379195690-6509-26-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1379195690-6509-1-git-send-email-rth@twiddle.net> References: <1379195690-6509-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:c03::22f Cc: peter.maydell@linaro.org, claudio.fontana@gmail.com Subject: [Qemu-devel] [PATCH v4 25/33] tcg-aarch64: Use adrp in 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 Loading an qemu pointer as an immediate happens often. E.g. - exit_tb $0x7fa8140013 + exit_tb $0x7f81ee0013 ... - : d2800260 mov x0, #0x13 - : f2b50280 movk x0, #0xa814, lsl #16 - : f2c00fe0 movk x0, #0x7f, lsl #32 + : 90ff1000 adrp x0, 0x7f81ee0000 + : 91004c00 add x0, x0, #0x13 Signed-off-by: Richard Henderson --- tcg/aarch64/tcg-target.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tcg/aarch64/tcg-target.c b/tcg/aarch64/tcg-target.c index e50abcb..5691cc3 100644 --- a/tcg/aarch64/tcg-target.c +++ b/tcg/aarch64/tcg-target.c @@ -323,6 +323,10 @@ typedef enum { /* Conditional select instructions */ INSN_CSEL = 0x1a800000, INSN_CSINC = 0x1a800400, + + /* PC relative addressing instructions */ + INSN_ADR = 0x10000000, + INSN_ADRP = 0x90000000, } AArch64Insn; static inline enum aarch64_ldst_op_data @@ -510,6 +514,12 @@ static inline void tcg_fmt_Rd_uimm(TCGContext *s, AArch64Insn insn, tcg_out32(s, insn | sf << 31 | shift << (21 - 4) | half << 5 | rd); } +static inline void tcg_fmt_Rd_disp21(TCGContext *s, AArch64Insn insn, + TCGReg rd, tcg_target_long disp) +{ + tcg_out32(s, insn | (disp & 3) << 29 | (disp & 0x1ffffc) << (5 - 2) | rd); +} + static inline void tcg_out_ldst_9(TCGContext *s, enum aarch64_ldst_op_data op_data, enum aarch64_ldst_op_type op_type, @@ -561,7 +571,7 @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd, AArch64Insn insn; int i, wantinv, shift; tcg_target_long svalue = value; - tcg_target_long ivalue, imask; + tcg_target_long ivalue, imask, disp; /* For 32-bit values, discard potential garbage in value. For 64-bit values within [2**31, 2**32-1], we can create smaller sequences by @@ -593,6 +603,17 @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd, return; } + /* Look for host pointer values within 4G of the PC. This happens + often when loading pointers to QEMU's own data structures. */ + disp = (value >> 12) - ((intptr_t)s->code_ptr >> 12); + if (disp == sextract64(disp, 0, 21)) { + tcg_fmt_Rd_disp21(s, INSN_ADRP, rd, disp); + if (value & 0xfff) { + tcg_fmt_Rdn_aimm(s, INSN_ADDI, type, rd, rd, value & 0xfff); + } + return; + } + /* Would it take fewer insns to begin with MOVN? For the value and its inverse, count the number of 16-bit lanes that are 0. For the benefit of 32-bit quantities, compare the zero-extended normal value vs the