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

Adding wrappers for __riscv_vget* and __riscv_vset* for non-tuple types #2345

Open
lsrcz opened this issue Oct 7, 2024 · 0 comments
Open

Comments

@lsrcz
Copy link
Contributor

lsrcz commented Oct 7, 2024

RVV provides the __riscv_vset_v_*_* and __riscv_vget_v_*_* intrinsics for not only tuple types but also for vector groups since v0.11, for example:

vint16m4_t __riscv_vset_v_i16m1_i16m4(vint16m4_t dest, size_t index, vint16m1_t value);
// __riscv_vset_v_i16m1_i16m4(dest, 2, value) copies the register `value` to the third register in the dest vector group

They are usually translated to whole register move instructions (e.g., vmv1r) and is usually efficient on most microarchitectures, and could potentially be eliminated by the register allocator when the compilers are getting more advanced.

These operations are useful when implementing concat operators like ConcatUpperLower when LMUL is not fractional. For example, the current ConcatUpperLower is implemented as follows

template <class D, class V>
HWY_API V ConcatUpperLower(D d, const V hi, const V lo) {
  const size_t half = Lanes(d) / 2;
  const V hi_down = detail::SlideDown(hi, half);
  return detail::SlideUp(lo, hi_down, half);
}

For V=vuint8m2_t, each of the two slide operations will take 4 cycles on x280. If we implement it with vget and vset, we can do

vuint8m2_t ConcatUpperLower(const vuint8m2_t hi, const vuint8m2_t lo) {
  auto v0 = __riscv_vget_v_u8m2_u8m1(lo, 0);
  return __riscv_vset_v_u8m1_u8m2(hi, 0, v0);
}

This will be translated to a program that takes 2 cycles by clang (trunk version).

ConcatUpperLower:
  vmv1r.v v8, v10
  ret

However, I have no idea on how to deal with all the macros to add the operations to highway. Any idea or instructions on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant