From patchwork Fri Jan 19 22:47:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 763958 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:10c4:b0:337:62d3:c6d5 with SMTP id b4csp99650wrx; Fri, 19 Jan 2024 14:48:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtD+/BDfLxwuXQNSILtdWELzt5EBzFNpGpnTc7w5wOiiPKZ1dEL9cjNxqdOe/RPIxsjreb X-Received: by 2002:a05:6808:11c2:b0:3bd:928e:b162 with SMTP id p2-20020a05680811c200b003bd928eb162mr591434oiv.68.1705704513587; Fri, 19 Jan 2024 14:48:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705704513; cv=none; d=google.com; s=arc-20160816; b=qr2qceGDwN5hSTN/urTPDCbtHTpinhaV75i36TTfoHoDJtgazyVn7L4XdjbGYpIwPR YV1KuKUvg/zR0+aJ7XyQIQA57izmAryUhPez0oj3ljTWVyljrItAdXjkNnlhC7j528+Q aqsN11jGpJ8DVa7xtZs/paIzD4Zw24uUWMQijA0uCSC1u3QZaKhdhp08jK1yHTn+EjFC TGkM3QKIPTTbwAwx1pkIJy3nJQtWGgr3aocTK/4lmaFx8XkzZFKN7gQ48viJXq6i3L+H e+c6oyojai6DUzVyYDogDBi71qeDuXDFfSHVKQuU3WUGVLuA1JpV86hf0mPVT0Hv8m9b d5Xg== 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=0i49bfX5EKeDHdiiMATpVEET9ukdc5btc9PSeKgXkWY=; fh=FGhvf/J6viukKll+OHHiF0KzEfQoh7e0u+ACsGzuW1Y=; b=hzg6HWXvBVYSLPGRL5gkPonDITnWR8i5GvzRdQ3+lBq0VS72eGMKk9Jtsp3dNVS6I5 8xPaPANPzy037/gp6v1xnXg1y3lrQNXz2tWk2X9m70FU2usHIZlAcD2DlM/73U9u/QuW Rzxl7T1MD5xTN2U2/1Pncsg59RDrziJb960MHvyOVEfLzVOrWSZCqJzcDSZF63RWP7wE QBSlCA1eU0JkNaX5cAS+wOraQygJ8TZc38u9PLOiRGNtM1PsIzRqXv1jmv7YGBKhrJy1 5+n7o6atF7bwba7DLLEW+DBrhNVjlF/KaHsIEe/lGTUFHEes+lHpQMh53eqMGw22jNBc tvAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N4kJLnJ2; 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 s10-20020a05620a29ca00b007837aa4968asi253919qkp.709.2024.01.19.14.48.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Jan 2024 14:48:33 -0800 (PST) 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=N4kJLnJ2; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQxeS-00061Y-50; Fri, 19 Jan 2024 17:47:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQxeQ-00061L-CK for qemu-devel@nongnu.org; Fri, 19 Jan 2024 17:47:50 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rQxeK-000810-Ux for qemu-devel@nongnu.org; Fri, 19 Jan 2024 17:47:50 -0500 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3366e78d872so1090893f8f.3 for ; Fri, 19 Jan 2024 14:47:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705704463; x=1706309263; darn=nongnu.org; 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=0i49bfX5EKeDHdiiMATpVEET9ukdc5btc9PSeKgXkWY=; b=N4kJLnJ2iz/KHtLYyu4fu5iS+qKem3beIuBd/LsOru1Lj9U9Oe3gYbZenp4nPyiSoE l+hXAo0hHnaNlh/UsS4co17bK9at9W5PadtMSBHJwZxhDNhahiI1P0cNpKmaIZyB/iLu IqB9drLphee4gj3B3lGLojs23GVEdJlXdzGd5Sb9xI7WT4A1MXJ13T14gKwciavlPtqT itqHCaX/OLS9UyAqZuojMm3mnZ+ytpKYGnYblIXv3CT23X0suLQi3zvdKxatty5mhXdS HMzqvBqZ7oScVevDzDQjuldZfFJO5OWOcY2WPHaatSBWsq3x24wYhHJjWTu7G3lmv2hx 5iYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705704463; x=1706309263; 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=0i49bfX5EKeDHdiiMATpVEET9ukdc5btc9PSeKgXkWY=; b=j9pQxSnEhz//n0wZFQS+MJGzBZHCFgv/2cF8Cytn6C1BbQFkcCH6sr3fkv4gBMuQav t5M+eYJHmH9ikpsnJs3aOYDicWMzH2BH+NTZnOjS/xFarDWHjIn8T3QFCMN5bwqVkMJo Ov9ThtuCcuJDeT9NQTJTTNjYh+6q9mPpAHYi60WSV0liXC4uZiEPn9fD+H8wPomNVYrV r/FWkwNt2na4wX1/SIwuhimSoxOziKMNSYilZ92PPLC43CU5PA5u2leHK3R9K/5s4Lo1 61yFuznZJ0tfKM4IcyZu0aFG0XAN5DoyPkIKzSDY9iWFBMkpHR6IpBTi+PHrplPI9Vx+ HoZQ== X-Gm-Message-State: AOJu0YzdWnNkiRawx0ZqdOAWKK5lQVDchRXxPm9lJE5cVsC/9fh7COJs Sr1dJZCBhqejOmaqnXPkuCJWIpLDsBDek8MK8NXTuX3CLasZTUFc3OQQUV+4VXAEpH+c+m87F4c g X-Received: by 2002:a7b:c389:0:b0:40e:76f4:8cc8 with SMTP id s9-20020a7bc389000000b0040e76f48cc8mr132652wmj.287.1705704463129; Fri, 19 Jan 2024 14:47:43 -0800 (PST) Received: from localhost.localdomain (91-163-26-170.subs.proxad.net. [91.163.26.170]) by smtp.gmail.com with ESMTPSA id p37-20020a05600c1da500b0040ea22b51cbsm911964wms.34.2024.01.19.14.47.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 19 Jan 2024 14:47:42 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 18/38 2/2] tcg/aarch64: Generate TBZ, TBNZ Date: Fri, 19 Jan 2024 23:47:37 +0100 Message-ID: <20240119224737.48943-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240110224408.10444-19-richard.henderson@linaro.org> References: <20240110224408.10444-19-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=philmd@linaro.org; helo=mail-wr1-x431.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-bounces+patch=linaro.org@nongnu.org From: Richard Henderson Test the sign bit for LT/GE vs 0, and TSTNE/EQ vs a power of 2. Signed-off-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daudé --- tcg/aarch64/tcg-target.c.inc | 71 ++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 12 deletions(-) diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc index a19158f4ea..55225313ad 100644 --- a/tcg/aarch64/tcg-target.c.inc +++ b/tcg/aarch64/tcg-target.c.inc @@ -105,6 +105,18 @@ static bool reloc_pc19(tcg_insn_unit *src_rw, const tcg_insn_unit *target) return false; } +static bool reloc_pc14(tcg_insn_unit *src_rw, const tcg_insn_unit *target) +{ + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + ptrdiff_t offset = target - src_rx; + + if (offset == sextract64(offset, 0, 14)) { + *src_rw = deposit32(*src_rw, 5, 14, offset); + return true; + } + return false; +} + static bool patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) { @@ -115,6 +127,8 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, return reloc_pc26(code_ptr, (const tcg_insn_unit *)value); case R_AARCH64_CONDBR19: return reloc_pc19(code_ptr, (const tcg_insn_unit *)value); + case R_AARCH64_TSTBR14: + return reloc_pc14(code_ptr, (const tcg_insn_unit *)value); default: g_assert_not_reached(); } @@ -380,6 +394,10 @@ typedef enum { /* Conditional branch (immediate). */ I3202_B_C = 0x54000000, + /* Test and branch (immediate). */ + I3205_TBZ = 0x36000000, + I3205_TBNZ = 0x37000000, + /* Unconditional branch (immediate). */ I3206_B = 0x14000000, I3206_BL = 0x94000000, @@ -660,6 +678,14 @@ static void tcg_out_insn_3202(TCGContext *s, AArch64Insn insn, tcg_out32(s, insn | tcg_cond_to_aarch64[c] | (imm19 & 0x7ffff) << 5); } +static void tcg_out_insn_3205(TCGContext *s, AArch64Insn insn, + TCGReg rt, int imm6, int imm14) +{ + insn |= (imm6 & 0x20) << (31 - 5); + insn |= (imm6 & 0x1f) << 19; + tcg_out32(s, insn | (imm14 & 0x3fff) << 5 | rt); +} + static void tcg_out_insn_3206(TCGContext *s, AArch64Insn insn, int imm26) { tcg_out32(s, insn | (imm26 & 0x03ffffff)); @@ -1415,7 +1441,7 @@ static inline void tcg_out_goto_label(TCGContext *s, TCGLabel *l) static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a, TCGArg b, bool b_const, TCGLabel *l) { - intptr_t offset; + int tbit = -1; bool need_cmp = true; switch (c) { @@ -1425,31 +1451,52 @@ static void tcg_out_brcond(TCGContext *s, TCGType ext, TCGCond c, TCGArg a, need_cmp = false; } break; + case TCG_COND_LT: + case TCG_COND_GE: + if (b_const && b == 0) { + c = (c == TCG_COND_LT ? TCG_COND_TSTNE : TCG_COND_TSTEQ); + tbit = ext ? 63 : 31; + need_cmp = false; + } + break; + case TCG_COND_TSTEQ: + case TCG_COND_TSTNE: + if (b_const && is_power_of_2(b)) { + tbit = ctz64(b); + need_cmp = false; + } + break; default: break; } if (need_cmp) { tcg_out_cmp(s, ext, c, a, b, b_const); - } - - if (!l->has_value) { tcg_out_reloc(s, s->code_ptr, R_AARCH64_CONDBR19, l, 0); - offset = tcg_in32(s) >> 5; - } else { - offset = tcg_pcrel_diff(s, l->u.value_ptr) >> 2; - tcg_debug_assert(offset == sextract64(offset, 0, 19)); + tcg_out_insn(s, 3202, B_C, c, 0); + return; } - if (need_cmp) { - tcg_out_insn(s, 3202, B_C, c, offset); + if (tbit >= 0) { + tcg_out_reloc(s, s->code_ptr, R_AARCH64_TSTBR14, l, 0); + switch (c) { + case TCG_COND_TSTEQ: + tcg_out_insn(s, 3205, TBZ, a, tbit, 0); + break; + case TCG_COND_TSTNE: + tcg_out_insn(s, 3205, TBNZ, a, tbit, 0); + break; + default: + g_assert_not_reached(); + } } else { + tcg_out_reloc(s, s->code_ptr, R_AARCH64_CONDBR19, l, 0); switch (c) { case TCG_COND_EQ: - tcg_out_insn(s, 3201, CBZ, ext, a, offset); + tcg_out_insn(s, 3201, CBZ, ext, a, 0); break; case TCG_COND_NE: - tcg_out_insn(s, 3201, CBNZ, ext, a, offset); + tcg_out_insn(s, 3201, CBNZ, ext, a, 0); break; default: g_assert_not_reached();