]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
prevent XXH64 from being autovectorized by XXH512 by default 3933/head
authorYann Collet <cyan@fb.com>
Fri, 8 Mar 2024 00:43:13 +0000 (16:43 -0800)
committerYann Collet <cyan@fb.com>
Fri, 8 Mar 2024 00:43:13 +0000 (16:43 -0800)
backport fix https://github.com/Cyan4973/xxHash/pull/924 from libxxhash

lib/common/xxhash.h

index e5ed3dc04430b4963ac4c95445757a9be00864b1..d95bad1916618672527099e3f6cb1dc628c6b964 100644 (file)
@@ -3317,6 +3317,23 @@ static xxh_u64 XXH64_round(xxh_u64 acc, xxh_u64 input)
     acc += input * XXH_PRIME64_2;
     acc  = XXH_rotl64(acc, 31);
     acc *= XXH_PRIME64_1;
+#if (defined(__AVX512F__)) && !defined(XXH_ENABLE_AUTOVECTORIZE)
+    /*
+     * DISABLE AUTOVECTORIZATION:
+     * A compiler fence is used to prevent GCC and Clang from
+     * autovectorizing the XXH64 loop (pragmas and attributes don't work for some
+     * reason) without globally disabling AVX512.
+     *
+     * Autovectorization of XXH64 tends to be detrimental,
+     * though the exact outcome may change depending on exact cpu and compiler version.
+     * For information, it has been reported as detrimental for Skylake-X,
+     * but possibly beneficial for Zen4.
+     *
+     * The default is to disable auto-vectorization,
+     * but you can select to enable it instead using `XXH_ENABLE_AUTOVECTORIZE` build variable.
+     */
+    XXH_COMPILER_GUARD(acc);
+#endif
     return acc;
 }