10b57cec5SDimitry Andric /*===----------------- gfniintrin.h - GFNI intrinsics ----------------------=== 20b57cec5SDimitry Andric * 30b57cec5SDimitry Andric * 40b57cec5SDimitry Andric * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric * See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric * 80b57cec5SDimitry Andric *===-----------------------------------------------------------------------=== 90b57cec5SDimitry Andric */ 100b57cec5SDimitry Andric #ifndef __IMMINTRIN_H 110b57cec5SDimitry Andric #error "Never use <gfniintrin.h> directly; include <immintrin.h> instead." 120b57cec5SDimitry Andric #endif 130b57cec5SDimitry Andric 140b57cec5SDimitry Andric #ifndef __GFNIINTRIN_H 150b57cec5SDimitry Andric #define __GFNIINTRIN_H 160b57cec5SDimitry Andric 17e8d8bef9SDimitry Andric /* Default attributes for simple form (no masking). */ 18*5f757f3fSDimitry Andric #define __DEFAULT_FN_ATTRS \ 19*5f757f3fSDimitry Andric __attribute__((__always_inline__, __nodebug__, \ 20*5f757f3fSDimitry Andric __target__("gfni,no-evex512"), __min_vector_width__(128))) 21e8d8bef9SDimitry Andric 22e8d8bef9SDimitry Andric /* Default attributes for YMM unmasked form. */ 23*5f757f3fSDimitry Andric #define __DEFAULT_FN_ATTRS_Y \ 24*5f757f3fSDimitry Andric __attribute__((__always_inline__, __nodebug__, \ 25*5f757f3fSDimitry Andric __target__("avx,gfni,no-evex512"), \ 26*5f757f3fSDimitry Andric __min_vector_width__(256))) 27e8d8bef9SDimitry Andric 28bdd1243dSDimitry Andric /* Default attributes for ZMM unmasked forms. */ 29*5f757f3fSDimitry Andric #define __DEFAULT_FN_ATTRS_Z \ 30*5f757f3fSDimitry Andric __attribute__((__always_inline__, __nodebug__, \ 31*5f757f3fSDimitry Andric __target__("avx512f,evex512,gfni"), \ 32*5f757f3fSDimitry Andric __min_vector_width__(512))) 33bdd1243dSDimitry Andric /* Default attributes for ZMM masked forms. */ 34*5f757f3fSDimitry Andric #define __DEFAULT_FN_ATTRS_Z_MASK \ 35*5f757f3fSDimitry Andric __attribute__((__always_inline__, __nodebug__, \ 36*5f757f3fSDimitry Andric __target__("avx512bw,evex512,gfni"), \ 37*5f757f3fSDimitry Andric __min_vector_width__(512))) 38e8d8bef9SDimitry Andric 39bdd1243dSDimitry Andric /* Default attributes for VLX masked forms. */ 40*5f757f3fSDimitry Andric #define __DEFAULT_FN_ATTRS_VL128 \ 41*5f757f3fSDimitry Andric __attribute__((__always_inline__, __nodebug__, \ 42*5f757f3fSDimitry Andric __target__("avx512bw,avx512vl,gfni,no-evex512"), \ 43*5f757f3fSDimitry Andric __min_vector_width__(128))) 44*5f757f3fSDimitry Andric #define __DEFAULT_FN_ATTRS_VL256 \ 45*5f757f3fSDimitry Andric __attribute__((__always_inline__, __nodebug__, \ 46*5f757f3fSDimitry Andric __target__("avx512bw,avx512vl,gfni,no-evex512"), \ 47*5f757f3fSDimitry Andric __min_vector_width__(256))) 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric #define _mm_gf2p8affineinv_epi64_epi8(A, B, I) \ 50349cc55cSDimitry Andric ((__m128i)__builtin_ia32_vgf2p8affineinvqb_v16qi((__v16qi)(__m128i)(A), \ 510b57cec5SDimitry Andric (__v16qi)(__m128i)(B), \ 52349cc55cSDimitry Andric (char)(I))) 530b57cec5SDimitry Andric 54e8d8bef9SDimitry Andric #define _mm_gf2p8affine_epi64_epi8(A, B, I) \ 55349cc55cSDimitry Andric ((__m128i)__builtin_ia32_vgf2p8affineqb_v16qi((__v16qi)(__m128i)(A), \ 56e8d8bef9SDimitry Andric (__v16qi)(__m128i)(B), \ 57349cc55cSDimitry Andric (char)(I))) 580b57cec5SDimitry Andric 59e8d8bef9SDimitry Andric static __inline__ __m128i __DEFAULT_FN_ATTRS 60e8d8bef9SDimitry Andric _mm_gf2p8mul_epi8(__m128i __A, __m128i __B) 61e8d8bef9SDimitry Andric { 62e8d8bef9SDimitry Andric return (__m128i) __builtin_ia32_vgf2p8mulb_v16qi((__v16qi) __A, 63e8d8bef9SDimitry Andric (__v16qi) __B); 64e8d8bef9SDimitry Andric } 650b57cec5SDimitry Andric 66e8d8bef9SDimitry Andric #ifdef __AVXINTRIN_H 670b57cec5SDimitry Andric #define _mm256_gf2p8affineinv_epi64_epi8(A, B, I) \ 68349cc55cSDimitry Andric ((__m256i)__builtin_ia32_vgf2p8affineinvqb_v32qi((__v32qi)(__m256i)(A), \ 690b57cec5SDimitry Andric (__v32qi)(__m256i)(B), \ 70349cc55cSDimitry Andric (char)(I))) 710b57cec5SDimitry Andric 72e8d8bef9SDimitry Andric #define _mm256_gf2p8affine_epi64_epi8(A, B, I) \ 73349cc55cSDimitry Andric ((__m256i)__builtin_ia32_vgf2p8affineqb_v32qi((__v32qi)(__m256i)(A), \ 74e8d8bef9SDimitry Andric (__v32qi)(__m256i)(B), \ 75349cc55cSDimitry Andric (char)(I))) 760b57cec5SDimitry Andric 77e8d8bef9SDimitry Andric static __inline__ __m256i __DEFAULT_FN_ATTRS_Y 78e8d8bef9SDimitry Andric _mm256_gf2p8mul_epi8(__m256i __A, __m256i __B) 79e8d8bef9SDimitry Andric { 80e8d8bef9SDimitry Andric return (__m256i) __builtin_ia32_vgf2p8mulb_v32qi((__v32qi) __A, 81e8d8bef9SDimitry Andric (__v32qi) __B); 82e8d8bef9SDimitry Andric } 83e8d8bef9SDimitry Andric #endif /* __AVXINTRIN_H */ 840b57cec5SDimitry Andric 85e8d8bef9SDimitry Andric #ifdef __AVX512BWINTRIN_H 860b57cec5SDimitry Andric #define _mm512_gf2p8affineinv_epi64_epi8(A, B, I) \ 87349cc55cSDimitry Andric ((__m512i)__builtin_ia32_vgf2p8affineinvqb_v64qi((__v64qi)(__m512i)(A), \ 880b57cec5SDimitry Andric (__v64qi)(__m512i)(B), \ 89349cc55cSDimitry Andric (char)(I))) 900b57cec5SDimitry Andric 910b57cec5SDimitry Andric #define _mm512_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) \ 92349cc55cSDimitry Andric ((__m512i)__builtin_ia32_selectb_512((__mmask64)(U), \ 930b57cec5SDimitry Andric (__v64qi)_mm512_gf2p8affineinv_epi64_epi8(A, B, I), \ 94349cc55cSDimitry Andric (__v64qi)(__m512i)(S))) 950b57cec5SDimitry Andric 960b57cec5SDimitry Andric #define _mm512_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) \ 97349cc55cSDimitry Andric _mm512_mask_gf2p8affineinv_epi64_epi8((__m512i)_mm512_setzero_si512(), \ 980b57cec5SDimitry Andric U, A, B, I) 990b57cec5SDimitry Andric 1000b57cec5SDimitry Andric #define _mm512_gf2p8affine_epi64_epi8(A, B, I) \ 101349cc55cSDimitry Andric ((__m512i)__builtin_ia32_vgf2p8affineqb_v64qi((__v64qi)(__m512i)(A), \ 1020b57cec5SDimitry Andric (__v64qi)(__m512i)(B), \ 103349cc55cSDimitry Andric (char)(I))) 1040b57cec5SDimitry Andric 1050b57cec5SDimitry Andric #define _mm512_mask_gf2p8affine_epi64_epi8(S, U, A, B, I) \ 106349cc55cSDimitry Andric ((__m512i)__builtin_ia32_selectb_512((__mmask64)(U), \ 107349cc55cSDimitry Andric (__v64qi)_mm512_gf2p8affine_epi64_epi8((A), (B), (I)), \ 108349cc55cSDimitry Andric (__v64qi)(__m512i)(S))) 1090b57cec5SDimitry Andric 1100b57cec5SDimitry Andric #define _mm512_maskz_gf2p8affine_epi64_epi8(U, A, B, I) \ 111349cc55cSDimitry Andric _mm512_mask_gf2p8affine_epi64_epi8((__m512i)_mm512_setzero_si512(), \ 1120b57cec5SDimitry Andric U, A, B, I) 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric static __inline__ __m512i __DEFAULT_FN_ATTRS_Z 1150b57cec5SDimitry Andric _mm512_gf2p8mul_epi8(__m512i __A, __m512i __B) 1160b57cec5SDimitry Andric { 1170b57cec5SDimitry Andric return (__m512i) __builtin_ia32_vgf2p8mulb_v64qi((__v64qi) __A, 1180b57cec5SDimitry Andric (__v64qi) __B); 1190b57cec5SDimitry Andric } 1200b57cec5SDimitry Andric 121bdd1243dSDimitry Andric static __inline__ __m512i __DEFAULT_FN_ATTRS_Z_MASK 1220b57cec5SDimitry Andric _mm512_mask_gf2p8mul_epi8(__m512i __S, __mmask64 __U, __m512i __A, __m512i __B) 1230b57cec5SDimitry Andric { 1240b57cec5SDimitry Andric return (__m512i) __builtin_ia32_selectb_512(__U, 1250b57cec5SDimitry Andric (__v64qi) _mm512_gf2p8mul_epi8(__A, __B), 1260b57cec5SDimitry Andric (__v64qi) __S); 1270b57cec5SDimitry Andric } 1280b57cec5SDimitry Andric 129bdd1243dSDimitry Andric static __inline__ __m512i __DEFAULT_FN_ATTRS_Z_MASK 1300b57cec5SDimitry Andric _mm512_maskz_gf2p8mul_epi8(__mmask64 __U, __m512i __A, __m512i __B) 1310b57cec5SDimitry Andric { 1320b57cec5SDimitry Andric return _mm512_mask_gf2p8mul_epi8((__m512i)_mm512_setzero_si512(), 1330b57cec5SDimitry Andric __U, __A, __B); 1340b57cec5SDimitry Andric } 135e8d8bef9SDimitry Andric #endif /* __AVX512BWINTRIN_H */ 136e8d8bef9SDimitry Andric 137e8d8bef9SDimitry Andric #ifdef __AVX512VLBWINTRIN_H 138e8d8bef9SDimitry Andric #define _mm_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) \ 139349cc55cSDimitry Andric ((__m128i)__builtin_ia32_selectb_128((__mmask16)(U), \ 140e8d8bef9SDimitry Andric (__v16qi)_mm_gf2p8affineinv_epi64_epi8(A, B, I), \ 141349cc55cSDimitry Andric (__v16qi)(__m128i)(S))) 142e8d8bef9SDimitry Andric 143e8d8bef9SDimitry Andric #define _mm_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) \ 144349cc55cSDimitry Andric _mm_mask_gf2p8affineinv_epi64_epi8((__m128i)_mm_setzero_si128(), \ 145e8d8bef9SDimitry Andric U, A, B, I) 146e8d8bef9SDimitry Andric 147e8d8bef9SDimitry Andric #define _mm256_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) \ 148349cc55cSDimitry Andric ((__m256i)__builtin_ia32_selectb_256((__mmask32)(U), \ 149e8d8bef9SDimitry Andric (__v32qi)_mm256_gf2p8affineinv_epi64_epi8(A, B, I), \ 150349cc55cSDimitry Andric (__v32qi)(__m256i)(S))) 151e8d8bef9SDimitry Andric 152e8d8bef9SDimitry Andric #define _mm256_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) \ 153349cc55cSDimitry Andric _mm256_mask_gf2p8affineinv_epi64_epi8((__m256i)_mm256_setzero_si256(), \ 154e8d8bef9SDimitry Andric U, A, B, I) 155e8d8bef9SDimitry Andric 156e8d8bef9SDimitry Andric #define _mm_mask_gf2p8affine_epi64_epi8(S, U, A, B, I) \ 157349cc55cSDimitry Andric ((__m128i)__builtin_ia32_selectb_128((__mmask16)(U), \ 158e8d8bef9SDimitry Andric (__v16qi)_mm_gf2p8affine_epi64_epi8(A, B, I), \ 159349cc55cSDimitry Andric (__v16qi)(__m128i)(S))) 160e8d8bef9SDimitry Andric 161e8d8bef9SDimitry Andric #define _mm_maskz_gf2p8affine_epi64_epi8(U, A, B, I) \ 162349cc55cSDimitry Andric _mm_mask_gf2p8affine_epi64_epi8((__m128i)_mm_setzero_si128(), U, A, B, I) 163e8d8bef9SDimitry Andric 164e8d8bef9SDimitry Andric #define _mm256_mask_gf2p8affine_epi64_epi8(S, U, A, B, I) \ 165349cc55cSDimitry Andric ((__m256i)__builtin_ia32_selectb_256((__mmask32)(U), \ 166e8d8bef9SDimitry Andric (__v32qi)_mm256_gf2p8affine_epi64_epi8(A, B, I), \ 167349cc55cSDimitry Andric (__v32qi)(__m256i)(S))) 168e8d8bef9SDimitry Andric 169e8d8bef9SDimitry Andric #define _mm256_maskz_gf2p8affine_epi64_epi8(U, A, B, I) \ 170349cc55cSDimitry Andric _mm256_mask_gf2p8affine_epi64_epi8((__m256i)_mm256_setzero_si256(), \ 171e8d8bef9SDimitry Andric U, A, B, I) 172e8d8bef9SDimitry Andric 173e8d8bef9SDimitry Andric static __inline__ __m128i __DEFAULT_FN_ATTRS_VL128 174e8d8bef9SDimitry Andric _mm_mask_gf2p8mul_epi8(__m128i __S, __mmask16 __U, __m128i __A, __m128i __B) 175e8d8bef9SDimitry Andric { 176e8d8bef9SDimitry Andric return (__m128i) __builtin_ia32_selectb_128(__U, 177e8d8bef9SDimitry Andric (__v16qi) _mm_gf2p8mul_epi8(__A, __B), 178e8d8bef9SDimitry Andric (__v16qi) __S); 179e8d8bef9SDimitry Andric } 180e8d8bef9SDimitry Andric 181e8d8bef9SDimitry Andric static __inline__ __m128i __DEFAULT_FN_ATTRS_VL128 182e8d8bef9SDimitry Andric _mm_maskz_gf2p8mul_epi8(__mmask16 __U, __m128i __A, __m128i __B) 183e8d8bef9SDimitry Andric { 184e8d8bef9SDimitry Andric return _mm_mask_gf2p8mul_epi8((__m128i)_mm_setzero_si128(), 185e8d8bef9SDimitry Andric __U, __A, __B); 186e8d8bef9SDimitry Andric } 187e8d8bef9SDimitry Andric 188e8d8bef9SDimitry Andric static __inline__ __m256i __DEFAULT_FN_ATTRS_VL256 189e8d8bef9SDimitry Andric _mm256_mask_gf2p8mul_epi8(__m256i __S, __mmask32 __U, __m256i __A, __m256i __B) 190e8d8bef9SDimitry Andric { 191e8d8bef9SDimitry Andric return (__m256i) __builtin_ia32_selectb_256(__U, 192e8d8bef9SDimitry Andric (__v32qi) _mm256_gf2p8mul_epi8(__A, __B), 193e8d8bef9SDimitry Andric (__v32qi) __S); 194e8d8bef9SDimitry Andric } 195e8d8bef9SDimitry Andric 196e8d8bef9SDimitry Andric static __inline__ __m256i __DEFAULT_FN_ATTRS_VL256 197e8d8bef9SDimitry Andric _mm256_maskz_gf2p8mul_epi8(__mmask32 __U, __m256i __A, __m256i __B) 198e8d8bef9SDimitry Andric { 199e8d8bef9SDimitry Andric return _mm256_mask_gf2p8mul_epi8((__m256i)_mm256_setzero_si256(), 200e8d8bef9SDimitry Andric __U, __A, __B); 201e8d8bef9SDimitry Andric } 202e8d8bef9SDimitry Andric #endif /* __AVX512VLBWINTRIN_H */ 2030b57cec5SDimitry Andric 2040b57cec5SDimitry Andric #undef __DEFAULT_FN_ATTRS 2050b57cec5SDimitry Andric #undef __DEFAULT_FN_ATTRS_Y 2060b57cec5SDimitry Andric #undef __DEFAULT_FN_ATTRS_Z 2070b57cec5SDimitry Andric #undef __DEFAULT_FN_ATTRS_VL128 2080b57cec5SDimitry Andric #undef __DEFAULT_FN_ATTRS_VL256 2090b57cec5SDimitry Andric 2100b57cec5SDimitry Andric #endif /* __GFNIINTRIN_H */ 2110b57cec5SDimitry Andric 212