| ... | ... | @@ -24,27 +24,12 @@ |
| 24 | 24 | #define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict) |
| 25 | 25 | #define ATTRIBUTE_NORETURN __declspec(noreturn) |
| 26 | 26 | |
| 27 | | static inline int clzll(unsigned long long mask) { |
| 28 | | unsigned long lz; |
| 29 | | #if defined(_WIN64) |
| 30 | | if (_BitScanReverse64(&lz, mask)) |
| 31 | | return static_cast<int>(63-lz); |
| 32 | | zig_unreachable(); |
| 33 | | #else |
| 34 | | if (_BitScanReverse(&lz, mask >> 32)) |
| 35 | | lz += 32; |
| 36 | | else |
| 37 | | _BitScanReverse(&lz, mask & 0xffffffff); |
| 38 | | return 63 - lz; |
| 39 | | #endif |
| 40 | | } |
| 41 | 27 | #else |
| 42 | 28 | |
| 43 | 29 | #define ATTRIBUTE_COLD __attribute__((cold)) |
| 44 | 30 | #define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b))) |
| 45 | 31 | #define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) |
| 46 | 32 | #define ATTRIBUTE_NORETURN __attribute__((noreturn)) |
| 47 | | #define clzll(x) __builtin_clzll(x) |
| 48 | 33 | |
| 49 | 34 | #endif |
| 50 | 35 | |
| ... | ... | @@ -61,6 +46,25 @@ static inline void zig_unreachable(void) { |
| 61 | 46 | zig_panic("unreachable"); |
| 62 | 47 | } |
| 63 | 48 | |
| 49 | #if defined(_MSC_VER) |
| 50 | static inline int clzll(unsigned long long mask) { |
| 51 | 	unsigned long lz; |
| 52 | #if defined(_WIN64) |
| 53 | 	if (_BitScanReverse64(&lz, mask)) |
| 54 | 		return static_cast<int>(63 - lz); |
| 55 | 	zig_unreachable(); |
| 56 | #else |
| 57 | 	if (_BitScanReverse(&lz, mask >> 32)) |
| 58 | 		lz += 32; |
| 59 | 	else |
| 60 | 		_BitScanReverse(&lz, mask & 0xffffffff); |
| 61 | 	return 63 - lz; |
| 62 | #endif |
| 63 | } |
| 64 | #else |
| 65 | #define clzll(x) __builtin_clzll(x) |
| 66 | #endif |
| 67 | |
| 64 | 68 | template<typename T> |
| 65 | 69 | ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate_nonzero(size_t count) { |
| 66 | 70 | T *ptr = reinterpret_cast<T*>(malloc(count * sizeof(T))); |