From patchwork Fri Dec 14 05:24:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 153768 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1685990ljp; Thu, 13 Dec 2018 21:50:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vax672J9t3Pd7lkpVd9GVfX4PkagUmTCckZOVc2Ln3xDusp+Z99IYOqYOB/FVxuUh/fXDb X-Received: by 2002:ac8:962:: with SMTP id z31mr1476627qth.305.1544766602379; Thu, 13 Dec 2018 21:50:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544766602; cv=none; d=google.com; s=arc-20160816; b=wAxkAA490gWM3Yt1OWDNasiLNN4X5lW7Bo3gmy4sAfRBJnH9a+sMidI0nzBeIbbTKX wAFecbWhX43DHAtbKtUJJ+Bo752l4yffOMed3wZAQ6Y8aSMdf4SIc39uFwXeQv3Pf08Q xe6hJIzOBNa3v/qCFadMsazx1r8aFO8EjdEFz5C/uN34RMYRRDnvav0UW0H5twnYyTXj YSD4Ck4lhI8PBBO2iaNrjnktEKMftFNmCduCe/TkNHQoO88K5E0i47qnYLgfeJbh6a3h 3TGWK5OoadZ6E31v7d/nhgsztDver7YgaQbBBm2CNQ9bqdHdbyCwT+BY3guYxAKO2BDR slyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=UXA8cM0cwjStQGcIey4x1Y3QYETvHjeC6zxF5/48Sfk=; b=vV0W+6lI1DVDbmFIx21pbhyxBW4hhyCs5TWBtD7i0uEwNKEE6PMmQU93+lGfrAQ31j W6Xd1WeBJtpqQfPwLnkIDrGRcPNhv9pbsYuU/wK8jcFcMjOwWTFTS07k1Q8s4ZIlQkTo vC+YQ7SpwU0CseqZfNA5jNv5CM1VbWSG3nvQoUKMH48uxMr4kDNPy8pgijZhKbixHP4k 8VNVwSFkuvHHwq8IMBlZN3SyMO82DIjOXSQmJE/CzsMu+iCeG0/FgwElXCSoom6ZYUvp 7RTO+cpdOC7XVtfFcYrVamqZo8RI3YczlQNRYEMcSo0ll5DziRuz/Q5pAM5SSNrQYosO 26/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IybUCLK+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v7si2366560qkv.68.2018.12.13.21.50.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 13 Dec 2018 21:50:02 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IybUCLK+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXgML-0000RR-Ux for patch@linaro.org; Fri, 14 Dec 2018 00:50:01 -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) 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-Received: by 2002:aca:ec55:: with SMTP id k82mr920668oih.55.1544765083290; Thu, 13 Dec 2018 21:24:43 -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) 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We can perform this with fewer operations. Signed-off-by: Richard Henderson --- target/arm/translate-a64.c | 65 ++++++++++++++------------------------ 1 file changed, 23 insertions(+), 42 deletions(-) -- 2.17.2 Reviewed-by: Peter Maydell 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 == 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 = s->tbi0, tbi1 = s->tbi1; if (s->current_el <= 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 = 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 = tcg_temp_new_i64(); - TCGv_i64 tcg_bit55 = tcg_temp_new_i64(); - TCGv_i64 tcg_zero = tcg_const_i64(0); + if (tbi0 || tbi1) { + /* Sign-extend from bit 55. */ + tcg_gen_sextract_i64(cpu_pc, src, 0, 56); - tcg_gen_andi_i64(tcg_bit55, src, (1ull << 55)); + if (tbi0 != tbi1) { + TCGv_i64 tcg_zero = tcg_const_i64(0); - if (s->tbi0) { - /* tbi0==1, tbi1==0, so 0-fill upper byte if bit 55 = 0 */ - tcg_gen_andi_i64(tcg_tmpval, src, - 0x00FFFFFFFFFFFFFFull); - tcg_gen_movcond_i64(TCG_COND_EQ, cpu_pc, tcg_bit55, tcg_zero, - tcg_tmpval, src); - } else { - /* tbi0==0, tbi1==1, so 1-fill upper byte if bit 55 = 1 */ - tcg_gen_ori_i64(tcg_tmpval, src, - 0xFF00000000000000ull); - tcg_gen_movcond_i64(TCG_COND_NE, cpu_pc, tcg_bit55, tcg_zero, - 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); } typedef struct DisasCompare64 {