Description
When passed --target=riscv64-linux-gnu -march=rv64gcv -mno-strict-align
, clang-18 and up generate vle64
and vse64
instructions for the following code despite receiving byte pointers:
__attribute__((noinline))
void vector_memcpy(uint8_t* d, uint8_t const* p) {
__builtin_memcpy(d, p, 16);
}
https://godbolt.org/z/eb4oqM3Ts
If the pointer is unaligned then my Kendryte K230 board (C908) will raise a bus error trying to execute this.
However, -mno-strict-align
offers big performance gains for some scalar code, where unaligned access is supported just fine. There seems to be no way to specify that vector code should respect alignments while scalar code can do unaligned access.
Scalar code "seems to work" when you cast a byte pointer to a wider type when it's unaligned, but there are other issues with that and most portable code prefers memcpy()
with the expectation that the compiler will optimise it correctly.