From patchwork Wed Apr 24 22:56:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 791549 Delivered-To: patch@linaro.org Received: by 2002:a5d:4884:0:b0:346:15ad:a2a with SMTP id g4csp1093288wrq; Wed, 24 Apr 2024 15:58:40 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUCVFhFP1c68cF0VknHEMtCJrQp1VynXsKVHMRfZg7pFj5sM+F/Gcu07ULoQQDS3vrsHKP61+7tKq+PyCrjsf89 X-Google-Smtp-Source: AGHT+IE766OHDuO2mgYED4Wt0uRCeldaWJZYeBVqem2gU2JUAS4cTAC+EZqU4k2b9yKnw/WdcNg+ X-Received: by 2002:ad4:4baf:0:b0:6a0:93c6:140e with SMTP id i15-20020ad44baf000000b006a093c6140emr1938522qvw.17.1713999520194; Wed, 24 Apr 2024 15:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713999520; cv=none; d=google.com; s=arc-20160816; b=UHss55PijqzVW/8TKV/7XvAsDHKti/ZGRMcrckCz8QGPeW2Q+mcLQqFL7MsVAaOeDM 5n7tRaD1lsA9UhQZAzh+DYltXYxLx9DwaWGG01dbfx26K7YgfCE2MKSl98nuSSWp2nYa Jxc0qqxS/UuWjL6Nm0UCmRPKeFJE+Xc6QyCX4HciUdHT8/8oz8/36KlGUAaUx+Tn9csk QUUf3osAUwToPzoQdEt3GcMtz5grzUXPCohxwW1mEepX2axmhn5ozgV4/IiB7jMwwAN6 DRfqKtVjurZR9kbJ8DaEfAmV3fgfSNk89rENMiOWwfkKmhSRno8TuLwJXYnGXHYkObxa EplA== 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=IOfZmL/4G2LGBtSV+LzySu7eotL7HJ1AQcRx3etIBXU=; b=lpn3Dm8NN4oYwVgUomo3bT3m4acOsS2FP4pvwCbUdlXFJTAdVvcZFptiovdDZulUuP 7pZvKtAXRFi4v1at0TyBYVANmI6Q7X1ryt5vqmuLP+HdNCH5YjfD/FLx3jorESGzNiHe XYE5clBwNWm+mibS1i9qx/T8jLNqOLkXPJEzfxt8vU+5SQtHv7lHqaeky0px6WrgFaB5 m6vw5JvXfNh6DdW3SKNCcj5tFQ+BJPrW6V3qufOGAeURG4li/ncbYQXhsZ60oOFuIlwL obyhvEB2SiGhPwotydXFAHOtP5UjHABOzYC0ONhzZKSlNkxgMYIkOJPsByQfwyZNe5wl B3PQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EkzqbIs1; 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 kd7-20020a056214400700b006a09fce11casi58106qvb.579.2024.04.24.15.58.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2024 15:58:40 -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=EkzqbIs1; 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 1rzlYA-0005Nz-PH; Wed, 24 Apr 2024 18:57:14 -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 1rzlY8-0005N7-SG for qemu-devel@nongnu.org; Wed, 24 Apr 2024 18:57:12 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rzlY6-0001lm-OJ for qemu-devel@nongnu.org; Wed, 24 Apr 2024 18:57:12 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6ee12766586so385432b3a.0 for ; Wed, 24 Apr 2024 15:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713999429; x=1714604229; 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=EkzqbIs1QpxUNxSBX+DIvfTyj+AW5b4wyB5AC9aCD+AGm5Vq7uFtpaY8ymDmZPISxH n//9vISUaPvSMyOpYXqkbHRDun4+7yi9DYLRGFGVtWABhmxDaJkY1wuwF1LXt5HgJfGu eDRUnLIOR45pohQwwSYrXozAMmuONGbRGllZWpQWYOaoq765AqeXm1S9OzRT4VDXi3GR M6rG/o1xxE6n8gGyLSY40O+MEbTg4LHHfOxQsyda7y0pzPGEU+auVrcB1uw5DzDOqYum nhAFXrqbcYGeslDTwJssCbc23VLel/ekXN8Di440eAhAykxfsdUk7FE3Z1bjA/ptrKkp edHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713999429; x=1714604229; 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=rcWd4j2FbHdGj7UdoqgxkRwoyFzqk5YeppuhnmFQxC0lo5r8kOtEVDHgjQcYT6QLgz 1RRuD7NK/q8mHZ1u1LwuAWU9wVp2AfdiX2DZ+WRtoiiL+xK+yhjcsAPVrwE2/nXDxjo4 HoOhknOTdfZw8IWmS7e29yimDH8fkr+HjcTF/DtkFjEyi4ke9/IQ+6ngfOpJioRxYEQk sVGgDmLPZSaFPyK4xaYaBidncijrOouSwV9CieVDelBGjYUk20Qc1nvNLG5Kqe0cV4qr HO+rb5Z09PgrZ7AmRTvz9eJQZ9aRhR5g45Zi4CnP4pdK79fuUXwpIeUAmSTh4mND0GCS YHUg== X-Gm-Message-State: AOJu0YzYUji6IUNVfk6Iu71wvdfLmh2jP+SkzqOspMYuCFvf05jGiru5 iseVSKKUpfB0VpwAHFPmueOcKD3ohP7CoefKzHfyfRBkd6LtaXkXDQIhpzoNNC2ZCssxTrZI3lN u X-Received: by 2002:a05:6a00:992:b0:6ea:f3fb:26fe with SMTP id u18-20020a056a00099200b006eaf3fb26femr1698891pfg.12.1713999429116; Wed, 24 Apr 2024 15:57:09 -0700 (PDT) Received: from stoup.. ([156.19.246.23]) by smtp.gmail.com with ESMTPSA id gu26-20020a056a004e5a00b006ed9760b815sm11947413pfb.211.2024.04.24.15.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 15:57:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Alexander Monakov , Mikhail Romanov Subject: [PATCH v6 02/10] util/bufferiszero: Remove AVX512 variant Date: Wed, 24 Apr 2024 15:56:57 -0700 Message-Id: <20240424225705.929812-3-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=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.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 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());