From patchwork Thu Oct 20 03:06:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 616709 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp712212pvb; Wed, 19 Oct 2022 20:20:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7cc7Heqd3YuSzQYG4VpnHA8LNWWtC31vGP6kyWVzlLmPzEyRl0c7Bz66JyJ/nY3QlXYIP4 X-Received: by 2002:a05:620a:4720:b0:6ee:dc2d:4729 with SMTP id bs32-20020a05620a472000b006eedc2d4729mr7746236qkb.36.1666236035390; Wed, 19 Oct 2022 20:20:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666236035; cv=none; d=google.com; s=arc-20160816; b=ChNCpqI8nOKtjOFbNFj4A4/6pMjB/OfhWI0ZR5upPaHDCWNg4Kw68U6XohNjoJzZIj esSX2LYSlje+rqAbe7m7t16jB0vLRukcoNpqkRN2/shXOdE6A6RkGfQcxNDBbv+KX7N2 SSp/TVIDGHIXU9PWNDxhIZg7z5945hoqtvgOgPl1Ilh1PmCrmfmEPOaRu/Q1W5CSBKZq eeEIaXysg3x/Un9hvYGDAfiuMT2iMtHDB/T6ztCGVyhiYCyjhK2/2eMntrirv5rT8SHB fW4sVGJoenNG+ckrKa4XGYLzyknlkKKVt7Lsah3O1/hSGNn/asC0wtEVpyk4CNctibVn Yj2Q== 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=eirybTGa1WIietzoG766hMinqRXYJPoKdxjJFXnDkP8=; b=XSk5fcEok5xEOA31czMmq18gQjQA6Yx2UQKbMelAgNdQnm8bKj/odBf9nKQsfkYE6y QKHxz/VRT8R+x3jwkzAZb+GhSbcHXU7PWBaIrw1E3jcV690HnYR/TmS7xQ/VEP0660f4 1b7ET1DLdiLfADkuScwOlm5D6lze9JmWTCvybGMG41EeUf+drXeqfxLfxBhhI/fMtzdU sifv1KmRyb6oMy4os0cPxQMVvSmtCC2l5giTugHnVgmC5kUE2WmdCJw3yw8bE3kazzLK w+5jzwppJa+b70EAXqoSDFlJkqriwXzOPzIDBdXDxst59QTCnAI+YHEw6+kfR6sObLvX N4Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kz2fCoX9; 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 x6-20020ac84d46000000b0034454d1be39si9389655qtv.419.2022.10.19.20.20.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Oct 2022 20:20:35 -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=kz2fCoX9; 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]:58410 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olM6k-000739-Nn for patch@linaro.org; Wed, 19 Oct 2022 23:20:34 -0400 Received: from [::1] (port=52804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olLy4-0003Vj-Tc for patch@linaro.org; Wed, 19 Oct 2022 23:11:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olLuI-0003S2-Eb for qemu-devel@nongnu.org; Wed, 19 Oct 2022 23:07:44 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:38540) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1olLuE-0001qy-Cv for qemu-devel@nongnu.org; Wed, 19 Oct 2022 23:07:41 -0400 Received: by mail-pg1-x529.google.com with SMTP id 20so917488pgc.5 for ; Wed, 19 Oct 2022 20:07:37 -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:subject:date :message-id:reply-to; bh=eirybTGa1WIietzoG766hMinqRXYJPoKdxjJFXnDkP8=; b=kz2fCoX9WreEHne84egX3WeZ2wc/0mO0RQCL1fRjOn0Lmfk33vK2uF6zD+YHbj8/pg jRBhwHN79Q5j/tsQt3VBoSIGgKIXU0464YfV0XAcG04XVGiE9F0kc/MeAnNmzJHzQa9v KYQ2tDn/04XiBQFGd4bTB49RiWa3xKw0ttNpbKoMXFZqgofxdwROvpszX+tN/W4TQeyF VcwhpFACOOqaldtPHxD2aO/gfqu2GUa5TjQBxOS+dsyQt2FVDDve9kUJqHphZKWLf8MZ fQBGY7rvfQs/wkgoxHUOvj/W3LJ3gB8N+Pk1GV7djbHSjJeVPPtI//tC5NRQjZ6Mu06t 1sfw== 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 :subject:date:message-id:reply-to; bh=eirybTGa1WIietzoG766hMinqRXYJPoKdxjJFXnDkP8=; b=m0oiCWT7Sc6VokOXBgxCvbmwBPULEALKd6hsWshFFmmSUtSjTo75xbhZdf74gzn11s Q7sgfRSRo4QwsjcSvLQyz9pxADcdLmvgOB55UF6BGkN3cHnjJo7kQNLCOS9ulqd1A128 JmvA8EoxiXJ7K7wj1Bw7lGyDyeRThvhLPG1KfUYJv1jAg+RRaoJ+YZiHeu9lB/IENa/8 nFIO/NL5VNSJdnYkia32RekJhpvi8izGm1k+st6/xLl9ncIYwvT1hnhdw95WrekpUYFd 8tHRAMnbaarRRXO61P25NQ53KrAo2yNev8ssqFE21xab/O1nygc51rAK2SGSg/B8LJEh H2gg== X-Gm-Message-State: ACrzQf3mc/mfWIu9X3FtlXPd+Kzug0M5xr/QZQUxf+dnb8xvPJzIk1Ql DWshsCgzDQq1RXaQCMEJke85adBe+CKX8jZy X-Received: by 2002:a63:4f4f:0:b0:434:b9db:b9f with SMTP id p15-20020a634f4f000000b00434b9db0b9fmr10183785pgl.438.1666235256357; Wed, 19 Oct 2022 20:07:36 -0700 (PDT) Received: from localhost.localdomain ([149.135.10.35]) by smtp.gmail.com with ESMTPSA id m9-20020a63ed49000000b0043c7996f7f0sm10657647pgk.58.2022.10.19.20.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 20:07:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v8 8/9] target/arm: Introduce gen_pc_plus_diff for aarch32 Date: Thu, 20 Oct 2022 13:06:40 +1000 Message-Id: <20221020030641.2066807-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221020030641.2066807-1-richard.henderson@linaro.org> References: <20221020030641.2066807-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x529.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 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. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/arm/translate.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/target/arm/translate.c b/target/arm/translate.c index ca128edab7..5f6bd9b5b7 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -260,23 +260,22 @@ static inline int get_a32_user_mem_index(DisasContext *s) } } -/* The architectural value of PC. */ -static uint32_t read_pc(DisasContext *s) -{ - return s->pc_curr + (s->thumb ? 4 : 8); -} - /* The pc_curr difference for an architectural jump. */ static target_long jmp_diff(DisasContext *s, target_long diff) { return diff + (s->thumb ? 4 : 8); } +static void gen_pc_plus_diff(DisasContext *s, TCGv_i32 var, target_long 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]); } @@ -292,7 +291,11 @@ 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 address is computed from an aligned PC: + * subtract off the low bits. + */ + gen_pc_plus_diff(s, tmp, jmp_diff(s, ofs - (s->pc_curr & 3))); } else { tcg_gen_addi_i32(tmp, cpu_R[reg], ofs); } @@ -1155,7 +1158,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; } @@ -6479,7 +6482,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; } @@ -8347,7 +8350,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; } @@ -8366,7 +8369,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 jump is computed from an aligned PC: subtract off the low bits. */ gen_jmp(s, jmp_diff(s, a->imm - (s->pc_curr & 3))); @@ -8376,7 +8379,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; } @@ -8386,7 +8389,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; } @@ -8402,7 +8405,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; } @@ -8725,10 +8728,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; }