[RFC PATCH 5/5] riscv: libmvec: exercise RVV ABI calls
Yao Zihong
zihong.plct@isrc.iscas.ac.cn
Sun Feb 8 22:04:40 GMT 2026
From: Zihong Yao <zihong.plct@isrc.iscas.ac.cn>
Extend the vector ABI test to call RVV libmvec variants directly.
The ABI entry points are not wired up in compilers yet because the
ABI naming is still under review, so call the RVV variants directly as a
temporary way for testing.
Signed-off-by: Zihong Yao <zihong.plct@isrc.iscas.ac.cn>
---
sysdeps/riscv/rvd/test-vector-abi-arg1.h | 76 ++++++++++++++++++++++--
1 file changed, 72 insertions(+), 4 deletions(-)
diff --git a/sysdeps/riscv/rvd/test-vector-abi-arg1.h b/sysdeps/riscv/rvd/test-vector-abi-arg1.h
index 1c28be8aa6..a422184c14 100644
--- a/sysdeps/riscv/rvd/test-vector-abi-arg1.h
+++ b/sysdeps/riscv/rvd/test-vector-abi-arg1.h
@@ -16,9 +16,13 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <math.h>
+#include <riscv_vector.h>
+#include <stddef.h>
#include <support/test-driver.h>
+#include <v_math_variants.h>
+#include <v_math_names.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
@@ -28,6 +32,70 @@ __typeof (support_test_main) *support_test_main_p = support_test_main;
#define N 1000
LIBMVEC_TYPE x[N], c[N];
+#define LIBMVEC_PASTE4(a, b, c, d) LIBMVEC_PASTE4_INNER (a, b, c, d)
+#define LIBMVEC_PASTE4_INNER(a, b, c, d) a##b##c##d
+#define LIBMVEC_PASTE5(a, b, c, d, e) LIBMVEC_PASTE5_INNER (a, b, c, d, e)
+#define LIBMVEC_PASTE5_INNER(a, b, c, d, e) a##b##c##d##e
+#define LIBMVEC_PASTE6(a, b, c, d, e, f) \
+ LIBMVEC_PASTE6_INNER (a, b, c, d, e, f)
+#define LIBMVEC_PASTE6_INNER(a, b, c, d, e, f) a##b##c##d##e##f
+
+#define RVV_LIBMVEC_IS_VALID_TYPE_double 1
+#define RVV_LIBMVEC_IS_VALID_TYPE_float 1
+#define RVV_LIBMVEC_IS_VALID_TYPE_INNER(t) RVV_LIBMVEC_IS_VALID_TYPE_##t
+#define RVV_LIBMVEC_IS_VALID_TYPE(t) RVV_LIBMVEC_IS_VALID_TYPE_INNER (t)
+
+#if !RVV_LIBMVEC_IS_VALID_TYPE (LIBMVEC_TYPE)
+# error "Unsupported LIBMVEC_TYPE for RVV libmvec ABI test (expected float or double)"
+#endif
+
+#define RVV_LIBMVEC_ELEM_WIDTH_double 64
+#define RVV_LIBMVEC_ELEM_WIDTH_float 32
+#define RVV_LIBMVEC_ELEM_WIDTH_INNER(t) RVV_LIBMVEC_ELEM_WIDTH_##t
+#define RVV_LIBMVEC_ELEM_WIDTH(t) RVV_LIBMVEC_ELEM_WIDTH_INNER (t)
+
+#define LIBMVEC_ELEM_WIDTH RVV_LIBMVEC_ELEM_WIDTH (LIBMVEC_TYPE)
+
+#define LIBMVEC_VTYPE_WIDTH(width, lmul) \
+ LIBMVEC_PASTE5 (vfloat, width, m, lmul, _t)
+#define LIBMVEC_VSETVL_WIDTH(width, lmul) \
+ LIBMVEC_PASTE4 (__riscv_vsetvl_e, width, m, lmul)
+#define LIBMVEC_VLE_WIDTH(width, lmul) \
+ LIBMVEC_PASTE6 (__riscv_vle, width, _v_f, width, m, lmul)
+#define LIBMVEC_VSE_WIDTH(width, lmul) \
+ LIBMVEC_PASTE6 (__riscv_vse, width, _v_f, width, m, lmul)
+
+#define LIBMVEC_VTYPE(lmul) LIBMVEC_VTYPE_WIDTH (LIBMVEC_ELEM_WIDTH, lmul)
+#define LIBMVEC_VSETVL(lmul) LIBMVEC_VSETVL_WIDTH (LIBMVEC_ELEM_WIDTH, lmul)
+#define LIBMVEC_VLE(lmul) LIBMVEC_VLE_WIDTH (LIBMVEC_ELEM_WIDTH, lmul)
+#define LIBMVEC_VSE(lmul) LIBMVEC_VSE_WIDTH (LIBMVEC_ELEM_WIDTH, lmul)
+
+#define LIBMVEC_DECLARE_VARIANT(lmul, simdlen) \
+ extern LIBMVEC_VTYPE (lmul) V_NAME_D1 (lmul, simdlen, LIBMVEC_FUNC) \
+ (LIBMVEC_VTYPE (lmul))
+
+#define LIBMVEC_CALL_VARIANT(lmul, simdlen) \
+ do \
+ { \
+ size_t vl = LIBMVEC_VSETVL (lmul) (simdlen); \
+ LIBMVEC_VTYPE (lmul) vx = LIBMVEC_VLE (lmul) (c, vl); \
+ LIBMVEC_VTYPE (lmul) vr = V_NAME_D1 (lmul, simdlen, LIBMVEC_FUNC) (vx);\
+ LIBMVEC_VSE (lmul) (x, vr, vl); \
+ } \
+ while (0)
+
+#if LIBMVEC_ELEM_WIDTH == 64
+# define LIBMVEC_VARIANTS(X) RVV_LIBMVEC_VARIANTS_F64 (X)
+#elif LIBMVEC_ELEM_WIDTH == 32
+# define LIBMVEC_VARIANTS(X) RVV_LIBMVEC_VARIANTS_F32 (X)
+#else
+# error "Unsupported LIBMVEC_ELEM_WIDTH for RVV libmvec ABI test"
+#endif
+
+#define X(lmul, simdlen) LIBMVEC_DECLARE_VARIANT (lmul, simdlen);
+LIBMVEC_VARIANTS (X)
+#undef X
+
int
test_vector_abi (void)
{
@@ -35,9 +103,9 @@ test_vector_abi (void)
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]);
+#define X(lmul, simdlen) LIBMVEC_CALL_VARIANT (lmul, simdlen);
+ LIBMVEC_VARIANTS (X)
+#undef X
return 0;
}
--
2.47.3
More information about the Libc-alpha
mailing list