gfniintrin.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*===----------------- gfniintrin.h - GFNI intrinsics ----------------------===
  2. *
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. * THE SOFTWARE.
  21. *
  22. *===-----------------------------------------------------------------------===
  23. */
  24. #ifndef __IMMINTRIN_H
  25. #error "Never use <gfniintrin.h> directly; include <immintrin.h> instead."
  26. #endif
  27. #ifndef __GFNIINTRIN_H
  28. #define __GFNIINTRIN_H
  29. #define _mm_gf2p8affineinv_epi64_epi8(A, B, I) __extension__ ({ \
  30. (__m128i)__builtin_ia32_vgf2p8affineinvqb_v16qi((__v16qi)(__m128i)(A), \
  31. (__v16qi)(__m128i)(B), \
  32. (char)(I)); })
  33. #define _mm_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) __extension__ ({ \
  34. (__m128i)__builtin_ia32_selectb_128((__mmask16)(U), \
  35. (__v16qi)_mm_gf2p8affineinv_epi64_epi8(A, B, I), \
  36. (__v16qi)(__m128i)(S)); })
  37. #define _mm_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) __extension__ ({ \
  38. (__m128i)_mm_mask_gf2p8affineinv_epi64_epi8((__m128i)_mm_setzero_si128(), \
  39. U, A, B, I); })
  40. #define _mm256_gf2p8affineinv_epi64_epi8(A, B, I) __extension__ ({ \
  41. (__m256i)__builtin_ia32_vgf2p8affineinvqb_v32qi((__v32qi)(__m256i)(A), \
  42. (__v32qi)(__m256i)(B), \
  43. (char)(I)); })
  44. #define _mm256_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) __extension__ ({ \
  45. (__m256i)__builtin_ia32_selectb_256((__mmask32)(U), \
  46. (__v32qi)_mm256_gf2p8affineinv_epi64_epi8(A, B, I), \
  47. (__v32qi)(__m256i)(S)); })
  48. #define _mm256_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) __extension__ ({ \
  49. (__m256i)_mm256_mask_gf2p8affineinv_epi64_epi8((__m256i)_mm256_setzero_si256(), \
  50. U, A, B, I); })
  51. #define _mm512_gf2p8affineinv_epi64_epi8(A, B, I) __extension__ ({ \
  52. (__m512i)__builtin_ia32_vgf2p8affineinvqb_v64qi((__v64qi)(__m512i)(A), \
  53. (__v64qi)(__m512i)(B), \
  54. (char)(I)); })
  55. #define _mm512_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) __extension__ ({ \
  56. (__m512i)__builtin_ia32_selectb_512((__mmask64)(U), \
  57. (__v64qi)_mm512_gf2p8affineinv_epi64_epi8(A, B, I), \
  58. (__v64qi)(__m512i)(S)); })
  59. #define _mm512_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) __extension__ ({ \
  60. (__m512i)_mm512_mask_gf2p8affineinv_epi64_epi8((__m512i)_mm512_setzero_qi(), \
  61. U, A, B, I); })
  62. #define _mm_gf2p8affine_epi64_epi8(A, B, I) __extension__ ({ \
  63. (__m128i)__builtin_ia32_vgf2p8affineqb_v16qi((__v16qi)(__m128i)(A), \
  64. (__v16qi)(__m128i)(B), \
  65. (char)(I)); })
  66. #define _mm_mask_gf2p8affine_epi64_epi8(S, U, A, B, I) __extension__ ({ \
  67. (__m128i)__builtin_ia32_selectb_128((__mmask16)(U), \
  68. (__v16qi)_mm_gf2p8affine_epi64_epi8(A, B, I), \
  69. (__v16qi)(__m128i)(S)); })
  70. #define _mm_maskz_gf2p8affine_epi64_epi8(U, A, B, I) __extension__ ({ \
  71. (__m128i)_mm_mask_gf2p8affine_epi64_epi8((__m128i)_mm_setzero_si128(), \
  72. U, A, B, I); })
  73. #define _mm256_gf2p8affine_epi64_epi8(A, B, I) __extension__ ({ \
  74. (__m256i)__builtin_ia32_vgf2p8affineqb_v32qi((__v32qi)(__m256i)(A), \
  75. (__v32qi)(__m256i)(B), \
  76. (char)(I)); })
  77. #define _mm256_mask_gf2p8affine_epi64_epi8(S, U, A, B, I) __extension__ ({ \
  78. (__m256i)__builtin_ia32_selectb_256((__mmask32)(U), \
  79. (__v32qi)_mm256_gf2p8affine_epi64_epi8(A, B, I), \
  80. (__v32qi)(__m256i)(S)); })
  81. #define _mm256_maskz_gf2p8affine_epi64_epi8(U, A, B, I) __extension__ ({ \
  82. (__m256i)_mm256_mask_gf2p8affine_epi64_epi8((__m256i)_mm256_setzero_si256(), \
  83. U, A, B, I); })
  84. #define _mm512_gf2p8affine_epi64_epi8(A, B, I) __extension__ ({ \
  85. (__m512i)__builtin_ia32_vgf2p8affineqb_v64qi((__v64qi)(__m512i)(A), \
  86. (__v64qi)(__m512i)(B), \
  87. (char)(I)); })
  88. #define _mm512_mask_gf2p8affine_epi64_epi8(S, U, A, B, I) __extension__ ({ \
  89. (__m512i)__builtin_ia32_selectb_512((__mmask64)(U), \
  90. (__v64qi)_mm512_gf2p8affine_epi64_epi8(A, B, I), \
  91. (__v64qi)(__m512i)(S)); })
  92. #define _mm512_maskz_gf2p8affine_epi64_epi8(U, A, B, I) __extension__ ({ \
  93. (__m512i)_mm512_mask_gf2p8affine_epi64_epi8((__m512i)_mm512_setzero_qi(), \
  94. U, A, B, I); })
  95. /* Default attributes for simple form (no masking). */
  96. #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("gfni")))
  97. /* Default attributes for ZMM forms. */
  98. #define __DEFAULT_FN_ATTRS_F __attribute__((__always_inline__, __nodebug__, __target__("avx512bw,gfni")))
  99. /* Default attributes for VLX forms. */
  100. #define __DEFAULT_FN_ATTRS_VL __attribute__((__always_inline__, __nodebug__, __target__("avx512bw,avx512vl,gfni")))
  101. static __inline__ __m128i __DEFAULT_FN_ATTRS
  102. _mm_gf2p8mul_epi8(__m128i __A, __m128i __B)
  103. {
  104. return (__m128i) __builtin_ia32_vgf2p8mulb_v16qi((__v16qi) __A,
  105. (__v16qi) __B);
  106. }
  107. static __inline__ __m128i __DEFAULT_FN_ATTRS_VL
  108. _mm_mask_gf2p8mul_epi8(__m128i __S, __mmask16 __U, __m128i __A, __m128i __B)
  109. {
  110. return (__m128i) __builtin_ia32_selectb_128(__U,
  111. (__v16qi) _mm_gf2p8mul_epi8(__A, __B),
  112. (__v16qi) __S);
  113. }
  114. static __inline__ __m128i __DEFAULT_FN_ATTRS_VL
  115. _mm_maskz_gf2p8mul_epi8(__mmask16 __U, __m128i __A, __m128i __B)
  116. {
  117. return _mm_mask_gf2p8mul_epi8((__m128i)_mm_setzero_si128(),
  118. __U, __A, __B);
  119. }
  120. static __inline__ __m256i __DEFAULT_FN_ATTRS
  121. _mm256_gf2p8mul_epi8(__m256i __A, __m256i __B)
  122. {
  123. return (__m256i) __builtin_ia32_vgf2p8mulb_v32qi((__v32qi) __A,
  124. (__v32qi) __B);
  125. }
  126. static __inline__ __m256i __DEFAULT_FN_ATTRS_VL
  127. _mm256_mask_gf2p8mul_epi8(__m256i __S, __mmask32 __U, __m256i __A, __m256i __B)
  128. {
  129. return (__m256i) __builtin_ia32_selectb_256(__U,
  130. (__v32qi) _mm256_gf2p8mul_epi8(__A, __B),
  131. (__v32qi) __S);
  132. }
  133. static __inline__ __m256i __DEFAULT_FN_ATTRS_VL
  134. _mm256_maskz_gf2p8mul_epi8(__mmask32 __U, __m256i __A, __m256i __B)
  135. {
  136. return _mm256_mask_gf2p8mul_epi8((__m256i)_mm256_setzero_si256(),
  137. __U, __A, __B);
  138. }
  139. static __inline__ __m512i __DEFAULT_FN_ATTRS_F
  140. _mm512_gf2p8mul_epi8(__m512i __A, __m512i __B)
  141. {
  142. return (__m512i) __builtin_ia32_vgf2p8mulb_v64qi((__v64qi) __A,
  143. (__v64qi) __B);
  144. }
  145. static __inline__ __m512i __DEFAULT_FN_ATTRS_F
  146. _mm512_mask_gf2p8mul_epi8(__m512i __S, __mmask64 __U, __m512i __A, __m512i __B)
  147. {
  148. return (__m512i) __builtin_ia32_selectb_512(__U,
  149. (__v64qi) _mm512_gf2p8mul_epi8(__A, __B),
  150. (__v64qi) __S);
  151. }
  152. static __inline__ __m512i __DEFAULT_FN_ATTRS_F
  153. _mm512_maskz_gf2p8mul_epi8(__mmask64 __U, __m512i __A, __m512i __B)
  154. {
  155. return _mm512_mask_gf2p8mul_epi8((__m512i)_mm512_setzero_qi(),
  156. __U, __A, __B);
  157. }
  158. #undef __DEFAULT_FN_ATTRS
  159. #undef __DEFAULT_FN_ATTRS_F
  160. #undef __DEFAULT_FN_ATTRS_VL
  161. #endif // __GFNIINTRIN_H