From patchwork Wed Apr 24 22:57:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 791547 Delivered-To: patch@linaro.org Received: by 2002:a5d:4884:0:b0:346:15ad:a2a with SMTP id g4csp1093276wrq; Wed, 24 Apr 2024 15:58:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUftQVcL+1KGyyzDw7jQX2lS1c2iDb9HOEZGbYCjBiqYMhWF2qm6iZqd7SnzIxGAriSx6oaMc7+4nMaVc6wsfWE X-Google-Smtp-Source: AGHT+IHz57+wvQEVbXSVzw6nwOPvweHO1q7/p8MuNQb/FFtjjv5W/HSsjm1uEbVd3JlUpXwvepev X-Received: by 2002:a05:622a:5e87:b0:439:f5f1:2d78 with SMTP id er7-20020a05622a5e8700b00439f5f12d78mr4771157qtb.25.1713999517884; Wed, 24 Apr 2024 15:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713999517; cv=none; d=google.com; s=arc-20160816; b=dyRJPO13jyWPKlboCj4cltQpf6q/VmbUyswkROn+lEw7zmMmhOTSpBin8kNOi56wkA t9M8bl7PsWxN5x/l7P0stT5w1VuygpyQKceud+FUSrAMNaEtJtdzS1quLfz2vy6IbrcL x/MBtUOeXadqfh62nmD8R3qfdRPov09OGaTQnRcGuMAO6yFug/bWDgPqs+HAMKNsbDPe pGC+vQWcuZ6iW8/gMkpqVxGo1b6vw/1BPcKq4AkSIwvRGAfYGNZw6E8yl3v4OCYP5eWM 45AeyHuRCUstsHVAMba2YccKYlDDw0sdZt4fwpeKb098Y7Z0FY7OyNdkyGIJcgEzgHlB rfVA== 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=tk69kpKyjYUr/UO/U64NCNbuvjm3YONEJG3YVMc5cs+/2fHHqrDo3xv2epPEwsDnF1 9zI1HTHAMBsc8DmhT90H/8TqVRrD/R22oU7aSKzqUTNUZPVoBg+b17wlF4JIiXYx5zfs DpNxEznz4+2UeiuwLcIh1phZaf57FgLzVLdiYH7mU3HVsMkSQgmLcrdBabScxeGGqDnB QhLrjB5pDaBBC7NIf2tPN5OESwV/w5tFtSMY+v58YzaIXZ/nrIbRhBqEm34eRe9FQ4H/ hevSilikHmhM39HQtwAcEZF9APmCMuEVSZcLoUWhPEn6jYz3flOgLuRJcx1JyulfL0FV 9G5Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kwDdxqO3; 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 o10-20020a05622a138a00b00439f37bf751si5010720qtk.628.2024.04.24.15.58.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2024 15:58:37 -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=kwDdxqO3; 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 1rzlYW-0005ck-PN; Wed, 24 Apr 2024 18:57:36 -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 1rzlYL-0005Py-8G for qemu-devel@nongnu.org; Wed, 24 Apr 2024 18:57:25 -0400 Received: from mail-oa1-x30.google.com ([2001:4860:4864:20::30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rzlYJ-0001p5-KV for qemu-devel@nongnu.org; Wed, 24 Apr 2024 18:57:25 -0400 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-22ed075a629so211118fac.3 for ; Wed, 24 Apr 2024 15:57:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713999442; x=1714604242; 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=kwDdxqO3dwbHcyqBo43kRllE23TQcpEJyqFw8JemDE5txYhXaZjr5WgsBgcTiU7Ejm oPepvBkr+bBnN/0hkqyAlcVobmN58khHUdPfJczQI0/7C5o+MNqpRkRyjFIlamDwvpKU tApVYVfuCq9BYWEm5OXybUvs8IEfLWpfcJsMgEKA9geYq6lI+pnsi8B844h2GHR9ZXSw z5h9tUzhYwbDn13d0SS4qoIp3JmMZThXE5CDzf7G/SarOiQ6QvxZTWx6LEE2SFb5Tq2t fZBk2bjZtot+kRPNWg21LZ8auV/QHVhJtc0JIhzNYYnyOoTGpl6DAWKgYk83SS2WRNF6 K8GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713999442; x=1714604242; 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=acAzHLS3v1oiBDndWd9ICYdvvpzewzCa6qcHkhRXyqTJlsV8aMaQlZArsgS7mv3Bre Rj6pEsgn3Gj6T3Ol7OwJnjFO1z0u1zRbgwrSmhh6wDCGzrV25L88vcZO9lR2BOMGrYBQ KXA2SITLRu2Uj6qF5kHv8MhSkcFVWL6L4OEAnAPrqUWPKMPNue/MVjuFWhQUvzyeJBtY sejZRpv4TB45NAa/VJ9w0upDeGq4NN8Dw4Q3GENtp1uPhoeBjUwf7P70xAugDbKvVWhP ggwVwnjPYf49YEC0EIO0O4Kv1clita1BGLf1882O55/DFx6IJUIFGWetJ+mKOMwcpQTM ATHA== X-Gm-Message-State: AOJu0Yy1kWlDpHUXWIuTmRDv2tHKFSiJL+/Wik5Bb/bbjs0iXCsXjFPF 5XLhlK+z6o5vNAr5G2y55c8f/cZ0UvS41LwP3TrHwvPUcbhxxFui/kgWXMF7pzNVmKFQ1E5a2vD T X-Received: by 2002:a05:6870:a345:b0:238:b140:1ab with SMTP id y5-20020a056870a34500b00238b14001abmr4443648oak.48.1713999442267; Wed, 24 Apr 2024 15:57:22 -0700 (PDT) Received: from stoup.. ([156.19.246.23]) by smtp.gmail.com with ESMTPSA id gu26-20020a056a004e5a00b006ed9760b815sm11947413pfb.211.2024.04.24.15.57.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 15:57:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v6 08/10] util/bufferiszero: Simplify test_buffer_is_zero_next_accel Date: Wed, 24 Apr 2024 15:57:03 -0700 Message-Id: <20240424225705.929812-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424225705.929812-1-richard.henderson@linaro.org> References: <20240424225705.929812-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::30; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x30.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 Reviewed-by: Philippe Mathieu-Daudé --- 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)