diff options
Diffstat (limited to '')
-rw-r--r-- | src/lj_def.h | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/lj_def.h b/src/lj_def.h index 88bc6336..1461d3d7 100644 --- a/src/lj_def.h +++ b/src/lj_def.h | |||
@@ -146,15 +146,9 @@ typedef uintptr_t BloomFilter; | |||
146 | #define LJ_UNLIKELY(x) __builtin_expect(!!(x), 0) | 146 | #define LJ_UNLIKELY(x) __builtin_expect(!!(x), 0) |
147 | 147 | ||
148 | #define lj_ffs(x) ((uint32_t)__builtin_ctz(x)) | 148 | #define lj_ffs(x) ((uint32_t)__builtin_ctz(x)) |
149 | /* Don't ask ... */ | ||
150 | #if defined(__INTEL_COMPILER) && (defined(__i386__) || defined(__x86_64__)) | ||
151 | static LJ_AINLINE uint32_t lj_fls(uint32_t x) | ||
152 | { | ||
153 | uint32_t r; __asm__("bsrl %1, %0" : "=r" (r) : "rm" (x) : "cc"); return r; | ||
154 | } | ||
155 | #else | ||
156 | #define lj_fls(x) ((uint32_t)(__builtin_clz(x)^31)) | 149 | #define lj_fls(x) ((uint32_t)(__builtin_clz(x)^31)) |
157 | #endif | 150 | #define lj_ffs64(x) ((uint32_t)__builtin_ctzll(x)) |
151 | #define lj_fls64(x) ((uint32_t)(__builtin_clzll(x)^63)) | ||
158 | 152 | ||
159 | #if defined(__arm__) | 153 | #if defined(__arm__) |
160 | static LJ_AINLINE uint32_t lj_bswap(uint32_t x) | 154 | static LJ_AINLINE uint32_t lj_bswap(uint32_t x) |
@@ -265,8 +259,12 @@ static LJ_AINLINE uint32_t lj_fls(uint32_t x) | |||
265 | #else | 259 | #else |
266 | unsigned char _BitScanForward(unsigned long *, unsigned long); | 260 | unsigned char _BitScanForward(unsigned long *, unsigned long); |
267 | unsigned char _BitScanReverse(unsigned long *, unsigned long); | 261 | unsigned char _BitScanReverse(unsigned long *, unsigned long); |
262 | unsigned char _BitScanForward64(unsigned long *, uint64_t); | ||
263 | unsigned char _BitScanReverse64(unsigned long *, uint64_t); | ||
268 | #pragma intrinsic(_BitScanForward) | 264 | #pragma intrinsic(_BitScanForward) |
269 | #pragma intrinsic(_BitScanReverse) | 265 | #pragma intrinsic(_BitScanReverse) |
266 | #pragma intrinsic(_BitScanForward64) | ||
267 | #pragma intrinsic(_BitScanReverse64) | ||
270 | 268 | ||
271 | static LJ_AINLINE uint32_t lj_ffs(uint32_t x) | 269 | static LJ_AINLINE uint32_t lj_ffs(uint32_t x) |
272 | { | 270 | { |
@@ -277,6 +275,16 @@ static LJ_AINLINE uint32_t lj_fls(uint32_t x) | |||
277 | { | 275 | { |
278 | unsigned long r; _BitScanReverse(&r, x); return (uint32_t)r; | 276 | unsigned long r; _BitScanReverse(&r, x); return (uint32_t)r; |
279 | } | 277 | } |
278 | |||
279 | static LJ_AINLINE uint32_t lj_ffs64(uint64_t x) | ||
280 | { | ||
281 | unsigned long r; _BitScanForward64(&r, x); return (uint32_t)r; | ||
282 | } | ||
283 | |||
284 | static LJ_AINLINE uint32_t lj_fls64(uint64_t x) | ||
285 | { | ||
286 | unsigned long r; _BitScanReverse64(&r, x); return (uint32_t)r; | ||
287 | } | ||
280 | #endif | 288 | #endif |
281 | 289 | ||
282 | unsigned long _byteswap_ulong(unsigned long); | 290 | unsigned long _byteswap_ulong(unsigned long); |