|
| 1 | +/*===---- pmmintrin.h - SSE3 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 __PMMINTRIN_H |
| 25 | +#define __PMMINTRIN_H |
| 26 | + |
| 27 | +#include <emmintrin.h> |
| 28 | + |
| 29 | +#ifndef __SSE3__ |
| 30 | +#error "SSE3 instruction set not enabled" |
| 31 | +#endif |
| 32 | + |
| 33 | +/* Define the default attributes for the functions in this file. */ |
| 34 | +#ifdef __EMSCRIPTEN__ |
| 35 | +#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) |
| 36 | +#else |
| 37 | +#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("sse3"))) |
| 38 | +#endif |
| 39 | + |
| 40 | +static __inline__ __m128i __DEFAULT_FN_ATTRS |
| 41 | +_mm_lddqu_si128(__m128i const *__p) |
| 42 | +{ |
| 43 | +#ifdef __EMSCRIPTEN__ |
| 44 | + return _mm_loadu_si128(__p); |
| 45 | +#else |
| 46 | + return (__m128i)__builtin_ia32_lddqu((char const *)__p); |
| 47 | +#endif |
| 48 | +} |
| 49 | + |
| 50 | +static __inline__ __m128 __DEFAULT_FN_ATTRS |
| 51 | +_mm_addsub_ps(__m128 __a, __m128 __b) |
| 52 | +{ |
| 53 | +#ifdef __EMSCRIPTEN__ |
| 54 | + return _mm_add_ps(__a, _mm_mul_ps(__b, _mm_set_ps(1.f, -1.f, 1.f, -1.f))); |
| 55 | +#else |
| 56 | + return __builtin_ia32_addsubps(__a, __b); |
| 57 | +#endif |
| 58 | +} |
| 59 | + |
| 60 | +static __inline__ __m128 __DEFAULT_FN_ATTRS |
| 61 | +_mm_hadd_ps(__m128 __a, __m128 __b) |
| 62 | +{ |
| 63 | +#ifdef __EMSCRIPTEN__ |
| 64 | + return _mm_add_ps(_mm_shuffle_ps(__a, __b, _MM_SHUFFLE(2, 0, 2, 0)), _mm_shuffle_ps(__a, __b, _MM_SHUFFLE(3, 1, 3, 1))); |
| 65 | +#else |
| 66 | + return __builtin_ia32_haddps(__a, __b); |
| 67 | +#endif |
| 68 | +} |
| 69 | + |
| 70 | +static __inline__ __m128 __DEFAULT_FN_ATTRS |
| 71 | +_mm_hsub_ps(__m128 __a, __m128 __b) |
| 72 | +{ |
| 73 | +#ifdef __EMSCRIPTEN__ |
| 74 | + return _mm_sub_ps(_mm_shuffle_ps(__a, __b, _MM_SHUFFLE(2, 0, 2, 0)), _mm_shuffle_ps(__a, __b, _MM_SHUFFLE(3, 1, 3, 1))); |
| 75 | +#else |
| 76 | + return __builtin_ia32_hsubps(__a, __b); |
| 77 | +#endif |
| 78 | +} |
| 79 | + |
| 80 | +static __inline__ __m128 __DEFAULT_FN_ATTRS |
| 81 | +_mm_movehdup_ps(__m128 __a) |
| 82 | +{ |
| 83 | + return __builtin_shufflevector(__a, __a, 1, 1, 3, 3); |
| 84 | +} |
| 85 | + |
| 86 | +static __inline__ __m128 __DEFAULT_FN_ATTRS |
| 87 | +_mm_moveldup_ps(__m128 __a) |
| 88 | +{ |
| 89 | + return __builtin_shufflevector(__a, __a, 0, 0, 2, 2); |
| 90 | +} |
| 91 | + |
| 92 | +static __inline__ __m128d __DEFAULT_FN_ATTRS |
| 93 | +_mm_addsub_pd(__m128d __a, __m128d __b) |
| 94 | +{ |
| 95 | +#ifdef __EMSCRIPTEN__ |
| 96 | + return _mm_add_pd(__a, _mm_mul_pd(__b, _mm_set_pd(1.0, -1.0))); |
| 97 | +#else |
| 98 | + return __builtin_ia32_addsubpd(__a, __b); |
| 99 | +#endif |
| 100 | +} |
| 101 | + |
| 102 | +static __inline__ __m128d __DEFAULT_FN_ATTRS |
| 103 | +_mm_hadd_pd(__m128d __a, __m128d __b) |
| 104 | +{ |
| 105 | +#ifdef __EMSCRIPTEN__ |
| 106 | + return _mm_add_pd(_mm_shuffle_pd(__a, __b, _MM_SHUFFLE2(0, 0)), _mm_shuffle_pd(__a, __b, _MM_SHUFFLE2(1, 1))); |
| 107 | +#else |
| 108 | + return __builtin_ia32_haddpd(__a, __b); |
| 109 | +#endif |
| 110 | +} |
| 111 | + |
| 112 | +static __inline__ __m128d __DEFAULT_FN_ATTRS |
| 113 | +_mm_hsub_pd(__m128d __a, __m128d __b) |
| 114 | +{ |
| 115 | +#ifdef __EMSCRIPTEN__ |
| 116 | + return _mm_sub_pd(_mm_shuffle_pd(__a, __b, _MM_SHUFFLE2(0, 0)), _mm_shuffle_pd(__a, __b, _MM_SHUFFLE2(1, 1))); |
| 117 | +#else |
| 118 | + return __builtin_ia32_hsubpd(__a, __b); |
| 119 | +#endif |
| 120 | +} |
| 121 | + |
| 122 | +#define _mm_loaddup_pd(dp) _mm_load1_pd(dp) |
| 123 | + |
| 124 | +static __inline__ __m128d __DEFAULT_FN_ATTRS |
| 125 | +_mm_movedup_pd(__m128d __a) |
| 126 | +{ |
| 127 | + return __builtin_shufflevector(__a, __a, 0, 0); |
| 128 | +} |
| 129 | + |
| 130 | +#define _MM_DENORMALS_ZERO_ON (0x0040) |
| 131 | +#define _MM_DENORMALS_ZERO_OFF (0x0000) |
| 132 | + |
| 133 | +#define _MM_DENORMALS_ZERO_MASK (0x0040) |
| 134 | + |
| 135 | +#define _MM_GET_DENORMALS_ZERO_MODE() (_mm_getcsr() & _MM_DENORMALS_ZERO_MASK) |
| 136 | +#define _MM_SET_DENORMALS_ZERO_MODE(x) (_mm_setcsr((_mm_getcsr() & ~_MM_DENORMALS_ZERO_MASK) | (x))) |
| 137 | + |
| 138 | +#ifndef __EMSCRIPTEN__ |
| 139 | + |
| 140 | +static __inline__ void __DEFAULT_FN_ATTRS |
| 141 | +_mm_monitor(void const *__p, unsigned __extensions, unsigned __hints) |
| 142 | +{ |
| 143 | + __builtin_ia32_monitor((void *)__p, __extensions, __hints); |
| 144 | +} |
| 145 | + |
| 146 | +static __inline__ void __DEFAULT_FN_ATTRS |
| 147 | +_mm_mwait(unsigned __extensions, unsigned __hints) |
| 148 | +{ |
| 149 | + __builtin_ia32_mwait(__extensions, __hints); |
| 150 | +} |
| 151 | + |
| 152 | +#endif /* __EMSCRIPTEN__ */ |
| 153 | + |
| 154 | +#undef __DEFAULT_FN_ATTRS |
| 155 | + |
| 156 | +#endif /* __PMMINTRIN_H */ |
0 commit comments