SuperDex Physics C++ API
Loading...
Searching...
No Matches
arm_simd_float_4_inl.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include "arm_simd_inl.h" // for IntelliSense
20
21#if MOCHI_USE_SIMD && MOCHI_ARCH_ARM_NEON
22
23namespace superdex {
24
25/***********************************************************************************************
26 Simd<float, 4>
27*/
28template <>
29class Simd<float, 4> {
30 public:
31 MOCHI_NATIVE_SIMD_IMPL_BOILERPLATE(float, 4, float32x4_t);
32
33 MOCHI_FORCE_INLINE Simd(float a, float b, float c = 0.0f, float d = 0.0f) : raw{a, b, c, d} {}
34 template <class U, MOCHI_REQUIRES_NON_BOOL_SCALAR(U, Scalar)>
35 MOCHI_FORCE_INLINE Simd(U a) : raw{vdupq_n_f32(a)} {}
36
37 template <int i>
38 [[nodiscard]] MOCHI_FORCE_INLINE static Scalar Get(Simd v) {
39 static_assert(i >= 0 && i < 4, "Index out of range");
40 return vgetq_lane_f32(v.raw, i);
41 }
42
43 [[nodiscard]] MOCHI_FORCE_INLINE Scalar operator[](int i) const {
44 MOCHI_ASSERT_VERBOSE(i >= 0 && i < kSize, "Index out of range");
45 return raw[i];
46 }
47
48 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Set(Simd v, int i, Scalar value) {
49 MOCHI_ASSERT_VERBOSE(i >= 0 && i < kSize, "Index out of range");
50 auto result = v;
51 result.raw[i] = value;
52 return result;
53 }
54
55 template <int i>
56 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Set(Simd v, Scalar value) {
57 static_assert(i >= 0 && i < kSize, "Index out of range");
58 return Set(v, i, value);
59 }
60
61 [[nodiscard]] MOCHI_FORCE_INLINE static Simd AsPoint(Simd a) {
62 return vsetq_lane_f32(1.0f, a.raw, 3);
63 }
64
65 [[nodiscard]] MOCHI_FORCE_INLINE static Simd AsDirection(Simd a) {
66 return vsetq_lane_f32(0.0f, a.raw, 3);
67 }
68
69 template <int x, int y, int z, int w>
70 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Blend(Simd a, Simd b) {
71 static_assert(
72 x >= 0 && x <= 1 && y >= 0 && y <= 1 && z >= 0 && z <= 1 && w >= 0 && w <= 1,
73 "invalid blend index");
74 int constexpr kCount = x + y + z + w;
75 if constexpr (kCount == 0) {
76 return a;
77 } else if constexpr (kCount == 4) {
78 return b;
79 } else if constexpr (kCount == 1) {
80 // Replace one lane of a with the corresponding lane of b.
81 int constexpr kLane = x ? 0 : (y ? 1 : (z ? 2 : 3));
82 return vcopyq_laneq_f32(a.raw, kLane, b.raw, kLane);
83 } else if constexpr (kCount == 3) {
84 // Replace one lane of b with the corresponding lane of a.
85 int constexpr kLane = !x ? 0 : (!y ? 1 : (!z ? 2 : 3));
86 return vcopyq_laneq_f32(b.raw, kLane, a.raw, kLane);
87 } else if constexpr (x == 1 && y == 1) { // <1,1,0,0>: low half from b, high from a
88 return vcombine_f32(vget_low_f32(b.raw), vget_high_f32(a.raw));
89 } else if constexpr (z == 1 && w == 1) { // <0,0,1,1>: low half from a, high from b
90 return vcombine_f32(vget_low_f32(a.raw), vget_high_f32(b.raw));
91 } else {
92 // Remaining patterns: <1,0,1,0>, <0,1,0,1>, <1,0,0,1>, <0,1,1,0>.
93 // mask lane = -1 -> select from a; mask lane = 0 -> select from b.
94 auto mask = int32x4_t{x ? 0 : -1, y ? 0 : -1, z ? 0 : -1, w ? 0 : -1};
95 return Select(vreinterpretq_f32_s32(mask), a, b);
96 }
97 }
98
99 template <int N>
100 [[nodiscard]] MOCHI_FORCE_INLINE static bool AllTrue(Simd v) {
101 static_assert(N >= 1 && N <= 4, "Invalid number of components");
102 uint64_t mask =
103 vget_lane_u64(vreinterpret_u64_u16(vqmovn_u32(vreinterpretq_u32_f32(v.raw))), 0);
104 if constexpr (N == kSize) {
105 return mask == 0xFFFFFFFFFFFFFFFFULL;
106 } else {
107 int constexpr kNumBits = N * 16; // 64-bit mask has 16 bits per lane
108 auto constexpr kMustBeSet = (uint64_t(1) << kNumBits) - 1;
109 return (mask & kMustBeSet) == kMustBeSet;
110 }
111 }
112
113 template <int N>
114 [[nodiscard]] MOCHI_FORCE_INLINE static bool AnyTrue(Simd v) {
115 static_assert(N >= 1 && N <= 4, "Invalid number of components");
116 uint64_t mask =
117 vget_lane_u64(vreinterpret_u64_u16(vqmovn_u32(vreinterpretq_u32_f32(v.raw))), 0);
118 if constexpr (N == kSize) {
119 return mask != 0;
120 } else {
121 int constexpr kNumBits = N * 16; // 64-bit mask has 16 bits per lane
122 auto constexpr kMayBeSet = (uint64_t(1) << kNumBits) - 1;
123 return (mask & kMayBeSet) != 0;
124 }
125 }
126
127 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Broadcast(float const* p) {
128 return Simd{*p};
129 }
130
131 template <int i>
132 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Broadcast(Simd v) {
133 return vdupq_laneq_f32(v.raw, i);
134 }
135
136 template <int N = kSize>
137 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Load([[maybe_unused]] float const* ptr) {
138 static_assert(N >= 0 && N <= 4);
139 if constexpr (N == 0) {
140 return Simd::Zero();
141 } else if constexpr (N == 1) {
142 return Simd{ptr[0], 0, 0, 0};
143 } else if constexpr (N == 2) {
144 return Simd{ptr[0], ptr[1], 0, 0};
145 } else if constexpr (N == 3) {
146 return Simd{ptr[0], ptr[1], ptr[2], 0};
147 } else {
148 return vld1q_f32(ptr);
149 }
150 }
151
152 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Load(Scalar const* ptr, int n) {
153 MOCHI_ASSERT_VERBOSE(n >= 0 && n <= kSize, "Invalid size parameter");
154 // clang-format off
155 switch (n) {
156 case 1: return Load<1>(ptr);
157 case 2: return Load<2>(ptr);
158 case 3: return Load<3>(ptr);
159 case 4: return Load<4>(ptr);
160 MOCHI_UNLIKELY default: return Zero();
161 } // clang-format on
162 }
163
164 [[nodiscard]] MOCHI_FORCE_INLINE static Simd LoadIndexed(
165 float const* ptr,
166 Simd<int, 4> const& indices) {
167 return Simd<float, 4>{
168 ptr[indices.raw[0]], ptr[indices.raw[1]], ptr[indices.raw[2]], ptr[indices.raw[3]]};
169 }
170
171 template <int kTupleCount = kSize>
172 MOCHI_FORCE_INLINE static void
173 LoadTransposed(float const* ptr, Simd& out0, Simd& out1, Simd& out2) {
174 static_assert(kTupleCount >= 1 && kTupleCount <= kSize, "Unsupported kTupleCount");
175 if constexpr (kTupleCount == 1) {
176 out0.raw = float32x4_t{ptr[0], 0.0f, 0.0f, 0.0f};
177 out1.raw = float32x4_t{ptr[1], 0.0f, 0.0f, 0.0f};
178 out2.raw = float32x4_t{ptr[2], 0.0f, 0.0f, 0.0f};
179 } else if constexpr (kTupleCount == 2) {
180 out0.raw = float32x4_t{ptr[0], ptr[3], 0.0f, 0.0f};
181 out1.raw = float32x4_t{ptr[1], ptr[4], 0.0f, 0.0f};
182 out2.raw = float32x4_t{ptr[2], ptr[5], 0.0f, 0.0f};
183 } else if constexpr (kTupleCount == 3) {
184 out0.raw = float32x4_t{ptr[0], ptr[3], ptr[6], 0.0f};
185 out1.raw = float32x4_t{ptr[1], ptr[4], ptr[7], 0.0f};
186 out2.raw = float32x4_t{ptr[2], ptr[5], ptr[8], 0.0f};
187 } else { // kTupleCount == 4 (kSize)
188 float32x4x3_t result = vld3q_f32(ptr);
189 out0.raw = result.val[0];
190 out1.raw = result.val[1];
191 out2.raw = result.val[2];
192 }
193 }
194
195 // Branchless: each lane loads one tuple from a selected address, inactive lanes from zeros.
196 MOCHI_FORCE_INLINE static void
197 LoadTransposed(Scalar const* ptr, Simd& out0, Simd& out1, Simd& out2, int count) {
198 MOCHI_ASSERT_VERBOSE(count >= 0 && count <= kSize, "Invalid tuple count");
199 float const* const zero = arm_simd::kZeroTuple<float>;
200 float32x4x3_t r = vld3q_dup_f32(count > 0 ? ptr : zero);
201 r = vld3q_lane_f32(count > 1 ? ptr + 3 : zero, r, 1);
202 r = vld3q_lane_f32(count > 2 ? ptr + 6 : zero, r, 2);
203 r = vld3q_lane_f32(count > 3 ? ptr + 9 : zero, r, 3);
204 out0.raw = r.val[0];
205 out1.raw = r.val[1];
206 out2.raw = r.val[2];
207 }
208
209 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Select(Simd mask, Simd a, Simd b) {
210 return vbslq_f32(vreinterpretq_u32_f32(mask.raw), a.raw, b.raw);
211 }
212
213 template <int i>
214 [[nodiscard]] MOCHI_FORCE_INLINE static Simd SetBasisVector() {
215 static_assert(i >= 0 && i <= 3, "Invalid component index");
216 auto zeros = vdupq_n_f32(0);
217 return vsetq_lane_f32(1.0f, zeros, i);
218 }
219
220 template <int x = 0, int y = 1, int z = 2, int w = 3>
221 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Shuffle(Simd a, Simd b) {
222 static_assert(
223 x >= 0 && x < 4 && y >= 0 && y < 4 && z >= 0 && z < 4 && w >= 0 && w < 4, "Invalid index");
224 return Simd{a.raw[x], a.raw[y], b.raw[z], b.raw[w]};
225 }
226
227 template <int x = 0, int y = 1, int z = 2, int w = 3>
228 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Shuffle(Simd v) {
229 return Shuffle<x, y, z, w>(v, v);
230 }
231
232 [[nodiscard]] MOCHI_FORCE_INLINE static Simd SignBitMask() {
233 return vreinterpretq_f32_s32(vdupq_n_s32((int32_t)0x80000000));
234 }
235
236 template <int N = kSize>
237 MOCHI_FORCE_INLINE static void Store([[maybe_unused]] float* ptr, [[maybe_unused]] Simd v) {
238 static_assert(N >= 0 && N <= kSize);
239 // Partial stores write the lanes straight from the register. A memcpy of the vector leaves the
240 // instructions and their order to the compiler.
241 if constexpr (N == 0) {
242 } else if constexpr (N == 1) {
243 vst1q_lane_f32(ptr, v.raw, 0);
244 } else if constexpr (N == 2) {
245 vst1_f32(ptr, vget_low_f32(v.raw));
246 } else if constexpr (N == 3) {
247 vst1_f32(ptr, vget_low_f32(v.raw));
248 vst1q_lane_f32(ptr + 2, v.raw, 2);
249 } else {
250 vst1q_f32(ptr, v.raw);
251 }
252 }
253
254 MOCHI_FORCE_INLINE static void Store(Scalar* ptr, Simd v, int n) {
255 MOCHI_ASSERT_VERBOSE(n >= 0 && n <= kSize, "Invalid size parameter");
256 // clang-format off
257 switch (n) {
258 case 1: Store<1>(ptr, v); break;
259 case 2: Store<2>(ptr, v); break;
260 case 3: Store<3>(ptr, v); break;
261 case 4: Store<4>(ptr, v); break;
262 MOCHI_UNLIKELY default: break;
263 } // clang-format on
264 }
265
266 MOCHI_FORCE_INLINE static int StoreSelected(float* ptr, Simd condition, Simd values) {
267 uint32x4_t shifted = vshrq_n_u32(vreinterpretq_u32_f32(condition.raw), 31);
268 uint32x4_t const multipliers = {1, 2, 4, 8};
269 uint32x4_t weighted = vmulq_u32(shifted, multipliers);
270 uint32_t count = vaddvq_u32(shifted);
271 uint32_t mask = vaddvq_u32(weighted);
272 uint8x16_t pattern = vld1q_u8(arm_simd::kStoreSelectedShuffleTableS4[mask]);
273 uint8x16_t packed = vqtbl1q_u8(vreinterpretq_u8_f32(values.raw), pattern);
274 vst1q_f32(ptr, vreinterpretq_f32_u8(packed));
275 return static_cast<int>(count);
276 }
277
278 template <int kTupleCount = kSize>
279 MOCHI_FORCE_INLINE static void StoreTransposed(float* ptr, Simd a, Simd b, Simd c) {
280 static_assert(kTupleCount >= 1 && kTupleCount <= kSize, "Invalid kTupleCount");
281 if constexpr (kTupleCount == 1) {
282 ptr[0] = a.raw[0];
283 ptr[1] = b.raw[0];
284 ptr[2] = c.raw[0];
285 } else if constexpr (kTupleCount == 2) {
286 Simd::Store(ptr, Simd{a[0], b[0], c[0], a[1]});
287 ptr[4] = b.raw[1];
288 ptr[5] = c.raw[1];
289 } else if constexpr (kTupleCount == 3) {
290 Simd::Store(ptr + 0, Simd{a[0], b[0], c[0], a[1]});
291 Simd::Store(ptr + 4, Simd{b[1], c[1], a[2], b[2]});
292 ptr[8] = c.raw[2];
293 } else {
294 vst3q_f32(ptr, float32x4x3_t({a.raw, b.raw, c.raw}));
295 }
296 }
297
298 // Inactive lanes write tuple 0, which lane 0 stores last.
299 MOCHI_FORCE_INLINE static void StoreTransposed(Scalar* ptr, Simd a, Simd b, Simd c, int count) {
300 MOCHI_ASSERT_VERBOSE(count >= 0 && count <= kSize, "Invalid tuple count");
301 if (count == 0) {
302 return;
303 }
304 float32x4x3_t const v = {a.raw, b.raw, c.raw};
305 vst3q_lane_f32(count > 3 ? ptr + 9 : ptr, v, 3);
306 vst3q_lane_f32(count > 2 ? ptr + 6 : ptr, v, 2);
307 vst3q_lane_f32(count > 1 ? ptr + 3 : ptr, v, 1);
308 vst3q_lane_f32(ptr, v, 0);
309 }
310
311 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Sqrt(Simd v) {
312 return vsqrtq_f32(v.raw);
313 }
314
315 [[nodiscard]] MOCHI_FORCE_INLINE static Simd RcpApprox(Simd v) {
316 return vrecpeq_f32(v.raw);
317 }
318
319 [[nodiscard]] MOCHI_FORCE_INLINE static Simd RcpSqrtApprox(Simd v) {
320 return vrsqrteq_f32(v.raw);
321 }
322
323 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Abs(Simd v) {
324 return vabsq_f32(v.raw);
325 }
326
327 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Min(Simd a, Simd b) {
328 return vminq_f32(a.raw, b.raw);
329 }
330
331 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Max(Simd a, Simd b) {
332 return vmaxq_f32(a.raw, b.raw);
333 }
334
335 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Floor(Simd a) {
336 return vrndmq_f32(a.raw);
337 }
338
339 [[nodiscard]] MOCHI_FORCE_INLINE static Simd FastRound(Simd v) {
340 return vrndaq_f32(v.raw);
341 }
342
343 [[nodiscard]] MOCHI_FORCE_INLINE static Simd MulAdd(Simd a, Simd b, Simd c) {
344 return vfmaq_f32(c.raw, b.raw, a.raw);
345 }
346
347 [[nodiscard]] MOCHI_FORCE_INLINE static Simd MulSub(Simd a, Simd b, Simd c) {
348 return MulAdd(a, b, -c);
349 }
350
351 [[nodiscard]] MOCHI_FORCE_INLINE static Simd NegMulAdd(Simd a, Simd b, Simd c) {
352 return vfmsq_f32(c.raw, b.raw, a.raw);
353 }
354
355 [[nodiscard]] MOCHI_FORCE_INLINE static Simd NegMulSub(Simd a, Simd b, Simd c) {
356 return NegMulAdd(a, b, -c);
357 }
358
359 template <int N = 4>
360 [[nodiscard]] MOCHI_FORCE_INLINE static Scalar HMin(Simd a) {
361 static_assert(N >= 2 && N <= 4, "Unsupported N");
362 if constexpr (N == 2) {
363 return superdex::Min(a.raw[0], a.raw[1]);
364 } else if constexpr (N == 3) {
365 return vminvq_f32(vsetq_lane_f32(std::numeric_limits<Scalar>::infinity(), a.raw, 3));
366 } else {
367 return vminvq_f32(a.raw);
368 }
369 }
370
371 template <int N = 4>
372 [[nodiscard]] MOCHI_FORCE_INLINE static Scalar HMax(Simd a) {
373 static_assert(N >= 2 && N <= 4, "Unsupported N");
374 if constexpr (N == 2) {
375 return superdex::Max(a.raw[0], a.raw[1]);
376 } else if constexpr (N == 3) {
377 // HMax({x, y, z, -infinity})
378 return vmaxvq_f32(vsetq_lane_f32(-std::numeric_limits<Scalar>::infinity(), a.raw, 3));
379 } else {
380 return vmaxvq_f32(a.raw);
381 }
382 }
383
384 template <int N>
385 [[nodiscard]] MOCHI_FORCE_INLINE static Scalar HSum(Simd a) {
386 static_assert(N >= 2 && N <= 4, "Unsupported N");
387 if constexpr (N == 2) {
388 return a.raw[0] + a.raw[1];
389 } else if constexpr (N == 3) {
390 return a.raw[0] + a.raw[1] + a.raw[2];
391 } else if constexpr (N == 4) {
392 return vaddvq_f32(a.raw);
393 }
394 }
395
396 [[nodiscard]] MOCHI_FORCE_INLINE static Simd HSumEach(Simd a, Simd b, Simd c, Simd d) {
397 return vpaddq_f32(vpaddq_f32(a.raw, b.raw), vpaddq_f32(c.raw, d.raw));
398 }
399
400 template <int N>
401 [[nodiscard]] MOCHI_FORCE_INLINE static Scalar HProd(Simd a) {
402 static_assert(N >= 2 && N <= 4, "Unsupported N");
403 if constexpr (N == 2) {
404 return a.raw[0] * a.raw[1];
405 } else if constexpr (N == 3) {
406 return a.raw[0] * a.raw[1] * a.raw[2];
407 } else if constexpr (N == 4) {
408 return a.raw[0] * a.raw[1] * a.raw[2] * a.raw[3];
409 }
410 }
411
412 template <int N>
413 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Dot(Simd a, Simd b) {
414 static_assert(N >= 2 && N <= 4, "Unsupported N");
415 return Simd{HSum<N>(a * b)};
416 }
417
418 [[nodiscard]] MOCHI_FORCE_INLINE Simd operator<(Simd rhs) const {
419 return vreinterpretq_f32_u32(vcltq_f32(this->raw, rhs.raw));
420 }
421
422 [[nodiscard]] MOCHI_FORCE_INLINE Simd operator>(Simd rhs) const {
423 return vreinterpretq_f32_u32(vcgtq_f32(this->raw, rhs.raw));
424 }
425
426 [[nodiscard]] MOCHI_FORCE_INLINE Simd operator<=(Simd rhs) const {
427 return vreinterpretq_f32_u32(vcleq_f32(this->raw, rhs.raw));
428 }
429
430 [[nodiscard]] MOCHI_FORCE_INLINE Simd operator>=(Simd rhs) const {
431 return vreinterpretq_f32_u32(vcgeq_f32(this->raw, rhs.raw));
432 }
433
434 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Equal(Simd a, Simd b) {
435 return vreinterpretq_f32_u32(vceqq_f32(a.raw, b.raw));
436 }
437
438 [[nodiscard]] MOCHI_FORCE_INLINE static Simd NotEqual(Simd a, Simd b) {
439 return ~Equal(a, b);
440 }
441
442 [[nodiscard]] MOCHI_FORCE_INLINE static Simd Zero() {
443 return vdupq_n_f32(0);
444 }
445
446 [[nodiscard]] MOCHI_FORCE_INLINE bool operator==(Simd rhs) const {
447 return AllTrue<kSize>(Equal(*this, rhs));
448 }
449
450 [[nodiscard]] MOCHI_FORCE_INLINE bool operator!=(Simd rhs) const {
451 return !(*this == rhs);
452 }
453
454 [[nodiscard]] MOCHI_FORCE_INLINE Simd operator~() const {
455 return vreinterpretq_f32_u32(vmvnq_u32(vreinterpretq_u32_f32(raw)));
456 }
457
458 [[nodiscard]] MOCHI_FORCE_INLINE Simd operator-() const {
459 return vnegq_f32(raw);
460 }
461
462 [[nodiscard]] MOCHI_FORCE_INLINE Simd operator+(Simd rhs) const {
463 return vaddq_f32(raw, rhs.raw);
464 }
465
466 [[nodiscard]] MOCHI_FORCE_INLINE Simd operator-(Simd rhs) const {
467 return vsubq_f32(raw, rhs.raw);
468 }
469
470 [[nodiscard]] MOCHI_FORCE_INLINE Simd operator*(Simd rhs) const {
471 return vmulq_f32(raw, rhs.raw);
472 }
473
474 [[nodiscard]] MOCHI_FORCE_INLINE Simd operator/(Simd rhs) const {
475 return vdivq_f32(raw, rhs.raw);
476 }
477
478 [[nodiscard]] MOCHI_FORCE_INLINE Simd operator&(Simd rhs) const {
479 return vreinterpretq_f32_u32(
480 vandq_u32(vreinterpretq_u32_f32(raw), vreinterpretq_u32_f32(rhs.raw)));
481 }
482
483 [[nodiscard]] MOCHI_FORCE_INLINE Simd operator|(Simd rhs) const {
484 return vreinterpretq_f32_u32(
485 vorrq_u32(vreinterpretq_u32_f32(raw), vreinterpretq_u32_f32(rhs.raw)));
486 }
487
488 [[nodiscard]] MOCHI_FORCE_INLINE Simd operator^(Simd rhs) const {
489 return vreinterpretq_f32_u32(
490 veorq_u32(vreinterpretq_u32_f32(raw), vreinterpretq_u32_f32(rhs.raw)));
491 }
492};
493
494} // namespace superdex
495
496#endif // MOCHI_USE_SIMD && MOCHI_ARCH_ARM_NEON
Simd operator&(Simd rhs) const
bool operator==(Simd rhs) const
NativeType raw
Definition simd.h:174
Simd operator>(Simd rhs) const
Simd operator*(Simd rhs) const
Simd operator^(Simd rhs) const
Simd operator-() const
Simd operator>=(Simd rhs) const
Simd operator<(Simd rhs) const
bool operator!=(Simd rhs) const
Simd operator|(Simd rhs) const
static constexpr int kSize
Definition simd.h:96
Simd operator+(Simd rhs) const
Simd operator~() const
Simd operator/(Simd rhs) const
Simd operator<=(Simd rhs) const
Scalar operator[](int i) const
#define MOCHI_ASSERT_VERBOSE(condition_without_side_effects,...)
Definition debug.h:102
#define MOCHI_UNLIKELY
#define MOCHI_FORCE_INLINE
T Dot(Simd< T, N > a, Simd< T, N > b)
Definition simd.h:710
constexpr T NegMulAdd(T a, T b, T c)
Simd< T, 2 > Shuffle(Simd< T, 2 > a)
Definition simd_inl.h:287
Simd< T, 2 > HSumEach(Simd< T, 2 > a, Simd< T, 2 > b)
Returns {HSum(a), HSum(b)}.
Definition simd_inl.h:401
V LoadIndexed(typename V::Scalar const *ptr, Simd< I, V::kSize > indices)
Definition simd_inl.h:202
constexpr T const & Min(T const &a, T const &b)
constexpr auto Equal(T const &a, T const &b)
T HSum(Simd< T, N > a)
Definition simd_inl.h:391
T HMin(Simd< T, N > a)
Definition simd_inl.h:451
bool AllTrue(T const &a)
Definition basic_utils.h:60
constexpr T NegMulSub(T a, T b, T c)
Simd< T, N > Set(Simd< T, N > a, T value)
Definition simd_inl.h:327
constexpr auto NotEqual(T const &a, T const &b)
T HMax(Simd< T, N > a)
Definition simd_inl.h:461
V Broadcast(typename V::Scalar a)
Definition simd_inl.h:117
constexpr T Abs(T a)
Definition basic_utils.h:50
constexpr T MulSub(T a, T b, T c)
Simd< T, N > Blend(Simd< T, N > a, Simd< T, N > b)
Definition simd_inl.h:302
bool AnyTrue(T const &a)
Definition basic_utils.h:66
constexpr T Select(bool condition, T a, T b)
constexpr T Sqrt(T a)
T Get(Simd< T, N > v)
Definition simd_inl.h:317
constexpr T Floor(T a)
T HProd(Simd< T, N > a)
Definition simd_inl.h:441
constexpr T const & Max(T const &a, T const &b)
void LoadTransposed(T const *ptr, Simd< T, N > &out0, Simd< T, N > &out1, Simd< T, N > &out2)
Definition simd_inl.h:209
Simd< T, N > FastRound(Simd< T, N > a)
Definition simd_inl.h:486
void StoreTransposed(T *ptr, Simd< T, N > a, Simd< T, N > b, Simd< T, N > c)
Definition simd_inl.h:253
void Store(T *ptr, Simd< T, N > a)
Definition simd_inl.h:221
Simd< T, N > RcpSqrtApprox(Simd< T, N > a)
Definition simd_inl.h:371
constexpr T RcpApprox(T a)
constexpr T MulAdd(T a, T b, T c)
int StoreSelected(T *ptr, Simd< MaskT, N > condition, Simd< T, N > values)
Definition simd_inl.h:233
V Load(typename V::Scalar const *ptr)
Definition simd_inl.h:186
#define MOCHI_NATIVE_SIMD_IMPL_BOILERPLATE(T, N, NativeT)