Home | History | Annotate | Download | only in clang-include
      1 /*===---- ammintrin.h - SSE4a intrinsics -----------------------------------===
      2  *
      3  * Permission is hereby granted, free of charge, to any person obtaining a copy
      4  * of this software and associated documentation files (the "Software"), to deal
      5  * in the Software without restriction, including without limitation the rights
      6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      7  * copies of the Software, and to permit persons to whom the Software is
      8  * furnished to do so, subject to the following conditions:
      9  *
     10  * The above copyright notice and this permission notice shall be included in
     11  * all copies or substantial portions of the Software.
     12  *
     13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     19  * THE SOFTWARE.
     20  *
     21  *===-----------------------------------------------------------------------===
     22  */
     23 
     24 #ifndef __AMMINTRIN_H
     25 #define __AMMINTRIN_H
     26 
     27 #include <pmmintrin.h>
     28 
     29 /* Define the default attributes for the functions in this file. */
     30 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("sse4a")))
     31 
     32 /// \brief Extracts the specified bits from the lower 64 bits of the 128-bit
     33 ///    integer vector operand at the index idx and of the length len.
     34 ///
     35 /// \headerfile <x86intrin.h>
     36 ///
     37 /// \code
     38 /// __m128i _mm_extracti_si64(__m128i x, const int len, const int idx);
     39 /// \endcode
     40 ///
     41 /// This intrinsic corresponds to the \c EXTRQ instruction.
     42 ///
     43 /// \param x
     44 ///    The value from which bits are extracted.
     45 /// \param len
     46 ///    Bits [5:0] specify the length; the other bits are ignored. If bits [5:0]
     47 ///    are zero, the length is interpreted as 64.
     48 /// \param idx
     49 ///    Bits [5:0] specify the index of the least significant bit; the other
     50 ///    bits are ignored. If the sum of the index and length is greater than 64,
     51 ///    the result is undefined. If the length and index are both zero, bits
     52 ///    [63:0] of parameter x are extracted. If the length is zero but the index
     53 ///    is non-zero, the result is undefined.
     54 /// \returns A 128-bit integer vector whose lower 64 bits contain the bits
     55 ///    extracted from the source operand.
     56 #define _mm_extracti_si64(x, len, idx) \
     57   ((__m128i)__builtin_ia32_extrqi((__v2di)(__m128i)(x), \
     58                                   (char)(len), (char)(idx)))
     59 
     60 /// \brief Extracts the specified bits from the lower 64 bits of the 128-bit
     61 ///    integer vector operand at the index and of the length specified by __y.
     62 ///
     63 /// \headerfile <x86intrin.h>
     64 ///
     65 /// This intrinsic corresponds to the \c EXTRQ instruction.
     66 ///
     67 /// \param __x
     68 ///    The value from which bits are extracted.
     69 /// \param __y
     70 ///    Specifies the index of the least significant bit at [13:8] and the
     71 ///    length at [5:0]; all other bits are ignored. If bits [5:0] are zero, the
     72 ///    length is interpreted as 64. If the sum of the index and length is
     73 ///    greater than 64, the result is undefined. If the length and index are
     74 ///    both zero, bits [63:0] of parameter __x are extracted. If the length is
     75 ///    zero but the index is non-zero, the result is undefined.
     76 /// \returns A 128-bit vector whose lower 64 bits contain the bits extracted
     77 ///    from the source operand.
     78 static __inline__ __m128i __DEFAULT_FN_ATTRS
     79 _mm_extract_si64(__m128i __x, __m128i __y)
     80 {
     81   return (__m128i)__builtin_ia32_extrq((__v2di)__x, (__v16qi)__y);
     82 }
     83 
     84 /// \brief Inserts bits of a specified length from the source integer vector y
     85 ///    into the lower 64 bits of the destination integer vector x at the index
     86 ///    idx and of the length len.
     87 ///
     88 /// \headerfile <x86intrin.h>
     89 ///
     90 /// \code
     91 /// __m128i _mm_inserti_si64(__m128i x, __m128i y, const int len,
     92 /// const int idx);
     93 /// \endcode
     94 ///
     95 /// This intrinsic corresponds to the \c INSERTQ instruction.
     96 ///
     97 /// \param x
     98 ///    The destination operand where bits will be inserted. The inserted bits
     99 ///    are defined by the length len and by the index idx specifying the least
    100 ///    significant bit.
    101 /// \param y
    102 ///    The source operand containing the bits to be extracted. The extracted
    103 ///    bits are the least significant bits of operand y of length len.
    104 /// \param len
    105 ///    Bits [5:0] specify the length; the other bits are ignored. If bits [5:0]
    106 ///    are zero, the length is interpreted as 64.
    107 /// \param idx
    108 ///    Bits [5:0] specify the index of the least significant bit; the other
    109 ///    bits are ignored. If the sum of the index and length is greater than 64,
    110 ///    the result is undefined. If the length and index are both zero, bits
    111 ///    [63:0] of parameter y are inserted into parameter x. If the length is
    112 ///    zero but the index is non-zero, the result is undefined.
    113 /// \returns A 128-bit integer vector containing the original lower 64-bits of
    114 ///    destination operand x with the specified bitfields replaced by the lower
    115 ///    bits of source operand y. The upper 64 bits of the return value are
    116 ///    undefined.
    117 
    118 #define _mm_inserti_si64(x, y, len, idx) \
    119   ((__m128i)__builtin_ia32_insertqi((__v2di)(__m128i)(x), \
    120                                     (__v2di)(__m128i)(y), \
    121                                     (char)(len), (char)(idx)))
    122 
    123 /// \brief Inserts bits of a specified length from the source integer vector
    124 ///    __y into the lower 64 bits of the destination integer vector __x at the
    125 ///    index and of the length specified by __y.
    126 ///
    127 /// \headerfile <x86intrin.h>
    128 ///
    129 /// This intrinsic corresponds to the \c INSERTQ instruction.
    130 ///
    131 /// \param __x
    132 ///    The destination operand where bits will be inserted. The inserted bits
    133 ///    are defined by the length and by the index of the least significant bit
    134 ///    specified by operand __y.
    135 /// \param __y
    136 ///    The source operand containing the bits to be extracted. The extracted
    137 ///    bits are the least significant bits of operand __y with length specified
    138 ///    by bits [69:64]. These are inserted into the destination at the index
    139 ///    specified by bits [77:72]; all other bits are ignored. If bits [69:64]
    140 ///    are zero, the length is interpreted as 64. If the sum of the index and
    141 ///    length is greater than 64, the result is undefined. If the length and
    142 ///    index are both zero, bits [63:0] of parameter __y are inserted into
    143 ///    parameter __x. If the length is zero but the index is non-zero, the
    144 ///    result is undefined.
    145 /// \returns A 128-bit integer vector containing the original lower 64-bits of
    146 ///    destination operand __x with the specified bitfields replaced by the
    147 ///    lower bits of source operand __y. The upper 64 bits of the return value
    148 ///    are undefined.
    149 
    150 static __inline__ __m128i __DEFAULT_FN_ATTRS
    151 _mm_insert_si64(__m128i __x, __m128i __y)
    152 {
    153   return (__m128i)__builtin_ia32_insertq((__v2di)__x, (__v2di)__y);
    154 }
    155 
    156 /// \brief Stores a 64-bit double-precision value in a 64-bit memory location.
    157 ///    To minimize caching, the data is flagged as non-temporal (unlikely to be
    158 ///    used again soon).
    159 ///
    160 /// \headerfile <x86intrin.h>
    161 ///
    162 /// This intrinsic corresponds to the \c MOVNTSD instruction.
    163 ///
    164 /// \param __p
    165 ///    The 64-bit memory location used to store the register value.
    166 /// \param __a
    167 ///    The 64-bit double-precision floating-point register value to be stored.
    168 static __inline__ void __DEFAULT_FN_ATTRS
    169 _mm_stream_sd(double *__p, __m128d __a)
    170 {
    171   __builtin_ia32_movntsd(__p, (__v2df)__a);
    172 }
    173 
    174 /// \brief Stores a 32-bit single-precision floating-point value in a 32-bit
    175 ///    memory location. To minimize caching, the data is flagged as
    176 ///    non-temporal (unlikely to be used again soon).
    177 ///
    178 /// \headerfile <x86intrin.h>
    179 ///
    180 /// This intrinsic corresponds to the \c MOVNTSS instruction.
    181 ///
    182 /// \param __p
    183 ///    The 32-bit memory location used to store the register value.
    184 /// \param __a
    185 ///    The 32-bit single-precision floating-point register value to be stored.
    186 static __inline__ void __DEFAULT_FN_ATTRS
    187 _mm_stream_ss(float *__p, __m128 __a)
    188 {
    189   __builtin_ia32_movntss(__p, (__v4sf)__a);
    190 }
    191 
    192 #undef __DEFAULT_FN_ATTRS
    193 
    194 #endif /* __AMMINTRIN_H */
    195