Skip to content

Commit

Permalink
Rename MultiShift to MultiRotateRight
Browse files Browse the repository at this point in the history
  • Loading branch information
wbb-ccl committed Feb 3, 2025
1 parent 20a7650 commit 2b14239
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions g3doc/quick_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ Per-lane variable shifts (slow if SSSE3/SSE4, or 16-bit, or Shr i64 on AVX2):
A compound shift on 64-bit values:

* `V`: `{u,i}64`, `VI`: `{u,i}8` \
<code>V **MultiShift**(V vals, VI indices)</code>: returns a
<code>V **MultiRotateRight**(V vals, VI indices)</code>: returns a
vector with `(vals[i] >> indices[i*8+j]) & 0xff` in byte `j` of vector `r[i]`
for each `j` between 0 and 7.

Expand All @@ -1033,7 +1033,7 @@ A compound shift on 64-bit values:
`VI` must be either `Vec<Repartition<int8_t, DFromV<V>>>` or
`Vec<Repartition<uint8_t, DFromV<V>>>`.

`MultiShift(V vals, VI indices)` is equivalent to the following loop (where `N` is
`MultiRotateRight(V vals, VI indices)` is equivalent to the following loop (where `N` is
equal to `Lanes(DFromV<V>())`):
```
for(size_t i = 0; i < N; i++) {
Expand Down
12 changes: 6 additions & 6 deletions hwy/ops/generic_ops-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7600,16 +7600,16 @@ HWY_API bool AllBits0(V a) {
}
#endif // HWY_NATIVE_ALLZEROS

// ------------------------------ MultiShift
#if (defined(HWY_NATIVE_MULTISHIFT) == defined(HWY_TARGET_TOGGLE))
#ifdef HWY_NATIVE_MULTISHIFT
#undef HWY_NATIVE_MULTISHIFT
// ------------------------------ MultiRotateRight
#if (defined(HWY_NATIVE_MULTIROTATERIGHT) == defined(HWY_TARGET_TOGGLE))
#ifdef HWY_NATIVE_MULTIROTATERIGHT
#undef HWY_NATIVE_MULTIROTATERIGHT
#else
#define HWY_NATIVE_MULTISHIFT
#define HWY_NATIVE_MULTIROTATERIGHT
#endif

template <class V, class VI, HWY_IF_UI64(TFromV<V>), HWY_IF_UI8(TFromV<VI>)>
HWY_API V MultiShift(V v, VI idx) {
HWY_API V MultiRotateRight(V v, VI idx) {
const DFromV<V> d64;
const Repartition<uint8_t, decltype(d64)> du8;
const Repartition<uint16_t, decltype(d64)> du16;
Expand Down
2 changes: 1 addition & 1 deletion hwy/ops/x86_128-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13664,7 +13664,7 @@ HWY_API V BitShuffle(V v, VI idx) {
}
#endif // HWY_TARGET <= HWY_AVX3_DL

// TODO: Implement MultiShift using _mm_multishift_epi64_epi8
// TODO: Implement MultiRotateRight using _mm_multishift_epi64_epi8

// ------------------------------ Lt128

Expand Down
2 changes: 1 addition & 1 deletion hwy/ops/x86_256-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8774,7 +8774,7 @@ HWY_API V BitShuffle(V v, VI idx) {
}
#endif // HWY_TARGET <= HWY_AVX3_DL

// TODO: Implement MultiShift using _mm256_multishift_epi64_epi8
// TODO: Implement MultiRotateRight using _mm256_multishift_epi64_epi8

// ------------------------------ LeadingZeroCount

Expand Down
2 changes: 1 addition & 1 deletion hwy/ops/x86_512-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7541,7 +7541,7 @@ HWY_API V BitShuffle(V v, VI idx) {
}
#endif // HWY_TARGET <= HWY_AVX3_DL

// TODO: Implement MultiShift using _mm512_multishift_epi64_epi8
// TODO: Implement MultiRotateRight using _mm512_multishift_epi64_epi8

// -------------------- LeadingZeroCount

Expand Down
14 changes: 7 additions & 7 deletions hwy/tests/shift_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ HWY_NOINLINE void TestAllMaskedShift() {
ForSignedTypes(ForPartialVectors<TestMaskedShrOr>());
}

struct TestMultiShift {
struct TestMultiRotateRight {
uint64_t byte_swap_64(uint64_t x) {
// Equivalent to std::byteswap for uint64 (in C++23)
return ((x << 56) & 0xff00000000000000ULL) |
Expand Down Expand Up @@ -592,7 +592,7 @@ struct TestMultiShift {
expected[i] = ConvertScalarTo<T>(initial_even);
expected[i + 1] = ConvertScalarTo<T>(byte_swap_64(initial_odd));
}
HWY_ASSERT_VEC_EQ(d, expected.get(), MultiShift(v1, indices));
HWY_ASSERT_VEC_EQ(d, expected.get(), MultiRotateRight(v1, indices));

// Test bit level shifts, different amounts for each byte
const auto v2 = Set(d, 0x0102010201020102ul);
Expand All @@ -614,7 +614,7 @@ struct TestMultiShift {
}
expected[i] = ConvertScalarTo<T>(shift_result);
}
HWY_ASSERT_VEC_EQ(d, expected.get(), MultiShift(v2, indices));
HWY_ASSERT_VEC_EQ(d, expected.get(), MultiRotateRight(v2, indices));

// Combine byte-level reordering with bit level shift
indices = Dup128VecFromValues(
Expand All @@ -631,13 +631,13 @@ struct TestMultiShift {
ConvertScalarTo<T>((initial_odd >> 4) | (initial_odd << (64 - 4)));
expected[i + 1] = ConvertScalarTo<T>(byte_swap_64(unreversed_val));
}
HWY_ASSERT_VEC_EQ(d, expected.get(), MultiShift(v1, indices));
HWY_ASSERT_VEC_EQ(d, expected.get(), MultiRotateRight(v1, indices));
}
};

HWY_NOINLINE void TestAllMultiShift() {
HWY_NOINLINE void TestAllMultiRotateRight() {
#if HWY_HAVE_INTEGER64
const ForGEVectors<128, TestMultiShift> test64;
const ForGEVectors<128, TestMultiRotateRight> test64;
test64(uint64_t());
test64(int64_t());
#endif
Expand All @@ -657,7 +657,7 @@ HWY_EXPORT_AND_TEST_P(HwyShiftTest, TestAllVariableShifts);
HWY_EXPORT_AND_TEST_P(HwyShiftTest, TestAllRoundingShiftRight);
HWY_EXPORT_AND_TEST_P(HwyShiftTest, TestAllVariableRoundingShr);
HWY_EXPORT_AND_TEST_P(HwyShiftTest, TestAllMaskedShift);
HWY_EXPORT_AND_TEST_P(HwyShiftTest, TestAllMultiShift);
HWY_EXPORT_AND_TEST_P(HwyShiftTest, TestAllMultiRotateRight);
HWY_AFTER_TEST();
} // namespace
} // namespace hwy
Expand Down

0 comments on commit 2b14239

Please sign in to comment.