From patchwork Thu Jan 2 18:06:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 854681 Delivered-To: patch@linaro.org Received: by 2002:a5d:4888:0:b0:385:e875:8a9e with SMTP id g8csp7901964wrq; Thu, 2 Jan 2025 10:09:41 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXqSPJD7I51Bl8SUTvS0l8meAuQe0NTVNbXSu2nOgevTFLBcAC0QZ24nfDRFDDws2BzyTIVYg==@linaro.org X-Google-Smtp-Source: AGHT+IGRg0caWY8NnKO15OL8gHCDKZ9kz/AXL1ZIN8Zbcd6u3HBlOUDmc387UpNaoGGEh5OqdZcX X-Received: by 2002:a05:620a:28c4:b0:7b7:142d:53b3 with SMTP id af79cd13be357-7b9ba81f465mr8276052485a.55.1735841380896; Thu, 02 Jan 2025 10:09:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1735841380; cv=none; d=google.com; s=arc-20240605; b=EIMpT+M7M6WFhE12/c6LDeB8eKRKiNj+H4Q5m27uA94FfWnFwTRhhkUJyVEcKQxNYN 3VJlJRXFZnvOB0037hk013N/2eJTth551orEx/MjShjcdsKrwZ22+AjEd3i/mgET6Aji OPdKxanxsni/QUjknEsFjUuAnyNuQeQcGtQZRC14pRezpiqhjAS5OdYLl+Fhl+gjqQvp LCh7F5df4yFFCkYJOVMZyxhn08TputIC+16/60qT/vj9czxDs+ivp3VURrmPG5qBP5W6 J9YauUbW37u+RO2dcxzFdmYENEmEx3aOmt6A/q0TuZc+Olet0mR0RZwbQfEqN81F1aL+ E6lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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:to:from :dkim-signature; bh=6BbOJGVKedcAH7Dn7J3WMmnBwhgk9Ccfhw3EFyhkC/4=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=fiJLgf8iN4cKVTdyD1lR16KGYAyxWpH9Jj3MOzVvLdF4LXw6K2BmcPHBockqokGRis Rj1K+Hn1rAoAHJs3iaT6tuUdIsS/hyB8dEcBzN5lSBYo1cYLzoBTzGUh91PoSn5Z0odY Riv+P52hLk82qy+7V0gfL+nloEd6itwm/W10KV1xs0fyy5L0BhnvHZ/2FcpsMDGdsQqt MkHiXxt9SLBQ97/CMWzq0jpIe1h4gN1DemUaPFWNhupJ7Cs46gC0zPQJzrN4QpEtwxNJ mQQfuLpQYMguPMNU6M7z+0xPQahf2NygduD3f5JzWXubNOpXgb06BTPe/Rqocmu2rr5B c5fg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yzq8pAYL; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7b9ac53e27bsi3528650185a.613.2025.01.02.10.09.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jan 2025 10:09:40 -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=Yzq8pAYL; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tTPbi-0007DX-Nr; Thu, 02 Jan 2025 13:07:42 -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 1tTPbQ-00071A-RT for qemu-devel@nongnu.org; Thu, 02 Jan 2025 13:07:26 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tTPbP-0005C6-0b for qemu-devel@nongnu.org; Thu, 02 Jan 2025 13:07:24 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2165448243fso190567375ad.1 for ; Thu, 02 Jan 2025 10:07:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735841242; x=1736446042; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=6BbOJGVKedcAH7Dn7J3WMmnBwhgk9Ccfhw3EFyhkC/4=; b=Yzq8pAYLc7P56RD5pahEBO1vQqZamNtYvhh4dQTBbCmzz13MXRwBXoLKXitbS5waOZ 8XAyO6hVaGirR4VHvgmtO5bHMxT3WPdEdyzAizQ8wy7WcK9ewnnXWOhf5f8n+slZjYGe yxpevdPvmnwz3gtyCTDrYFLGdDk52/n3A5CfkT7rE6h1sWcVU+HJrpCTA+lDqQFGZvUX WUEAYnMH55LVVYy0Gb0EQ77GEx7GKCcfr1BngxygIg/Fig18KuR5ZT5CwImdmWKPnh8i WYcRLjQuyp18TSOkaBKRAIszCo2As5hAnV/bay8towQWc6l5lJjFGXg+3jgMe6tulv1P RMpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735841242; x=1736446042; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6BbOJGVKedcAH7Dn7J3WMmnBwhgk9Ccfhw3EFyhkC/4=; b=XXKisH+edDUccpNcQ7c3ssIud3LLCkGekd0dD0nAx4IwgxPITLJDELlVhDQtyzcRPh 8O32YZyiyPGxcjenn+sF0YhkpLtQFqvZw6it4IyGREIDTQr/QVUnxcGw0kMD13legML4 ThGN3hBIiRCjnbbi6MpbCVuoOr3Xexsh3+fAJWF+uZLC87YYwVue/iiZGV+Xp2YSreT7 i2G1XkML0uEjB9Fnh9E/Zm5as3tbfYwjPMURaYOwV50rrW8EUR6Ck75wbSO75+7FvHR6 t/C+zSUhOalzU8lpbUo/IqHIC53ou81FzexPScRiFuYoANO1UDjDktSKJcwSO+u5J/NI QKlg== X-Gm-Message-State: AOJu0YwwWbqjohZLaEK3hRqOUkxgbF6CNdONpU+UXjNElRzSVN9ulShh w+IKCX/QLMaSY3u9LP55/tYOsgRBTVvymv0M0sYAKl8ZiBriphe9f8zo1uInY98PU24yDsYrwRB j X-Gm-Gg: ASbGncsfy5VBHCI2dfcVJoybDNb3KDir06kt+x5b/e+j/4a+Oyi+rjW5Gv0ZipPo+Uh Pl78T27qt8XnQpjOAeC5CuGApdsSCKQIBAFMJ2fcCFuRiPbsKC958JDThAxal0iKw3eWuiyaICv ej0sYCJmxNLeYczlc17W32r6UaSXcOF4d+f4lWeImaYeWpXZS+6iNc6+2v5txcVaDSDcv9fAcjk TXQzJZaylQ57FpEl9idDdfAIW5ldfU+5jytTLb/B66aW8eocYssJx323yQRMQ== X-Received: by 2002:a05:6a21:9102:b0:1d9:c753:6bad with SMTP id adf61e73a8af0-1e5e04647c8mr64854146637.10.1735841241702; Thu, 02 Jan 2025 10:07:21 -0800 (PST) Received: from stoup.. ([63.239.63.212]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72ad3393d5fsm20604456b3a.154.2025.01.02.10.07.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 10:07:21 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 34/73] tcg/arm: Add full [US]XT[BH] into {s}extract Date: Thu, 2 Jan 2025 10:06:14 -0800 Message-ID: <20250102180654.1420056-35-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250102180654.1420056-1-richard.henderson@linaro.org> References: <20250102180654.1420056-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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=ham 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 The armv6 uxt and sxt opcodes have a 2-bit rotate field which supports extractions from ofs = {0,8,16,24}. Special case ofs = 0, len <= 8 as AND. Signed-off-by: Richard Henderson --- tcg/arm/tcg-target-has.h | 17 +++++++++++++ tcg/arm/tcg-target.c.inc | 54 +++++++++++++++++++++++++++++++++++----- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/tcg/arm/tcg-target-has.h b/tcg/arm/tcg-target-has.h index cd9b68a024..6990968b06 100644 --- a/tcg/arm/tcg-target-has.h +++ b/tcg/arm/tcg-target-has.h @@ -80,4 +80,21 @@ extern bool use_neon_instructions; #define TCG_TARGET_HAS_cmpsel_vec 0 #define TCG_TARGET_HAS_tst_vec 1 +static inline bool +tcg_target_extract_valid(TCGType type, unsigned ofs, unsigned len) +{ + if (use_armv7_instructions) { + return true; /* SBFX or UBFX */ + } + switch (len) { + case 8: /* SXTB or UXTB */ + case 16: /* SXTH or UXTH */ + return (ofs % 8) == 0; + } + return false; +} + +#define TCG_TARGET_extract_valid tcg_target_extract_valid +#define TCG_TARGET_sextract_valid tcg_target_extract_valid + #endif diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc index 90ac80077f..44b7c6d185 100644 --- a/tcg/arm/tcg-target.c.inc +++ b/tcg/arm/tcg-target.c.inc @@ -1036,19 +1036,61 @@ static void tcg_out_deposit(TCGContext *s, ARMCond cond, TCGReg rd, static void tcg_out_extract(TCGContext *s, ARMCond cond, TCGReg rd, TCGReg rn, int ofs, int len) { - /* ubfx */ - tcg_out32(s, 0x07e00050 | (cond << 28) | (rd << 12) | rn - | (ofs << 7) | ((len - 1) << 16)); + /* According to gcc, AND can be faster. */ + if (ofs == 0 && len <= 8) { + tcg_out_dat_imm(s, cond, ARITH_AND, rd, rn, + encode_imm_nofail((1 << len) - 1)); + return; + } + + if (use_armv7_instructions) { + /* ubfx */ + tcg_out32(s, 0x07e00050 | (cond << 28) | (rd << 12) | rn + | (ofs << 7) | ((len - 1) << 16)); + return; + } + + assert(ofs % 8 == 0); + switch (len) { + case 8: + /* uxtb */ + tcg_out32(s, 0x06ef0070 | (cond << 28) | (rd << 12) | (ofs << 7) | rn); + break; + case 16: + /* uxth */ + tcg_out32(s, 0x06ff0070 | (cond << 28) | (rd << 12) | (ofs << 7) | rn); + break; + default: + g_assert_not_reached(); + } } static void tcg_out_sextract(TCGContext *s, ARMCond cond, TCGReg rd, TCGReg rn, int ofs, int len) { - /* sbfx */ - tcg_out32(s, 0x07a00050 | (cond << 28) | (rd << 12) | rn - | (ofs << 7) | ((len - 1) << 16)); + if (use_armv7_instructions) { + /* sbfx */ + tcg_out32(s, 0x07a00050 | (cond << 28) | (rd << 12) | rn + | (ofs << 7) | ((len - 1) << 16)); + return; + } + + assert(ofs % 8 == 0); + switch (len) { + case 8: + /* sxtb */ + tcg_out32(s, 0x06af0070 | (cond << 28) | (rd << 12) | (ofs << 7) | rn); + break; + case 16: + /* sxth */ + tcg_out32(s, 0x06bf0070 | (cond << 28) | (rd << 12) | (ofs << 7) | rn); + break; + default: + g_assert_not_reached(); + } } + static void tcg_out_ld32u(TCGContext *s, ARMCond cond, TCGReg rd, TCGReg rn, int32_t offset) {