From: Elliot Gorokhovsky Date: Wed, 16 Feb 2022 21:49:42 +0000 (-0500) Subject: Replace XOR with subtraction for readability X-Git-Tag: v1.5.4^2~238^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71d9dab76f6c496a39356f4d5e984525f2050373;p=thirdparty%2Fzstd.git Replace XOR with subtraction for readability --- diff --git a/lib/common/bits.h b/lib/common/bits.h index 2c4ade865..c0e917750 100644 --- a/lib/common/bits.h +++ b/lib/common/bits.h @@ -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 */ diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 047afc1c8..018da622c 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -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);