1*d6493dbbSRichard Henderson /* 2*d6493dbbSRichard Henderson * x86 specific clmul acceleration. 3*d6493dbbSRichard Henderson * SPDX-License-Identifier: GPL-2.0-or-later 4*d6493dbbSRichard Henderson */ 5*d6493dbbSRichard Henderson 6*d6493dbbSRichard Henderson #ifndef X86_HOST_CRYPTO_CLMUL_H 7*d6493dbbSRichard Henderson #define X86_HOST_CRYPTO_CLMUL_H 8*d6493dbbSRichard Henderson 9*d6493dbbSRichard Henderson #include "host/cpuinfo.h" 10*d6493dbbSRichard Henderson #include <immintrin.h> 11*d6493dbbSRichard Henderson 12*d6493dbbSRichard Henderson #if defined(__PCLMUL__) 13*d6493dbbSRichard Henderson # define HAVE_CLMUL_ACCEL true 14*d6493dbbSRichard Henderson # define ATTR_CLMUL_ACCEL 15*d6493dbbSRichard Henderson #else 16*d6493dbbSRichard Henderson # define HAVE_CLMUL_ACCEL likely(cpuinfo & CPUINFO_PCLMUL) 17*d6493dbbSRichard Henderson # define ATTR_CLMUL_ACCEL __attribute__((target("pclmul"))) 18*d6493dbbSRichard Henderson #endif 19*d6493dbbSRichard Henderson 20*d6493dbbSRichard Henderson static inline Int128 ATTR_CLMUL_ACCEL clmul_64_accel(uint64_t n,uint64_t m)21*d6493dbbSRichard Hendersonclmul_64_accel(uint64_t n, uint64_t m) 22*d6493dbbSRichard Henderson { 23*d6493dbbSRichard Henderson union { __m128i v; Int128 s; } u; 24*d6493dbbSRichard Henderson 25*d6493dbbSRichard Henderson u.v = _mm_clmulepi64_si128(_mm_set_epi64x(0, n), _mm_set_epi64x(0, m), 0); 26*d6493dbbSRichard Henderson return u.s; 27*d6493dbbSRichard Henderson } 28*d6493dbbSRichard Henderson 29*d6493dbbSRichard Henderson #endif /* X86_HOST_CRYPTO_CLMUL_H */ 30