diff options
Diffstat (limited to 'src/lj_def.h')
-rw-r--r-- | src/lj_def.h | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/lj_def.h b/src/lj_def.h index a28d84d7..3d8a972d 100644 --- a/src/lj_def.h +++ b/src/lj_def.h | |||
@@ -242,12 +242,18 @@ static LJ_AINLINE uint32_t lj_getu32(const void *p) | |||
242 | #define LJ_FASTCALL __fastcall | 242 | #define LJ_FASTCALL __fastcall |
243 | #endif | 243 | #endif |
244 | 244 | ||
245 | #ifdef _M_PPC | ||
246 | #pragma intrinsic(_CountLeadingZeros) | ||
247 | unsigned int _CountLeadingZeros(long); | ||
248 | static LJ_AINLINE uint32_t lj_fls(uint32_t x) | ||
249 | { | ||
250 | return _CountLeadingZeros(x) ^ 31; | ||
251 | } | ||
252 | #else | ||
245 | #pragma intrinsic(_BitScanForward) | 253 | #pragma intrinsic(_BitScanForward) |
246 | #pragma intrinsic(_BitScanReverse) | 254 | #pragma intrinsic(_BitScanReverse) |
247 | unsigned char _BitScanForward(uint32_t *, unsigned long); | 255 | unsigned char _BitScanForward(uint32_t *, unsigned long); |
248 | unsigned char _BitScanReverse(uint32_t *, unsigned long); | 256 | unsigned char _BitScanReverse(uint32_t *, unsigned long); |
249 | unsigned long _byteswap_ulong(unsigned long); | ||
250 | uint64_t _byteswap_uint64(uint64_t); | ||
251 | 257 | ||
252 | static LJ_AINLINE uint32_t lj_ffs(uint32_t x) | 258 | static LJ_AINLINE uint32_t lj_ffs(uint32_t x) |
253 | { | 259 | { |
@@ -258,13 +264,33 @@ static LJ_AINLINE uint32_t lj_fls(uint32_t x) | |||
258 | { | 264 | { |
259 | uint32_t r; _BitScanReverse(&r, x); return r; | 265 | uint32_t r; _BitScanReverse(&r, x); return r; |
260 | } | 266 | } |
267 | #endif | ||
261 | 268 | ||
269 | unsigned long _byteswap_ulong(unsigned long); | ||
270 | uint64_t _byteswap_uint64(uint64_t); | ||
262 | #define lj_bswap(x) (_byteswap_ulong((x))) | 271 | #define lj_bswap(x) (_byteswap_ulong((x))) |
263 | #define lj_bswap64(x) (_byteswap_uint64((x))) | 272 | #define lj_bswap64(x) (_byteswap_uint64((x))) |
264 | 273 | ||
265 | /* MSVC is only supported on x86/x64, where unaligned loads are always ok. */ | 274 | #if defined(_M_PPC) && defined(LUAJIT_NO_UNALIGNED) |
275 | /* | ||
276 | ** Replacement for unaligned loads on XBox 360. Disabled by default since it's | ||
277 | ** usually more costly than the occasional stall when crossing a cache-line. | ||
278 | */ | ||
279 | static LJ_AINLINE uint16_t lj_getu16(const void *v) | ||
280 | { | ||
281 | const uint8_t *p = (const uint8_t *)v; | ||
282 | return (uint16_t)((p[0]<<8) | p[1]); | ||
283 | } | ||
284 | static LJ_AINLINE uint32_t lj_getu32(const void *v) | ||
285 | { | ||
286 | const uint8_t *p = (const uint8_t *)v; | ||
287 | return (uint32_t)((p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]); | ||
288 | } | ||
289 | #else | ||
290 | /* Unaligned loads are generally ok on x86/x64. */ | ||
266 | #define lj_getu16(p) (*(uint16_t *)(p)) | 291 | #define lj_getu16(p) (*(uint16_t *)(p)) |
267 | #define lj_getu32(p) (*(uint32_t *)(p)) | 292 | #define lj_getu32(p) (*(uint32_t *)(p)) |
293 | #endif | ||
268 | 294 | ||
269 | #else | 295 | #else |
270 | #error "missing defines for your compiler" | 296 | #error "missing defines for your compiler" |