X-Git-Url: https://www.bearssl.org/gitweb//home/git/?p=BearSSL;a=blobdiff_plain;f=src%2Fsymcipher%2Fchacha20_sse2.c;h=92b4a4a83591dac95f6aceae3b8566aa32edc2e3;hp=0b32d51a19908420d707d52520d9725c6732a62b;hb=f0ddbc32f07c4042ea31759b0d90864ca087b2b7;hpb=24c6f09bf83015e04e16666e8a5fb66e75967e0d diff --git a/src/symcipher/chacha20_sse2.c b/src/symcipher/chacha20_sse2.c index 0b32d51..92b4a4a 100644 --- a/src/symcipher/chacha20_sse2.c +++ b/src/symcipher/chacha20_sse2.c @@ -22,22 +22,43 @@ * SOFTWARE. */ +#define BR_ENABLE_INTRINSICS 1 #include "inner.h" +#if BR_SSE2 + /* * This file contains a ChaCha20 implementation that leverages SSE2 * opcodes for better performance. */ -#if BR_SSE2 +/* see bearssl_block.h */ +br_chacha20_run +br_chacha20_sse2_get(void) +{ + /* + * If using 64-bit mode, then SSE2 opcodes should be automatically + * available, since they are part of the ABI. + * + * In 32-bit mode, we use CPUID to detect the SSE2 feature. + */ -#if BR_SSE2_GCC -#include -#include -#endif -#if BR_SSE2_MSC -#include +#if BR_amd64 + return &br_chacha20_sse2_run; +#else + + /* + * SSE2 support is indicated by bit 26 in EDX. + */ + if (br_cpuid(0, 0, 0, 0x04000000)) { + return &br_chacha20_sse2_run; + } else { + return 0; + } #endif +} + +BR_TARGETS_X86_UP /* see bearssl_block.h */ BR_TARGET("sse2") @@ -202,48 +223,7 @@ br_chacha20_sse2_run(const void *key, | ((uint32_t)_mm_extract_epi16(iw, 1) << 16); } -/* see bearssl_block.h */ -br_chacha20_run -br_chacha20_sse2_get(void) -{ - /* - * If using 64-bit mode, then SSE2 opcodes should be automatically - * available, since they are part of the ABI. - * - * In 32-bit mode, we use CPUID to detect the SSE2 feature. - */ - -#if __x86_64__ || _M_X64 - - return &br_chacha20_sse2_run; - -#else - - /* - * SSE2 support is indicated by bit 26 in EDX. - */ -#define MASK 0x04000000 - -#if BR_SSE2_GCC - unsigned eax, ebx, ecx, edx; - - if (__get_cpuid(1, &eax, &ebx, &ecx, &edx)) { - if ((edx & MASK) == MASK) { - return &br_chacha20_sse2_run; - } - } -#elif BR_SSE2_MSC - int info[4]; - - __cpuid(info, 1); - if (((uint32_t)info[3] & MASK) == MASK) { - return &br_chacha20_sse2_run; - } -#endif - return 0; - -#endif -} +BR_TARGETS_X86_DOWN #else