diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-03-13 12:56:58 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-03-13 12:56:58 -0400 |
| commit | 54edbc6815e42457cd28fa9f1b94e732504b3fc9 (patch) | |
| tree | 36c97169bf0cd59326a93b8c3c0d458f94aed8a9 /src/util.hpp | |
| parent | 4cb55d3af6a71467b7d4399bedb961c81e9ad3d5 (diff) | |
| parent | d495dcc3c952c99e5358d9610cf09eb856f643b0 (diff) | |
| download | zig-54edbc6815e42457cd28fa9f1b94e732504b3fc9.tar.gz zig-54edbc6815e42457cd28fa9f1b94e732504b3fc9.zip | |
Merge remote-tracking branch 'origin/master' into llvm8
Diffstat (limited to 'src/util.hpp')
| -rw-r--r-- | src/util.hpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/util.hpp b/src/util.hpp index abf4d37c88..64c85033e3 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -63,10 +63,27 @@ static inline int clzll(unsigned long long mask) { return 63 - lz; #endif } +static inline int ctzll(unsigned long long mask) { + unsigned long result; +#if defined(_WIN64) + if (_BitScanForward64(&result, mask)) + return result; + zig_unreachable(); +#else + if (_BitScanForward(&result, mask & 0xffffffff)) + return result; + } + if (_BitScanForward(&result, mask >> 32)) + return 32 + result; + zig_unreachable(); +#endif +} #else #define clzll(x) __builtin_clzll(x) +#define ctzll(x) __builtin_ctzll(x) #endif + template<typename T> ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate_nonzero(size_t count) { #ifndef NDEBUG |
