tests/tcg/riscv64: Add vector load and store tests
cover tests/tcg/riscv64: Add vector load and store tests
Hi Richard, I was testing your riscv vector load/store series and noticed there were some regressions with page crossing loads and stores. We don't have any tests for that in the tree, so I wrote some.
The tests trigger assertions in linux-user for me:
$ make -C build/tests/tcg/riscv64-linux-user run-test-rvv-ldst
make: Entering directory 'build/tests/tcg/riscv64-linux-user'
TEST test-rvv-ldst on riscv64
**
ERROR:../accel/tcg/user-exec.c:810:probe_access: assertion failed: (-(addr | TARGET_PAGE_MASK) >= size)
timeout: the monitored command dumped core
Aborted
make: *** [Makefile:223: run-test-rvv-ldst] Error 134
make: Leaving directory 'build/tests/tcg/riscv64-linux-user'I wrote the assembly one first before realising a C version would be easy enough to do too. I'm not sure about using memcmp to check (in case it's vectorised) so perhaps that's where the asm wins. I can tidy them up and send the preferred version if we decide to put it in the tree.
Joel Stanley (2):
tests/tcg/riscv64: Vector load test tests/tcg/riscv64: Add intrinsics version of test-rvv-ldst
tests/tcg/riscv64/test-rvv-ldst-intrinsics.c | 66 ++++++++++ tests/tcg/riscv64/Makefile.target | 19 +++ tests/tcg/riscv64/test-rvv-ldst.S | 131 +++++++++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 tests/tcg/riscv64/test-rvv-ldst-intrinsics.c create mode 100644 tests/tcg/riscv64/test-rvv-ldst.S
Signature · 1 line
2.53.0
PATCH 1/2 tests/tcg/riscv64: Vector load test
A userspace program to perform vector loads and stores that cross page boundaries, and check the result.
--- tests/tcg/riscv64/Makefile.target | 13 +++ tests/tcg/riscv64/test-rvv-ldst.S | 131 ++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 tests/tcg/riscv64/test-rvv-ldst.S
tests/tcg/riscv64/Makefile.target +13 -0
@@ -13,6 +13,19 @@ run-test-noc: QEMU_OPTS += -cpu rv64,c=false TESTS += test-aes run-test-aes: QEMU_OPTS += -cpu rv64,zk=on +# Vector load test +TESTS += test-rvv-ldst +test-rvv-ldst: CFLAGS += -march=rv64gcv +test-rvv-ldst: LDFLAGS = -nostdlib -static +run-test-rvv-ldst: QEMU_OPTS += -cpu max + +# Re-run the vector tests at each supported VLEN +TEST_RVV_VLENS = 128 256 512 1024 +EXTRA_RUNS += $(patsubst %,run-test-rvv-ldst-vlen%,$(TEST_RVV_VLENS)) +run-test-rvv-ldst-vlen%: test-rvv-ldst + $(call run-test, $@, env QEMU=$(QEMU) $(QEMU) $(QEMU_OPTS) -cpu max$(COMMA)vlen=$* $<, \ + test-rvv-ldst with vlen=$*) + # Test for fcvtmod TESTS += test-fcvtmod test-fcvtmod: CFLAGS += -march=rv64imafdc
tests/tcg/riscv64/test-rvv-ldst.S new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 2/2 tests/tcg/riscv64: Add intrinsics version of test-rvv-ldst
In reply to Joel StanleyA C userspace program to perform vector loads and stores that cross page boundaries, and check the result.
--- tests/tcg/riscv64/test-rvv-ldst-intrinsics.c | 66 ++++++++++++++++++++ tests/tcg/riscv64/Makefile.target | 12 +++- 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 tests/tcg/riscv64/test-rvv-ldst-intrinsics.c
tests/tcg/riscv64/test-rvv-ldst-intrinsics.c new file +66 -0
@@ -0,0 +1,66 @@ +/* +* RISC-V vector load/store test, including accesses that cross a page +* boundary. Intrinsics version of test-rvv-ldst.S. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include <riscv_vector.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#define MAX_PAGE_SIZE 65536 +#define NUM_BYTES 16 + +struct cross_page { +uint8_t pad[MAX_PAGE_SIZE -NUM_BYTES /2 ]; +uint8_t data[NUM_BYTES ]; +}; + +/* Page aligned so the within-page cases never cross a boundary */ +static const uint8_t src_data[NUM_BYTES] + __attribute__((aligned(MAX_PAGE_SIZE))) = { +0x10 ,0x11 ,0x12 ,0x13 ,0x14 ,0x15 ,0x16 ,0x17 , + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, +}; + +static const struct cross_page src_cross + __attribute__((aligned(MAX_PAGE_SIZE))) = { + .data = { +0x20 ,0x21 ,0x22 ,0x23 ,0x24 ,0x25 ,0x26 ,0x27 , +0x28 ,0x29 ,0x2A ,0x2B ,0x2C ,0x2D ,0x2E ,0x2F , + }, +}; + +static uint8_t dst_data[NUM_BYTES] __attribute__((aligned(MAX_PAGE_SIZE))); +static struct cross_page dst_cross __attribute__((aligned(MAX_PAGE_SIZE))); + +static void vec_copy (uint8_t *dst,const uint8_t *src,int code) +{ +size_t vl =__riscv_vsetvl_e8m1 (NUM_BYTES ); +if (vl !=NUM_BYTES ) { +exit (code); + } + +vuint8m1_t v =__riscv_vle8_v_u8m1 (src, vl); +__riscv_vse8_v_u8m1 (dst, v, vl); + +if (memcmp (dst, src,NUM_BYTES )) { +exit (code); + } +} + +int main (void ) +{ +/* Case 1: load/store within a page */ +vec_copy (dst_data, src_data,1 ); + +/* Case 2: the load straddles a page boundary */ +vec_copy (dst_data, src_cross.data,2 ); + +/* Case 3: the store straddles a page boundary */ +vec_copy (dst_cross.data, src_data,3 ); + +return 0 ; +}
tests/tcg/riscv64/Makefile.target +9 -3
@@ -14,10 +14,11 @@ TESTS += test-aes run-test-aes: QEMU_OPTS += -cpu rv64,zk=on # Vector load test -TESTS += test-rvv-ldst -test-rvv-ldst: CFLAGS += -march=rv64gcv +TESTS += test-rvv-ldst test-rvv-ldst-intrinsics +test-rvv-ldst-intrinsics test-rvv-ldst: CFLAGS += -march=rv64gcv test-rvv-ldst: LDFLAGS = -nostdlib -static -run-test-rvv-ldst: QEMU_OPTS += -cpu max +test-rvv-ldst-intrinsics: LDFLAGS = -static +run-test-rvv-ldst-intrinsics run-test-rvv-ldst: QEMU_OPTS += -cpu max # Re-run the vector tests at each supported VLEN TEST_RVV_VLENS = 128 256 512 1024
@@ -26,6 +27,11 @@ run-test-rvv-ldst-vlen%: test-rvv-ldst $(call run-test, $@, env QEMU=$(QEMU) $(QEMU) $(QEMU_OPTS) -cpu max$(COMMA)vlen=$* $<, \ test-rvv-ldst with vlen=$*) +EXTRA_RUNS += $(patsubst %,run-test-rvv-ldst-intrinsics-vlen%,$(TEST_RVV_VLENS)) +run-test-rvv-ldst-intrinsics-vlen%: test-rvv-ldst-intrinsics + $(call run-test, $@, env QEMU=$(QEMU) $(QEMU) $(QEMU_OPTS) -cpu max$(COMMA)vlen=$* $<, \ + test-rvv-ldst-intrinsics with vlen=$*) + # Test for fcvtmod TESTS += test-fcvtmod test-fcvtmod: CFLAGS += -march=rv64imafdc
Signature · 1 line
2.53.0
Quoted 16 lines · Joel Stanley
Hi Richard, I was testing your riscv vector load/store series and noticed there were some regressions with page crossing loads and stores. We don't have any tests for that in the tree, so I wrote some.
The tests trigger assertions in linux-user for me:
$ make -C build/tests/tcg/riscv64-linux-user run-test-rvv-ldst make: Entering directory 'build/tests/tcg/riscv64-linux-user' TEST test-rvv-ldst on riscv64 ** ERROR:../accel/tcg/user-exec.c:810:probe_access: assertion failed: (-(addr | TARGET_PAGE_MASK) >= size) timeout: the monitored command dumped core Aborted make: *** [Makefile:223: run-test-rvv-ldst] Error 134 make: Leaving directory 'build/tests/tcg/riscv64-linux-user'
Quoted 4 lines
I wrote the assembly one first before realising a C version would be easy enough to do too. I'm not sure about using memcmp to check (in case it's vectorised) so perhaps that's where the asm wins. I can tidy them up and send the preferred version if we decide to put it in the tree.
Thanks! I'll take a look at these failures.
r~
Quoted 6 lines · Joel Stanley
Hi Richard, I was testing your riscv vector load/store series and noticed there were some regressions with page crossing loads and stores. We don't have any tests for that in the tree, so I wrote some.
The tests trigger assertions in linux-user for me:
Quoted 9 lines
$ make -C build/tests/tcg/riscv64-linux-user run-test-rvv-ldst
make: Entering directory 'build/tests/tcg/riscv64-linux-user'
TEST test-rvv-ldst on riscv64
**
ERROR:../accel/tcg/user-exec.c:810:probe_access: assertion failed: (-(addr | TARGET_PAGE_MASK) >= size)
timeout: the monitored command dumped core
Aborted
make: *** [Makefile:223: run-test-rvv-ldst] Error 134
make: Leaving directory 'build/tests/tcg/riscv64-linux-user'Bah. Off by one bug. I'll post v2 shortly.
Thanks again.
r~
Quoted 18 lines · Joel Stanley
Hi Richard, I was testing your riscv vector load/store series and noticed there were some regressions with page crossing loads and stores.
We don't have any tests for that in the tree, so I wrote some.The tests trigger assertions in linux-user for me:
$ make -C build/tests/tcg/riscv64-linux-user run-test-rvv-ldst make: Entering directory 'build/tests/tcg/riscv64-linux-user' TEST test-rvv-ldst on riscv64 ** ERROR:../accel/tcg/user-exec.c:810:probe_access: assertion failed: (-(addr | TARGET_PAGE_MASK) >= size) timeout: the monitored command dumped core Aborted make: *** [Makefile:223: run-test-rvv-ldst] Error 134 make: Leaving directory 'build/tests/tcg/riscv64-linux-user'
Quoted 6 lines
I wrote the assembly one first before realising a C version would be easy enough to do too. I'm not sure about using memcmp to check (in case
it's vectorised) so perhaps that's where the asm wins. I can tidy them
up and send the preferred version if we decide to put it in the tree.
Why not just use the C one, but replace memcmp() with a simple for loop? That way we avoid the assembly and know memcmp() isn't vectorised and won't be in the future.
Alistair
Quoted 12 lines
Joel Stanley (2):
tests/tcg/riscv64: Vector load test tests/tcg/riscv64: Add intrinsics version of test-rvv-ldsttests/tcg/riscv64/test-rvv-ldst-intrinsics.c | 66 ++++++++++ tests/tcg/riscv64/Makefile.target | 19 +++ tests/tcg/riscv64/test-rvv-ldst.S | 131
+++++++++++++++++++3 files changed, 216 insertions(+)create mode 100644
tests/tcg/riscv64/test-rvv-ldst-intrinsics.ccreate mode 100644tests/tcg/riscv64/test-rvv-ldst.S