[RFC PATCH 2/5] riscv: libmvec: add ABI tests
Yao Zihong
zihong.plct@isrc.iscas.ac.cn
Sun Feb 8 22:04:37 GMT 2026
From: Zihong Yao <zihong.plct@isrc.iscas.ac.cn>
Add libmvec ABI tests for RISC-V by generating per-function
test targets and wiring them into the mathvec build.
The tests compile with RVV-capable -march flags and the fast-math
test options, and introduce a simple one-argument vector ABI
harness plus a log test.
Signed-off-by: Zihong Yao <zihong.plct@isrc.iscas.ac.cn>
---
sysdeps/riscv/rvd/Makeconfig | 34 ++++++++++++++++
sysdeps/riscv/rvd/Makefile | 14 +++++++
sysdeps/riscv/rvd/test-double-libmvec-log.c | 21 ++++++++++
sysdeps/riscv/rvd/test-vector-abi-arg1.h | 45 +++++++++++++++++++++
sysdeps/riscv/rvd/test-vector-abi.h | 36 +++++++++++++++++
5 files changed, 150 insertions(+)
create mode 100644 sysdeps/riscv/rvd/test-double-libmvec-log.c
create mode 100644 sysdeps/riscv/rvd/test-vector-abi-arg1.h
create mode 100644 sysdeps/riscv/rvd/test-vector-abi.h
diff --git a/sysdeps/riscv/rvd/Makeconfig b/sysdeps/riscv/rvd/Makeconfig
index 56f63a5d01..84649c6500 100644
--- a/sysdeps/riscv/rvd/Makeconfig
+++ b/sysdeps/riscv/rvd/Makeconfig
@@ -31,3 +31,37 @@ libmvec-double-funcs-with-data = \
libmvec-float-funcs = $(libmvec-float-funcs-bare) $(libmvec-float-funcs-with-data)
libmvec-double-funcs = $(libmvec-double-funcs-bare) $(libmvec-double-funcs-with-data)
+
+ifeq ($(config-machine),riscv64)
+libmvec-abi-test-arch-cflags = -march=rv64gcv
+else ifeq ($(config-machine),riscv32)
+libmvec-abi-test-arch-cflags = -march=rv32gcv
+endif
+
+libmvec-abi-test-cflags = \
+ $(libmvec-abi-test-arch-cflags) \
+ $(libm-test-fast-math-cflags) \
+ -fno-inline -fopenmp -Wno-unknown-pragmas
+
+# The base libmvec ABI tests.
+libmvec-abi-func-tests = \
+ $(addprefix test-float-libmvec-,$(libmvec-float-funcs)) \
+ $(addprefix test-double-libmvec-,$(libmvec-double-funcs)) \
+
+$(common-objpfx)libmvec.mk: $(common-objpfx)config.make
+ (echo "ifeq (\$$(subdir)\$$(build-mathvec),mathyes)"; \
+ echo; \
+ for t in $(libmvec-abi-func-tests); do \
+ echo "\$$(objpfx)$$t: \\"; \
+ echo " \$$(objpfx)$$t.o \\"; \
+ echo " \$$(libmvec)"; \
+ echo "LDLIBS-$$t = \$$(libmvec)"; \
+ echo; \
+ done; \
+ for t in $(libmvec-abi-func-tests); do \
+ echo "CFLAGS-$$t.c = \\"; \
+ echo " \$$(libmvec-abi-test-cflags)"; \
+ echo; \
+ done; \
+ echo "endif";)> $@T
+ mv -f $@T $@
diff --git a/sysdeps/riscv/rvd/Makefile b/sysdeps/riscv/rvd/Makefile
index 05cd793906..7f409e3f02 100644
--- a/sysdeps/riscv/rvd/Makefile
+++ b/sysdeps/riscv/rvd/Makefile
@@ -23,3 +23,17 @@ $(foreach f,$(libmvec-sysdep_routines), $(eval $(call riscv32-vector-cflags-temp
endif
endif
+
+ifneq ($(multi-arch),no)
+ifeq ($(subdir)$(build-mathvec),mathyes)
+
+ifneq ($(have-test-clang),yes)
+
+tests += \
+ $(libmvec-abi-func-tests) \
+
+endif
+
+endif
+
+endif
diff --git a/sysdeps/riscv/rvd/test-double-libmvec-log.c b/sysdeps/riscv/rvd/test-double-libmvec-log.c
new file mode 100644
index 0000000000..fa81716a1a
--- /dev/null
+++ b/sysdeps/riscv/rvd/test-double-libmvec-log.c
@@ -0,0 +1,21 @@
+/* Vector ABI test for RISC-V libmvec log.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#define LIBMVEC_TYPE double
+#define LIBMVEC_FUNC log
+#include "test-vector-abi-arg1.h"
diff --git a/sysdeps/riscv/rvd/test-vector-abi-arg1.h b/sysdeps/riscv/rvd/test-vector-abi-arg1.h
new file mode 100644
index 0000000000..1c28be8aa6
--- /dev/null
+++ b/sysdeps/riscv/rvd/test-vector-abi-arg1.h
@@ -0,0 +1,45 @@
+/* Test for vector ABI with 1 argument.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <math.h>
+#include <support/test-driver.h>
+
+/* Since libsupport_nonshared.a is placed before test-libmvec*.o, which
+ defines do_test, reference support_test_main here to include it to
+ avoid undefined reference to support_test_main. The libmvec ABI test
+ doesn't need other symbols in libsupport_nonshared.a. */
+__typeof (support_test_main) *support_test_main_p = support_test_main;
+
+#define N 1000
+LIBMVEC_TYPE x[N], c[N];
+
+int
+test_vector_abi (void)
+{
+ int i;
+ for (i = 0; i < N; i++)
+ c[i] = i / 3;
+
+#pragma omp simd
+ for (i = 0; i < N; i++)
+ x[i] = LIBMVEC_FUNC (c[i]);
+
+ return 0;
+}
+
+#include <test-vector-abi.h>
diff --git a/sysdeps/riscv/rvd/test-vector-abi.h b/sysdeps/riscv/rvd/test-vector-abi.h
new file mode 100644
index 0000000000..35d4d2042a
--- /dev/null
+++ b/sysdeps/riscv/rvd/test-vector-abi.h
@@ -0,0 +1,36 @@
+/* Test for vector ABI.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <stdbool.h>
+#include <support/test-driver.h>
+#include <sys/hwprobe.h>
+
+extern int test_vector_abi (void);
+
+static int
+do_test (void)
+{
+ struct riscv_hwprobe pair = { .key = RISCV_HWPROBE_KEY_IMA_EXT_0 };
+ if (__riscv_hwprobe (&pair, 1, 0, NULL, 0) != 0
+ || (pair.value & RISCV_HWPROBE_IMA_V) == 0)
+ return EXIT_UNSUPPORTED;
+
+ return test_vector_abi ();
+}
+
+#include <support/test-driver.c>
--
2.47.3
More information about the Libc-alpha
mailing list