[PATCH v2 4/4] riscv: Enable TOINT_INTRINSICS with Zfa
Julian Zhu
jz531210@gmail.com
Thu Aug 13 14:23:20 GMT 2026
Provide Zfa-gated roundtoint and converttoint helpers for the common
libm argument-reduction code. Zfa turns roundtoint into one fround.d
instruction while non-Zfa builds continue using the generic reduction
path.
Signed-off-by: Julian Zhu <jz531210@gmail.com>
---
sysdeps/riscv/rvd/math_private.h | 44 ++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 sysdeps/riscv/rvd/math_private.h
diff --git a/sysdeps/riscv/rvd/math_private.h b/sysdeps/riscv/rvd/math_private.h
new file mode 100644
index 0000000000..9760702560
--- /dev/null
+++ b/sysdeps/riscv/rvd/math_private.h
@@ -0,0 +1,44 @@
+/* Configure optimized libm functions. RISC-V version.
+ 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/>. */
+
+#ifndef RISCV_MATH_PRIVATE_H
+#define RISCV_MATH_PRIVATE_H 1
+
+#include <stdint.h>
+
+#ifdef __riscv_zfa
+# define TOINT_INTRINSICS 1
+
+static inline double
+roundtoint (double x)
+{
+ return __builtin_round (x); /* Zfa: single fround.d. */
+}
+
+static inline int32_t
+converttoint (double x)
+{
+ int32_t r;
+ asm ("fcvt.w.d %0, %1, rmm" : "=r" (r) : "f" (x));
+ return r;
+}
+#endif /* __riscv_zfa */
+
+#include_next <math_private.h>
+
+#endif /* RISCV_MATH_PRIVATE_H */
--
2.53.0
More information about the Libc-alpha
mailing list