google / google/highway

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

Open
#2,345 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5.8k
Forks
471
Avg merge
1d 6h
Merged PRs (30d)
81

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:

```C
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

```C++
template
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

```C++
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).

```assembly
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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.