Debian Codegraph @

third-party/simde/arm/neon/tbx.h

raw
1 /* SPDX-License-Identifier: MIT
2 *
3 * Permission is hereby granted, free of charge, to any person
4 * obtaining a copy of this software and associated documentation
5 * files (the "Software"), to deal in the Software without
6 * restriction, including without limitation the rights to use, copy,
7 * modify, merge, publish, distribute, sublicense, and/or sell copies
8 * of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be
12 * included in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Copyright:
24 * 2020 Evan Nemerson <[email protected]>
25 * 2020 Christopher Moore <[email protected]>
26 */
27
28 #if !defined(SIMDE_ARM_NEON_TBX_H)
29 #define SIMDE_ARM_NEON_TBX_H
30
31 #include "reinterpret.h"
32 #include "types.h"
33
34 HEDLEY_DIAGNOSTIC_PUSH
35 SIMDE_DISABLE_UNWANTED_DIAGNOSTICS
36 SIMDE_BEGIN_DECLS_
37
38 SIMDE_FUNCTION_ATTRIBUTES
39 simde_uint8x8_t
40 simde_vtbx1_u8(simde_uint8x8_t a, simde_uint8x8_t b, simde_uint8x8_t c) {
41 #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
42 return vtbx1_u8(a, b, c);
43 #else
44 simde_uint8x8_private
45 r_,
46 a_ = simde_uint8x8_to_private(a),
47 b_ = simde_uint8x8_to_private(b),
48 c_ = simde_uint8x8_to_private(c);
49
50 #if defined(SIMDE_X86_SSE4_1_NATIVE) && defined(SIMDE_X86_MMX_NATIVE)
51 __m128i a128 = _mm_set1_epi64(a_.m64);
52 __m128i b128 = _mm_set1_epi64(b_.m64);
53 __m128i c128 = _mm_set1_epi64(c_.m64);
54 c128 = _mm_or_si128(c128, _mm_cmpgt_epi8(c128, _mm_set1_epi8(7)));
55 __m128i r128 = _mm_shuffle_epi8(b128, c128);
56 r128 = _mm_blendv_epi8(r128, a128, c128);
57 r_.m64 = _mm_movepi64_pi64(r128);
58 #else
59 SIMDE_VECTORIZE
60 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
61 r_.values[i] = (c_.values[i] < 8) ? b_.values[c_.values[i]] : a_.values[i];
62 }
63 #endif
64
65 return simde_uint8x8_from_private(r_);
66 #endif
67 }
68 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
69 #undef vtbx1_u8
70 #define vtbx1_u8(a, b, c) simde_vtbx1_u8((a), (b), (c))
71 #endif
72
73 SIMDE_FUNCTION_ATTRIBUTES
74 simde_int8x8_t
75 simde_vtbx1_s8(simde_int8x8_t a, simde_int8x8_t b, simde_int8x8_t c) {
76 #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
77 return vtbx1_s8(a, b, c);
78 #else
79 return simde_vreinterpret_s8_u8(simde_vtbx1_u8(simde_vreinterpret_u8_s8(a), simde_vreinterpret_u8_s8(b), simde_vreinterpret_u8_s8(c)));
80 #endif
81 }
82 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
83 #undef vtbx1_s8
84 #define vtbx1_s8(a, b, c) simde_vtbx1_s8((a), (b), (c))
85 #endif
86
87 #if !defined(SIMDE_BUG_INTEL_857088)
88
89 SIMDE_FUNCTION_ATTRIBUTES
90 simde_uint8x8_t
91 simde_vtbx2_u8(simde_uint8x8_t a, simde_uint8x8x2_t b, simde_uint8x8_t c) {
92 #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
93 return vtbx2_u8(a, b, c);
94 #else
95 simde_uint8x8_private
96 r_,
97 a_ = simde_uint8x8_to_private(a),
98 b_[2] = { simde_uint8x8_to_private(b.val[0]), simde_uint8x8_to_private(b.val[1]) },
99 c_ = simde_uint8x8_to_private(c);
100
101 #if defined(SIMDE_X86_SSE4_1_NATIVE) && defined(SIMDE_X86_MMX_NATIVE)
102 __m128i a128 = _mm_set1_epi64(a_.m64);
103 __m128i b128 = _mm_set_epi64(b_[1].m64, b_[0].m64);
104 __m128i c128 = _mm_set1_epi64(c_.m64);
105 c128 = _mm_or_si128(c128, _mm_cmpgt_epi8(c128, _mm_set1_epi8(15)));
106 __m128i r128 = _mm_shuffle_epi8(b128, c128);
107 r128 = _mm_blendv_epi8(r128, a128, c128);
108 r_.m64 = _mm_movepi64_pi64(r128);
109 #else
110 SIMDE_VECTORIZE
111 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
112 r_.values[i] = (c_.values[i] < 16) ? b_[c_.values[i] / 8].values[c_.values[i] & 7] : a_.values[i];
113 }
114 #endif
115
116 return simde_uint8x8_from_private(r_);
117 #endif
118 }
119 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
120 #undef vtbx2_u8
121 #define vtbx2_u8(a, b, c) simde_vtbx2_u8((a), (b), (c))
122 #endif
123
124 SIMDE_FUNCTION_ATTRIBUTES
125 simde_int8x8_t
126 simde_vtbx2_s8(simde_int8x8_t a, simde_int8x8x2_t b, simde_int8x8_t c) {
127 #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
128 return vtbx2_s8(a, b, c);
129 #else
130 simde_uint8x8x2_t b_;
131 simde_memcpy(&b_, &b, sizeof(b_));
132 return simde_vreinterpret_s8_u8(simde_vtbx2_u8(simde_vreinterpret_u8_s8(a),
133 b_,
134 simde_vreinterpret_u8_s8(c)));
135 #endif
136 }
137 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
138 #undef vtbx2_s8
139 #define vtbx2_s8(a, b, c) simde_vtbx2_s8((a), (b), (c))
140 #endif
141
142 SIMDE_FUNCTION_ATTRIBUTES
143 simde_uint8x8_t
144 simde_vtbx3_u8(simde_uint8x8_t a, simde_uint8x8x3_t b, simde_uint8x8_t c) {
145 #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
146 return vtbx3_u8(a, b, c);
147 #else
148 simde_uint8x8_private
149 r_,
150 a_ = simde_uint8x8_to_private(a),
151 b_[3] = { simde_uint8x8_to_private(b.val[0]), simde_uint8x8_to_private(b.val[1]), simde_uint8x8_to_private(b.val[2]) },
152 c_ = simde_uint8x8_to_private(c);
153
154 #if defined(SIMDE_X86_SSE4_1_NATIVE) && defined(SIMDE_X86_MMX_NATIVE)
155 __m128i a128 = _mm_set1_epi64(a_.m64);
156 __m128i c128 = _mm_set1_epi64(c_.m64);
157 c128 = _mm_or_si128(c128, _mm_cmpgt_epi8(c128, _mm_set1_epi8(23)));
158 __m128i r128_01 = _mm_shuffle_epi8(_mm_set_epi64(b_[1].m64, b_[0].m64), c128);
159 __m128i r128_2 = _mm_shuffle_epi8(_mm_set1_epi64(b_[2].m64), c128);
160 __m128i r128 = _mm_blendv_epi8(r128_01, r128_2, _mm_slli_epi32(c128, 3));
161 r128 = _mm_blendv_epi8(r128, a128, c128);
162 r_.m64 = _mm_movepi64_pi64(r128);
163 #else
164 SIMDE_VECTORIZE
165 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
166 r_.values[i] = (c_.values[i] < 24) ? b_[c_.values[i] / 8].values[c_.values[i] & 7] : a_.values[i];
167 }
168 #endif
169
170 return simde_uint8x8_from_private(r_);
171 #endif
172 }
173 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
174 #undef vtbx3_u8
175 #define vtbx3_u8(a, b, c) simde_vtbx3_u8((a), (b), (c))
176 #endif
177
178 SIMDE_FUNCTION_ATTRIBUTES
179 simde_int8x8_t
180 simde_vtbx3_s8(simde_int8x8_t a, simde_int8x8x3_t b, simde_int8x8_t c) {
181 #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
182 return vtbx3_s8(a, b, c);
183 #else
184 simde_uint8x8x3_t b_;
185 simde_memcpy(&b_, &b, sizeof(b_));
186 return simde_vreinterpret_s8_u8(simde_vtbx3_u8(simde_vreinterpret_u8_s8(a),
187 b_,
188 simde_vreinterpret_u8_s8(c)));
189 #endif
190 }
191 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
192 #undef vtbx3_s8
193 #define vtbx3_s8(a, b, c) simde_vtbx3_s8((a), (b), (c))
194 #endif
195
196 SIMDE_FUNCTION_ATTRIBUTES
197 simde_uint8x8_t
198 simde_vtbx4_u8(simde_uint8x8_t a, simde_uint8x8x4_t b, simde_uint8x8_t c) {
199 #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
200 return vtbx4_u8(a, b, c);
201 #else
202 simde_uint8x8_private
203 r_,
204 a_ = simde_uint8x8_to_private(a),
205 b_[4] = { simde_uint8x8_to_private(b.val[0]), simde_uint8x8_to_private(b.val[1]), simde_uint8x8_to_private(b.val[2]), simde_uint8x8_to_private(b.val[3]) },
206 c_ = simde_uint8x8_to_private(c);
207
208 #if defined(SIMDE_X86_SSE4_1_NATIVE) && defined(SIMDE_X86_MMX_NATIVE)
209 __m128i a128 = _mm_set1_epi64(a_.m64);
210 __m128i c128 = _mm_set1_epi64(c_.m64);
211 c128 = _mm_or_si128(c128, _mm_cmpgt_epi8(c128, _mm_set1_epi8(31)));
212 __m128i r128_01 = _mm_shuffle_epi8(_mm_set_epi64(b_[1].m64, b_[0].m64), c128);
213 __m128i r128_23 = _mm_shuffle_epi8(_mm_set_epi64(b_[3].m64, b_[2].m64), c128);
214 __m128i r128 = _mm_blendv_epi8(r128_01, r128_23, _mm_slli_epi32(c128, 3));
215 r128 = _mm_blendv_epi8(r128, a128, c128);
216 r_.m64 = _mm_movepi64_pi64(r128);
217 #else
218 SIMDE_VECTORIZE
219 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
220 r_.values[i] = (c_.values[i] < 32) ? b_[c_.values[i] / 8].values[c_.values[i] & 7] : a_.values[i];
221 }
222 #endif
223
224 return simde_uint8x8_from_private(r_);
225 #endif
226 }
227 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
228 #undef vtbx4_u8
229 #define vtbx4_u8(a, b, c) simde_vtbx4_u8((a), (b), (c))
230 #endif
231
232 SIMDE_FUNCTION_ATTRIBUTES
233 simde_int8x8_t
234 simde_vtbx4_s8(simde_int8x8_t a, simde_int8x8x4_t b, simde_int8x8_t c) {
235 #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
236 return vtbx4_s8(a, b, c);
237 #else
238 simde_uint8x8x4_t b_;
239 simde_memcpy(&b_, &b, sizeof(b_));
240 return simde_vreinterpret_s8_u8(simde_vtbx4_u8(simde_vreinterpret_u8_s8(a),
241 b_,
242 simde_vreinterpret_u8_s8(c)));
243 #endif
244 }
245 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
246 #undef vtbx4_s8
247 #define vtbx4_s8(a, b, c) simde_vtbx4_s8((a), (b), (c))
248 #endif
249
250 #endif /* !defined(SIMDE_BUG_INTEL_857088) */
251
252 SIMDE_END_DECLS_
253 HEDLEY_DIAGNOSTIC_POP
254
255 #endif /* !defined(SIMDE_ARM_NEON_TBX_H) */