21 #if defined(HIGHWAY_HWY_TESTS_TEST_UTIL_INL_H_) == \
22 defined(HWY_TARGET_TOGGLE)
23 #ifdef HIGHWAY_HWY_TESTS_TEST_UTIL_INL_H_
24 #undef HIGHWAY_HWY_TESTS_TEST_UTIL_INL_H_
26 #define HIGHWAY_HWY_TESTS_TEST_UTIL_INL_H_
33 template <
typename T, HWY_IF_LANE_SIZE(T, 1)>
36 CopyBytes<1>(&value, &
byte);
37 fprintf(stderr,
"0x%02X,",
byte);
43 CopyBytes<2>(&value, &bits);
44 fprintf(stderr,
"0x%02X,", bits);
50 template <
typename T, HWY_IF_NOT_LANE_SIZE(T, 1)>
52 fprintf(stderr,
"%g,",
double(value));
56 template <
class D,
class V = Vec<D>>
58 size_t max_lanes = 7) {
60 const size_t N =
Lanes(d);
61 auto lanes = AllocateAligned<T>(N);
62 Store(v, d, lanes.get());
64 const auto info = hwy::detail::MakeTypeInfo<T>();
69 template <
class D,
typename T = TFromD<D>,
class V = Vec<D>>
71 const char* filename,
const int line) {
72 const size_t N =
Lanes(d);
73 auto actual_lanes = AllocateAligned<T>(N);
74 Store(actual, d, actual_lanes.get());
76 const auto info = hwy::detail::MakeTypeInfo<T>();
79 target_name, filename,
line);
83 template <
class D,
typename T = TFromD<D>,
class V = Vec<D>>
85 const char* filename,
int line) {
86 auto expected_lanes = AllocateAligned<T>(
Lanes(d));
87 Store(expected, d, expected_lanes.get());
94 const char* filename,
int line) {
103 #if HWY_TARGET != HWY_RVV && HWY_TARGET != HWY_SCALAR
104 const size_t N =
Lanes(d);
106 const size_t N8 =
Lanes(d8);
107 auto bits_a = AllocateAligned<uint8_t>(
HWY_MAX(8, N8));
108 auto bits_b = AllocateAligned<uint8_t>(
HWY_MAX(8, N8));
109 memset(bits_a.get(), 0, N8);
110 memset(bits_b.get(), 0, N8);
111 const size_t num_bytes_a =
StoreMaskBits(d, a, bits_a.get());
112 const size_t num_bytes_b =
StoreMaskBits(d, b, bits_b.get());
116 for (; i < N / 8; ++i) {
117 if (bits_a[i] != bits_b[i]) {
118 fprintf(stderr,
"Mismatch in byte %zu: %d != %d\n", i, bits_a[i],
120 Print(d8,
"expect",
Load(d8, bits_a.get()), 0, N8);
121 Print(d8,
"actual",
Load(d8, bits_b.get()), 0, N8);
122 hwy::Abort(filename,
line,
"Masks not equal");
126 const size_t remainder = N % 8;
127 if (remainder != 0) {
128 const int mask = (1 << remainder) - 1;
129 const int valid_a = bits_a[i] & mask;
130 const int valid_b = bits_b[i] & mask;
131 if (valid_a != valid_b) {
132 fprintf(stderr,
"Mismatch in last byte %zu: %d != %d\n", i, valid_a,
134 Print(d8,
"expect",
Load(d8, bits_a.get()), 0, N8);
135 Print(d8,
"actual",
Load(d8, bits_b.get()), 0, N8);
136 hwy::Abort(filename,
line,
"Masks not equal");
157 #ifndef HWY_ASSERT_EQ
159 #define HWY_ASSERT_EQ(expected, actual) \
160 hwy::AssertEqual(expected, actual, hwy::TargetName(HWY_TARGET), __FILE__, \
163 #define HWY_ASSERT_STRING_EQ(expected, actual) \
164 hwy::AssertStringEqual(expected, actual, hwy::TargetName(HWY_TARGET), \
167 #define HWY_ASSERT_VEC_EQ(d, expected, actual) \
168 AssertVecEqual(d, expected, actual, __FILE__, __LINE__)
170 #define HWY_ASSERT_MASK_EQ(d, expected, actual) \
171 AssertMaskEqual(d, expected, actual, __FILE__, __LINE__)
180 template <
class D, HWY_IF_NOT_LANE_SIZE_D(D, 8)>
185 template <
class D, HWY_IF_LANE_SIZE_D(D, 8)>
192 template <
typename T,
size_t kMul,
size_t kMinLanes,
class Test,
193 bool kPromote =
false>
200 if (lanes < kMinLanes)
return;
204 static_assert(kMul != 0,
"Recursion should have ended already");
210 template <
typename T,
size_t kMinLanes,
class Test,
bool kPromote>
219 template <
class Test,
size_t kFactor = 2>
221 template <
typename T>
223 #if HWY_TARGET == HWY_SCALAR
226 constexpr
bool kPromote =
true;
227 #if HWY_TARGET == HWY_RVV
231 #elif HWY_TARGET == HWY_SVE || HWY_TARGET == HWY_SVE2
233 ForeachSizeR<T, (16 /
sizeof(T)) / kFactor, 1, Test, kPromote>::Do();
245 template <
class Test,
size_t kFactor = 2>
247 template <
typename T>
249 #if HWY_TARGET == HWY_SCALAR
251 #elif HWY_TARGET == HWY_RVV
254 #elif HWY_TARGET == HWY_SVE || HWY_TARGET == HWY_SVE2
256 ForeachSizeR<T, (16 /
sizeof(T)) / kFactor, kFactor, Test>::Do();
259 #elif HWY_TARGET == HWY_SCALAR
269 template <
class Test>
271 template <
typename T>
273 #if HWY_TARGET == HWY_SCALAR
275 #elif HWY_TARGET == HWY_RVV
279 #elif HWY_TARGET == HWY_SVE || HWY_TARGET == HWY_SVE2
293 template <
class Test>
295 template <
typename T>
297 #if HWY_TARGET == HWY_SCALAR
299 #elif HWY_TARGET == HWY_RVV
303 #elif HWY_TARGET == HWY_SVE || HWY_TARGET == HWY_SVE2
317 template <
class Test,
size_t kFactor = 2>
319 template <
typename T>
321 #if HWY_TARGET == HWY_SCALAR
331 template <
class Test,
size_t kFactor = 2>
333 template <
typename T>
335 #if HWY_TARGET == HWY_SCALAR
345 template <
class Test>
347 template <
typename T>
355 template <
class Func>
360 #if HWY_CAP_INTEGER64
365 template <
class Func>
370 #if HWY_CAP_INTEGER64
375 template <
class Func>
381 template <
class Func>
389 template <
class Func>
395 template <
class Func>
399 #if HWY_CAP_INTEGER64
411 return HWY_MAX(max_reps / 16, 2);
413 return HWY_MAX(max_reps / 4, 2);
414 #elif HWY_IS_DEBUG_BUILD
415 return HWY_MAX(max_reps / 8, 2);
#define HWY_MAX(a, b)
Definition: base.h:123
#define HWY_NOINLINE
Definition: base.h:60
#define HWY_INLINE
Definition: base.h:59
#define HWY_TARGET
Definition: detect_targets.h:330
V VecArg
Definition: shared-inl.h:226
constexpr size_t AdjustedReps(size_t max_reps)
Definition: test_util-inl.h:409
HWY_API auto Lt(V a, V b) -> decltype(a==b)
Definition: arm_neon-inl.h:5035
HWY_API size_t StoreMaskBits(Simd< T, N >, const Mask128< T, N > mask, uint8_t *bits)
Definition: arm_neon-inl.h:4528
HWY_API Mask128< T, N > FirstN(const Simd< T, N > d, size_t num)
Definition: arm_neon-inl.h:1806
HWY_API Vec128< T, N > Load(Simd< T, N > d, const T *HWY_RESTRICT p)
Definition: arm_neon-inl.h:2152
Repartition< MakeWide< TFromD< D > >, D > RepartitionToWide
Definition: shared-inl.h:158
HWY_API Vec128< T, N > VecFromMask(const Mask128< T, N > v)
Definition: arm_neon-inl.h:1607
void ForUIF3264(const Func &func)
Definition: test_util-inl.h:396
constexpr HWY_API size_t Lanes(Simd< T, N >)
Definition: arm_sve-inl.h:226
HWY_NOINLINE void PrintValue(T value)
Definition: test_util-inl.h:34
void ForAllTypes(const Func &func)
Definition: test_util-inl.h:390
Rebind< MakeSigned< TFromD< D > >, D > RebindToSigned
Definition: shared-inl.h:147
HWY_API Mask128< TTo, N > RebindMask(Simd< TTo, N > dto, Mask128< TFrom, N > m)
Definition: arm_neon-inl.h:1619
void ForFloatTypes(const Func &func)
Definition: test_util-inl.h:382
void Print(const D d, const char *caption, VecArg< V > v, size_t lane_u=0, size_t max_lanes=7)
Definition: test_util-inl.h:57
HWY_API size_t CountTrue(Full128< T >, const Mask128< T > mask)
Definition: arm_neon-inl.h:4509
void ForIntegerTypes(const Func &func)
Definition: test_util-inl.h:376
HWY_API bool AllFalse(const Full128< T > d, const Mask128< T > m)
Definition: arm_neon-inl.h:4538
HWY_API bool AllTrue(const Simd< T, N > d, const Mask128< T, N > m)
Definition: arm_neon-inl.h:4557
void AssertVecEqual(D d, const T *expected, VecArg< V > actual, const char *filename, const int line)
Definition: test_util-inl.h:70
void ForSignedTypes(const Func &func)
Definition: test_util-inl.h:356
HWY_NOINLINE void AssertMaskEqual(D d, VecArg< Mask< D >> a, VecArg< Mask< D >> b, const char *filename, int line)
Definition: test_util-inl.h:93
HWY_INLINE size_t PromotedLanes(const D d)
Definition: test_util-inl.h:181
typename D::template Repartition< T > Repartition
Definition: shared-inl.h:155
decltype(MaskFromVec(Zero(D()))) Mask
Definition: generic_ops-inl.h:37
HWY_API Vec128< T, N > Zero(Simd< T, N > d)
Definition: arm_neon-inl.h:710
HWY_INLINE Mask< D > MaskFalse(const D d)
Definition: test_util-inl.h:152
HWY_INLINE Mask< D > MaskTrue(const D d)
Definition: test_util-inl.h:147
void ForUnsignedTypes(const Func &func)
Definition: test_util-inl.h:366
HWY_API void Store(Vec128< T, N > v, Simd< T, N > d, T *HWY_RESTRICT aligned)
Definition: arm_neon-inl.h:2343
typename D::T TFromD
Definition: shared-inl.h:140
void AssertArrayEqual(const TypeInfo &info, const void *expected_void, const void *actual_void, size_t N, const char *target_name, const char *filename, int line)
void PrintArray(const TypeInfo &info, const char *caption, const void *array_void, size_t N, size_t lane_u=0, size_t max_lanes=7)
Definition: aligned_allocator.h:23
FuncOutput(*)(const void *, FuncInput) Func
Definition: nanobenchmark.h:102
static HWY_MAYBE_UNUSED const char * TargetName(uint32_t target)
Definition: targets.h:74
HWY_INLINE void AssertEqual(const T expected, const T actual, const char *target_name, const char *filename, int line, size_t lane=0)
Definition: test_util.h:173
HWY_NORETURN void int line
Definition: base.h:665
message_info info
Definition: ojph_message.cpp:50
#define HWY_LANES(T)
Definition: set_macros-inl.h:80
#define HWY_NAMESPACE
Definition: set_macros-inl.h:77
Definition: test_util-inl.h:332
void operator()(T) const
Definition: test_util-inl.h:334
Definition: test_util-inl.h:220
void operator()(T) const
Definition: test_util-inl.h:222
Definition: test_util-inl.h:270
void operator()(T) const
Definition: test_util-inl.h:272
Definition: test_util-inl.h:294
void operator()(T) const
Definition: test_util-inl.h:296
Definition: test_util-inl.h:346
void operator()(T t) const
Definition: test_util-inl.h:348
Definition: test_util-inl.h:246
void operator()(T) const
Definition: test_util-inl.h:248
Definition: test_util-inl.h:194
static void Do()
Definition: test_util-inl.h:195
Definition: shared-inl.h:35