| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include <stdint.h> |
| 19 |
|
| 20 |
#include "hwy/base.h" |
| 21 |
#include "hwy/tests/hwy_gtest.h" |
| 22 |
#include "hwy/tests/test_util.h" |
| 23 |
|
| 24 |
|
| 25 |
#include "hwy/print-inl.h" |
| 26 |
|
| 27 |
|
| 28 |
#if defined(HIGHWAY_HWY_TESTS_TEST_UTIL_INL_H_) == \ |
| 29 |
defined(HWY_TARGET_TOGGLE) |
| 30 |
#ifdef HIGHWAY_HWY_TESTS_TEST_UTIL_INL_H_ |
| 31 |
#undef HIGHWAY_HWY_TESTS_TEST_UTIL_INL_H_ |
| 32 |
#else |
| 33 |
#define HIGHWAY_HWY_TESTS_TEST_UTIL_INL_H_ |
| 34 |
#endif |
| 35 |
|
| 36 |
HWY_BEFORE_NAMESPACE(); |
| 37 |
namespace hwy { |
| 38 |
namespace HWY_NAMESPACE { |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
template <class D, typename T = TFromD<D>, class V = Vec<D>> |
| 44 |
HWY_INLINE void AssertVecEqual(D d, const T* expected, VecArg<V> actual, |
| 45 |
const char* filename, const int line) { |
| 46 |
const size_t N = Lanes(d); |
| 47 |
auto actual_lanes = AllocateAligned<T>(N); |
| 48 |
Store(actual, d, actual_lanes.get()); |
| 49 |
|
| 50 |
const auto info = hwy::detail::MakeTypeInfo<T>(); |
| 51 |
const char* target_name = hwy::TargetName(HWY_TARGET); |
| 52 |
hwy::detail::AssertArrayEqual(info, expected, actual_lanes.get(), N, |
| 53 |
target_name, filename, line); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
template <class D, typename T = TFromD<D>, class V = Vec<D>> |
| 60 |
HWY_INLINE void AssertVecEqual(D d, VecArg<V> expected, VecArg<V> actual, |
| 61 |
const char* filename, int line) { |
| 62 |
auto expected_lanes = AllocateAligned<T>(Lanes(d)); |
| 63 |
Store(expected, d, expected_lanes.get()); |
| 64 |
AssertVecEqual(d, expected_lanes.get(), actual, filename, line); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
template <class D> |
| 69 |
HWY_NOINLINE void AssertMaskEqual(D d, VecArg<Mask<D>> a, VecArg<Mask<D>> b, |
| 70 |
const char* filename, int line) { |
| 71 |
|
| 72 |
const Vec<D> va = VecFromMask(d, a); |
| 73 |
const Vec<D> vb = VecFromMask(d, b); |
| 74 |
AssertVecEqual(d, va, vb, filename, line); |
| 75 |
|
| 76 |
const char* target_name = hwy::TargetName(HWY_TARGET); |
| 77 |
AssertEqual(CountTrue(d, a), CountTrue(d, b), target_name, filename, line); |
| 78 |
AssertEqual(AllTrue(d, a), AllTrue(d, b), target_name, filename, line); |
| 79 |
AssertEqual(AllFalse(d, a), AllFalse(d, b), target_name, filename, line); |
| 80 |
|
| 81 |
const size_t N = Lanes(d); |
| 82 |
#if HWY_TARGET == HWY_SCALAR |
| 83 |
const Rebind<uint8_t, D> d8; |
| 84 |
#else |
| 85 |
const Repartition<uint8_t, D> d8; |
| 86 |
#endif |
| 87 |
const size_t N8 = Lanes(d8); |
| 88 |
auto bits_a = AllocateAligned<uint8_t>(HWY_MAX(size_t{8}, N8)); |
| 89 |
auto bits_b = AllocateAligned<uint8_t>(size_t{HWY_MAX(8, N8)}); |
| 90 |
memset(bits_a.get(), 0, N8); |
| 91 |
memset(bits_b.get(), 0, N8); |
| 92 |
const size_t num_bytes_a = StoreMaskBits(d, a, bits_a.get()); |
| 93 |
const size_t num_bytes_b = StoreMaskBits(d, b, bits_b.get()); |
| 94 |
AssertEqual(num_bytes_a, num_bytes_b, target_name, filename, line); |
| 95 |
size_t i = 0; |
| 96 |
|
| 97 |
for (; i < N / 8; ++i) { |
| 98 |
if (bits_a[i] != bits_b[i]) { |
| 99 |
fprintf(stderr, "Mismatch in byte %d: %d != %d\n", static_cast<int>(i), |
| 100 |
bits_a[i], bits_b[i]); |
| 101 |
Print(d8, "expect", Load(d8, bits_a.get()), 0, N8); |
| 102 |
Print(d8, "actual", Load(d8, bits_b.get()), 0, N8); |
| 103 |
hwy::Abort(filename, line, "Masks not equal"); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
const size_t remainder = N % 8; |
| 108 |
if (remainder != 0) { |
| 109 |
const int mask = (1 << remainder) - 1; |
| 110 |
const int valid_a = bits_a[i] & mask; |
| 111 |
const int valid_b = bits_b[i] & mask; |
| 112 |
if (valid_a != valid_b) { |
| 113 |
fprintf(stderr, "Mismatch in last byte %d: %d != %d\n", |
| 114 |
static_cast<int>(i), valid_a, valid_b); |
| 115 |
Print(d8, "expect", Load(d8, bits_a.get()), 0, N8); |
| 116 |
Print(d8, "actual", Load(d8, bits_b.get()), 0, N8); |
| 117 |
hwy::Abort(filename, line, "Masks not equal"); |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
template <class D> |
| 127 |
HWY_INLINE Mask<D> MaskTrue(const D d) { |
| 128 |
return FirstN(d, Lanes(d)); |
| 129 |
} |
| 130 |
|
| 131 |
template <class D> |
| 132 |
HWY_INLINE Mask<D> MaskFalse(const D d) { |
| 133 |
const auto zero = Zero(RebindToSigned<D>()); |
| 134 |
return RebindMask(d, Lt(zero, zero)); |
| 135 |
} |
| 136 |
|
| 137 |
#ifndef HWY_ASSERT_EQ |
| 138 |
|
| 139 |
#define HWY_ASSERT_EQ(expected, actual) \ |
| 140 |
hwy::AssertEqual(expected, actual, hwy::TargetName(HWY_TARGET), __FILE__, \ |
| 141 |
__LINE__) |
| 142 |
|
| 143 |
#define HWY_ASSERT_ARRAY_EQ(expected, actual, count) \ |
| 144 |
hwy::AssertArrayEqual(expected, actual, count, hwy::TargetName(HWY_TARGET), \ |
| 145 |
__FILE__, __LINE__) |
| 146 |
|
| 147 |
#define HWY_ASSERT_STRING_EQ(expected, actual) \ |
| 148 |
hwy::AssertStringEqual(expected, actual, hwy::TargetName(HWY_TARGET), \ |
| 149 |
__FILE__, __LINE__) |
| 150 |
|
| 151 |
#define HWY_ASSERT_VEC_EQ(d, expected, actual) \ |
| 152 |
AssertVecEqual(d, expected, actual, __FILE__, __LINE__) |
| 153 |
|
| 154 |
#define HWY_ASSERT_MASK_EQ(d, expected, actual) \ |
| 155 |
AssertMaskEqual(d, expected, actual, __FILE__, __LINE__) |
| 156 |
|
| 157 |
#endif |
| 158 |
|
| 159 |
namespace detail { |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
template <typename T, size_t kMul, size_t kMinArg, class Test> |
| 168 |
struct ForeachCappedR { |
| 169 |
static void Do(size_t min_lanes, size_t max_lanes) { |
| 170 |
const CappedTag<T, kMul * kMinArg> d; |
| 171 |
|
| 172 |
|
| 173 |
const size_t lanes = Lanes(d); |
| 174 |
if (lanes < min_lanes) return; |
| 175 |
|
| 176 |
if (lanes <= max_lanes) { |
| 177 |
Test()(T(), d); |
| 178 |
} |
| 179 |
ForeachCappedR<T, kMul / 2, kMinArg, Test>::Do(min_lanes, max_lanes); |
| 180 |
} |
| 181 |
}; |
| 182 |
|
| 183 |
|
| 184 |
template <typename T, size_t kMinArg, class Test> |
| 185 |
struct ForeachCappedR<T, 0, kMinArg, Test> { |
| 186 |
static void Do(size_t, size_t) {} |
| 187 |
}; |
| 188 |
|
| 189 |
#if HWY_HAVE_SCALABLE |
| 190 |
|
| 191 |
template <typename T> |
| 192 |
constexpr int MinPow2() { |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
return HWY_MAX(-3, -static_cast<int>(CeilLog2(16 / sizeof(T)))); |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
template <typename T, int kPow2, int kAddPow2, class Test> |
| 202 |
struct ForeachShiftR { |
| 203 |
static void Do(size_t min_lanes) { |
| 204 |
const ScalableTag<T, kPow2 + kAddPow2> d; |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
if (Lanes(d) >= min_lanes) { |
| 209 |
Test()(T(), d); |
| 210 |
} else { |
| 211 |
fprintf(stderr, "%d lanes < %d: T=%d pow=%d\n", |
| 212 |
static_cast<int>(Lanes(d)), static_cast<int>(min_lanes), |
| 213 |
static_cast<int>(sizeof(T)), kPow2 + kAddPow2); |
| 214 |
HWY_ASSERT(min_lanes != 1); |
| 215 |
} |
| 216 |
|
| 217 |
ForeachShiftR<T, kPow2 + 1, kAddPow2, Test>::Do(min_lanes); |
| 218 |
} |
| 219 |
}; |
| 220 |
|
| 221 |
|
| 222 |
template <typename T, int kAddPow2, class Test> |
| 223 |
struct ForeachShiftR<T, 4, kAddPow2, Test> { |
| 224 |
static void Do(size_t) {} |
| 225 |
}; |
| 226 |
#else |
| 227 |
|
| 228 |
#endif |
| 229 |
|
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
template <class Test, int kPow2 = 1> |
| 243 |
class ForExtendableVectors { |
| 244 |
mutable bool called_ = false; |
| 245 |
|
| 246 |
public: |
| 247 |
~ForExtendableVectors() { |
| 248 |
if (!called_) { |
| 249 |
HWY_ABORT("Test is incorrect, ensure operator() is called"); |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
template <typename T> |
| 254 |
void operator()(T ) const { |
| 255 |
called_ = true; |
| 256 |
constexpr size_t kMaxCapped = HWY_LANES(T); |
| 257 |
|
| 258 |
const size_t max_lanes = Lanes(ScalableTag<T>()) >> kPow2; |
| 259 |
(void)kMaxCapped; |
| 260 |
(void)max_lanes; |
| 261 |
#if HWY_TARGET == HWY_SCALAR |
| 262 |
|
| 263 |
#else |
| 264 |
detail::ForeachCappedR<T, (kMaxCapped >> kPow2), 1, Test>::Do(1, max_lanes); |
| 265 |
#if HWY_TARGET == HWY_RVV |
| 266 |
|
| 267 |
detail::ForeachShiftR<T, detail::MinPow2<T>() + kPow2, -kPow2, Test>::Do(1); |
| 268 |
#elif HWY_HAVE_SCALABLE |
| 269 |
|
| 270 |
detail::ForeachShiftR<T, detail::MinPow2<T>() + kPow2 + 3, -kPow2 - 3, |
| 271 |
Test>::Do(1); |
| 272 |
#endif |
| 273 |
#endif |
| 274 |
} |
| 275 |
}; |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
template <class Test, int kPow2 = 1> |
| 280 |
class ForShrinkableVectors { |
| 281 |
mutable bool called_ = false; |
| 282 |
|
| 283 |
public: |
| 284 |
~ForShrinkableVectors() { |
| 285 |
if (!called_) { |
| 286 |
HWY_ABORT("Test is incorrect, ensure operator() is called"); |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
template <typename T> |
| 291 |
void operator()(T ) const { |
| 292 |
called_ = true; |
| 293 |
constexpr size_t kMinLanes = size_t{1} << kPow2; |
| 294 |
constexpr size_t kMaxCapped = HWY_LANES(T); |
| 295 |
|
| 296 |
constexpr size_t max_lanes = kMaxCapped; |
| 297 |
|
| 298 |
(void)kMinLanes; |
| 299 |
(void)max_lanes; |
| 300 |
(void)max_lanes; |
| 301 |
#if HWY_TARGET == HWY_SCALAR |
| 302 |
|
| 303 |
#else |
| 304 |
detail::ForeachCappedR<T, (kMaxCapped >> kPow2), kMinLanes, Test>::Do( |
| 305 |
kMinLanes, max_lanes); |
| 306 |
#if HWY_TARGET == HWY_RVV |
| 307 |
|
| 308 |
detail::ForeachShiftR<T, detail::MinPow2<T>() + kPow2, 0, Test>::Do( |
| 309 |
kMinLanes); |
| 310 |
#elif HWY_HAVE_SCALABLE |
| 311 |
|
| 312 |
detail::ForeachShiftR<T, detail::MinPow2<T>() + kPow2 + 3, -3, Test>::Do( |
| 313 |
kMinLanes); |
| 314 |
#endif |
| 315 |
#endif |
| 316 |
} |
| 317 |
}; |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
template <size_t kMinBits, class Test> |
| 322 |
class ForGEVectors { |
| 323 |
mutable bool called_ = false; |
| 324 |
|
| 325 |
public: |
| 326 |
~ForGEVectors() { |
| 327 |
if (!called_) { |
| 328 |
HWY_ABORT("Test is incorrect, ensure operator() is called"); |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
template <typename T> |
| 333 |
void operator()(T ) const { |
| 334 |
called_ = true; |
| 335 |
constexpr size_t kMaxCapped = HWY_LANES(T); |
| 336 |
constexpr size_t kMinLanes = kMinBits / 8 / sizeof(T); |
| 337 |
|
| 338 |
constexpr size_t max_lanes = kMaxCapped; |
| 339 |
(void)max_lanes; |
| 340 |
#if HWY_TARGET == HWY_SCALAR |
| 341 |
(void)kMinLanes; |
| 342 |
#else |
| 343 |
detail::ForeachCappedR<T, HWY_LANES(T) / kMinLanes, kMinLanes, Test>::Do( |
| 344 |
kMinLanes, max_lanes); |
| 345 |
#if HWY_TARGET == HWY_RVV |
| 346 |
|
| 347 |
constexpr size_t kRatio = 128 / kMinBits; |
| 348 |
constexpr int kMinPow2 = |
| 349 |
kRatio == 0 ? 0 : -static_cast<int>(CeilLog2(kRatio)); |
| 350 |
|
| 351 |
detail::ForeachShiftR<T, kMinPow2, 0, Test>::Do(kMinLanes); |
| 352 |
#elif HWY_HAVE_SCALABLE |
| 353 |
|
| 354 |
constexpr size_t kRatio = 128 / kMinBits; |
| 355 |
constexpr int kMinPow2 = |
| 356 |
kRatio == 0 ? 0 : -static_cast<int>(CeilLog2(kRatio)); |
| 357 |
|
| 358 |
detail::ForeachShiftR<T, kMinPow2 + 3, -3, Test>::Do(kMinLanes); |
| 359 |
#endif |
| 360 |
#endif |
| 361 |
} |
| 362 |
}; |
| 363 |
|
| 364 |
template <class Test> |
| 365 |
using ForGE128Vectors = ForGEVectors<128, Test>; |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
template <class Test, int kPow2 = 1> |
| 370 |
class ForPromoteVectors { |
| 371 |
mutable bool called_ = false; |
| 372 |
|
| 373 |
public: |
| 374 |
~ForPromoteVectors() { |
| 375 |
if (!called_) { |
| 376 |
HWY_ABORT("Test is incorrect, ensure operator() is called"); |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
template <typename T> |
| 381 |
void operator()(T ) const { |
| 382 |
called_ = true; |
| 383 |
constexpr size_t kFactor = size_t{1} << kPow2; |
| 384 |
static_assert(kFactor >= 2 && kFactor * sizeof(T) <= sizeof(uint64_t), ""); |
| 385 |
constexpr size_t kMaxCapped = HWY_LANES(T); |
| 386 |
constexpr size_t kMinLanes = kFactor; |
| 387 |
|
| 388 |
const size_t max_lanes = Lanes(ScalableTag<T>()) >> kPow2; |
| 389 |
(void)kMaxCapped; |
| 390 |
(void)kMinLanes; |
| 391 |
(void)max_lanes; |
| 392 |
#if HWY_TARGET == HWY_SCALAR |
| 393 |
detail::ForeachCappedR<T, 1, 1, Test>::Do(1, 1); |
| 394 |
#else |
| 395 |
|
| 396 |
detail::ForeachCappedR<T, (kMaxCapped >> kPow2), 1, Test>::Do(kMinLanes, |
| 397 |
max_lanes); |
| 398 |
#if HWY_TARGET == HWY_RVV |
| 399 |
|
| 400 |
detail::ForeachShiftR<T, detail::MinPow2<T>() + kPow2, -kPow2, Test>::Do( |
| 401 |
kMinLanes); |
| 402 |
#elif HWY_HAVE_SCALABLE |
| 403 |
|
| 404 |
detail::ForeachShiftR<T, detail::MinPow2<T>() + kPow2 + 3, -kPow2 - 3, |
| 405 |
Test>::Do(kMinLanes); |
| 406 |
#endif |
| 407 |
#endif |
| 408 |
} |
| 409 |
}; |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
template <class Test, int kPow2 = 1> |
| 414 |
class ForDemoteVectors { |
| 415 |
mutable bool called_ = false; |
| 416 |
|
| 417 |
public: |
| 418 |
~ForDemoteVectors() { |
| 419 |
if (!called_) { |
| 420 |
HWY_ABORT("Test is incorrect, ensure operator() is called"); |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
template <typename T> |
| 425 |
void operator()(T ) const { |
| 426 |
called_ = true; |
| 427 |
constexpr size_t kMinLanes = size_t{1} << kPow2; |
| 428 |
constexpr size_t kMaxCapped = HWY_LANES(T); |
| 429 |
|
| 430 |
constexpr size_t max_lanes = kMaxCapped; |
| 431 |
|
| 432 |
(void)kMinLanes; |
| 433 |
(void)max_lanes; |
| 434 |
(void)max_lanes; |
| 435 |
#if HWY_TARGET == HWY_SCALAR |
| 436 |
detail::ForeachCappedR<T, 1, 1, Test>::Do(1, 1); |
| 437 |
#else |
| 438 |
detail::ForeachCappedR<T, (kMaxCapped >> kPow2), kMinLanes, Test>::Do( |
| 439 |
kMinLanes, max_lanes); |
| 440 |
|
| 441 |
|
| 442 |
#if HWY_TARGET == HWY_RVV |
| 443 |
|
| 444 |
detail::ForeachShiftR<T, detail::MinPow2<T>() + kPow2, 0, Test>::Do( |
| 445 |
kMinLanes); |
| 446 |
#elif HWY_HAVE_SCALABLE |
| 447 |
|
| 448 |
detail::ForeachShiftR<T, detail::MinPow2<T>() + kPow2 + 3, -3, Test>::Do( |
| 449 |
kMinLanes); |
| 450 |
#endif |
| 451 |
#endif |
| 452 |
} |
| 453 |
}; |
| 454 |
|
| 455 |
|
| 456 |
template <class Test, int kPow2 = 1> |
| 457 |
class ForHalfVectors { |
| 458 |
mutable bool called_ = false; |
| 459 |
|
| 460 |
public: |
| 461 |
~ForHalfVectors() { |
| 462 |
if (!called_) { |
| 463 |
HWY_ABORT("Test is incorrect, ensure operator() is called"); |
| 464 |
} |
| 465 |
} |
| 466 |
|
| 467 |
template <typename T> |
| 468 |
void operator()(T ) const { |
| 469 |
called_ = true; |
| 470 |
#if HWY_TARGET == HWY_SCALAR |
| 471 |
detail::ForeachCappedR<T, 1, 1, Test>::Do(1, 1); |
| 472 |
#else |
| 473 |
constexpr size_t kMinLanes = size_t{1} << kPow2; |
| 474 |
|
| 475 |
constexpr size_t kMaxCapped = HWY_LANES(T); |
| 476 |
detail::ForeachCappedR<T, (kMaxCapped >> kPow2), kMinLanes, Test>::Do( |
| 477 |
kMinLanes, kMaxCapped); |
| 478 |
|
| 479 |
|
| 480 |
#if HWY_TARGET == HWY_RVV |
| 481 |
|
| 482 |
detail::ForeachShiftR<T, detail::MinPow2<T>() + kPow2, 0, Test>::Do( |
| 483 |
kMinLanes); |
| 484 |
#elif HWY_HAVE_SCALABLE |
| 485 |
|
| 486 |
detail::ForeachShiftR<T, detail::MinPow2<T>() + kPow2 + 3, -3, Test>::Do( |
| 487 |
kMinLanes); |
| 488 |
#endif |
| 489 |
#endif |
| 490 |
} |
| 491 |
}; |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
template <class Test> |
| 496 |
class ForPartialVectors { |
| 497 |
mutable bool called_ = false; |
| 498 |
|
| 499 |
public: |
| 500 |
~ForPartialVectors() { |
| 501 |
if (!called_) { |
| 502 |
HWY_ABORT("Test is incorrect, ensure operator() is called"); |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
template <typename T> |
| 507 |
void operator()(T t) const { |
| 508 |
called_ = true; |
| 509 |
#if HWY_TARGET == HWY_SCALAR |
| 510 |
(void)t; |
| 511 |
detail::ForeachCappedR<T, 1, 1, Test>::Do(1, 1); |
| 512 |
#else |
| 513 |
ForExtendableVectors<Test, 0>()(t); |
| 514 |
#endif |
| 515 |
} |
| 516 |
}; |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
template <class Func> |
| 521 |
void ForSignedTypes(const Func& func) { |
| 522 |
func(int8_t()); |
| 523 |
func(int16_t()); |
| 524 |
func(int32_t()); |
| 525 |
#if HWY_HAVE_INTEGER64 |
| 526 |
func(int64_t()); |
| 527 |
#endif |
| 528 |
} |
| 529 |
|
| 530 |
template <class Func> |
| 531 |
void ForUnsignedTypes(const Func& func) { |
| 532 |
func(uint8_t()); |
| 533 |
func(uint16_t()); |
| 534 |
func(uint32_t()); |
| 535 |
#if HWY_HAVE_INTEGER64 |
| 536 |
func(uint64_t()); |
| 537 |
#endif |
| 538 |
} |
| 539 |
|
| 540 |
template <class Func> |
| 541 |
void ForIntegerTypes(const Func& func) { |
| 542 |
ForSignedTypes(func); |
| 543 |
ForUnsignedTypes(func); |
| 544 |
} |
| 545 |
|
| 546 |
template <class Func> |
| 547 |
void ForFloatTypes(const Func& func) { |
| 548 |
func(float()); |
| 549 |
#if HWY_HAVE_FLOAT64 |
| 550 |
func(double()); |
| 551 |
#endif |
| 552 |
} |
| 553 |
|
| 554 |
template <class Func> |
| 555 |
void ForAllTypes(const Func& func) { |
| 556 |
ForIntegerTypes(func); |
| 557 |
ForFloatTypes(func); |
| 558 |
} |
| 559 |
|
| 560 |
template <class Func> |
| 561 |
void ForUI8(const Func& func) { |
| 562 |
func(uint8_t()); |
| 563 |
func(int8_t()); |
| 564 |
} |
| 565 |
|
| 566 |
template <class Func> |
| 567 |
void ForUI16(const Func& func) { |
| 568 |
func(uint16_t()); |
| 569 |
func(int16_t()); |
| 570 |
} |
| 571 |
|
| 572 |
template <class Func> |
| 573 |
void ForUIF16(const Func& func) { |
| 574 |
ForUI16(func); |
| 575 |
#if HWY_HAVE_FLOAT16 |
| 576 |
func(float16_t()); |
| 577 |
#endif |
| 578 |
} |
| 579 |
|
| 580 |
template <class Func> |
| 581 |
void ForUI32(const Func& func) { |
| 582 |
func(uint32_t()); |
| 583 |
func(int32_t()); |
| 584 |
} |
| 585 |
|
| 586 |
template <class Func> |
| 587 |
void ForUIF32(const Func& func) { |
| 588 |
ForUI32(func); |
| 589 |
func(float()); |
| 590 |
} |
| 591 |
|
| 592 |
template <class Func> |
| 593 |
void ForUI64(const Func& func) { |
| 594 |
#if HWY_HAVE_INTEGER64 |
| 595 |
func(uint64_t()); |
| 596 |
func(int64_t()); |
| 597 |
#endif |
| 598 |
} |
| 599 |
|
| 600 |
template <class Func> |
| 601 |
void ForUIF64(const Func& func) { |
| 602 |
ForUI64(func); |
| 603 |
#if HWY_HAVE_FLOAT64 |
| 604 |
func(double()); |
| 605 |
#endif |
| 606 |
} |
| 607 |
|
| 608 |
template <class Func> |
| 609 |
void ForUI3264(const Func& func) { |
| 610 |
ForUI32(func); |
| 611 |
ForUI64(func); |
| 612 |
} |
| 613 |
|
| 614 |
template <class Func> |
| 615 |
void ForUIF3264(const Func& func) { |
| 616 |
ForUIF32(func); |
| 617 |
ForUIF64(func); |
| 618 |
} |
| 619 |
|
| 620 |
template <class Func> |
| 621 |
void ForUI163264(const Func& func) { |
| 622 |
ForUI16(func); |
| 623 |
ForUI3264(func); |
| 624 |
} |
| 625 |
|
| 626 |
template <class Func> |
| 627 |
void ForUIF163264(const Func& func) { |
| 628 |
ForUIF16(func); |
| 629 |
ForUIF3264(func); |
| 630 |
} |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
constexpr size_t AdjustedReps(size_t max_reps) { |
| 635 |
#if HWY_ARCH_RVV |
| 636 |
return HWY_MAX(max_reps / 32, 2); |
| 637 |
#elif HWY_IS_DEBUG_BUILD |
| 638 |
return HWY_MAX(max_reps / 8, 2); |
| 639 |
#elif HWY_ARCH_ARM |
| 640 |
return HWY_MAX(max_reps / 4, 2); |
| 641 |
#else |
| 642 |
return HWY_MAX(max_reps, 2); |
| 643 |
#endif |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
constexpr size_t AdjustedLog2Reps(size_t max_pow2) { |
| 648 |
|
| 649 |
#if HWY_ARCH_RVV |
| 650 |
return HWY_MIN(max_pow2 - 4, max_pow2); |
| 651 |
#elif HWY_IS_DEBUG_BUILD |
| 652 |
return HWY_MIN(max_pow2 - 1, max_pow2); |
| 653 |
#elif HWY_ARCH_ARM |
| 654 |
return HWY_MIN(max_pow2 - 1, max_pow2); |
| 655 |
#else |
| 656 |
return max_pow2; |
| 657 |
#endif |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
} |
| 662 |
} |
| 663 |
HWY_AFTER_NAMESPACE(); |
| 664 |
|
| 665 |
#endif |