wmmintrin.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* Copyright (C) 2008-2019 Free Software Foundation, Inc.
  2. This file is part of GCC.
  3. GCC is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3, or (at your option)
  6. any later version.
  7. GCC is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. Under Section 7 of GPL version 3, you are granted additional
  12. permissions described in the GCC Runtime Library Exception, version
  13. 3.1, as published by the Free Software Foundation.
  14. You should have received a copy of the GNU General Public License and
  15. a copy of the GCC Runtime Library Exception along with this program;
  16. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  17. <http://www.gnu.org/licenses/>. */
  18. /* Implemented from the specification included in the Intel C++ Compiler
  19. User Guide and Reference, version 10.1. */
  20. #ifndef _WMMINTRIN_H_INCLUDED
  21. #define _WMMINTRIN_H_INCLUDED
  22. /* We need definitions from the SSE2 header file. */
  23. #include <emmintrin.h>
  24. /* AES */
  25. #if !defined(__AES__) || !defined(__SSE2__)
  26. #pragma GCC push_options
  27. #pragma GCC target("aes,sse2")
  28. #define __DISABLE_AES__
  29. #endif /* __AES__ */
  30. /* Performs 1 round of AES decryption of the first m128i using
  31. the second m128i as a round key. */
  32. extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  33. _mm_aesdec_si128 (__m128i __X, __m128i __Y)
  34. {
  35. return (__m128i) __builtin_ia32_aesdec128 ((__v2di)__X, (__v2di)__Y);
  36. }
  37. /* Performs the last round of AES decryption of the first m128i
  38. using the second m128i as a round key. */
  39. extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  40. _mm_aesdeclast_si128 (__m128i __X, __m128i __Y)
  41. {
  42. return (__m128i) __builtin_ia32_aesdeclast128 ((__v2di)__X,
  43. (__v2di)__Y);
  44. }
  45. /* Performs 1 round of AES encryption of the first m128i using
  46. the second m128i as a round key. */
  47. extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  48. _mm_aesenc_si128 (__m128i __X, __m128i __Y)
  49. {
  50. return (__m128i) __builtin_ia32_aesenc128 ((__v2di)__X, (__v2di)__Y);
  51. }
  52. /* Performs the last round of AES encryption of the first m128i
  53. using the second m128i as a round key. */
  54. extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  55. _mm_aesenclast_si128 (__m128i __X, __m128i __Y)
  56. {
  57. return (__m128i) __builtin_ia32_aesenclast128 ((__v2di)__X, (__v2di)__Y);
  58. }
  59. /* Performs the InverseMixColumn operation on the source m128i
  60. and stores the result into m128i destination. */
  61. extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  62. _mm_aesimc_si128 (__m128i __X)
  63. {
  64. return (__m128i) __builtin_ia32_aesimc128 ((__v2di)__X);
  65. }
  66. /* Generates a m128i round key for the input m128i AES cipher key and
  67. byte round constant. The second parameter must be a compile time
  68. constant. */
  69. #ifdef __OPTIMIZE__
  70. extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  71. _mm_aeskeygenassist_si128 (__m128i __X, const int __C)
  72. {
  73. return (__m128i) __builtin_ia32_aeskeygenassist128 ((__v2di)__X, __C);
  74. }
  75. #else
  76. #define _mm_aeskeygenassist_si128(X, C) \
  77. ((__m128i) __builtin_ia32_aeskeygenassist128 ((__v2di)(__m128i)(X), \
  78. (int)(C)))
  79. #endif
  80. #ifdef __DISABLE_AES__
  81. #undef __DISABLE_AES__
  82. #pragma GCC pop_options
  83. #endif /* __DISABLE_AES__ */
  84. /* PCLMUL */
  85. #if !defined(__PCLMUL__) || !defined(__SSE2__)
  86. #pragma GCC push_options
  87. #pragma GCC target("pclmul,sse2")
  88. #define __DISABLE_PCLMUL__
  89. #endif /* __PCLMUL__ */
  90. /* Performs carry-less integer multiplication of 64-bit halves of
  91. 128-bit input operands. The third parameter inducates which 64-bit
  92. haves of the input parameters v1 and v2 should be used. It must be
  93. a compile time constant. */
  94. #ifdef __OPTIMIZE__
  95. extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  96. _mm_clmulepi64_si128 (__m128i __X, __m128i __Y, const int __I)
  97. {
  98. return (__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)__X,
  99. (__v2di)__Y, __I);
  100. }
  101. #else
  102. #define _mm_clmulepi64_si128(X, Y, I) \
  103. ((__m128i) __builtin_ia32_pclmulqdq128 ((__v2di)(__m128i)(X), \
  104. (__v2di)(__m128i)(Y), (int)(I)))
  105. #endif
  106. #ifdef __DISABLE_PCLMUL__
  107. #undef __DISABLE_PCLMUL__
  108. #pragma GCC pop_options
  109. #endif /* __DISABLE_PCLMUL__ */
  110. #endif /* _WMMINTRIN_H_INCLUDED */