diff options
-rw-r--r-- | src/lj_def.h | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/lj_def.h b/src/lj_def.h index e72a8ef9..5574524f 100644 --- a/src/lj_def.h +++ b/src/lj_def.h | |||
@@ -94,8 +94,8 @@ typedef unsigned __int32 uintptr_t; | |||
94 | #define checkptr32(x) ((uintptr_t)(x) == (uint32_t)(uintptr_t)(x)) | 94 | #define checkptr32(x) ((uintptr_t)(x) == (uint32_t)(uintptr_t)(x)) |
95 | 95 | ||
96 | /* Every half-decent C compiler transforms this into a rotate instruction. */ | 96 | /* Every half-decent C compiler transforms this into a rotate instruction. */ |
97 | #define lj_rol(x, n) (((x)<<(n)) | ((x)>>(32-(n)))) | 97 | #define lj_rol(x, n) (((x)<<(n)) | ((x)>>(8*sizeof(x)-(n)))) |
98 | #define lj_ror(x, n) (((x)<<(32-(n))) | ((x)>>(n))) | 98 | #define lj_ror(x, n) (((x)<<(8*sizeof(x)-(n))) | ((x)>>(n))) |
99 | 99 | ||
100 | /* A really naive Bloom filter. But sufficient for our needs. */ | 100 | /* A really naive Bloom filter. But sufficient for our needs. */ |
101 | typedef uintptr_t BloomFilter; | 101 | typedef uintptr_t BloomFilter; |
@@ -143,11 +143,28 @@ static LJ_AINLINE uint32_t lj_bswap(uint32_t x) | |||
143 | { | 143 | { |
144 | return (uint32_t)__builtin_bswap32((int32_t)x); | 144 | return (uint32_t)__builtin_bswap32((int32_t)x); |
145 | } | 145 | } |
146 | |||
147 | static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) | ||
148 | { | ||
149 | return (uint64_t)__builtin_bswap64((int64_t)x); | ||
150 | } | ||
146 | #elif defined(__i386__) || defined(__x86_64__) | 151 | #elif defined(__i386__) || defined(__x86_64__) |
147 | static LJ_AINLINE uint32_t lj_bswap(uint32_t x) | 152 | static LJ_AINLINE uint32_t lj_bswap(uint32_t x) |
148 | { | 153 | { |
149 | uint32_t r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r; | 154 | uint32_t r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r; |
150 | } | 155 | } |
156 | |||
157 | #if defined(__i386__) | ||
158 | static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) | ||
159 | { | ||
160 | return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32)); | ||
161 | } | ||
162 | #else | ||
163 | static LJ_AINLINE uint64_t lj_bswap64(uint64_t x) | ||
164 | { | ||
165 | uint64_t r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r; | ||
166 | } | ||
167 | #endif | ||
151 | #else | 168 | #else |
152 | #error "missing define for lj_bswap()" | 169 | #error "missing define for lj_bswap()" |
153 | #endif | 170 | #endif |
@@ -174,6 +191,7 @@ static LJ_AINLINE uint32_t lj_fls(uint32_t x) | |||
174 | } | 191 | } |
175 | 192 | ||
176 | #define lj_bswap(x) (_byteswap_ulong((x))) | 193 | #define lj_bswap(x) (_byteswap_ulong((x))) |
194 | #define lj_bswap64(x) (_byteswap_uint64((x))) | ||
177 | 195 | ||
178 | #else | 196 | #else |
179 | #error "missing defines for your compiler" | 197 | #error "missing defines for your compiler" |