diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-09-20 19:02:18 +0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-20 19:02:18 +0600 |
commit | 4ccd25c56d4875d8f719bd3487aec27c7f8ae31c (patch) | |
tree | f6bfd77ec8c1c1503b2ce7a7201ad5d9b9877985 /src | |
parent | 92b679d17ca41f85009c9e33cdd5967f955b5557 (diff) | |
parent | f8fdd2ba0881fdfbbe371e114781a6fc87809138 (diff) | |
download | rspamd-4ccd25c56d4875d8f719bd3487aec27c7f8ae31c.tar.gz rspamd-4ccd25c56d4875d8f719bd3487aec27c7f8ae31c.zip |
Merge pull request #5140 from rspamd/vstakhov-cpu-detection
[Feature] Detect CPU using __builtin_cpu_supports where it's possible
Diffstat (limited to 'src')
-rw-r--r-- | src/libcryptobox/cryptobox.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/libcryptobox/cryptobox.c b/src/libcryptobox/cryptobox.c index eeeed020c..a976653df 100644 --- a/src/libcryptobox/cryptobox.c +++ b/src/libcryptobox/cryptobox.c @@ -86,6 +86,60 @@ rspamd_cryptobox_cpuid(int cpu[4], int info) #endif } +#ifdef HAVE_BUILTIN_CPU_SUPPORTS +RSPAMD_CONSTRUCTOR(cryptobox_cpu_init) +{ + __builtin_cpu_init(); +} +static gboolean +rspamd_cryptobox_test_instr(int instr) +{ + gboolean ret = FALSE; + switch (instr) { +#if defined HAVE_SSE2 && defined(__x86_64__) + case CPUID_SSE2: + ret = __builtin_cpu_supports("sse2"); + break; + case CPUID_RDRAND: + /* XXX: no check to test for rdrand, but all avx2 cpus are def. capable of rdrand */ + ret = __builtin_cpu_supports("avx2"); + break; +#endif +#ifdef HAVE_SSE3 + case CPUID_SSE3: + ret = __builtin_cpu_supports("sse3"); + break; +#endif +#ifdef HAVE_SSSE3 + case CPUID_SSSE3: + ret = __builtin_cpu_supports("ssse3"); + break; +#endif +#ifdef HAVE_SSE41 + case CPUID_SSE41: + ret = __builtin_cpu_supports("sse4.1"); + break; +#endif +#if defined HAVE_SSE42 && defined(__x86_64__) + case CPUID_SSE42: + ret = __builtin_cpu_supports("sse4.2"); + break; +#endif +#ifdef HAVE_AVX + case CPUID_AVX: + ret = __builtin_cpu_supports("avx"); + break; +#endif +#ifdef HAVE_AVX2 + case CPUID_AVX2: + ret = __builtin_cpu_supports("avx2"); + break; +#endif + } + + return ret; +} +#else static sig_atomic_t ok = 0; static jmp_buf j; @@ -171,6 +225,7 @@ rspamd_cryptobox_test_instr(int instr) /* We actually never return here if SIGILL has been caught */ return ok == 1; } +#endif /* HAVE_BUILTIN_CPU_SUPPORTS */ struct rspamd_cryptobox_library_ctx * rspamd_cryptobox_init(void) |