Skip to content

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

Open
@lsrcz

Description

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions