blob: 1cfcac5c2962f034af9565a732b7c2dd6b70fc8c [file] [log] [blame]
Craig Topper925be542011-12-19 05:04:33 +00001/*===---- avx2intrin.h - AVX2 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 __IMMINTRIN_H
25#error "Never use <avx2intrin.h> directly; include <immintrin.h> instead."
26#endif
27
28/* SSE4 Multiple Packed Sums of Absolute Difference. */
29#define _mm256_mpsadbw_epu8(X, Y, M) __builtin_ia32_mpsadbw256((X), (Y), (M))
30
31static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
32_mm256_abs_epi8(__m256i a)
33{
34 return (__m256i)__builtin_ia32_pabsb256((__v32qi)a);
35}
36
37static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
38_mm256_abs_epi16(__m256i a)
39{
40 return (__m256i)__builtin_ia32_pabsw256((__v16hi)a);
41}
42
43static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
44_mm256_abs_epi32(__m256i a)
45{
46 return (__m256i)__builtin_ia32_pabsd256((__v8si)a);
47}
48
49static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
50_mm256_packs_epi16(__m256i a, __m256i b)
51{
52 return (__m256i)__builtin_ia32_packsswb256((__v16hi)a, (__v16hi)b);
53}
54
55static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
56_mm256_packs_epi32(__m256i a, __m256i b)
57{
58 return (__m256i)__builtin_ia32_packssdw256((__v8si)a, (__v8si)b);
59}
60
61static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
62_mm256_packus_epi16(__m256i a, __m256i b)
63{
64 return (__m256i)__builtin_ia32_packuswb256((__v16hi)a, (__v16hi)b);
65}
66
67static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
68_mm256_packus_epi32(__m256i __V1, __m256i __V2)
69{
70 return (__m256i) __builtin_ia32_packusdw256((__v8si)__V1, (__v8si)__V2);
71}
72
73static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
74_mm256_add_epi8(__m256i a, __m256i b)
75{
76 return (__m256i)((__v32qi)a + (__v32qi)b);
77}
78
79static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
80_mm256_add_epi16(__m256i a, __m256i b)
81{
82 return (__m256i)((__v16hi)a + (__v16hi)b);
83}
84
85static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
86_mm256_add_epi32(__m256i a, __m256i b)
87{
88 return (__m256i)((__v8si)a + (__v8si)b);
89}
90
91static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
92_mm256_add_epi64(__m256i a, __m256i b)
93{
94 return a + b;
95}
96
97static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
98_mm256_sub_epi8(__m256i a, __m256i b)
99{
100 return (__m256i)((__v32qi)a - (__v32qi)b);
101}
102
103static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
104_mm256_sub_epi16(__m256i a, __m256i b)
105{
106 return (__m256i)((__v16hi)a - (__v16hi)b);
107}
108
109static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
110_mm256_sub_epi32(__m256i a, __m256i b)
111{
112 return (__m256i)((__v8si)a - (__v8si)b);
113}
114
115static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
116_mm256_sub_epi64(__m256i a, __m256i b)
117{
118 return a - b;
119}