From patchwork Sun Dec 4 01:51:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 630860 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp1780592pvb; Sat, 3 Dec 2022 17:52:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf6nari1h37lU4X/BPjD2YvPkpZA3iQBXPC9SRGs0gh/rxkono1MFrrfqvSyKuMwj7YDwpcz X-Received: by 2002:a05:620a:13f5:b0:6fc:a9ef:f5e9 with SMTP id h21-20020a05620a13f500b006fca9eff5e9mr10840701qkl.18.1670118754877; Sat, 03 Dec 2022 17:52:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670118754; cv=none; d=google.com; s=arc-20160816; b=orxwkPRGhCNGZcKBr6XEtAQNf2a4sbLOMzaUtb22D6rnFl0tlyD6X+cs8ReP/dNsZ3 DQTS/ryLgh3cMVpm/jEnbi2rAtWnbp/BSGGhxJ/Hk1eQZgOtphLgB1yDQGVfDzLOfVjO u2lj+Ib1GLXIlhK1o2hH4yHUHBTCTcj0TZPfH3u6vqjRjpwIhYPJohZtlsar2T/+pW3p Ck7SPsgdiP/fecvT8bSIxU5Nv8sOO5P0DS41q9bWWLOb7vy6CrJYE0RGbROzsuCX3YiI m5BSvu53d9vdwMYqhwN77pIdppSDpxr5Nbh93e8zT4ydBK9n/4lJcgTmeVNbAIxvrp1j 6x/Q== 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=9u/Uw0Ie39D5553Yw1gw6awZ7nIzmtrFVt1jBUP4Idk=; b=MbaKulDTe19tTLc2J4ucHUzNV8PiXTffqmJSXmj13ZGmd/vblrMsv1AxV8G+Zjl1IN L9h5FfAasOTREcrlr8vSoCeZ0a0Uii91vEnhWlqBj71Xt0nfeGYINZ6Kz6T2nkL9utHt not45DXoH1b0ZvjieUX0ZvjeeruyAday4rleOiTG/1hnGDisugJxBqpKWCeBgATuyef8 bqIr4WklbXlSNNK8grKJ65CzOfTlTv+yXlG5yFabpjaTFNOUq6xicA3VCWVY5QednAED P75ZHM8gr5VdRw+9JnJyUbvkPs4+qIOJ2nB4jyPzSlHzlZdEvveY+TNhfx7KzOc7tQWH 7/Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GwyGbZT8; 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 fb19-20020a05622a481300b0039cbebbeabfsi6562077qtb.283.2022.12.03.17.52.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 03 Dec 2022 17:52:34 -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=GwyGbZT8; 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 1p1eAJ-0001ZT-DB; Sat, 03 Dec 2022 20:51:35 -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 1p1eAH-0001YP-HP for qemu-devel@nongnu.org; Sat, 03 Dec 2022 20:51:33 -0500 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p1eAC-0006o0-B7 for qemu-devel@nongnu.org; Sat, 03 Dec 2022 20:51:33 -0500 Received: by mail-oi1-x22d.google.com with SMTP id c129so9349248oia.0 for ; Sat, 03 Dec 2022 17:51:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=9u/Uw0Ie39D5553Yw1gw6awZ7nIzmtrFVt1jBUP4Idk=; b=GwyGbZT8GMyvoj87AhyMO7u2kmw47u0gdfg6Hr4MwMAzlHjtZul7h/8oMeWiasRGyC 5D02yx8Ma/mJoXTT8jYoHf89GqADv82ss987/VcGzTsYHWUDa6efoLKUU70pYu72PkHw 3Ms4ctJjdxTW7O0ax0ZBfaRLEhGe5BUYjrcXPX2sAHm4cYGW/nqSrkna5T1rTfs12XqA YNfXaH9xn1LNHHcyolZryZgD2H9AmwNCt9tkSuwVqBzLNxItnrnJhyV2DEkQeW6SFpIE i0vWapJrlgRpW7rBTIrYjeHAGNqPbUauvHTEx16OoVful0fD2ECdOyCIlswh332fbsVn pEfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=9u/Uw0Ie39D5553Yw1gw6awZ7nIzmtrFVt1jBUP4Idk=; b=nNkuvSgdgr0SwOtRkRtqgCVHd6vQDsq/9XA0UutXhRQ9cxijzakp5k5+hngy/YH4Ci bPGUoIE4cVFT63xBqt7ha8UfyYu1WTT3kz0dMnQ3O5GYgEc94++aIXP1e3nAkMzqsc8E wTSIKo0fgy1eagTKUQsWQjUJ/l+2okPxmzxJsrk18taEQSWkX3mtrCmooozeSgOWc0Wk ncSgf1vtv1L+FCVsIYJ3Q2Av6SveHkG8EWR5JlJFMMj6h1ZwQ+DHpF5G8wnbTK+ENb+e BlgQ0TiaTSclZSRCuinx09y2CIXkM3EsNmSksHwPY/G3bN93LN0NHUQCtS0j5un2Hcp2 0kbw== X-Gm-Message-State: ANoB5pkDqf98sFPdmSe3DoLT3L7wX0IaGsbL3+NXTKdaTXHgt6JVgNq0 9nNXxU2f7mP+HZVMVVPnDuvHD2pqCcb9QaqWCTY= X-Received: by 2002:a05:6808:170d:b0:35a:757a:ef9d with SMTP id bc13-20020a056808170d00b0035a757aef9dmr36816882oib.121.1670118686952; Sat, 03 Dec 2022 17:51:26 -0800 (PST) Received: from stoup.. ([2806:102e:18:70b5:6b63:a06c:99b3:833]) by smtp.gmail.com with ESMTPSA id e16-20020aca2310000000b003436fa2c23bsm4964215oie.7.2022.12.03.17.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Dec 2022 17:51:26 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, tstellar@redhat.com, berrange@redhat.com Subject: [PATCH 1/2] util/bufferiszero: Use __attribute__((target)) for avx2/avx512 Date: Sat, 3 Dec 2022 19:51:22 -0600 Message-Id: <20221204015123.362726-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221204015123.362726-1-richard.henderson@linaro.org> References: <20221204015123.362726-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22d; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22d.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 Use the attribute, which is supported by clang, instead of the #pragma, which is not supported and, for some reason, also not detected by the meson probe, so we fail by -Werror. Signed-off-by: Richard Henderson --- meson.build | 8 ++------ util/bufferiszero.c | 41 ++++++----------------------------------- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/meson.build b/meson.build index 5c6b5a1c75..11b873f911 100644 --- a/meson.build +++ b/meson.build @@ -2324,11 +2324,9 @@ config_host_data.set('CONFIG_CPUID_H', have_cpuid_h) config_host_data.set('CONFIG_AVX2_OPT', get_option('avx2') \ .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX2') \ .require(cc.links(''' - #pragma GCC push_options - #pragma GCC target("avx2") #include #include - static int bar(void *a) { + static int __attribute__((target("avx2"))) bar(void *a) { __m256i x = *(__m256i *)a; return _mm256_testz_si256(x, x); } @@ -2338,11 +2336,9 @@ config_host_data.set('CONFIG_AVX2_OPT', get_option('avx2') \ config_host_data.set('CONFIG_AVX512F_OPT', get_option('avx512f') \ .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX512F') \ .require(cc.links(''' - #pragma GCC push_options - #pragma GCC target("avx512f") #include #include - static int bar(void *a) { + static int __attribute__((target("avx512f"))) bar(void *a) { __m512i x = *(__m512i *)a; return _mm512_test_epi64_mask(x, x); } diff --git a/util/bufferiszero.c b/util/bufferiszero.c index ec3cd4ca15..1790ded7d4 100644 --- a/util/bufferiszero.c +++ b/util/bufferiszero.c @@ -64,18 +64,11 @@ buffer_zero_int(const void *buf, size_t len) } #if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) || defined(__SSE2__) -/* Do not use push_options pragmas unnecessarily, because clang - * does not support them. - */ -#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) -#pragma GCC push_options -#pragma GCC target("sse2") -#endif -#include +#include /* Note that each of these vectorized functions require len >= 64. */ -static bool +static bool __attribute__((target("sse2"))) buffer_zero_sse2(const void *buf, size_t len) { __m128i t = _mm_loadu_si128(buf); @@ -104,20 +97,9 @@ buffer_zero_sse2(const void *buf, size_t len) return _mm_movemask_epi8(_mm_cmpeq_epi8(t, zero)) == 0xFFFF; } -#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) -#pragma GCC pop_options -#endif #ifdef CONFIG_AVX2_OPT -/* Note that due to restrictions/bugs wrt __builtin functions in gcc <= 4.8, - * the includes have to be within the corresponding push_options region, and - * therefore the regions themselves have to be ordered with increasing ISA. - */ -#pragma GCC push_options -#pragma GCC target("sse4") -#include - -static bool +static bool __attribute__((target("sse4"))) buffer_zero_sse4(const void *buf, size_t len) { __m128i t = _mm_loadu_si128(buf); @@ -145,12 +127,7 @@ buffer_zero_sse4(const void *buf, size_t len) return _mm_testz_si128(t, t); } -#pragma GCC pop_options -#pragma GCC push_options -#pragma GCC target("avx2") -#include - -static bool +static bool __attribute__((target("avx2"))) buffer_zero_avx2(const void *buf, size_t len) { /* Begin with an unaligned head of 32 bytes. */ @@ -176,15 +153,10 @@ buffer_zero_avx2(const void *buf, size_t len) return _mm256_testz_si256(t, t); } -#pragma GCC pop_options #endif /* CONFIG_AVX2_OPT */ #ifdef CONFIG_AVX512F_OPT -#pragma GCC push_options -#pragma GCC target("avx512f") -#include - -static bool +static bool __attribute__((target("avx512f"))) buffer_zero_avx512(const void *buf, size_t len) { /* Begin with an unaligned head of 64 bytes. */ @@ -210,8 +182,7 @@ buffer_zero_avx512(const void *buf, size_t len) return !_mm512_test_epi64_mask(t, t); } -#pragma GCC pop_options -#endif +#endif /* CONFIG_AVX512F_OPT */ /* Note that for test_buffer_is_zero_next_accel, the most preferred