]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Replace XOR with subtraction for readability 3045/head
authorElliot Gorokhovsky <embg@fb.com>
Wed, 16 Feb 2022 21:49:42 +0000 (16:49 -0500)
committerElliot Gorokhovsky <embg@fb.com>
Wed, 16 Feb 2022 21:49:42 +0000 (16:49 -0500)
lib/common/bits.h
tests/fuzzer.c

index 2c4ade865acc248d4d15c32c9baa037cad48e74a..c0e9177507f3741e52955935dd7cc4747b0147fe 100644 (file)
@@ -60,7 +60,7 @@ MEM_STATIC unsigned ZSTD_countLeadingZeros32_fallback(U32 val) {
         val |= val >> 4;
         val |= val >> 8;
         val |= val >> 16;
-        return DeBruijnClz[(val * 0x07C4ACDDU) >> 27] ^ 31;
+        return 31 - DeBruijnClz[(val * 0x07C4ACDDU) >> 27];
     }
 }
 
@@ -74,7 +74,7 @@ MEM_STATIC unsigned ZSTD_countLeadingZeros32(U32 val)
             if (val != 0) {
                 unsigned long r;
                 _BitScanReverse(&r, val);
-                return (unsigned)(r ^ 31);
+                return (unsigned)(31 - r);
             } else {
                 /* Should not reach this code path */
                 __assume(0);
@@ -128,7 +128,7 @@ MEM_STATIC unsigned ZSTD_countLeadingZeros64(U64 val)
             if (val != 0) {
                 unsigned long r;
                 _BitScanReverse64(&r, val);
-                return (unsigned)(r ^ 63);
+                return (unsigned)(63 - r);
             } else {
                 /* Should not reach this code path */
                 __assume(0);
@@ -169,7 +169,7 @@ MEM_STATIC unsigned ZSTD_NbCommonBytes(size_t val)
 MEM_STATIC unsigned ZSTD_highbit32(U32 val)   /* compress, dictBuilder, decodeCorpus */
 {
     assert(val != 0);
-    return ZSTD_countLeadingZeros32(val) ^ 31;
+    return 31 - ZSTD_countLeadingZeros32(val);
 }
 
 #endif /* ZSTD_BITS_H */
index 047afc1c82b1b753d4d1cac98e38d4c4761812f5..018da622ceac49ca1a6e6d48546628b169101f65 100644 (file)
@@ -3375,7 +3375,7 @@ static int basicUnitTests(U32 const seed, double compressibility)
     }
     DISPLAYLEVEL(3, "OK \n");
 
-    DISPLAYLEVEL(3, "test%3i : testing bitwise instrinsics PR#3045: ", testNb++);
+    DISPLAYLEVEL(3, "test%3i : testing bitwise intrinsics PR#3045: ", testNb++);
     {
         U32 seed_copy = seed; // need non-const seed to avoid compiler warning for FUZ_rand(&seed)
         U32 rand32 = FUZ_rand(&seed_copy);