zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

blob 4d0e770f (8692B) - Raw


      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 #ifndef __SSE4A__
     28 #error "SSE4A instruction set not enabled"
     29 #else
     30 
     31 #include <pmmintrin.h>
     32 
     33 /* Define the default attributes for the functions in this file. */
     34 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
     35 
     36 /// \brief Extracts the specified bits from the lower 64 bits of the 128-bit
     37 ///    integer vector operand at the index idx and of the length len.
     38 ///
     39 /// \headerfile <x86intrin.h>
     40 ///
     41 /// \code 
     42 /// __m128i _mm_extracti_si64(__m128i x, const int len, const int idx);
     43 /// \endcode 
     44 ///
     45 /// \code                                                    
     46 /// This intrinsic corresponds to the \c EXTRQ instruction.
     47 /// \endcode 
     48 ///
     49 /// \param x
     50 ///    The value from which bits are extracted.
     51 /// \param len
     52 ///    Bits [5:0] specify the length; the other bits are ignored. If bits [5:0]
     53 ///    are zero, the length is interpreted as 64.
     54 /// \param idx
     55 ///    Bits [5:0] specify the index of the least significant bit; the other 
     56 ///    bits are ignored. If the sum of the index and length is greater than 
     57 ///    64, the result is undefined. If the length and index are both zero, 
     58 ///    bits [63:0] of parameter x are extracted. If the length is zero 
     59 ///    but the index is non-zero, the result is undefined.
     60 /// \returns A 128-bit integer vector whose lower 64 bits contain the bits
     61 ///    extracted from the source operand.
     62 #define _mm_extracti_si64(x, len, idx) \
     63   ((__m128i)__builtin_ia32_extrqi((__v2di)(__m128i)(x), \
     64                                   (char)(len), (char)(idx)))
     65 
     66 /// \brief Extracts the specified bits from the lower 64 bits of the 128-bit
     67 ///    integer vector operand at the index and of the length specified by __y.
     68 ///
     69 /// \headerfile <x86intrin.h>
     70 ///
     71 /// \code 
     72 /// This intrinsic corresponds to the \c EXTRQ instruction.
     73 /// \endcode 
     74 ///
     75 /// \param __x
     76 ///    The value from which bits are extracted.
     77 /// \param __y
     78 ///    Specifies the index of the least significant bit at [13:8] 
     79 ///    and the length at [5:0]; all other bits are ignored. 
     80 ///    If bits [5:0] are zero, the length is interpreted as 64.
     81 ///    If the sum of the index and length is greater than 64, the result is 
     82 ///    undefined. If the length and index are both zero, bits [63:0] of 
     83 ///    parameter __x are extracted. If the length is zero but the index is 
     84 ///    non-zero, the result is undefined. 
     85 /// \returns A 128-bit vector whose lower 64 bits contain the bits extracted 
     86 ///    from the source operand.
     87 static __inline__ __m128i __DEFAULT_FN_ATTRS
     88 _mm_extract_si64(__m128i __x, __m128i __y)
     89 {
     90   return (__m128i)__builtin_ia32_extrq((__v2di)__x, (__v16qi)__y);
     91 }
     92 
     93 /// \brief Inserts bits of a specified length from the source integer vector 
     94 ///    y into the lower 64 bits of the destination integer vector x at the 
     95 ///    index idx and of the length len.
     96 ///
     97 /// \headerfile <x86intrin.h>
     98 ///
     99 /// \code 
    100 /// __m128i _mm_inserti_si64(__m128i x, __m128i y, const int len,
    101 /// const int idx);
    102 /// \endcode 
    103 ///
    104 /// \code 
    105 /// This intrinsic corresponds to the \c INSERTQ instruction.
    106 /// \endcode 
    107 ///
    108 /// \param x
    109 ///    The destination operand where bits will be inserted. The inserted bits 
    110 ///    are defined by the length len and by the index idx specifying the least 
    111 ///    significant bit.
    112 /// \param y
    113 ///    The source operand containing the bits to be extracted. The extracted 
    114 ///    bits are the least significant bits of operand y of length len.
    115 /// \param len
    116 ///    Bits [5:0] specify the length; the other bits are ignored. If bits [5:0]
    117 ///    are zero, the length is interpreted as 64.
    118 /// \param idx
    119 ///    Bits [5:0] specify the index of the least significant bit; the other 
    120 ///    bits are ignored. If the sum of the index and length is greater than 
    121 ///    64, the result is undefined. If the length and index are both zero, 
    122 ///    bits [63:0] of parameter y are inserted into parameter x. If the 
    123 ///    length is zero but the index is non-zero, the result is undefined.
    124 /// \returns A 128-bit integer vector containing the original lower 64-bits 
    125 ///    of destination operand x with the specified bitfields replaced by the
    126 ///    lower bits of source operand y. The upper 64 bits of the return value 
    127 ///    are undefined.
    128 
    129 #define _mm_inserti_si64(x, y, len, idx) \
    130   ((__m128i)__builtin_ia32_insertqi((__v2di)(__m128i)(x), \
    131                                     (__v2di)(__m128i)(y), \
    132                                     (char)(len), (char)(idx)))
    133 
    134 /// \brief Inserts bits of a specified length from the source integer vector 
    135 ///    __y into the lower 64 bits of the destination integer vector __x at 
    136 ///    the index and of the length specified by __y.
    137 ///
    138 /// \headerfile <x86intrin.h>
    139 ///
    140 /// \code 
    141 /// This intrinsic corresponds to the \c INSERTQ instruction.
    142 /// \endcode 
    143 ///
    144 /// \param __x
    145 ///    The destination operand where bits will be inserted. The inserted bits 
    146 ///    are defined by the length and by the index of the least significant bit 
    147 ///    specified by operand __y.
    148 /// \param __y
    149 ///    The source operand containing the bits to be extracted. The extracted 
    150 ///    bits are the least significant bits of operand __y with length specified
    151 ///    by bits [69:64]. These are inserted into the destination at the index 
    152 ///    specified by bits [77:72]; all other bits are ignored.
    153 ///    If bits [69:64] are zero, the length is interpreted as 64.
    154 ///    If the sum of the index and length is greater than 64, the result is 
    155 ///    undefined. If the length and index are both zero, bits [63:0] of 
    156 ///    parameter __y are inserted into parameter __x. If the length
    157 ///    is zero but the index is non-zero, the result is undefined. 
    158 /// \returns A 128-bit integer vector containing the original lower 64-bits 
    159 ///    of destination operand __x with the specified bitfields replaced by the
    160 ///    lower bits of source operand __y. The upper 64 bits of the return value 
    161 ///    are undefined.
    162 
    163 static __inline__ __m128i __DEFAULT_FN_ATTRS
    164 _mm_insert_si64(__m128i __x, __m128i __y)
    165 {
    166   return (__m128i)__builtin_ia32_insertq((__v2di)__x, (__v2di)__y);
    167 }
    168 
    169 /// \brief Stores a 64-bit double-precision value in a 64-bit memory location. 
    170 ///    To minimize caching, the data is flagged as non-temporal (unlikely to be
    171 ///    used again soon).
    172 ///
    173 /// \headerfile <x86intrin.h>
    174 ///
    175 /// \code 
    176 /// This intrinsic corresponds to the \c MOVNTSD instruction.
    177 /// \endcode 
    178 ///
    179 /// \param __p
    180 ///    The 64-bit memory location used to store the register value.
    181 /// \param __a
    182 ///    The 64-bit double-precision floating-point register value to
    183 ///    be stored.
    184 static __inline__ void __DEFAULT_FN_ATTRS
    185 _mm_stream_sd(double *__p, __m128d __a)
    186 {
    187   __builtin_ia32_movntsd(__p, (__v2df)__a);
    188 }
    189 
    190 /// \brief Stores a 32-bit single-precision floating-point value in a 32-bit
    191 ///    memory location. To minimize caching, the data is flagged as
    192 ///    non-temporal (unlikely to be used again soon).
    193 ///
    194 /// \headerfile <x86intrin.h>
    195 ///
    196 /// \code 
    197 /// This intrinsic corresponds to the \c MOVNTSS instruction.
    198 /// \endcode 
    199 ///
    200 /// \param __p
    201 ///    The 32-bit memory location used to store the register value.
    202 /// \param __a
    203 ///    The 32-bit single-precision floating-point register value to
    204 ///    be stored.
    205 static __inline__ void __DEFAULT_FN_ATTRS
    206 _mm_stream_ss(float *__p, __m128 __a)
    207 {
    208   __builtin_ia32_movntss(__p, (__v4sf)__a);
    209 }
    210 
    211 #undef __DEFAULT_FN_ATTRS
    212 
    213 #endif /* __SSE4A__ */
    214 
    215 #endif /* __AMMINTRIN_H */