1
0
mirror of https://github.com/facebook/zstd.git synced 2025-11-28 23:23:59 +03:00

Don't initialize the first parameter of _BitScanReverse* functions

Like the document example, no need to initialize `r` to 0.
https://docs.microsoft.com/en-us/cpp/intrinsics/bitscanreverse-bitscanreverse64
This commit is contained in:
Ma Lin
2021-09-24 19:24:29 +08:00
parent cc22042da0
commit 95f492ea17
11 changed files with 21 additions and 30 deletions

View File

@@ -145,7 +145,7 @@ MEM_STATIC unsigned BIT_highbit32 (U32 val)
# if STATIC_BMI2 == 1 # if STATIC_BMI2 == 1
return _lzcnt_u32(val) ^ 31; return _lzcnt_u32(val) ^ 31;
# else # else
unsigned long r = 0; unsigned long r;
return _BitScanReverse(&r, val) ? (unsigned)r : 0; return _BitScanReverse(&r, val) ? (unsigned)r : 0;
# endif # endif
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */ # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */

View File

@@ -358,7 +358,7 @@ MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus
# if STATIC_BMI2 == 1 # if STATIC_BMI2 == 1
return _lzcnt_u32(val)^31; return _lzcnt_u32(val)^31;
# else # else
unsigned long r=0; unsigned long r;
return _BitScanReverse(&r, val) ? (unsigned)r : 0; return _BitScanReverse(&r, val) ? (unsigned)r : 0;
# endif # endif
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */ # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */

View File

