1313
1414#include "lj_str_hash.h"
1515
16- #if LJ_OR_STRHASHCRC32
16+ #if LUAJIT_TARGET == LUAJIT_ARCH_X64
17+ #include "lj_vm.h"
18+
19+ #ifndef F_CPU_SSE4_2
20+ #define F_CPU_SSE4_2 (1 << 20)
21+ #endif
22+
23+ #elif LUAJIT_TARGET == LUAJIT_ARCH_ARM64
24+ #include <sys/auxv.h>
25+ #include <errno.h>
26+
27+ #ifndef HWCAP_CRC32
28+ #define HWCAP_CRC32 (1 << 7)
29+ #endif
30+ #endif
1731
32+ #if LJ_OR_STRHASHCRC32
1833#include <sys/types.h>
1934#include <unistd.h>
2035#include <time.h>
21- #include "lj_vm.h"
2236
2337#if LUAJIT_TARGET == LUAJIT_ARCH_X64
2438#include <smmintrin.h>
2539
2640#define lj_crc32_u32 _mm_crc32_u32
2741#define lj_crc32_u64 _mm_crc32_u64
2842
29- #ifndef F_CPU_SSE4_2
30- #define F_CPU_SSE4_2 (1 << 20)
31- #endif
32-
3343#elif LUAJIT_TARGET == LUAJIT_ARCH_ARM64
34- #include <sys/auxv.h>
3544#include <arm_acle.h>
36- #include <errno.h>
3745
3846#define lj_crc32_u32 __crc32cw
3947#define lj_crc32_u64 __crc32cd
4048
41- #ifndef HWCAP_CRC32
42- #define HWCAP_CRC32 (1 << 7)
43- #endif
44-
4549#else
4650#error "LJ_OR_STRHASHCRC32 not supported on this architecture"
4751#endif
@@ -288,20 +292,6 @@ static void lj_str_hash_init_random(void)
288292
289293#undef POW2_MASK
290294
291- LJ_FUNC unsigned char lj_check_crc32_support ()
292- {
293- #if LUAJIT_TARGET == LUAJIT_ARCH_X64
294- uint32_t features [4 ];
295- if (lj_vm_cpuid (1 , features ))
296- return (features [2 ] & F_CPU_SSE4_2 ) != 0 ;
297- #elif LUAJIT_TARGET == LUAJIT_ARCH_ARM64
298- uint32_t hwcap = getauxval (AT_HWCAP );
299- if (hwcap != ENOENT )
300- return (hwcap & HWCAP_CRC32 ) != 0 ;
301- #endif
302- return 0 ;
303- }
304-
305295LJ_FUNC void lj_init_strhashfn (global_State * g )
306296{
307297 static StrHashFunction strhashfn ;
@@ -318,6 +308,20 @@ LJ_FUNC void lj_init_strhashfn(global_State *g)
318308
319309#endif
320310
311+ LJ_FUNC unsigned char lj_check_crc32_support ()
312+ {
313+ #if LUAJIT_TARGET == LUAJIT_ARCH_X64
314+ uint32_t features [4 ];
315+ if (lj_vm_cpuid (1 , features ))
316+ return (features [2 ] & F_CPU_SSE4_2 ) != 0 ;
317+ #elif LUAJIT_TARGET == LUAJIT_ARCH_ARM64
318+ uint32_t hwcap = getauxval (AT_HWCAP );
319+ if (hwcap != ENOENT )
320+ return (hwcap & HWCAP_CRC32 ) != 0 ;
321+ #endif
322+ return 0 ;
323+ }
324+
321325LJ_FUNC MSize lj_str_hash_orig (const char * str , size_t lenx )
322326{
323327 MSize len = (MSize )lenx ;
0 commit comments