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