@@ -708,7 +708,7 @@ static unsigned ZSTD_NbCommonBytes (size_t val)
# if STATIC_BMI2 # if STATIC_BMI2
return _lzcnt_u64(val) >> 3; return _lzcnt_u64(val) >> 3;
# else # else
unsigned long r = 0; unsigned long r;
return _BitScanReverse64(&r, (U64)val) ? (unsigned)(r >> 3) : 0; return _BitScanReverse64(&r, (U64)val) ? (unsigned)(r >> 3) : 0;
# endif # endif
# elif defined(__GNUC__) && (__GNUC__ >= 4) # elif defined(__GNUC__) && (__GNUC__ >= 4)
@@ -723,7 +723,7 @@ static unsigned ZSTD_NbCommonBytes (size_t val)
# endif # endif
} else { /* 32 bits */ } else { /* 32 bits */
# if defined(_MSC_VER) # if defined(_MSC_VER)
unsigned long r = 0; unsigned long r;
return _BitScanReverse( &r, (unsigned long)val ) ? (unsigned)(r >> 3) : 0; return _BitScanReverse( &r, (unsigned long)val ) ? (unsigned)(r >> 3) : 0;
# elif defined(__GNUC__) && (__GNUC__ >= 3) # elif defined(__GNUC__) && (__GNUC__ >= 3)
return (__builtin_clz((U32)val) >> 3); return (__builtin_clz((U32)val) >> 3);

View File

@@ -159,9 +159,8 @@ static unsigned ZDICT_NbCommonBytes (size_t val)
} else { /* Big Endian CPU */ } else { /* Big Endian CPU */
if (MEM_64bits()) { if (MEM_64bits()) {
# if defined(_MSC_VER) && defined(_WIN64) # if defined(_MSC_VER) && defined(_WIN64)
unsigned long r = 0; unsigned long r;
_BitScanReverse64( &r, val ); return _BitScanReverse64(&r, val) ? (unsigned)(r >> 3) : 0;
return (unsigned)(r>>3);
# elif defined(__GNUC__) && (__GNUC__ >= 3) # elif defined(__GNUC__) && (__GNUC__ >= 3)
return (unsigned)(__builtin_clzll(val) >> 3); return (unsigned)(__builtin_clzll(val) >> 3);
# else # else
@@ -174,9 +173,8 @@ static unsigned ZDICT_NbCommonBytes (size_t val)
# endif # endif
} else { /* 32 bits */ } else { /* 32 bits */
# if defined(_MSC_VER) # if defined(_MSC_VER)
unsigned long r = 0; unsigned long r;
_BitScanReverse( &r, (unsigned long)val ); return _BitScanReverse(&r, (unsigned long)val) ? (unsigned)(r >> 3) : 0;
return (unsigned)(r>>3);
# elif defined(__GNUC__) && (__GNUC__ >= 3) # elif defined(__GNUC__) && (__GNUC__ >= 3)
return (unsigned)(__builtin_clz((U32)val) >> 3); return (unsigned)(__builtin_clz((U32)val) >> 3);
# else # else

View File

@@ -343,8 +343,7 @@ FORCE_INLINE unsigned FSE_highbit32 (U32 val)
{ {
# if defined(_MSC_VER) /* Visual */ # if defined(_MSC_VER) /* Visual */
unsigned long r; unsigned long r;
_BitScanReverse ( &r, val ); return _BitScanReverse(&r, val) ? (unsigned)r : 0;
return (unsigned) r;
# elif defined(__GNUC__) && (GCC_VERSION >= 304) /* GCC Intrinsic */ # elif defined(__GNUC__) && (GCC_VERSION >= 304) /* GCC Intrinsic */
return __builtin_clz (val) ^ 31; return __builtin_clz (val) ^ 31;
# else /* Software version */ # else /* Software version */

View File

@@ -353,9 +353,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
MEM_STATIC unsigned BIT_highbit32 (U32 val) MEM_STATIC unsigned BIT_highbit32 (U32 val)
{ {
# if defined(_MSC_VER) /* Visual */ # if defined(_MSC_VER) /* Visual */
unsigned long r=0; unsigned long r;
_BitScanReverse ( &r, val ); return _BitScanReverse(&r, val) ? (unsigned)r : 0;
return (unsigned) r;
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */ # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
return __builtin_clz (val) ^ 31; return __builtin_clz (val) ^ 31;
# else /* Software version */ # else /* Software version */

View File

@@ -356,9 +356,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
MEM_STATIC unsigned BIT_highbit32 (U32 val) MEM_STATIC unsigned BIT_highbit32 (U32 val)
{ {
# if defined(_MSC_VER) /* Visual */ # if defined(_MSC_VER) /* Visual */
unsigned long r=0; unsigned long r;
_BitScanReverse ( &r, val ); return _BitScanReverse(&r, val) ? (unsigned)r : 0;
return (unsigned) r;
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */ # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
return __builtin_clz (val) ^ 31; return __builtin_clz (val) ^ 31;
# else /* Software version */ # else /* Software version */

View File

@@ -627,9 +627,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
MEM_STATIC unsigned BIT_highbit32 (U32 val) MEM_STATIC unsigned BIT_highbit32 (U32 val)
{ {
# if defined(_MSC_VER) /* Visual */ # if defined(_MSC_VER) /* Visual */
unsigned long r=0; unsigned long r;
_BitScanReverse ( &r, val ); return _BitScanReverse(&r, val) ? (unsigned)r : 0;
return (unsigned) r;
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */ # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
return __builtin_clz (val) ^ 31; return __builtin_clz (val) ^ 31;
# else /* Software version */ # else /* Software version */

View File

@@ -756,9 +756,8 @@ MEM_STATIC size_t BITv05_readBitsFast(BITv05_DStream_t* bitD, unsigned nbBits);
MEM_STATIC unsigned BITv05_highbit32 (U32 val) MEM_STATIC unsigned BITv05_highbit32 (U32 val)
{ {
# if defined(_MSC_VER) /* Visual */ # if defined(_MSC_VER) /* Visual */
unsigned long r=0; unsigned long r;
_BitScanReverse ( &r, val ); return _BitScanReverse(&r, val) ? (unsigned)r : 0;
return (unsigned) r;
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */ # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
return __builtin_clz (val) ^ 31; return __builtin_clz (val) ^ 31;
# else /* Software version */ # else /* Software version */

View File

@@ -860,9 +860,8 @@ MEM_STATIC size_t BITv06_readBitsFast(BITv06_DStream_t* bitD, unsigned nbBits);
MEM_STATIC unsigned BITv06_highbit32 ( U32 val) MEM_STATIC unsigned BITv06_highbit32 ( U32 val)
{ {
# if defined(_MSC_VER) /* Visual */ # if defined(_MSC_VER) /* Visual */
unsigned long r=0; unsigned long r;
_BitScanReverse ( &r, val ); return _BitScanReverse(&r, val) ? (unsigned)r : 0;
return (unsigned) r;
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */ # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
return __builtin_clz (val) ^ 31; return __builtin_clz (val) ^ 31;
# else /* Software version */ # else /* Software version */

View File

@@ -530,9 +530,8 @@ MEM_STATIC size_t BITv07_readBitsFast(BITv07_DStream_t* bitD, unsigned nbBits);
MEM_STATIC unsigned BITv07_highbit32 (U32 val) MEM_STATIC unsigned BITv07_highbit32 (U32 val)
{ {
# if defined(_MSC_VER) /* Visual */ # if defined(_MSC_VER) /* Visual */
unsigned long r=0; unsigned long r;
_BitScanReverse ( &r, val ); return _BitScanReverse(&r, val) ? (unsigned)r : 0;
return (unsigned) r;
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */ # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
return __builtin_clz (val) ^ 31; return __builtin_clz (val) ^ 31;
# else /* Software version */ # else /* Software version */