From patchwork Mon Apr 8 17:49:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 786926 Delivered-To: patch@linaro.org Received: by 2002:adf:fb4d:0:b0:346:15ad:a2a with SMTP id c13csp157wrs; Mon, 8 Apr 2024 10:51:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVAA0V513HLlncxrPYGziQ++OKS7tkEFaAW7NHS4QkpEcmzbHxG7MB5sOZrvnRQcp1hvxaxchMBydA6Y5oPgOY+ X-Google-Smtp-Source: AGHT+IGqvSHK9rTR1uMk+BZXv3+ja8Iv5zHRMXF4D9mG/hJQRr/Sj2b5BqEgGfRREPDAq4qO9ySQ X-Received: by 2002:ae9:e648:0:b0:78d:6d20:7092 with SMTP id x8-20020ae9e648000000b0078d6d207092mr76060qkl.39.1712598678244; Mon, 08 Apr 2024 10:51:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712598678; cv=none; d=google.com; s=arc-20160816; b=0ScbXEQiTR5L+vRe/SVI4ZlMZhH+u0fZAbAWBuFNnc5jwdD8c6uIKmPLX5rnv5qrZc kMaonV1kxYhsZFopivPi6D9EPhmBXndp/39bKnMDQC10wB+uqps9dFow+niuKa1Xps2u 65PF2HqMTofgTzW5Jm6bhV3pnkYr8Q0mO8WKretwVy6jHKVZ18AqaDwWWBZ6DrsjX0qn BqbylW9Jv8r1SymEYphhYKE63ccPHQyVmrloLRRLQTMx9nVzcEGswTiBVDMPiIVY1VVM y9WHKlQ8ioTMNwnEMwydWnYvT+NIW2bo57yDSROcaz0vJeNGoDoZMbmfoqh02j3KdcBd 2lAg== 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:to:from :dkim-signature; bh=DA4w6vWBcl/o/fCPqKs/e8JAcC2+x8OTjBrtE2E7+xQ=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=dGedQbNJoBvPcjv+2g3QY2pDS3LmyBytZxIbGmaQlevN1eXZKzfcK/fyDRjHy8xfm2 rAeJYOXbuO4QN9H7u2IUpNMgHCO8bENVT1aIq4ROISchXZ+rzGt8dajAhrAKMtl+e1+o kjxBlbvJ1EqtjMryNQ13V13DkUuZEUGa+w+c9Q5al24vWlpU0UnM9op5TDO7uAFCh7DQ ydclrb/beqrB4xjkgcEaYuUHqhoUtmBrgFhK8WCzYzBI9nOQCiWa1Rt6I+lb95anSyuz zEl9nPextkRKooZAf6iPhk90QG6eLBBGtokG7Npz6H3RBS41XPFY7neg2sEdQ8y0d99v DcwA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cgC6t8W+; 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 x4-20020a05620a448400b0078bba8642c9si9424555qkp.519.2024.04.08.10.51.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 10:51:18 -0700 (PDT) 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=cgC6t8W+; 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 1rtt8s-0002Kt-T5; Mon, 08 Apr 2024 13:50:52 -0400 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 1rtt8V-0002B2-HU for qemu-devel@nongnu.org; Mon, 08 Apr 2024 13:50:29 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rtt8S-0003qM-VQ for qemu-devel@nongnu.org; Mon, 08 Apr 2024 13:50:26 -0400 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2a2d248a2e1so3034345a91.0 for ; Mon, 08 Apr 2024 10:50:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712598623; x=1713203423; 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=DA4w6vWBcl/o/fCPqKs/e8JAcC2+x8OTjBrtE2E7+xQ=; b=cgC6t8W++rsm4GL4DdBm2x4la/mNiP5CD1+N+vKqUhrhHmAyfgBPGhvWuRv8giGwLA kF1SlwafiwEIiJo4oJkTgOeN9Vy1JWtPnJzZ8DV6R7463IOfgytxHjYw8xLCdqZxkW57 KCvl3HBN6bE2q/taxUeU2Uff6wt+Z+BSmswl2bTU21QoP1tsOzuDZDjbg5isiyqgHeBb TgRrgjDZ6uUT/W1vbkaJvECqbJS6oivPe4IfawZbCF/WnzVPkB9Pv4LS3z0R3edj+CAu Jn4u+UEPmouK9fvEhw7Xbad7BkmmFNcBtojxMkIbvlRLxixECS9mEVibD/UCJZ9q7ws2 FCXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712598623; x=1713203423; 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=DA4w6vWBcl/o/fCPqKs/e8JAcC2+x8OTjBrtE2E7+xQ=; b=DDfqBacFkJ0ht/xVA1lHf0nf4tIaqoCDytxAWmZ+7/s8AD/TW8qiJRKWhsOtdRkIs6 t9moCIcRxF/XVS8bb/uAjgPZIKM75Tcb5uhCEty1Zea3Z53WHUqjfVozyEt7scI49B3X 6RTeILVt5a6mB/fDU6JQVf14cq99pCoGDiRNQzRlTabbTxQGdzBcEpmDAbASZpyYFela DVmfJJxMdiPWSAGDHM+mnjQa3iRuC5Jdc/5sSwFTcoh2xRZQVWcbpwjTzxQwkgke+N6C 4P7LZoJZrr1A2eecZofjcGX7obHXeg1i36HbSjRPBsQ+Oci7zpeYyFwa4EQmCWG/lx9M iRjg== X-Gm-Message-State: AOJu0YyUHvFELsCcpZ3zTeqvlE7IiDGgk1v+BEo20TAC9nuoQ80NKjHA abFsM2f2zlYswSZX70u3zEtYBDomnra1J4HCO9LpadCxWLhAmKnL1ys/a11wWwlgGY9Xu9x5U67 E X-Received: by 2002:a17:90b:4a12:b0:29f:76d4:306a with SMTP id kk18-20020a17090b4a1200b0029f76d4306amr469099pjb.24.1712598623420; Mon, 08 Apr 2024 10:50:23 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id ga15-20020a17090b038f00b0029c3bac0aa8sm8658432pjb.4.2024.04.08.10.50.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 10:50:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 35/35] util/bufferiszero: Simplify test_buffer_is_zero_next_accel Date: Mon, 8 Apr 2024 07:49:29 -1000 Message-Id: <20240408174929.862917-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240408174929.862917-1-richard.henderson@linaro.org> References: <20240408174929.862917-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.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 Because the three alternatives are monotonic, we don't need to keep a couple of bitmasks, just identify the strongest alternative at startup. Signed-off-by: Richard Henderson --- util/bufferiszero.c | 56 ++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/util/bufferiszero.c b/util/bufferiszero.c index eb8030a3f0..ff003dc40e 100644 --- a/util/bufferiszero.c +++ b/util/bufferiszero.c @@ -179,51 +179,39 @@ buffer_zero_avx2(const void *buf, size_t len) } #endif /* CONFIG_AVX2_OPT */ - - -static unsigned __attribute__((noinline)) -select_accel_cpuinfo(unsigned info) -{ - /* Array is sorted in order of algorithm preference. */ - static const struct { - unsigned bit; - biz_accel_fn fn; - } all[] = { +static biz_accel_fn const accel_table[] = { + buffer_is_zero_int_ge256, + buffer_zero_sse2, #ifdef CONFIG_AVX2_OPT - { CPUINFO_AVX2, buffer_zero_avx2 }, + buffer_zero_avx2, #endif - { CPUINFO_SSE2, buffer_zero_sse2 }, - { CPUINFO_ALWAYS, buffer_is_zero_int_ge256 }, - }; - - for (unsigned i = 0; i < ARRAY_SIZE(all); ++i) { - if (info & all[i].bit) { - buffer_is_zero_accel = all[i].fn; - return all[i].bit; - } - } - return 0; -} - -static unsigned used_accel; +}; +static unsigned accel_index; static void __attribute__((constructor)) init_accel(void) { - used_accel = select_accel_cpuinfo(cpuinfo_init()); + unsigned info = cpuinfo_init(); + unsigned index = (info & CPUINFO_SSE2 ? 1 : 0); + +#ifdef CONFIG_AVX2_OPT + if (info & CPUINFO_AVX2) { + index = 2; + } +#endif + + accel_index = index; + buffer_is_zero_accel = accel_table[index]; } #define INIT_ACCEL NULL bool test_buffer_is_zero_next_accel(void) { - /* - * Accumulate the accelerators that we've already tested, and - * remove them from the set to test this round. We'll get back - * a zero from select_accel_cpuinfo when there are no more. - */ - unsigned used = select_accel_cpuinfo(cpuinfo & ~used_accel); - used_accel |= used; - return used; + if (accel_index != 0) { + buffer_is_zero_accel = accel_table[--accel_index]; + return true; + } + return false; } #else bool test_buffer_is_zero_next_accel(void)