File tree 1 file changed +18
-4
lines changed
1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 15
15
#include " FuzzerDefs.h"
16
16
17
17
#if LIBFUZZER_MSVC
18
- #if !defined(_M_ARM) && !defined(_M_X64)
19
- #error "_BitScanReverse64 unavailable on this platform so MSVC is unsupported."
20
- #endif
21
18
#include < intrin.h>
22
19
#include < cstdint>
23
20
#include < cstdlib>
@@ -40,7 +37,18 @@ inline uint64_t Bswap(uint64_t x) { return _byteswap_uint64(x); }
40
37
// outside of Windows.
41
38
inline uint32_t Clzll (uint64_t X) {
42
39
unsigned long LeadZeroIdx = 0 ;
40
+
41
+ #if !defined(_M_ARM) && !defined(_M_X64)
42
+ // Scan the high 32 bits.
43
+ if (_BitScanReverse (&LeadZeroIdx, static_cast <unsigned long >(X >> 32 )))
44
+ return static_cast <int >(63 - (LeadZeroIdx + 32 )); // Create a bit offset from the MSB.
45
+ // Scan the low 32 bits.
46
+ if (_BitScanReverse (&LeadZeroIdx, static_cast <unsigned long >(X)))
47
+ return static_cast <int >(63 - LeadZeroIdx);
48
+
49
+ #else
43
50
if (_BitScanReverse64 (&LeadZeroIdx, X)) return 63 - LeadZeroIdx;
51
+ #endif
44
52
return 64 ;
45
53
}
46
54
@@ -50,7 +58,13 @@ inline uint32_t Clz(uint32_t X) {
50
58
return 32 ;
51
59
}
52
60
53
- inline int Popcountll (unsigned long long X) { return __popcnt64 (X); }
61
+ inline int Popcountll (unsigned long long X) {
62
+ #if !defined(_M_ARM) && !defined(_M_X64)
63
+ return __popcnt (X) + __popcnt (X >> 32 );
64
+ #else
65
+ return __popcnt64 (X);
66
+ #endif
67
+ }
54
68
55
69
} // namespace fuzzer
56
70
You can’t perform that action at this time.
0 commit comments