| ... | @@ -24,27 +24,12 @@ | ... | @@ -24,27 +24,12 @@ |
| 24 | #define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict) | 24 | #define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict) |
| 25 | #define ATTRIBUTE_NORETURN __declspec(noreturn) | 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 | #else | 27 | #else |
| 42 | | 28 | |
| 43 | #define ATTRIBUTE_COLD __attribute__((cold)) | 29 | #define ATTRIBUTE_COLD __attribute__((cold)) |
| 44 | #define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b))) | 30 | #define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b))) |
| 45 | #define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) | 31 | #define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) |
| 46 | #define ATTRIBUTE_NORETURN __attribute__((noreturn)) | 32 | #define ATTRIBUTE_NORETURN __attribute__((noreturn)) |
| 47 | #define clzll(x) __builtin_clzll(x) | | |
| 48 | | 33 | |
| 49 | #endif | 34 | #endif |
| 50 | | 35 | |
| ... | @@ -61,6 +46,25 @@ static inline void zig_unreachable(void) { | ... | @@ -61,6 +46,25 @@ static inline void zig_unreachable(void) { |
| 61 | zig_panic("unreachable"); | 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 | template<typename T> | 68 | template<typename T> |
| 65 | ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate_nonzero(size_t count) { | 69 | ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate_nonzero(size_t count) { |
| 66 | T *ptr = reinterpret_cast<T*>(malloc(count * sizeof(T))); | 70 | T *ptr = reinterpret_cast<T*>(malloc(count * sizeof(T))); |