Use __assume(0) for unreachable code path in msvc

msvc will optimize away the condition check.
This commit is contained in:
Ma Lin
2021-09-27 19:23:57 +08:00
parent e5ba858270
commit ae986fcdb8
6 changed files with 113 additions and 32 deletions
+8 -5
View File
@@ -881,11 +881,14 @@ typedef U64 ZSTD_VecMask; /* Clarifies when we are interacting with a U64 repr
static U32 ZSTD_VecMask_next(ZSTD_VecMask val) {
assert(val != 0);
# if defined(_MSC_VER) && defined(_WIN64)
{
unsigned long r;
/* _BitScanForward64 is not defined outside of x64 */
return _BitScanForward64(&r, val) ? (U32)r : 0;
}
if (val != 0) {
unsigned long r;
_BitScanForward64(&r, val);
return (U32)(r);
} else {
/* Should not reach this code path */
__assume(0);
}
# elif (defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))))
if (sizeof(size_t) == 4) {
U32 mostSignificantWord = (U32)(val >> 32);