From nobody Fri Nov 7 02:11:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544766641368814.3773120311405; Thu, 13 Dec 2018 21:50:41 -0800 (PST) Received: from localhost ([::1]:59560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXgMy-0000oW-B5 for importer@patchew.org; Fri, 14 Dec 2018 00:50:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXfxu-0004mZ-5u for qemu-devel@nongnu.org; Fri, 14 Dec 2018 00:24:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXfxs-0005W4-Iz for qemu-devel@nongnu.org; Fri, 14 Dec 2018 00:24:46 -0500 Received: from mail-oi1-x242.google.com ([2607:f8b0:4864:20::242]:37728) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gXfxs-0005Vj-DP for qemu-devel@nongnu.org; Fri, 14 Dec 2018 00:24:44 -0500 Received: by mail-oi1-x242.google.com with SMTP id y23so3631802oia.4 for ; Thu, 13 Dec 2018 21:24:44 -0800 (PST) Received: from cloudburst.twiddle.net ([187.217.227.243]) by smtp.gmail.com with ESMTPSA id r1sm1845379oti.44.2018.12.13.21.24.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Dec 2018 21:24:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UXA8cM0cwjStQGcIey4x1Y3QYETvHjeC6zxF5/48Sfk=; b=IybUCLK+jzARGxmjVpzT3qdpcTflqMGwBXCFjd/2mu1NV1yCWmyv4k3ITixNAALHmq +LIxwzdR+OnJQyxhjCDyL0mKj2rYqmyKaodB9U4cpekrDZ9/Ydfu8uH3bT3d1B9/3H2s PHmnCCsL/Ei1RhE8C8/ybsd3njCkCcR/mnyOM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UXA8cM0cwjStQGcIey4x1Y3QYETvHjeC6zxF5/48Sfk=; b=YhBeYtj+qks2Rwjx+KbltRQGV13AURUAjYmp9cT4Aqn45E5dLzIyVXlnoDJ0q567uc pzKTREs5I7BIHUQQ//0iz56xeC+UWxRo7/tqjOaxFAUp6qyv5NSvxVeK25FaBeaOQcGX qyyKgCgBgLrE2qyEzTdrYg2ZSjnADIm8DxOPXu2goFxrkQFGV5GJ7ZMy/biyikO8xlbQ gSqF+my6BtNR/qUa5p7kfj5ArRVKtDDlp8LusmUMHiXDFfvelrkG0QapVCWcUSsIaLWo HmWx5C0saN+ZuJmhOrtD49jk1BpOnDiBYimYCOFhONqFBEqegHsbbOKbDBndGn5utCgP bd1w== X-Gm-Message-State: AA+aEWZc8J5WmeMWoSAKL48PyssVmH3reB0oYjKDiAe+4npSAjKx+3N6 hQihdoEg04RrzsE33o9WZ6MUoCyuPNBkEQ== X-Google-Smtp-Source: AFSGD/XMrFxpcms5MNVde6vzyfzVEeX7gaz3nVk6ldkpUsZ/jt3qfg8zdw9rqXyM9paGCvAytUkRig== X-Received: by 2002:aca:ec55:: with SMTP id k82mr920668oih.55.1544765083290; Thu, 13 Dec 2018 21:24:43 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 13 Dec 2018 23:24:10 -0600 Message-Id: <20181214052410.11863-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181214052410.11863-1-richard.henderson@linaro.org> References: <20181214052410.11863-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::242 Subject: [Qemu-devel] [PATCH v2 27/27] target/arm: Tidy TBI handling in gen_a64_set_pc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We can perform this with fewer operations. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/translate-a64.c | 65 ++++++++++++++------------------------ 1 file changed, 23 insertions(+), 42 deletions(-) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index c57c89d98a..5c06e429d4 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -261,7 +261,7 @@ void gen_a64_set_pc_im(uint64_t val) /* Load the PC from a generic TCG variable. * * If address tagging is enabled via the TCR TBI bits, then loading - * an address into the PC will clear out any tag in the it: + * an address into the PC will clear out any tag in it: * + for EL2 and EL3 there is only one TBI bit, and if it is set * then the address is zero-extended, clearing bits [63:56] * + for EL0 and EL1, TBI0 controls addresses with bit 55 =3D=3D 0 @@ -276,56 +276,37 @@ void gen_a64_set_pc_im(uint64_t val) */ static void gen_a64_set_pc(DisasContext *s, TCGv_i64 src) { + bool tbi0 =3D s->tbi0, tbi1 =3D s->tbi1; =20 if (s->current_el <=3D 1) { - /* Test if NEITHER or BOTH TBI values are set. If so, no need to - * examine bit 55 of address, can just generate code. - * If mixed, then test via generated code - */ - if (s->tbi0 && s->tbi1) { - TCGv_i64 tmp_reg =3D tcg_temp_new_i64(); - /* Both bits set, sign extension from bit 55 into [63:56] will - * cover both cases - */ - tcg_gen_shli_i64(tmp_reg, src, 8); - tcg_gen_sari_i64(cpu_pc, tmp_reg, 8); - tcg_temp_free_i64(tmp_reg); - } else if (!s->tbi0 && !s->tbi1) { - /* Neither bit set, just load it as-is */ - tcg_gen_mov_i64(cpu_pc, src); - } else { - TCGv_i64 tcg_tmpval =3D tcg_temp_new_i64(); - TCGv_i64 tcg_bit55 =3D tcg_temp_new_i64(); - TCGv_i64 tcg_zero =3D tcg_const_i64(0); + if (tbi0 || tbi1) { + /* Sign-extend from bit 55. */ + tcg_gen_sextract_i64(cpu_pc, src, 0, 56); =20 - tcg_gen_andi_i64(tcg_bit55, src, (1ull << 55)); + if (tbi0 !=3D tbi1) { + TCGv_i64 tcg_zero =3D tcg_const_i64(0); =20 - if (s->tbi0) { - /* tbi0=3D=3D1, tbi1=3D=3D0, so 0-fill upper byte if bit 5= 5 =3D 0 */ - tcg_gen_andi_i64(tcg_tmpval, src, - 0x00FFFFFFFFFFFFFFull); - tcg_gen_movcond_i64(TCG_COND_EQ, cpu_pc, tcg_bit55, tcg_ze= ro, - tcg_tmpval, src); - } else { - /* tbi0=3D=3D0, tbi1=3D=3D1, so 1-fill upper byte if bit 5= 5 =3D 1 */ - tcg_gen_ori_i64(tcg_tmpval, src, - 0xFF00000000000000ull); - tcg_gen_movcond_i64(TCG_COND_NE, cpu_pc, tcg_bit55, tcg_ze= ro, - tcg_tmpval, src); + /* + * The two TBI bits differ. + * If tbi0, then !tbi1: only use the extension if positive. + * if !tbi0, then tbi1: only use the extension if negative. + */ + tcg_gen_movcond_i64(tbi0 ? TCG_COND_GE : TCG_COND_LT, + cpu_pc, cpu_pc, tcg_zero, cpu_pc, src); + tcg_temp_free_i64(tcg_zero); } - tcg_temp_free_i64(tcg_zero); - tcg_temp_free_i64(tcg_bit55); - tcg_temp_free_i64(tcg_tmpval); + return; } - } else { /* EL > 1 */ - if (s->tbi0) { + } else { + if (tbi0) { /* Force tag byte to all zero */ - tcg_gen_andi_i64(cpu_pc, src, 0x00FFFFFFFFFFFFFFull); - } else { - /* Load unmodified address */ - tcg_gen_mov_i64(cpu_pc, src); + tcg_gen_extract_i64(cpu_pc, src, 0, 56); + return; } } + + /* Load unmodified address */ + tcg_gen_mov_i64(cpu_pc, src); } =20 typedef struct DisasCompare64 { --=20 2.17.2