[PATCH 5/5] riscv: Enable TOINT_INTRINSICS with Zfa
Julian Zhu <[email protected]> Thu, 6 Aug 2026 18:25:31 +0800
| Newsgroups | gmane.comp.lib.glibc.alpha |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> --- 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