| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "hwy/base.h" |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
HWY_DIAGNOSTICS(push) |
| 29 |
#if HWY_COMPILER_GCC_ACTUAL |
| 30 |
HWY_DIAGNOSTICS_OFF(disable : 4701, ignored "-Wuninitialized") |
| 31 |
HWY_DIAGNOSTICS_OFF(disable : 4703 6001 26494, ignored "-Wmaybe-uninitialized") |
| 32 |
#endif |
| 33 |
|
| 34 |
|
| 35 |
#include <immintrin.h> |
| 36 |
|
| 37 |
#if HWY_COMPILER_CLANGCL |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
#include <avxintrin.h> |
| 42 |
|
| 43 |
#include <avx2intrin.h> |
| 44 |
#include <bmi2intrin.h> |
| 45 |
#include <f16cintrin.h> |
| 46 |
#include <fmaintrin.h> |
| 47 |
#include <smmintrin.h> |
| 48 |
#endif |
| 49 |
|
| 50 |
#include <stddef.h> |
| 51 |
#include <stdint.h> |
| 52 |
#include <string.h> |
| 53 |
|
| 54 |
#if HWY_IS_MSAN |
| 55 |
#include <sanitizer/msan_interface.h> |
| 56 |
#endif |
| 57 |
|
| 58 |
|
| 59 |
#include "hwy/ops/x86_128-inl.h" |
| 60 |
|
| 61 |
HWY_BEFORE_NAMESPACE(); |
| 62 |
namespace hwy { |
| 63 |
namespace HWY_NAMESPACE { |
| 64 |
namespace detail { |
| 65 |
|
| 66 |
template <typename T> |
| 67 |
struct Raw256 { |
| 68 |
using type = __m256i; |
| 69 |
}; |
| 70 |
template <> |
| 71 |
struct Raw256<float> { |
| 72 |
using type = __m256; |
| 73 |
}; |
| 74 |
template <> |
| 75 |
struct Raw256<double> { |
| 76 |
using type = __m256d; |
| 77 |
}; |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
template <typename T> |
| 82 |
class Vec256 { |
| 83 |
using Raw = typename detail::Raw256<T>::type; |
| 84 |
|
| 85 |
public: |
| 86 |
using PrivateT = T; |
| 87 |
static constexpr size_t kPrivateN = 32 / sizeof(T); |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
HWY_INLINE Vec256& operator*=(const Vec256 other) { |
| 92 |
return *this = (*this * other); |
| 93 |
} |
| 94 |
HWY_INLINE Vec256& operator/=(const Vec256 other) { |
| 95 |
return *this = (*this / other); |
| 96 |
} |
| 97 |
HWY_INLINE Vec256& operator+=(const Vec256 other) { |
| 98 |
return *this = (*this + other); |
| 99 |
} |
| 100 |
HWY_INLINE Vec256& operator-=(const Vec256 other) { |
| 101 |
return *this = (*this - other); |
| 102 |
} |
| 103 |
HWY_INLINE Vec256& operator&=(const Vec256 other) { |
| 104 |
return *this = (*this & other); |
| 105 |
} |
| 106 |
HWY_INLINE Vec256& operator|=(const Vec256 other) { |
| 107 |
return *this = (*this | other); |
| 108 |
} |
| 109 |
HWY_INLINE Vec256& operator^=(const Vec256 other) { |
| 110 |
return *this = (*this ^ other); |
| 111 |
} |
| 112 |
|
| 113 |
Raw raw; |
| 114 |
}; |
| 115 |
|
| 116 |
#if HWY_TARGET <= HWY_AVX3 |
| 117 |
|
| 118 |
namespace detail { |
| 119 |
|
| 120 |
|
| 121 |
template <size_t size> |
| 122 |
struct RawMask256 {}; |
| 123 |
template <> |
| 124 |
struct RawMask256<1> { |
| 125 |
using type = __mmask32; |
| 126 |
}; |
| 127 |
template <> |
| 128 |
struct RawMask256<2> { |
| 129 |
using type = __mmask16; |
| 130 |
}; |
| 131 |
template <> |
| 132 |
struct RawMask256<4> { |
| 133 |
using type = __mmask8; |
| 134 |
}; |
| 135 |
template <> |
| 136 |
struct RawMask256<8> { |
| 137 |
using type = __mmask8; |
| 138 |
}; |
| 139 |
|
| 140 |
} |
| 141 |
|
| 142 |
template <typename T> |
| 143 |
struct Mask256 { |
| 144 |
using Raw = typename detail::RawMask256<sizeof(T)>::type; |
| 145 |
|
| 146 |
static Mask256<T> FromBits(uint64_t mask_bits) { |
| 147 |
return Mask256<T>{static_cast<Raw>(mask_bits)}; |
| 148 |
} |
| 149 |
|
| 150 |
Raw raw; |
| 151 |
}; |
| 152 |
|
| 153 |
#else |
| 154 |
|
| 155 |
|
| 156 |
template <typename T> |
| 157 |
struct Mask256 { |
| 158 |
typename detail::Raw256<T>::type raw; |
| 159 |
}; |
| 160 |
|
| 161 |
#endif |
| 162 |
|
| 163 |
template <typename T> |
| 164 |
using Full256 = Simd<T, 32 / sizeof(T), 0>; |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
namespace detail { |
| 169 |
|
| 170 |
HWY_INLINE __m256i BitCastToInteger(__m256i v) { return v; } |
| 171 |
HWY_INLINE __m256i BitCastToInteger(__m256 v) { return _mm256_castps_si256(v); } |
| 172 |
HWY_INLINE __m256i BitCastToInteger(__m256d v) { |
| 173 |
return _mm256_castpd_si256(v); |
| 174 |
} |
| 175 |
|
| 176 |
template <typename T> |
| 177 |
HWY_INLINE Vec256<uint8_t> BitCastToByte(Vec256<T> v) { |
| 178 |
return Vec256<uint8_t>{BitCastToInteger(v.raw)}; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
template <typename T> |
| 183 |
struct BitCastFromInteger256 { |
| 184 |
HWY_INLINE __m256i operator()(__m256i v) { return v; } |
| 185 |
}; |
| 186 |
template <> |
| 187 |
struct BitCastFromInteger256<float> { |
| 188 |
HWY_INLINE __m256 operator()(__m256i v) { return _mm256_castsi256_ps(v); } |
| 189 |
}; |
| 190 |
template <> |
| 191 |
struct BitCastFromInteger256<double> { |
| 192 |
HWY_INLINE __m256d operator()(__m256i v) { return _mm256_castsi256_pd(v); } |
| 193 |
}; |
| 194 |
|
| 195 |
template <typename T> |
| 196 |
HWY_INLINE Vec256<T> BitCastFromByte(Full256<T> , Vec256<uint8_t> v) { |
| 197 |
return Vec256<T>{BitCastFromInteger256<T>()(v.raw)}; |
| 198 |
} |
| 199 |
|
| 200 |
} |
| 201 |
|
| 202 |
template <typename T, typename FromT> |
| 203 |
HWY_API Vec256<T> BitCast(Full256<T> d, Vec256<FromT> v) { |
| 204 |
return detail::BitCastFromByte(d, detail::BitCastToByte(v)); |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
template <typename T> |
| 211 |
HWY_API Vec256<T> Zero(Full256<T> ) { |
| 212 |
return Vec256<T>{_mm256_setzero_si256()}; |
| 213 |
} |
| 214 |
HWY_API Vec256<float> Zero(Full256<float> ) { |
| 215 |
return Vec256<float>{_mm256_setzero_ps()}; |
| 216 |
} |
| 217 |
HWY_API Vec256<double> Zero(Full256<double> ) { |
| 218 |
return Vec256<double>{_mm256_setzero_pd()}; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
HWY_API Vec256<uint8_t> Set(Full256<uint8_t> , const uint8_t t) { |
| 223 |
return Vec256<uint8_t>{_mm256_set1_epi8(static_cast<char>(t))}; |
| 224 |
} |
| 225 |
HWY_API Vec256<uint16_t> Set(Full256<uint16_t> , const uint16_t t) { |
| 226 |
return Vec256<uint16_t>{_mm256_set1_epi16(static_cast<short>(t))}; |
| 227 |
} |
| 228 |
HWY_API Vec256<uint32_t> Set(Full256<uint32_t> , const uint32_t t) { |
| 229 |
return Vec256<uint32_t>{_mm256_set1_epi32(static_cast<int>(t))}; |
| 230 |
} |
| 231 |
HWY_API Vec256<uint64_t> Set(Full256<uint64_t> , const uint64_t t) { |
| 232 |
return Vec256<uint64_t>{ |
| 233 |
_mm256_set1_epi64x(static_cast<long long>(t))}; |
| 234 |
} |
| 235 |
HWY_API Vec256<int8_t> Set(Full256<int8_t> , const int8_t t) { |
| 236 |
return Vec256<int8_t>{_mm256_set1_epi8(static_cast<char>(t))}; |
| 237 |
} |
| 238 |
HWY_API Vec256<int16_t> Set(Full256<int16_t> , const int16_t t) { |
| 239 |
return Vec256<int16_t>{_mm256_set1_epi16(static_cast<short>(t))}; |
| 240 |
} |
| 241 |
HWY_API Vec256<int32_t> Set(Full256<int32_t> , const int32_t t) { |
| 242 |
return Vec256<int32_t>{_mm256_set1_epi32(t)}; |
| 243 |
} |
| 244 |
HWY_API Vec256<int64_t> Set(Full256<int64_t> , const int64_t t) { |
| 245 |
return Vec256<int64_t>{ |
| 246 |
_mm256_set1_epi64x(static_cast<long long>(t))}; |
| 247 |
} |
| 248 |
HWY_API Vec256<float> Set(Full256<float> , const float t) { |
| 249 |
return Vec256<float>{_mm256_set1_ps(t)}; |
| 250 |
} |
| 251 |
HWY_API Vec256<double> Set(Full256<double> , const double t) { |
| 252 |
return Vec256<double>{_mm256_set1_pd(t)}; |
| 253 |
} |
| 254 |
|
| 255 |
HWY_DIAGNOSTICS(push) |
| 256 |
HWY_DIAGNOSTICS_OFF(disable : 4700, ignored "-Wuninitialized") |
| 257 |
|
| 258 |
|
| 259 |
template <typename T> |
| 260 |
HWY_API Vec256<T> Undefined(Full256<T> ) { |
| 261 |
|
| 262 |
|
| 263 |
return Vec256<T>{_mm256_undefined_si256()}; |
| 264 |
} |
| 265 |
HWY_API Vec256<float> Undefined(Full256<float> ) { |
| 266 |
return Vec256<float>{_mm256_undefined_ps()}; |
| 267 |
} |
| 268 |
HWY_API Vec256<double> Undefined(Full256<double> ) { |
| 269 |
return Vec256<double>{_mm256_undefined_pd()}; |
| 270 |
} |
| 271 |
|
| 272 |
HWY_DIAGNOSTICS(pop) |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
template <typename T> |
| 279 |
HWY_API Vec256<T> And(Vec256<T> a, Vec256<T> b) { |
| 280 |
return Vec256<T>{_mm256_and_si256(a.raw, b.raw)}; |
| 281 |
} |
| 282 |
|
| 283 |
HWY_API Vec256<float> And(const Vec256<float> a, const Vec256<float> b) { |
| 284 |
return Vec256<float>{_mm256_and_ps(a.raw, b.raw)}; |
| 285 |
} |
| 286 |
HWY_API Vec256<double> And(const Vec256<double> a, const Vec256<double> b) { |
| 287 |
return Vec256<double>{_mm256_and_pd(a.raw, b.raw)}; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
template <typename T> |
| 294 |
HWY_API Vec256<T> AndNot(Vec256<T> not_mask, Vec256<T> mask) { |
| 295 |
return Vec256<T>{_mm256_andnot_si256(not_mask.raw, mask.raw)}; |
| 296 |
} |
| 297 |
HWY_API Vec256<float> AndNot(const Vec256<float> not_mask, |
| 298 |
const Vec256<float> mask) { |
| 299 |
return Vec256<float>{_mm256_andnot_ps(not_mask.raw, mask.raw)}; |
| 300 |
} |
| 301 |
HWY_API Vec256<double> AndNot(const Vec256<double> not_mask, |
| 302 |
const Vec256<double> mask) { |
| 303 |
return Vec256<double>{_mm256_andnot_pd(not_mask.raw, mask.raw)}; |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
template <typename T> |
| 309 |
HWY_API Vec256<T> Or(Vec256<T> a, Vec256<T> b) { |
| 310 |
return Vec256<T>{_mm256_or_si256(a.raw, b.raw)}; |
| 311 |
} |
| 312 |
|
| 313 |
HWY_API Vec256<float> Or(const Vec256<float> a, const Vec256<float> b) { |
| 314 |
return Vec256<float>{_mm256_or_ps(a.raw, b.raw)}; |
| 315 |
} |
| 316 |
HWY_API Vec256<double> Or(const Vec256<double> a, const Vec256<double> b) { |
| 317 |
return Vec256<double>{_mm256_or_pd(a.raw, b.raw)}; |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
template <typename T> |
| 323 |
HWY_API Vec256<T> Xor(Vec256<T> a, Vec256<T> b) { |
| 324 |
return Vec256<T>{_mm256_xor_si256(a.raw, b.raw)}; |
| 325 |
} |
| 326 |
|
| 327 |
HWY_API Vec256<float> Xor(const Vec256<float> a, const Vec256<float> b) { |
| 328 |
return Vec256<float>{_mm256_xor_ps(a.raw, b.raw)}; |
| 329 |
} |
| 330 |
HWY_API Vec256<double> Xor(const Vec256<double> a, const Vec256<double> b) { |
| 331 |
return Vec256<double>{_mm256_xor_pd(a.raw, b.raw)}; |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
template <typename T> |
| 336 |
HWY_API Vec256<T> Not(const Vec256<T> v) { |
| 337 |
using TU = MakeUnsigned<T>; |
| 338 |
#if HWY_TARGET <= HWY_AVX3 |
| 339 |
const __m256i vu = BitCast(Full256<TU>(), v).raw; |
| 340 |
return BitCast(Full256<T>(), |
| 341 |
Vec256<TU>{_mm256_ternarylogic_epi32(vu, vu, vu, 0x55)}); |
| 342 |
#else |
| 343 |
return Xor(v, BitCast(Full256<T>(), Vec256<TU>{_mm256_set1_epi32(-1)})); |
| 344 |
#endif |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
template <typename T> |
| 349 |
HWY_API Vec256<T> Xor3(Vec256<T> x1, Vec256<T> x2, Vec256<T> x3) { |
| 350 |
#if HWY_TARGET <= HWY_AVX3 |
| 351 |
const Full256<T> d; |
| 352 |
const RebindToUnsigned<decltype(d)> du; |
| 353 |
using VU = VFromD<decltype(du)>; |
| 354 |
const __m256i ret = _mm256_ternarylogic_epi64( |
| 355 |
BitCast(du, x1).raw, BitCast(du, x2).raw, BitCast(du, x3).raw, 0x96); |
| 356 |
return BitCast(d, VU{ret}); |
| 357 |
#else |
| 358 |
return Xor(x1, Xor(x2, x3)); |
| 359 |
#endif |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
template <typename T> |
| 364 |
HWY_API Vec256<T> Or3(Vec256<T> o1, Vec256<T> o2, Vec256<T> o3) { |
| 365 |
#if HWY_TARGET <= HWY_AVX3 |
| 366 |
const Full256<T> d; |
| 367 |
const RebindToUnsigned<decltype(d)> du; |
| 368 |
using VU = VFromD<decltype(du)>; |
| 369 |
const __m256i ret = _mm256_ternarylogic_epi64( |
| 370 |
BitCast(du, o1).raw, BitCast(du, o2).raw, BitCast(du, o3).raw, 0xFE); |
| 371 |
return BitCast(d, VU{ret}); |
| 372 |
#else |
| 373 |
return Or(o1, Or(o2, o3)); |
| 374 |
#endif |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
template <typename T> |
| 379 |
HWY_API Vec256<T> OrAnd(Vec256<T> o, Vec256<T> a1, Vec256<T> a2) { |
| 380 |
#if HWY_TARGET <= HWY_AVX3 |
| 381 |
const Full256<T> d; |
| 382 |
const RebindToUnsigned<decltype(d)> du; |
| 383 |
using VU = VFromD<decltype(du)>; |
| 384 |
const __m256i ret = _mm256_ternarylogic_epi64( |
| 385 |
BitCast(du, o).raw, BitCast(du, a1).raw, BitCast(du, a2).raw, 0xF8); |
| 386 |
return BitCast(d, VU{ret}); |
| 387 |
#else |
| 388 |
return Or(o, And(a1, a2)); |
| 389 |
#endif |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
template <typename T> |
| 394 |
HWY_API Vec256<T> IfVecThenElse(Vec256<T> mask, Vec256<T> yes, Vec256<T> no) { |
| 395 |
#if HWY_TARGET <= HWY_AVX3 |
| 396 |
const Full256<T> d; |
| 397 |
const RebindToUnsigned<decltype(d)> du; |
| 398 |
using VU = VFromD<decltype(du)>; |
| 399 |
return BitCast(d, VU{_mm256_ternarylogic_epi64(BitCast(du, mask).raw, |
| 400 |
BitCast(du, yes).raw, |
| 401 |
BitCast(du, no).raw, 0xCA)}); |
| 402 |
#else |
| 403 |
return IfThenElse(MaskFromVec(mask), yes, no); |
| 404 |
#endif |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
template <typename T> |
| 410 |
HWY_API Vec256<T> operator&(const Vec256<T> a, const Vec256<T> b) { |
| 411 |
return And(a, b); |
| 412 |
} |
| 413 |
|
| 414 |
template <typename T> |
| 415 |
HWY_API Vec256<T> operator|(const Vec256<T> a, const Vec256<T> b) { |
| 416 |
return Or(a, b); |
| 417 |
} |
| 418 |
|
| 419 |
template <typename T> |
| 420 |
HWY_API Vec256<T> operator^(const Vec256<T> a, const Vec256<T> b) { |
| 421 |
return Xor(a, b); |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
#if HWY_TARGET == HWY_AVX3_DL |
| 428 |
|
| 429 |
#ifdef HWY_NATIVE_POPCNT |
| 430 |
#undef HWY_NATIVE_POPCNT |
| 431 |
#else |
| 432 |
#define HWY_NATIVE_POPCNT |
| 433 |
#endif |
| 434 |
|
| 435 |
namespace detail { |
| 436 |
|
| 437 |
template <typename T> |
| 438 |
HWY_INLINE Vec256<T> PopulationCount(hwy::SizeTag<1> , Vec256<T> v) { |
| 439 |
return Vec256<T>{_mm256_popcnt_epi8(v.raw)}; |
| 440 |
} |
| 441 |
template <typename T> |
| 442 |
HWY_INLINE Vec256<T> PopulationCount(hwy::SizeTag<2> , Vec256<T> v) { |
| 443 |
return Vec256<T>{_mm256_popcnt_epi16(v.raw)}; |
| 444 |
} |
| 445 |
template <typename T> |
| 446 |
HWY_INLINE Vec256<T> PopulationCount(hwy::SizeTag<4> , Vec256<T> v) { |
| 447 |
return Vec256<T>{_mm256_popcnt_epi32(v.raw)}; |
| 448 |
} |
| 449 |
template <typename T> |
| 450 |
HWY_INLINE Vec256<T> PopulationCount(hwy::SizeTag<8> , Vec256<T> v) { |
| 451 |
return Vec256<T>{_mm256_popcnt_epi64(v.raw)}; |
| 452 |
} |
| 453 |
|
| 454 |
} |
| 455 |
|
| 456 |
template <typename T> |
| 457 |
HWY_API Vec256<T> PopulationCount(Vec256<T> v) { |
| 458 |
return detail::PopulationCount(hwy::SizeTag<sizeof(T)>(), v); |
| 459 |
} |
| 460 |
|
| 461 |
#endif |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
template <typename T> |
| 468 |
HWY_API Vec256<T> CopySign(const Vec256<T> magn, const Vec256<T> sign) { |
| 469 |
static_assert(IsFloat<T>(), "Only makes sense for floating-point"); |
| 470 |
|
| 471 |
const Full256<T> d; |
| 472 |
const auto msb = SignBit(d); |
| 473 |
|
| 474 |
#if HWY_TARGET <= HWY_AVX3 |
| 475 |
const Rebind<MakeUnsigned<T>, decltype(d)> du; |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
const __m256i out = _mm256_ternarylogic_epi32( |
| 487 |
BitCast(du, msb).raw, BitCast(du, magn).raw, BitCast(du, sign).raw, 0xAC); |
| 488 |
return BitCast(d, decltype(Zero(du)){out}); |
| 489 |
#else |
| 490 |
return Or(AndNot(msb, magn), And(msb, sign)); |
| 491 |
#endif |
| 492 |
} |
| 493 |
|
| 494 |
template <typename T> |
| 495 |
HWY_API Vec256<T> CopySignToAbs(const Vec256<T> abs, const Vec256<T> sign) { |
| 496 |
#if HWY_TARGET <= HWY_AVX3 |
| 497 |
|
| 498 |
return CopySign(abs, sign); |
| 499 |
#else |
| 500 |
return Or(abs, And(SignBit(Full256<T>()), sign)); |
| 501 |
#endif |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
#if HWY_TARGET <= HWY_AVX3 |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
namespace detail { |
| 513 |
|
| 514 |
|
| 515 |
template <typename T> |
| 516 |
HWY_INLINE Vec256<T> IfThenElse(hwy::SizeTag<1> , Mask256<T> mask, |
| 517 |
Vec256<T> yes, Vec256<T> no) { |
| 518 |
return Vec256<T>{_mm256_mask_mov_epi8(no.raw, mask.raw, yes.raw)}; |
| 519 |
} |
| 520 |
template <typename T> |
| 521 |
HWY_INLINE Vec256<T> IfThenElse(hwy::SizeTag<2> , Mask256<T> mask, |
| 522 |
Vec256<T> yes, Vec256<T> no) { |
| 523 |
return Vec256<T>{_mm256_mask_mov_epi16(no.raw, mask.raw, yes.raw)}; |
| 524 |
} |
| 525 |
template <typename T> |
| 526 |
HWY_INLINE Vec256<T> IfThenElse(hwy::SizeTag<4> , Mask256<T> mask, |
| 527 |
Vec256<T> yes, Vec256<T> no) { |
| 528 |
return Vec256<T>{_mm256_mask_mov_epi32(no.raw, mask.raw, yes.raw)}; |
| 529 |
} |
| 530 |
template <typename T> |
| 531 |
HWY_INLINE Vec256<T> IfThenElse(hwy::SizeTag<8> , Mask256<T> mask, |
| 532 |
Vec256<T> yes, Vec256<T> no) { |
| 533 |
return Vec256<T>{_mm256_mask_mov_epi64(no.raw, mask.raw, yes.raw)}; |
| 534 |
} |
| 535 |
|
| 536 |
} |
| 537 |
|
| 538 |
template <typename T> |
| 539 |
HWY_API Vec256<T> IfThenElse(Mask256<T> mask, Vec256<T> yes, Vec256<T> no) { |
| 540 |
return detail::IfThenElse(hwy::SizeTag<sizeof(T)>(), mask, yes, no); |
| 541 |
} |
| 542 |
HWY_API Vec256<float> IfThenElse(Mask256<float> mask, Vec256<float> yes, |
| 543 |
Vec256<float> no) { |
| 544 |
return Vec256<float>{_mm256_mask_mov_ps(no.raw, mask.raw, yes.raw)}; |
| 545 |
} |
| 546 |
HWY_API Vec256<double> IfThenElse(Mask256<double> mask, Vec256<double> yes, |
| 547 |
Vec256<double> no) { |
| 548 |
return Vec256<double>{_mm256_mask_mov_pd(no.raw, mask.raw, yes.raw)}; |
| 549 |
} |
| 550 |
|
| 551 |
namespace detail { |
| 552 |
|
| 553 |
template <typename T> |
| 554 |
HWY_INLINE Vec256<T> IfThenElseZero(hwy::SizeTag<1> , Mask256<T> mask, |
| 555 |
Vec256<T> yes) { |
| 556 |
return Vec256<T>{_mm256_maskz_mov_epi8(mask.raw, yes.raw)}; |
| 557 |
} |
| 558 |
template <typename T> |
| 559 |
HWY_INLINE Vec256<T> IfThenElseZero(hwy::SizeTag<2> , Mask256<T> mask, |
| 560 |
Vec256<T> yes) { |
| 561 |
return Vec256<T>{_mm256_maskz_mov_epi16(mask.raw, yes.raw)}; |
| 562 |
} |
| 563 |
template <typename T> |
| 564 |
HWY_INLINE Vec256<T> IfThenElseZero(hwy::SizeTag<4> , Mask256<T> mask, |
| 565 |
Vec256<T> yes) { |
| 566 |
return Vec256<T>{_mm256_maskz_mov_epi32(mask.raw, yes.raw)}; |
| 567 |
} |
| 568 |
template <typename T> |
| 569 |
HWY_INLINE Vec256<T> IfThenElseZero(hwy::SizeTag<8> , Mask256<T> mask, |
| 570 |
Vec256<T> yes) { |
| 571 |
return Vec256<T>{_mm256_maskz_mov_epi64(mask.raw, yes.raw)}; |
| 572 |
} |
| 573 |
|
| 574 |
} |
| 575 |
|
| 576 |
template <typename T> |
| 577 |
HWY_API Vec256<T> IfThenElseZero(Mask256<T> mask, Vec256<T> yes) { |
| 578 |
return detail::IfThenElseZero(hwy::SizeTag<sizeof(T)>(), mask, yes); |
| 579 |
} |
| 580 |
HWY_API Vec256<float> IfThenElseZero(Mask256<float> mask, Vec256<float> yes) { |
| 581 |
return Vec256<float>{_mm256_maskz_mov_ps(mask.raw, yes.raw)}; |
| 582 |
} |
| 583 |
HWY_API Vec256<double> IfThenElseZero(Mask256<double> mask, |
| 584 |
Vec256<double> yes) { |
| 585 |
return Vec256<double>{_mm256_maskz_mov_pd(mask.raw, yes.raw)}; |
| 586 |
} |
| 587 |
|
| 588 |
namespace detail { |
| 589 |
|
| 590 |
template <typename T> |
| 591 |
HWY_INLINE Vec256<T> IfThenZeroElse(hwy::SizeTag<1> , Mask256<T> mask, |
| 592 |
Vec256<T> no) { |
| 593 |
|
| 594 |
return Vec256<T>{_mm256_mask_sub_epi8(no.raw, mask.raw, no.raw, no.raw)}; |
| 595 |
} |
| 596 |
template <typename T> |
| 597 |
HWY_INLINE Vec256<T> IfThenZeroElse(hwy::SizeTag<2> , Mask256<T> mask, |
| 598 |
Vec256<T> no) { |
| 599 |
return Vec256<T>{_mm256_mask_sub_epi16(no.raw, mask.raw, no.raw, no.raw)}; |
| 600 |
} |
| 601 |
template <typename T> |
| 602 |
HWY_INLINE Vec256<T> IfThenZeroElse(hwy::SizeTag<4> , Mask256<T> mask, |
| 603 |
Vec256<T> no) { |
| 604 |
return Vec256<T>{_mm256_mask_xor_epi32(no.raw, mask.raw, no.raw, no.raw)}; |
| 605 |
} |
| 606 |
template <typename T> |
| 607 |
HWY_INLINE Vec256<T> IfThenZeroElse(hwy::SizeTag<8> , Mask256<T> mask, |
| 608 |
Vec256<T> no) { |
| 609 |
return Vec256<T>{_mm256_mask_xor_epi64(no.raw, mask.raw, no.raw, no.raw)}; |
| 610 |
} |
| 611 |
|
| 612 |
} |
| 613 |
|
| 614 |
template <typename T> |
| 615 |
HWY_API Vec256<T> IfThenZeroElse(Mask256<T> mask, Vec256<T> no) { |
| 616 |
return detail::IfThenZeroElse(hwy::SizeTag<sizeof(T)>(), mask, no); |
| 617 |
} |
| 618 |
HWY_API Vec256<float> IfThenZeroElse(Mask256<float> mask, Vec256<float> no) { |
| 619 |
return Vec256<float>{_mm256_mask_xor_ps(no.raw, mask.raw, no.raw, no.raw)}; |
| 620 |
} |
| 621 |
HWY_API Vec256<double> IfThenZeroElse(Mask256<double> mask, Vec256<double> no) { |
| 622 |
return Vec256<double>{_mm256_mask_xor_pd(no.raw, mask.raw, no.raw, no.raw)}; |
| 623 |
} |
| 624 |
|
| 625 |
template <typename T> |
| 626 |
HWY_API Vec256<T> ZeroIfNegative(const Vec256<T> v) { |
| 627 |
static_assert(IsSigned<T>(), "Only for float"); |
| 628 |
|
| 629 |
return IfThenZeroElse(MaskFromVec(v), v); |
| 630 |
} |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
namespace detail { |
| 635 |
|
| 636 |
template <typename T> |
| 637 |
HWY_INLINE Mask256<T> And(hwy::SizeTag<1> , const Mask256<T> a, |
| 638 |
const Mask256<T> b) { |
| 639 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 640 |
return Mask256<T>{_kand_mask32(a.raw, b.raw)}; |
| 641 |
#else |
| 642 |
return Mask256<T>{static_cast<__mmask32>(a.raw & b.raw)}; |
| 643 |
#endif |
| 644 |
} |
| 645 |
template <typename T> |
| 646 |
HWY_INLINE Mask256<T> And(hwy::SizeTag<2> , const Mask256<T> a, |
| 647 |
const Mask256<T> b) { |
| 648 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 649 |
return Mask256<T>{_kand_mask16(a.raw, b.raw)}; |
| 650 |
#else |
| 651 |
return Mask256<T>{static_cast<__mmask16>(a.raw & b.raw)}; |
| 652 |
#endif |
| 653 |
} |
| 654 |
template <typename T> |
| 655 |
HWY_INLINE Mask256<T> And(hwy::SizeTag<4> , const Mask256<T> a, |
| 656 |
const Mask256<T> b) { |
| 657 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 658 |
return Mask256<T>{_kand_mask8(a.raw, b.raw)}; |
| 659 |
#else |
| 660 |
return Mask256<T>{static_cast<__mmask8>(a.raw & b.raw)}; |
| 661 |
#endif |
| 662 |
} |
| 663 |
template <typename T> |
| 664 |
HWY_INLINE Mask256<T> And(hwy::SizeTag<8> , const Mask256<T> a, |
| 665 |
const Mask256<T> b) { |
| 666 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 667 |
return Mask256<T>{_kand_mask8(a.raw, b.raw)}; |
| 668 |
#else |
| 669 |
return Mask256<T>{static_cast<__mmask8>(a.raw & b.raw)}; |
| 670 |
#endif |
| 671 |
} |
| 672 |
|
| 673 |
template <typename T> |
| 674 |
HWY_INLINE Mask256<T> AndNot(hwy::SizeTag<1> , const Mask256<T> a, |
| 675 |
const Mask256<T> b) { |
| 676 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 677 |
return Mask256<T>{_kandn_mask32(a.raw, b.raw)}; |
| 678 |
#else |
| 679 |
return Mask256<T>{static_cast<__mmask32>(~a.raw & b.raw)}; |
| 680 |
#endif |
| 681 |
} |
| 682 |
template <typename T> |
| 683 |
HWY_INLINE Mask256<T> AndNot(hwy::SizeTag<2> , const Mask256<T> a, |
| 684 |
const Mask256<T> b) { |
| 685 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 686 |
return Mask256<T>{_kandn_mask16(a.raw, b.raw)}; |
| 687 |
#else |
| 688 |
return Mask256<T>{static_cast<__mmask16>(~a.raw & b.raw)}; |
| 689 |
#endif |
| 690 |
} |
| 691 |
template <typename T> |
| 692 |
HWY_INLINE Mask256<T> AndNot(hwy::SizeTag<4> , const Mask256<T> a, |
| 693 |
const Mask256<T> b) { |
| 694 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 695 |
return Mask256<T>{_kandn_mask8(a.raw, b.raw)}; |
| 696 |
#else |
| 697 |
return Mask256<T>{static_cast<__mmask8>(~a.raw & b.raw)}; |
| 698 |
#endif |
| 699 |
} |
| 700 |
template <typename T> |
| 701 |
HWY_INLINE Mask256<T> AndNot(hwy::SizeTag<8> , const Mask256<T> a, |
| 702 |
const Mask256<T> b) { |
| 703 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 704 |
return Mask256<T>{_kandn_mask8(a.raw, b.raw)}; |
| 705 |
#else |
| 706 |
return Mask256<T>{static_cast<__mmask8>(~a.raw & b.raw)}; |
| 707 |
#endif |
| 708 |
} |
| 709 |
|
| 710 |
template <typename T> |
| 711 |
HWY_INLINE Mask256<T> Or(hwy::SizeTag<1> , const Mask256<T> a, |
| 712 |
const Mask256<T> b) { |
| 713 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 714 |
return Mask256<T>{_kor_mask32(a.raw, b.raw)}; |
| 715 |
#else |
| 716 |
return Mask256<T>{static_cast<__mmask32>(a.raw | b.raw)}; |
| 717 |
#endif |
| 718 |
} |
| 719 |
template <typename T> |
| 720 |
HWY_INLINE Mask256<T> Or(hwy::SizeTag<2> , const Mask256<T> a, |
| 721 |
const Mask256<T> b) { |
| 722 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 723 |
return Mask256<T>{_kor_mask16(a.raw, b.raw)}; |
| 724 |
#else |
| 725 |
return Mask256<T>{static_cast<__mmask16>(a.raw | b.raw)}; |
| 726 |
#endif |
| 727 |
} |
| 728 |
template <typename T> |
| 729 |
HWY_INLINE Mask256<T> Or(hwy::SizeTag<4> , const Mask256<T> a, |
| 730 |
const Mask256<T> b) { |
| 731 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 732 |
return Mask256<T>{_kor_mask8(a.raw, b.raw)}; |
| 733 |
#else |
| 734 |
return Mask256<T>{static_cast<__mmask8>(a.raw | b.raw)}; |
| 735 |
#endif |
| 736 |
} |
| 737 |
template <typename T> |
| 738 |
HWY_INLINE Mask256<T> Or(hwy::SizeTag<8> , const Mask256<T> a, |
| 739 |
const Mask256<T> b) { |
| 740 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 741 |
return Mask256<T>{_kor_mask8(a.raw, b.raw)}; |
| 742 |
#else |
| 743 |
return Mask256<T>{static_cast<__mmask8>(a.raw | b.raw)}; |
| 744 |
#endif |
| 745 |
} |
| 746 |
|
| 747 |
template <typename T> |
| 748 |
HWY_INLINE Mask256<T> Xor(hwy::SizeTag<1> , const Mask256<T> a, |
| 749 |
const Mask256<T> b) { |
| 750 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 751 |
return Mask256<T>{_kxor_mask32(a.raw, b.raw)}; |
| 752 |
#else |
| 753 |
return Mask256<T>{static_cast<__mmask32>(a.raw ^ b.raw)}; |
| 754 |
#endif |
| 755 |
} |
| 756 |
template <typename T> |
| 757 |
HWY_INLINE Mask256<T> Xor(hwy::SizeTag<2> , const Mask256<T> a, |
| 758 |
const Mask256<T> b) { |
| 759 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 760 |
return Mask256<T>{_kxor_mask16(a.raw, b.raw)}; |
| 761 |
#else |
| 762 |
return Mask256<T>{static_cast<__mmask16>(a.raw ^ b.raw)}; |
| 763 |
#endif |
| 764 |
} |
| 765 |
template <typename T> |
| 766 |
HWY_INLINE Mask256<T> Xor(hwy::SizeTag<4> , const Mask256<T> a, |
| 767 |
const Mask256<T> b) { |
| 768 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 769 |
return Mask256<T>{_kxor_mask8(a.raw, b.raw)}; |
| 770 |
#else |
| 771 |
return Mask256<T>{static_cast<__mmask8>(a.raw ^ b.raw)}; |
| 772 |
#endif |
| 773 |
} |
| 774 |
template <typename T> |
| 775 |
HWY_INLINE Mask256<T> Xor(hwy::SizeTag<8> , const Mask256<T> a, |
| 776 |
const Mask256<T> b) { |
| 777 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 778 |
return Mask256<T>{_kxor_mask8(a.raw, b.raw)}; |
| 779 |
#else |
| 780 |
return Mask256<T>{static_cast<__mmask8>(a.raw ^ b.raw)}; |
| 781 |
#endif |
| 782 |
} |
| 783 |
|
| 784 |
template <typename T> |
| 785 |
HWY_INLINE Mask256<T> ExclusiveNeither(hwy::SizeTag<1> , |
| 786 |
const Mask256<T> a, const Mask256<T> b) { |
| 787 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 788 |
return Mask256<T>{_kxnor_mask32(a.raw, b.raw)}; |
| 789 |
#else |
| 790 |
return Mask256<T>{static_cast<__mmask32>(~(a.raw ^ b.raw) & 0xFFFFFFFF)}; |
| 791 |
#endif |
| 792 |
} |
| 793 |
template <typename T> |
| 794 |
HWY_INLINE Mask256<T> ExclusiveNeither(hwy::SizeTag<2> , |
| 795 |
const Mask256<T> a, const Mask256<T> b) { |
| 796 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 797 |
return Mask256<T>{_kxnor_mask16(a.raw, b.raw)}; |
| 798 |
#else |
| 799 |
return Mask256<T>{static_cast<__mmask16>(~(a.raw ^ b.raw) & 0xFFFF)}; |
| 800 |
#endif |
| 801 |
} |
| 802 |
template <typename T> |
| 803 |
HWY_INLINE Mask256<T> ExclusiveNeither(hwy::SizeTag<4> , |
| 804 |
const Mask256<T> a, const Mask256<T> b) { |
| 805 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 806 |
return Mask256<T>{_kxnor_mask8(a.raw, b.raw)}; |
| 807 |
#else |
| 808 |
return Mask256<T>{static_cast<__mmask8>(~(a.raw ^ b.raw) & 0xFF)}; |
| 809 |
#endif |
| 810 |
} |
| 811 |
template <typename T> |
| 812 |
HWY_INLINE Mask256<T> ExclusiveNeither(hwy::SizeTag<8> , |
| 813 |
const Mask256<T> a, const Mask256<T> b) { |
| 814 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 815 |
return Mask256<T>{static_cast<__mmask8>(_kxnor_mask8(a.raw, b.raw) & 0xF)}; |
| 816 |
#else |
| 817 |
return Mask256<T>{static_cast<__mmask8>(~(a.raw ^ b.raw) & 0xF)}; |
| 818 |
#endif |
| 819 |
} |
| 820 |
|
| 821 |
} |
| 822 |
|
| 823 |
template <typename T> |
| 824 |
HWY_API Mask256<T> And(const Mask256<T> a, Mask256<T> b) { |
| 825 |
return detail::And(hwy::SizeTag<sizeof(T)>(), a, b); |
| 826 |
} |
| 827 |
|
| 828 |
template <typename T> |
| 829 |
HWY_API Mask256<T> AndNot(const Mask256<T> a, Mask256<T> b) { |
| 830 |
return detail::AndNot(hwy::SizeTag<sizeof(T)>(), a, b); |
| 831 |
} |
| 832 |
|
| 833 |
template <typename T> |
| 834 |
HWY_API Mask256<T> Or(const Mask256<T> a, Mask256<T> b) { |
| 835 |
return detail::Or(hwy::SizeTag<sizeof(T)>(), a, b); |
| 836 |
} |
| 837 |
|
| 838 |
template <typename T> |
| 839 |
HWY_API Mask256<T> Xor(const Mask256<T> a, Mask256<T> b) { |
| 840 |
return detail::Xor(hwy::SizeTag<sizeof(T)>(), a, b); |
| 841 |
} |
| 842 |
|
| 843 |
template <typename T> |
| 844 |
HWY_API Mask256<T> Not(const Mask256<T> m) { |
| 845 |
|
| 846 |
constexpr size_t N = 32 / sizeof(T); |
| 847 |
return Xor(m, Mask256<T>::FromBits((1ull << N) - 1)); |
| 848 |
} |
| 849 |
|
| 850 |
template <typename T> |
| 851 |
HWY_API Mask256<T> ExclusiveNeither(const Mask256<T> a, Mask256<T> b) { |
| 852 |
return detail::ExclusiveNeither(hwy::SizeTag<sizeof(T)>(), a, b); |
| 853 |
} |
| 854 |
|
| 855 |
#else |
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
template <typename T> |
| 861 |
HWY_API Mask256<T> MaskFromVec(const Vec256<T> v) { |
| 862 |
return Mask256<T>{v.raw}; |
| 863 |
} |
| 864 |
|
| 865 |
template <typename T> |
| 866 |
HWY_API Vec256<T> VecFromMask(const Mask256<T> v) { |
| 867 |
return Vec256<T>{v.raw}; |
| 868 |
} |
| 869 |
|
| 870 |
template <typename T> |
| 871 |
HWY_API Vec256<T> VecFromMask(Full256<T> , const Mask256<T> v) { |
| 872 |
return Vec256<T>{v.raw}; |
| 873 |
} |
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
template <typename T> |
| 879 |
HWY_API Vec256<T> IfThenElse(const Mask256<T> mask, const Vec256<T> yes, |
| 880 |
const Vec256<T> no) { |
| 881 |
return Vec256<T>{_mm256_blendv_epi8(no.raw, yes.raw, mask.raw)}; |
| 882 |
} |
| 883 |
HWY_API Vec256<float> IfThenElse(const Mask256<float> mask, |
| 884 |
const Vec256<float> yes, |
| 885 |
const Vec256<float> no) { |
| 886 |
return Vec256<float>{_mm256_blendv_ps(no.raw, yes.raw, mask.raw)}; |
| 887 |
} |
| 888 |
HWY_API Vec256<double> IfThenElse(const Mask256<double> mask, |
| 889 |
const Vec256<double> yes, |
| 890 |
const Vec256<double> no) { |
| 891 |
return Vec256<double>{_mm256_blendv_pd(no.raw, yes.raw, mask.raw)}; |
| 892 |
} |
| 893 |
|
| 894 |
|
| 895 |
template <typename T> |
| 896 |
HWY_API Vec256<T> IfThenElseZero(Mask256<T> mask, Vec256<T> yes) { |
| 897 |
return yes & VecFromMask(Full256<T>(), mask); |
| 898 |
} |
| 899 |
|
| 900 |
|
| 901 |
template <typename T> |
| 902 |
HWY_API Vec256<T> IfThenZeroElse(Mask256<T> mask, Vec256<T> no) { |
| 903 |
return AndNot(VecFromMask(Full256<T>(), mask), no); |
| 904 |
} |
| 905 |
|
| 906 |
template <typename T> |
| 907 |
HWY_API Vec256<T> ZeroIfNegative(Vec256<T> v) { |
| 908 |
static_assert(IsSigned<T>(), "Only for float"); |
| 909 |
const auto zero = Zero(Full256<T>()); |
| 910 |
|
| 911 |
return IfThenElse(MaskFromVec(v), zero, v); |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
template <typename T> |
| 917 |
HWY_API Mask256<T> Not(const Mask256<T> m) { |
| 918 |
return MaskFromVec(Not(VecFromMask(Full256<T>(), m))); |
| 919 |
} |
| 920 |
|
| 921 |
template <typename T> |
| 922 |
HWY_API Mask256<T> And(const Mask256<T> a, Mask256<T> b) { |
| 923 |
const Full256<T> d; |
| 924 |
return MaskFromVec(And(VecFromMask(d, a), VecFromMask(d, b))); |
| 925 |
} |
| 926 |
|
| 927 |
template <typename T> |
| 928 |
HWY_API Mask256<T> AndNot(const Mask256<T> a, Mask256<T> b) { |
| 929 |
const Full256<T> d; |
| 930 |
return MaskFromVec(AndNot(VecFromMask(d, a), VecFromMask(d, b))); |
| 931 |
} |
| 932 |
|
| 933 |
template <typename T> |
| 934 |
HWY_API Mask256<T> Or(const Mask256<T> a, Mask256<T> b) { |
| 935 |
const Full256<T> d; |
| 936 |
return MaskFromVec(Or(VecFromMask(d, a), VecFromMask(d, b))); |
| 937 |
} |
| 938 |
|
| 939 |
template <typename T> |
| 940 |
HWY_API Mask256<T> Xor(const Mask256<T> a, Mask256<T> b) { |
| 941 |
const Full256<T> d; |
| 942 |
return MaskFromVec(Xor(VecFromMask(d, a), VecFromMask(d, b))); |
| 943 |
} |
| 944 |
|
| 945 |
template <typename T> |
| 946 |
HWY_API Mask256<T> ExclusiveNeither(const Mask256<T> a, Mask256<T> b) { |
| 947 |
const Full256<T> d; |
| 948 |
return MaskFromVec(AndNot(VecFromMask(d, a), Not(VecFromMask(d, b)))); |
| 949 |
} |
| 950 |
|
| 951 |
#endif |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
#if HWY_TARGET <= HWY_AVX3 |
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
template <typename TFrom, typename TTo> |
| 960 |
HWY_API Mask256<TTo> RebindMask(Full256<TTo> , Mask256<TFrom> m) { |
| 961 |
static_assert(sizeof(TFrom) == sizeof(TTo), "Must have same size"); |
| 962 |
return Mask256<TTo>{m.raw}; |
| 963 |
} |
| 964 |
|
| 965 |
namespace detail { |
| 966 |
|
| 967 |
template <typename T> |
| 968 |
HWY_INLINE Mask256<T> TestBit(hwy::SizeTag<1> , const Vec256<T> v, |
| 969 |
const Vec256<T> bit) { |
| 970 |
return Mask256<T>{_mm256_test_epi8_mask(v.raw, bit.raw)}; |
| 971 |
} |
| 972 |
template <typename T> |
| 973 |
HWY_INLINE Mask256<T> TestBit(hwy::SizeTag<2> , const Vec256<T> v, |
| 974 |
const Vec256<T> bit) { |
| 975 |
return Mask256<T>{_mm256_test_epi16_mask(v.raw, bit.raw)}; |
| 976 |
} |
| 977 |
template <typename T> |
| 978 |
HWY_INLINE Mask256<T> TestBit(hwy::SizeTag<4> , const Vec256<T> v, |
| 979 |
const Vec256<T> bit) { |
| 980 |
return Mask256<T>{_mm256_test_epi32_mask(v.raw, bit.raw)}; |
| 981 |
} |
| 982 |
template <typename T> |
| 983 |
HWY_INLINE Mask256<T> TestBit(hwy::SizeTag<8> , const Vec256<T> v, |
| 984 |
const Vec256<T> bit) { |
| 985 |
return Mask256<T>{_mm256_test_epi64_mask(v.raw, bit.raw)}; |
| 986 |
} |
| 987 |
|
| 988 |
} |
| 989 |
|
| 990 |
template <typename T> |
| 991 |
HWY_API Mask256<T> TestBit(const Vec256<T> v, const Vec256<T> bit) { |
| 992 |
static_assert(!hwy::IsFloat<T>(), "Only integer vectors supported"); |
| 993 |
return detail::TestBit(hwy::SizeTag<sizeof(T)>(), v, bit); |
| 994 |
} |
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
template <typename T, HWY_IF_LANE_SIZE(T, 1)> |
| 999 |
HWY_API Mask256<T> operator==(const Vec256<T> a, const Vec256<T> b) { |
| 1000 |
return Mask256<T>{_mm256_cmpeq_epi8_mask(a.raw, b.raw)}; |
| 1001 |
} |
| 1002 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 1003 |
HWY_API Mask256<T> operator==(const Vec256<T> a, const Vec256<T> b) { |
| 1004 |
return Mask256<T>{_mm256_cmpeq_epi16_mask(a.raw, b.raw)}; |
| 1005 |
} |
| 1006 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 1007 |
HWY_API Mask256<T> operator==(const Vec256<T> a, const Vec256<T> b) { |
| 1008 |
return Mask256<T>{_mm256_cmpeq_epi32_mask(a.raw, b.raw)}; |
| 1009 |
} |
| 1010 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 1011 |
HWY_API Mask256<T> operator==(const Vec256<T> a, const Vec256<T> b) { |
| 1012 |
return Mask256<T>{_mm256_cmpeq_epi64_mask(a.raw, b.raw)}; |
| 1013 |
} |
| 1014 |
|
| 1015 |
HWY_API Mask256<float> operator==(Vec256<float> a, Vec256<float> b) { |
| 1016 |
return Mask256<float>{_mm256_cmp_ps_mask(a.raw, b.raw, _CMP_EQ_OQ)}; |
| 1017 |
} |
| 1018 |
|
| 1019 |
HWY_API Mask256<double> operator==(Vec256<double> a, Vec256<double> b) { |
| 1020 |
return Mask256<double>{_mm256_cmp_pd_mask(a.raw, b.raw, _CMP_EQ_OQ)}; |
| 1021 |
} |
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
template <typename T, HWY_IF_LANE_SIZE(T, 1)> |
| 1026 |
HWY_API Mask256<T> operator!=(const Vec256<T> a, const Vec256<T> b) { |
| 1027 |
return Mask256<T>{_mm256_cmpneq_epi8_mask(a.raw, b.raw)}; |
| 1028 |
} |
| 1029 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 1030 |
HWY_API Mask256<T> operator!=(const Vec256<T> a, const Vec256<T> b) { |
| 1031 |
return Mask256<T>{_mm256_cmpneq_epi16_mask(a.raw, b.raw)}; |
| 1032 |
} |
| 1033 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 1034 |
HWY_API Mask256<T> operator!=(const Vec256<T> a, const Vec256<T> b) { |
| 1035 |
return Mask256<T>{_mm256_cmpneq_epi32_mask(a.raw, b.raw)}; |
| 1036 |
} |
| 1037 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 1038 |
HWY_API Mask256<T> operator!=(const Vec256<T> a, const Vec256<T> b) { |
| 1039 |
return Mask256<T>{_mm256_cmpneq_epi64_mask(a.raw, b.raw)}; |
| 1040 |
} |
| 1041 |
|
| 1042 |
HWY_API Mask256<float> operator!=(Vec256<float> a, Vec256<float> b) { |
| 1043 |
return Mask256<float>{_mm256_cmp_ps_mask(a.raw, b.raw, _CMP_NEQ_OQ)}; |
| 1044 |
} |
| 1045 |
|
| 1046 |
HWY_API Mask256<double> operator!=(Vec256<double> a, Vec256<double> b) { |
| 1047 |
return Mask256<double>{_mm256_cmp_pd_mask(a.raw, b.raw, _CMP_NEQ_OQ)}; |
| 1048 |
} |
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
HWY_API Mask256<int8_t> operator>(Vec256<int8_t> a, Vec256<int8_t> b) { |
| 1053 |
return Mask256<int8_t>{_mm256_cmpgt_epi8_mask(a.raw, b.raw)}; |
| 1054 |
} |
| 1055 |
HWY_API Mask256<int16_t> operator>(Vec256<int16_t> a, Vec256<int16_t> b) { |
| 1056 |
return Mask256<int16_t>{_mm256_cmpgt_epi16_mask(a.raw, b.raw)}; |
| 1057 |
} |
| 1058 |
HWY_API Mask256<int32_t> operator>(Vec256<int32_t> a, Vec256<int32_t> b) { |
| 1059 |
return Mask256<int32_t>{_mm256_cmpgt_epi32_mask(a.raw, b.raw)}; |
| 1060 |
} |
| 1061 |
HWY_API Mask256<int64_t> operator>(Vec256<int64_t> a, Vec256<int64_t> b) { |
| 1062 |
return Mask256<int64_t>{_mm256_cmpgt_epi64_mask(a.raw, b.raw)}; |
| 1063 |
} |
| 1064 |
|
| 1065 |
HWY_API Mask256<uint8_t> operator>(Vec256<uint8_t> a, Vec256<uint8_t> b) { |
| 1066 |
return Mask256<uint8_t>{_mm256_cmpgt_epu8_mask(a.raw, b.raw)}; |
| 1067 |
} |
| 1068 |
HWY_API Mask256<uint16_t> operator>(const Vec256<uint16_t> a, |
| 1069 |
const Vec256<uint16_t> b) { |
| 1070 |
return Mask256<uint16_t>{_mm256_cmpgt_epu16_mask(a.raw, b.raw)}; |
| 1071 |
} |
| 1072 |
HWY_API Mask256<uint32_t> operator>(const Vec256<uint32_t> a, |
| 1073 |
const Vec256<uint32_t> b) { |
| 1074 |
return Mask256<uint32_t>{_mm256_cmpgt_epu32_mask(a.raw, b.raw)}; |
| 1075 |
} |
| 1076 |
HWY_API Mask256<uint64_t> operator>(const Vec256<uint64_t> a, |
| 1077 |
const Vec256<uint64_t> b) { |
| 1078 |
return Mask256<uint64_t>{_mm256_cmpgt_epu64_mask(a.raw, b.raw)}; |
| 1079 |
} |
| 1080 |
|
| 1081 |
HWY_API Mask256<float> operator>(Vec256<float> a, Vec256<float> b) { |
| 1082 |
return Mask256<float>{_mm256_cmp_ps_mask(a.raw, b.raw, _CMP_GT_OQ)}; |
| 1083 |
} |
| 1084 |
HWY_API Mask256<double> operator>(Vec256<double> a, Vec256<double> b) { |
| 1085 |
return Mask256<double>{_mm256_cmp_pd_mask(a.raw, b.raw, _CMP_GT_OQ)}; |
| 1086 |
} |
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
HWY_API Mask256<float> operator>=(Vec256<float> a, Vec256<float> b) { |
| 1091 |
return Mask256<float>{_mm256_cmp_ps_mask(a.raw, b.raw, _CMP_GE_OQ)}; |
| 1092 |
} |
| 1093 |
HWY_API Mask256<double> operator>=(Vec256<double> a, Vec256<double> b) { |
| 1094 |
return Mask256<double>{_mm256_cmp_pd_mask(a.raw, b.raw, _CMP_GE_OQ)}; |
| 1095 |
} |
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
namespace detail { |
| 1100 |
|
| 1101 |
template <typename T> |
| 1102 |
HWY_INLINE Mask256<T> MaskFromVec(hwy::SizeTag<1> , const Vec256<T> v) { |
| 1103 |
return Mask256<T>{_mm256_movepi8_mask(v.raw)}; |
| 1104 |
} |
| 1105 |
template <typename T> |
| 1106 |
HWY_INLINE Mask256<T> MaskFromVec(hwy::SizeTag<2> , const Vec256<T> v) { |
| 1107 |
return Mask256<T>{_mm256_movepi16_mask(v.raw)}; |
| 1108 |
} |
| 1109 |
template <typename T> |
| 1110 |
HWY_INLINE Mask256<T> MaskFromVec(hwy::SizeTag<4> , const Vec256<T> v) { |
| 1111 |
return Mask256<T>{_mm256_movepi32_mask(v.raw)}; |
| 1112 |
} |
| 1113 |
template <typename T> |
| 1114 |
HWY_INLINE Mask256<T> MaskFromVec(hwy::SizeTag<8> , const Vec256<T> v) { |
| 1115 |
return Mask256<T>{_mm256_movepi64_mask(v.raw)}; |
| 1116 |
} |
| 1117 |
|
| 1118 |
} |
| 1119 |
|
| 1120 |
template <typename T> |
| 1121 |
HWY_API Mask256<T> MaskFromVec(const Vec256<T> v) { |
| 1122 |
return detail::MaskFromVec(hwy::SizeTag<sizeof(T)>(), v); |
| 1123 |
} |
| 1124 |
|
| 1125 |
HWY_API Mask256<float> MaskFromVec(const Vec256<float> v) { |
| 1126 |
return Mask256<float>{MaskFromVec(BitCast(Full256<int32_t>(), v)).raw}; |
| 1127 |
} |
| 1128 |
HWY_API Mask256<double> MaskFromVec(const Vec256<double> v) { |
| 1129 |
return Mask256<double>{MaskFromVec(BitCast(Full256<int64_t>(), v)).raw}; |
| 1130 |
} |
| 1131 |
|
| 1132 |
template <typename T, HWY_IF_LANE_SIZE(T, 1)> |
| 1133 |
HWY_API Vec256<T> VecFromMask(const Mask256<T> v) { |
| 1134 |
return Vec256<T>{_mm256_movm_epi8(v.raw)}; |
| 1135 |
} |
| 1136 |
|
| 1137 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 1138 |
HWY_API Vec256<T> VecFromMask(const Mask256<T> v) { |
| 1139 |
return Vec256<T>{_mm256_movm_epi16(v.raw)}; |
| 1140 |
} |
| 1141 |
|
| 1142 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 1143 |
HWY_API Vec256<T> VecFromMask(const Mask256<T> v) { |
| 1144 |
return Vec256<T>{_mm256_movm_epi32(v.raw)}; |
| 1145 |
} |
| 1146 |
|
| 1147 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 1148 |
HWY_API Vec256<T> VecFromMask(const Mask256<T> v) { |
| 1149 |
return Vec256<T>{_mm256_movm_epi64(v.raw)}; |
| 1150 |
} |
| 1151 |
|
| 1152 |
HWY_API Vec256<float> VecFromMask(const Mask256<float> v) { |
| 1153 |
return Vec256<float>{_mm256_castsi256_ps(_mm256_movm_epi32(v.raw))}; |
| 1154 |
} |
| 1155 |
|
| 1156 |
HWY_API Vec256<double> VecFromMask(const Mask256<double> v) { |
| 1157 |
return Vec256<double>{_mm256_castsi256_pd(_mm256_movm_epi64(v.raw))}; |
| 1158 |
} |
| 1159 |
|
| 1160 |
template <typename T> |
| 1161 |
HWY_API Vec256<T> VecFromMask(Full256<T> , const Mask256<T> v) { |
| 1162 |
return VecFromMask(v); |
| 1163 |
} |
| 1164 |
|
| 1165 |
#else |
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
template <typename TFrom, typename TTo> |
| 1170 |
HWY_API Mask256<TTo> RebindMask(Full256<TTo> d_to, Mask256<TFrom> m) { |
| 1171 |
static_assert(sizeof(TFrom) == sizeof(TTo), "Must have same size"); |
| 1172 |
return MaskFromVec(BitCast(d_to, VecFromMask(Full256<TFrom>(), m))); |
| 1173 |
} |
| 1174 |
|
| 1175 |
template <typename T> |
| 1176 |
HWY_API Mask256<T> TestBit(const Vec256<T> v, const Vec256<T> bit) { |
| 1177 |
static_assert(!hwy::IsFloat<T>(), "Only integer vectors supported"); |
| 1178 |
return (v & bit) == bit; |
| 1179 |
} |
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
template <typename T, HWY_IF_LANE_SIZE(T, 1)> |
| 1184 |
HWY_API Mask256<T> operator==(const Vec256<T> a, const Vec256<T> b) { |
| 1185 |
return Mask256<T>{_mm256_cmpeq_epi8(a.raw, b.raw)}; |
| 1186 |
} |
| 1187 |
|
| 1188 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 1189 |
HWY_API Mask256<T> operator==(const Vec256<T> a, const Vec256<T> b) { |
| 1190 |
return Mask256<T>{_mm256_cmpeq_epi16(a.raw, b.raw)}; |
| 1191 |
} |
| 1192 |
|
| 1193 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 1194 |
HWY_API Mask256<T> operator==(const Vec256<T> a, const Vec256<T> b) { |
| 1195 |
return Mask256<T>{_mm256_cmpeq_epi32(a.raw, b.raw)}; |
| 1196 |
} |
| 1197 |
|
| 1198 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 1199 |
HWY_API Mask256<T> operator==(const Vec256<T> a, const Vec256<T> b) { |
| 1200 |
return Mask256<T>{_mm256_cmpeq_epi64(a.raw, b.raw)}; |
| 1201 |
} |
| 1202 |
|
| 1203 |
HWY_API Mask256<float> operator==(const Vec256<float> a, |
| 1204 |
const Vec256<float> b) { |
| 1205 |
return Mask256<float>{_mm256_cmp_ps(a.raw, b.raw, _CMP_EQ_OQ)}; |
| 1206 |
} |
| 1207 |
|
| 1208 |
HWY_API Mask256<double> operator==(const Vec256<double> a, |
| 1209 |
const Vec256<double> b) { |
| 1210 |
return Mask256<double>{_mm256_cmp_pd(a.raw, b.raw, _CMP_EQ_OQ)}; |
| 1211 |
} |
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
template <typename T> |
| 1216 |
HWY_API Mask256<T> operator!=(const Vec256<T> a, const Vec256<T> b) { |
| 1217 |
return Not(a == b); |
| 1218 |
} |
| 1219 |
HWY_API Mask256<float> operator!=(const Vec256<float> a, |
| 1220 |
const Vec256<float> b) { |
| 1221 |
return Mask256<float>{_mm256_cmp_ps(a.raw, b.raw, _CMP_NEQ_OQ)}; |
| 1222 |
} |
| 1223 |
HWY_API Mask256<double> operator!=(const Vec256<double> a, |
| 1224 |
const Vec256<double> b) { |
| 1225 |
return Mask256<double>{_mm256_cmp_pd(a.raw, b.raw, _CMP_NEQ_OQ)}; |
| 1226 |
} |
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
namespace detail { |
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
#if HWY_COMPILER_GCC != 0 && HWY_COMPILER_GCC < 930 |
| 1237 |
#define HWY_AVX2_GCC_CMPGT8_WORKAROUND 1 |
| 1238 |
#else |
| 1239 |
#define HWY_AVX2_GCC_CMPGT8_WORKAROUND 0 |
| 1240 |
#endif |
| 1241 |
|
| 1242 |
HWY_API Mask256<int8_t> Gt(hwy::SignedTag , Vec256<int8_t> a, |
| 1243 |
Vec256<int8_t> b) { |
| 1244 |
#if HWY_AVX2_GCC_CMPGT8_WORKAROUND |
| 1245 |
using i8x32 = signed char __attribute__((__vector_size__(32))); |
| 1246 |
return Mask256<int8_t>{static_cast<__m256i>(reinterpret_cast<i8x32>(a.raw) > |
| 1247 |
reinterpret_cast<i8x32>(b.raw))}; |
| 1248 |
#else |
| 1249 |
return Mask256<int8_t>{_mm256_cmpgt_epi8(a.raw, b.raw)}; |
| 1250 |
#endif |
| 1251 |
} |
| 1252 |
HWY_API Mask256<int16_t> Gt(hwy::SignedTag , Vec256<int16_t> a, |
| 1253 |
Vec256<int16_t> b) { |
| 1254 |
return Mask256<int16_t>{_mm256_cmpgt_epi16(a.raw, b.raw)}; |
| 1255 |
} |
| 1256 |
HWY_API Mask256<int32_t> Gt(hwy::SignedTag , Vec256<int32_t> a, |
| 1257 |
Vec256<int32_t> b) { |
| 1258 |
return Mask256<int32_t>{_mm256_cmpgt_epi32(a.raw, b.raw)}; |
| 1259 |
} |
| 1260 |
HWY_API Mask256<int64_t> Gt(hwy::SignedTag , Vec256<int64_t> a, |
| 1261 |
Vec256<int64_t> b) { |
| 1262 |
return Mask256<int64_t>{_mm256_cmpgt_epi64(a.raw, b.raw)}; |
| 1263 |
} |
| 1264 |
|
| 1265 |
template <typename T> |
| 1266 |
HWY_INLINE Mask256<T> Gt(hwy::UnsignedTag , Vec256<T> a, Vec256<T> b) { |
| 1267 |
const Full256<T> du; |
| 1268 |
const RebindToSigned<decltype(du)> di; |
| 1269 |
const Vec256<T> msb = Set(du, (LimitsMax<T>() >> 1) + 1); |
| 1270 |
return RebindMask(du, BitCast(di, Xor(a, msb)) > BitCast(di, Xor(b, msb))); |
| 1271 |
} |
| 1272 |
|
| 1273 |
HWY_API Mask256<float> Gt(hwy::FloatTag , Vec256<float> a, |
| 1274 |
Vec256<float> b) { |
| 1275 |
return Mask256<float>{_mm256_cmp_ps(a.raw, b.raw, _CMP_GT_OQ)}; |
| 1276 |
} |
| 1277 |
HWY_API Mask256<double> Gt(hwy::FloatTag , Vec256<double> a, |
| 1278 |
Vec256<double> b) { |
| 1279 |
return Mask256<double>{_mm256_cmp_pd(a.raw, b.raw, _CMP_GT_OQ)}; |
| 1280 |
} |
| 1281 |
|
| 1282 |
} |
| 1283 |
|
| 1284 |
template <typename T> |
| 1285 |
HWY_API Mask256<T> operator>(Vec256<T> a, Vec256<T> b) { |
| 1286 |
return detail::Gt(hwy::TypeTag<T>(), a, b); |
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
HWY_API Mask256<float> operator>=(const Vec256<float> a, |
| 1292 |
const Vec256<float> b) { |
| 1293 |
return Mask256<float>{_mm256_cmp_ps(a.raw, b.raw, _CMP_GE_OQ)}; |
| 1294 |
} |
| 1295 |
HWY_API Mask256<double> operator>=(const Vec256<double> a, |
| 1296 |
const Vec256<double> b) { |
| 1297 |
return Mask256<double>{_mm256_cmp_pd(a.raw, b.raw, _CMP_GE_OQ)}; |
| 1298 |
} |
| 1299 |
|
| 1300 |
#endif |
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
template <typename T> |
| 1305 |
HWY_API Mask256<T> operator<(const Vec256<T> a, const Vec256<T> b) { |
| 1306 |
return b > a; |
| 1307 |
} |
| 1308 |
|
| 1309 |
template <typename T> |
| 1310 |
HWY_API Mask256<T> operator<=(const Vec256<T> a, const Vec256<T> b) { |
| 1311 |
return b >= a; |
| 1312 |
} |
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
HWY_API Vec256<uint8_t> Min(const Vec256<uint8_t> a, const Vec256<uint8_t> b) { |
| 1318 |
return Vec256<uint8_t>{_mm256_min_epu8(a.raw, b.raw)}; |
| 1319 |
} |
| 1320 |
HWY_API Vec256<uint16_t> Min(const Vec256<uint16_t> a, |
| 1321 |
const Vec256<uint16_t> b) { |
| 1322 |
return Vec256<uint16_t>{_mm256_min_epu16(a.raw, b.raw)}; |
| 1323 |
} |
| 1324 |
HWY_API Vec256<uint32_t> Min(const Vec256<uint32_t> a, |
| 1325 |
const Vec256<uint32_t> b) { |
| 1326 |
return Vec256<uint32_t>{_mm256_min_epu32(a.raw, b.raw)}; |
| 1327 |
} |
| 1328 |
HWY_API Vec256<uint64_t> Min(const Vec256<uint64_t> a, |
| 1329 |
const Vec256<uint64_t> b) { |
| 1330 |
#if HWY_TARGET <= HWY_AVX3 |
| 1331 |
return Vec256<uint64_t>{_mm256_min_epu64(a.raw, b.raw)}; |
| 1332 |
#else |
| 1333 |
const Full256<uint64_t> du; |
| 1334 |
const Full256<int64_t> di; |
| 1335 |
const auto msb = Set(du, 1ull << 63); |
| 1336 |
const auto gt = RebindMask(du, BitCast(di, a ^ msb) > BitCast(di, b ^ msb)); |
| 1337 |
return IfThenElse(gt, b, a); |
| 1338 |
#endif |
| 1339 |
} |
| 1340 |
|
| 1341 |
|
| 1342 |
HWY_API Vec256<int8_t> Min(const Vec256<int8_t> a, const Vec256<int8_t> b) { |
| 1343 |
return Vec256<int8_t>{_mm256_min_epi8(a.raw, b.raw)}; |
| 1344 |
} |
| 1345 |
HWY_API Vec256<int16_t> Min(const Vec256<int16_t> a, const Vec256<int16_t> b) { |
| 1346 |
return Vec256<int16_t>{_mm256_min_epi16(a.raw, b.raw)}; |
| 1347 |
} |
| 1348 |
HWY_API Vec256<int32_t> Min(const Vec256<int32_t> a, const Vec256<int32_t> b) { |
| 1349 |
return Vec256<int32_t>{_mm256_min_epi32(a.raw, b.raw)}; |
| 1350 |
} |
| 1351 |
HWY_API Vec256<int64_t> Min(const Vec256<int64_t> a, const Vec256<int64_t> b) { |
| 1352 |
#if HWY_TARGET <= HWY_AVX3 |
| 1353 |
return Vec256<int64_t>{_mm256_min_epi64(a.raw, b.raw)}; |
| 1354 |
#else |
| 1355 |
return IfThenElse(a < b, a, b); |
| 1356 |
#endif |
| 1357 |
} |
| 1358 |
|
| 1359 |
|
| 1360 |
HWY_API Vec256<float> Min(const Vec256<float> a, const Vec256<float> b) { |
| 1361 |
return Vec256<float>{_mm256_min_ps(a.raw, b.raw)}; |
| 1362 |
} |
| 1363 |
HWY_API Vec256<double> Min(const Vec256<double> a, const Vec256<double> b) { |
| 1364 |
return Vec256<double>{_mm256_min_pd(a.raw, b.raw)}; |
| 1365 |
} |
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
HWY_API Vec256<uint8_t> Max(const Vec256<uint8_t> a, const Vec256<uint8_t> b) { |
| 1371 |
return Vec256<uint8_t>{_mm256_max_epu8(a.raw, b.raw)}; |
| 1372 |
} |
| 1373 |
HWY_API Vec256<uint16_t> Max(const Vec256<uint16_t> a, |
| 1374 |
const Vec256<uint16_t> b) { |
| 1375 |
return Vec256<uint16_t>{_mm256_max_epu16(a.raw, b.raw)}; |
| 1376 |
} |
| 1377 |
HWY_API Vec256<uint32_t> Max(const Vec256<uint32_t> a, |
| 1378 |
const Vec256<uint32_t> b) { |
| 1379 |
return Vec256<uint32_t>{_mm256_max_epu32(a.raw, b.raw)}; |
| 1380 |
} |
| 1381 |
HWY_API Vec256<uint64_t> Max(const Vec256<uint64_t> a, |
| 1382 |
const Vec256<uint64_t> b) { |
| 1383 |
#if HWY_TARGET <= HWY_AVX3 |
| 1384 |
return Vec256<uint64_t>{_mm256_max_epu64(a.raw, b.raw)}; |
| 1385 |
#else |
| 1386 |
const Full256<uint64_t> du; |
| 1387 |
const Full256<int64_t> di; |
| 1388 |
const auto msb = Set(du, 1ull << 63); |
| 1389 |
const auto gt = RebindMask(du, BitCast(di, a ^ msb) > BitCast(di, b ^ msb)); |
| 1390 |
return IfThenElse(gt, a, b); |
| 1391 |
#endif |
| 1392 |
} |
| 1393 |
|
| 1394 |
|
| 1395 |
HWY_API Vec256<int8_t> Max(const Vec256<int8_t> a, const Vec256<int8_t> b) { |
| 1396 |
return Vec256<int8_t>{_mm256_max_epi8(a.raw, b.raw)}; |
| 1397 |
} |
| 1398 |
HWY_API Vec256<int16_t> Max(const Vec256<int16_t> a, const Vec256<int16_t> b) { |
| 1399 |
return Vec256<int16_t>{_mm256_max_epi16(a.raw, b.raw)}; |
| 1400 |
} |
| 1401 |
HWY_API Vec256<int32_t> Max(const Vec256<int32_t> a, const Vec256<int32_t> b) { |
| 1402 |
return Vec256<int32_t>{_mm256_max_epi32(a.raw, b.raw)}; |
| 1403 |
} |
| 1404 |
HWY_API Vec256<int64_t> Max(const Vec256<int64_t> a, const Vec256<int64_t> b) { |
| 1405 |
#if HWY_TARGET <= HWY_AVX3 |
| 1406 |
return Vec256<int64_t>{_mm256_max_epi64(a.raw, b.raw)}; |
| 1407 |
#else |
| 1408 |
return IfThenElse(a < b, b, a); |
| 1409 |
#endif |
| 1410 |
} |
| 1411 |
|
| 1412 |
|
| 1413 |
HWY_API Vec256<float> Max(const Vec256<float> a, const Vec256<float> b) { |
| 1414 |
return Vec256<float>{_mm256_max_ps(a.raw, b.raw)}; |
| 1415 |
} |
| 1416 |
HWY_API Vec256<double> Max(const Vec256<double> a, const Vec256<double> b) { |
| 1417 |
return Vec256<double>{_mm256_max_pd(a.raw, b.raw)}; |
| 1418 |
} |
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
template <typename T> |
| 1423 |
HWY_API Mask256<T> FirstN(const Full256<T> d, size_t n) { |
| 1424 |
#if HWY_TARGET <= HWY_AVX3 |
| 1425 |
(void)d; |
| 1426 |
constexpr size_t N = 32 / sizeof(T); |
| 1427 |
#if HWY_ARCH_X86_64 |
| 1428 |
const uint64_t all = (1ull << N) - 1; |
| 1429 |
|
| 1430 |
return Mask256<T>::FromBits((n > 255) ? all : _bzhi_u64(all, n)); |
| 1431 |
#else |
| 1432 |
const uint32_t all = static_cast<uint32_t>((1ull << N) - 1); |
| 1433 |
|
| 1434 |
return Mask256<T>::FromBits( |
| 1435 |
(n > 255) ? all : _bzhi_u32(all, static_cast<uint32_t>(n))); |
| 1436 |
#endif |
| 1437 |
#else |
| 1438 |
const RebindToSigned<decltype(d)> di; |
| 1439 |
return RebindMask(d, Iota(di, 0) < Set(di, static_cast<MakeSigned<T>>(n))); |
| 1440 |
#endif |
| 1441 |
} |
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
HWY_API Vec256<uint8_t> operator+(const Vec256<uint8_t> a, |
| 1449 |
const Vec256<uint8_t> b) { |
| 1450 |
return Vec256<uint8_t>{_mm256_add_epi8(a.raw, b.raw)}; |
| 1451 |
} |
| 1452 |
HWY_API Vec256<uint16_t> operator+(const Vec256<uint16_t> a, |
| 1453 |
const Vec256<uint16_t> b) { |
| 1454 |
return Vec256<uint16_t>{_mm256_add_epi16(a.raw, b.raw)}; |
| 1455 |
} |
| 1456 |
HWY_API Vec256<uint32_t> operator+(const Vec256<uint32_t> a, |
| 1457 |
const Vec256<uint32_t> b) { |
| 1458 |
return Vec256<uint32_t>{_mm256_add_epi32(a.raw, b.raw)}; |
| 1459 |
} |
| 1460 |
HWY_API Vec256<uint64_t> operator+(const Vec256<uint64_t> a, |
| 1461 |
const Vec256<uint64_t> b) { |
| 1462 |
return Vec256<uint64_t>{_mm256_add_epi64(a.raw, b.raw)}; |
| 1463 |
} |
| 1464 |
|
| 1465 |
|
| 1466 |
HWY_API Vec256<int8_t> operator+(const Vec256<int8_t> a, |
| 1467 |
const Vec256<int8_t> b) { |
| 1468 |
return Vec256<int8_t>{_mm256_add_epi8(a.raw, b.raw)}; |
| 1469 |
} |
| 1470 |
HWY_API Vec256<int16_t> operator+(const Vec256<int16_t> a, |
| 1471 |
const Vec256<int16_t> b) { |
| 1472 |
return Vec256<int16_t>{_mm256_add_epi16(a.raw, b.raw)}; |
| 1473 |
} |
| 1474 |
HWY_API Vec256<int32_t> operator+(const Vec256<int32_t> a, |
| 1475 |
const Vec256<int32_t> b) { |
| 1476 |
return Vec256<int32_t>{_mm256_add_epi32(a.raw, b.raw)}; |
| 1477 |
} |
| 1478 |
HWY_API Vec256<int64_t> operator+(const Vec256<int64_t> a, |
| 1479 |
const Vec256<int64_t> b) { |
| 1480 |
return Vec256<int64_t>{_mm256_add_epi64(a.raw, b.raw)}; |
| 1481 |
} |
| 1482 |
|
| 1483 |
|
| 1484 |
HWY_API Vec256<float> operator+(const Vec256<float> a, const Vec256<float> b) { |
| 1485 |
return Vec256<float>{_mm256_add_ps(a.raw, b.raw)}; |
| 1486 |
} |
| 1487 |
HWY_API Vec256<double> operator+(const Vec256<double> a, |
| 1488 |
const Vec256<double> b) { |
| 1489 |
return Vec256<double>{_mm256_add_pd(a.raw, b.raw)}; |
| 1490 |
} |
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
HWY_API Vec256<uint8_t> operator-(const Vec256<uint8_t> a, |
| 1496 |
const Vec256<uint8_t> b) { |
| 1497 |
return Vec256<uint8_t>{_mm256_sub_epi8(a.raw, b.raw)}; |
| 1498 |
} |
| 1499 |
HWY_API Vec256<uint16_t> operator-(const Vec256<uint16_t> a, |
| 1500 |
const Vec256<uint16_t> b) { |
| 1501 |
return Vec256<uint16_t>{_mm256_sub_epi16(a.raw, b.raw)}; |
| 1502 |
} |
| 1503 |
HWY_API Vec256<uint32_t> operator-(const Vec256<uint32_t> a, |
| 1504 |
const Vec256<uint32_t> b) { |
| 1505 |
return Vec256<uint32_t>{_mm256_sub_epi32(a.raw, b.raw)}; |
| 1506 |
} |
| 1507 |
HWY_API Vec256<uint64_t> operator-(const Vec256<uint64_t> a, |
| 1508 |
const Vec256<uint64_t> b) { |
| 1509 |
return Vec256<uint64_t>{_mm256_sub_epi64(a.raw, b.raw)}; |
| 1510 |
} |
| 1511 |
|
| 1512 |
|
| 1513 |
HWY_API Vec256<int8_t> operator-(const Vec256<int8_t> a, |
| 1514 |
const Vec256<int8_t> b) { |
| 1515 |
return Vec256<int8_t>{_mm256_sub_epi8(a.raw, b.raw)}; |
| 1516 |
} |
| 1517 |
HWY_API Vec256<int16_t> operator-(const Vec256<int16_t> a, |
| 1518 |
const Vec256<int16_t> b) { |
| 1519 |
return Vec256<int16_t>{_mm256_sub_epi16(a.raw, b.raw)}; |
| 1520 |
} |
| 1521 |
HWY_API Vec256<int32_t> operator-(const Vec256<int32_t> a, |
| 1522 |
const Vec256<int32_t> b) { |
| 1523 |
return Vec256<int32_t>{_mm256_sub_epi32(a.raw, b.raw)}; |
| 1524 |
} |
| 1525 |
HWY_API Vec256<int64_t> operator-(const Vec256<int64_t> a, |
| 1526 |
const Vec256<int64_t> b) { |
| 1527 |
return Vec256<int64_t>{_mm256_sub_epi64(a.raw, b.raw)}; |
| 1528 |
} |
| 1529 |
|
| 1530 |
|
| 1531 |
HWY_API Vec256<float> operator-(const Vec256<float> a, const Vec256<float> b) { |
| 1532 |
return Vec256<float>{_mm256_sub_ps(a.raw, b.raw)}; |
| 1533 |
} |
| 1534 |
HWY_API Vec256<double> operator-(const Vec256<double> a, |
| 1535 |
const Vec256<double> b) { |
| 1536 |
return Vec256<double>{_mm256_sub_pd(a.raw, b.raw)}; |
| 1537 |
} |
| 1538 |
|
| 1539 |
|
| 1540 |
HWY_API Vec256<uint64_t> SumsOf8(const Vec256<uint8_t> v) { |
| 1541 |
return Vec256<uint64_t>{_mm256_sad_epu8(v.raw, _mm256_setzero_si256())}; |
| 1542 |
} |
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
HWY_API Vec256<uint8_t> SaturatedAdd(const Vec256<uint8_t> a, |
| 1550 |
const Vec256<uint8_t> b) { |
| 1551 |
return Vec256<uint8_t>{_mm256_adds_epu8(a.raw, b.raw)}; |
| 1552 |
} |
| 1553 |
HWY_API Vec256<uint16_t> SaturatedAdd(const Vec256<uint16_t> a, |
| 1554 |
const Vec256<uint16_t> b) { |
| 1555 |
return Vec256<uint16_t>{_mm256_adds_epu16(a.raw, b.raw)}; |
| 1556 |
} |
| 1557 |
|
| 1558 |
|
| 1559 |
HWY_API Vec256<int8_t> SaturatedAdd(const Vec256<int8_t> a, |
| 1560 |
const Vec256<int8_t> b) { |
| 1561 |
return Vec256<int8_t>{_mm256_adds_epi8(a.raw, b.raw)}; |
| 1562 |
} |
| 1563 |
HWY_API Vec256<int16_t> SaturatedAdd(const Vec256<int16_t> a, |
| 1564 |
const Vec256<int16_t> b) { |
| 1565 |
return Vec256<int16_t>{_mm256_adds_epi16(a.raw, b.raw)}; |
| 1566 |
} |
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
HWY_API Vec256<uint8_t> SaturatedSub(const Vec256<uint8_t> a, |
| 1574 |
const Vec256<uint8_t> b) { |
| 1575 |
return Vec256<uint8_t>{_mm256_subs_epu8(a.raw, b.raw)}; |
| 1576 |
} |
| 1577 |
HWY_API Vec256<uint16_t> SaturatedSub(const Vec256<uint16_t> a, |
| 1578 |
const Vec256<uint16_t> b) { |
| 1579 |
return Vec256<uint16_t>{_mm256_subs_epu16(a.raw, b.raw)}; |
| 1580 |
} |
| 1581 |
|
| 1582 |
|
| 1583 |
HWY_API Vec256<int8_t> SaturatedSub(const Vec256<int8_t> a, |
| 1584 |
const Vec256<int8_t> b) { |
| 1585 |
return Vec256<int8_t>{_mm256_subs_epi8(a.raw, b.raw)}; |
| 1586 |
} |
| 1587 |
HWY_API Vec256<int16_t> SaturatedSub(const Vec256<int16_t> a, |
| 1588 |
const Vec256<int16_t> b) { |
| 1589 |
return Vec256<int16_t>{_mm256_subs_epi16(a.raw, b.raw)}; |
| 1590 |
} |
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
HWY_API Vec256<uint8_t> AverageRound(const Vec256<uint8_t> a, |
| 1598 |
const Vec256<uint8_t> b) { |
| 1599 |
return Vec256<uint8_t>{_mm256_avg_epu8(a.raw, b.raw)}; |
| 1600 |
} |
| 1601 |
HWY_API Vec256<uint16_t> AverageRound(const Vec256<uint16_t> a, |
| 1602 |
const Vec256<uint16_t> b) { |
| 1603 |
return Vec256<uint16_t>{_mm256_avg_epu16(a.raw, b.raw)}; |
| 1604 |
} |
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
HWY_API Vec256<int8_t> Abs(const Vec256<int8_t> v) { |
| 1610 |
#if HWY_COMPILER_MSVC |
| 1611 |
|
| 1612 |
const auto zero = Zero(Full256<int8_t>()); |
| 1613 |
return Vec256<int8_t>{_mm256_max_epi8(v.raw, (zero - v).raw)}; |
| 1614 |
#else |
| 1615 |
return Vec256<int8_t>{_mm256_abs_epi8(v.raw)}; |
| 1616 |
#endif |
| 1617 |
} |
| 1618 |
HWY_API Vec256<int16_t> Abs(const Vec256<int16_t> v) { |
| 1619 |
return Vec256<int16_t>{_mm256_abs_epi16(v.raw)}; |
| 1620 |
} |
| 1621 |
HWY_API Vec256<int32_t> Abs(const Vec256<int32_t> v) { |
| 1622 |
return Vec256<int32_t>{_mm256_abs_epi32(v.raw)}; |
| 1623 |
} |
| 1624 |
|
| 1625 |
|
| 1626 |
HWY_API Vec256<float> Abs(const Vec256<float> v) { |
| 1627 |
const Vec256<int32_t> mask{_mm256_set1_epi32(0x7FFFFFFF)}; |
| 1628 |
return v & BitCast(Full256<float>(), mask); |
| 1629 |
} |
| 1630 |
HWY_API Vec256<double> Abs(const Vec256<double> v) { |
| 1631 |
const Vec256<int64_t> mask{_mm256_set1_epi64x(0x7FFFFFFFFFFFFFFFLL)}; |
| 1632 |
return v & BitCast(Full256<double>(), mask); |
| 1633 |
} |
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
HWY_API Vec256<uint16_t> operator*(Vec256<uint16_t> a, Vec256<uint16_t> b) { |
| 1639 |
return Vec256<uint16_t>{_mm256_mullo_epi16(a.raw, b.raw)}; |
| 1640 |
} |
| 1641 |
HWY_API Vec256<uint32_t> operator*(Vec256<uint32_t> a, Vec256<uint32_t> b) { |
| 1642 |
return Vec256<uint32_t>{_mm256_mullo_epi32(a.raw, b.raw)}; |
| 1643 |
} |
| 1644 |
|
| 1645 |
|
| 1646 |
HWY_API Vec256<int16_t> operator*(Vec256<int16_t> a, Vec256<int16_t> b) { |
| 1647 |
return Vec256<int16_t>{_mm256_mullo_epi16(a.raw, b.raw)}; |
| 1648 |
} |
| 1649 |
HWY_API Vec256<int32_t> operator*(Vec256<int32_t> a, Vec256<int32_t> b) { |
| 1650 |
return Vec256<int32_t>{_mm256_mullo_epi32(a.raw, b.raw)}; |
| 1651 |
} |
| 1652 |
|
| 1653 |
|
| 1654 |
HWY_API Vec256<uint16_t> MulHigh(Vec256<uint16_t> a, Vec256<uint16_t> b) { |
| 1655 |
return Vec256<uint16_t>{_mm256_mulhi_epu16(a.raw, b.raw)}; |
| 1656 |
} |
| 1657 |
HWY_API Vec256<int16_t> MulHigh(Vec256<int16_t> a, Vec256<int16_t> b) { |
| 1658 |
return Vec256<int16_t>{_mm256_mulhi_epi16(a.raw, b.raw)}; |
| 1659 |
} |
| 1660 |
|
| 1661 |
HWY_API Vec256<int16_t> MulFixedPoint15(Vec256<int16_t> a, Vec256<int16_t> b) { |
| 1662 |
return Vec256<int16_t>{_mm256_mulhrs_epi16(a.raw, b.raw)}; |
| 1663 |
} |
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
HWY_API Vec256<int64_t> MulEven(Vec256<int32_t> a, Vec256<int32_t> b) { |
| 1668 |
return Vec256<int64_t>{_mm256_mul_epi32(a.raw, b.raw)}; |
| 1669 |
} |
| 1670 |
HWY_API Vec256<uint64_t> MulEven(Vec256<uint32_t> a, Vec256<uint32_t> b) { |
| 1671 |
return Vec256<uint64_t>{_mm256_mul_epu32(a.raw, b.raw)}; |
| 1672 |
} |
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
template <int kBits> |
| 1677 |
HWY_API Vec256<uint16_t> ShiftLeft(const Vec256<uint16_t> v) { |
| 1678 |
return Vec256<uint16_t>{_mm256_slli_epi16(v.raw, kBits)}; |
| 1679 |
} |
| 1680 |
|
| 1681 |
template <int kBits> |
| 1682 |
HWY_API Vec256<uint32_t> ShiftLeft(const Vec256<uint32_t> v) { |
| 1683 |
return Vec256<uint32_t>{_mm256_slli_epi32(v.raw, kBits)}; |
| 1684 |
} |
| 1685 |
|
| 1686 |
template <int kBits> |
| 1687 |
HWY_API Vec256<uint64_t> ShiftLeft(const Vec256<uint64_t> v) { |
| 1688 |
return Vec256<uint64_t>{_mm256_slli_epi64(v.raw, kBits)}; |
| 1689 |
} |
| 1690 |
|
| 1691 |
template <int kBits> |
| 1692 |
HWY_API Vec256<int16_t> ShiftLeft(const Vec256<int16_t> v) { |
| 1693 |
return Vec256<int16_t>{_mm256_slli_epi16(v.raw, kBits)}; |
| 1694 |
} |
| 1695 |
|
| 1696 |
template <int kBits> |
| 1697 |
HWY_API Vec256<int32_t> ShiftLeft(const Vec256<int32_t> v) { |
| 1698 |
return Vec256<int32_t>{_mm256_slli_epi32(v.raw, kBits)}; |
| 1699 |
} |
| 1700 |
|
| 1701 |
template <int kBits> |
| 1702 |
HWY_API Vec256<int64_t> ShiftLeft(const Vec256<int64_t> v) { |
| 1703 |
return Vec256<int64_t>{_mm256_slli_epi64(v.raw, kBits)}; |
| 1704 |
} |
| 1705 |
|
| 1706 |
template <int kBits, typename T, HWY_IF_LANE_SIZE(T, 1)> |
| 1707 |
HWY_API Vec256<T> ShiftLeft(const Vec256<T> v) { |
| 1708 |
const Full256<T> d8; |
| 1709 |
const RepartitionToWide<decltype(d8)> d16; |
| 1710 |
const auto shifted = BitCast(d8, ShiftLeft<kBits>(BitCast(d16, v))); |
| 1711 |
return kBits == 1 |
| 1712 |
? (v + v) |
| 1713 |
: (shifted & Set(d8, static_cast<T>((0xFF << kBits) & 0xFF))); |
| 1714 |
} |
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
template <int kBits> |
| 1719 |
HWY_API Vec256<uint16_t> ShiftRight(const Vec256<uint16_t> v) { |
| 1720 |
return Vec256<uint16_t>{_mm256_srli_epi16(v.raw, kBits)}; |
| 1721 |
} |
| 1722 |
|
| 1723 |
template <int kBits> |
| 1724 |
HWY_API Vec256<uint32_t> ShiftRight(const Vec256<uint32_t> v) { |
| 1725 |
return Vec256<uint32_t>{_mm256_srli_epi32(v.raw, kBits)}; |
| 1726 |
} |
| 1727 |
|
| 1728 |
template <int kBits> |
| 1729 |
HWY_API Vec256<uint64_t> ShiftRight(const Vec256<uint64_t> v) { |
| 1730 |
return Vec256<uint64_t>{_mm256_srli_epi64(v.raw, kBits)}; |
| 1731 |
} |
| 1732 |
|
| 1733 |
template <int kBits> |
| 1734 |
HWY_API Vec256<uint8_t> ShiftRight(const Vec256<uint8_t> v) { |
| 1735 |
const Full256<uint8_t> d8; |
| 1736 |
|
| 1737 |
const Vec256<uint8_t> shifted{ShiftRight<kBits>(Vec256<uint16_t>{v.raw}).raw}; |
| 1738 |
return shifted & Set(d8, 0xFF >> kBits); |
| 1739 |
} |
| 1740 |
|
| 1741 |
template <int kBits> |
| 1742 |
HWY_API Vec256<int16_t> ShiftRight(const Vec256<int16_t> v) { |
| 1743 |
return Vec256<int16_t>{_mm256_srai_epi16(v.raw, kBits)}; |
| 1744 |
} |
| 1745 |
|
| 1746 |
template <int kBits> |
| 1747 |
HWY_API Vec256<int32_t> ShiftRight(const Vec256<int32_t> v) { |
| 1748 |
return Vec256<int32_t>{_mm256_srai_epi32(v.raw, kBits)}; |
| 1749 |
} |
| 1750 |
|
| 1751 |
template <int kBits> |
| 1752 |
HWY_API Vec256<int8_t> ShiftRight(const Vec256<int8_t> v) { |
| 1753 |
const Full256<int8_t> di; |
| 1754 |
const Full256<uint8_t> du; |
| 1755 |
const auto shifted = BitCast(di, ShiftRight<kBits>(BitCast(du, v))); |
| 1756 |
const auto shifted_sign = BitCast(di, Set(du, 0x80 >> kBits)); |
| 1757 |
return (shifted ^ shifted_sign) - shifted_sign; |
| 1758 |
} |
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
template <int kBits> |
| 1765 |
HWY_API Vec256<uint32_t> RotateRight(const Vec256<uint32_t> v) { |
| 1766 |
static_assert(0 <= kBits && kBits < 32, "Invalid shift count"); |
| 1767 |
#if HWY_TARGET <= HWY_AVX3 |
| 1768 |
return Vec256<uint32_t>{_mm256_ror_epi32(v.raw, kBits)}; |
| 1769 |
#else |
| 1770 |
if (kBits == 0) return v; |
| 1771 |
return Or(ShiftRight<kBits>(v), ShiftLeft<HWY_MIN(31, 32 - kBits)>(v)); |
| 1772 |
#endif |
| 1773 |
} |
| 1774 |
|
| 1775 |
template <int kBits> |
| 1776 |
HWY_API Vec256<uint64_t> RotateRight(const Vec256<uint64_t> v) { |
| 1777 |
static_assert(0 <= kBits && kBits < 64, "Invalid shift count"); |
| 1778 |
#if HWY_TARGET <= HWY_AVX3 |
| 1779 |
return Vec256<uint64_t>{_mm256_ror_epi64(v.raw, kBits)}; |
| 1780 |
#else |
| 1781 |
if (kBits == 0) return v; |
| 1782 |
return Or(ShiftRight<kBits>(v), ShiftLeft<HWY_MIN(63, 64 - kBits)>(v)); |
| 1783 |
#endif |
| 1784 |
} |
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
HWY_API Vec256<int8_t> BroadcastSignBit(const Vec256<int8_t> v) { |
| 1789 |
return VecFromMask(v < Zero(Full256<int8_t>())); |
| 1790 |
} |
| 1791 |
|
| 1792 |
HWY_API Vec256<int16_t> BroadcastSignBit(const Vec256<int16_t> v) { |
| 1793 |
return ShiftRight<15>(v); |
| 1794 |
} |
| 1795 |
|
| 1796 |
HWY_API Vec256<int32_t> BroadcastSignBit(const Vec256<int32_t> v) { |
| 1797 |
return ShiftRight<31>(v); |
| 1798 |
} |
| 1799 |
|
| 1800 |
HWY_API Vec256<int64_t> BroadcastSignBit(const Vec256<int64_t> v) { |
| 1801 |
#if HWY_TARGET == HWY_AVX2 |
| 1802 |
return VecFromMask(v < Zero(Full256<int64_t>())); |
| 1803 |
#else |
| 1804 |
return Vec256<int64_t>{_mm256_srai_epi64(v.raw, 63)}; |
| 1805 |
#endif |
| 1806 |
} |
| 1807 |
|
| 1808 |
template <int kBits> |
| 1809 |
HWY_API Vec256<int64_t> ShiftRight(const Vec256<int64_t> v) { |
| 1810 |
#if HWY_TARGET <= HWY_AVX3 |
| 1811 |
return Vec256<int64_t>{_mm256_srai_epi64(v.raw, kBits)}; |
| 1812 |
#else |
| 1813 |
const Full256<int64_t> di; |
| 1814 |
const Full256<uint64_t> du; |
| 1815 |
const auto right = BitCast(di, ShiftRight<kBits>(BitCast(du, v))); |
| 1816 |
const auto sign = ShiftLeft<64 - kBits>(BroadcastSignBit(v)); |
| 1817 |
return right | sign; |
| 1818 |
#endif |
| 1819 |
} |
| 1820 |
|
| 1821 |
HWY_API Vec256<int64_t> Abs(const Vec256<int64_t> v) { |
| 1822 |
#if HWY_TARGET <= HWY_AVX3 |
| 1823 |
return Vec256<int64_t>{_mm256_abs_epi64(v.raw)}; |
| 1824 |
#else |
| 1825 |
const auto zero = Zero(Full256<int64_t>()); |
| 1826 |
return IfThenElse(MaskFromVec(BroadcastSignBit(v)), zero - v, v); |
| 1827 |
#endif |
| 1828 |
} |
| 1829 |
|
| 1830 |
|
| 1831 |
HWY_API Vec256<int8_t> IfNegativeThenElse(Vec256<int8_t> v, Vec256<int8_t> yes, |
| 1832 |
Vec256<int8_t> no) { |
| 1833 |
|
| 1834 |
return IfThenElse(MaskFromVec(v), yes, no); |
| 1835 |
} |
| 1836 |
|
| 1837 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 1838 |
HWY_API Vec256<T> IfNegativeThenElse(Vec256<T> v, Vec256<T> yes, Vec256<T> no) { |
| 1839 |
static_assert(IsSigned<T>(), "Only works for signed/float"); |
| 1840 |
const Full256<T> d; |
| 1841 |
const RebindToSigned<decltype(d)> di; |
| 1842 |
|
| 1843 |
|
| 1844 |
v = BitCast(d, BroadcastSignBit(BitCast(di, v))); |
| 1845 |
return IfThenElse(MaskFromVec(v), yes, no); |
| 1846 |
} |
| 1847 |
|
| 1848 |
template <typename T, HWY_IF_NOT_LANE_SIZE(T, 2)> |
| 1849 |
HWY_API Vec256<T> IfNegativeThenElse(Vec256<T> v, Vec256<T> yes, Vec256<T> no) { |
| 1850 |
static_assert(IsSigned<T>(), "Only works for signed/float"); |
| 1851 |
const Full256<T> d; |
| 1852 |
const RebindToFloat<decltype(d)> df; |
| 1853 |
|
| 1854 |
|
| 1855 |
const MFromD<decltype(df)> msb = MaskFromVec(BitCast(df, v)); |
| 1856 |
return BitCast(d, IfThenElse(msb, BitCast(df, yes), BitCast(df, no))); |
| 1857 |
} |
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
HWY_API Vec256<uint16_t> ShiftLeftSame(const Vec256<uint16_t> v, |
| 1862 |
const int bits) { |
| 1863 |
return Vec256<uint16_t>{_mm256_sll_epi16(v.raw, _mm_cvtsi32_si128(bits))}; |
| 1864 |
} |
| 1865 |
HWY_API Vec256<uint32_t> ShiftLeftSame(const Vec256<uint32_t> v, |
| 1866 |
const int bits) { |
| 1867 |
return Vec256<uint32_t>{_mm256_sll_epi32(v.raw, _mm_cvtsi32_si128(bits))}; |
| 1868 |
} |
| 1869 |
HWY_API Vec256<uint64_t> ShiftLeftSame(const Vec256<uint64_t> v, |
| 1870 |
const int bits) { |
| 1871 |
return Vec256<uint64_t>{_mm256_sll_epi64(v.raw, _mm_cvtsi32_si128(bits))}; |
| 1872 |
} |
| 1873 |
|
| 1874 |
HWY_API Vec256<int16_t> ShiftLeftSame(const Vec256<int16_t> v, const int bits) { |
| 1875 |
return Vec256<int16_t>{_mm256_sll_epi16(v.raw, _mm_cvtsi32_si128(bits))}; |
| 1876 |
} |
| 1877 |
|
| 1878 |
HWY_API Vec256<int32_t> ShiftLeftSame(const Vec256<int32_t> v, const int bits) { |
| 1879 |
return Vec256<int32_t>{_mm256_sll_epi32(v.raw, _mm_cvtsi32_si128(bits))}; |
| 1880 |
} |
| 1881 |
|
| 1882 |
HWY_API Vec256<int64_t> ShiftLeftSame(const Vec256<int64_t> v, const int bits) { |
| 1883 |
return Vec256<int64_t>{_mm256_sll_epi64(v.raw, _mm_cvtsi32_si128(bits))}; |
| 1884 |
} |
| 1885 |
|
| 1886 |
template <typename T, HWY_IF_LANE_SIZE(T, 1)> |
| 1887 |
HWY_API Vec256<T> ShiftLeftSame(const Vec256<T> v, const int bits) { |
| 1888 |
const Full256<T> d8; |
| 1889 |
const RepartitionToWide<decltype(d8)> d16; |
| 1890 |
const auto shifted = BitCast(d8, ShiftLeftSame(BitCast(d16, v), bits)); |
| 1891 |
return shifted & Set(d8, static_cast<T>((0xFF << bits) & 0xFF)); |
| 1892 |
} |
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
HWY_API Vec256<uint16_t> ShiftRightSame(const Vec256<uint16_t> v, |
| 1897 |
const int bits) { |
| 1898 |
return Vec256<uint16_t>{_mm256_srl_epi16(v.raw, _mm_cvtsi32_si128(bits))}; |
| 1899 |
} |
| 1900 |
HWY_API Vec256<uint32_t> ShiftRightSame(const Vec256<uint32_t> v, |
| 1901 |
const int bits) { |
| 1902 |
return Vec256<uint32_t>{_mm256_srl_epi32(v.raw, _mm_cvtsi32_si128(bits))}; |
| 1903 |
} |
| 1904 |
HWY_API Vec256<uint64_t> ShiftRightSame(const Vec256<uint64_t> v, |
| 1905 |
const int bits) { |
| 1906 |
return Vec256<uint64_t>{_mm256_srl_epi64(v.raw, _mm_cvtsi32_si128(bits))}; |
| 1907 |
} |
| 1908 |
|
| 1909 |
HWY_API Vec256<uint8_t> ShiftRightSame(Vec256<uint8_t> v, const int bits) { |
| 1910 |
const Full256<uint8_t> d8; |
| 1911 |
const RepartitionToWide<decltype(d8)> d16; |
| 1912 |
const auto shifted = BitCast(d8, ShiftRightSame(BitCast(d16, v), bits)); |
| 1913 |
return shifted & Set(d8, static_cast<uint8_t>(0xFF >> bits)); |
| 1914 |
} |
| 1915 |
|
| 1916 |
HWY_API Vec256<int16_t> ShiftRightSame(const Vec256<int16_t> v, |
| 1917 |
const int bits) { |
| 1918 |
return Vec256<int16_t>{_mm256_sra_epi16(v.raw, _mm_cvtsi32_si128(bits))}; |
| 1919 |
} |
| 1920 |
|
| 1921 |
HWY_API Vec256<int32_t> ShiftRightSame(const Vec256<int32_t> v, |
| 1922 |
const int bits) { |
| 1923 |
return Vec256<int32_t>{_mm256_sra_epi32(v.raw, _mm_cvtsi32_si128(bits))}; |
| 1924 |
} |
| 1925 |
HWY_API Vec256<int64_t> ShiftRightSame(const Vec256<int64_t> v, |
| 1926 |
const int bits) { |
| 1927 |
#if HWY_TARGET <= HWY_AVX3 |
| 1928 |
return Vec256<int64_t>{_mm256_sra_epi64(v.raw, _mm_cvtsi32_si128(bits))}; |
| 1929 |
#else |
| 1930 |
const Full256<int64_t> di; |
| 1931 |
const Full256<uint64_t> du; |
| 1932 |
const auto right = BitCast(di, ShiftRightSame(BitCast(du, v), bits)); |
| 1933 |
const auto sign = ShiftLeftSame(BroadcastSignBit(v), 64 - bits); |
| 1934 |
return right | sign; |
| 1935 |
#endif |
| 1936 |
} |
| 1937 |
|
| 1938 |
HWY_API Vec256<int8_t> ShiftRightSame(Vec256<int8_t> v, const int bits) { |
| 1939 |
const Full256<int8_t> di; |
| 1940 |
const Full256<uint8_t> du; |
| 1941 |
const auto shifted = BitCast(di, ShiftRightSame(BitCast(du, v), bits)); |
| 1942 |
const auto shifted_sign = |
| 1943 |
BitCast(di, Set(du, static_cast<uint8_t>(0x80 >> bits))); |
| 1944 |
return (shifted ^ shifted_sign) - shifted_sign; |
| 1945 |
} |
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
namespace detail { |
| 1951 |
|
| 1952 |
template <typename T> |
| 1953 |
HWY_INLINE Vec256<T> Neg(hwy::FloatTag , const Vec256<T> v) { |
| 1954 |
return Xor(v, SignBit(Full256<T>())); |
| 1955 |
} |
| 1956 |
|
| 1957 |
|
| 1958 |
template <typename T> |
| 1959 |
HWY_INLINE Vec256<T> Neg(hwy::NonFloatTag , const Vec256<T> v) { |
| 1960 |
return Zero(Full256<T>()) - v; |
| 1961 |
} |
| 1962 |
|
| 1963 |
} |
| 1964 |
|
| 1965 |
template <typename T> |
| 1966 |
HWY_API Vec256<T> Neg(const Vec256<T> v) { |
| 1967 |
return detail::Neg(hwy::IsFloatTag<T>(), v); |
| 1968 |
} |
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
HWY_API Vec256<float> operator*(const Vec256<float> a, const Vec256<float> b) { |
| 1973 |
return Vec256<float>{_mm256_mul_ps(a.raw, b.raw)}; |
| 1974 |
} |
| 1975 |
HWY_API Vec256<double> operator*(const Vec256<double> a, |
| 1976 |
const Vec256<double> b) { |
| 1977 |
return Vec256<double>{_mm256_mul_pd(a.raw, b.raw)}; |
| 1978 |
} |
| 1979 |
|
| 1980 |
HWY_API Vec256<float> operator/(const Vec256<float> a, const Vec256<float> b) { |
| 1981 |
return Vec256<float>{_mm256_div_ps(a.raw, b.raw)}; |
| 1982 |
} |
| 1983 |
HWY_API Vec256<double> operator/(const Vec256<double> a, |
| 1984 |
const Vec256<double> b) { |
| 1985 |
return Vec256<double>{_mm256_div_pd(a.raw, b.raw)}; |
| 1986 |
} |
| 1987 |
|
| 1988 |
|
| 1989 |
HWY_API Vec256<float> ApproximateReciprocal(const Vec256<float> v) { |
| 1990 |
return Vec256<float>{_mm256_rcp_ps(v.raw)}; |
| 1991 |
} |
| 1992 |
|
| 1993 |
|
| 1994 |
HWY_API Vec256<float> AbsDiff(const Vec256<float> a, const Vec256<float> b) { |
| 1995 |
return Abs(a - b); |
| 1996 |
} |
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
HWY_API Vec256<float> MulAdd(const Vec256<float> mul, const Vec256<float> x, |
| 2002 |
const Vec256<float> add) { |
| 2003 |
#ifdef HWY_DISABLE_BMI2_FMA |
| 2004 |
return mul * x + add; |
| 2005 |
#else |
| 2006 |
return Vec256<float>{_mm256_fmadd_ps(mul.raw, x.raw, add.raw)}; |
| 2007 |
#endif |
| 2008 |
} |
| 2009 |
HWY_API Vec256<double> MulAdd(const Vec256<double> mul, const Vec256<double> x, |
| 2010 |
const Vec256<double> add) { |
| 2011 |
#ifdef HWY_DISABLE_BMI2_FMA |
| 2012 |
return mul * x + add; |
| 2013 |
#else |
| 2014 |
return Vec256<double>{_mm256_fmadd_pd(mul.raw, x.raw, add.raw)}; |
| 2015 |
#endif |
| 2016 |
} |
| 2017 |
|
| 2018 |
|
| 2019 |
HWY_API Vec256<float> NegMulAdd(const Vec256<float> mul, const Vec256<float> x, |
| 2020 |
const Vec256<float> add) { |
| 2021 |
#ifdef HWY_DISABLE_BMI2_FMA |
| 2022 |
return add - mul * x; |
| 2023 |
#else |
| 2024 |
return Vec256<float>{_mm256_fnmadd_ps(mul.raw, x.raw, add.raw)}; |
| 2025 |
#endif |
| 2026 |
} |
| 2027 |
HWY_API Vec256<double> NegMulAdd(const Vec256<double> mul, |
| 2028 |
const Vec256<double> x, |
| 2029 |
const Vec256<double> add) { |
| 2030 |
#ifdef HWY_DISABLE_BMI2_FMA |
| 2031 |
return add - mul * x; |
| 2032 |
#else |
| 2033 |
return Vec256<double>{_mm256_fnmadd_pd(mul.raw, x.raw, add.raw)}; |
| 2034 |
#endif |
| 2035 |
} |
| 2036 |
|
| 2037 |
|
| 2038 |
HWY_API Vec256<float> MulSub(const Vec256<float> mul, const Vec256<float> x, |
| 2039 |
const Vec256<float> sub) { |
| 2040 |
#ifdef HWY_DISABLE_BMI2_FMA |
| 2041 |
return mul * x - sub; |
| 2042 |
#else |
| 2043 |
return Vec256<float>{_mm256_fmsub_ps(mul.raw, x.raw, sub.raw)}; |
| 2044 |
#endif |
| 2045 |
} |
| 2046 |
HWY_API Vec256<double> MulSub(const Vec256<double> mul, const Vec256<double> x, |
| 2047 |
const Vec256<double> sub) { |
| 2048 |
#ifdef HWY_DISABLE_BMI2_FMA |
| 2049 |
return mul * x - sub; |
| 2050 |
#else |
| 2051 |
return Vec256<double>{_mm256_fmsub_pd(mul.raw, x.raw, sub.raw)}; |
| 2052 |
#endif |
| 2053 |
} |
| 2054 |
|
| 2055 |
|
| 2056 |
HWY_API Vec256<float> NegMulSub(const Vec256<float> mul, const Vec256<float> x, |
| 2057 |
const Vec256<float> sub) { |
| 2058 |
#ifdef HWY_DISABLE_BMI2_FMA |
| 2059 |
return Neg(mul * x) - sub; |
| 2060 |
#else |
| 2061 |
return Vec256<float>{_mm256_fnmsub_ps(mul.raw, x.raw, sub.raw)}; |
| 2062 |
#endif |
| 2063 |
} |
| 2064 |
HWY_API Vec256<double> NegMulSub(const Vec256<double> mul, |
| 2065 |
const Vec256<double> x, |
| 2066 |
const Vec256<double> sub) { |
| 2067 |
#ifdef HWY_DISABLE_BMI2_FMA |
| 2068 |
return Neg(mul * x) - sub; |
| 2069 |
#else |
| 2070 |
return Vec256<double>{_mm256_fnmsub_pd(mul.raw, x.raw, sub.raw)}; |
| 2071 |
#endif |
| 2072 |
} |
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
HWY_API Vec256<float> Sqrt(const Vec256<float> v) { |
| 2078 |
return Vec256<float>{_mm256_sqrt_ps(v.raw)}; |
| 2079 |
} |
| 2080 |
HWY_API Vec256<double> Sqrt(const Vec256<double> v) { |
| 2081 |
return Vec256<double>{_mm256_sqrt_pd(v.raw)}; |
| 2082 |
} |
| 2083 |
|
| 2084 |
|
| 2085 |
HWY_API Vec256<float> ApproximateReciprocalSqrt(const Vec256<float> v) { |
| 2086 |
return Vec256<float>{_mm256_rsqrt_ps(v.raw)}; |
| 2087 |
} |
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
HWY_API Vec256<float> Round(const Vec256<float> v) { |
| 2093 |
return Vec256<float>{ |
| 2094 |
_mm256_round_ps(v.raw, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC)}; |
| 2095 |
} |
| 2096 |
HWY_API Vec256<double> Round(const Vec256<double> v) { |
| 2097 |
return Vec256<double>{ |
| 2098 |
_mm256_round_pd(v.raw, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC)}; |
| 2099 |
} |
| 2100 |
|
| 2101 |
|
| 2102 |
HWY_API Vec256<float> Trunc(const Vec256<float> v) { |
| 2103 |
return Vec256<float>{ |
| 2104 |
_mm256_round_ps(v.raw, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC)}; |
| 2105 |
} |
| 2106 |
HWY_API Vec256<double> Trunc(const Vec256<double> v) { |
| 2107 |
return Vec256<double>{ |
| 2108 |
_mm256_round_pd(v.raw, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC)}; |
| 2109 |
} |
| 2110 |
|
| 2111 |
|
| 2112 |
HWY_API Vec256<float> Ceil(const Vec256<float> v) { |
| 2113 |
return Vec256<float>{ |
| 2114 |
_mm256_round_ps(v.raw, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC)}; |
| 2115 |
} |
| 2116 |
HWY_API Vec256<double> Ceil(const Vec256<double> v) { |
| 2117 |
return Vec256<double>{ |
| 2118 |
_mm256_round_pd(v.raw, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC)}; |
| 2119 |
} |
| 2120 |
|
| 2121 |
|
| 2122 |
HWY_API Vec256<float> Floor(const Vec256<float> v) { |
| 2123 |
return Vec256<float>{ |
| 2124 |
_mm256_round_ps(v.raw, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC)}; |
| 2125 |
} |
| 2126 |
HWY_API Vec256<double> Floor(const Vec256<double> v) { |
| 2127 |
return Vec256<double>{ |
| 2128 |
_mm256_round_pd(v.raw, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC)}; |
| 2129 |
} |
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
HWY_API Mask256<float> IsNaN(const Vec256<float> v) { |
| 2134 |
#if HWY_TARGET <= HWY_AVX3 |
| 2135 |
return Mask256<float>{_mm256_fpclass_ps_mask(v.raw, 0x81)}; |
| 2136 |
#else |
| 2137 |
return Mask256<float>{_mm256_cmp_ps(v.raw, v.raw, _CMP_UNORD_Q)}; |
| 2138 |
#endif |
| 2139 |
} |
| 2140 |
HWY_API Mask256<double> IsNaN(const Vec256<double> v) { |
| 2141 |
#if HWY_TARGET <= HWY_AVX3 |
| 2142 |
return Mask256<double>{_mm256_fpclass_pd_mask(v.raw, 0x81)}; |
| 2143 |
#else |
| 2144 |
return Mask256<double>{_mm256_cmp_pd(v.raw, v.raw, _CMP_UNORD_Q)}; |
| 2145 |
#endif |
| 2146 |
} |
| 2147 |
|
| 2148 |
#if HWY_TARGET <= HWY_AVX3 |
| 2149 |
|
| 2150 |
HWY_API Mask256<float> IsInf(const Vec256<float> v) { |
| 2151 |
return Mask256<float>{_mm256_fpclass_ps_mask(v.raw, 0x18)}; |
| 2152 |
} |
| 2153 |
HWY_API Mask256<double> IsInf(const Vec256<double> v) { |
| 2154 |
return Mask256<double>{_mm256_fpclass_pd_mask(v.raw, 0x18)}; |
| 2155 |
} |
| 2156 |
|
| 2157 |
HWY_API Mask256<float> IsFinite(const Vec256<float> v) { |
| 2158 |
|
| 2159 |
|
| 2160 |
return Not(Mask256<float>{_mm256_fpclass_ps_mask(v.raw, 0x99)}); |
| 2161 |
} |
| 2162 |
HWY_API Mask256<double> IsFinite(const Vec256<double> v) { |
| 2163 |
return Not(Mask256<double>{_mm256_fpclass_pd_mask(v.raw, 0x99)}); |
| 2164 |
} |
| 2165 |
|
| 2166 |
#else |
| 2167 |
|
| 2168 |
template <typename T> |
| 2169 |
HWY_API Mask256<T> IsInf(const Vec256<T> v) { |
| 2170 |
static_assert(IsFloat<T>(), "Only for float"); |
| 2171 |
const Full256<T> d; |
| 2172 |
const RebindToSigned<decltype(d)> di; |
| 2173 |
const VFromD<decltype(di)> vi = BitCast(di, v); |
| 2174 |
|
| 2175 |
return RebindMask(d, Eq(Add(vi, vi), Set(di, hwy::MaxExponentTimes2<T>()))); |
| 2176 |
} |
| 2177 |
|
| 2178 |
|
| 2179 |
template <typename T> |
| 2180 |
HWY_API Mask256<T> IsFinite(const Vec256<T> v) { |
| 2181 |
static_assert(IsFloat<T>(), "Only for float"); |
| 2182 |
const Full256<T> d; |
| 2183 |
const RebindToUnsigned<decltype(d)> du; |
| 2184 |
const RebindToSigned<decltype(d)> di; |
| 2185 |
const VFromD<decltype(du)> vu = BitCast(du, v); |
| 2186 |
|
| 2187 |
|
| 2188 |
|
| 2189 |
|
| 2190 |
const VFromD<decltype(di)> exp = |
| 2191 |
BitCast(di, ShiftRight<hwy::MantissaBits<T>() + 1>(ShiftLeft<1>(vu))); |
| 2192 |
return RebindMask(d, Lt(exp, Set(di, hwy::MaxExponentField<T>()))); |
| 2193 |
} |
| 2194 |
|
| 2195 |
#endif |
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
template <typename T> |
| 2202 |
HWY_API Vec256<T> Load(Full256<T> , const T* HWY_RESTRICT aligned) { |
| 2203 |
return Vec256<T>{ |
| 2204 |
_mm256_load_si256(reinterpret_cast<const __m256i*>(aligned))}; |
| 2205 |
} |
| 2206 |
HWY_API Vec256<float> Load(Full256<float> , |
| 2207 |
const float* HWY_RESTRICT aligned) { |
| 2208 |
return Vec256<float>{_mm256_load_ps(aligned)}; |
| 2209 |
} |
| 2210 |
HWY_API Vec256<double> Load(Full256<double> , |
| 2211 |
const double* HWY_RESTRICT aligned) { |
| 2212 |
return Vec256<double>{_mm256_load_pd(aligned)}; |
| 2213 |
} |
| 2214 |
|
| 2215 |
template <typename T> |
| 2216 |
HWY_API Vec256<T> LoadU(Full256<T> , const T* HWY_RESTRICT p) { |
| 2217 |
return Vec256<T>{_mm256_loadu_si256(reinterpret_cast<const __m256i*>(p))}; |
| 2218 |
} |
| 2219 |
HWY_API Vec256<float> LoadU(Full256<float> , |
| 2220 |
const float* HWY_RESTRICT p) { |
| 2221 |
return Vec256<float>{_mm256_loadu_ps(p)}; |
| 2222 |
} |
| 2223 |
HWY_API Vec256<double> LoadU(Full256<double> , |
| 2224 |
const double* HWY_RESTRICT p) { |
| 2225 |
return Vec256<double>{_mm256_loadu_pd(p)}; |
| 2226 |
} |
| 2227 |
|
| 2228 |
|
| 2229 |
|
| 2230 |
#if HWY_TARGET <= HWY_AVX3 |
| 2231 |
|
| 2232 |
template <typename T, HWY_IF_LANE_SIZE(T, 1)> |
| 2233 |
HWY_API Vec256<T> MaskedLoad(Mask256<T> m, Full256<T> , |
| 2234 |
const T* HWY_RESTRICT p) { |
| 2235 |
return Vec256<T>{_mm256_maskz_loadu_epi8(m.raw, p)}; |
| 2236 |
} |
| 2237 |
|
| 2238 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 2239 |
HWY_API Vec256<T> MaskedLoad(Mask256<T> m, Full256<T> , |
| 2240 |
const T* HWY_RESTRICT p) { |
| 2241 |
return Vec256<T>{_mm256_maskz_loadu_epi16(m.raw, p)}; |
| 2242 |
} |
| 2243 |
|
| 2244 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 2245 |
HWY_API Vec256<T> MaskedLoad(Mask256<T> m, Full256<T> , |
| 2246 |
const T* HWY_RESTRICT p) { |
| 2247 |
return Vec256<T>{_mm256_maskz_loadu_epi32(m.raw, p)}; |
| 2248 |
} |
| 2249 |
|
| 2250 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 2251 |
HWY_API Vec256<T> MaskedLoad(Mask256<T> m, Full256<T> , |
| 2252 |
const T* HWY_RESTRICT p) { |
| 2253 |
return Vec256<T>{_mm256_maskz_loadu_epi64(m.raw, p)}; |
| 2254 |
} |
| 2255 |
|
| 2256 |
HWY_API Vec256<float> MaskedLoad(Mask256<float> m, Full256<float> , |
| 2257 |
const float* HWY_RESTRICT p) { |
| 2258 |
return Vec256<float>{_mm256_maskz_loadu_ps(m.raw, p)}; |
| 2259 |
} |
| 2260 |
|
| 2261 |
HWY_API Vec256<double> MaskedLoad(Mask256<double> m, Full256<double> , |
| 2262 |
const double* HWY_RESTRICT p) { |
| 2263 |
return Vec256<double>{_mm256_maskz_loadu_pd(m.raw, p)}; |
| 2264 |
} |
| 2265 |
|
| 2266 |
#else |
| 2267 |
|
| 2268 |
|
| 2269 |
template <typename T, hwy::EnableIf<sizeof(T) <= 2>* = nullptr> |
| 2270 |
HWY_API Vec256<T> MaskedLoad(Mask256<T> m, Full256<T> d, |
| 2271 |
const T* HWY_RESTRICT p) { |
| 2272 |
return IfThenElseZero(m, LoadU(d, p)); |
| 2273 |
} |
| 2274 |
|
| 2275 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 2276 |
HWY_API Vec256<T> MaskedLoad(Mask256<T> m, Full256<T> , |
| 2277 |
const T* HWY_RESTRICT p) { |
| 2278 |
auto pi = reinterpret_cast<const int*>(p); |
| 2279 |
return Vec256<T>{_mm256_maskload_epi32(pi, m.raw)}; |
| 2280 |
} |
| 2281 |
|
| 2282 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 2283 |
HWY_API Vec256<T> MaskedLoad(Mask256<T> m, Full256<T> , |
| 2284 |
const T* HWY_RESTRICT p) { |
| 2285 |
auto pi = reinterpret_cast<const long long*>(p); |
| 2286 |
return Vec256<T>{_mm256_maskload_epi64(pi, m.raw)}; |
| 2287 |
} |
| 2288 |
|
| 2289 |
HWY_API Vec256<float> MaskedLoad(Mask256<float> m, Full256<float> d, |
| 2290 |
const float* HWY_RESTRICT p) { |
| 2291 |
const Vec256<int32_t> mi = |
| 2292 |
BitCast(RebindToSigned<decltype(d)>(), VecFromMask(d, m)); |
| 2293 |
return Vec256<float>{_mm256_maskload_ps(p, mi.raw)}; |
| 2294 |
} |
| 2295 |
|
| 2296 |
HWY_API Vec256<double> MaskedLoad(Mask256<double> m, Full256<double> d, |
| 2297 |
const double* HWY_RESTRICT p) { |
| 2298 |
const Vec256<int64_t> mi = |
| 2299 |
BitCast(RebindToSigned<decltype(d)>(), VecFromMask(d, m)); |
| 2300 |
return Vec256<double>{_mm256_maskload_pd(p, mi.raw)}; |
| 2301 |
} |
| 2302 |
|
| 2303 |
#endif |
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
template <typename T> |
| 2310 |
HWY_API Vec256<T> LoadDup128(Full256<T> , const T* HWY_RESTRICT p) { |
| 2311 |
#if HWY_COMPILER_MSVC && HWY_COMPILER_MSVC < 1931 |
| 2312 |
|
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
const __m128i v128 = LoadU(Full128<T>(), p).raw; |
| 2318 |
return Vec256<T>{ |
| 2319 |
_mm256_inserti128_si256(_mm256_castsi128_si256(v128), v128, 1)}; |
| 2320 |
#else |
| 2321 |
return Vec256<T>{_mm256_broadcastsi128_si256(LoadU(Full128<T>(), p).raw)}; |
| 2322 |
#endif |
| 2323 |
} |
| 2324 |
HWY_API Vec256<float> LoadDup128(Full256<float> , |
| 2325 |
const float* const HWY_RESTRICT p) { |
| 2326 |
#if HWY_COMPILER_MSVC && HWY_COMPILER_MSVC < 1931 |
| 2327 |
const __m128 v128 = LoadU(Full128<float>(), p).raw; |
| 2328 |
return Vec256<float>{ |
| 2329 |
_mm256_insertf128_ps(_mm256_castps128_ps256(v128), v128, 1)}; |
| 2330 |
#else |
| 2331 |
return Vec256<float>{_mm256_broadcast_ps(reinterpret_cast<const __m128*>(p))}; |
| 2332 |
#endif |
| 2333 |
} |
| 2334 |
HWY_API Vec256<double> LoadDup128(Full256<double> , |
| 2335 |
const double* const HWY_RESTRICT p) { |
| 2336 |
#if HWY_COMPILER_MSVC && HWY_COMPILER_MSVC < 1931 |
| 2337 |
const __m128d v128 = LoadU(Full128<double>(), p).raw; |
| 2338 |
return Vec256<double>{ |
| 2339 |
_mm256_insertf128_pd(_mm256_castpd128_pd256(v128), v128, 1)}; |
| 2340 |
#else |
| 2341 |
return Vec256<double>{ |
| 2342 |
_mm256_broadcast_pd(reinterpret_cast<const __m128d*>(p))}; |
| 2343 |
#endif |
| 2344 |
} |
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
template <typename T> |
| 2349 |
HWY_API void Store(Vec256<T> v, Full256<T> , T* HWY_RESTRICT aligned) { |
| 2350 |
_mm256_store_si256(reinterpret_cast<__m256i*>(aligned), v.raw); |
| 2351 |
} |
| 2352 |
HWY_API void Store(const Vec256<float> v, Full256<float> , |
| 2353 |
float* HWY_RESTRICT aligned) { |
| 2354 |
_mm256_store_ps(aligned, v.raw); |
| 2355 |
} |
| 2356 |
HWY_API void Store(const Vec256<double> v, Full256<double> , |
| 2357 |
double* HWY_RESTRICT aligned) { |
| 2358 |
_mm256_store_pd(aligned, v.raw); |
| 2359 |
} |
| 2360 |
|
| 2361 |
template <typename T> |
| 2362 |
HWY_API void StoreU(Vec256<T> v, Full256<T> , T* HWY_RESTRICT p) { |
| 2363 |
_mm256_storeu_si256(reinterpret_cast<__m256i*>(p), v.raw); |
| 2364 |
} |
| 2365 |
HWY_API void StoreU(const Vec256<float> v, Full256<float> , |
| 2366 |
float* HWY_RESTRICT p) { |
| 2367 |
_mm256_storeu_ps(p, v.raw); |
| 2368 |
} |
| 2369 |
HWY_API void StoreU(const Vec256<double> v, Full256<double> , |
| 2370 |
double* HWY_RESTRICT p) { |
| 2371 |
_mm256_storeu_pd(p, v.raw); |
| 2372 |
} |
| 2373 |
|
| 2374 |
|
| 2375 |
|
| 2376 |
#if HWY_TARGET <= HWY_AVX3 |
| 2377 |
|
| 2378 |
template <typename T, HWY_IF_LANE_SIZE(T, 1)> |
| 2379 |
HWY_API void BlendedStore(Vec256<T> v, Mask256<T> m, Full256<T> , |
| 2380 |
T* HWY_RESTRICT p) { |
| 2381 |
_mm256_mask_storeu_epi8(p, m.raw, v.raw); |
| 2382 |
} |
| 2383 |
|
| 2384 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 2385 |
HWY_API void BlendedStore(Vec256<T> v, Mask256<T> m, Full256<T> , |
| 2386 |
T* HWY_RESTRICT p) { |
| 2387 |
_mm256_mask_storeu_epi16(p, m.raw, v.raw); |
| 2388 |
} |
| 2389 |
|
| 2390 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 2391 |
HWY_API void BlendedStore(Vec256<T> v, Mask256<T> m, Full256<T> , |
| 2392 |
T* HWY_RESTRICT p) { |
| 2393 |
_mm256_mask_storeu_epi32(p, m.raw, v.raw); |
| 2394 |
} |
| 2395 |
|
| 2396 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 2397 |
HWY_API void BlendedStore(Vec256<T> v, Mask256<T> m, Full256<T> , |
| 2398 |
T* HWY_RESTRICT p) { |
| 2399 |
_mm256_mask_storeu_epi64(p, m.raw, v.raw); |
| 2400 |
} |
| 2401 |
|
| 2402 |
HWY_API void BlendedStore(Vec256<float> v, Mask256<float> m, |
| 2403 |
Full256<float> , float* HWY_RESTRICT p) { |
| 2404 |
_mm256_mask_storeu_ps(p, m.raw, v.raw); |
| 2405 |
} |
| 2406 |
|
| 2407 |
HWY_API void BlendedStore(Vec256<double> v, Mask256<double> m, |
| 2408 |
Full256<double> , double* HWY_RESTRICT p) { |
| 2409 |
_mm256_mask_storeu_pd(p, m.raw, v.raw); |
| 2410 |
} |
| 2411 |
|
| 2412 |
#else |
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
|
| 2423 |
template <typename T, hwy::EnableIf<sizeof(T) <= 2>* = nullptr> |
| 2424 |
HWY_API void BlendedStore(Vec256<T> v, Mask256<T> m, Full256<T> d, |
| 2425 |
T* HWY_RESTRICT p) { |
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
const RebindToUnsigned<decltype(d)> du; |
| 2430 |
using TU = TFromD<decltype(du)>; |
| 2431 |
alignas(32) TU buf[32 / sizeof(T)]; |
| 2432 |
alignas(32) TU mask[32 / sizeof(T)]; |
| 2433 |
Store(BitCast(du, v), du, buf); |
| 2434 |
Store(BitCast(du, VecFromMask(d, m)), du, mask); |
| 2435 |
for (size_t i = 0; i < 32 / sizeof(T); ++i) { |
| 2436 |
if (mask[i]) { |
| 2437 |
CopySameSize(buf + i, p + i); |
| 2438 |
} |
| 2439 |
} |
| 2440 |
} |
| 2441 |
|
| 2442 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 2443 |
HWY_API void BlendedStore(Vec256<T> v, Mask256<T> m, Full256<T> , |
| 2444 |
T* HWY_RESTRICT p) { |
| 2445 |
auto pi = reinterpret_cast<int*>(p); |
| 2446 |
_mm256_maskstore_epi32(pi, m.raw, v.raw); |
| 2447 |
} |
| 2448 |
|
| 2449 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 2450 |
HWY_API void BlendedStore(Vec256<T> v, Mask256<T> m, Full256<T> , |
| 2451 |
T* HWY_RESTRICT p) { |
| 2452 |
auto pi = reinterpret_cast<long long*>(p); |
| 2453 |
_mm256_maskstore_epi64(pi, m.raw, v.raw); |
| 2454 |
} |
| 2455 |
|
| 2456 |
HWY_API void BlendedStore(Vec256<float> v, Mask256<float> m, Full256<float> d, |
| 2457 |
float* HWY_RESTRICT p) { |
| 2458 |
const Vec256<int32_t> mi = |
| 2459 |
BitCast(RebindToSigned<decltype(d)>(), VecFromMask(d, m)); |
| 2460 |
_mm256_maskstore_ps(p, mi.raw, v.raw); |
| 2461 |
} |
| 2462 |
|
| 2463 |
HWY_API void BlendedStore(Vec256<double> v, Mask256<double> m, |
| 2464 |
Full256<double> d, double* HWY_RESTRICT p) { |
| 2465 |
const Vec256<int64_t> mi = |
| 2466 |
BitCast(RebindToSigned<decltype(d)>(), VecFromMask(d, m)); |
| 2467 |
_mm256_maskstore_pd(p, mi.raw, v.raw); |
| 2468 |
} |
| 2469 |
|
| 2470 |
#endif |
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
template <typename T> |
| 2475 |
HWY_API void Stream(Vec256<T> v, Full256<T> , |
| 2476 |
T* HWY_RESTRICT aligned) { |
| 2477 |
_mm256_stream_si256(reinterpret_cast<__m256i*>(aligned), v.raw); |
| 2478 |
} |
| 2479 |
HWY_API void Stream(const Vec256<float> v, Full256<float> , |
| 2480 |
float* HWY_RESTRICT aligned) { |
| 2481 |
_mm256_stream_ps(aligned, v.raw); |
| 2482 |
} |
| 2483 |
HWY_API void Stream(const Vec256<double> v, Full256<double> , |
| 2484 |
double* HWY_RESTRICT aligned) { |
| 2485 |
_mm256_stream_pd(aligned, v.raw); |
| 2486 |
} |
| 2487 |
|
| 2488 |
|
| 2489 |
|
| 2490 |
|
| 2491 |
HWY_DIAGNOSTICS(push) |
| 2492 |
HWY_DIAGNOSTICS_OFF(disable : 4245 4365, ignored "-Wsign-conversion") |
| 2493 |
|
| 2494 |
#if HWY_TARGET <= HWY_AVX3 |
| 2495 |
namespace detail { |
| 2496 |
|
| 2497 |
template <typename T> |
| 2498 |
HWY_INLINE void ScatterOffset(hwy::SizeTag<4> , Vec256<T> v, |
| 2499 |
Full256<T> , T* HWY_RESTRICT base, |
| 2500 |
const Vec256<int32_t> offset) { |
| 2501 |
_mm256_i32scatter_epi32(base, offset.raw, v.raw, 1); |
| 2502 |
} |
| 2503 |
template <typename T> |
| 2504 |
HWY_INLINE void ScatterIndex(hwy::SizeTag<4> , Vec256<T> v, |
| 2505 |
Full256<T> , T* HWY_RESTRICT base, |
| 2506 |
const Vec256<int32_t> index) { |
| 2507 |
_mm256_i32scatter_epi32(base, index.raw, v.raw, 4); |
| 2508 |
} |
| 2509 |
|
| 2510 |
template <typename T> |
| 2511 |
HWY_INLINE void ScatterOffset(hwy::SizeTag<8> , Vec256<T> v, |
| 2512 |
Full256<T> , T* HWY_RESTRICT base, |
| 2513 |
const Vec256<int64_t> offset) { |
| 2514 |
_mm256_i64scatter_epi64(base, offset.raw, v.raw, 1); |
| 2515 |
} |
| 2516 |
template <typename T> |
| 2517 |
HWY_INLINE void ScatterIndex(hwy::SizeTag<8> , Vec256<T> v, |
| 2518 |
Full256<T> , T* HWY_RESTRICT base, |
| 2519 |
const Vec256<int64_t> index) { |
| 2520 |
_mm256_i64scatter_epi64(base, index.raw, v.raw, 8); |
| 2521 |
} |
| 2522 |
|
| 2523 |
} |
| 2524 |
|
| 2525 |
template <typename T, typename Offset> |
| 2526 |
HWY_API void ScatterOffset(Vec256<T> v, Full256<T> d, T* HWY_RESTRICT base, |
| 2527 |
const Vec256<Offset> offset) { |
| 2528 |
static_assert(sizeof(T) == sizeof(Offset), "Must match for portability"); |
| 2529 |
return detail::ScatterOffset(hwy::SizeTag<sizeof(T)>(), v, d, base, offset); |
| 2530 |
} |
| 2531 |
template <typename T, typename Index> |
| 2532 |
HWY_API void ScatterIndex(Vec256<T> v, Full256<T> d, T* HWY_RESTRICT base, |
| 2533 |
const Vec256<Index> index) { |
| 2534 |
static_assert(sizeof(T) == sizeof(Index), "Must match for portability"); |
| 2535 |
return detail::ScatterIndex(hwy::SizeTag<sizeof(T)>(), v, d, base, index); |
| 2536 |
} |
| 2537 |
|
| 2538 |
HWY_API void ScatterOffset(Vec256<float> v, Full256<float> , |
| 2539 |
float* HWY_RESTRICT base, |
| 2540 |
const Vec256<int32_t> offset) { |
| 2541 |
_mm256_i32scatter_ps(base, offset.raw, v.raw, 1); |
| 2542 |
} |
| 2543 |
HWY_API void ScatterIndex(Vec256<float> v, Full256<float> , |
| 2544 |
float* HWY_RESTRICT base, |
| 2545 |
const Vec256<int32_t> index) { |
| 2546 |
_mm256_i32scatter_ps(base, index.raw, v.raw, 4); |
| 2547 |
} |
| 2548 |
|
| 2549 |
HWY_API void ScatterOffset(Vec256<double> v, Full256<double> , |
| 2550 |
double* HWY_RESTRICT base, |
| 2551 |
const Vec256<int64_t> offset) { |
| 2552 |
_mm256_i64scatter_pd(base, offset.raw, v.raw, 1); |
| 2553 |
} |
| 2554 |
HWY_API void ScatterIndex(Vec256<double> v, Full256<double> , |
| 2555 |
double* HWY_RESTRICT base, |
| 2556 |
const Vec256<int64_t> index) { |
| 2557 |
_mm256_i64scatter_pd(base, index.raw, v.raw, 8); |
| 2558 |
} |
| 2559 |
|
| 2560 |
#else |
| 2561 |
|
| 2562 |
template <typename T, typename Offset> |
| 2563 |
HWY_API void ScatterOffset(Vec256<T> v, Full256<T> d, T* HWY_RESTRICT base, |
| 2564 |
const Vec256<Offset> offset) { |
| 2565 |
static_assert(sizeof(T) == sizeof(Offset), "Must match for portability"); |
| 2566 |
|
| 2567 |
constexpr size_t N = 32 / sizeof(T); |
| 2568 |
alignas(32) T lanes[N]; |
| 2569 |
Store(v, d, lanes); |
| 2570 |
|
| 2571 |
alignas(32) Offset offset_lanes[N]; |
| 2572 |
Store(offset, Full256<Offset>(), offset_lanes); |
| 2573 |
|
| 2574 |
uint8_t* base_bytes = reinterpret_cast<uint8_t*>(base); |
| 2575 |
for (size_t i = 0; i < N; ++i) { |
| 2576 |
CopyBytes<sizeof(T)>(&lanes[i], base_bytes + offset_lanes[i]); |
| 2577 |
} |
| 2578 |
} |
| 2579 |
|
| 2580 |
template <typename T, typename Index> |
| 2581 |
HWY_API void ScatterIndex(Vec256<T> v, Full256<T> d, T* HWY_RESTRICT base, |
| 2582 |
const Vec256<Index> index) { |
| 2583 |
static_assert(sizeof(T) == sizeof(Index), "Must match for portability"); |
| 2584 |
|
| 2585 |
constexpr size_t N = 32 / sizeof(T); |
| 2586 |
alignas(32) T lanes[N]; |
| 2587 |
Store(v, d, lanes); |
| 2588 |
|
| 2589 |
alignas(32) Index index_lanes[N]; |
| 2590 |
Store(index, Full256<Index>(), index_lanes); |
| 2591 |
|
| 2592 |
for (size_t i = 0; i < N; ++i) { |
| 2593 |
base[index_lanes[i]] = lanes[i]; |
| 2594 |
} |
| 2595 |
} |
| 2596 |
|
| 2597 |
#endif |
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
namespace detail { |
| 2602 |
|
| 2603 |
template <typename T> |
| 2604 |
HWY_INLINE Vec256<T> GatherOffset(hwy::SizeTag<4> , |
| 2605 |
Full256<T> , |
| 2606 |
const T* HWY_RESTRICT base, |
| 2607 |
const Vec256<int32_t> offset) { |
| 2608 |
return Vec256<T>{_mm256_i32gather_epi32( |
| 2609 |
reinterpret_cast<const int32_t*>(base), offset.raw, 1)}; |
| 2610 |
} |
| 2611 |
template <typename T> |
| 2612 |
HWY_INLINE Vec256<T> GatherIndex(hwy::SizeTag<4> , |
| 2613 |
Full256<T> , |
| 2614 |
const T* HWY_RESTRICT base, |
| 2615 |
const Vec256<int32_t> index) { |
| 2616 |
return Vec256<T>{_mm256_i32gather_epi32( |
| 2617 |
reinterpret_cast<const int32_t*>(base), index.raw, 4)}; |
| 2618 |
} |
| 2619 |
|
| 2620 |
template <typename T> |
| 2621 |
HWY_INLINE Vec256<T> GatherOffset(hwy::SizeTag<8> , |
| 2622 |
Full256<T> , |
| 2623 |
const T* HWY_RESTRICT base, |
| 2624 |
const Vec256<int64_t> offset) { |
| 2625 |
return Vec256<T>{_mm256_i64gather_epi64( |
| 2626 |
reinterpret_cast<const GatherIndex64*>(base), offset.raw, 1)}; |
| 2627 |
} |
| 2628 |
template <typename T> |
| 2629 |
HWY_INLINE Vec256<T> GatherIndex(hwy::SizeTag<8> , |
| 2630 |
Full256<T> , |
| 2631 |
const T* HWY_RESTRICT base, |
| 2632 |
const Vec256<int64_t> index) { |
| 2633 |
return Vec256<T>{_mm256_i64gather_epi64( |
| 2634 |
reinterpret_cast<const GatherIndex64*>(base), index.raw, 8)}; |
| 2635 |
} |
| 2636 |
|
| 2637 |
} |
| 2638 |
|
| 2639 |
template <typename T, typename Offset> |
| 2640 |
HWY_API Vec256<T> GatherOffset(Full256<T> d, const T* HWY_RESTRICT base, |
| 2641 |
const Vec256<Offset> offset) { |
| 2642 |
static_assert(sizeof(T) == sizeof(Offset), "Must match for portability"); |
| 2643 |
return detail::GatherOffset(hwy::SizeTag<sizeof(T)>(), d, base, offset); |
| 2644 |
} |
| 2645 |
template <typename T, typename Index> |
| 2646 |
HWY_API Vec256<T> GatherIndex(Full256<T> d, const T* HWY_RESTRICT base, |
| 2647 |
const Vec256<Index> index) { |
| 2648 |
static_assert(sizeof(T) == sizeof(Index), "Must match for portability"); |
| 2649 |
return detail::GatherIndex(hwy::SizeTag<sizeof(T)>(), d, base, index); |
| 2650 |
} |
| 2651 |
|
| 2652 |
HWY_API Vec256<float> GatherOffset(Full256<float> , |
| 2653 |
const float* HWY_RESTRICT base, |
| 2654 |
const Vec256<int32_t> offset) { |
| 2655 |
return Vec256<float>{_mm256_i32gather_ps(base, offset.raw, 1)}; |
| 2656 |
} |
| 2657 |
HWY_API Vec256<float> GatherIndex(Full256<float> , |
| 2658 |
const float* HWY_RESTRICT base, |
| 2659 |
const Vec256<int32_t> index) { |
| 2660 |
return Vec256<float>{_mm256_i32gather_ps(base, index.raw, 4)}; |
| 2661 |
} |
| 2662 |
|
| 2663 |
HWY_API Vec256<double> GatherOffset(Full256<double> , |
| 2664 |
const double* HWY_RESTRICT base, |
| 2665 |
const Vec256<int64_t> offset) { |
| 2666 |
return Vec256<double>{_mm256_i64gather_pd(base, offset.raw, 1)}; |
| 2667 |
} |
| 2668 |
HWY_API Vec256<double> GatherIndex(Full256<double> , |
| 2669 |
const double* HWY_RESTRICT base, |
| 2670 |
const Vec256<int64_t> index) { |
| 2671 |
return Vec256<double>{_mm256_i64gather_pd(base, index.raw, 8)}; |
| 2672 |
} |
| 2673 |
|
| 2674 |
HWY_DIAGNOSTICS(pop) |
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
|
| 2679 |
|
| 2680 |
template <typename T> |
| 2681 |
HWY_API Vec128<T> LowerHalf(Full128<T> , Vec256<T> v) { |
| 2682 |
return Vec128<T>{_mm256_castsi256_si128(v.raw)}; |
| 2683 |
} |
| 2684 |
HWY_API Vec128<float> LowerHalf(Full128<float> , Vec256<float> v) { |
| 2685 |
return Vec128<float>{_mm256_castps256_ps128(v.raw)}; |
| 2686 |
} |
| 2687 |
HWY_API Vec128<double> LowerHalf(Full128<double> , Vec256<double> v) { |
| 2688 |
return Vec128<double>{_mm256_castpd256_pd128(v.raw)}; |
| 2689 |
} |
| 2690 |
|
| 2691 |
template <typename T> |
| 2692 |
HWY_API Vec128<T> LowerHalf(Vec256<T> v) { |
| 2693 |
return LowerHalf(Full128<T>(), v); |
| 2694 |
} |
| 2695 |
|
| 2696 |
|
| 2697 |
|
| 2698 |
template <typename T> |
| 2699 |
HWY_API Vec128<T> UpperHalf(Full128<T> , Vec256<T> v) { |
| 2700 |
return Vec128<T>{_mm256_extracti128_si256(v.raw, 1)}; |
| 2701 |
} |
| 2702 |
HWY_API Vec128<float> UpperHalf(Full128<float> , Vec256<float> v) { |
| 2703 |
return Vec128<float>{_mm256_extractf128_ps(v.raw, 1)}; |
| 2704 |
} |
| 2705 |
HWY_API Vec128<double> UpperHalf(Full128<double> , Vec256<double> v) { |
| 2706 |
return Vec128<double>{_mm256_extractf128_pd(v.raw, 1)}; |
| 2707 |
} |
| 2708 |
|
| 2709 |
|
| 2710 |
template <typename T> |
| 2711 |
HWY_API T ExtractLane(const Vec256<T> v, size_t i) { |
| 2712 |
const Full256<T> d; |
| 2713 |
HWY_DASSERT(i < Lanes(d)); |
| 2714 |
alignas(32) T lanes[32 / sizeof(T)]; |
| 2715 |
Store(v, d, lanes); |
| 2716 |
return lanes[i]; |
| 2717 |
} |
| 2718 |
|
| 2719 |
|
| 2720 |
template <typename T> |
| 2721 |
HWY_API Vec256<T> InsertLane(const Vec256<T> v, size_t i, T t) { |
| 2722 |
const Full256<T> d; |
| 2723 |
HWY_DASSERT(i < Lanes(d)); |
| 2724 |
alignas(64) T lanes[64 / sizeof(T)]; |
| 2725 |
Store(v, d, lanes); |
| 2726 |
lanes[i] = t; |
| 2727 |
return Load(d, lanes); |
| 2728 |
} |
| 2729 |
|
| 2730 |
|
| 2731 |
template <typename T> |
| 2732 |
HWY_API T GetLane(const Vec256<T> v) { |
| 2733 |
return GetLane(LowerHalf(v)); |
| 2734 |
} |
| 2735 |
|
| 2736 |
|
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
|
| 2748 |
|
| 2749 |
#if !defined(HWY_HAVE_ZEXT) |
| 2750 |
#if (HWY_COMPILER_MSVC && HWY_COMPILER_MSVC >= 1915) || \ |
| 2751 |
(HWY_COMPILER_CLANG && HWY_COMPILER_CLANG >= 500) || \ |
| 2752 |
(HWY_COMPILER_GCC_ACTUAL && HWY_COMPILER_GCC_ACTUAL >= 1000) |
| 2753 |
#define HWY_HAVE_ZEXT 1 |
| 2754 |
#else |
| 2755 |
#define HWY_HAVE_ZEXT 0 |
| 2756 |
#endif |
| 2757 |
#endif |
| 2758 |
|
| 2759 |
template <typename T> |
| 2760 |
HWY_API Vec256<T> ZeroExtendVector(Full256<T> , Vec128<T> lo) { |
| 2761 |
#if HWY_HAVE_ZEXT |
| 2762 |
return Vec256<T>{_mm256_zextsi128_si256(lo.raw)}; |
| 2763 |
#else |
| 2764 |
return Vec256<T>{_mm256_inserti128_si256(_mm256_setzero_si256(), lo.raw, 0)}; |
| 2765 |
#endif |
| 2766 |
} |
| 2767 |
HWY_API Vec256<float> ZeroExtendVector(Full256<float> , |
| 2768 |
Vec128<float> lo) { |
| 2769 |
#if HWY_HAVE_ZEXT |
| 2770 |
return Vec256<float>{_mm256_zextps128_ps256(lo.raw)}; |
| 2771 |
#else |
| 2772 |
return Vec256<float>{_mm256_insertf128_ps(_mm256_setzero_ps(), lo.raw, 0)}; |
| 2773 |
#endif |
| 2774 |
} |
| 2775 |
HWY_API Vec256<double> ZeroExtendVector(Full256<double> , |
| 2776 |
Vec128<double> lo) { |
| 2777 |
#if HWY_HAVE_ZEXT |
| 2778 |
return Vec256<double>{_mm256_zextpd128_pd256(lo.raw)}; |
| 2779 |
#else |
| 2780 |
return Vec256<double>{_mm256_insertf128_pd(_mm256_setzero_pd(), lo.raw, 0)}; |
| 2781 |
#endif |
| 2782 |
} |
| 2783 |
|
| 2784 |
|
| 2785 |
|
| 2786 |
template <typename T> |
| 2787 |
HWY_API Vec256<T> Combine(Full256<T> d, Vec128<T> hi, Vec128<T> lo) { |
| 2788 |
const auto lo256 = ZeroExtendVector(d, lo); |
| 2789 |
return Vec256<T>{_mm256_inserti128_si256(lo256.raw, hi.raw, 1)}; |
| 2790 |
} |
| 2791 |
HWY_API Vec256<float> Combine(Full256<float> d, Vec128<float> hi, |
| 2792 |
Vec128<float> lo) { |
| 2793 |
const auto lo256 = ZeroExtendVector(d, lo); |
| 2794 |
return Vec256<float>{_mm256_insertf128_ps(lo256.raw, hi.raw, 1)}; |
| 2795 |
} |
| 2796 |
HWY_API Vec256<double> Combine(Full256<double> d, Vec128<double> hi, |
| 2797 |
Vec128<double> lo) { |
| 2798 |
const auto lo256 = ZeroExtendVector(d, lo); |
| 2799 |
return Vec256<double>{_mm256_insertf128_pd(lo256.raw, hi.raw, 1)}; |
| 2800 |
} |
| 2801 |
|
| 2802 |
|
| 2803 |
|
| 2804 |
template <int kBytes, typename T> |
| 2805 |
HWY_API Vec256<T> ShiftLeftBytes(Full256<T> , const Vec256<T> v) { |
| 2806 |
static_assert(0 <= kBytes && kBytes <= 16, "Invalid kBytes"); |
| 2807 |
|
| 2808 |
return Vec256<T>{_mm256_slli_si256(v.raw, kBytes)}; |
| 2809 |
} |
| 2810 |
|
| 2811 |
template <int kBytes, typename T> |
| 2812 |
HWY_API Vec256<T> ShiftLeftBytes(const Vec256<T> v) { |
| 2813 |
return ShiftLeftBytes<kBytes>(Full256<T>(), v); |
| 2814 |
} |
| 2815 |
|
| 2816 |
|
| 2817 |
|
| 2818 |
template <int kLanes, typename T> |
| 2819 |
HWY_API Vec256<T> ShiftLeftLanes(Full256<T> d, const Vec256<T> v) { |
| 2820 |
const Repartition<uint8_t, decltype(d)> d8; |
| 2821 |
return BitCast(d, ShiftLeftBytes<kLanes * sizeof(T)>(BitCast(d8, v))); |
| 2822 |
} |
| 2823 |
|
| 2824 |
template <int kLanes, typename T> |
| 2825 |
HWY_API Vec256<T> ShiftLeftLanes(const Vec256<T> v) { |
| 2826 |
return ShiftLeftLanes<kLanes>(Full256<T>(), v); |
| 2827 |
} |
| 2828 |
|
| 2829 |
|
| 2830 |
|
| 2831 |
template <int kBytes, typename T> |
| 2832 |
HWY_API Vec256<T> ShiftRightBytes(Full256<T> , const Vec256<T> v) { |
| 2833 |
static_assert(0 <= kBytes && kBytes <= 16, "Invalid kBytes"); |
| 2834 |
|
| 2835 |
return Vec256<T>{_mm256_srli_si256(v.raw, kBytes)}; |
| 2836 |
} |
| 2837 |
|
| 2838 |
|
| 2839 |
template <int kLanes, typename T> |
| 2840 |
HWY_API Vec256<T> ShiftRightLanes(Full256<T> d, const Vec256<T> v) { |
| 2841 |
const Repartition<uint8_t, decltype(d)> d8; |
| 2842 |
return BitCast(d, ShiftRightBytes<kLanes * sizeof(T)>(d8, BitCast(d8, v))); |
| 2843 |
} |
| 2844 |
|
| 2845 |
|
| 2846 |
|
| 2847 |
|
| 2848 |
template <int kBytes, typename T, class V = Vec256<T>> |
| 2849 |
HWY_API V CombineShiftRightBytes(Full256<T> d, V hi, V lo) { |
| 2850 |
const Repartition<uint8_t, decltype(d)> d8; |
| 2851 |
return BitCast(d, Vec256<uint8_t>{_mm256_alignr_epi8( |
| 2852 |
BitCast(d8, hi).raw, BitCast(d8, lo).raw, kBytes)}); |
| 2853 |
} |
| 2854 |
|
| 2855 |
|
| 2856 |
|
| 2857 |
|
| 2858 |
template <int kLane> |
| 2859 |
HWY_API Vec256<uint16_t> Broadcast(const Vec256<uint16_t> v) { |
| 2860 |
static_assert(0 <= kLane && kLane < 8, "Invalid lane"); |
| 2861 |
if (kLane < 4) { |
| 2862 |
const __m256i lo = _mm256_shufflelo_epi16(v.raw, (0x55 * kLane) & 0xFF); |
| 2863 |
return Vec256<uint16_t>{_mm256_unpacklo_epi64(lo, lo)}; |
| 2864 |
} else { |
| 2865 |
const __m256i hi = |
| 2866 |
_mm256_shufflehi_epi16(v.raw, (0x55 * (kLane - 4)) & 0xFF); |
| 2867 |
return Vec256<uint16_t>{_mm256_unpackhi_epi64(hi, hi)}; |
| 2868 |
} |
| 2869 |
} |
| 2870 |
template <int kLane> |
| 2871 |
HWY_API Vec256<uint32_t> Broadcast(const Vec256<uint32_t> v) { |
| 2872 |
static_assert(0 <= kLane && kLane < 4, "Invalid lane"); |
| 2873 |
return Vec256<uint32_t>{_mm256_shuffle_epi32(v.raw, 0x55 * kLane)}; |
| 2874 |
} |
| 2875 |
template <int kLane> |
| 2876 |
HWY_API Vec256<uint64_t> Broadcast(const Vec256<uint64_t> v) { |
| 2877 |
static_assert(0 <= kLane && kLane < 2, "Invalid lane"); |
| 2878 |
return Vec256<uint64_t>{_mm256_shuffle_epi32(v.raw, kLane ? 0xEE : 0x44)}; |
| 2879 |
} |
| 2880 |
|
| 2881 |
|
| 2882 |
template <int kLane> |
| 2883 |
HWY_API Vec256<int16_t> Broadcast(const Vec256<int16_t> v) { |
| 2884 |
static_assert(0 <= kLane && kLane < 8, "Invalid lane"); |
| 2885 |
if (kLane < 4) { |
| 2886 |
const __m256i lo = _mm256_shufflelo_epi16(v.raw, (0x55 * kLane) & 0xFF); |
| 2887 |
return Vec256<int16_t>{_mm256_unpacklo_epi64(lo, lo)}; |
| 2888 |
} else { |
| 2889 |
const __m256i hi = |
| 2890 |
_mm256_shufflehi_epi16(v.raw, (0x55 * (kLane - 4)) & 0xFF); |
| 2891 |
return Vec256<int16_t>{_mm256_unpackhi_epi64(hi, hi)}; |
| 2892 |
} |
| 2893 |
} |
| 2894 |
template <int kLane> |
| 2895 |
HWY_API Vec256<int32_t> Broadcast(const Vec256<int32_t> v) { |
| 2896 |
static_assert(0 <= kLane && kLane < 4, "Invalid lane"); |
| 2897 |
return Vec256<int32_t>{_mm256_shuffle_epi32(v.raw, 0x55 * kLane)}; |
| 2898 |
} |
| 2899 |
template <int kLane> |
| 2900 |
HWY_API Vec256<int64_t> Broadcast(const Vec256<int64_t> v) { |
| 2901 |
static_assert(0 <= kLane && kLane < 2, "Invalid lane"); |
| 2902 |
return Vec256<int64_t>{_mm256_shuffle_epi32(v.raw, kLane ? 0xEE : 0x44)}; |
| 2903 |
} |
| 2904 |
|
| 2905 |
|
| 2906 |
template <int kLane> |
| 2907 |
HWY_API Vec256<float> Broadcast(Vec256<float> v) { |
| 2908 |
static_assert(0 <= kLane && kLane < 4, "Invalid lane"); |
| 2909 |
return Vec256<float>{_mm256_shuffle_ps(v.raw, v.raw, 0x55 * kLane)}; |
| 2910 |
} |
| 2911 |
template <int kLane> |
| 2912 |
HWY_API Vec256<double> Broadcast(const Vec256<double> v) { |
| 2913 |
static_assert(0 <= kLane && kLane < 2, "Invalid lane"); |
| 2914 |
return Vec256<double>{_mm256_shuffle_pd(v.raw, v.raw, 15 * kLane)}; |
| 2915 |
} |
| 2916 |
|
| 2917 |
|
| 2918 |
|
| 2919 |
|
| 2920 |
|
| 2921 |
|
| 2922 |
|
| 2923 |
|
| 2924 |
|
| 2925 |
|
| 2926 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 2927 |
HWY_API Vec256<T> Shuffle2301(const Vec256<T> v) { |
| 2928 |
return Vec256<T>{_mm256_shuffle_epi32(v.raw, 0xB1)}; |
| 2929 |
} |
| 2930 |
HWY_API Vec256<float> Shuffle2301(const Vec256<float> v) { |
| 2931 |
return Vec256<float>{_mm256_shuffle_ps(v.raw, v.raw, 0xB1)}; |
| 2932 |
} |
| 2933 |
|
| 2934 |
|
| 2935 |
namespace detail { |
| 2936 |
|
| 2937 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 2938 |
HWY_API Vec256<T> Shuffle2301(const Vec256<T> a, const Vec256<T> b) { |
| 2939 |
const Full256<T> d; |
| 2940 |
const RebindToFloat<decltype(d)> df; |
| 2941 |
constexpr int m = _MM_SHUFFLE(2, 3, 0, 1); |
| 2942 |
return BitCast(d, Vec256<float>{_mm256_shuffle_ps(BitCast(df, a).raw, |
| 2943 |
BitCast(df, b).raw, m)}); |
| 2944 |
} |
| 2945 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 2946 |
HWY_API Vec256<T> Shuffle1230(const Vec256<T> a, const Vec256<T> b) { |
| 2947 |
const Full256<T> d; |
| 2948 |
const RebindToFloat<decltype(d)> df; |
| 2949 |
constexpr int m = _MM_SHUFFLE(1, 2, 3, 0); |
| 2950 |
return BitCast(d, Vec256<float>{_mm256_shuffle_ps(BitCast(df, a).raw, |
| 2951 |
BitCast(df, b).raw, m)}); |
| 2952 |
} |
| 2953 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 2954 |
HWY_API Vec256<T> Shuffle3012(const Vec256<T> a, const Vec256<T> b) { |
| 2955 |
const Full256<T> d; |
| 2956 |
const RebindToFloat<decltype(d)> df; |
| 2957 |
constexpr int m = _MM_SHUFFLE(3, 0, 1, 2); |
| 2958 |
return BitCast(d, Vec256<float>{_mm256_shuffle_ps(BitCast(df, a).raw, |
| 2959 |
BitCast(df, b).raw, m)}); |
| 2960 |
} |
| 2961 |
|
| 2962 |
} |
| 2963 |
|
| 2964 |
|
| 2965 |
HWY_API Vec256<uint32_t> Shuffle1032(const Vec256<uint32_t> v) { |
| 2966 |
return Vec256<uint32_t>{_mm256_shuffle_epi32(v.raw, 0x4E)}; |
| 2967 |
} |
| 2968 |
HWY_API Vec256<int32_t> Shuffle1032(const Vec256<int32_t> v) { |
| 2969 |
return Vec256<int32_t>{_mm256_shuffle_epi32(v.raw, 0x4E)}; |
| 2970 |
} |
| 2971 |
HWY_API Vec256<float> Shuffle1032(const Vec256<float> v) { |
| 2972 |
|
| 2973 |
return Vec256<float>{_mm256_shuffle_ps(v.raw, v.raw, 0x4E)}; |
| 2974 |
} |
| 2975 |
HWY_API Vec256<uint64_t> Shuffle01(const Vec256<uint64_t> v) { |
| 2976 |
return Vec256<uint64_t>{_mm256_shuffle_epi32(v.raw, 0x4E)}; |
| 2977 |
} |
| 2978 |
HWY_API Vec256<int64_t> Shuffle01(const Vec256<int64_t> v) { |
| 2979 |
return Vec256<int64_t>{_mm256_shuffle_epi32(v.raw, 0x4E)}; |
| 2980 |
} |
| 2981 |
HWY_API Vec256<double> Shuffle01(const Vec256<double> v) { |
| 2982 |
|
| 2983 |
return Vec256<double>{_mm256_shuffle_pd(v.raw, v.raw, 5)}; |
| 2984 |
} |
| 2985 |
|
| 2986 |
|
| 2987 |
HWY_API Vec256<uint32_t> Shuffle0321(const Vec256<uint32_t> v) { |
| 2988 |
return Vec256<uint32_t>{_mm256_shuffle_epi32(v.raw, 0x39)}; |
| 2989 |
} |
| 2990 |
HWY_API Vec256<int32_t> Shuffle0321(const Vec256<int32_t> v) { |
| 2991 |
return Vec256<int32_t>{_mm256_shuffle_epi32(v.raw, 0x39)}; |
| 2992 |
} |
| 2993 |
HWY_API Vec256<float> Shuffle0321(const Vec256<float> v) { |
| 2994 |
return Vec256<float>{_mm256_shuffle_ps(v.raw, v.raw, 0x39)}; |
| 2995 |
} |
| 2996 |
|
| 2997 |
HWY_API Vec256<uint32_t> Shuffle2103(const Vec256<uint32_t> v) { |
| 2998 |
return Vec256<uint32_t>{_mm256_shuffle_epi32(v.raw, 0x93)}; |
| 2999 |
} |
| 3000 |
HWY_API Vec256<int32_t> Shuffle2103(const Vec256<int32_t> v) { |
| 3001 |
return Vec256<int32_t>{_mm256_shuffle_epi32(v.raw, 0x93)}; |
| 3002 |
} |
| 3003 |
HWY_API Vec256<float> Shuffle2103(const Vec256<float> v) { |
| 3004 |
return Vec256<float>{_mm256_shuffle_ps(v.raw, v.raw, 0x93)}; |
| 3005 |
} |
| 3006 |
|
| 3007 |
|
| 3008 |
HWY_API Vec256<uint32_t> Shuffle0123(const Vec256<uint32_t> v) { |
| 3009 |
return Vec256<uint32_t>{_mm256_shuffle_epi32(v.raw, 0x1B)}; |
| 3010 |
} |
| 3011 |
HWY_API Vec256<int32_t> Shuffle0123(const Vec256<int32_t> v) { |
| 3012 |
return Vec256<int32_t>{_mm256_shuffle_epi32(v.raw, 0x1B)}; |
| 3013 |
} |
| 3014 |
HWY_API Vec256<float> Shuffle0123(const Vec256<float> v) { |
| 3015 |
return Vec256<float>{_mm256_shuffle_ps(v.raw, v.raw, 0x1B)}; |
| 3016 |
} |
| 3017 |
|
| 3018 |
|
| 3019 |
|
| 3020 |
|
| 3021 |
template <typename T> |
| 3022 |
struct Indices256 { |
| 3023 |
__m256i raw; |
| 3024 |
}; |
| 3025 |
|
| 3026 |
|
| 3027 |
template <typename T, typename TI, HWY_IF_LANE_SIZE(T, 4)> |
| 3028 |
HWY_API Indices256<T> IndicesFromVec(Full256<T> , Vec256<TI> vec) { |
| 3029 |
static_assert(sizeof(T) == sizeof(TI), "Index size must match lane"); |
| 3030 |
#if HWY_IS_DEBUG_BUILD |
| 3031 |
const Full256<TI> di; |
| 3032 |
HWY_DASSERT(AllFalse(di, Lt(vec, Zero(di))) && |
| 3033 |
AllTrue(di, Lt(vec, Set(di, static_cast<TI>(32 / sizeof(T)))))); |
| 3034 |
#endif |
| 3035 |
return Indices256<T>{vec.raw}; |
| 3036 |
} |
| 3037 |
|
| 3038 |
|
| 3039 |
template <typename T, typename TI, HWY_IF_LANE_SIZE(T, 8)> |
| 3040 |
HWY_API Indices256<T> IndicesFromVec(Full256<T> d, Vec256<TI> idx64) { |
| 3041 |
static_assert(sizeof(T) == sizeof(TI), "Index size must match lane"); |
| 3042 |
const Rebind<TI, decltype(d)> di; |
| 3043 |
(void)di; |
| 3044 |
#if HWY_IS_DEBUG_BUILD |
| 3045 |
HWY_DASSERT(AllFalse(di, Lt(idx64, Zero(di))) && |
| 3046 |
AllTrue(di, Lt(idx64, Set(di, static_cast<TI>(32 / sizeof(T)))))); |
| 3047 |
#endif |
| 3048 |
|
| 3049 |
#if HWY_TARGET <= HWY_AVX3 |
| 3050 |
(void)d; |
| 3051 |
return Indices256<T>{idx64.raw}; |
| 3052 |
#else |
| 3053 |
const Repartition<float, decltype(d)> df; |
| 3054 |
|
| 3055 |
const Vec256<TI> dup = |
| 3056 |
BitCast(di, Vec256<float>{_mm256_moveldup_ps(BitCast(df, idx64).raw)}); |
| 3057 |
|
| 3058 |
const Vec256<TI> idx32 = dup + dup + Set(di, TI(1) << 32); |
| 3059 |
return Indices256<T>{idx32.raw}; |
| 3060 |
#endif |
| 3061 |
} |
| 3062 |
|
| 3063 |
template <typename T, typename TI> |
| 3064 |
HWY_API Indices256<T> SetTableIndices(const Full256<T> d, const TI* idx) { |
| 3065 |
const Rebind<TI, decltype(d)> di; |
| 3066 |
return IndicesFromVec(d, LoadU(di, idx)); |
| 3067 |
} |
| 3068 |
|
| 3069 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 3070 |
HWY_API Vec256<T> TableLookupLanes(Vec256<T> v, Indices256<T> idx) { |
| 3071 |
return Vec256<T>{_mm256_permutevar8x32_epi32(v.raw, idx.raw)}; |
| 3072 |
} |
| 3073 |
|
| 3074 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 3075 |
HWY_API Vec256<T> TableLookupLanes(Vec256<T> v, Indices256<T> idx) { |
| 3076 |
#if HWY_TARGET <= HWY_AVX3 |
| 3077 |
return Vec256<T>{_mm256_permutexvar_epi64(idx.raw, v.raw)}; |
| 3078 |
#else |
| 3079 |
return Vec256<T>{_mm256_permutevar8x32_epi32(v.raw, idx.raw)}; |
| 3080 |
#endif |
| 3081 |
} |
| 3082 |
|
| 3083 |
HWY_API Vec256<float> TableLookupLanes(const Vec256<float> v, |
| 3084 |
const Indices256<float> idx) { |
| 3085 |
return Vec256<float>{_mm256_permutevar8x32_ps(v.raw, idx.raw)}; |
| 3086 |
} |
| 3087 |
|
| 3088 |
HWY_API Vec256<double> TableLookupLanes(const Vec256<double> v, |
| 3089 |
const Indices256<double> idx) { |
| 3090 |
#if HWY_TARGET <= HWY_AVX3 |
| 3091 |
return Vec256<double>{_mm256_permutexvar_pd(idx.raw, v.raw)}; |
| 3092 |
#else |
| 3093 |
const Full256<double> df; |
| 3094 |
const Full256<uint64_t> du; |
| 3095 |
return BitCast(df, Vec256<uint64_t>{_mm256_permutevar8x32_epi32( |
| 3096 |
BitCast(du, v).raw, idx.raw)}); |
| 3097 |
#endif |
| 3098 |
} |
| 3099 |
|
| 3100 |
|
| 3101 |
|
| 3102 |
template <typename T> |
| 3103 |
HWY_API Vec256<T> SwapAdjacentBlocks(Vec256<T> v) { |
| 3104 |
return Vec256<T>{_mm256_permute2x128_si256(v.raw, v.raw, 0x01)}; |
| 3105 |
} |
| 3106 |
|
| 3107 |
HWY_API Vec256<float> SwapAdjacentBlocks(Vec256<float> v) { |
| 3108 |
return Vec256<float>{_mm256_permute2f128_ps(v.raw, v.raw, 0x01)}; |
| 3109 |
} |
| 3110 |
|
| 3111 |
HWY_API Vec256<double> SwapAdjacentBlocks(Vec256<double> v) { |
| 3112 |
return Vec256<double>{_mm256_permute2f128_pd(v.raw, v.raw, 0x01)}; |
| 3113 |
} |
| 3114 |
|
| 3115 |
|
| 3116 |
|
| 3117 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 3118 |
HWY_API Vec256<T> Reverse(Full256<T> d, const Vec256<T> v) { |
| 3119 |
alignas(32) constexpr int32_t kReverse[8] = {7, 6, 5, 4, 3, 2, 1, 0}; |
| 3120 |
return TableLookupLanes(v, SetTableIndices(d, kReverse)); |
| 3121 |
} |
| 3122 |
|
| 3123 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 3124 |
HWY_API Vec256<T> Reverse(Full256<T> d, const Vec256<T> v) { |
| 3125 |
alignas(32) constexpr int64_t kReverse[4] = {3, 2, 1, 0}; |
| 3126 |
return TableLookupLanes(v, SetTableIndices(d, kReverse)); |
| 3127 |
} |
| 3128 |
|
| 3129 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 3130 |
HWY_API Vec256<T> Reverse(Full256<T> d, const Vec256<T> v) { |
| 3131 |
#if HWY_TARGET <= HWY_AVX3 |
| 3132 |
const RebindToSigned<decltype(d)> di; |
| 3133 |
alignas(32) constexpr int16_t kReverse[16] = {15, 14, 13, 12, 11, 10, 9, 8, |
| 3134 |
7, 6, 5, 4, 3, 2, 1, 0}; |
| 3135 |
const Vec256<int16_t> idx = Load(di, kReverse); |
| 3136 |
return BitCast(d, Vec256<int16_t>{ |
| 3137 |
_mm256_permutexvar_epi16(idx.raw, BitCast(di, v).raw)}); |
| 3138 |
#else |
| 3139 |
const RepartitionToWide<RebindToUnsigned<decltype(d)>> du32; |
| 3140 |
const Vec256<uint32_t> rev32 = Reverse(du32, BitCast(du32, v)); |
| 3141 |
return BitCast(d, RotateRight<16>(rev32)); |
| 3142 |
#endif |
| 3143 |
} |
| 3144 |
|
| 3145 |
|
| 3146 |
|
| 3147 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 3148 |
HWY_API Vec256<T> Reverse2(Full256<T> d, const Vec256<T> v) { |
| 3149 |
const Full256<uint32_t> du32; |
| 3150 |
return BitCast(d, RotateRight<16>(BitCast(du32, v))); |
| 3151 |
} |
| 3152 |
|
| 3153 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 3154 |
HWY_API Vec256<T> Reverse2(Full256<T> , const Vec256<T> v) { |
| 3155 |
return Shuffle2301(v); |
| 3156 |
} |
| 3157 |
|
| 3158 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 3159 |
HWY_API Vec256<T> Reverse2(Full256<T> , const Vec256<T> v) { |
| 3160 |
return Shuffle01(v); |
| 3161 |
} |
| 3162 |
|
| 3163 |
|
| 3164 |
|
| 3165 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 3166 |
HWY_API Vec256<T> Reverse4(Full256<T> d, const Vec256<T> v) { |
| 3167 |
#if HWY_TARGET <= HWY_AVX3 |
| 3168 |
const RebindToSigned<decltype(d)> di; |
| 3169 |
alignas(32) constexpr int16_t kReverse4[16] = {3, 2, 1, 0, 7, 6, 5, 4, |
| 3170 |
11, 10, 9, 8, 15, 14, 13, 12}; |
| 3171 |
const Vec256<int16_t> idx = Load(di, kReverse4); |
| 3172 |
return BitCast(d, Vec256<int16_t>{ |
| 3173 |
_mm256_permutexvar_epi16(idx.raw, BitCast(di, v).raw)}); |
| 3174 |
#else |
| 3175 |
const RepartitionToWide<decltype(d)> dw; |
| 3176 |
return Reverse2(d, BitCast(d, Shuffle2301(BitCast(dw, v)))); |
| 3177 |
#endif |
| 3178 |
} |
| 3179 |
|
| 3180 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 3181 |
HWY_API Vec256<T> Reverse4(Full256<T> , const Vec256<T> v) { |
| 3182 |
return Shuffle0123(v); |
| 3183 |
} |
| 3184 |
|
| 3185 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 3186 |
HWY_API Vec256<T> Reverse4(Full256<T> , const Vec256<T> v) { |
| 3187 |
|
| 3188 |
return SwapAdjacentBlocks(Shuffle01(v)); |
| 3189 |
} |
| 3190 |
|
| 3191 |
|
| 3192 |
|
| 3193 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 3194 |
HWY_API Vec256<T> Reverse8(Full256<T> d, const Vec256<T> v) { |
| 3195 |
#if HWY_TARGET <= HWY_AVX3 |
| 3196 |
const RebindToSigned<decltype(d)> di; |
| 3197 |
alignas(32) constexpr int16_t kReverse8[16] = {7, 6, 5, 4, 3, 2, 1, 0, |
| 3198 |
15, 14, 13, 12, 11, 10, 9, 8}; |
| 3199 |
const Vec256<int16_t> idx = Load(di, kReverse8); |
| 3200 |
return BitCast(d, Vec256<int16_t>{ |
| 3201 |
_mm256_permutexvar_epi16(idx.raw, BitCast(di, v).raw)}); |
| 3202 |
#else |
| 3203 |
const RepartitionToWide<decltype(d)> dw; |
| 3204 |
return Reverse2(d, BitCast(d, Shuffle0123(BitCast(dw, v)))); |
| 3205 |
#endif |
| 3206 |
} |
| 3207 |
|
| 3208 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 3209 |
HWY_API Vec256<T> Reverse8(Full256<T> d, const Vec256<T> v) { |
| 3210 |
return Reverse(d, v); |
| 3211 |
} |
| 3212 |
|
| 3213 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 3214 |
HWY_API Vec256<T> Reverse8(Full256<T> , const Vec256<T> ) { |
| 3215 |
HWY_ASSERT(0); |
| 3216 |
} |
| 3217 |
|
| 3218 |
|
| 3219 |
|
| 3220 |
|
| 3221 |
|
| 3222 |
|
| 3223 |
|
| 3224 |
HWY_API Vec256<uint8_t> InterleaveLower(const Vec256<uint8_t> a, |
| 3225 |
const Vec256<uint8_t> b) { |
| 3226 |
return Vec256<uint8_t>{_mm256_unpacklo_epi8(a.raw, b.raw)}; |
| 3227 |
} |
| 3228 |
HWY_API Vec256<uint16_t> InterleaveLower(const Vec256<uint16_t> a, |
| 3229 |
const Vec256<uint16_t> b) { |
| 3230 |
return Vec256<uint16_t>{_mm256_unpacklo_epi16(a.raw, b.raw)}; |
| 3231 |
} |
| 3232 |
HWY_API Vec256<uint32_t> InterleaveLower(const Vec256<uint32_t> a, |
| 3233 |
const Vec256<uint32_t> b) { |
| 3234 |
return Vec256<uint32_t>{_mm256_unpacklo_epi32(a.raw, b.raw)}; |
| 3235 |
} |
| 3236 |
HWY_API Vec256<uint64_t> InterleaveLower(const Vec256<uint64_t> a, |
| 3237 |
const Vec256<uint64_t> b) { |
| 3238 |
return Vec256<uint64_t>{_mm256_unpacklo_epi64(a.raw, b.raw)}; |
| 3239 |
} |
| 3240 |
|
| 3241 |
HWY_API Vec256<int8_t> InterleaveLower(const Vec256<int8_t> a, |
| 3242 |
const Vec256<int8_t> b) { |
| 3243 |
return Vec256<int8_t>{_mm256_unpacklo_epi8(a.raw, b.raw)}; |
| 3244 |
} |
| 3245 |
HWY_API Vec256<int16_t> InterleaveLower(const Vec256<int16_t> a, |
| 3246 |
const Vec256<int16_t> b) { |
| 3247 |
return Vec256<int16_t>{_mm256_unpacklo_epi16(a.raw, b.raw)}; |
| 3248 |
} |
| 3249 |
HWY_API Vec256<int32_t> InterleaveLower(const Vec256<int32_t> a, |
| 3250 |
const Vec256<int32_t> b) { |
| 3251 |
return Vec256<int32_t>{_mm256_unpacklo_epi32(a.raw, b.raw)}; |
| 3252 |
} |
| 3253 |
HWY_API Vec256<int64_t> InterleaveLower(const Vec256<int64_t> a, |
| 3254 |
const Vec256<int64_t> b) { |
| 3255 |
return Vec256<int64_t>{_mm256_unpacklo_epi64(a.raw, b.raw)}; |
| 3256 |
} |
| 3257 |
|
| 3258 |
HWY_API Vec256<float> InterleaveLower(const Vec256<float> a, |
| 3259 |
const Vec256<float> b) { |
| 3260 |
return Vec256<float>{_mm256_unpacklo_ps(a.raw, b.raw)}; |
| 3261 |
} |
| 3262 |
HWY_API Vec256<double> InterleaveLower(const Vec256<double> a, |
| 3263 |
const Vec256<double> b) { |
| 3264 |
return Vec256<double>{_mm256_unpacklo_pd(a.raw, b.raw)}; |
| 3265 |
} |
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
|
| 3270 |
namespace detail { |
| 3271 |
|
| 3272 |
HWY_API Vec256<uint8_t> InterleaveUpper(const Vec256<uint8_t> a, |
| 3273 |
const Vec256<uint8_t> b) { |
| 3274 |
return Vec256<uint8_t>{_mm256_unpackhi_epi8(a.raw, b.raw)}; |
| 3275 |
} |
| 3276 |
HWY_API Vec256<uint16_t> InterleaveUpper(const Vec256<uint16_t> a, |
| 3277 |
const Vec256<uint16_t> b) { |
| 3278 |
return Vec256<uint16_t>{_mm256_unpackhi_epi16(a.raw, b.raw)}; |
| 3279 |
} |
| 3280 |
HWY_API Vec256<uint32_t> InterleaveUpper(const Vec256<uint32_t> a, |
| 3281 |
const Vec256<uint32_t> b) { |
| 3282 |
return Vec256<uint32_t>{_mm256_unpackhi_epi32(a.raw, b.raw)}; |
| 3283 |
} |
| 3284 |
HWY_API Vec256<uint64_t> InterleaveUpper(const Vec256<uint64_t> a, |
| 3285 |
const Vec256<uint64_t> b) { |
| 3286 |
return Vec256<uint64_t>{_mm256_unpackhi_epi64(a.raw, b.raw)}; |
| 3287 |
} |
| 3288 |
|
| 3289 |
HWY_API Vec256<int8_t> InterleaveUpper(const Vec256<int8_t> a, |
| 3290 |
const Vec256<int8_t> b) { |
| 3291 |
return Vec256<int8_t>{_mm256_unpackhi_epi8(a.raw, b.raw)}; |
| 3292 |
} |
| 3293 |
HWY_API Vec256<int16_t> InterleaveUpper(const Vec256<int16_t> a, |
| 3294 |
const Vec256<int16_t> b) { |
| 3295 |
return Vec256<int16_t>{_mm256_unpackhi_epi16(a.raw, b.raw)}; |
| 3296 |
} |
| 3297 |
HWY_API Vec256<int32_t> InterleaveUpper(const Vec256<int32_t> a, |
| 3298 |
const Vec256<int32_t> b) { |
| 3299 |
return Vec256<int32_t>{_mm256_unpackhi_epi32(a.raw, b.raw)}; |
| 3300 |
} |
| 3301 |
HWY_API Vec256<int64_t> InterleaveUpper(const Vec256<int64_t> a, |
| 3302 |
const Vec256<int64_t> b) { |
| 3303 |
return Vec256<int64_t>{_mm256_unpackhi_epi64(a.raw, b.raw)}; |
| 3304 |
} |
| 3305 |
|
| 3306 |
HWY_API Vec256<float> InterleaveUpper(const Vec256<float> a, |
| 3307 |
const Vec256<float> b) { |
| 3308 |
return Vec256<float>{_mm256_unpackhi_ps(a.raw, b.raw)}; |
| 3309 |
} |
| 3310 |
HWY_API Vec256<double> InterleaveUpper(const Vec256<double> a, |
| 3311 |
const Vec256<double> b) { |
| 3312 |
return Vec256<double>{_mm256_unpackhi_pd(a.raw, b.raw)}; |
| 3313 |
} |
| 3314 |
|
| 3315 |
} |
| 3316 |
|
| 3317 |
template <typename T, class V = Vec256<T>> |
| 3318 |
HWY_API V InterleaveUpper(Full256<T> , V a, V b) { |
| 3319 |
return detail::InterleaveUpper(a, b); |
| 3320 |
} |
| 3321 |
|
| 3322 |
|
| 3323 |
|
| 3324 |
|
| 3325 |
|
| 3326 |
template <typename T, typename TW = MakeWide<T>> |
| 3327 |
HWY_API Vec256<TW> ZipLower(Vec256<T> a, Vec256<T> b) { |
| 3328 |
return BitCast(Full256<TW>(), InterleaveLower(a, b)); |
| 3329 |
} |
| 3330 |
template <typename T, typename TW = MakeWide<T>> |
| 3331 |
HWY_API Vec256<TW> ZipLower(Full256<TW> dw, Vec256<T> a, Vec256<T> b) { |
| 3332 |
return BitCast(dw, InterleaveLower(a, b)); |
| 3333 |
} |
| 3334 |
|
| 3335 |
template <typename T, typename TW = MakeWide<T>> |
| 3336 |
HWY_API Vec256<TW> ZipUpper(Full256<TW> dw, Vec256<T> a, Vec256<T> b) { |
| 3337 |
return BitCast(dw, InterleaveUpper(Full256<T>(), a, b)); |
| 3338 |
} |
| 3339 |
|
| 3340 |
|
| 3341 |
|
| 3342 |
|
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
template <typename T> |
| 3348 |
HWY_API Vec256<T> ConcatLowerLower(Full256<T> d, const Vec256<T> hi, |
| 3349 |
const Vec256<T> lo) { |
| 3350 |
const Half<decltype(d)> d2; |
| 3351 |
return Vec256<T>{_mm256_inserti128_si256(lo.raw, LowerHalf(d2, hi).raw, 1)}; |
| 3352 |
} |
| 3353 |
HWY_API Vec256<float> ConcatLowerLower(Full256<float> d, const Vec256<float> hi, |
| 3354 |
const Vec256<float> lo) { |
| 3355 |
const Half<decltype(d)> d2; |
| 3356 |
return Vec256<float>{_mm256_insertf128_ps(lo.raw, LowerHalf(d2, hi).raw, 1)}; |
| 3357 |
} |
| 3358 |
HWY_API Vec256<double> ConcatLowerLower(Full256<double> d, |
| 3359 |
const Vec256<double> hi, |
| 3360 |
const Vec256<double> lo) { |
| 3361 |
const Half<decltype(d)> d2; |
| 3362 |
return Vec256<double>{_mm256_insertf128_pd(lo.raw, LowerHalf(d2, hi).raw, 1)}; |
| 3363 |
} |
| 3364 |
|
| 3365 |
|
| 3366 |
template <typename T> |
| 3367 |
HWY_API Vec256<T> ConcatLowerUpper(Full256<T> , const Vec256<T> hi, |
| 3368 |
const Vec256<T> lo) { |
| 3369 |
return Vec256<T>{_mm256_permute2x128_si256(lo.raw, hi.raw, 0x21)}; |
| 3370 |
} |
| 3371 |
HWY_API Vec256<float> ConcatLowerUpper(Full256<float> , |
| 3372 |
const Vec256<float> hi, |
| 3373 |
const Vec256<float> lo) { |
| 3374 |
return Vec256<float>{_mm256_permute2f128_ps(lo.raw, hi.raw, 0x21)}; |
| 3375 |
} |
| 3376 |
HWY_API Vec256<double> ConcatLowerUpper(Full256<double> , |
| 3377 |
const Vec256<double> hi, |
| 3378 |
const Vec256<double> lo) { |
| 3379 |
return Vec256<double>{_mm256_permute2f128_pd(lo.raw, hi.raw, 0x21)}; |
| 3380 |
} |
| 3381 |
|
| 3382 |
|
| 3383 |
template <typename T> |
| 3384 |
HWY_API Vec256<T> ConcatUpperLower(Full256<T> , const Vec256<T> hi, |
| 3385 |
const Vec256<T> lo) { |
| 3386 |
return Vec256<T>{_mm256_blend_epi32(hi.raw, lo.raw, 0x0F)}; |
| 3387 |
} |
| 3388 |
HWY_API Vec256<float> ConcatUpperLower(Full256<float> , |
| 3389 |
const Vec256<float> hi, |
| 3390 |
const Vec256<float> lo) { |
| 3391 |
return Vec256<float>{_mm256_blend_ps(hi.raw, lo.raw, 0x0F)}; |
| 3392 |
} |
| 3393 |
HWY_API Vec256<double> ConcatUpperLower(Full256<double> , |
| 3394 |
const Vec256<double> hi, |
| 3395 |
const Vec256<double> lo) { |
| 3396 |
return Vec256<double>{_mm256_blend_pd(hi.raw, lo.raw, 3)}; |
| 3397 |
} |
| 3398 |
|
| 3399 |
|
| 3400 |
template <typename T> |
| 3401 |
HWY_API Vec256<T> ConcatUpperUpper(Full256<T> , const Vec256<T> hi, |
| 3402 |
const Vec256<T> lo) { |
| 3403 |
return Vec256<T>{_mm256_permute2x128_si256(lo.raw, hi.raw, 0x31)}; |
| 3404 |
} |
| 3405 |
HWY_API Vec256<float> ConcatUpperUpper(Full256<float> , |
| 3406 |
const Vec256<float> hi, |
| 3407 |
const Vec256<float> lo) { |
| 3408 |
return Vec256<float>{_mm256_permute2f128_ps(lo.raw, hi.raw, 0x31)}; |
| 3409 |
} |
| 3410 |
HWY_API Vec256<double> ConcatUpperUpper(Full256<double> , |
| 3411 |
const Vec256<double> hi, |
| 3412 |
const Vec256<double> lo) { |
| 3413 |
return Vec256<double>{_mm256_permute2f128_pd(lo.raw, hi.raw, 0x31)}; |
| 3414 |
} |
| 3415 |
|
| 3416 |
|
| 3417 |
|
| 3418 |
template <typename T, HWY_IF_LANE_SIZE(T, 1)> |
| 3419 |
HWY_API Vec256<T> ConcatOdd(Full256<T> d, Vec256<T> hi, Vec256<T> lo) { |
| 3420 |
const RebindToUnsigned<decltype(d)> du; |
| 3421 |
#if HWY_TARGET == HWY_AVX3_DL |
| 3422 |
alignas(32) constexpr uint8_t kIdx[32] = { |
| 3423 |
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, |
| 3424 |
33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63}; |
| 3425 |
return BitCast(d, Vec256<uint16_t>{_mm256_mask2_permutex2var_epi8( |
| 3426 |
BitCast(du, lo).raw, Load(du, kIdx).raw, |
| 3427 |
__mmask32{0xFFFFFFFFu}, BitCast(du, hi).raw)}); |
| 3428 |
#else |
| 3429 |
const RepartitionToWide<decltype(du)> dw; |
| 3430 |
|
| 3431 |
const Vec256<uint16_t> uH = ShiftRight<8>(BitCast(dw, hi)); |
| 3432 |
const Vec256<uint16_t> uL = ShiftRight<8>(BitCast(dw, lo)); |
| 3433 |
const __m256i u8 = _mm256_packus_epi16(uL.raw, uH.raw); |
| 3434 |
return Vec256<T>{_mm256_permute4x64_epi64(u8, _MM_SHUFFLE(3, 1, 2, 0))}; |
| 3435 |
#endif |
| 3436 |
} |
| 3437 |
|
| 3438 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 3439 |
HWY_API Vec256<T> ConcatOdd(Full256<T> d, Vec256<T> hi, Vec256<T> lo) { |
| 3440 |
const RebindToUnsigned<decltype(d)> du; |
| 3441 |
#if HWY_TARGET <= HWY_AVX3 |
| 3442 |
alignas(32) constexpr uint16_t kIdx[16] = {1, 3, 5, 7, 9, 11, 13, 15, |
| 3443 |
17, 19, 21, 23, 25, 27, 29, 31}; |
| 3444 |
return BitCast(d, Vec256<uint16_t>{_mm256_mask2_permutex2var_epi16( |
| 3445 |
BitCast(du, lo).raw, Load(du, kIdx).raw, |
| 3446 |
__mmask16{0xFFFF}, BitCast(du, hi).raw)}); |
| 3447 |
#else |
| 3448 |
const RepartitionToWide<decltype(du)> dw; |
| 3449 |
|
| 3450 |
const Vec256<uint32_t> uH = ShiftRight<16>(BitCast(dw, hi)); |
| 3451 |
const Vec256<uint32_t> uL = ShiftRight<16>(BitCast(dw, lo)); |
| 3452 |
const __m256i u16 = _mm256_packus_epi32(uL.raw, uH.raw); |
| 3453 |
return Vec256<T>{_mm256_permute4x64_epi64(u16, _MM_SHUFFLE(3, 1, 2, 0))}; |
| 3454 |
#endif |
| 3455 |
} |
| 3456 |
|
| 3457 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 3458 |
HWY_API Vec256<T> ConcatOdd(Full256<T> d, Vec256<T> hi, Vec256<T> lo) { |
| 3459 |
const RebindToUnsigned<decltype(d)> du; |
| 3460 |
#if HWY_TARGET <= HWY_AVX3 |
| 3461 |
alignas(32) constexpr uint32_t kIdx[8] = {1, 3, 5, 7, 9, 11, 13, 15}; |
| 3462 |
return BitCast(d, Vec256<uint32_t>{_mm256_mask2_permutex2var_epi32( |
| 3463 |
BitCast(du, lo).raw, Load(du, kIdx).raw, __mmask8{0xFF}, |
| 3464 |
BitCast(du, hi).raw)}); |
| 3465 |
#else |
| 3466 |
const RebindToFloat<decltype(d)> df; |
| 3467 |
const Vec256<float> v3131{_mm256_shuffle_ps( |
| 3468 |
BitCast(df, lo).raw, BitCast(df, hi).raw, _MM_SHUFFLE(3, 1, 3, 1))}; |
| 3469 |
return Vec256<T>{_mm256_permute4x64_epi64(BitCast(du, v3131).raw, |
| 3470 |
_MM_SHUFFLE(3, 1, 2, 0))}; |
| 3471 |
#endif |
| 3472 |
} |
| 3473 |
|
| 3474 |
HWY_API Vec256<float> ConcatOdd(Full256<float> d, Vec256<float> hi, |
| 3475 |
Vec256<float> lo) { |
| 3476 |
const RebindToUnsigned<decltype(d)> du; |
| 3477 |
#if HWY_TARGET <= HWY_AVX3 |
| 3478 |
alignas(32) constexpr uint32_t kIdx[8] = {1, 3, 5, 7, 9, 11, 13, 15}; |
| 3479 |
return Vec256<float>{_mm256_mask2_permutex2var_ps(lo.raw, Load(du, kIdx).raw, |
| 3480 |
__mmask8{0xFF}, hi.raw)}; |
| 3481 |
#else |
| 3482 |
const Vec256<float> v3131{ |
| 3483 |
_mm256_shuffle_ps(lo.raw, hi.raw, _MM_SHUFFLE(3, 1, 3, 1))}; |
| 3484 |
return BitCast(d, Vec256<uint32_t>{_mm256_permute4x64_epi64( |
| 3485 |
BitCast(du, v3131).raw, _MM_SHUFFLE(3, 1, 2, 0))}); |
| 3486 |
#endif |
| 3487 |
} |
| 3488 |
|
| 3489 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 3490 |
HWY_API Vec256<T> ConcatOdd(Full256<T> d, Vec256<T> hi, Vec256<T> lo) { |
| 3491 |
const RebindToUnsigned<decltype(d)> du; |
| 3492 |
#if HWY_TARGET <= HWY_AVX3 |
| 3493 |
alignas(64) constexpr uint64_t kIdx[4] = {1, 3, 5, 7}; |
| 3494 |
return BitCast(d, Vec256<uint64_t>{_mm256_mask2_permutex2var_epi64( |
| 3495 |
BitCast(du, lo).raw, Load(du, kIdx).raw, __mmask8{0xFF}, |
| 3496 |
BitCast(du, hi).raw)}); |
| 3497 |
#else |
| 3498 |
const RebindToFloat<decltype(d)> df; |
| 3499 |
const Vec256<double> v31{ |
| 3500 |
_mm256_shuffle_pd(BitCast(df, lo).raw, BitCast(df, hi).raw, 15)}; |
| 3501 |
return Vec256<T>{ |
| 3502 |
_mm256_permute4x64_epi64(BitCast(du, v31).raw, _MM_SHUFFLE(3, 1, 2, 0))}; |
| 3503 |
#endif |
| 3504 |
} |
| 3505 |
|
| 3506 |
HWY_API Vec256<double> ConcatOdd(Full256<double> d, Vec256<double> hi, |
| 3507 |
Vec256<double> lo) { |
| 3508 |
#if HWY_TARGET <= HWY_AVX3 |
| 3509 |
const RebindToUnsigned<decltype(d)> du; |
| 3510 |
alignas(64) constexpr uint64_t kIdx[4] = {1, 3, 5, 7}; |
| 3511 |
return Vec256<double>{_mm256_mask2_permutex2var_pd(lo.raw, Load(du, kIdx).raw, |
| 3512 |
__mmask8{0xFF}, hi.raw)}; |
| 3513 |
#else |
| 3514 |
(void)d; |
| 3515 |
const Vec256<double> v31{_mm256_shuffle_pd(lo.raw, hi.raw, 15)}; |
| 3516 |
return Vec256<double>{ |
| 3517 |
_mm256_permute4x64_pd(v31.raw, _MM_SHUFFLE(3, 1, 2, 0))}; |
| 3518 |
#endif |
| 3519 |
} |
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
template <typename T, HWY_IF_LANE_SIZE(T, 1)> |
| 3524 |
HWY_API Vec256<T> ConcatEven(Full256<T> d, Vec256<T> hi, Vec256<T> lo) { |
| 3525 |
const RebindToUnsigned<decltype(d)> du; |
| 3526 |
#if HWY_TARGET == HWY_AVX3_DL |
| 3527 |
alignas(64) constexpr uint8_t kIdx[32] = { |
| 3528 |
0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, |
| 3529 |
32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62}; |
| 3530 |
return BitCast(d, Vec256<uint32_t>{_mm256_mask2_permutex2var_epi8( |
| 3531 |
BitCast(du, lo).raw, Load(du, kIdx).raw, |
| 3532 |
__mmask32{0xFFFFFFFFu}, BitCast(du, hi).raw)}); |
| 3533 |
#else |
| 3534 |
const RepartitionToWide<decltype(du)> dw; |
| 3535 |
|
| 3536 |
const Vec256<uint16_t> mask = Set(dw, 0x00FF); |
| 3537 |
const Vec256<uint16_t> uH = And(BitCast(dw, hi), mask); |
| 3538 |
const Vec256<uint16_t> uL = And(BitCast(dw, lo), mask); |
| 3539 |
const __m256i u8 = _mm256_packus_epi16(uL.raw, uH.raw); |
| 3540 |
return Vec256<T>{_mm256_permute4x64_epi64(u8, _MM_SHUFFLE(3, 1, 2, 0))}; |
| 3541 |
#endif |
| 3542 |
} |
| 3543 |
|
| 3544 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 3545 |
HWY_API Vec256<T> ConcatEven(Full256<T> d, Vec256<T> hi, Vec256<T> lo) { |
| 3546 |
const RebindToUnsigned<decltype(d)> du; |
| 3547 |
#if HWY_TARGET <= HWY_AVX3 |
| 3548 |
alignas(64) constexpr uint16_t kIdx[16] = {0, 2, 4, 6, 8, 10, 12, 14, |
| 3549 |
16, 18, 20, 22, 24, 26, 28, 30}; |
| 3550 |
return BitCast(d, Vec256<uint32_t>{_mm256_mask2_permutex2var_epi16( |
| 3551 |
BitCast(du, lo).raw, Load(du, kIdx).raw, |
| 3552 |
__mmask16{0xFFFF}, BitCast(du, hi).raw)}); |
| 3553 |
#else |
| 3554 |
const RepartitionToWide<decltype(du)> dw; |
| 3555 |
|
| 3556 |
const Vec256<uint32_t> mask = Set(dw, 0x0000FFFF); |
| 3557 |
const Vec256<uint32_t> uH = And(BitCast(dw, hi), mask); |
| 3558 |
const Vec256<uint32_t> uL = And(BitCast(dw, lo), mask); |
| 3559 |
const __m256i u16 = _mm256_packus_epi32(uL.raw, uH.raw); |
| 3560 |
return Vec256<T>{_mm256_permute4x64_epi64(u16, _MM_SHUFFLE(3, 1, 2, 0))}; |
| 3561 |
#endif |
| 3562 |
} |
| 3563 |
|
| 3564 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 3565 |
HWY_API Vec256<T> ConcatEven(Full256<T> d, Vec256<T> hi, Vec256<T> lo) { |
| 3566 |
const RebindToUnsigned<decltype(d)> du; |
| 3567 |
#if HWY_TARGET <= HWY_AVX3 |
| 3568 |
alignas(64) constexpr uint32_t kIdx[8] = {0, 2, 4, 6, 8, 10, 12, 14}; |
| 3569 |
return BitCast(d, Vec256<uint32_t>{_mm256_mask2_permutex2var_epi32( |
| 3570 |
BitCast(du, lo).raw, Load(du, kIdx).raw, __mmask8{0xFF}, |
| 3571 |
BitCast(du, hi).raw)}); |
| 3572 |
#else |
| 3573 |
const RebindToFloat<decltype(d)> df; |
| 3574 |
const Vec256<float> v2020{_mm256_shuffle_ps( |
| 3575 |
BitCast(df, lo).raw, BitCast(df, hi).raw, _MM_SHUFFLE(2, 0, 2, 0))}; |
| 3576 |
return Vec256<T>{_mm256_permute4x64_epi64(BitCast(du, v2020).raw, |
| 3577 |
_MM_SHUFFLE(3, 1, 2, 0))}; |
| 3578 |
|
| 3579 |
#endif |
| 3580 |
} |
| 3581 |
|
| 3582 |
HWY_API Vec256<float> ConcatEven(Full256<float> d, Vec256<float> hi, |
| 3583 |
Vec256<float> lo) { |
| 3584 |
const RebindToUnsigned<decltype(d)> du; |
| 3585 |
#if HWY_TARGET <= HWY_AVX3 |
| 3586 |
alignas(64) constexpr uint32_t kIdx[8] = {0, 2, 4, 6, 8, 10, 12, 14}; |
| 3587 |
return Vec256<float>{_mm256_mask2_permutex2var_ps(lo.raw, Load(du, kIdx).raw, |
| 3588 |
__mmask8{0xFF}, hi.raw)}; |
| 3589 |
#else |
| 3590 |
const Vec256<float> v2020{ |
| 3591 |
_mm256_shuffle_ps(lo.raw, hi.raw, _MM_SHUFFLE(2, 0, 2, 0))}; |
| 3592 |
return BitCast(d, Vec256<uint32_t>{_mm256_permute4x64_epi64( |
| 3593 |
BitCast(du, v2020).raw, _MM_SHUFFLE(3, 1, 2, 0))}); |
| 3594 |
|
| 3595 |
#endif |
| 3596 |
} |
| 3597 |
|
| 3598 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 3599 |
HWY_API Vec256<T> ConcatEven(Full256<T> d, Vec256<T> hi, Vec256<T> lo) { |
| 3600 |
const RebindToUnsigned<decltype(d)> du; |
| 3601 |
#if HWY_TARGET <= HWY_AVX3 |
| 3602 |
alignas(64) constexpr uint64_t kIdx[4] = {0, 2, 4, 6}; |
| 3603 |
return BitCast(d, Vec256<uint64_t>{_mm256_mask2_permutex2var_epi64( |
| 3604 |
BitCast(du, lo).raw, Load(du, kIdx).raw, __mmask8{0xFF}, |
| 3605 |
BitCast(du, hi).raw)}); |
| 3606 |
#else |
| 3607 |
const RebindToFloat<decltype(d)> df; |
| 3608 |
const Vec256<double> v20{ |
| 3609 |
_mm256_shuffle_pd(BitCast(df, lo).raw, BitCast(df, hi).raw, 0)}; |
| 3610 |
return Vec256<T>{ |
| 3611 |
_mm256_permute4x64_epi64(BitCast(du, v20).raw, _MM_SHUFFLE(3, 1, 2, 0))}; |
| 3612 |
|
| 3613 |
#endif |
| 3614 |
} |
| 3615 |
|
| 3616 |
HWY_API Vec256<double> ConcatEven(Full256<double> d, Vec256<double> hi, |
| 3617 |
Vec256<double> lo) { |
| 3618 |
#if HWY_TARGET <= HWY_AVX3 |
| 3619 |
const RebindToUnsigned<decltype(d)> du; |
| 3620 |
alignas(64) constexpr uint64_t kIdx[4] = {0, 2, 4, 6}; |
| 3621 |
return Vec256<double>{_mm256_mask2_permutex2var_pd(lo.raw, Load(du, kIdx).raw, |
| 3622 |
__mmask8{0xFF}, hi.raw)}; |
| 3623 |
#else |
| 3624 |
(void)d; |
| 3625 |
const Vec256<double> v20{_mm256_shuffle_pd(lo.raw, hi.raw, 0)}; |
| 3626 |
return Vec256<double>{ |
| 3627 |
_mm256_permute4x64_pd(v20.raw, _MM_SHUFFLE(3, 1, 2, 0))}; |
| 3628 |
#endif |
| 3629 |
} |
| 3630 |
|
| 3631 |
|
| 3632 |
|
| 3633 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 3634 |
HWY_API Vec256<T> DupEven(Vec256<T> v) { |
| 3635 |
return Vec256<T>{_mm256_shuffle_epi32(v.raw, _MM_SHUFFLE(2, 2, 0, 0))}; |
| 3636 |
} |
| 3637 |
HWY_API Vec256<float> DupEven(Vec256<float> v) { |
| 3638 |
return Vec256<float>{ |
| 3639 |
_mm256_shuffle_ps(v.raw, v.raw, _MM_SHUFFLE(2, 2, 0, 0))}; |
| 3640 |
} |
| 3641 |
|
| 3642 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 3643 |
HWY_API Vec256<T> DupEven(const Vec256<T> v) { |
| 3644 |
return InterleaveLower(Full256<T>(), v, v); |
| 3645 |
} |
| 3646 |
|
| 3647 |
|
| 3648 |
|
| 3649 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 3650 |
HWY_API Vec256<T> DupOdd(Vec256<T> v) { |
| 3651 |
return Vec256<T>{_mm256_shuffle_epi32(v.raw, _MM_SHUFFLE(3, 3, 1, 1))}; |
| 3652 |
} |
| 3653 |
HWY_API Vec256<float> DupOdd(Vec256<float> v) { |
| 3654 |
return Vec256<float>{ |
| 3655 |
_mm256_shuffle_ps(v.raw, v.raw, _MM_SHUFFLE(3, 3, 1, 1))}; |
| 3656 |
} |
| 3657 |
|
| 3658 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 3659 |
HWY_API Vec256<T> DupOdd(const Vec256<T> v) { |
| 3660 |
return InterleaveUpper(Full256<T>(), v, v); |
| 3661 |
} |
| 3662 |
|
| 3663 |
|
| 3664 |
|
| 3665 |
namespace detail { |
| 3666 |
|
| 3667 |
template <typename T> |
| 3668 |
HWY_INLINE Vec256<T> OddEven(hwy::SizeTag<1> , const Vec256<T> a, |
| 3669 |
const Vec256<T> b) { |
| 3670 |
const Full256<T> d; |
| 3671 |
const Full256<uint8_t> d8; |
| 3672 |
alignas(32) constexpr uint8_t mask[16] = {0xFF, 0, 0xFF, 0, 0xFF, 0, 0xFF, 0, |
| 3673 |
0xFF, 0, 0xFF, 0, 0xFF, 0, 0xFF, 0}; |
| 3674 |
return IfThenElse(MaskFromVec(BitCast(d, LoadDup128(d8, mask))), b, a); |
| 3675 |
} |
| 3676 |
template <typename T> |
| 3677 |
HWY_INLINE Vec256<T> OddEven(hwy::SizeTag<2> , const Vec256<T> a, |
| 3678 |
const Vec256<T> b) { |
| 3679 |
return Vec256<T>{_mm256_blend_epi16(a.raw, b.raw, 0x55)}; |
| 3680 |
} |
| 3681 |
template <typename T> |
| 3682 |
HWY_INLINE Vec256<T> OddEven(hwy::SizeTag<4> , const Vec256<T> a, |
| 3683 |
const Vec256<T> b) { |
| 3684 |
return Vec256<T>{_mm256_blend_epi32(a.raw, b.raw, 0x55)}; |
| 3685 |
} |
| 3686 |
template <typename T> |
| 3687 |
HWY_INLINE Vec256<T> OddEven(hwy::SizeTag<8> , const Vec256<T> a, |
| 3688 |
const Vec256<T> b) { |
| 3689 |
return Vec256<T>{_mm256_blend_epi32(a.raw, b.raw, 0x33)}; |
| 3690 |
} |
| 3691 |
|
| 3692 |
} |
| 3693 |
|
| 3694 |
template <typename T> |
| 3695 |
HWY_API Vec256<T> OddEven(const Vec256<T> a, const Vec256<T> b) { |
| 3696 |
return detail::OddEven(hwy::SizeTag<sizeof(T)>(), a, b); |
| 3697 |
} |
| 3698 |
HWY_API Vec256<float> OddEven(const Vec256<float> a, const Vec256<float> b) { |
| 3699 |
return Vec256<float>{_mm256_blend_ps(a.raw, b.raw, 0x55)}; |
| 3700 |
} |
| 3701 |
|
| 3702 |
HWY_API Vec256<double> OddEven(const Vec256<double> a, const Vec256<double> b) { |
| 3703 |
return Vec256<double>{_mm256_blend_pd(a.raw, b.raw, 5)}; |
| 3704 |
} |
| 3705 |
|
| 3706 |
|
| 3707 |
|
| 3708 |
template <typename T> |
| 3709 |
Vec256<T> OddEvenBlocks(Vec256<T> odd, Vec256<T> even) { |
| 3710 |
return Vec256<T>{_mm256_blend_epi32(odd.raw, even.raw, 0xFu)}; |
| 3711 |
} |
| 3712 |
|
| 3713 |
HWY_API Vec256<float> OddEvenBlocks(Vec256<float> odd, Vec256<float> even) { |
| 3714 |
return Vec256<float>{_mm256_blend_ps(odd.raw, even.raw, 0xFu)}; |
| 3715 |
} |
| 3716 |
|
| 3717 |
HWY_API Vec256<double> OddEvenBlocks(Vec256<double> odd, Vec256<double> even) { |
| 3718 |
return Vec256<double>{_mm256_blend_pd(odd.raw, even.raw, 0x3u)}; |
| 3719 |
} |
| 3720 |
|
| 3721 |
|
| 3722 |
|
| 3723 |
template <typename T> |
| 3724 |
HWY_API Vec256<T> ReverseBlocks(Full256<T> d, Vec256<T> v) { |
| 3725 |
return ConcatLowerUpper(d, v, v); |
| 3726 |
} |
| 3727 |
|
| 3728 |
|
| 3729 |
|
| 3730 |
|
| 3731 |
template <typename T, typename TI> |
| 3732 |
HWY_API Vec256<TI> TableLookupBytes(const Vec256<T> bytes, |
| 3733 |
const Vec256<TI> from) { |
| 3734 |
return Vec256<TI>{_mm256_shuffle_epi8(bytes.raw, from.raw)}; |
| 3735 |
} |
| 3736 |
|
| 3737 |
|
| 3738 |
template <typename T, typename TI, size_t NI> |
| 3739 |
HWY_API Vec128<TI, NI> TableLookupBytes(const Vec256<T> bytes, |
| 3740 |
const Vec128<TI, NI> from) { |
| 3741 |
|
| 3742 |
const auto from_256 = ZeroExtendVector(Full256<TI>(), Vec128<TI>{from.raw}); |
| 3743 |
const auto tbl_full = TableLookupBytes(bytes, from_256); |
| 3744 |
|
| 3745 |
return Vec128<TI, NI>{LowerHalf(Full128<TI>(), tbl_full).raw}; |
| 3746 |
} |
| 3747 |
|
| 3748 |
|
| 3749 |
template <typename T, size_t N, typename TI> |
| 3750 |
HWY_API Vec256<TI> TableLookupBytes(const Vec128<T, N> bytes, |
| 3751 |
const Vec256<TI> from) { |
| 3752 |
|
| 3753 |
const auto bytes_256 = ZeroExtendVector(Full256<T>(), Vec128<T>{bytes.raw}); |
| 3754 |
return TableLookupBytes(bytes_256, from); |
| 3755 |
} |
| 3756 |
|
| 3757 |
|
| 3758 |
|
| 3759 |
|
| 3760 |
|
| 3761 |
namespace detail { |
| 3762 |
|
| 3763 |
#if HWY_TARGET > HWY_AVX3 && !HWY_IDE |
| 3764 |
|
| 3765 |
|
| 3766 |
template <typename T> |
| 3767 |
HWY_INLINE Vec256<MakeUnsigned<T>> Pow2(const Vec256<T> v) { |
| 3768 |
static_assert(sizeof(T) == 2, "Only for 16-bit"); |
| 3769 |
const Full256<T> d; |
| 3770 |
const RepartitionToWide<decltype(d)> dw; |
| 3771 |
const Rebind<float, decltype(dw)> df; |
| 3772 |
const auto zero = Zero(d); |
| 3773 |
|
| 3774 |
const auto exp = ShiftLeft<23 - 16>(v); |
| 3775 |
const auto upper = exp + Set(d, 0x3F80); |
| 3776 |
|
| 3777 |
const auto f0 = ZipLower(dw, zero, upper); |
| 3778 |
const auto f1 = ZipUpper(dw, zero, upper); |
| 3779 |
|
| 3780 |
|
| 3781 |
const Vec256<int32_t> bits0{_mm256_cvttps_epi32(BitCast(df, f0).raw)}; |
| 3782 |
const Vec256<int32_t> bits1{_mm256_cvttps_epi32(BitCast(df, f1).raw)}; |
| 3783 |
return Vec256<MakeUnsigned<T>>{_mm256_packus_epi32(bits0.raw, bits1.raw)}; |
| 3784 |
} |
| 3785 |
|
| 3786 |
#endif |
| 3787 |
|
| 3788 |
HWY_INLINE Vec256<uint16_t> Shl(hwy::UnsignedTag , Vec256<uint16_t> v, |
| 3789 |
Vec256<uint16_t> bits) { |
| 3790 |
#if HWY_TARGET <= HWY_AVX3 || HWY_IDE |
| 3791 |
return Vec256<uint16_t>{_mm256_sllv_epi16(v.raw, bits.raw)}; |
| 3792 |
#else |
| 3793 |
return v * Pow2(bits); |
| 3794 |
#endif |
| 3795 |
} |
| 3796 |
|
| 3797 |
HWY_INLINE Vec256<uint32_t> Shl(hwy::UnsignedTag , Vec256<uint32_t> v, |
| 3798 |
Vec256<uint32_t> bits) { |
| 3799 |
return Vec256<uint32_t>{_mm256_sllv_epi32(v.raw, bits.raw)}; |
| 3800 |
} |
| 3801 |
|
| 3802 |
HWY_INLINE Vec256<uint64_t> Shl(hwy::UnsignedTag , Vec256<uint64_t> v, |
| 3803 |
Vec256<uint64_t> bits) { |
| 3804 |
return Vec256<uint64_t>{_mm256_sllv_epi64(v.raw, bits.raw)}; |
| 3805 |
} |
| 3806 |
|
| 3807 |
template <typename T> |
| 3808 |
HWY_INLINE Vec256<T> Shl(hwy::SignedTag , Vec256<T> v, Vec256<T> bits) { |
| 3809 |
|
| 3810 |
const Full256<T> di; |
| 3811 |
const Full256<MakeUnsigned<T>> du; |
| 3812 |
return BitCast(di, |
| 3813 |
Shl(hwy::UnsignedTag(), BitCast(du, v), BitCast(du, bits))); |
| 3814 |
} |
| 3815 |
|
| 3816 |
} |
| 3817 |
|
| 3818 |
template <typename T> |
| 3819 |
HWY_API Vec256<T> operator<<(Vec256<T> v, Vec256<T> bits) { |
| 3820 |
return detail::Shl(hwy::TypeTag<T>(), v, bits); |
| 3821 |
} |
| 3822 |
|
| 3823 |
|
| 3824 |
|
| 3825 |
HWY_API Vec256<uint16_t> operator>>(Vec256<uint16_t> v, Vec256<uint16_t> bits) { |
| 3826 |
#if HWY_TARGET <= HWY_AVX3 || HWY_IDE |
| 3827 |
return Vec256<uint16_t>{_mm256_srlv_epi16(v.raw, bits.raw)}; |
| 3828 |
#else |
| 3829 |
Full256<uint16_t> d; |
| 3830 |
|
| 3831 |
auto out = MulHigh(v, detail::Pow2(Set(d, 16) - bits)); |
| 3832 |
|
| 3833 |
return IfThenElse(bits == Zero(d), v, out); |
| 3834 |
#endif |
| 3835 |
} |
| 3836 |
|
| 3837 |
HWY_API Vec256<uint32_t> operator>>(Vec256<uint32_t> v, Vec256<uint32_t> bits) { |
| 3838 |
return Vec256<uint32_t>{_mm256_srlv_epi32(v.raw, bits.raw)}; |
| 3839 |
} |
| 3840 |
|
| 3841 |
HWY_API Vec256<uint64_t> operator>>(Vec256<uint64_t> v, Vec256<uint64_t> bits) { |
| 3842 |
return Vec256<uint64_t>{_mm256_srlv_epi64(v.raw, bits.raw)}; |
| 3843 |
} |
| 3844 |
|
| 3845 |
HWY_API Vec256<int16_t> operator>>(Vec256<int16_t> v, Vec256<int16_t> bits) { |
| 3846 |
#if HWY_TARGET <= HWY_AVX3 |
| 3847 |
return Vec256<int16_t>{_mm256_srav_epi16(v.raw, bits.raw)}; |
| 3848 |
#else |
| 3849 |
return detail::SignedShr(Full256<int16_t>(), v, bits); |
| 3850 |
#endif |
| 3851 |
} |
| 3852 |
|
| 3853 |
HWY_API Vec256<int32_t> operator>>(Vec256<int32_t> v, Vec256<int32_t> bits) { |
| 3854 |
return Vec256<int32_t>{_mm256_srav_epi32(v.raw, bits.raw)}; |
| 3855 |
} |
| 3856 |
|
| 3857 |
HWY_API Vec256<int64_t> operator>>(Vec256<int64_t> v, Vec256<int64_t> bits) { |
| 3858 |
#if HWY_TARGET <= HWY_AVX3 |
| 3859 |
return Vec256<int64_t>{_mm256_srav_epi64(v.raw, bits.raw)}; |
| 3860 |
#else |
| 3861 |
return detail::SignedShr(Full256<int64_t>(), v, bits); |
| 3862 |
#endif |
| 3863 |
} |
| 3864 |
|
| 3865 |
HWY_INLINE Vec256<uint64_t> MulEven(const Vec256<uint64_t> a, |
| 3866 |
const Vec256<uint64_t> b) { |
| 3867 |
const Full256<uint64_t> du64; |
| 3868 |
const RepartitionToNarrow<decltype(du64)> du32; |
| 3869 |
const auto maskL = Set(du64, 0xFFFFFFFFULL); |
| 3870 |
const auto a32 = BitCast(du32, a); |
| 3871 |
const auto b32 = BitCast(du32, b); |
| 3872 |
|
| 3873 |
const auto aH = Shuffle2301(a32); |
| 3874 |
const auto bH = Shuffle2301(b32); |
| 3875 |
|
| 3876 |
|
| 3877 |
|
| 3878 |
|
| 3879 |
const auto aLbL = MulEven(a32, b32); |
| 3880 |
const auto w3 = aLbL & maskL; |
| 3881 |
|
| 3882 |
const auto t2 = MulEven(aH, b32) + ShiftRight<32>(aLbL); |
| 3883 |
const auto w2 = t2 & maskL; |
| 3884 |
const auto w1 = ShiftRight<32>(t2); |
| 3885 |
|
| 3886 |
const auto t = MulEven(a32, bH) + w2; |
| 3887 |
const auto k = ShiftRight<32>(t); |
| 3888 |
|
| 3889 |
const auto mulH = MulEven(aH, bH) + w1 + k; |
| 3890 |
const auto mulL = ShiftLeft<32>(t) + w3; |
| 3891 |
return InterleaveLower(mulL, mulH); |
| 3892 |
} |
| 3893 |
|
| 3894 |
HWY_INLINE Vec256<uint64_t> MulOdd(const Vec256<uint64_t> a, |
| 3895 |
const Vec256<uint64_t> b) { |
| 3896 |
const Full256<uint64_t> du64; |
| 3897 |
const RepartitionToNarrow<decltype(du64)> du32; |
| 3898 |
const auto maskL = Set(du64, 0xFFFFFFFFULL); |
| 3899 |
const auto a32 = BitCast(du32, a); |
| 3900 |
const auto b32 = BitCast(du32, b); |
| 3901 |
|
| 3902 |
const auto aH = Shuffle2301(a32); |
| 3903 |
const auto bH = Shuffle2301(b32); |
| 3904 |
|
| 3905 |
|
| 3906 |
const auto aLbL = MulEven(a32, b32); |
| 3907 |
const auto w3 = aLbL & maskL; |
| 3908 |
|
| 3909 |
const auto t2 = MulEven(aH, b32) + ShiftRight<32>(aLbL); |
| 3910 |
const auto w2 = t2 & maskL; |
| 3911 |
const auto w1 = ShiftRight<32>(t2); |
| 3912 |
|
| 3913 |
const auto t = MulEven(a32, bH) + w2; |
| 3914 |
const auto k = ShiftRight<32>(t); |
| 3915 |
|
| 3916 |
const auto mulH = MulEven(aH, bH) + w1 + k; |
| 3917 |
const auto mulL = ShiftLeft<32>(t) + w3; |
| 3918 |
return InterleaveUpper(du64, mulL, mulH); |
| 3919 |
} |
| 3920 |
|
| 3921 |
|
| 3922 |
HWY_API Vec256<int32_t> ReorderWidenMulAccumulate(Full256<int32_t> , |
| 3923 |
Vec256<int16_t> a, |
| 3924 |
Vec256<int16_t> b, |
| 3925 |
const Vec256<int32_t> sum0, |
| 3926 |
Vec256<int32_t>& ) { |
| 3927 |
return sum0 + Vec256<int32_t>{_mm256_madd_epi16(a.raw, b.raw)}; |
| 3928 |
} |
| 3929 |
|
| 3930 |
|
| 3931 |
HWY_API Vec256<int32_t> RearrangeToOddPlusEven(const Vec256<int32_t> sum0, |
| 3932 |
Vec256<int32_t> ) { |
| 3933 |
return sum0; |
| 3934 |
} |
| 3935 |
|
| 3936 |
|
| 3937 |
|
| 3938 |
|
| 3939 |
|
| 3940 |
HWY_API Vec256<double> PromoteTo(Full256<double> , |
| 3941 |
const Vec128<float, 4> v) { |
| 3942 |
return Vec256<double>{_mm256_cvtps_pd(v.raw)}; |
| 3943 |
} |
| 3944 |
|
| 3945 |
HWY_API Vec256<double> PromoteTo(Full256<double> , |
| 3946 |
const Vec128<int32_t, 4> v) { |
| 3947 |
return Vec256<double>{_mm256_cvtepi32_pd(v.raw)}; |
| 3948 |
} |
| 3949 |
|
| 3950 |
|
| 3951 |
|
| 3952 |
|
| 3953 |
HWY_API Vec256<uint16_t> PromoteTo(Full256<uint16_t> , |
| 3954 |
Vec128<uint8_t> v) { |
| 3955 |
return Vec256<uint16_t>{_mm256_cvtepu8_epi16(v.raw)}; |
| 3956 |
} |
| 3957 |
HWY_API Vec256<uint32_t> PromoteTo(Full256<uint32_t> , |
| 3958 |
Vec128<uint8_t, 8> v) { |
| 3959 |
return Vec256<uint32_t>{_mm256_cvtepu8_epi32(v.raw)}; |
| 3960 |
} |
| 3961 |
HWY_API Vec256<int16_t> PromoteTo(Full256<int16_t> , |
| 3962 |
Vec128<uint8_t> v) { |
| 3963 |
return Vec256<int16_t>{_mm256_cvtepu8_epi16(v.raw)}; |
| 3964 |
} |
| 3965 |
HWY_API Vec256<int32_t> PromoteTo(Full256<int32_t> , |
| 3966 |
Vec128<uint8_t, 8> v) { |
| 3967 |
return Vec256<int32_t>{_mm256_cvtepu8_epi32(v.raw)}; |
| 3968 |
} |
| 3969 |
HWY_API Vec256<uint32_t> PromoteTo(Full256<uint32_t> , |
| 3970 |
Vec128<uint16_t> v) { |
| 3971 |
return Vec256<uint32_t>{_mm256_cvtepu16_epi32(v.raw)}; |
| 3972 |
} |
| 3973 |
HWY_API Vec256<int32_t> PromoteTo(Full256<int32_t> , |
| 3974 |
Vec128<uint16_t> v) { |
| 3975 |
return Vec256<int32_t>{_mm256_cvtepu16_epi32(v.raw)}; |
| 3976 |
} |
| 3977 |
HWY_API Vec256<uint64_t> PromoteTo(Full256<uint64_t> , |
| 3978 |
Vec128<uint32_t> v) { |
| 3979 |
return Vec256<uint64_t>{_mm256_cvtepu32_epi64(v.raw)}; |
| 3980 |
} |
| 3981 |
|
| 3982 |
|
| 3983 |
|
| 3984 |
|
| 3985 |
|
| 3986 |
HWY_API Vec256<int16_t> PromoteTo(Full256<int16_t> , |
| 3987 |
Vec128<int8_t> v) { |
| 3988 |
return Vec256<int16_t>{_mm256_cvtepi8_epi16(v.raw)}; |
| 3989 |
} |
| 3990 |
HWY_API Vec256<int32_t> PromoteTo(Full256<int32_t> , |
| 3991 |
Vec128<int8_t, 8> v) { |
| 3992 |
return Vec256<int32_t>{_mm256_cvtepi8_epi32(v.raw)}; |
| 3993 |
} |
| 3994 |
HWY_API Vec256<int32_t> PromoteTo(Full256<int32_t> , |
| 3995 |
Vec128<int16_t> v) { |
| 3996 |
return Vec256<int32_t>{_mm256_cvtepi16_epi32(v.raw)}; |
| 3997 |
} |
| 3998 |
HWY_API Vec256<int64_t> PromoteTo(Full256<int64_t> , |
| 3999 |
Vec128<int32_t> v) { |
| 4000 |
return Vec256<int64_t>{_mm256_cvtepi32_epi64(v.raw)}; |
| 4001 |
} |
| 4002 |
|
| 4003 |
|
| 4004 |
|
| 4005 |
HWY_API Vec128<uint16_t> DemoteTo(Full128<uint16_t> , |
| 4006 |
const Vec256<int32_t> v) { |
| 4007 |
const __m256i u16 = _mm256_packus_epi32(v.raw, v.raw); |
| 4008 |
|
| 4009 |
|
| 4010 |
return Vec128<uint16_t>{ |
| 4011 |
_mm256_castsi256_si128(_mm256_permute4x64_epi64(u16, 0x88))}; |
| 4012 |
} |
| 4013 |
|
| 4014 |
HWY_API Vec128<int16_t> DemoteTo(Full128<int16_t> , |
| 4015 |
const Vec256<int32_t> v) { |
| 4016 |
const __m256i i16 = _mm256_packs_epi32(v.raw, v.raw); |
| 4017 |
return Vec128<int16_t>{ |
| 4018 |
_mm256_castsi256_si128(_mm256_permute4x64_epi64(i16, 0x88))}; |
| 4019 |
} |
| 4020 |
|
| 4021 |
HWY_API Vec128<uint8_t, 8> DemoteTo(Full64<uint8_t> , |
| 4022 |
const Vec256<int32_t> v) { |
| 4023 |
const __m256i u16_blocks = _mm256_packus_epi32(v.raw, v.raw); |
| 4024 |
|
| 4025 |
const __m256i u16_concat = _mm256_permute4x64_epi64(u16_blocks, 0x88); |
| 4026 |
const __m128i u16 = _mm256_castsi256_si128(u16_concat); |
| 4027 |
|
| 4028 |
|
| 4029 |
const __m128i i16 = _mm_and_si128(u16, _mm_set1_epi16(0x7FFF)); |
| 4030 |
return Vec128<uint8_t, 8>{_mm_packus_epi16(i16, i16)}; |
| 4031 |
} |
| 4032 |
|
| 4033 |
HWY_API Vec128<uint8_t> DemoteTo(Full128<uint8_t> , |
| 4034 |
const Vec256<int16_t> v) { |
| 4035 |
const __m256i u8 = _mm256_packus_epi16(v.raw, v.raw); |
| 4036 |
return Vec128<uint8_t>{ |
| 4037 |
_mm256_castsi256_si128(_mm256_permute4x64_epi64(u8, 0x88))}; |
| 4038 |
} |
| 4039 |
|
| 4040 |
HWY_API Vec128<int8_t, 8> DemoteTo(Full64<int8_t> , |
| 4041 |
const Vec256<int32_t> v) { |
| 4042 |
const __m256i i16_blocks = _mm256_packs_epi32(v.raw, v.raw); |
| 4043 |
|
| 4044 |
const __m256i i16_concat = _mm256_permute4x64_epi64(i16_blocks, 0x88); |
| 4045 |
const __m128i i16 = _mm256_castsi256_si128(i16_concat); |
| 4046 |
return Vec128<int8_t, 8>{_mm_packs_epi16(i16, i16)}; |
| 4047 |
} |
| 4048 |
|
| 4049 |
HWY_API Vec128<int8_t> DemoteTo(Full128<int8_t> , |
| 4050 |
const Vec256<int16_t> v) { |
| 4051 |
const __m256i i8 = _mm256_packs_epi16(v.raw, v.raw); |
| 4052 |
return Vec128<int8_t>{ |
| 4053 |
_mm256_castsi256_si128(_mm256_permute4x64_epi64(i8, 0x88))}; |
| 4054 |
} |
| 4055 |
|
| 4056 |
|
| 4057 |
|
| 4058 |
HWY_DIAGNOSTICS(push) |
| 4059 |
HWY_DIAGNOSTICS_OFF(disable : 4556, ignored "-Wsign-conversion") |
| 4060 |
|
| 4061 |
HWY_API Vec128<float16_t> DemoteTo(Full128<float16_t> df16, |
| 4062 |
const Vec256<float> v) { |
| 4063 |
#ifdef HWY_DISABLE_F16C |
| 4064 |
const RebindToUnsigned<decltype(df16)> du16; |
| 4065 |
const Rebind<uint32_t, decltype(df16)> du; |
| 4066 |
const RebindToSigned<decltype(du)> di; |
| 4067 |
const auto bits32 = BitCast(du, v); |
| 4068 |
const auto sign = ShiftRight<31>(bits32); |
| 4069 |
const auto biased_exp32 = ShiftRight<23>(bits32) & Set(du, 0xFF); |
| 4070 |
const auto mantissa32 = bits32 & Set(du, 0x7FFFFF); |
| 4071 |
|
| 4072 |
const auto k15 = Set(di, 15); |
| 4073 |
const auto exp = Min(BitCast(di, biased_exp32) - Set(di, 127), k15); |
| 4074 |
const auto is_tiny = exp < Set(di, -24); |
| 4075 |
|
| 4076 |
const auto is_subnormal = exp < Set(di, -14); |
| 4077 |
const auto biased_exp16 = |
| 4078 |
BitCast(du, IfThenZeroElse(is_subnormal, exp + k15)); |
| 4079 |
const auto sub_exp = BitCast(du, Set(di, -14) - exp); |
| 4080 |
const auto sub_m = (Set(du, 1) << (Set(du, 10) - sub_exp)) + |
| 4081 |
(mantissa32 >> (Set(du, 13) + sub_exp)); |
| 4082 |
const auto mantissa16 = IfThenElse(RebindMask(du, is_subnormal), sub_m, |
| 4083 |
ShiftRight<13>(mantissa32)); |
| 4084 |
|
| 4085 |
const auto sign16 = ShiftLeft<15>(sign); |
| 4086 |
const auto normal16 = sign16 | ShiftLeft<10>(biased_exp16) | mantissa16; |
| 4087 |
const auto bits16 = IfThenZeroElse(is_tiny, BitCast(di, normal16)); |
| 4088 |
return BitCast(df16, DemoteTo(du16, bits16)); |
| 4089 |
#else |
| 4090 |
(void)df16; |
| 4091 |
return Vec128<float16_t>{_mm256_cvtps_ph(v.raw, _MM_FROUND_NO_EXC)}; |
| 4092 |
#endif |
| 4093 |
} |
| 4094 |
|
| 4095 |
HWY_DIAGNOSTICS(pop) |
| 4096 |
|
| 4097 |
HWY_API Vec128<bfloat16_t> DemoteTo(Full128<bfloat16_t> dbf16, |
| 4098 |
const Vec256<float> v) { |
| 4099 |
|
| 4100 |
const Rebind<int32_t, decltype(dbf16)> di32; |
| 4101 |
const Rebind<uint32_t, decltype(dbf16)> du32; |
| 4102 |
const Rebind<uint16_t, decltype(dbf16)> du16; |
| 4103 |
const auto bits_in_32 = BitCast(di32, ShiftRight<16>(BitCast(du32, v))); |
| 4104 |
return BitCast(dbf16, DemoteTo(du16, bits_in_32)); |
| 4105 |
} |
| 4106 |
|
| 4107 |
HWY_API Vec256<bfloat16_t> ReorderDemote2To(Full256<bfloat16_t> dbf16, |
| 4108 |
Vec256<float> a, Vec256<float> b) { |
| 4109 |
|
| 4110 |
const RebindToUnsigned<decltype(dbf16)> du16; |
| 4111 |
const Repartition<uint32_t, decltype(dbf16)> du32; |
| 4112 |
const Vec256<uint32_t> b_in_even = ShiftRight<16>(BitCast(du32, b)); |
| 4113 |
return BitCast(dbf16, OddEven(BitCast(du16, a), BitCast(du16, b_in_even))); |
| 4114 |
} |
| 4115 |
|
| 4116 |
HWY_API Vec256<int16_t> ReorderDemote2To(Full256<int16_t> , |
| 4117 |
Vec256<int32_t> a, Vec256<int32_t> b) { |
| 4118 |
return Vec256<int16_t>{_mm256_packs_epi32(a.raw, b.raw)}; |
| 4119 |
} |
| 4120 |
|
| 4121 |
HWY_API Vec128<float> DemoteTo(Full128<float> , |
| 4122 |
const Vec256<double> v) { |
| 4123 |
return Vec128<float>{_mm256_cvtpd_ps(v.raw)}; |
| 4124 |
} |
| 4125 |
|
| 4126 |
HWY_API Vec128<int32_t> DemoteTo(Full128<int32_t> , |
| 4127 |
const Vec256<double> v) { |
| 4128 |
const auto clamped = detail::ClampF64ToI32Max(Full256<double>(), v); |
| 4129 |
return Vec128<int32_t>{_mm256_cvttpd_epi32(clamped.raw)}; |
| 4130 |
} |
| 4131 |
|
| 4132 |
|
| 4133 |
HWY_API Vec128<uint8_t, 8> U8FromU32(const Vec256<uint32_t> v) { |
| 4134 |
const Full256<uint32_t> d32; |
| 4135 |
alignas(32) static constexpr uint32_t k8From32[8] = { |
| 4136 |
0x0C080400u, ~0u, ~0u, ~0u, ~0u, 0x0C080400u, ~0u, ~0u}; |
| 4137 |
|
| 4138 |
const auto quad = TableLookupBytes(v, Load(d32, k8From32)); |
| 4139 |
|
| 4140 |
const auto lo = LowerHalf(quad); |
| 4141 |
const auto hi = UpperHalf(Full128<uint32_t>(), quad); |
| 4142 |
const auto pair = LowerHalf(lo | hi); |
| 4143 |
return BitCast(Full64<uint8_t>(), pair); |
| 4144 |
} |
| 4145 |
|
| 4146 |
|
| 4147 |
|
| 4148 |
namespace detail { |
| 4149 |
|
| 4150 |
|
| 4151 |
template <uint32_t LO, uint32_t HI, typename T> |
| 4152 |
HWY_INLINE Vec128<uint32_t> LookupAndConcatHalves(Vec256<T> v) { |
| 4153 |
const Full256<uint32_t> d32; |
| 4154 |
|
| 4155 |
#if HWY_TARGET <= HWY_AVX3_DL |
| 4156 |
alignas(32) constexpr uint32_t kMap[8] = { |
| 4157 |
LO, HI, 0x10101010 + LO, 0x10101010 + HI, 0, 0, 0, 0}; |
| 4158 |
const auto result = _mm256_permutexvar_epi8(v.raw, Load(d32, kMap).raw); |
| 4159 |
#else |
| 4160 |
alignas(32) static constexpr uint32_t kMap[8] = {LO, HI, ~0u, ~0u, |
| 4161 |
~0u, ~0u, LO, HI}; |
| 4162 |
const auto quad = TableLookupBytes(v, Load(d32, kMap)); |
| 4163 |
const auto result = _mm256_permute4x64_epi64(quad.raw, 0xCC); |
| 4164 |
|
| 4165 |
|
| 4166 |
|
| 4167 |
|
| 4168 |
#endif |
| 4169 |
|
| 4170 |
return Vec128<uint32_t>{_mm256_castsi256_si128(result)}; |
| 4171 |
} |
| 4172 |
|
| 4173 |
|
| 4174 |
template <uint16_t LO, uint16_t HI, typename T> |
| 4175 |
HWY_INLINE Vec128<uint32_t, 2> LookupAndConcatQuarters(Vec256<T> v) { |
| 4176 |
const Full256<uint16_t> d16; |
| 4177 |
|
| 4178 |
#if HWY_TARGET <= HWY_AVX3_DL |
| 4179 |
alignas(32) constexpr uint16_t kMap[16] = { |
| 4180 |
LO, HI, 0x1010 + LO, 0x1010 + HI, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 4181 |
const auto result = _mm256_permutexvar_epi8(v.raw, Load(d16, kMap).raw); |
| 4182 |
return LowerHalf(Vec128<uint32_t>{_mm256_castsi256_si128(result)}); |
| 4183 |
#else |
| 4184 |
constexpr uint16_t ff = static_cast<uint16_t>(~0u); |
| 4185 |
alignas(32) static constexpr uint16_t kMap[16] = { |
| 4186 |
LO, ff, HI, ff, ff, ff, ff, ff, ff, ff, ff, ff, LO, ff, HI, ff}; |
| 4187 |
const auto quad = TableLookupBytes(v, Load(d16, kMap)); |
| 4188 |
const auto mixed = _mm256_permute4x64_epi64(quad.raw, 0xCC); |
| 4189 |
const auto half = _mm256_castsi256_si128(mixed); |
| 4190 |
return LowerHalf(Vec128<uint32_t>{_mm_packus_epi32(half, half)}); |
| 4191 |
#endif |
| 4192 |
} |
| 4193 |
|
| 4194 |
} |
| 4195 |
|
| 4196 |
HWY_API Vec128<uint8_t, 4> TruncateTo(Simd<uint8_t, 4, 0> , |
| 4197 |
const Vec256<uint64_t> v) { |
| 4198 |
const Full256<uint32_t> d32; |
| 4199 |
#if HWY_TARGET <= HWY_AVX3_DL |
| 4200 |
alignas(32) constexpr uint32_t kMap[8] = {0x18100800u, 0, 0, 0, 0, 0, 0, 0}; |
| 4201 |
const auto result = _mm256_permutexvar_epi8(v.raw, Load(d32, kMap).raw); |
| 4202 |
return LowerHalf(LowerHalf(LowerHalf(Vec256<uint8_t>{result}))); |
| 4203 |
#else |
| 4204 |
alignas(32) static constexpr uint32_t kMap[8] = {0xFFFF0800u, ~0u, ~0u, ~0u, |
| 4205 |
0x0800FFFFu, ~0u, ~0u, ~0u}; |
| 4206 |
const auto quad = TableLookupBytes(v, Load(d32, kMap)); |
| 4207 |
const auto lo = LowerHalf(quad); |
| 4208 |
const auto hi = UpperHalf(Full128<uint32_t>(), quad); |
| 4209 |
const auto result = lo | hi; |
| 4210 |
return LowerHalf(LowerHalf(Vec128<uint8_t>{result.raw})); |
| 4211 |
#endif |
| 4212 |
} |
| 4213 |
|
| 4214 |
HWY_API Vec128<uint16_t, 4> TruncateTo(Simd<uint16_t, 4, 0> , |
| 4215 |
const Vec256<uint64_t> v) { |
| 4216 |
const auto result = detail::LookupAndConcatQuarters<0x100, 0x908>(v); |
| 4217 |
return Vec128<uint16_t, 4>{result.raw}; |
| 4218 |
} |
| 4219 |
|
| 4220 |
HWY_API Vec128<uint32_t> TruncateTo(Simd<uint32_t, 4, 0> , |
| 4221 |
const Vec256<uint64_t> v) { |
| 4222 |
const Full256<uint32_t> d32; |
| 4223 |
alignas(32) constexpr uint32_t kEven[8] = {0, 2, 4, 6, 0, 2, 4, 6}; |
| 4224 |
const auto v32 = |
| 4225 |
TableLookupLanes(BitCast(d32, v), SetTableIndices(d32, kEven)); |
| 4226 |
return LowerHalf(Vec256<uint32_t>{v32.raw}); |
| 4227 |
} |
| 4228 |
|
| 4229 |
HWY_API Vec128<uint8_t, 8> TruncateTo(Simd<uint8_t, 8, 0> , |
| 4230 |
const Vec256<uint32_t> v) { |
| 4231 |
const auto full = detail::LookupAndConcatQuarters<0x400, 0xC08>(v); |
| 4232 |
return Vec128<uint8_t, 8>{full.raw}; |
| 4233 |
} |
| 4234 |
|
| 4235 |
HWY_API Vec128<uint16_t> TruncateTo(Simd<uint16_t, 8, 0> , |
| 4236 |
const Vec256<uint32_t> v) { |
| 4237 |
const auto full = detail::LookupAndConcatHalves<0x05040100, 0x0D0C0908>(v); |
| 4238 |
return Vec128<uint16_t>{full.raw}; |
| 4239 |
} |
| 4240 |
|
| 4241 |
HWY_API Vec128<uint8_t> TruncateTo(Simd<uint8_t, 16, 0> , |
| 4242 |
const Vec256<uint16_t> v) { |
| 4243 |
const auto full = detail::LookupAndConcatHalves<0x06040200, 0x0E0C0A08>(v); |
| 4244 |
return Vec128<uint8_t>{full.raw}; |
| 4245 |
} |
| 4246 |
|
| 4247 |
|
| 4248 |
|
| 4249 |
HWY_API Vec256<float> ConvertTo(Full256<float> , |
| 4250 |
const Vec256<int32_t> v) { |
| 4251 |
return Vec256<float>{_mm256_cvtepi32_ps(v.raw)}; |
| 4252 |
} |
| 4253 |
|
| 4254 |
HWY_API Vec256<double> ConvertTo(Full256<double> dd, const Vec256<int64_t> v) { |
| 4255 |
#if HWY_TARGET <= HWY_AVX3 |
| 4256 |
(void)dd; |
| 4257 |
return Vec256<double>{_mm256_cvtepi64_pd(v.raw)}; |
| 4258 |
#else |
| 4259 |
|
| 4260 |
const Repartition<uint32_t, decltype(dd)> d32; |
| 4261 |
const Repartition<uint64_t, decltype(dd)> d64; |
| 4262 |
|
| 4263 |
|
| 4264 |
const auto k84_63 = Set(d64, 0x4530000080000000ULL); |
| 4265 |
const auto v_upper = BitCast(dd, ShiftRight<32>(BitCast(d64, v)) ^ k84_63); |
| 4266 |
|
| 4267 |
|
| 4268 |
const auto k52 = Set(d32, 0x43300000); |
| 4269 |
const auto v_lower = BitCast(dd, OddEven(k52, BitCast(d32, v))); |
| 4270 |
|
| 4271 |
const auto k84_63_52 = BitCast(dd, Set(d64, 0x4530000080100000ULL)); |
| 4272 |
return (v_upper - k84_63_52) + v_lower; |
| 4273 |
#endif |
| 4274 |
} |
| 4275 |
|
| 4276 |
HWY_API Vec256<float> ConvertTo(HWY_MAYBE_UNUSED Full256<float> df, |
| 4277 |
const Vec256<uint32_t> v) { |
| 4278 |
#if HWY_TARGET <= HWY_AVX3 |
| 4279 |
return Vec256<float>{_mm256_cvtepu32_ps(v.raw)}; |
| 4280 |
#else |
| 4281 |
|
| 4282 |
const RebindToUnsigned<decltype(df)> du32; |
| 4283 |
const RebindToSigned<decltype(df)> d32; |
| 4284 |
|
| 4285 |
const auto msk_lo = Set(du32, 0xFFFF); |
| 4286 |
const auto cnst2_16_flt = Set(df, 65536.0f); |
| 4287 |
|
| 4288 |
|
| 4289 |
const auto v_lo = BitCast(d32, And(v, msk_lo)); |
| 4290 |
const auto v_hi = BitCast(d32, ShiftRight<16>(v)); |
| 4291 |
|
| 4292 |
return MulAdd(cnst2_16_flt, ConvertTo(df, v_hi), ConvertTo(df, v_lo)); |
| 4293 |
#endif |
| 4294 |
} |
| 4295 |
|
| 4296 |
HWY_API Vec256<double> ConvertTo(HWY_MAYBE_UNUSED Full256<double> dd, |
| 4297 |
const Vec256<uint64_t> v) { |
| 4298 |
#if HWY_TARGET <= HWY_AVX3 |
| 4299 |
return Vec256<double>{_mm256_cvtepu64_pd(v.raw)}; |
| 4300 |
#else |
| 4301 |
|
| 4302 |
const RebindToUnsigned<decltype(dd)> d64; |
| 4303 |
using VU = VFromD<decltype(d64)>; |
| 4304 |
|
| 4305 |
const VU msk_lo = Set(d64, 0xFFFFFFFFULL); |
| 4306 |
const auto cnst2_32_dbl = Set(dd, 4294967296.0); |
| 4307 |
|
| 4308 |
|
| 4309 |
const VU v_lo = And(v, msk_lo); |
| 4310 |
const VU v_hi = ShiftRight<32>(v); |
| 4311 |
|
| 4312 |
auto uint64_to_double256_fast = [&dd](Vec256<uint64_t> w) HWY_ATTR { |
| 4313 |
w = Or(w, Vec256<uint64_t>{ |
| 4314 |
detail::BitCastToInteger(Set(dd, 0x0010000000000000).raw)}); |
| 4315 |
return BitCast(dd, w) - Set(dd, 0x0010000000000000); |
| 4316 |
}; |
| 4317 |
|
| 4318 |
const auto v_lo_dbl = uint64_to_double256_fast(v_lo); |
| 4319 |
return MulAdd(cnst2_32_dbl, uint64_to_double256_fast(v_hi), v_lo_dbl); |
| 4320 |
#endif |
| 4321 |
} |
| 4322 |
|
| 4323 |
|
| 4324 |
HWY_API Vec256<int32_t> ConvertTo(Full256<int32_t> d, const Vec256<float> v) { |
| 4325 |
return detail::FixConversionOverflow(d, v, _mm256_cvttps_epi32(v.raw)); |
| 4326 |
} |
| 4327 |
|
| 4328 |
HWY_API Vec256<int64_t> ConvertTo(Full256<int64_t> di, const Vec256<double> v) { |
| 4329 |
#if HWY_TARGET <= HWY_AVX3 |
| 4330 |
return detail::FixConversionOverflow(di, v, _mm256_cvttpd_epi64(v.raw)); |
| 4331 |
#else |
| 4332 |
using VI = decltype(Zero(di)); |
| 4333 |
const VI k0 = Zero(di); |
| 4334 |
const VI k1 = Set(di, 1); |
| 4335 |
const VI k51 = Set(di, 51); |
| 4336 |
|
| 4337 |
|
| 4338 |
const VI biased_exp = ShiftRight<52>(BitCast(di, v)) & Set(di, 0x7FF); |
| 4339 |
const VI exp = biased_exp - Set(di, 0x3FF); |
| 4340 |
const auto in_range = exp < Set(di, 63); |
| 4341 |
|
| 4342 |
|
| 4343 |
|
| 4344 |
|
| 4345 |
|
| 4346 |
|
| 4347 |
|
| 4348 |
const VI shift_mnt = Max(k51 - exp, k0); |
| 4349 |
const VI shift_int = Max(exp - k51, k0); |
| 4350 |
const VI mantissa = BitCast(di, v) & Set(di, (1ULL << 52) - 1); |
| 4351 |
|
| 4352 |
const VI int52 = (mantissa | Set(di, 1ULL << 52)) >> (shift_mnt + k1); |
| 4353 |
|
| 4354 |
const VI shifted = int52 << shift_int; |
| 4355 |
|
| 4356 |
const VI restored = shifted | ((mantissa & k1) << (shift_int - k1)); |
| 4357 |
|
| 4358 |
|
| 4359 |
const VI sign_mask = BroadcastSignBit(BitCast(di, v)); |
| 4360 |
const VI limit = Set(di, LimitsMax<int64_t>()) - sign_mask; |
| 4361 |
const VI magnitude = IfThenElse(in_range, restored, limit); |
| 4362 |
|
| 4363 |
|
| 4364 |
return (magnitude ^ sign_mask) - sign_mask; |
| 4365 |
#endif |
| 4366 |
} |
| 4367 |
|
| 4368 |
HWY_API Vec256<int32_t> NearestInt(const Vec256<float> v) { |
| 4369 |
const Full256<int32_t> di; |
| 4370 |
return detail::FixConversionOverflow(di, v, _mm256_cvtps_epi32(v.raw)); |
| 4371 |
} |
| 4372 |
|
| 4373 |
|
| 4374 |
HWY_API Vec256<float> PromoteTo(Full256<float> df32, |
| 4375 |
const Vec128<float16_t> v) { |
| 4376 |
#ifdef HWY_DISABLE_F16C |
| 4377 |
const RebindToSigned<decltype(df32)> di32; |
| 4378 |
const RebindToUnsigned<decltype(df32)> du32; |
| 4379 |
|
| 4380 |
const auto bits16 = PromoteTo(du32, Vec128<uint16_t>{v.raw}); |
| 4381 |
const auto sign = ShiftRight<15>(bits16); |
| 4382 |
const auto biased_exp = ShiftRight<10>(bits16) & Set(du32, 0x1F); |
| 4383 |
const auto mantissa = bits16 & Set(du32, 0x3FF); |
| 4384 |
const auto subnormal = |
| 4385 |
BitCast(du32, ConvertTo(df32, BitCast(di32, mantissa)) * |
| 4386 |
Set(df32, 1.0f / 16384 / 1024)); |
| 4387 |
|
| 4388 |
const auto biased_exp32 = biased_exp + Set(du32, 127 - 15); |
| 4389 |
const auto mantissa32 = ShiftLeft<23 - 10>(mantissa); |
| 4390 |
const auto normal = ShiftLeft<23>(biased_exp32) | mantissa32; |
| 4391 |
const auto bits32 = IfThenElse(biased_exp == Zero(du32), subnormal, normal); |
| 4392 |
return BitCast(df32, ShiftLeft<31>(sign) | bits32); |
| 4393 |
#else |
| 4394 |
(void)df32; |
| 4395 |
return Vec256<float>{_mm256_cvtph_ps(v.raw)}; |
| 4396 |
#endif |
| 4397 |
} |
| 4398 |
|
| 4399 |
HWY_API Vec256<float> PromoteTo(Full256<float> df32, |
| 4400 |
const Vec128<bfloat16_t> v) { |
| 4401 |
const Rebind<uint16_t, decltype(df32)> du16; |
| 4402 |
const RebindToSigned<decltype(df32)> di32; |
| 4403 |
return BitCast(df32, ShiftLeft<16>(PromoteTo(di32, BitCast(du16, v)))); |
| 4404 |
} |
| 4405 |
|
| 4406 |
|
| 4407 |
|
| 4408 |
#if !defined(HWY_DISABLE_PCLMUL_AES) |
| 4409 |
|
| 4410 |
|
| 4411 |
#ifdef HWY_NATIVE_AES |
| 4412 |
#undef HWY_NATIVE_AES |
| 4413 |
#else |
| 4414 |
#define HWY_NATIVE_AES |
| 4415 |
#endif |
| 4416 |
|
| 4417 |
HWY_API Vec256<uint8_t> AESRound(Vec256<uint8_t> state, |
| 4418 |
Vec256<uint8_t> round_key) { |
| 4419 |
#if HWY_TARGET == HWY_AVX3_DL |
| 4420 |
return Vec256<uint8_t>{_mm256_aesenc_epi128(state.raw, round_key.raw)}; |
| 4421 |
#else |
| 4422 |
const Full256<uint8_t> d; |
| 4423 |
const Half<decltype(d)> d2; |
| 4424 |
return Combine(d, AESRound(UpperHalf(d2, state), UpperHalf(d2, round_key)), |
| 4425 |
AESRound(LowerHalf(state), LowerHalf(round_key))); |
| 4426 |
#endif |
| 4427 |
} |
| 4428 |
|
| 4429 |
HWY_API Vec256<uint8_t> AESLastRound(Vec256<uint8_t> state, |
| 4430 |
Vec256<uint8_t> round_key) { |
| 4431 |
#if HWY_TARGET == HWY_AVX3_DL |
| 4432 |
return Vec256<uint8_t>{_mm256_aesenclast_epi128(state.raw, round_key.raw)}; |
| 4433 |
#else |
| 4434 |
const Full256<uint8_t> d; |
| 4435 |
const Half<decltype(d)> d2; |
| 4436 |
return Combine(d, |
| 4437 |
AESLastRound(UpperHalf(d2, state), UpperHalf(d2, round_key)), |
| 4438 |
AESLastRound(LowerHalf(state), LowerHalf(round_key))); |
| 4439 |
#endif |
| 4440 |
} |
| 4441 |
|
| 4442 |
HWY_API Vec256<uint64_t> CLMulLower(Vec256<uint64_t> a, Vec256<uint64_t> b) { |
| 4443 |
#if HWY_TARGET == HWY_AVX3_DL |
| 4444 |
return Vec256<uint64_t>{_mm256_clmulepi64_epi128(a.raw, b.raw, 0x00)}; |
| 4445 |
#else |
| 4446 |
const Full256<uint64_t> d; |
| 4447 |
const Half<decltype(d)> d2; |
| 4448 |
return Combine(d, CLMulLower(UpperHalf(d2, a), UpperHalf(d2, b)), |
| 4449 |
CLMulLower(LowerHalf(a), LowerHalf(b))); |
| 4450 |
#endif |
| 4451 |
} |
| 4452 |
|
| 4453 |
HWY_API Vec256<uint64_t> CLMulUpper(Vec256<uint64_t> a, Vec256<uint64_t> b) { |
| 4454 |
#if HWY_TARGET == HWY_AVX3_DL |
| 4455 |
return Vec256<uint64_t>{_mm256_clmulepi64_epi128(a.raw, b.raw, 0x11)}; |
| 4456 |
#else |
| 4457 |
const Full256<uint64_t> d; |
| 4458 |
const Half<decltype(d)> d2; |
| 4459 |
return Combine(d, CLMulUpper(UpperHalf(d2, a), UpperHalf(d2, b)), |
| 4460 |
CLMulUpper(LowerHalf(a), LowerHalf(b))); |
| 4461 |
#endif |
| 4462 |
} |
| 4463 |
|
| 4464 |
#endif |
| 4465 |
|
| 4466 |
|
| 4467 |
|
| 4468 |
|
| 4469 |
template <typename T, typename T2> |
| 4470 |
HWY_API Vec256<T> Iota(const Full256<T> d, const T2 first) { |
| 4471 |
HWY_ALIGN T lanes[32 / sizeof(T)]; |
| 4472 |
for (size_t i = 0; i < 32 / sizeof(T); ++i) { |
| 4473 |
lanes[i] = |
| 4474 |
AddWithWraparound(hwy::IsFloatTag<T>(), static_cast<T>(first), i); |
| 4475 |
} |
| 4476 |
return Load(d, lanes); |
| 4477 |
} |
| 4478 |
|
| 4479 |
#if HWY_TARGET <= HWY_AVX3 |
| 4480 |
|
| 4481 |
|
| 4482 |
|
| 4483 |
|
| 4484 |
template <typename T> |
| 4485 |
HWY_API Mask256<T> LoadMaskBits(const Full256<T> , |
| 4486 |
const uint8_t* HWY_RESTRICT bits) { |
| 4487 |
constexpr size_t N = 32 / sizeof(T); |
| 4488 |
constexpr size_t kNumBytes = (N + 7) / 8; |
| 4489 |
|
| 4490 |
uint64_t mask_bits = 0; |
| 4491 |
CopyBytes<kNumBytes>(bits, &mask_bits); |
| 4492 |
|
| 4493 |
if (N < 8) { |
| 4494 |
mask_bits &= (1ull << N) - 1; |
| 4495 |
} |
| 4496 |
|
| 4497 |
return Mask256<T>::FromBits(mask_bits); |
| 4498 |
} |
| 4499 |
|
| 4500 |
|
| 4501 |
|
| 4502 |
|
| 4503 |
template <typename T> |
| 4504 |
HWY_API size_t StoreMaskBits(const Full256<T> , const Mask256<T> mask, |
| 4505 |
uint8_t* bits) { |
| 4506 |
constexpr size_t N = 32 / sizeof(T); |
| 4507 |
constexpr size_t kNumBytes = (N + 7) / 8; |
| 4508 |
|
| 4509 |
CopyBytes<kNumBytes>(&mask.raw, bits); |
| 4510 |
|
| 4511 |
|
| 4512 |
if (N < 8) { |
| 4513 |
const int mask_bits = static_cast<int>((1ull << N) - 1); |
| 4514 |
bits[0] = static_cast<uint8_t>(bits[0] & mask_bits); |
| 4515 |
} |
| 4516 |
return kNumBytes; |
| 4517 |
} |
| 4518 |
|
| 4519 |
|
| 4520 |
|
| 4521 |
template <typename T> |
| 4522 |
HWY_API size_t CountTrue(const Full256<T> , const Mask256<T> mask) { |
| 4523 |
return PopCount(static_cast<uint64_t>(mask.raw)); |
| 4524 |
} |
| 4525 |
|
| 4526 |
template <typename T> |
| 4527 |
HWY_API size_t FindKnownFirstTrue(const Full256<T> , |
| 4528 |
const Mask256<T> mask) { |
| 4529 |
return Num0BitsBelowLS1Bit_Nonzero32(mask.raw); |
| 4530 |
} |
| 4531 |
|
| 4532 |
template <typename T> |
| 4533 |
HWY_API intptr_t FindFirstTrue(const Full256<T> d, const Mask256<T> mask) { |
| 4534 |
return mask.raw ? static_cast<intptr_t>(FindKnownFirstTrue(d, mask)) |
| 4535 |
: intptr_t{-1}; |
| 4536 |
} |
| 4537 |
|
| 4538 |
|
| 4539 |
|
| 4540 |
namespace detail { |
| 4541 |
|
| 4542 |
template <typename T> |
| 4543 |
HWY_INLINE bool AllFalse(hwy::SizeTag<1> , const Mask256<T> mask) { |
| 4544 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 4545 |
return _kortestz_mask32_u8(mask.raw, mask.raw); |
| 4546 |
#else |
| 4547 |
return mask.raw == 0; |
| 4548 |
#endif |
| 4549 |
} |
| 4550 |
template <typename T> |
| 4551 |
HWY_INLINE bool AllFalse(hwy::SizeTag<2> , const Mask256<T> mask) { |
| 4552 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 4553 |
return _kortestz_mask16_u8(mask.raw, mask.raw); |
| 4554 |
#else |
| 4555 |
return mask.raw == 0; |
| 4556 |
#endif |
| 4557 |
} |
| 4558 |
template <typename T> |
| 4559 |
HWY_INLINE bool AllFalse(hwy::SizeTag<4> , const Mask256<T> mask) { |
| 4560 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 4561 |
return _kortestz_mask8_u8(mask.raw, mask.raw); |
| 4562 |
#else |
| 4563 |
return mask.raw == 0; |
| 4564 |
#endif |
| 4565 |
} |
| 4566 |
template <typename T> |
| 4567 |
HWY_INLINE bool AllFalse(hwy::SizeTag<8> , const Mask256<T> mask) { |
| 4568 |
return (uint64_t{mask.raw} & 0xF) == 0; |
| 4569 |
} |
| 4570 |
|
| 4571 |
} |
| 4572 |
|
| 4573 |
template <typename T> |
| 4574 |
HWY_API bool AllFalse(const Full256<T> , const Mask256<T> mask) { |
| 4575 |
return detail::AllFalse(hwy::SizeTag<sizeof(T)>(), mask); |
| 4576 |
} |
| 4577 |
|
| 4578 |
namespace detail { |
| 4579 |
|
| 4580 |
template <typename T> |
| 4581 |
HWY_INLINE bool AllTrue(hwy::SizeTag<1> , const Mask256<T> mask) { |
| 4582 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 4583 |
return _kortestc_mask32_u8(mask.raw, mask.raw); |
| 4584 |
#else |
| 4585 |
return mask.raw == 0xFFFFFFFFu; |
| 4586 |
#endif |
| 4587 |
} |
| 4588 |
template <typename T> |
| 4589 |
HWY_INLINE bool AllTrue(hwy::SizeTag<2> , const Mask256<T> mask) { |
| 4590 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 4591 |
return _kortestc_mask16_u8(mask.raw, mask.raw); |
| 4592 |
#else |
| 4593 |
return mask.raw == 0xFFFFu; |
| 4594 |
#endif |
| 4595 |
} |
| 4596 |
template <typename T> |
| 4597 |
HWY_INLINE bool AllTrue(hwy::SizeTag<4> , const Mask256<T> mask) { |
| 4598 |
#if HWY_COMPILER_HAS_MASK_INTRINSICS |
| 4599 |
return _kortestc_mask8_u8(mask.raw, mask.raw); |
| 4600 |
#else |
| 4601 |
return mask.raw == 0xFFu; |
| 4602 |
#endif |
| 4603 |
} |
| 4604 |
template <typename T> |
| 4605 |
HWY_INLINE bool AllTrue(hwy::SizeTag<8> , const Mask256<T> mask) { |
| 4606 |
|
| 4607 |
return mask.raw == 0xFu; |
| 4608 |
} |
| 4609 |
|
| 4610 |
} |
| 4611 |
|
| 4612 |
template <typename T> |
| 4613 |
HWY_API bool AllTrue(const Full256<T> , const Mask256<T> mask) { |
| 4614 |
return detail::AllTrue(hwy::SizeTag<sizeof(T)>(), mask); |
| 4615 |
} |
| 4616 |
|
| 4617 |
|
| 4618 |
|
| 4619 |
|
| 4620 |
|
| 4621 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 4622 |
HWY_API Vec256<T> Compress(Vec256<T> v, Mask256<T> mask) { |
| 4623 |
return Vec256<T>{_mm256_maskz_compress_epi32(mask.raw, v.raw)}; |
| 4624 |
} |
| 4625 |
|
| 4626 |
HWY_API Vec256<float> Compress(Vec256<float> v, Mask256<float> mask) { |
| 4627 |
return Vec256<float>{_mm256_maskz_compress_ps(mask.raw, v.raw)}; |
| 4628 |
} |
| 4629 |
|
| 4630 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 4631 |
HWY_API Vec256<T> Compress(Vec256<T> v, Mask256<T> mask) { |
| 4632 |
|
| 4633 |
alignas(16) constexpr uint64_t packed_array[16] = { |
| 4634 |
|
| 4635 |
0x00003210, 0x00003210, 0x00003201, 0x00003210, 0x00003102, 0x00003120, |
| 4636 |
0x00003021, 0x00003210, 0x00002103, 0x00002130, 0x00002031, 0x00002310, |
| 4637 |
0x00001032, 0x00001320, 0x00000321, 0x00003210}; |
| 4638 |
|
| 4639 |
|
| 4640 |
|
| 4641 |
const Full256<T> d; |
| 4642 |
const RebindToUnsigned<decltype(d)> du64; |
| 4643 |
const auto packed = Set(du64, packed_array[mask.raw]); |
| 4644 |
alignas(64) constexpr uint64_t shifts[4] = {0, 4, 8, 12}; |
| 4645 |
const auto indices = Indices256<T>{(packed >> Load(du64, shifts)).raw}; |
| 4646 |
return TableLookupLanes(v, indices); |
| 4647 |
} |
| 4648 |
|
| 4649 |
|
| 4650 |
|
| 4651 |
|
| 4652 |
|
| 4653 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 4654 |
HWY_API Vec256<T> CompressNot(Vec256<T> v, Mask256<T> mask) { |
| 4655 |
|
| 4656 |
alignas(16) constexpr uint64_t packed_array[16] = { |
| 4657 |
|
| 4658 |
0x00003210, 0x00000321, 0x00001320, 0x00001032, 0x00002310, 0x00002031, |
| 4659 |
0x00002130, 0x00002103, 0x00003210, 0x00003021, 0x00003120, 0x00003102, |
| 4660 |
0x00003210, 0x00003201, 0x00003210, 0x00003210}; |
| 4661 |
|
| 4662 |
|
| 4663 |
|
| 4664 |
const Full256<T> d; |
| 4665 |
const RebindToUnsigned<decltype(d)> du64; |
| 4666 |
const auto packed = Set(du64, packed_array[mask.raw]); |
| 4667 |
alignas(32) constexpr uint64_t shifts[4] = {0, 4, 8, 12}; |
| 4668 |
const auto indices = Indices256<T>{(packed >> Load(du64, shifts)).raw}; |
| 4669 |
return TableLookupLanes(v, indices); |
| 4670 |
} |
| 4671 |
|
| 4672 |
|
| 4673 |
|
| 4674 |
|
| 4675 |
|
| 4676 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 4677 |
HWY_API size_t CompressStore(Vec256<T> v, Mask256<T> mask, Full256<T> , |
| 4678 |
T* HWY_RESTRICT unaligned) { |
| 4679 |
_mm256_mask_compressstoreu_epi32(unaligned, mask.raw, v.raw); |
| 4680 |
const size_t count = PopCount(uint64_t{mask.raw}); |
| 4681 |
detail::MaybeUnpoison(unaligned, count); |
| 4682 |
return count; |
| 4683 |
} |
| 4684 |
|
| 4685 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 4686 |
HWY_API size_t CompressStore(Vec256<T> v, Mask256<T> mask, Full256<T> , |
| 4687 |
T* HWY_RESTRICT unaligned) { |
| 4688 |
_mm256_mask_compressstoreu_epi64(unaligned, mask.raw, v.raw); |
| 4689 |
const size_t count = PopCount(uint64_t{mask.raw} & 0xFull); |
| 4690 |
detail::MaybeUnpoison(unaligned, count); |
| 4691 |
return count; |
| 4692 |
} |
| 4693 |
|
| 4694 |
HWY_API size_t CompressStore(Vec256<float> v, Mask256<float> mask, |
| 4695 |
Full256<float> , |
| 4696 |
float* HWY_RESTRICT unaligned) { |
| 4697 |
_mm256_mask_compressstoreu_ps(unaligned, mask.raw, v.raw); |
| 4698 |
const size_t count = PopCount(uint64_t{mask.raw}); |
| 4699 |
detail::MaybeUnpoison(unaligned, count); |
| 4700 |
return count; |
| 4701 |
} |
| 4702 |
|
| 4703 |
HWY_API size_t CompressStore(Vec256<double> v, Mask256<double> mask, |
| 4704 |
Full256<double> , |
| 4705 |
double* HWY_RESTRICT unaligned) { |
| 4706 |
_mm256_mask_compressstoreu_pd(unaligned, mask.raw, v.raw); |
| 4707 |
const size_t count = PopCount(uint64_t{mask.raw} & 0xFull); |
| 4708 |
detail::MaybeUnpoison(unaligned, count); |
| 4709 |
return count; |
| 4710 |
} |
| 4711 |
|
| 4712 |
|
| 4713 |
|
| 4714 |
template <typename T> |
| 4715 |
HWY_API size_t CompressBlendedStore(Vec256<T> v, Mask256<T> m, Full256<T> d, |
| 4716 |
T* HWY_RESTRICT unaligned) { |
| 4717 |
if (HWY_TARGET == HWY_AVX3_DL || sizeof(T) > 2) { |
| 4718 |
|
| 4719 |
|
| 4720 |
return CompressStore(v, m, d, unaligned); |
| 4721 |
} else { |
| 4722 |
const size_t count = CountTrue(d, m); |
| 4723 |
BlendedStore(Compress(v, m), FirstN(d, count), d, unaligned); |
| 4724 |
detail::MaybeUnpoison(unaligned, count); |
| 4725 |
return count; |
| 4726 |
} |
| 4727 |
} |
| 4728 |
|
| 4729 |
|
| 4730 |
|
| 4731 |
template <typename T, HWY_IF_NOT_LANE_SIZE(T, 1)> |
| 4732 |
HWY_API size_t CompressBitsStore(Vec256<T> v, const uint8_t* HWY_RESTRICT bits, |
| 4733 |
Full256<T> d, T* HWY_RESTRICT unaligned) { |
| 4734 |
return CompressStore(v, LoadMaskBits(d, bits), d, unaligned); |
| 4735 |
} |
| 4736 |
|
| 4737 |
#else |
| 4738 |
|
| 4739 |
|
| 4740 |
|
| 4741 |
namespace detail { |
| 4742 |
|
| 4743 |
|
| 4744 |
template <typename T, HWY_IF_LANE_SIZE(T, 1)> |
| 4745 |
HWY_INLINE Mask256<T> LoadMaskBits256(Full256<T> d, uint64_t mask_bits) { |
| 4746 |
const RebindToUnsigned<decltype(d)> du; |
| 4747 |
const Repartition<uint32_t, decltype(d)> du32; |
| 4748 |
const auto vbits = BitCast(du, Set(du32, static_cast<uint32_t>(mask_bits))); |
| 4749 |
|
| 4750 |
|
| 4751 |
const Repartition<uint64_t, decltype(d)> du64; |
| 4752 |
alignas(32) constexpr uint64_t kRep8[4] = { |
| 4753 |
0x0000000000000000ull, 0x0101010101010101ull, 0x0202020202020202ull, |
| 4754 |
0x0303030303030303ull}; |
| 4755 |
const auto rep8 = TableLookupBytes(vbits, BitCast(du, Load(du64, kRep8))); |
| 4756 |
|
| 4757 |
alignas(32) constexpr uint8_t kBit[16] = {1, 2, 4, 8, 16, 32, 64, 128, |
| 4758 |
1, 2, 4, 8, 16, 32, 64, 128}; |
| 4759 |
return RebindMask(d, TestBit(rep8, LoadDup128(du, kBit))); |
| 4760 |
} |
| 4761 |
|
| 4762 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 4763 |
HWY_INLINE Mask256<T> LoadMaskBits256(Full256<T> d, uint64_t mask_bits) { |
| 4764 |
const RebindToUnsigned<decltype(d)> du; |
| 4765 |
alignas(32) constexpr uint16_t kBit[16] = { |
| 4766 |
1, 2, 4, 8, 16, 32, 64, 128, |
| 4767 |
0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000}; |
| 4768 |
const auto vmask_bits = Set(du, static_cast<uint16_t>(mask_bits)); |
| 4769 |
return RebindMask(d, TestBit(vmask_bits, Load(du, kBit))); |
| 4770 |
} |
| 4771 |
|
| 4772 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 4773 |
HWY_INLINE Mask256<T> LoadMaskBits256(Full256<T> d, uint64_t mask_bits) { |
| 4774 |
const RebindToUnsigned<decltype(d)> du; |
| 4775 |
alignas(32) constexpr uint32_t kBit[8] = {1, 2, 4, 8, 16, 32, 64, 128}; |
| 4776 |
const auto vmask_bits = Set(du, static_cast<uint32_t>(mask_bits)); |
| 4777 |
return RebindMask(d, TestBit(vmask_bits, Load(du, kBit))); |
| 4778 |
} |
| 4779 |
|
| 4780 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 4781 |
HWY_INLINE Mask256<T> LoadMaskBits256(Full256<T> d, uint64_t mask_bits) { |
| 4782 |
const RebindToUnsigned<decltype(d)> du; |
| 4783 |
alignas(32) constexpr uint64_t kBit[8] = {1, 2, 4, 8}; |
| 4784 |
return RebindMask(d, TestBit(Set(du, mask_bits), Load(du, kBit))); |
| 4785 |
} |
| 4786 |
|
| 4787 |
} |
| 4788 |
|
| 4789 |
|
| 4790 |
template <typename T> |
| 4791 |
HWY_API Mask256<T> LoadMaskBits(Full256<T> d, |
| 4792 |
const uint8_t* HWY_RESTRICT bits) { |
| 4793 |
constexpr size_t N = 32 / sizeof(T); |
| 4794 |
constexpr size_t kNumBytes = (N + 7) / 8; |
| 4795 |
|
| 4796 |
uint64_t mask_bits = 0; |
| 4797 |
CopyBytes<kNumBytes>(bits, &mask_bits); |
| 4798 |
|
| 4799 |
if (N < 8) { |
| 4800 |
mask_bits &= (1ull << N) - 1; |
| 4801 |
} |
| 4802 |
|
| 4803 |
return detail::LoadMaskBits256(d, mask_bits); |
| 4804 |
} |
| 4805 |
|
| 4806 |
|
| 4807 |
|
| 4808 |
namespace detail { |
| 4809 |
|
| 4810 |
template <typename T, HWY_IF_LANE_SIZE(T, 1)> |
| 4811 |
HWY_INLINE uint64_t BitsFromMask(const Mask256<T> mask) { |
| 4812 |
const Full256<T> d; |
| 4813 |
const Full256<uint8_t> d8; |
| 4814 |
const auto sign_bits = BitCast(d8, VecFromMask(d, mask)).raw; |
| 4815 |
|
| 4816 |
return static_cast<uint32_t>(_mm256_movemask_epi8(sign_bits)); |
| 4817 |
} |
| 4818 |
|
| 4819 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 4820 |
HWY_INLINE uint64_t BitsFromMask(const Mask256<T> mask) { |
| 4821 |
#if HWY_ARCH_X86_64 |
| 4822 |
const Full256<T> d; |
| 4823 |
const Full256<uint8_t> d8; |
| 4824 |
const Mask256<uint8_t> mask8 = MaskFromVec(BitCast(d8, VecFromMask(d, mask))); |
| 4825 |
const uint64_t sign_bits8 = BitsFromMask(mask8); |
| 4826 |
|
| 4827 |
|
| 4828 |
return _pext_u64(sign_bits8, 0xAAAAAAAAull); |
| 4829 |
#else |
| 4830 |
|
| 4831 |
|
| 4832 |
|
| 4833 |
const auto sign_bits = _mm256_packs_epi16(mask.raw, _mm256_setzero_si256()); |
| 4834 |
|
| 4835 |
const auto compressed = |
| 4836 |
_mm256_permute4x64_epi64(sign_bits, _MM_SHUFFLE(3, 1, 2, 0)); |
| 4837 |
return static_cast<unsigned>(_mm256_movemask_epi8(compressed)); |
| 4838 |
#endif |
| 4839 |
} |
| 4840 |
|
| 4841 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 4842 |
HWY_INLINE uint64_t BitsFromMask(const Mask256<T> mask) { |
| 4843 |
const Full256<T> d; |
| 4844 |
const Full256<float> df; |
| 4845 |
const auto sign_bits = BitCast(df, VecFromMask(d, mask)).raw; |
| 4846 |
return static_cast<unsigned>(_mm256_movemask_ps(sign_bits)); |
| 4847 |
} |
| 4848 |
|
| 4849 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 4850 |
HWY_INLINE uint64_t BitsFromMask(const Mask256<T> mask) { |
| 4851 |
const Full256<T> d; |
| 4852 |
const Full256<double> df; |
| 4853 |
const auto sign_bits = BitCast(df, VecFromMask(d, mask)).raw; |
| 4854 |
return static_cast<unsigned>(_mm256_movemask_pd(sign_bits)); |
| 4855 |
} |
| 4856 |
|
| 4857 |
} |
| 4858 |
|
| 4859 |
|
| 4860 |
template <typename T> |
| 4861 |
HWY_API size_t StoreMaskBits(const Full256<T> , const Mask256<T> mask, |
| 4862 |
uint8_t* bits) { |
| 4863 |
constexpr size_t N = 32 / sizeof(T); |
| 4864 |
constexpr size_t kNumBytes = (N + 7) / 8; |
| 4865 |
|
| 4866 |
const uint64_t mask_bits = detail::BitsFromMask(mask); |
| 4867 |
CopyBytes<kNumBytes>(&mask_bits, bits); |
| 4868 |
return kNumBytes; |
| 4869 |
} |
| 4870 |
|
| 4871 |
|
| 4872 |
|
| 4873 |
|
| 4874 |
|
| 4875 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 4876 |
HWY_API bool AllFalse(const Full256<T> d, const Mask256<T> mask) { |
| 4877 |
const Repartition<uint8_t, decltype(d)> d8; |
| 4878 |
const Mask256<uint8_t> mask8 = MaskFromVec(BitCast(d8, VecFromMask(d, mask))); |
| 4879 |
return detail::BitsFromMask(mask8) == 0; |
| 4880 |
} |
| 4881 |
|
| 4882 |
template <typename T, HWY_IF_NOT_LANE_SIZE(T, 2)> |
| 4883 |
HWY_API bool AllFalse(const Full256<T> , const Mask256<T> mask) { |
| 4884 |
|
| 4885 |
return detail::BitsFromMask(mask) == 0; |
| 4886 |
} |
| 4887 |
|
| 4888 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 4889 |
HWY_API bool AllTrue(const Full256<T> d, const Mask256<T> mask) { |
| 4890 |
const Repartition<uint8_t, decltype(d)> d8; |
| 4891 |
const Mask256<uint8_t> mask8 = MaskFromVec(BitCast(d8, VecFromMask(d, mask))); |
| 4892 |
return detail::BitsFromMask(mask8) == (1ull << 32) - 1; |
| 4893 |
} |
| 4894 |
template <typename T, HWY_IF_NOT_LANE_SIZE(T, 2)> |
| 4895 |
HWY_API bool AllTrue(const Full256<T> , const Mask256<T> mask) { |
| 4896 |
constexpr uint64_t kAllBits = (1ull << (32 / sizeof(T))) - 1; |
| 4897 |
return detail::BitsFromMask(mask) == kAllBits; |
| 4898 |
} |
| 4899 |
|
| 4900 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 4901 |
HWY_API size_t CountTrue(const Full256<T> d, const Mask256<T> mask) { |
| 4902 |
const Repartition<uint8_t, decltype(d)> d8; |
| 4903 |
const Mask256<uint8_t> mask8 = MaskFromVec(BitCast(d8, VecFromMask(d, mask))); |
| 4904 |
return PopCount(detail::BitsFromMask(mask8)) >> 1; |
| 4905 |
} |
| 4906 |
template <typename T, HWY_IF_NOT_LANE_SIZE(T, 2)> |
| 4907 |
HWY_API size_t CountTrue(const Full256<T> , const Mask256<T> mask) { |
| 4908 |
return PopCount(detail::BitsFromMask(mask)); |
| 4909 |
} |
| 4910 |
|
| 4911 |
template <typename T> |
| 4912 |
HWY_API size_t FindKnownFirstTrue(const Full256<T> , |
| 4913 |
const Mask256<T> mask) { |
| 4914 |
const uint64_t mask_bits = detail::BitsFromMask(mask); |
| 4915 |
return Num0BitsBelowLS1Bit_Nonzero64(mask_bits); |
| 4916 |
} |
| 4917 |
|
| 4918 |
template <typename T> |
| 4919 |
HWY_API intptr_t FindFirstTrue(const Full256<T> , |
| 4920 |
const Mask256<T> mask) { |
| 4921 |
const uint64_t mask_bits = detail::BitsFromMask(mask); |
| 4922 |
return mask_bits ? intptr_t(Num0BitsBelowLS1Bit_Nonzero64(mask_bits)) : -1; |
| 4923 |
} |
| 4924 |
|
| 4925 |
|
| 4926 |
|
| 4927 |
namespace detail { |
| 4928 |
|
| 4929 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 4930 |
HWY_INLINE Vec256<uint32_t> IndicesFromBits(Full256<T> d, uint64_t mask_bits) { |
| 4931 |
const RebindToUnsigned<decltype(d)> d32; |
| 4932 |
|
| 4933 |
|
| 4934 |
|
| 4935 |
|
| 4936 |
|
| 4937 |
alignas(16) constexpr uint32_t packed_array[256] = { |
| 4938 |
|
| 4939 |
0x76543210, 0x76543218, 0x76543209, 0x76543298, 0x7654310a, 0x765431a8, |
| 4940 |
0x765430a9, 0x76543a98, 0x7654210b, 0x765421b8, 0x765420b9, 0x76542b98, |
| 4941 |
0x765410ba, 0x76541ba8, 0x76540ba9, 0x7654ba98, 0x7653210c, 0x765321c8, |
| 4942 |
0x765320c9, 0x76532c98, 0x765310ca, 0x76531ca8, 0x76530ca9, 0x7653ca98, |
| 4943 |
0x765210cb, 0x76521cb8, 0x76520cb9, 0x7652cb98, 0x76510cba, 0x7651cba8, |
| 4944 |
0x7650cba9, 0x765cba98, 0x7643210d, 0x764321d8, 0x764320d9, 0x76432d98, |
| 4945 |
0x764310da, 0x76431da8, 0x76430da9, 0x7643da98, 0x764210db, 0x76421db8, |
| 4946 |
0x76420db9, 0x7642db98, 0x76410dba, 0x7641dba8, 0x7640dba9, 0x764dba98, |
| 4947 |
0x763210dc, 0x76321dc8, 0x76320dc9, 0x7632dc98, 0x76310dca, 0x7631dca8, |
| 4948 |
0x7630dca9, 0x763dca98, 0x76210dcb, 0x7621dcb8, 0x7620dcb9, 0x762dcb98, |
| 4949 |
0x7610dcba, 0x761dcba8, 0x760dcba9, 0x76dcba98, 0x7543210e, 0x754321e8, |
| 4950 |
0x754320e9, 0x75432e98, 0x754310ea, 0x75431ea8, 0x75430ea9, 0x7543ea98, |
| 4951 |
0x754210eb, 0x75421eb8, 0x75420eb9, 0x7542eb98, 0x75410eba, 0x7541eba8, |
| 4952 |
0x7540eba9, 0x754eba98, 0x753210ec, 0x75321ec8, 0x75320ec9, 0x7532ec98, |
| 4953 |
0x75310eca, 0x7531eca8, 0x7530eca9, 0x753eca98, 0x75210ecb, 0x7521ecb8, |
| 4954 |
0x7520ecb9, 0x752ecb98, 0x7510ecba, 0x751ecba8, 0x750ecba9, 0x75ecba98, |
| 4955 |
0x743210ed, 0x74321ed8, 0x74320ed9, 0x7432ed98, 0x74310eda, 0x7431eda8, |
| 4956 |
0x7430eda9, 0x743eda98, 0x74210edb, 0x7421edb8, 0x7420edb9, 0x742edb98, |
| 4957 |
0x7410edba, 0x741edba8, 0x740edba9, 0x74edba98, 0x73210edc, 0x7321edc8, |
| 4958 |
0x7320edc9, 0x732edc98, 0x7310edca, 0x731edca8, 0x730edca9, 0x73edca98, |
| 4959 |
0x7210edcb, 0x721edcb8, 0x720edcb9, 0x72edcb98, 0x710edcba, 0x71edcba8, |
| 4960 |
0x70edcba9, 0x7edcba98, 0x6543210f, 0x654321f8, 0x654320f9, 0x65432f98, |
| 4961 |
0x654310fa, 0x65431fa8, 0x65430fa9, 0x6543fa98, 0x654210fb, 0x65421fb8, |
| 4962 |
0x65420fb9, 0x6542fb98, 0x65410fba, 0x6541fba8, 0x6540fba9, 0x654fba98, |
| 4963 |
0x653210fc, 0x65321fc8, 0x65320fc9, 0x6532fc98, 0x65310fca, 0x6531fca8, |
| 4964 |
0x6530fca9, 0x653fca98, 0x65210fcb, 0x6521fcb8, 0x6520fcb9, 0x652fcb98, |
| 4965 |
0x6510fcba, 0x651fcba8, 0x650fcba9, 0x65fcba98, 0x643210fd, 0x64321fd8, |
| 4966 |
0x64320fd9, 0x6432fd98, 0x64310fda, 0x6431fda8, 0x6430fda9, 0x643fda98, |
| 4967 |
0x64210fdb, 0x6421fdb8, 0x6420fdb9, 0x642fdb98, 0x6410fdba, 0x641fdba8, |
| 4968 |
0x640fdba9, 0x64fdba98, 0x63210fdc, 0x6321fdc8, 0x6320fdc9, 0x632fdc98, |
| 4969 |
0x6310fdca, 0x631fdca8, 0x630fdca9, 0x63fdca98, 0x6210fdcb, 0x621fdcb8, |
| 4970 |
0x620fdcb9, 0x62fdcb98, 0x610fdcba, 0x61fdcba8, 0x60fdcba9, 0x6fdcba98, |
| 4971 |
0x543210fe, 0x54321fe8, 0x54320fe9, 0x5432fe98, 0x54310fea, 0x5431fea8, |
| 4972 |
0x5430fea9, 0x543fea98, 0x54210feb, 0x5421feb8, 0x5420feb9, 0x542feb98, |
| 4973 |
0x5410feba, 0x541feba8, 0x540feba9, 0x54feba98, 0x53210fec, 0x5321fec8, |
| 4974 |
0x5320fec9, 0x532fec98, 0x5310feca, 0x531feca8, 0x530feca9, 0x53feca98, |
| 4975 |
0x5210fecb, 0x521fecb8, 0x520fecb9, 0x52fecb98, 0x510fecba, 0x51fecba8, |
| 4976 |
0x50fecba9, 0x5fecba98, 0x43210fed, 0x4321fed8, 0x4320fed9, 0x432fed98, |
| 4977 |
0x4310feda, 0x431feda8, 0x430feda9, 0x43feda98, 0x4210fedb, 0x421fedb8, |
| 4978 |
0x420fedb9, 0x42fedb98, 0x410fedba, 0x41fedba8, 0x40fedba9, 0x4fedba98, |
| 4979 |
0x3210fedc, 0x321fedc8, 0x320fedc9, 0x32fedc98, 0x310fedca, 0x31fedca8, |
| 4980 |
0x30fedca9, 0x3fedca98, 0x210fedcb, 0x21fedcb8, 0x20fedcb9, 0x2fedcb98, |
| 4981 |
0x10fedcba, 0x1fedcba8, 0x0fedcba9, 0xfedcba98}; |
| 4982 |
|
| 4983 |
|
| 4984 |
|
| 4985 |
|
| 4986 |
|
| 4987 |
const auto packed = Set(d32, packed_array[mask_bits]); |
| 4988 |
alignas(32) constexpr uint32_t shifts[8] = {0, 4, 8, 12, 16, 20, 24, 28}; |
| 4989 |
return packed >> Load(d32, shifts); |
| 4990 |
} |
| 4991 |
|
| 4992 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 4993 |
HWY_INLINE Vec256<uint32_t> IndicesFromBits(Full256<T> d, uint64_t mask_bits) { |
| 4994 |
const Repartition<uint32_t, decltype(d)> d32; |
| 4995 |
|
| 4996 |
|
| 4997 |
|
| 4998 |
|
| 4999 |
alignas(32) constexpr uint32_t u32_indices[128] = { |
| 5000 |
|
| 5001 |
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, |
| 5002 |
10, 11, 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 4, 5, 6, 7, |
| 5003 |
12, 13, 0, 1, 2, 3, 6, 7, 8, 9, 12, 13, 2, 3, 6, 7, |
| 5004 |
10, 11, 12, 13, 0, 1, 6, 7, 8, 9, 10, 11, 12, 13, 6, 7, |
| 5005 |
14, 15, 0, 1, 2, 3, 4, 5, 8, 9, 14, 15, 2, 3, 4, 5, |
| 5006 |
10, 11, 14, 15, 0, 1, 4, 5, 8, 9, 10, 11, 14, 15, 4, 5, |
| 5007 |
12, 13, 14, 15, 0, 1, 2, 3, 8, 9, 12, 13, 14, 15, 2, 3, |
| 5008 |
10, 11, 12, 13, 14, 15, 0, 1, 8, 9, 10, 11, 12, 13, 14, 15}; |
| 5009 |
return Load(d32, u32_indices + 8 * mask_bits); |
| 5010 |
} |
| 5011 |
|
| 5012 |
template <typename T, HWY_IF_LANE_SIZE(T, 4)> |
| 5013 |
HWY_INLINE Vec256<uint32_t> IndicesFromNotBits(Full256<T> d, |
| 5014 |
uint64_t mask_bits) { |
| 5015 |
const RebindToUnsigned<decltype(d)> d32; |
| 5016 |
|
| 5017 |
|
| 5018 |
|
| 5019 |
|
| 5020 |
|
| 5021 |
alignas(16) constexpr uint32_t packed_array[256] = { |
| 5022 |
|
| 5023 |
0xfedcba98, 0x8fedcba9, 0x9fedcba8, 0x98fedcba, 0xafedcb98, 0xa8fedcb9, |
| 5024 |
0xa9fedcb8, 0xa98fedcb, 0xbfedca98, 0xb8fedca9, 0xb9fedca8, 0xb98fedca, |
| 5025 |
0xbafedc98, 0xba8fedc9, 0xba9fedc8, 0xba98fedc, 0xcfedba98, 0xc8fedba9, |
| 5026 |
0xc9fedba8, 0xc98fedba, 0xcafedb98, 0xca8fedb9, 0xca9fedb8, 0xca98fedb, |
| 5027 |
0xcbfeda98, 0xcb8feda9, 0xcb9feda8, 0xcb98feda, 0xcbafed98, 0xcba8fed9, |
| 5028 |
0xcba9fed8, 0xcba98fed, 0xdfecba98, 0xd8fecba9, 0xd9fecba8, 0xd98fecba, |
| 5029 |
0xdafecb98, 0xda8fecb9, 0xda9fecb8, 0xda98fecb, 0xdbfeca98, 0xdb8feca9, |
| 5030 |
0xdb9feca8, 0xdb98feca, 0xdbafec98, 0xdba8fec9, 0xdba9fec8, 0xdba98fec, |
| 5031 |
0xdcfeba98, 0xdc8feba9, 0xdc9feba8, 0xdc98feba, 0xdcafeb98, 0xdca8feb9, |
| 5032 |
0xdca9feb8, 0xdca98feb, 0xdcbfea98, 0xdcb8fea9, 0xdcb9fea8, 0xdcb98fea, |
| 5033 |
0xdcbafe98, 0xdcba8fe9, 0xdcba9fe8, 0xdcba98fe, 0xefdcba98, 0xe8fdcba9, |
| 5034 |
0xe9fdcba8, 0xe98fdcba, 0xeafdcb98, 0xea8fdcb9, 0xea9fdcb8, 0xea98fdcb, |
| 5035 |
0xebfdca98, 0xeb8fdca9, 0xeb9fdca8, 0xeb98fdca, 0xebafdc98, 0xeba8fdc9, |
| 5036 |
0xeba9fdc8, 0xeba98fdc, 0xecfdba98, 0xec8fdba9, 0xec9fdba8, 0xec98fdba, |
| 5037 |
0xecafdb98, 0xeca8fdb9, 0xeca9fdb8, 0xeca98fdb, 0xecbfda98, 0xecb8fda9, |
| 5038 |
0xecb9fda8, 0xecb98fda, 0xecbafd98, 0xecba8fd9, 0xecba9fd8, 0xecba98fd, |
| 5039 |
0xedfcba98, 0xed8fcba9, 0xed9fcba8, 0xed98fcba, 0xedafcb98, 0xeda8fcb9, |
| 5040 |
0xeda9fcb8, 0xeda98fcb, 0xedbfca98, 0xedb8fca9, 0xedb9fca8, 0xedb98fca, |
| 5041 |
0xedbafc98, 0xedba8fc9, 0xedba9fc8, 0xedba98fc, 0xedcfba98, 0xedc8fba9, |
| 5042 |
0xedc9fba8, 0xedc98fba, 0xedcafb98, 0xedca8fb9, 0xedca9fb8, 0xedca98fb, |
| 5043 |
0xedcbfa98, 0xedcb8fa9, 0xedcb9fa8, 0xedcb98fa, 0xedcbaf98, 0xedcba8f9, |
| 5044 |
0xedcba9f8, 0xedcba98f, 0xfedcba98, 0xf8edcba9, 0xf9edcba8, 0xf98edcba, |
| 5045 |
0xfaedcb98, 0xfa8edcb9, 0xfa9edcb8, 0xfa98edcb, 0xfbedca98, 0xfb8edca9, |
| 5046 |
0xfb9edca8, 0xfb98edca, 0xfbaedc98, 0xfba8edc9, 0xfba9edc8, 0xfba98edc, |
| 5047 |
0xfcedba98, 0xfc8edba9, 0xfc9edba8, 0xfc98edba, 0xfcaedb98, 0xfca8edb9, |
| 5048 |
0xfca9edb8, 0xfca98edb, 0xfcbeda98, 0xfcb8eda9, 0xfcb9eda8, 0xfcb98eda, |
| 5049 |
0xfcbaed98, 0xfcba8ed9, 0xfcba9ed8, 0xfcba98ed, 0xfdecba98, 0xfd8ecba9, |
| 5050 |
0xfd9ecba8, 0xfd98ecba, 0xfdaecb98, 0xfda8ecb9, 0xfda9ecb8, 0xfda98ecb, |
| 5051 |
0xfdbeca98, 0xfdb8eca9, 0xfdb9eca8, 0xfdb98eca, 0xfdbaec98, 0xfdba8ec9, |
| 5052 |
0xfdba9ec8, 0xfdba98ec, 0xfdceba98, 0xfdc8eba9, 0xfdc9eba8, 0xfdc98eba, |
| 5053 |
0xfdcaeb98, 0xfdca8eb9, 0xfdca9eb8, 0xfdca98eb, 0xfdcbea98, 0xfdcb8ea9, |
| 5054 |
0xfdcb9ea8, 0xfdcb98ea, 0xfdcbae98, 0xfdcba8e9, 0xfdcba9e8, 0xfdcba98e, |
| 5055 |
0xfedcba98, 0xfe8dcba9, 0xfe9dcba8, 0xfe98dcba, 0xfeadcb98, 0xfea8dcb9, |
| 5056 |
0xfea9dcb8, 0xfea98dcb, 0xfebdca98, 0xfeb8dca9, 0xfeb9dca8, 0xfeb98dca, |
| 5057 |
0xfebadc98, 0xfeba8dc9, 0xfeba9dc8, 0xfeba98dc, 0xfecdba98, 0xfec8dba9, |
| 5058 |
0xfec9dba8, 0xfec98dba, 0xfecadb98, 0xfeca8db9, 0xfeca9db8, 0xfeca98db, |
| 5059 |
0xfecbda98, 0xfecb8da9, 0xfecb9da8, 0xfecb98da, 0xfecbad98, 0xfecba8d9, |
| 5060 |
0xfecba9d8, 0xfecba98d, 0xfedcba98, 0xfed8cba9, 0xfed9cba8, 0xfed98cba, |
| 5061 |
0xfedacb98, 0xfeda8cb9, 0xfeda9cb8, 0xfeda98cb, 0xfedbca98, 0xfedb8ca9, |
| 5062 |
0xfedb9ca8, 0xfedb98ca, 0xfedbac98, 0xfedba8c9, 0xfedba9c8, 0xfedba98c, |
| 5063 |
0xfedcba98, 0xfedc8ba9, 0xfedc9ba8, 0xfedc98ba, 0xfedcab98, 0xfedca8b9, |
| 5064 |
0xfedca9b8, 0xfedca98b, 0xfedcba98, 0xfedcb8a9, 0xfedcb9a8, 0xfedcb98a, |
| 5065 |
0xfedcba98, 0xfedcba89, 0xfedcba98, 0xfedcba98}; |
| 5066 |
|
| 5067 |
|
| 5068 |
|
| 5069 |
|
| 5070 |
|
| 5071 |
const auto packed = Set(d32, packed_array[mask_bits]); |
| 5072 |
alignas(32) constexpr uint32_t shifts[8] = {0, 4, 8, 12, 16, 20, 24, 28}; |
| 5073 |
return packed >> Load(d32, shifts); |
| 5074 |
} |
| 5075 |
|
| 5076 |
template <typename T, HWY_IF_LANE_SIZE(T, 8)> |
| 5077 |
HWY_INLINE Vec256<uint32_t> IndicesFromNotBits(Full256<T> d, |
| 5078 |
uint64_t mask_bits) { |
| 5079 |
const Repartition<uint32_t, decltype(d)> d32; |
| 5080 |
|
| 5081 |
|
| 5082 |
|
| 5083 |
|
| 5084 |
alignas(32) constexpr uint32_t u32_indices[128] = { |
| 5085 |
|
| 5086 |
8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15, 8, 9, |
| 5087 |
8, 9, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, |
| 5088 |
8, 9, 10, 11, 14, 15, 12, 13, 10, 11, 14, 15, 8, 9, 12, 13, |
| 5089 |
8, 9, 14, 15, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, |
| 5090 |
8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 8, 9, 14, 15, |
| 5091 |
8, 9, 12, 13, 10, 11, 14, 15, 12, 13, 8, 9, 10, 11, 14, 15, |
| 5092 |
8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 8, 9, 12, 13, 14, 15, |
| 5093 |
8, 9, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15}; |
| 5094 |
return Load(d32, u32_indices + 8 * mask_bits); |
| 5095 |
} |
| 5096 |
template <typename T, HWY_IF_NOT_LANE_SIZE(T, 2)> |
| 5097 |
HWY_INLINE Vec256<T> Compress(Vec256<T> v, const uint64_t mask_bits) { |
| 5098 |
const Full256<T> d; |
| 5099 |
const Repartition<uint32_t, decltype(d)> du32; |
| 5100 |
|
| 5101 |
HWY_DASSERT(mask_bits < (1ull << (32 / sizeof(T)))); |
| 5102 |
|
| 5103 |
|
| 5104 |
const Indices256<uint32_t> indices{IndicesFromBits(d, mask_bits).raw}; |
| 5105 |
return BitCast(d, TableLookupLanes(BitCast(du32, v), indices)); |
| 5106 |
} |
| 5107 |
|
| 5108 |
|
| 5109 |
|
| 5110 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 5111 |
HWY_INLINE Vec256<T> Compress(Vec256<T> v, const uint64_t mask_bits) { |
| 5112 |
const Full256<T> d; |
| 5113 |
const RebindToUnsigned<decltype(d)> du; |
| 5114 |
const auto vu16 = BitCast(du, v); |
| 5115 |
const Half<decltype(du)> duh; |
| 5116 |
const auto half0 = LowerHalf(duh, vu16); |
| 5117 |
const auto half1 = UpperHalf(duh, vu16); |
| 5118 |
|
| 5119 |
const uint64_t mask_bits0 = mask_bits & 0xFF; |
| 5120 |
const uint64_t mask_bits1 = mask_bits >> 8; |
| 5121 |
const auto compressed0 = detail::CompressBits(half0, mask_bits0); |
| 5122 |
const auto compressed1 = detail::CompressBits(half1, mask_bits1); |
| 5123 |
|
| 5124 |
alignas(32) uint16_t all_true[16] = {}; |
| 5125 |
|
| 5126 |
const size_t num_true0 = PopCount(mask_bits0); |
| 5127 |
Store(compressed0, duh, all_true); |
| 5128 |
StoreU(compressed1, duh, all_true + num_true0); |
| 5129 |
|
| 5130 |
if (hwy::HWY_NAMESPACE::CompressIsPartition<T>::value) { |
| 5131 |
|
| 5132 |
|
| 5133 |
|
| 5134 |
alignas(32) uint16_t all_false[16] = {}; |
| 5135 |
const size_t num_true1 = PopCount(mask_bits1); |
| 5136 |
Store(compressed1, duh, all_false + 8); |
| 5137 |
StoreU(compressed0, duh, all_false + num_true1); |
| 5138 |
|
| 5139 |
const auto mask = FirstN(du, num_true0 + num_true1); |
| 5140 |
return BitCast(d, |
| 5141 |
IfThenElse(mask, Load(du, all_true), Load(du, all_false))); |
| 5142 |
} else { |
| 5143 |
|
| 5144 |
return BitCast(d, Load(du, all_true)); |
| 5145 |
} |
| 5146 |
} |
| 5147 |
|
| 5148 |
template <typename T, HWY_IF_LANE_SIZE_ONE_OF(T, 0x110)> |
| 5149 |
HWY_INLINE Vec256<T> CompressNot(Vec256<T> v, const uint64_t mask_bits) { |
| 5150 |
const Full256<T> d; |
| 5151 |
const Repartition<uint32_t, decltype(d)> du32; |
| 5152 |
|
| 5153 |
HWY_DASSERT(mask_bits < (1ull << (32 / sizeof(T)))); |
| 5154 |
|
| 5155 |
|
| 5156 |
const Indices256<uint32_t> indices{IndicesFromNotBits(d, mask_bits).raw}; |
| 5157 |
return BitCast(d, TableLookupLanes(BitCast(du32, v), indices)); |
| 5158 |
} |
| 5159 |
|
| 5160 |
|
| 5161 |
|
| 5162 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 5163 |
HWY_INLINE Vec256<T> CompressNot(Vec256<T> v, const uint64_t mask_bits) { |
| 5164 |
|
| 5165 |
return Compress(v, mask_bits ^ 0xFFFF); |
| 5166 |
} |
| 5167 |
|
| 5168 |
} |
| 5169 |
|
| 5170 |
template <typename T, HWY_IF_NOT_LANE_SIZE(T, 1)> |
| 5171 |
HWY_API Vec256<T> Compress(Vec256<T> v, Mask256<T> m) { |
| 5172 |
return detail::Compress(v, detail::BitsFromMask(m)); |
| 5173 |
} |
| 5174 |
|
| 5175 |
template <typename T, HWY_IF_NOT_LANE_SIZE(T, 1)> |
| 5176 |
HWY_API Vec256<T> CompressNot(Vec256<T> v, Mask256<T> m) { |
| 5177 |
return detail::CompressNot(v, detail::BitsFromMask(m)); |
| 5178 |
} |
| 5179 |
|
| 5180 |
HWY_API Vec256<uint64_t> CompressBlocksNot(Vec256<uint64_t> v, |
| 5181 |
Mask256<uint64_t> mask) { |
| 5182 |
return CompressNot(v, mask); |
| 5183 |
} |
| 5184 |
|
| 5185 |
template <typename T, HWY_IF_NOT_LANE_SIZE(T, 1)> |
| 5186 |
HWY_API Vec256<T> CompressBits(Vec256<T> v, const uint8_t* HWY_RESTRICT bits) { |
| 5187 |
constexpr size_t N = 32 / sizeof(T); |
| 5188 |
constexpr size_t kNumBytes = (N + 7) / 8; |
| 5189 |
|
| 5190 |
uint64_t mask_bits = 0; |
| 5191 |
CopyBytes<kNumBytes>(bits, &mask_bits); |
| 5192 |
|
| 5193 |
if (N < 8) { |
| 5194 |
mask_bits &= (1ull << N) - 1; |
| 5195 |
} |
| 5196 |
|
| 5197 |
return detail::Compress(v, mask_bits); |
| 5198 |
} |
| 5199 |
|
| 5200 |
|
| 5201 |
|
| 5202 |
template <typename T, HWY_IF_NOT_LANE_SIZE(T, 1)> |
| 5203 |
HWY_API size_t CompressStore(Vec256<T> v, Mask256<T> m, Full256<T> d, |
| 5204 |
T* HWY_RESTRICT unaligned) { |
| 5205 |
const uint64_t mask_bits = detail::BitsFromMask(m); |
| 5206 |
const size_t count = PopCount(mask_bits); |
| 5207 |
StoreU(detail::Compress(v, mask_bits), d, unaligned); |
| 5208 |
detail::MaybeUnpoison(unaligned, count); |
| 5209 |
return count; |
| 5210 |
} |
| 5211 |
|
| 5212 |
template <typename T, HWY_IF_LANE_SIZE_ONE_OF(T, 0x110)> |
| 5213 |
HWY_API size_t CompressBlendedStore(Vec256<T> v, Mask256<T> m, Full256<T> d, |
| 5214 |
T* HWY_RESTRICT unaligned) { |
| 5215 |
const uint64_t mask_bits = detail::BitsFromMask(m); |
| 5216 |
const size_t count = PopCount(mask_bits); |
| 5217 |
|
| 5218 |
const Repartition<uint32_t, decltype(d)> du32; |
| 5219 |
HWY_DASSERT(mask_bits < (1ull << (32 / sizeof(T)))); |
| 5220 |
|
| 5221 |
|
| 5222 |
const Vec256<uint32_t> idx_and_mask = detail::IndicesFromBits(d, mask_bits); |
| 5223 |
|
| 5224 |
const Mask256<uint32_t> mask32 = MaskFromVec(ShiftLeft<28>(idx_and_mask)); |
| 5225 |
|
| 5226 |
const Mask256<MakeUnsigned<T>> mask_u{mask32.raw}; |
| 5227 |
const Mask256<T> mask = RebindMask(d, mask_u); |
| 5228 |
const Vec256<T> compressed = |
| 5229 |
BitCast(d, TableLookupLanes(BitCast(du32, v), |
| 5230 |
Indices256<uint32_t>{idx_and_mask.raw})); |
| 5231 |
|
| 5232 |
BlendedStore(compressed, mask, d, unaligned); |
| 5233 |
detail::MaybeUnpoison(unaligned, count); |
| 5234 |
return count; |
| 5235 |
} |
| 5236 |
|
| 5237 |
template <typename T, HWY_IF_LANE_SIZE(T, 2)> |
| 5238 |
HWY_API size_t CompressBlendedStore(Vec256<T> v, Mask256<T> m, Full256<T> d, |
| 5239 |
T* HWY_RESTRICT unaligned) { |
| 5240 |
const uint64_t mask_bits = detail::BitsFromMask(m); |
| 5241 |
const size_t count = PopCount(mask_bits); |
| 5242 |
const Vec256<T> compressed = detail::Compress(v, mask_bits); |
| 5243 |
|
| 5244 |
#if HWY_MEM_OPS_MIGHT_FAULT |
| 5245 |
|
| 5246 |
|
| 5247 |
alignas(32) T buf[16]; |
| 5248 |
Store(compressed, d, buf); |
| 5249 |
memcpy(unaligned, buf, count * sizeof(T)); |
| 5250 |
#else |
| 5251 |
BlendedStore(compressed, FirstN(d, count), d, unaligned); |
| 5252 |
#endif |
| 5253 |
return count; |
| 5254 |
} |
| 5255 |
|
| 5256 |
template <typename T, HWY_IF_NOT_LANE_SIZE(T, 1)> |
| 5257 |
HWY_API size_t CompressBitsStore(Vec256<T> v, const uint8_t* HWY_RESTRICT bits, |
| 5258 |
Full256<T> d, T* HWY_RESTRICT unaligned) { |
| 5259 |
constexpr size_t N = 32 / sizeof(T); |
| 5260 |
constexpr size_t kNumBytes = (N + 7) / 8; |
| 5261 |
|
| 5262 |
uint64_t mask_bits = 0; |
| 5263 |
CopyBytes<kNumBytes>(bits, &mask_bits); |
| 5264 |
|
| 5265 |
if (N < 8) { |
| 5266 |
mask_bits &= (1ull << N) - 1; |
| 5267 |
} |
| 5268 |
const size_t count = PopCount(mask_bits); |
| 5269 |
|
| 5270 |
StoreU(detail::Compress(v, mask_bits), d, unaligned); |
| 5271 |
detail::MaybeUnpoison(unaligned, count); |
| 5272 |
return count; |
| 5273 |
} |
| 5274 |
|
| 5275 |
#endif |
| 5276 |
|
| 5277 |
|
| 5278 |
|
| 5279 |
|
| 5280 |
|
| 5281 |
namespace detail { |
| 5282 |
|
| 5283 |
|
| 5284 |
|
| 5285 |
|
| 5286 |
|
| 5287 |
|
| 5288 |
|
| 5289 |
|
| 5290 |
|
| 5291 |
template <typename T> |
| 5292 |
HWY_API void LoadTransposedBlocks3(Full256<T> d, |
| 5293 |
const T* HWY_RESTRICT unaligned, |
| 5294 |
Vec256<T>& A, Vec256<T>& B, Vec256<T>& C) { |
| 5295 |
constexpr size_t N = 32 / sizeof(T); |
| 5296 |
const Vec256<T> v10 = LoadU(d, unaligned + 0 * N); |
| 5297 |
const Vec256<T> v32 = LoadU(d, unaligned + 1 * N); |
| 5298 |
const Vec256<T> v54 = LoadU(d, unaligned + 2 * N); |
| 5299 |
|
| 5300 |
A = ConcatUpperLower(d, v32, v10); |
| 5301 |
B = ConcatLowerUpper(d, v54, v10); |
| 5302 |
C = ConcatUpperLower(d, v54, v32); |
| 5303 |
} |
| 5304 |
|
| 5305 |
|
| 5306 |
|
| 5307 |
|
| 5308 |
|
| 5309 |
|
| 5310 |
|
| 5311 |
|
| 5312 |
|
| 5313 |
|
| 5314 |
|
| 5315 |
template <typename T> |
| 5316 |
HWY_API void LoadTransposedBlocks4(Full256<T> d, |
| 5317 |
const T* HWY_RESTRICT unaligned, |
| 5318 |
Vec256<T>& A, Vec256<T>& B, Vec256<T>& C, |
| 5319 |
Vec256<T>& D) { |
| 5320 |
constexpr size_t N = 32 / sizeof(T); |
| 5321 |
const Vec256<T> v10 = LoadU(d, unaligned + 0 * N); |
| 5322 |
const Vec256<T> v32 = LoadU(d, unaligned + 1 * N); |
| 5323 |
const Vec256<T> v54 = LoadU(d, unaligned + 2 * N); |
| 5324 |
const Vec256<T> v76 = LoadU(d, unaligned + 3 * N); |
| 5325 |
|
| 5326 |
A = ConcatLowerLower(d, v54, v10); |
| 5327 |
B = ConcatUpperUpper(d, v54, v10); |
| 5328 |
C = ConcatLowerLower(d, v76, v32); |
| 5329 |
D = ConcatUpperUpper(d, v76, v32); |
| 5330 |
} |
| 5331 |
|
| 5332 |
} |
| 5333 |
|
| 5334 |
|
| 5335 |
|
| 5336 |
|
| 5337 |
|
| 5338 |
namespace detail { |
| 5339 |
|
| 5340 |
|
| 5341 |
|
| 5342 |
|
| 5343 |
|
| 5344 |
|
| 5345 |
|
| 5346 |
template <typename T> |
| 5347 |
HWY_API void StoreTransposedBlocks2(const Vec256<T> i, const Vec256<T> j, |
| 5348 |
const Full256<T> d, |
| 5349 |
T* HWY_RESTRICT unaligned) { |
| 5350 |
constexpr size_t N = 32 / sizeof(T); |
| 5351 |
const auto out0 = ConcatLowerLower(d, j, i); |
| 5352 |
const auto out1 = ConcatUpperUpper(d, j, i); |
| 5353 |
StoreU(out0, d, unaligned + 0 * N); |
| 5354 |
StoreU(out1, d, unaligned + 1 * N); |
| 5355 |
} |
| 5356 |
|
| 5357 |
|
| 5358 |
|
| 5359 |
|
| 5360 |
|
| 5361 |
|
| 5362 |
|
| 5363 |
|
| 5364 |
|
| 5365 |
template <typename T> |
| 5366 |
HWY_API void StoreTransposedBlocks3(const Vec256<T> i, const Vec256<T> j, |
| 5367 |
const Vec256<T> k, Full256<T> d, |
| 5368 |
T* HWY_RESTRICT unaligned) { |
| 5369 |
constexpr size_t N = 32 / sizeof(T); |
| 5370 |
const auto out0 = ConcatLowerLower(d, j, i); |
| 5371 |
const auto out1 = ConcatUpperLower(d, i, k); |
| 5372 |
const auto out2 = ConcatUpperUpper(d, k, j); |
| 5373 |
StoreU(out0, d, unaligned + 0 * N); |
| 5374 |
StoreU(out1, d, unaligned + 1 * N); |
| 5375 |
StoreU(out2, d, unaligned + 2 * N); |
| 5376 |
} |
| 5377 |
|
| 5378 |
|
| 5379 |
|
| 5380 |
|
| 5381 |
|
| 5382 |
|
| 5383 |
|
| 5384 |
|
| 5385 |
|
| 5386 |
|
| 5387 |
|
| 5388 |
template <typename T> |
| 5389 |
HWY_API void StoreTransposedBlocks4(const Vec256<T> i, const Vec256<T> j, |
| 5390 |
const Vec256<T> k, const Vec256<T> l, |
| 5391 |
Full256<T> d, T* HWY_RESTRICT unaligned) { |
| 5392 |
constexpr size_t N = 32 / sizeof(T); |
| 5393 |
|
| 5394 |
const auto out0 = ConcatLowerLower(d, j, i); |
| 5395 |
const auto out1 = ConcatLowerLower(d, l, k); |
| 5396 |
StoreU(out0, d, unaligned + 0 * N); |
| 5397 |
StoreU(out1, d, unaligned + 1 * N); |
| 5398 |
const auto out2 = ConcatUpperUpper(d, j, i); |
| 5399 |
const auto out3 = ConcatUpperUpper(d, l, k); |
| 5400 |
StoreU(out2, d, unaligned + 2 * N); |
| 5401 |
StoreU(out3, d, unaligned + 3 * N); |
| 5402 |
} |
| 5403 |
|
| 5404 |
} |
| 5405 |
|
| 5406 |
|
| 5407 |
|
| 5408 |
namespace detail { |
| 5409 |
|
| 5410 |
|
| 5411 |
|
| 5412 |
template <typename T> |
| 5413 |
HWY_INLINE Vec256<T> SumOfLanes(hwy::SizeTag<4> , |
| 5414 |
const Vec256<T> v3210) { |
| 5415 |
const auto v1032 = Shuffle1032(v3210); |
| 5416 |
const auto v31_20_31_20 = v3210 + v1032; |
| 5417 |
const auto v20_31_20_31 = Shuffle0321(v31_20_31_20); |
| 5418 |
return v20_31_20_31 + v31_20_31_20; |
| 5419 |
} |
| 5420 |
template <typename T> |
| 5421 |
HWY_INLINE Vec256<T> MinOfLanes(hwy::SizeTag<4> , |
| 5422 |
const Vec256<T> v3210) { |
| 5423 |
const auto v1032 = Shuffle1032(v3210); |
| 5424 |
const auto v31_20_31_20 = Min(v3210, v1032); |
| 5425 |
const auto v20_31_20_31 = Shuffle0321(v31_20_31_20); |
| 5426 |
return Min(v20_31_20_31, v31_20_31_20); |
| 5427 |
} |
| 5428 |
template <typename T> |
| 5429 |
HWY_INLINE Vec256<T> MaxOfLanes(hwy::SizeTag<4> , |
| 5430 |
const Vec256<T> v3210) { |
| 5431 |
const auto v1032 = Shuffle1032(v3210); |
| 5432 |
const auto v31_20_31_20 = Max(v3210, v1032); |
| 5433 |
const auto v20_31_20_31 = Shuffle0321(v31_20_31_20); |
| 5434 |
return Max(v20_31_20_31, v31_20_31_20); |
| 5435 |
} |
| 5436 |
|
| 5437 |
template <typename T> |
| 5438 |
HWY_INLINE Vec256<T> SumOfLanes(hwy::SizeTag<8> , |
| 5439 |
const Vec256<T> v10) { |
| 5440 |
const auto v01 = Shuffle01(v10); |
| 5441 |
return v10 + v01; |
| 5442 |
} |
| 5443 |
template <typename T> |
| 5444 |
HWY_INLINE Vec256<T> MinOfLanes(hwy::SizeTag<8> , |
| 5445 |
const Vec256<T> v10) { |
| 5446 |
const auto v01 = Shuffle01(v10); |
| 5447 |
return Min(v10, v01); |
| 5448 |
} |
| 5449 |
template <typename T> |
| 5450 |
HWY_INLINE Vec256<T> MaxOfLanes(hwy::SizeTag<8> , |
| 5451 |
const Vec256<T> v10) { |
| 5452 |
const auto v01 = Shuffle01(v10); |
| 5453 |
return Max(v10, v01); |
| 5454 |
} |
| 5455 |
|
| 5456 |
HWY_API Vec256<uint16_t> SumOfLanes(hwy::SizeTag<2> , |
| 5457 |
Vec256<uint16_t> v) { |
| 5458 |
const Full256<uint16_t> d; |
| 5459 |
const RepartitionToWide<decltype(d)> d32; |
| 5460 |
const auto even = And(BitCast(d32, v), Set(d32, 0xFFFF)); |
| 5461 |
const auto odd = ShiftRight<16>(BitCast(d32, v)); |
| 5462 |
const auto sum = SumOfLanes(hwy::SizeTag<4>(), even + odd); |
| 5463 |
|
| 5464 |
return OddEven(BitCast(d, ShiftLeft<16>(sum)), BitCast(d, sum)); |
| 5465 |
} |
| 5466 |
HWY_API Vec256<int16_t> SumOfLanes(hwy::SizeTag<2> , |
| 5467 |
Vec256<int16_t> v) { |
| 5468 |
const Full256<int16_t> d; |
| 5469 |
const RepartitionToWide<decltype(d)> d32; |
| 5470 |
|
| 5471 |
const auto even = ShiftRight<16>(ShiftLeft<16>(BitCast(d32, v))); |
| 5472 |
const auto odd = ShiftRight<16>(BitCast(d32, v)); |
| 5473 |
const auto sum = SumOfLanes(hwy::SizeTag<4>(), even + odd); |
| 5474 |
|
| 5475 |
return OddEven(BitCast(d, ShiftLeft<16>(sum)), BitCast(d, sum)); |
| 5476 |
} |
| 5477 |
|
| 5478 |
HWY_API Vec256<uint16_t> MinOfLanes(hwy::SizeTag<2> , |
| 5479 |
Vec256<uint16_t> v) { |
| 5480 |
const Full256<uint16_t> d; |
| 5481 |
const RepartitionToWide<decltype(d)> d32; |
| 5482 |
const auto even = And(BitCast(d32, v), Set(d32, 0xFFFF)); |
| 5483 |
const auto odd = ShiftRight<16>(BitCast(d32, v)); |
| 5484 |
const auto min = MinOfLanes(hwy::SizeTag<4>(), Min(even, odd)); |
| 5485 |
|
| 5486 |
return OddEven(BitCast(d, ShiftLeft<16>(min)), BitCast(d, min)); |
| 5487 |
} |
| 5488 |
HWY_API Vec256<int16_t> MinOfLanes(hwy::SizeTag<2> , |
| 5489 |
Vec256<int16_t> v) { |
| 5490 |
const Full256<int16_t> d; |
| 5491 |
const RepartitionToWide<decltype(d)> d32; |
| 5492 |
|
| 5493 |
const auto even = ShiftRight<16>(ShiftLeft<16>(BitCast(d32, v))); |
| 5494 |
const auto odd = ShiftRight<16>(BitCast(d32, v)); |
| 5495 |
const auto min = MinOfLanes(hwy::SizeTag<4>(), Min(even, odd)); |
| 5496 |
|
| 5497 |
return OddEven(BitCast(d, ShiftLeft<16>(min)), BitCast(d, min)); |
| 5498 |
} |
| 5499 |
|
| 5500 |
HWY_API Vec256<uint16_t> MaxOfLanes(hwy::SizeTag<2> , |
| 5501 |
Vec256<uint16_t> v) { |
| 5502 |
const Full256<uint16_t> d; |
| 5503 |
const RepartitionToWide<decltype(d)> d32; |
| 5504 |
const auto even = And(BitCast(d32, v), Set(d32, 0xFFFF)); |
| 5505 |
const auto odd = ShiftRight<16>(BitCast(d32, v)); |
| 5506 |
const auto min = MaxOfLanes(hwy::SizeTag<4>(), Max(even, odd)); |
| 5507 |
|
| 5508 |
return OddEven(BitCast(d, ShiftLeft<16>(min)), BitCast(d, min)); |
| 5509 |
} |
| 5510 |
HWY_API Vec256<int16_t> MaxOfLanes(hwy::SizeTag<2> , |
| 5511 |
Vec256<int16_t> v) { |
| 5512 |
const Full256<int16_t> d; |
| 5513 |
const RepartitionToWide<decltype(d)> d32; |
| 5514 |
|
| 5515 |
const auto even = ShiftRight<16>(ShiftLeft<16>(BitCast(d32, v))); |
| 5516 |
const auto odd = ShiftRight<16>(BitCast(d32, v)); |
| 5517 |
const auto min = MaxOfLanes(hwy::SizeTag<4>(), Max(even, odd)); |
| 5518 |
|
| 5519 |
return OddEven(BitCast(d, ShiftLeft<16>(min)), BitCast(d, min)); |
| 5520 |
} |
| 5521 |
|
| 5522 |
} |
| 5523 |
|
| 5524 |
|
| 5525 |
template <typename T> |
| 5526 |
HWY_API Vec256<T> SumOfLanes(Full256<T> d, const Vec256<T> vHL) { |
| 5527 |
const Vec256<T> vLH = ConcatLowerUpper(d, vHL, vHL); |
| 5528 |
return detail::SumOfLanes(hwy::SizeTag<sizeof(T)>(), vLH + vHL); |
| 5529 |
} |
| 5530 |
template <typename T> |
| 5531 |
HWY_API Vec256<T> MinOfLanes(Full256<T> d, const Vec256<T> vHL) { |
| 5532 |
const Vec256<T> vLH = ConcatLowerUpper(d, vHL, vHL); |
| 5533 |
return detail::MinOfLanes(hwy::SizeTag<sizeof(T)>(), Min(vLH, vHL)); |
| 5534 |
} |
| 5535 |
template <typename T> |
| 5536 |
HWY_API Vec256<T> MaxOfLanes(Full256<T> d, const Vec256<T> vHL) { |
| 5537 |
const Vec256<T> vLH = ConcatLowerUpper(d, vHL, vHL); |
| 5538 |
return detail::MaxOfLanes(hwy::SizeTag<sizeof(T)>(), Max(vLH, vHL)); |
| 5539 |
} |
| 5540 |
|
| 5541 |
|
| 5542 |
} |
| 5543 |
} |
| 5544 |
HWY_AFTER_NAMESPACE(); |
| 5545 |
|
| 5546 |
|
| 5547 |
|
| 5548 |
HWY_DIAGNOSTICS(pop) |