From patchwork Fri Dec 7 10:36:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 153129 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp347336ljp; Fri, 7 Dec 2018 02:53:21 -0800 (PST) X-Google-Smtp-Source: AFSGD/WRQ2b60YN5H8gEgwNopTBXRw7bOaH9MwdBCg91HIEMu9Pf2wc9lzfOdPxMimncmKU9AFL7 X-Received: by 2002:a37:8882:: with SMTP id k124mr1295145qkd.1.1544180001021; Fri, 07 Dec 2018 02:53:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544180001; cv=none; d=google.com; s=arc-20160816; b=beG/8QtL8+AzAF0MgAvf/OS2C214adKA/ucEzSgSDrwU/UZ5sPRnlCI66YnFw28IDW kV918+C/bcdRYArC6x1OxKbUas7MwgiTyaJbeKTBWxr7sLQFPSkGlf6vDd1Or7lWMnHs rN6mGCue1oTZEyBAMMK19IyBzUp/ZMBbXHyA26WzNcem4++q6Nh5WV92pO/NRL7x6C61 RhfH0ikCdsoiYbZkqUQ4FrGwKyhzNzUaF5ehc+AzD4O7HvUcyuuLZAKahanBCuYbsWRb ZB9JL/ymouE0UI/EcmKBbYSTWVo2OuDCDd0iJDXTS7P5muBhxfx03X3rGu+uxPgT21M+ jKsw== 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=U+yA0gpIKvjd3st8336MWjcYGoymhOrHRSCnKqU8W1M=; b=VEIdXczwugOceWmbZW40KCstM8s0xdAbqwFFrWODgaO6/YhrG+TtHkHYaIpXCSpaoX gOmnLI9QtL6aUMy8sUMFUNhpgZdWeWGTCLS83ukvy+E6h2cSnNespV3oG7yqfx9mThLV 2NwVJhEZx3ytSA9tgSdpvDdyQvfAFJLAq8M2SL0YA0Qm5GoTMeM2L3jGYpfp3K22+zgR qOXV5wrnE+I8zgq6eBsBGSlT7Yhjh+79RmqeBHct3s9ng3Tq4M6xQOK5G8xOwTozwSyM cBXBoN6HURe4XC01ysnxwDxYgSALwAcawq4XZgFBno120Yu65GuEcTpfwIPwhe3vp0I/ NaCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=AIZY0ejo; 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 q128si1959971qka.151.2018.12.07.02.53.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Dec 2018 02:53:21 -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=AIZY0ejo; 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]:45336 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVDl2-0002oM-Ey for patch@linaro.org; Fri, 07 Dec 2018 05:53:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVDVW-00007O-5e for qemu-devel@nongnu.org; Fri, 07 Dec 2018 05:37:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gVDVT-00083g-4l for qemu-devel@nongnu.org; Fri, 07 Dec 2018 05:37:18 -0500 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]:41505) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gVDVS-00082y-Vf for qemu-devel@nongnu.org; Fri, 07 Dec 2018 05:37:15 -0500 Received: by mail-ot1-x342.google.com with SMTP id u16so3339889otk.8 for ; Fri, 07 Dec 2018 02:37:14 -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=U+yA0gpIKvjd3st8336MWjcYGoymhOrHRSCnKqU8W1M=; b=AIZY0ejoG1yXxsUlm3vBzEUoACwtyVyxXKTsJEN9MKhIyIBGVxmTCCD3Y1d6FwKRa8 ZG+PA2qipXo5XdDy7yPLJ7NGxm3AMcQ/5b+o13rgwtd0g5jHYGFv5sii6w9JCBc6UlFN usS6jm9wEJIsdeELqrhdL5BfkOWvWpSa26TdU= 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=U+yA0gpIKvjd3st8336MWjcYGoymhOrHRSCnKqU8W1M=; b=ljYoN0Y8JA6NJa6xLp2VdpKAzF0gbBb1qChmxbr046qJeOve7nS9fj0030F4RON3iJ qwOOKkACXRJoX3ruROa7Zws32zWMo4qYBnp2eXT2HtX5k11ZQSoZ43AWZ1OfQ3vLj9s7 ZVMyxQwh5P09HoJa+vC2V91xMAULXLjsx8tt5cO2L+LL7P1WPNiOlgdTLCqU6wWRhsNg p7Netzmbmeo4wCkBfZfKW0hsaazEvQJe6/JV4EYmbc+hfAufLXq9Ih/PAOMrAnpvjoD8 Xs2uxeMz57VecvfScIWxE9UJDKLf3rG1MQNqIiKWTIkrSPHq1u8XUnYpP5su/3o63C+k 31vA== X-Gm-Message-State: AA+aEWYutx+HOrKkFAiw8lhS1ka2HMHBHeo/RMmViQrs4SzKe7tgYFpO 101p1wbYlshmJ0XvIMINQMK5hcgdpiY= X-Received: by 2002:a9d:3e4a:: with SMTP id h10mr1179313otg.74.1544179033691; Fri, 07 Dec 2018 02:37:13 -0800 (PST) Received: from cloudburst.twiddle.net (172.189-204-159.bestel.com.mx. [189.204.159.172]) by smtp.gmail.com with ESMTPSA id c19sm2037594otl.16.2018.12.07.02.37.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Dec 2018 02:37:13 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 7 Dec 2018 04:36:31 -0600 Message-Id: <20181207103631.28193-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181207103631.28193-1-richard.henderson@linaro.org> References: <20181207103631.28193-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::342 Subject: [Qemu-devel] [PATCH 26/26] 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, ramana.radhakrishnan@arm.com 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 diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 99e1405dff..15080cbb3c 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 {