From patchwork Tue Aug 16 20:33:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 597534 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp2719241maz; Tue, 16 Aug 2022 14:20:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR72buODNnNYO8ftczdeYrvcMDKxUuMcFEwJVf0QjN3AWoc2+u5HpY7ESM1HYhrfjTefOc+C X-Received: by 2002:a05:620a:2844:b0:6b8:8cc3:9387 with SMTP id h4-20020a05620a284400b006b88cc39387mr16272400qkp.615.1660684856826; Tue, 16 Aug 2022 14:20:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660684856; cv=none; d=google.com; s=arc-20160816; b=T+cP97u49kDSYjj/2HoG4Qg2+zjJ2wEq87IGnfkoSxpPO7VstjXglNqvKICgsON2RW kKr6J6qjtGijTbst9MhpSbUXRgaKePS8YS08rzhwI9mSAerWhhj3gBvUy43EZckpvfI/ Z2nGpSDe0FquJ/i1rMkfBUhYNPywMPaq6fGvt1AgvCb4q5s1njH9hmMCvJhsixPHRFGg xuzcuErU8Ch0rR1h+UwqBWbeChKjp6dE/+eo/tXSbSarzKphlfO4tIqmod8/GsgTBLzi dfQRVGu7LoFeSF55SDlWe8YNXQgKpICNjud/m4whDAb6ylb6PzQ/HU8MRwNbR9/zEh6t frLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cxOV+kgTy/28wcHyCPRFLTS2yytwO8pyxXme1WE5d5k=; b=X4N5dzz+1EjgNBee0AD0zS1KoTvRQeYz/8GVSc5Fir+flkIH84A9PY3jJb5d7LTIFb B2KUeD+qzx9nW9ULivcNEYKRa9Cxx0U3JqCIBn+goqmPa2rCz13+NH6mORemdCA0HXdc +SAQWaEjN8B6xRrjJH+ela3qWECY8WQtnMjiFmTZrHH1vyMvAk1DuSeufSUqemCEMsG8 bLykUDZNXgDhwks6jK0kTWmFZm1Nc+3Y9oI/BTqznrYbipfAI308kG4sVys9CCKYShoC HeXU1YDSet4PSaO9w1+AB1K2b8PD6T6VFRzalW7ZX8NCj60JDyJZ7XWIP3s0VU4MFODl uuVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="JwuVNg/R"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 5-20020a0562140d6500b00476a01a28a5si6300181qvs.135.2022.08.16.14.20.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Aug 2022 14:20:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="JwuVNg/R"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oO3zc-000852-DO for patch@linaro.org; Tue, 16 Aug 2022 17:20:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oO3HO-0005Nz-Ur for qemu-devel@nongnu.org; Tue, 16 Aug 2022 16:35:16 -0400 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]:40585) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oO3HJ-0004d2-NK for qemu-devel@nongnu.org; Tue, 16 Aug 2022 16:35:14 -0400 Received: by mail-ot1-x32b.google.com with SMTP id z22-20020a056830129600b0063711f456ceso8177928otp.7 for ; Tue, 16 Aug 2022 13:35:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=cxOV+kgTy/28wcHyCPRFLTS2yytwO8pyxXme1WE5d5k=; b=JwuVNg/RJE+pSlfrNHRTjFpEwbACpsYfduMHVnoUdZKxBMBwHvyo0MP28gK34n6uYD tjdcfQEz15T0yc4s4cMBfytj/46eSRVOK40ANHelH0z/hblLi+kVSS34jaPTxUAMDI1G EEo7MZ9y8ZFq1UX26FEfAbARYWVGA/Xa/o6Ci+HHS1qZEzJAo34K2opARzFfN5XpyPVT 2rTMLeaXi1QlUK/F4SWDpm9AqjUMBXKYV6Z4rlQ5lNtGUJjnQD7rzocZiderH2PV42r4 +ZOXyZuhyL1hOvCucrM+4TiXAJAJqbvkvmkJbg2OOYCazFWvrXgU/0yqVZRzfe5hvkH4 iJLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=cxOV+kgTy/28wcHyCPRFLTS2yytwO8pyxXme1WE5d5k=; b=aUdA96dk+E4p6CxqgfFMHeF165HVjr95UgpZyhQr2YEpebCQmQgoh7HANjfKKPKIa0 yXTey8Hkr9SSVd2uQoUceiS31BqD1wlq+V0L+HWTBUDC6kXSIJ2Eo9W6xOEU8bisRhIT rFAjGLmDJXH6WA2HeFntPkw4d72KPhUqSTCJDGW51ylHIhT9lMLvYdUgYuOxdYUUZ/UI XWTtLNcAXTZ//OezRKAaNFJuZrOqpoQBrOVBmUY6PB6wWVplumsUyTxlniakOYFGQLJa hAOiddbFYOKEgiPHn0Zx3+B5bV8FVVQcfDoYGlFW1aLkjcGX8AgrvyigwkK5NDR1tWXV jA+Q== X-Gm-Message-State: ACgBeo1Izq8hzB07+hLzQt3hItculELoO5ZRbQDlpcSuWIOqw2DtcWbK mCxRsR/IR0FchqH8XVJ5cO/YrMWOYE9UoA== X-Received: by 2002:a05:6830:3194:b0:636:e7ef:aa1b with SMTP id p20-20020a056830319400b00636e7efaa1bmr8541227ots.24.1660682109036; Tue, 16 Aug 2022 13:35:09 -0700 (PDT) Received: from stoup.. ([2605:ef80:80f6:61fa:9bc2:5095:d612:5e22]) by smtp.gmail.com with ESMTPSA id y23-20020a056870b01700b0010ef8ccde67sm2285220oae.13.2022.08.16.13.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 13:35:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, alex.bennee@linaro.org, iii@linux.ibm.com Subject: [PATCH v2 32/33] target/arm: Introduce gen_pc_plus_diff for aarch32 Date: Tue, 16 Aug 2022 15:33:59 -0500 Message-Id: <20220816203400.161187-33-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220816203400.161187-1-richard.henderson@linaro.org> References: <20220816203400.161187-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::32b; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x32b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" In preparation for TARGET_TB_PCREL, reduce reliance on absolute values. Signed-off-by: Richard Henderson --- target/arm/translate.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/target/arm/translate.c b/target/arm/translate.c index 4d13e365e2..f01c8df60a 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -276,11 +276,16 @@ static int jmp_diff(DisasContext *s, int diff) return diff + (s->thumb ? 4 : 8); } +static void gen_pc_plus_diff(DisasContext *s, TCGv_i32 var, int diff) +{ + tcg_gen_movi_i32(var, s->pc_curr + diff); +} + /* Set a variable to the value of a CPU register. */ void load_reg_var(DisasContext *s, TCGv_i32 var, int reg) { if (reg == 15) { - tcg_gen_movi_i32(var, read_pc(s)); + gen_pc_plus_diff(s, var, jmp_diff(s, 0)); } else { tcg_gen_mov_i32(var, cpu_R[reg]); } @@ -296,7 +301,8 @@ TCGv_i32 add_reg_for_lit(DisasContext *s, int reg, int ofs) TCGv_i32 tmp = tcg_temp_new_i32(); if (reg == 15) { - tcg_gen_movi_i32(tmp, (read_pc(s) & ~3) + ofs); + /* This difference computes a page offset so ok for TARGET_TB_PCREL. */ + gen_pc_plus_diff(s, tmp, (read_pc(s) & ~3) - s->pc_curr + ofs); } else { tcg_gen_addi_i32(tmp, cpu_R[reg], ofs); } @@ -1158,7 +1164,7 @@ void unallocated_encoding(DisasContext *s) /* Force a TB lookup after an instruction that changes the CPU state. */ void gen_lookup_tb(DisasContext *s) { - tcg_gen_movi_i32(cpu_R[15], s->base.pc_next); + gen_pc_plus_diff(s, cpu_R[15], curr_insn_len(s)); s->base.is_jmp = DISAS_EXIT; } @@ -6485,7 +6491,7 @@ static bool trans_BLX_r(DisasContext *s, arg_BLX_r *a) return false; } tmp = load_reg(s, a->rm); - tcg_gen_movi_i32(cpu_R[14], s->base.pc_next | s->thumb); + gen_pc_plus_diff(s, cpu_R[14], curr_insn_len(s) | s->thumb); gen_bx(s, tmp); return true; } @@ -8356,7 +8362,7 @@ static bool trans_B_cond_thumb(DisasContext *s, arg_ci *a) static bool trans_BL(DisasContext *s, arg_i *a) { - tcg_gen_movi_i32(cpu_R[14], s->base.pc_next | s->thumb); + gen_pc_plus_diff(s, cpu_R[14], curr_insn_len(s) | s->thumb); gen_jmp(s, jmp_diff(s, a->imm)); return true; } @@ -8375,7 +8381,7 @@ static bool trans_BLX_i(DisasContext *s, arg_BLX_i *a) if (s->thumb && (a->imm & 2)) { return false; } - tcg_gen_movi_i32(cpu_R[14], s->base.pc_next | s->thumb); + gen_pc_plus_diff(s, cpu_R[14], curr_insn_len(s) | s->thumb); store_cpu_field_constant(!s->thumb, thumb); /* This difference computes a page offset so ok for TARGET_TB_PCREL. */ gen_jmp(s, (read_pc(s) & ~3) - s->pc_curr + a->imm); @@ -8385,7 +8391,7 @@ static bool trans_BLX_i(DisasContext *s, arg_BLX_i *a) static bool trans_BL_BLX_prefix(DisasContext *s, arg_BL_BLX_prefix *a) { assert(!arm_dc_feature(s, ARM_FEATURE_THUMB2)); - tcg_gen_movi_i32(cpu_R[14], read_pc(s) + (a->imm << 12)); + gen_pc_plus_diff(s, cpu_R[14], jmp_diff(s, a->imm << 12)); return true; } @@ -8395,7 +8401,7 @@ static bool trans_BL_suffix(DisasContext *s, arg_BL_suffix *a) assert(!arm_dc_feature(s, ARM_FEATURE_THUMB2)); tcg_gen_addi_i32(tmp, cpu_R[14], (a->imm << 1) | 1); - tcg_gen_movi_i32(cpu_R[14], s->base.pc_next | 1); + gen_pc_plus_diff(s, cpu_R[14], curr_insn_len(s) | 1); gen_bx(s, tmp); return true; } @@ -8411,7 +8417,7 @@ static bool trans_BLX_suffix(DisasContext *s, arg_BLX_suffix *a) tmp = tcg_temp_new_i32(); tcg_gen_addi_i32(tmp, cpu_R[14], a->imm << 1); tcg_gen_andi_i32(tmp, tmp, 0xfffffffc); - tcg_gen_movi_i32(cpu_R[14], s->base.pc_next | 1); + gen_pc_plus_diff(s, cpu_R[14], curr_insn_len(s) | 1); gen_bx(s, tmp); return true; } @@ -8734,10 +8740,11 @@ static bool op_tbranch(DisasContext *s, arg_tbranch *a, bool half) tcg_gen_add_i32(addr, addr, tmp); gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), half ? MO_UW : MO_UB); - tcg_temp_free_i32(addr); tcg_gen_add_i32(tmp, tmp, tmp); - tcg_gen_addi_i32(tmp, tmp, read_pc(s)); + gen_pc_plus_diff(s, addr, jmp_diff(s, 0)); + tcg_gen_add_i32(tmp, tmp, addr); + tcg_temp_free_i32(addr); store_reg(s, 15, tmp); return true; }