From nobody Mon Apr 29 12:01:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1595464168; cv=none; d=zohomail.com; s=zohoarc; b=laaFyYr3q5+3sBuUS+1JlvYO2AZ4opW0qymnWIvGlnvaIhtMapTucwEORpd92WIVcC24Ptoiv746C2BvP0gHHdFk3lYUAaMUQltlb+G5uHPwGi2ACgY1b0QYqD3WVNA1vXKOgzCZNWGcdWiVSZqLYF5KYyQfHjWRo46g0V95X20= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595464168; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sCOftwdnsJ6da9H2SVH18et2O50tZ5Rzg9ttJkK+/9I=; b=cnhuQ0pG/54PMMHGXFffGlm1qTDtg+dMOhICzMQrbO2uzN0/FrGd9CzhypX4JB03H/3zPu1VCsiMZTobB2uHT33OHmHAJWWm5ooDZ9sFgKf2IGR0/PB3qVTEJFKqk10pi3nyjwqCr4PUxt682rY/EWdropQy2QHA6tAuom6TyC8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595464168035719.1740220747201; Wed, 22 Jul 2020 17:29:28 -0700 (PDT) Received: from localhost ([::1]:53320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyP70-0003va-OM for importer@patchew.org; Wed, 22 Jul 2020 20:29:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3XdkYXwMKCnIiSmWeeWbU.SecgUck-TUlUbdedWdk.ehW@flex--scw.bounces.google.com>) id 1jyP4r-0001i5-0x for qemu-devel@nongnu.org; Wed, 22 Jul 2020 20:27:13 -0400 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]:54448) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3XdkYXwMKCnIiSmWeeWbU.SecgUck-TUlUbdedWdk.ehW@flex--scw.bounces.google.com>) id 1jyP4p-00035U-Dv for qemu-devel@nongnu.org; Wed, 22 Jul 2020 20:27:12 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id p22so4475462ybg.21 for ; Wed, 22 Jul 2020 17:27:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=sCOftwdnsJ6da9H2SVH18et2O50tZ5Rzg9ttJkK+/9I=; b=kXUJEkw8+OjdOAqCX7Qg80IJeQT41lu2DILBcQHueAtEyIiIO+JC9VcXyz6idzC6kU y7DRnOp5x/imhvipbdHJ3M/mpDsZokXhH8PoUMVOsMyW/txeeu/hAHI4Q1LOnKz9xE80 cpTZMS2JJkgCqetGS/8vWFMRsxyLfosLD50a+hJn6C2f+0TQpmjJmir80hCkBdQi6lu2 6QO65gKax9fm0IwkFekOLfK+5ZeCEp0EPG6CQQ+voZyG2ZT0ybg1fY1kqSmAUbaVQFyw BHhqKAWquTxHjuBL/5VhiAvpYT6+dqQWw58f3d145FnkX/tzhEMWQ3LQteScMTSLpIxv 2Ykg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=sCOftwdnsJ6da9H2SVH18et2O50tZ5Rzg9ttJkK+/9I=; b=uczYfY2PaF8g2c1/ujSOHQKVgGZ69EMfED+XpUmI0TyVOTOUDUHnnlplMU922pzkkB +3cXBjoCtanW22C4ePEB9yt2pbfjhvhkUylU2kjfbNln++r9CgsOFL385u7l40Al95nI HEctvWY7RCXC4t0302L6dxn6xBpNNs7Qrn4xIliN5CbCBrm0ooTf23UFu5AXOdzbRi6M OT1j4CWLISmDp/4excxvoPz/7AacVL7leLJXyVgKnKIiPF0ggNmpqhwbx5lBPwL/D9Dx 3sehH0E90cTZQ8YwjxW1OiYoHLa2RaeOM61pYw/V18td9O0yz2TAPggyApKCvGkzMHZB 0LMA== X-Gm-Message-State: AOAM530q185827yfcI2oJf6JcJhZ1Ja7/wonRcywqOwfTHB2hxdjodeo zsHN4nVqhE6f8VV8R3ww2nxuWEI= X-Google-Smtp-Source: ABdhPJwkjhNqCkLPCALkltPyMGelbhaXcQCxMo4fB5Frc3Dk+AGf9EnCaB8IYyguKmJfN6nB1P3WLbE= X-Received: by 2002:a25:e708:: with SMTP id e8mr3226850ybh.137.1595464029847; Wed, 22 Jul 2020 17:27:09 -0700 (PDT) Date: Wed, 22 Jul 2020 17:27:04 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog Subject: [PATCH 1/2] configure: avx2 and avx512f detection for clang From: Shu-Chun Weng To: rth@twiddle.net Cc: Shu-Chun Weng , qemu-devel@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::b4a; envelope-from=3XdkYXwMKCnIiSmWeeWbU.SecgUck-TUlUbdedWdk.ehW@flex--scw.bounces.google.com; helo=mail-yb1-xb4a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -105 X-Spam_score: -10.6 X-Spam_bar: ---------- X-Spam_report: (-10.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-1, 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, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @google.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since clang does not support "#pragma GCC", the instruction sets are always disabled. In this change, we 1. wrap "#pragma GCC" inside "#ifndef __clang__", 2. only retain them around "#include <{e,i,s}mmintrin.h>" to work around gcc bug, 3. and annotate each function with `__attribute__((target(*)))` which is recognized by both gcc and clang. Signed-off-by: Shu-Chun Weng --- configure | 16 ++++++++++++++-- util/bufferiszero.c | 33 +++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/configure b/configure index 4bd80ed507..d9ce3aa5db 100755 --- a/configure +++ b/configure @@ -5808,10 +5808,16 @@ fi =20 if test "$cpuid_h" =3D "yes" && test "$avx2_opt" !=3D "no"; then cat > $TMPC << EOF +#include +#ifndef __clang__ #pragma GCC push_options #pragma GCC target("avx2") -#include +#endif #include +#ifndef __clang__ +#pragma GCC pop_options +#endif +__attribute__((target("avx2"))) static int bar(void *a) { __m256i x =3D *(__m256i *)a; return _mm256_testz_si256(x, x); @@ -5835,10 +5841,16 @@ fi =20 if test "$cpuid_h" =3D "yes" && test "$avx512f_opt" =3D "yes"; then cat > $TMPC << EOF +#include +#ifndef __clang__ #pragma GCC push_options #pragma GCC target("avx512f") -#include +#endif #include +#ifndef __clang__ +#pragma GCC pop_options +#endif +__attribute__((target("avx512f"))) static int bar(void *a) { __m512i x =3D *(__m512i *)a; return _mm512_test_epi64_mask(x, x); diff --git a/util/bufferiszero.c b/util/bufferiszero.c index 695bb4ce28..ca836b6e8c 100644 --- a/util/bufferiszero.c +++ b/util/bufferiszero.c @@ -64,17 +64,18 @@ buffer_zero_int(const void *buf, size_t len) } =20 #if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) || defined(__S= SE2__) -/* Do not use push_options pragmas unnecessarily, because clang - * does not support them. - */ -#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) +#ifndef __clang__ #pragma GCC push_options #pragma GCC target("sse2") #endif #include +#ifndef __clang__ +#pragma GCC pop_options +#endif =20 /* Note that each of these vectorized functions require len >=3D 64. */ =20 +__attribute__((target("sse2"))) static bool buffer_zero_sse2(const void *buf, size_t len) { @@ -104,19 +105,22 @@ buffer_zero_sse2(const void *buf, size_t len) =20 return _mm_movemask_epi8(_mm_cmpeq_epi8(t, zero)) =3D=3D 0xFFFF; } -#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) -#pragma GCC pop_options -#endif =20 #ifdef CONFIG_AVX2_OPT /* Note that due to restrictions/bugs wrt __builtin functions in gcc <=3D = 4.8, * the includes have to be within the corresponding push_options region, a= nd * therefore the regions themselves have to be ordered with increasing ISA. */ +#ifndef __clang__ #pragma GCC push_options #pragma GCC target("sse4") +#endif #include +#ifndef __clang__ +#pragma GCC pop_options +#endif =20 +__attribute__((target("sse4"))) static bool buffer_zero_sse4(const void *buf, size_t len) { @@ -145,11 +149,16 @@ buffer_zero_sse4(const void *buf, size_t len) return _mm_testz_si128(t, t); } =20 -#pragma GCC pop_options +#ifndef __clang__ #pragma GCC push_options #pragma GCC target("avx2") +#endif #include +#ifndef __clang__ +#pragma GCC pop_options +#endif =20 +__attribute__((target("avx2"))) static bool buffer_zero_avx2(const void *buf, size_t len) { @@ -176,14 +185,19 @@ buffer_zero_avx2(const void *buf, size_t len) =20 return _mm256_testz_si256(t, t); } -#pragma GCC pop_options #endif /* CONFIG_AVX2_OPT */ =20 #ifdef CONFIG_AVX512F_OPT +#ifndef __clang__ #pragma GCC push_options #pragma GCC target("avx512f") +#endif #include +#ifndef __clang__ +#pragma GCC pop_options +#endif =20 +__attribute__((target("avx512f"))) static bool buffer_zero_avx512(const void *buf, size_t len) { @@ -210,7 +224,6 @@ buffer_zero_avx512(const void *buf, size_t len) return !_mm512_test_epi64_mask(t, t); =20 } -#pragma GCC pop_options #endif =20 =20 --=20 2.28.0.rc0.105.gf9edc3c819-goog From nobody Mon Apr 29 12:01:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1595464100; cv=none; d=zohomail.com; s=zohoarc; b=jef6KbfloAGzw6o6gl/yRGUztYUU6keezFgc2H4mweEwCimwU/XRlTWY1sxXV2UeYYK8KupUyhMjncXnWMXOZVhNkIBorRNMPd/svILkJJp7n8j8EDFIjaeATAIrpz4FKgfARZ+wJbwqF10ZMlKfPXPoRUYghum4Q8OgcH1bL6A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595464100; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I4PnbRt4YsoZkPIh8NPwRmvs8OJi++5TzHmGoc+l+rk=; b=C3+PRGFHv6dMexIYjxPIdJvTbdMy9JrbLScyNnHifJhZBTE9vYo0VOFj06SoPbczIDSXzuy4Rk4lNIUvUds4NzEVEap2ZF/NomVq5Aj9aQaOWSuyOrD4pAPJY5x5ErcxsCizSZT6ZUic+KVF+pLNGITeKrogV7jGfItN1BYw+kE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595464100978589.3457712873121; Wed, 22 Jul 2020 17:28:20 -0700 (PDT) Received: from localhost ([::1]:50160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyP5v-0002c3-P4 for importer@patchew.org; Wed, 22 Jul 2020 20:28:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3X9kYXwMKCnQkUoYggYdW.UgeiWem-VWnWdfgfYfm.gjY@flex--scw.bounces.google.com>) id 1jyP4t-0001jK-6Q for qemu-devel@nongnu.org; Wed, 22 Jul 2020 20:27:15 -0400 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]:54448) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3X9kYXwMKCnQkUoYggYdW.UgeiWem-VWnWdfgfYfm.gjY@flex--scw.bounces.google.com>) id 1jyP4r-00035c-8t for qemu-devel@nongnu.org; Wed, 22 Jul 2020 20:27:14 -0400 Received: by mail-yb1-xb49.google.com with SMTP id p22so4475554ybg.21 for ; Wed, 22 Jul 2020 17:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=I4PnbRt4YsoZkPIh8NPwRmvs8OJi++5TzHmGoc+l+rk=; b=O14NoHKM7RNc8GRET8tQBYDYwjgt9kzNdN9VpymlTFGYJ4AcYplcSwEX7O+G6ZfceE hSAwYJGhRBl0DrARa4Fr6F3Hqpin58AfDcuKxpyKJRRzfHyf5D++rO0H+/WM2Qo/vSMN T5EjwYLBulpfo9jQE+U5j2fBYNVKsBRC5p9nNmey53Tp1dPQ2kcVL+2GHx+bB7pobVFG mq7eWrCZe/jOc00grAkQmyL+vmWL7rlP07YXSgztjOSvC6iRiiHXW6oEg1lCfYZ/Enp7 34S+wveu6njLQ3N6fJ1qwrnqv3zVRL8SA3yM6aPU7ZDpmjekhweCQk41U/Ih2vzKfgiJ 1iyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=I4PnbRt4YsoZkPIh8NPwRmvs8OJi++5TzHmGoc+l+rk=; b=QCbpqPe5QsfcZeptgSRAWmraCyRPhAL5HWh84S0n4qd9nPclKCcpqCfkuF+/un7zxw C7xrYuKjPLRDEEP/jbPQFy8DdU27kdZDQeSzjapMDCt75Crnq5Kedv3zREUWsV4+84aW 7bMCXy+uXD6hEJCaPV7OBWRAoYJUia8fnQyFIgfX+0kt0hGbDoe005yT8tq//qB+aY0w jUqbQZBqhERMAbOYMrwONewZHApKv1GMNK/f6AlJpr60grgEfOThJnQhH+TdQc3twSHL +cKIrEYmMDAp8wmRVZHWWjOmxCY4CHzhGHz9PznTfALop6xaHNC/vjPdAYq3o2RdUnIo hqVw== X-Gm-Message-State: AOAM530THmyG0VUmUgMtbPLlYux9reb96zeH3TYgFOaOoiLh1Q/j2IRq nUBI08eRTr6NuoOgdc9bxru82dc= X-Google-Smtp-Source: ABdhPJyVg5i641YrhniPoZ4h9L2oBrGQFJGWdne6EoH2hZx2YPA3aH1WHLFkYmCfAmSJC26hZVNvJPg= X-Received: by 2002:a25:3789:: with SMTP id e131mr3048610yba.417.1595464031758; Wed, 22 Jul 2020 17:27:11 -0700 (PDT) Date: Wed, 22 Jul 2020 17:27:05 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog Subject: [PATCH 2/2] configure: atomic64/128 detection for clang From: Shu-Chun Weng To: rth@twiddle.net Cc: Shu-Chun Weng , qemu-devel@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::b49; envelope-from=3X9kYXwMKCnQkUoYggYdW.UgeiWem-VWnWdfgfYfm.gjY@flex--scw.bounces.google.com; helo=mail-yb1-xb49.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -105 X-Spam_score: -10.6 X-Spam_bar: ---------- X-Spam_report: (-10.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-1, 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, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @google.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The public interface for __atomic_* and __sync_* do not contain the explicit *_{number} versions: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html They appear to be GCC's internal symbols which happen to work. However, clang does not recognize them. Replace the existing usages with the `_n` versions (or no suffix) which are the documented API. Signed-off-by: Shu-Chun Weng --- configure | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/configure b/configure index d9ce3aa5db..0613a049e9 100755 --- a/configure +++ b/configure @@ -5894,9 +5894,9 @@ if test "$int128" =3D "yes"; then int main(void) { unsigned __int128 x =3D 0, y =3D 0; - y =3D __atomic_load_16(&x, 0); - __atomic_store_16(&x, y, 0); - __atomic_compare_exchange_16(&x, &y, x, 0, 0, 0); + y =3D __atomic_load_n(&x, 0); + __atomic_store_n(&x, y, 0); + __atomic_compare_exchange_n(&x, &y, x, 0, 0, 0); return 0; } EOF @@ -5911,7 +5911,7 @@ if test "$int128" =3D yes && test "$atomic128" =3D no= ; then int main(void) { unsigned __int128 x =3D 0, y =3D 0; - __sync_val_compare_and_swap_16(&x, y, x); + __sync_val_compare_and_swap(&x, y, x); return 0; } EOF @@ -5931,11 +5931,11 @@ int main(void) { uint64_t x =3D 0, y =3D 0; #ifdef __ATOMIC_RELAXED - y =3D __atomic_load_8(&x, 0); - __atomic_store_8(&x, y, 0); - __atomic_compare_exchange_8(&x, &y, x, 0, 0, 0); - __atomic_exchange_8(&x, y, 0); - __atomic_fetch_add_8(&x, y, 0); + y =3D __atomic_load_n(&x, 0); + __atomic_store_n(&x, y, 0); + __atomic_compare_exchange_n(&x, &y, x, 0, 0, 0); + __atomic_exchange_n(&x, y, 0); + __atomic_fetch_add(&x, y, 0); #else typedef char is_host64[sizeof(void *) >=3D sizeof(uint64_t) ? 1 : -1]; __sync_lock_test_and_set(&x, y); --=20 2.28.0.rc0.105.gf9edc3c819-goog