From patchwork Sat Feb 17 00:39:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 773704 Delivered-To: patch@linaro.org Received: by 2002:a5d:4943:0:b0:33b:4db1:f5b3 with SMTP id r3csp206715wrs; Fri, 16 Feb 2024 16:41:09 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUtXx93N4S7PxRfXOjuJYXzTb1ETlItsRBHn0H7UdKw0K40vUS4mAY8xLnEa6qPhrERP0yuXyeMHXRCRe1Y9afH X-Google-Smtp-Source: AGHT+IG8HKyGsCadDeM/d9aKM9D/eHYz4dG9zdP9eQeqGfVllHQWgrWS1VzSvuZ1ncVBngLqfsGQ X-Received: by 2002:a05:6808:15a7:b0:3c1:4a3e:bfd0 with SMTP id t39-20020a05680815a700b003c14a3ebfd0mr689167oiw.10.1708130468901; Fri, 16 Feb 2024 16:41:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708130468; cv=none; d=google.com; s=arc-20160816; b=HhLZ8H7+YTYkNdR4pUDoE/YxxpfNzsKoZ1QdjEuZGXGkcQ+7JM1zLI00MPQIoR8xEG JoUQul/ibH3gADVfY07ERZC3pOWaFYdNx7Ya+pD/M7jKFlDgyW38F2vZuOQr/11j0SsH IfAJaYaavqyzd+XDt+dbXTI4oyV29+u/eb/tQqjqhOJoBtTJCQHAXKsaXq/8UpZu5Ipu BOR1no+sCNNs2RNh9dkMtL2Q4CD7elb0SSQT+GQozeZKAZHPtohNws6DmWNQMSkvP8NA q7Zg+BSTHydfwLTJ6gERInejV5qZlI+fSgK1mH+P0jShaQe8O2ECNMPSd54GWZH9LVt2 Lc/A== 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=Sc6Au+pExfgVbkEVt3xBcrgjk6DJCZWLxXzjjgNJTcI=; fh=bXD9UGo7d05OYjVg0qF2wA28p2gxs496M6ftxgeDKVY=; b=kgIpiJGMfljc/1sWPPyNC/Bfi4PNK8XzAJF2CX9TRViSDIfyRn8OqOfMfRh4H7+vqk vo2+tVE8dCEpE/3Fjf+pgGylPquIf76Bx9e44BacBNDiIFtr9s4pLH4JPPuMP7yOuLiq F8/UAxtF/j5QzPXwy0hm96tkCt6t024LMXON8dUUEl+0gCbPlp/oGwA4sxPSK98vKhyo IkH5IZ9NyhLHvVDbyqGeaq8MpN/roEyAL8EfruvZiIZJUxGlON8KiUXhF5Lk9iCnr3ow 329JuHrvpcoyCqk1BcEy9XdWqZhBMUyWdljfFiahEfuoTrlp74QFk/mHYvazZhdKXguH fBog==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PsmPtOjw; 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 t2-20020a05621421a200b0068ccc9a313csi917285qvc.606.2024.02.16.16.41.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Feb 2024 16:41:08 -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=PsmPtOjw; 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 1rb8jp-00064g-6t; Fri, 16 Feb 2024 19:39:29 -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 1rb8jn-00063x-Ld for qemu-devel@nongnu.org; Fri, 16 Feb 2024 19:39:27 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rb8jl-0008FM-E0 for qemu-devel@nongnu.org; Fri, 16 Feb 2024 19:39:27 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1d953fa3286so11474115ad.2 for ; Fri, 16 Feb 2024 16:39:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708130364; x=1708735164; 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=Sc6Au+pExfgVbkEVt3xBcrgjk6DJCZWLxXzjjgNJTcI=; b=PsmPtOjwIOUa0GBrFYzxy0RmwnLHQaK2UN5QIV+4QaMnBXDFOaDouihhHYDvn7UOBz 8plMNwvieI+/46Qlpa/Fe3Ag6drshE94ewgH1ofo9rCLiEQpb3N7j/2M7+xQr05711UA jSCSouLYdwviT2LJ+DdL7WLJnF8vwkb6C/+dhLWZYjIRpizrLJpmj/+jEgw6oCvKPpcq O4pNb1grhHkgknhyO/UEb9lqCCe6WX0/cTOrhssC4FdgR/biIXDg0YJo100NVY+0W3IY K+P5usF6ROlgUiEoLLUdUCEXbk2a5yX9++rvxwLYaQ3QVrB+LupMvIVBf8+9VQmj1uyM +alA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708130364; x=1708735164; 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=Sc6Au+pExfgVbkEVt3xBcrgjk6DJCZWLxXzjjgNJTcI=; b=bXUUKA4duaW/mJQU9j8kjX3JUy9zqTI/lwhAYX73CkiwvGOjHmXXA6su5e2ftDBoKf BIqvViCv69RD42ahSWBhAOGtdTXKhWMIdQ4+tS09o45jWN6aNBGH0cqUZseQzYPTXCS8 gazNcdIln4dvdj8rUGOy3ZQ2vpMx+31fNUm9KXozD4kYlepyxhajZ9bwbWxa/V+4Hx2S VIXXNu6qi860Pli3RsFFijgfAGnhGPFI8VumP2voMTPrMlrpdMQDSkP5l3rJUTBS1v0c TZZvJ5GaqTEt3xT090itXjs74bBSqWfow31TcGABNhvlvAmNp7sLGupvH+kMf/rImVaU IqJg== X-Gm-Message-State: AOJu0YwvGTOuQn6DBpbGqIr+rhrR8x2ltfd79h5eYGnJGu8arwuOC1gH ys89fkenr3U8LT8fMHaqIXKDoMJDXvnLRW5HTQz4hiiSbxRySRq+ZYr5u0NZyilrdV/AgQqSgXT U X-Received: by 2002:a17:902:c944:b0:1db:c1a3:7d59 with SMTP id i4-20020a170902c94400b001dbc1a37d59mr1228054pla.9.1708130364123; Fri, 16 Feb 2024 16:39:24 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:39:23 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: amonakov@ispras.ru, mmromanov@ispras.ru Subject: [PATCH v5 02/10] util/bufferiszero: Remove AVX512 variant Date: Fri, 16 Feb 2024 14:39:10 -1000 Message-Id: <20240217003918.52229-3-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::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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 From: Alexander Monakov Thanks to early checks in the inline buffer_is_zero wrapper, the SIMD routines are invoked much more rarely in normal use when most buffers are non-zero. This makes use of AVX512 unprofitable, as it incurs extra frequency and voltage transition periods during which the CPU operates at reduced performance, as described in https://travisdowns.github.io/blog/2020/01/17/avxfreq1.html Signed-off-by: Mikhail Romanov Signed-off-by: Alexander Monakov Reviewed-by: Richard Henderson Message-Id: <20240206204809.9859-4-amonakov@ispras.ru> Signed-off-by: Richard Henderson --- util/bufferiszero.c | 38 +++----------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/util/bufferiszero.c b/util/bufferiszero.c index f5a3634f9a..641d5f9b9e 100644 --- a/util/bufferiszero.c +++ b/util/bufferiszero.c @@ -64,7 +64,7 @@ buffer_zero_int(const void *buf, size_t len) } } -#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) || defined(__SSE2__) +#if defined(CONFIG_AVX2_OPT) || defined(__SSE2__) #include /* Note that each of these vectorized functions require len >= 64. */ @@ -128,41 +128,12 @@ buffer_zero_avx2(const void *buf, size_t len) } #endif /* CONFIG_AVX2_OPT */ -#ifdef CONFIG_AVX512F_OPT -static bool __attribute__((target("avx512f"))) -buffer_zero_avx512(const void *buf, size_t len) -{ - /* Begin with an unaligned head of 64 bytes. */ - __m512i t = _mm512_loadu_si512(buf); - __m512i *p = (__m512i *)(((uintptr_t)buf + 5 * 64) & -64); - __m512i *e = (__m512i *)(((uintptr_t)buf + len) & -64); - - /* Loop over 64-byte aligned blocks of 256. */ - while (p <= e) { - __builtin_prefetch(p); - if (unlikely(_mm512_test_epi64_mask(t, t))) { - return false; - } - t = p[-4] | p[-3] | p[-2] | p[-1]; - p += 4; - } - - t |= _mm512_loadu_si512(buf + len - 4 * 64); - t |= _mm512_loadu_si512(buf + len - 3 * 64); - t |= _mm512_loadu_si512(buf + len - 2 * 64); - t |= _mm512_loadu_si512(buf + len - 1 * 64); - - return !_mm512_test_epi64_mask(t, t); - -} -#endif /* CONFIG_AVX512F_OPT */ - /* * Make sure that these variables are appropriately initialized when * SSE2 is enabled on the compiler command-line, but the compiler is * too old to support CONFIG_AVX2_OPT. */ -#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) +#if defined(CONFIG_AVX2_OPT) # define INIT_USED 0 # define INIT_LENGTH 0 # define INIT_ACCEL buffer_zero_int @@ -188,9 +159,6 @@ select_accel_cpuinfo(unsigned info) unsigned len; bool (*fn)(const void *, size_t); } all[] = { -#ifdef CONFIG_AVX512F_OPT - { CPUINFO_AVX512F, 256, buffer_zero_avx512 }, -#endif #ifdef CONFIG_AVX2_OPT { CPUINFO_AVX2, 128, buffer_zero_avx2 }, #endif @@ -208,7 +176,7 @@ select_accel_cpuinfo(unsigned info) return 0; } -#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) +#if defined(CONFIG_AVX2_OPT) static void __attribute__((constructor)) init_accel(void) { used_accel = select_accel_cpuinfo(cpuinfo_init());