From patchwork Tue Aug 16 20:33:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 597532 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp2716735maz; Tue, 16 Aug 2022 14:15:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR7uBh7C3thaLvkyXBQllRNQwTMwDl5GqcgAuekuh1UfehehVMyBJI4UNzKYNM88zT3pMO+Q X-Received: by 2002:a05:622a:209:b0:343:7345:36f7 with SMTP id b9-20020a05622a020900b00343734536f7mr18126342qtx.121.1660684548082; Tue, 16 Aug 2022 14:15:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660684548; cv=none; d=google.com; s=arc-20160816; b=EhfkyBmFMlzDtaG506YBZFxZuwf5VqH0Y9b2D9RklwW0T9K2qt6HGtj9G4wuS7Lz0P pd3E5PcPCGnwcHK9/m9FBK8HkU1GRkKUctcBSAW2jWB88wVWycyIY+LXPcfOwjQ2NueT +g3DXah3/FmX2J207eNoX9RrfrOeCpEsgYoRq5xHXqM/gUxxLp9XiDGPv7Q/nOGEvhLL KTstXq6dhGg4jk9JQbbBh18gw1wvBR1+3tw8ZB2fuqKLqWJa3OzfAEYVublduUifgJu4 XSweSZKzCLAVqwk5ePp+DvPZ/3DnD/o6Zl1QNyqaduB7vpgoWb4aH6HRIXnACFNvt5uu PmuA== 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=RKoJ35vLYvCsMuP+JFswrPYXmhyjLc71nVTkFzG8E7k=; b=FRm3YiAOVG7SWyDT3eV+nQfqNGWKxeM3df6rkQisT1daAerU/pE+JV9SfKe/2gvMSC C+VCrcbO904LJkJlCVIB/w3bExcbNEPpC3hVNPZupBEuMyYol5xeHTobXE+CKLfwdjqS h0ASyOec2lU6s8hNdC+nkPkcC1ouqhtFBlrja/tkp6vD1dUbXehQpwwoWhy9NE7J0heR wmdyOvu/lk59cpPHykxWZRoZhGajHkY8Rg0LCevEBQVZnfkLfJGBmlrnKb2HF2QtDB8i m1kLZcqay00mi8yZ0NsyuZ7vOkxgaQ0IBdnkO0BCzBH4Qvwyh5eGDcEMPNzUkeqJdJj6 CPVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AsluQiSt; 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 m20-20020a05620a291400b006b5fabb4c7esi8052251qkp.537.2022.08.16.14.15.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Aug 2022 14:15:48 -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=AsluQiSt; 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]:50164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oO3ud-0001eH-He for patch@linaro.org; Tue, 16 Aug 2022 17:15:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oO3HL-0005NP-Ry for qemu-devel@nongnu.org; Tue, 16 Aug 2022 16:35:13 -0400 Received: from mail-oa1-x35.google.com ([2001:4860:4864:20::35]:38603) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oO3HG-0004UZ-Kd for qemu-devel@nongnu.org; Tue, 16 Aug 2022 16:35:11 -0400 Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-10ee900cce0so12956695fac.5 for ; Tue, 16 Aug 2022 13:35:06 -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=RKoJ35vLYvCsMuP+JFswrPYXmhyjLc71nVTkFzG8E7k=; b=AsluQiStnRkJ9ZaIy06VakISyMKR5BOUXAO5Xqc8K9AksyMOFQGZgBWvu4nLZD0JV1 8U7v+uW9Nyc5aq9BsgB5dVMw5VG0HJ9SCHo5A6INEaZ7r4XTNE/MLX+aTzdlSFYtydMj M2VqrfWS8cilzwtl0lugDXQWxazN0woSIaoZsNvLvOIQSEpKxhpa+VYr9JVU7QydtlIb 7XTbbNOeBIT5ryaf4Yvj2jAQf32Y5b20GcYsEi000dqZuFNBmrIFn3JFxl0lsX9f3T3z oewh4/1aid3AEt+3DajeAoRROSt/hXcqL+22ddp1iEHClzkifu17RhcLdfDr9ROnVt1p yRUQ== 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=RKoJ35vLYvCsMuP+JFswrPYXmhyjLc71nVTkFzG8E7k=; b=itINSe/aJFHP5eL5iv8q3BC68Q/fWnRrHlhNvV6v4ddU7ImAwtyz0zWMO7p252FJTh E3rzS3LYsZlz85nuswWtm1KfInnwtCrTt3/RiiHyCq1hbg8KAgpT3rnEPokxKf2n9ZZQ tbZBVkN+DNNk4rdq21w1aGigUr+GjNkUxI6fS7hFlSK1TZmtYi2PZt7a/AO1MXYVXF4R uzLuMes2V+MYkgnBrvpShTJRvIeeqwppR7ycsJGT3z+O7R3wYjOJ7RbE5tz5c3sTnoZj c7Tv/sKDv551m5nGBMGb+mKre4ESVBtXWmbmuNCluW20nqS1VMQrYZI0/tYSHYtYb9pP qx/Q== X-Gm-Message-State: ACgBeo3vlpPhZJeNRUJr//MsYWG4+YkTqfFTZFSOMaMh1hKuABGQVyAI VzDo1mQTWo9D+WgZxVvvaxVrfwgYIQueOA== X-Received: by 2002:a05:6870:b52c:b0:10e:e9e2:81b2 with SMTP id v44-20020a056870b52c00b0010ee9e281b2mr143761oap.75.1660682105910; Tue, 16 Aug 2022 13:35:05 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 13:35:05 -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 30/33] target/arm: Change gen_jmp* to work on displacements Date: Tue, 16 Aug 2022 15:33:57 -0500 Message-Id: <20220816203400.161187-31-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=2001:4860:4864:20::35; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x35.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 | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/target/arm/translate.c b/target/arm/translate.c index 63a41ed438..4d13e365e2 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -270,6 +270,12 @@ static uint32_t read_pc(DisasContext *s) return s->pc_curr + (s->thumb ? 4 : 8); } +/* The pc_curr difference for an architectural jump. */ +static int jmp_diff(DisasContext *s, int diff) +{ + return diff + (s->thumb ? 4 : 8); +} + /* Set a variable to the value of a CPU register. */ void load_reg_var(DisasContext *s, TCGv_i32 var, int reg) { @@ -2614,10 +2620,8 @@ static void gen_goto_tb(DisasContext *s, int n, int diff) } /* Jump, specifying which TB number to use if we gen_goto_tb() */ -static inline void gen_jmp_tb(DisasContext *s, uint32_t dest, int tbno) +static void gen_jmp_tb(DisasContext *s, int diff, int tbno) { - int diff = dest - s->pc_curr; - if (unlikely(s->ss_active)) { /* An indirect jump so that we still trigger the debug exception. */ gen_update_pc(s, diff); @@ -2659,9 +2663,9 @@ static inline void gen_jmp_tb(DisasContext *s, uint32_t dest, int tbno) } } -static inline void gen_jmp(DisasContext *s, uint32_t dest) +static inline void gen_jmp(DisasContext *s, int diff) { - gen_jmp_tb(s, dest, 0); + gen_jmp_tb(s, diff, 0); } static inline void gen_mulxy(TCGv_i32 t0, TCGv_i32 t1, int x, int y) @@ -8331,7 +8335,7 @@ static bool trans_CLRM(DisasContext *s, arg_CLRM *a) static bool trans_B(DisasContext *s, arg_i *a) { - gen_jmp(s, read_pc(s) + a->imm); + gen_jmp(s, jmp_diff(s, a->imm)); return true; } @@ -8346,14 +8350,14 @@ static bool trans_B_cond_thumb(DisasContext *s, arg_ci *a) return true; } arm_skip_unless(s, a->cond); - gen_jmp(s, read_pc(s) + a->imm); + gen_jmp(s, jmp_diff(s, a->imm)); return true; } static bool trans_BL(DisasContext *s, arg_i *a) { tcg_gen_movi_i32(cpu_R[14], s->base.pc_next | s->thumb); - gen_jmp(s, read_pc(s) + a->imm); + gen_jmp(s, jmp_diff(s, a->imm)); return true; } @@ -8373,7 +8377,8 @@ static bool trans_BLX_i(DisasContext *s, arg_BLX_i *a) } tcg_gen_movi_i32(cpu_R[14], s->base.pc_next | s->thumb); store_cpu_field_constant(!s->thumb, thumb); - gen_jmp(s, (read_pc(s) & ~3) + a->imm); + /* This difference computes a page offset so ok for TARGET_TB_PCREL. */ + gen_jmp(s, (read_pc(s) & ~3) - s->pc_curr + a->imm); return true; } @@ -8534,10 +8539,10 @@ static bool trans_WLS(DisasContext *s, arg_WLS *a) * when we take this upcoming exit from this TB, so gen_jmp_tb() is OK. */ } - gen_jmp_tb(s, s->base.pc_next, 1); + gen_jmp_tb(s, curr_insn_len(s), 1); gen_set_label(nextlabel); - gen_jmp(s, read_pc(s) + a->imm); + gen_jmp(s, jmp_diff(s, a->imm)); return true; } @@ -8617,7 +8622,7 @@ static bool trans_LE(DisasContext *s, arg_LE *a) if (a->f) { /* Loop-forever: just jump back to the loop start */ - gen_jmp(s, read_pc(s) - a->imm); + gen_jmp(s, jmp_diff(s, -a->imm)); return true; } @@ -8648,7 +8653,7 @@ static bool trans_LE(DisasContext *s, arg_LE *a) tcg_temp_free_i32(decr); } /* Jump back to the loop start */ - gen_jmp(s, read_pc(s) - a->imm); + gen_jmp(s, jmp_diff(s, -a->imm)); gen_set_label(loopend); if (a->tp) { @@ -8656,7 +8661,7 @@ static bool trans_LE(DisasContext *s, arg_LE *a) store_cpu_field(tcg_constant_i32(4), v7m.ltpsize); } /* End TB, continuing to following insn */ - gen_jmp_tb(s, s->base.pc_next, 1); + gen_jmp_tb(s, curr_insn_len(s), 1); return true; } @@ -8755,7 +8760,7 @@ static bool trans_CBZ(DisasContext *s, arg_CBZ *a) tcg_gen_brcondi_i32(a->nz ? TCG_COND_EQ : TCG_COND_NE, tmp, 0, s->condlabel); tcg_temp_free_i32(tmp); - gen_jmp(s, read_pc(s) + a->imm); + gen_jmp(s, jmp_diff(s, a->imm)); return true; }