From patchwork Mon Aug 22 23:23:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 599216 Delivered-To: patch@linaro.org Received: by 2002:a05:6918:5e84:b0:d4:ea33:5523 with SMTP id nd4csp2088758ysb; Mon, 22 Aug 2022 16:36:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Gqqyix+ga2wDxoe6yCd5VOTl+6JzNyPk17WV9Q7qBL41sSCFL1d+cnUjFNptMIXQKTTxS X-Received: by 2002:ae9:ed89:0:b0:6bb:9968:de30 with SMTP id c131-20020ae9ed89000000b006bb9968de30mr14164089qkg.774.1661211404738; Mon, 22 Aug 2022 16:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661211404; cv=none; d=google.com; s=arc-20160816; b=O07GrG7D2+6Pn8BN8x2OY4XfR1YM3Z2nY7sEqidFJUENOxR6uhmy0W95kM6hRgyLIf 6qBtVf1TzegZiGlI/j/Hh5L/acS33eMz18hC1RSiGscMfXNxM7cCKMo8KIgycUh1PXiO fC+R1QRuD+yBg4e5LW+GSQ8NY7uyhoEicKX3iCPk8hjKzuwYi3HnQO+3yFno5dpFbA7I 1y8ZbgGDSt+oE20IdT2z9356Mxv15JxU4UiGcyeaz2PebkwOMb6XRUnq+qn3iThTe2f3 RQhwR3LxijO97JrTuHeQjcjpqVFT0oj2ajwPx2kPu2D99OBho+LIpgJLXVCmoulakng6 O+0w== 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=bPLSwnwAm3KKQjuztom5hM3FzbmQvthZN4SqhLXx1Bg=; b=EwVGwYsRWMTB3lmc7bGgpfMk+mHpNpUUtZW5j+xHA2/f8Zl4QAGJkOMCWpAlHpDJmf tGMQskaozN3MpPNV+/wsn1CfV/xCF/nqYKjOXHNeg1bPWvy5k9X498ph6aZM7/lQi11U m1z3MAkZqGbA/Fmdqb9p3cQV+YySoSfIMXze8t30TbUj3hCYGzMMwMtOcTURPBaqSEtG BjERNkz1szb1Cstjb45/RBZsPKG/0JQBGQO9Is//IMYHFi0DE80F+5OHb1xAGi1U59cG EkXYGTlJcsWz/aAerke58Ye2RatXnEGhy9r/rot0Jp0bm4lOZhvNAcQ5gGOJa+v2YaVq O7yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UeNdYtLA; 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 jp15-20020ad45f8f000000b0047374d5a8c1si5416697qvb.576.2022.08.22.16.36.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Aug 2022 16:36:44 -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=UeNdYtLA; 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]:41036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQGyK-00073n-A5 for patch@linaro.org; Mon, 22 Aug 2022 19:36:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQGm0-0005jj-Eg for qemu-devel@nongnu.org; Mon, 22 Aug 2022 19:24:00 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:39788) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQGly-0005fe-JH for qemu-devel@nongnu.org; Mon, 22 Aug 2022 19:24:00 -0400 Received: by mail-pg1-x52d.google.com with SMTP id q9so1705707pgq.6 for ; Mon, 22 Aug 2022 16:23:58 -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=bPLSwnwAm3KKQjuztom5hM3FzbmQvthZN4SqhLXx1Bg=; b=UeNdYtLADZG4eSDIPPAhVi4iVHBkj7Yk9I/guWApjmVI3meS3LoDAp23SpcgKqbece d+/gxLr0Xfn0UvS5MV7YKDX5pzM19o53gf96v3BAxEBQd1RvrB3vnQtJ1ixO1EAShzOp IcuF7eQLmPutmE4UVj5YG1Dl3/NZ7xzrdtfKwsuE3Dd6A6H7IzBollcn2FP1Q4Gx//RP GNqau1xp2bM3YZP5dOC2A2W12Y7arlTK5i2hQfOV1YQFmXcuz+sZAfZkPTedInzGxirr +kTt4SSMbZ9PENtllAAOOh3TZDLSof6hOoT3BpW4nJ/tWZZg+nZutuHp/YZTS4WdJogq g4Qg== 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=bPLSwnwAm3KKQjuztom5hM3FzbmQvthZN4SqhLXx1Bg=; b=yn93mu9jARU1QLSWWaPM8eLjPraLJaqCoqPio0smY4wLQae0NZol2a9I06F3Nywial at4onQcfcywYuCZLhGFb/wwP5dVyNCXl53eLfbb9bn/v+xMBBTD1UT2U7jmAOU+9TXcN iisFVoWHug7cwl1K5zptHGY/ultr4gsCYdoLvCuIkCHQRyN1Zz3QIRUg0B1Jbe9RuxIy 15Vm0Ghh4IFBiY1TTvVfRH86W/D1EkHSAcA6bnalgIK47oSHw0r1IJpMWhMnWTyaOpTA m+MIa2G0BUWfOHdqv4jP+4miLi8C9Doam1B1IFUkyvwdGKuiGHH94xv6G/PyCn9VhFG2 AZtA== X-Gm-Message-State: ACgBeo3fNMcyApMZBPxLmonxiQ9H/CceAnVhE/HwLyQeLneiHLSBdK+b kautqPAMI+d8IA503zvZS74GDIr0Y6+Wag== X-Received: by 2002:a63:ee49:0:b0:428:8e10:200a with SMTP id n9-20020a63ee49000000b004288e10200amr18580455pgk.453.1661210637193; Mon, 22 Aug 2022 16:23:57 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:c3f1:b74f:5edd:63af]) by smtp.gmail.com with ESMTPSA id k17-20020aa79731000000b0052d3899f8c2sm3809112pfg.4.2022.08.22.16.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 16:23:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v3 15/17] target/arm: Introduce gen_pc_plus_diff for aarch64 Date: Mon, 22 Aug 2022 16:23:36 -0700 Message-Id: <20220822232338.1727934-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220822232338.1727934-1-richard.henderson@linaro.org> References: <20220822232338.1727934-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52d; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52d.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=unavailable 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-a64.c | 41 +++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index b777742643..322a09c503 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -148,9 +148,14 @@ static void reset_btype(DisasContext *s) } } +static void gen_pc_plus_diff(DisasContext *s, TCGv_i64 dest, int diff) +{ + tcg_gen_movi_i64(dest, s->pc_curr + diff); +} + void gen_a64_update_pc(DisasContext *s, int diff) { - tcg_gen_movi_i64(cpu_pc, s->pc_curr + diff); + gen_pc_plus_diff(s, cpu_pc, diff); } /* @@ -1368,7 +1373,7 @@ static void disas_uncond_b_imm(DisasContext *s, uint32_t insn) if (insn & (1U << 31)) { /* BL Branch with link */ - tcg_gen_movi_i64(cpu_reg(s, 30), s->base.pc_next); + gen_pc_plus_diff(s, cpu_reg(s, 30), curr_insn_len(s)); } /* B Branch / BL Branch with link */ @@ -2319,11 +2324,17 @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn) default: goto do_unallocated; } - gen_a64_set_pc(s, dst); /* BLR also needs to load return address */ if (opc == 1) { - tcg_gen_movi_i64(cpu_reg(s, 30), s->base.pc_next); + TCGv_i64 lr = cpu_reg(s, 30); + if (dst == lr) { + TCGv_i64 tmp = new_tmp_a64(s); + tcg_gen_mov_i64(tmp, dst); + dst = tmp; + } + gen_pc_plus_diff(s, lr, curr_insn_len(s)); } + gen_a64_set_pc(s, dst); break; case 8: /* BRAA */ @@ -2346,11 +2357,17 @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn) } else { dst = cpu_reg(s, rn); } - gen_a64_set_pc(s, dst); /* BLRAA also needs to load return address */ if (opc == 9) { - tcg_gen_movi_i64(cpu_reg(s, 30), s->base.pc_next); + TCGv_i64 lr = cpu_reg(s, 30); + if (dst == lr) { + TCGv_i64 tmp = new_tmp_a64(s); + tcg_gen_mov_i64(tmp, dst); + dst = tmp; + } + gen_pc_plus_diff(s, lr, curr_insn_len(s)); } + gen_a64_set_pc(s, dst); break; case 4: /* ERET */ @@ -2918,7 +2935,8 @@ static void disas_ld_lit(DisasContext *s, uint32_t insn) tcg_rt = cpu_reg(s, rt); - clean_addr = tcg_constant_i64(s->pc_curr + imm); + clean_addr = new_tmp_a64(s); + gen_pc_plus_diff(s, clean_addr, imm); if (is_vector) { do_fp_ld(s, rt, clean_addr, size); } else { @@ -4262,23 +4280,22 @@ static void disas_ldst(DisasContext *s, uint32_t insn) static void disas_pc_rel_adr(DisasContext *s, uint32_t insn) { unsigned int page, rd; - uint64_t base; - uint64_t offset; + int64_t offset; page = extract32(insn, 31, 1); /* SignExtend(immhi:immlo) -> offset */ offset = sextract64(insn, 5, 19); offset = offset << 2 | extract32(insn, 29, 2); rd = extract32(insn, 0, 5); - base = s->pc_curr; if (page) { /* ADRP (page based) */ - base &= ~0xfff; offset <<= 12; + /* The page offset is ok for TARGET_TB_PCREL. */ + offset -= s->pc_curr & 0xfff; } - tcg_gen_movi_i64(cpu_reg(s, rd), base + offset); + gen_pc_plus_diff(s, cpu_reg(s, rd), offset); } /*