Home | History | Annotate | Download | only in include
      1 /* Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
      2 
      3    This file is part of GCC.
      4 
      5    GCC is free software; you can redistribute it and/or modify
      6    it under the terms of the GNU General Public License as published by
      7    the Free Software Foundation; either version 3, or (at your option)
      8    any later version.
      9 
     10    GCC is distributed in the hope that it will be useful,
     11    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13    GNU General Public License for more details.
     14 
     15    Under Section 7 of GPL version 3, you are granted additional
     16    permissions described in the GCC Runtime Library Exception, version
     17    3.1, as published by the Free Software Foundation.
     18 
     19    You should have received a copy of the GNU General Public License and
     20    a copy of the GCC Runtime Library Exception along with this program;
     21    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     22    <http://www.gnu.org/licenses/>.  */
     23 
     24 #ifndef _IMMINTRIN_H_INCLUDED
     25 #define _IMMINTRIN_H_INCLUDED
     26 
     27 #ifdef __MMX__
     28 #include <mmintrin.h>
     29 #endif
     30 
     31 #ifdef __SSE__
     32 #include <xmmintrin.h>
     33 #endif
     34 
     35 #ifdef __SSE2__
     36 #include <emmintrin.h>
     37 #endif
     38 
     39 #ifdef __SSE3__
     40 #include <pmmintrin.h>
     41 #endif
     42 
     43 #ifdef __SSSE3__
     44 #include <tmmintrin.h>
     45 #endif
     46 
     47 #if defined (__SSE4_2__) || defined (__SSE4_1__)
     48 #include <smmintrin.h>
     49 #endif
     50 
     51 #if defined (__AES__) || defined (__PCLMUL__)
     52 #include <wmmintrin.h>
     53 #endif
     54 
     55 #ifdef __AVX__
     56 #include <avxintrin.h>
     57 #endif
     58 
     59 #ifdef __RDRND__
     60 extern __inline int
     61 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
     62 _rdrand16_step (unsigned short *__P)
     63 {
     64   return __builtin_ia32_rdrand16_step (__P);
     65 }
     66 
     67 extern __inline int
     68 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
     69 _rdrand32_step (unsigned int *__P)
     70 {
     71   return __builtin_ia32_rdrand32_step (__P);
     72 }
     73 #endif /* __RDRND__ */
     74 
     75 #ifdef  __x86_64__
     76 #ifdef __FSGSBASE__
     77 extern __inline unsigned int
     78 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
     79 _readfsbase_u32 (void)
     80 {
     81   return __builtin_ia32_rdfsbase32 ();
     82 }
     83 
     84 extern __inline unsigned long long
     85 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
     86 _readfsbase_u64 (void)
     87 {
     88   return __builtin_ia32_rdfsbase64 ();
     89 }
     90 
     91 extern __inline unsigned int
     92 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
     93 _readgsbase_u32 (void)
     94 {
     95   return __builtin_ia32_rdgsbase32 ();
     96 }
     97 
     98 extern __inline unsigned long long
     99 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
    100 _readgsbase_u64 (void)
    101 {
    102   return __builtin_ia32_rdgsbase64 ();
    103 }
    104 
    105 extern __inline void
    106 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
    107 _writefsbase_u32 (unsigned int __B)
    108 {
    109   __builtin_ia32_wrfsbase32 (__B);
    110 }
    111 
    112 extern __inline void
    113 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
    114 _writefsbase_u64 (unsigned long long __B)
    115 {
    116   __builtin_ia32_wrfsbase64 (__B);
    117 }
    118 
    119 extern __inline void
    120 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
    121 _writegsbase_u32 (unsigned int __B)
    122 {
    123   __builtin_ia32_wrgsbase32 (__B);
    124 }
    125 
    126 extern __inline void
    127 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
    128 _writegsbase_u64 (unsigned long long __B)
    129 {
    130   __builtin_ia32_wrgsbase64 (__B);
    131 }
    132 #endif /* __FSGSBASE__ */
    133 
    134 #ifdef __RDRND__
    135 extern __inline int
    136 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
    137 _rdrand64_step (unsigned long long *__P)
    138 {
    139   return __builtin_ia32_rdrand64_step (__P);
    140 }
    141 #endif /* __RDRND__ */
    142 #endif /* __x86_64__  */
    143 
    144 #ifdef __F16C__
    145 extern __inline float __attribute__((__gnu_inline__, __always_inline__, __artificial__))
    146 _cvtsh_ss (unsigned short __S)
    147 {
    148   __v8hi __H = __extension__ (__v8hi){ __S, 0, 0, 0, 0, 0, 0, 0 };
    149   __v4sf __A = __builtin_ia32_vcvtph2ps (__H);
    150   return __builtin_ia32_vec_ext_v4sf (__A, 0);
    151 }
    152 
    153 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
    154 _mm_cvtph_ps (__m128i __A)
    155 {
    156   return (__m128) __builtin_ia32_vcvtph2ps ((__v8hi) __A);
    157 }
    158 
    159 extern __inline __m256 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
    160 _mm256_cvtph_ps (__m128i __A)
    161 {
    162   return (__m256) __builtin_ia32_vcvtph2ps256 ((__v8hi) __A);
    163 }
    164 
    165 #ifdef __OPTIMIZE__
    166 extern __inline unsigned short __attribute__((__gnu_inline__, __always_inline__, __artificial__))
    167 _cvtss_sh (float __F, const int __I)
    168 {
    169   __v4sf __A =  __extension__ (__v4sf){ __F, 0, 0, 0 };
    170   __v8hi __H = __builtin_ia32_vcvtps2ph (__A, __I);
    171   return (unsigned short) __builtin_ia32_vec_ext_v8hi (__H, 0);
    172 }
    173 
    174 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
    175 _mm_cvtps_ph (__m128 __A, const int __I)
    176 {
    177   return (__m128i) __builtin_ia32_vcvtps2ph ((__v4sf) __A, __I);
    178 }
    179 
    180 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
    181 _mm256_cvtps_ph (__m256 __A, const int __I)
    182 {
    183   return (__m128i) __builtin_ia32_vcvtps2ph256 ((__v8sf) __A, __I);
    184 }
    185 #else
    186 #define _cvtss_sh(__F, __I)						\
    187   (__extension__ 							\
    188    ({									\
    189       __v4sf __A =  __extension__ (__v4sf){ __F, 0, 0, 0 };		\
    190       __v8hi __H = __builtin_ia32_vcvtps2ph (__A, __I);			\
    191       (unsigned short) __builtin_ia32_vec_ext_v8hi (__H, 0);		\
    192     }))
    193 
    194 #define _mm_cvtps_ph(A, I) \
    195   ((__m128i) __builtin_ia32_vcvtps2ph ((__v4sf)(__m128) A, (int) (I)))
    196 
    197 #define _mm256_cvtps_ph(A, I) \
    198   ((__m128i) __builtin_ia32_vcvtps2ph256 ((__v8sf)(__m256) A, (int) (I)))
    199 #endif
    200 
    201 #endif /* __F16C__ */
    202 
    203 #endif /* _IMMINTRIN_H_INCLUDED */
    204