From patchwork Sat Feb 17 00:39:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 773702 Delivered-To: patch@linaro.org Received: by 2002:a5d:4943:0:b0:33b:4db1:f5b3 with SMTP id r3csp206702wrs; Fri, 16 Feb 2024 16:41:03 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX6dndkCIvpumYqWXxJ7DAMMmTf01c9szN2/0NvwU0NcKRk1r7LJQ+SUtDllTp7OTvPSpoRc8DR8NlFOWV8jJL4 X-Google-Smtp-Source: AGHT+IFZWzBEeRx2lqGJ0qi92bsRHp6YCMpeEA6E9PLKwGeUyaJt5mFj4aXgadIvOOyWgd7JP+ay X-Received: by 2002:a05:622a:316:b0:42c:710a:2778 with SMTP id q22-20020a05622a031600b0042c710a2778mr7149330qtw.60.1708130463279; Fri, 16 Feb 2024 16:41:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708130463; cv=none; d=google.com; s=arc-20160816; b=Vnswf9jvsSQ8HGDSaDCGhN4JSnDf9eCjXZnZ8jA50t36AkeT44T1Wn4jno1/083vHF 8VHasfm4ZX0MbO9bQwXdeqXmnqElC+F6v5hMUBMVTUsXDzf2MOTUI+UIdyxM7WwDH5/9 bw7lzK9ui8U8Vru6a4ssXKYHD0hl3UN5YmFuCGu77EyhW3TAUjw1JEuZtyJMTCVfH0sW UPfRLy3Qz7g09eFmlVd2HkS1aTrlQcD35anQOXd+LXE1/JMYjGDaNjvu2tfDmM3VD65M Px4aHHYdM6fZQazIzQDZdKnw3WokHavZ1u97zpP2Jjej6y6eoRB0KuvYKxAtQmqDnoGs 0HXQ== 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=6+vMZHnTNPjSijzEPZ6pE1ZEQb70DOSnKuGgl762H28=; fh=bXD9UGo7d05OYjVg0qF2wA28p2gxs496M6ftxgeDKVY=; b=gLODUMsh+ddNAJFnvQKkCQrqgZgKykc4fc+cVopAxnyPePaGSeL9TmEm/9lswmEUQP iwQ7jCb41ltSC34Oz6Ob8GjYiE0cJ15Oo90gk2w61LEncfpKflv8O0f921FtOBSNhuT/ IX1rS7YDJ+hBsdimo+5AWtvjPFkGzfScjerryZRCV0egIc+i+tOV+jm4EUy7JvQbIqfI 6Q/irg/rZsPh/+iG8qjlNN+vn27vsgf2GLC/I67aoYlt4Ebe5hWIwr7I03CPclWF1U7p iKCKlormHEhSaCifmlgUwnk8SlbFP4n3A7KcrdcfbqAoQA52d/tRc4l0LU2mhgNHKnUX wZrw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pTpzVQ6K; 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 jr14-20020a05622a800e00b0042c44c065e6si978052qtb.733.2024.02.16.16.41.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Feb 2024 16:41:03 -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=pTpzVQ6K; 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 1rb8jy-000694-2Z; Fri, 16 Feb 2024 19:39:38 -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 1rb8jv-00068G-5c for qemu-devel@nongnu.org; Fri, 16 Feb 2024 19:39:35 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rb8jt-0008HG-HK for qemu-devel@nongnu.org; Fri, 16 Feb 2024 19:39:34 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1d73066880eso25546425ad.3 for ; Fri, 16 Feb 2024 16:39:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708130372; x=1708735172; 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=6+vMZHnTNPjSijzEPZ6pE1ZEQb70DOSnKuGgl762H28=; b=pTpzVQ6K1hAWblQycMsIJ7wnX4N4Upz/AKqBuk72pAFbryGG89nyBR0xK1Elglt7Kx by3MbFawWOvT6AEiSkCTCp77eZSFc7PphIeMCQLYuZLPAv4URWHxc4qFtAbraXr2gs4X Zi3Q07WZuZ6ikdrYrF+NGCdYhRv67ldooWzkHhGN0OcsTGpCTZH8Wd3iQ1q9W7N7O384 iYU7RYO1LWgLAbN6iL4R28YEaoFnhabh0q3FRBhpR8+vICywFoIaxMHuFNv+Vu5H5ayt OmmbWM9jXM7G7VjMQVZKEbZHenmsElanYEU+4Zsc04SNzxd9/RLxt3OnihUqtYBvvnFj tkvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708130372; x=1708735172; 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=6+vMZHnTNPjSijzEPZ6pE1ZEQb70DOSnKuGgl762H28=; b=AlDjFOttL2biPLkGqgIywmzqdpZuicJEo/TuoaBgMg/gabT/mrir7USEcAiJJA/x66 BGuuwRNSouuYTwgPs5W2a9WiAPEeV40ju1wh6BT57ohA5EU0B6LjYaAFlCNcOiCpO6ud GCk+7ta646/bO730tgxpy063WNw5ao1hPjFVqVo+EGa9YfSnfC2sO8Hn3LihhgUCeIPx lqn5FAQfRy+lG7rNXh6Sq8KUfzn9GWhS3JRhePsUTYkWv4VcjKQtG9yml8bIxBhs3frr pjuPu8xrrtugwZvEI+PdEjpNhZ3BFbpHr5PuEPH3ubOiw+w43Vzk61IdcEs7oy29WEC4 RCBQ== X-Gm-Message-State: AOJu0YxIyE+VUq9MloMFKTKxoLykp8c0/+ZQRA0rehXRfYEVqipfoXKb KeVqM+trklUUY6GFLO2lbCV2paTA7fwidM7MIivd4NcmLIsGqs70mm6pnPMB1VatvS+8btzI4u9 W X-Received: by 2002:a17:903:32c5:b0:1db:c348:60d8 with SMTP id i5-20020a17090332c500b001dbc34860d8mr1153996plr.23.1708130372163; Fri, 16 Feb 2024 16:39:32 -0800 (PST) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id z6-20020a170902ee0600b001d90306bdcfsm419325plb.65.2024.02.16.16.39.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:39:31 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: amonakov@ispras.ru, mmromanov@ispras.ru Subject: [PATCH v5 08/10] util/bufferiszero: Simplify test_buffer_is_zero_next_accel Date: Fri, 16 Feb 2024 14:39:16 -1000 Message-Id: <20240217003918.52229-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217003918.52229-1-richard.henderson@linaro.org> References: <20240217003918.52229-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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=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 61ea59d2e0..9b338f7be5 100644 --- a/util/bufferiszero.c +++ b/util/bufferiszero.c @@ -180,51 +180,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)