Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MulEven performance for RVV #2334

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions hwy/ops/rvv-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5655,9 +5655,13 @@ HWY_API V64 BitShuffle(V64 values, VI idx) {
template <class V, HWY_IF_T_SIZE_ONE_OF_V(V, (1 << 1) | (1 << 2) | (1 << 4)),
class D = DFromV<V>, class DW = RepartitionToWide<D>>
HWY_API VFromD<DW> MulEven(const V a, const V b) {
const auto lo = Mul(a, b);
const auto hi = MulHigh(a, b);
return BitCast(DW(), OddEven(detail::Slide1Up(hi), lo));
constexpr int maskVal = sizeof(TFromD<D>) == 4 ? 5
: sizeof(TFromD<D>) == 2 ? 0x55
: 0x5555;
const auto mask = Dup128MaskFromMaskBits(D(), maskVal);
const auto hi = Slide1Up(D(), MulHigh(a, b));
const auto res = MaskedMulOr(hi, mask, a, b);
return BitCast(DW(), res);
}

template <class V, HWY_IF_T_SIZE_ONE_OF_V(V, (1 << 1) | (1 << 2) | (1 << 4)),
Expand All @@ -5671,9 +5675,9 @@ HWY_API VFromD<DW> MulOdd(const V a, const V b) {
// There is no 64x64 vwmul.
template <class V, HWY_IF_T_SIZE_V(V, 8)>
HWY_INLINE V MulEven(const V a, const V b) {
const auto lo = Mul(a, b);
const auto hi = MulHigh(a, b);
return OddEven(detail::Slide1Up(hi), lo);
const auto mask = Dup128MaskFromMaskBits(DFromV<V>(), 1);
const auto hi = Slide1Up(DFromV<V>(), MulHigh(a, b));
return MaskedMulOr(hi, mask, a, b);
}

template <class V, HWY_IF_T_SIZE_V(V, 8)>
Expand Down
Loading