21#if MOCHI_USE_SIMD && MOCHI_ARCH_ARM_NEON
29class Simd<double, 2> {
34 template <
class U, MOCHI_REQUIRES_NON_BOOL_SCALAR(U, Scalar)>
39 static_assert(i >= 0 && i < 2,
"Index out of range");
40 return vgetq_lane_f64(v.raw, i);
51 result.raw[i] = value;
57 static_assert(i >= 0 && i <
kSize,
"Index out of range");
58 return Set(v, i, value);
63 static_assert(N == 1 || N == 2,
"Invalid N");
65 vget_lane_u64(vreinterpret_u64_u16(vqmovn_u32(vreinterpretq_u32_f64(v.raw))), 0);
66 if constexpr (N == 1) {
67 return (mask & 0x00000000FFFFFFFFULL) == 0x00000000FFFFFFFFULL;
69 return mask == 0xFFFFFFFFFFFFFFFFULL;
75 static_assert(N == 1 || N == 2,
"Invalid N");
77 vget_lane_u64(vreinterpret_u64_u16(vqmovn_u32(vreinterpretq_u32_f64(v.raw))), 0);
78 if constexpr (N == 1) {
79 return (mask & 0x00000000FFFFFFFFULL) == 0x00000000FFFFFFFFULL;
85 template <
int x,
int y>
87 static_assert(x >= 0 && x <= 1 && y >= 0 && y <= 1,
"invalid blend index");
88 if constexpr (x == 0 && y == 0) {
90 }
else if constexpr (x == 1 && y == 1) {
93 auto mask = vreinterpretq_f64_s64(
94 int64x2_t{x ? (int64_t)0 : (int64_t)-1, y ? (int64_t)0 : (int64_t)-1});
105 static_assert(i >= 0 && i < 2,
"Index out of range");
106 return vdupq_laneq_f64(v.raw, i);
109 template <
int N = kSize>
111 static_assert(N >= 0 && N <=
kSize);
112 if constexpr (N == 0) {
114 }
else if constexpr (N == 1) {
115 return Simd{*ptr, 0.0};
117 return vld1q_f64(ptr);
137 template <
int kTupleCount = kSize>
140 static_assert(kTupleCount >= 1 && kTupleCount <=
kSize,
"Unsupported kTupleCount");
141 if constexpr (kTupleCount == 1) {
142 out0.raw = float64x2_t{ptr[0], 0.0};
143 out1.raw = float64x2_t{ptr[1], 0.0};
144 out2.raw = float64x2_t{ptr[2], 0.0};
146 float64x2x3_t result = vld3q_f64(ptr);
147 out0.raw = result.val[0];
148 out1.raw = result.val[1];
149 out2.raw = result.val[2];
157 double const*
const zero = arm_simd::kZeroTuple<double>;
158 float64x2x3_t r = vld3q_dup_f64(count > 0 ? ptr : zero);
159 r = vld3q_lane_f64(count > 1 ? ptr + 3 : zero, r, 1);
165 template <
int N = kSize>
166 static void Store([[maybe_unused]]
double* ptr, [[maybe_unused]]
Simd v) {
167 static_assert(N >= 0 && N <=
kSize);
168 if constexpr (N == 0) {
169 }
else if constexpr (N == 1) {
172 vst1q_f64(ptr, v.raw);
187 uint64x2_t shifted = vshrq_n_u64(vreinterpretq_u64_f64(condition.raw), 63);
188 uint32_t bit0 = vgetq_lane_u64(shifted, 0);
189 uint32_t bit1 = vgetq_lane_u64(shifted, 1);
190 uint32_t mask = bit0 | (bit1 << 1);
191 uint32_t count = bit0 + bit1;
192 uint8x16_t pattern = vld1q_u8(arm_simd::kStoreSelectedShuffleTableD2[mask]);
193 uint8x16_t packed = vqtbl1q_u8(vreinterpretq_u8_f64(values.raw), pattern);
194 vst1q_f64(ptr, vreinterpretq_f64_u8(packed));
195 return static_cast<int>(count);
198 template <
int kTupleCount = kSize>
200 static_assert(kTupleCount >= 1 && kTupleCount <=
kSize,
"Invalid kTupleCount");
201 if constexpr (kTupleCount == 1) {
206 vst3q_f64(ptr, float64x2x3_t({a.raw, b.raw, c.raw}));
216 float64x2x3_t
const v = {a.raw, b.raw, c.raw};
217 vst3q_lane_f64(count > 1 ? ptr + 3 : ptr, v, 1);
218 vst3q_lane_f64(ptr, v, 0);
222 return vbslq_f64(vreinterpretq_u64_f64(mask.raw), a.raw, b.raw);
226 template <
int x = 0,
int y = 1>
228 static_assert(x >= 0 && x < 2,
"Invalid index");
229 static_assert(y >= 0 && y < 2,
"Invalid index");
230 if constexpr (x == 0 && y == 0) {
232 }
else if constexpr (x == 0 && y == 1) {
234 }
else if constexpr (x == 1 && y == 0) {
235 return vcombine_f64(vget_high_f64(v.raw), vget_low_f64(v.raw));
236 }
else if constexpr (x == 1 && y == 1) {
242 return vreinterpretq_f64_s64(vdupq_n_s64((int64_t)0x8000000000000000LL));
246 return vsqrtq_f64(v.raw);
250 return vrecpeq_f64(v.raw);
254 return vrsqrteq_f64(v.raw);
258 return vabsq_f64(v.raw);
262 return vminq_f64(a.raw, b.raw);
266 return vmaxq_f64(a.raw, b.raw);
270 return vrndmq_f64(a.raw);
274 return vrndaq_f64(v.raw);
278 return vfmaq_f64(c.raw, b.raw, a.raw);
286 return vfmsq_f64(c.raw, b.raw, a.raw);
295 static_assert(N == 2,
"Unsupported N");
296 return vminvq_f64(a.raw);
301 static_assert(N == 2,
"Unsupported N");
302 return vmaxvq_f64(a.raw);
307 static_assert(N == 2,
"Unsupported N");
308 return vaddvq_f64(a.raw);
312 return vpaddq_f64(a.raw, b.raw);
317 static_assert(N == 2,
"Unsupported N");
323 static_assert(N == 2,
"Unsupported N");
328 return vreinterpretq_f64_u64(vcltq_f64(this->
raw, rhs.raw));
332 return vreinterpretq_f64_u64(vcgtq_f64(this->
raw, rhs.raw));
336 return vreinterpretq_f64_u64(vcleq_f64(this->
raw, rhs.raw));
340 return vreinterpretq_f64_u64(vcgeq_f64(this->
raw, rhs.raw));
344 return vreinterpretq_f64_u64(vceqq_f64(a.raw, b.raw));
352 return vdupq_n_f64(0);
360 return !(*
this == rhs);
364 return vreinterpretq_f64_u32(vmvnq_u32(vreinterpretq_u32_f64(
raw)));
368 return vnegq_f64(
raw);
372 return vaddq_f64(
raw, rhs.raw);
376 return vsubq_f64(
raw, rhs.raw);
380 return vmulq_f64(
raw, rhs.raw);
384 return vdivq_f64(
raw, rhs.raw);
388 return vreinterpretq_f64_s64(
389 vandq_s64(vreinterpretq_s64_f64(
raw), vreinterpretq_s64_f64(rhs.raw)));
393 return vreinterpretq_f64_s64(
394 vorrq_s64(vreinterpretq_s64_f64(
raw), vreinterpretq_s64_f64(rhs.raw)));
398 return vreinterpretq_f64_s64(
399 veorq_s64(vreinterpretq_s64_f64(
raw), vreinterpretq_s64_f64(rhs.raw)));
Simd operator&(Simd rhs) const
bool operator==(Simd rhs) const
Simd operator>(Simd rhs) const
Simd operator*(Simd rhs) const
Simd operator^(Simd rhs) 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
Simd operator+(Simd rhs) const
Simd operator/(Simd rhs) const
Simd operator<=(Simd rhs) const
Scalar operator[](int i) const
#define MOCHI_ASSERT_VERBOSE(condition_without_side_effects,...)
T Dot(Simd< T, N > a, Simd< T, N > b)
constexpr T NegMulAdd(T a, T b, T c)
Simd< T, 2 > Shuffle(Simd< T, 2 > a)
Simd< T, 2 > HSumEach(Simd< T, 2 > a, Simd< T, 2 > b)
Returns {HSum(a), HSum(b)}.
V LoadIndexed(typename V::Scalar const *ptr, Simd< I, V::kSize > indices)
constexpr T const & Min(T const &a, T const &b)
constexpr auto Equal(T const &a, T const &b)
constexpr T NegMulSub(T a, T b, T c)
Simd< T, N > Set(Simd< T, N > a, T value)
constexpr auto NotEqual(T const &a, T const &b)
V Broadcast(typename V::Scalar a)
constexpr T MulSub(T a, T b, T c)
Simd< T, N > Blend(Simd< T, N > a, Simd< T, N > b)
constexpr T Select(bool condition, T a, T b)
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)
Simd< T, N > FastRound(Simd< T, N > a)
void StoreTransposed(T *ptr, Simd< T, N > a, Simd< T, N > b, Simd< T, N > c)
void Store(T *ptr, Simd< T, N > a)
Simd< T, N > RcpSqrtApprox(Simd< T, N > a)
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)
V Load(typename V::Scalar const *ptr)
#define MOCHI_NATIVE_SIMD_IMPL_BOILERPLATE(T, N, NativeT)