Skip to content

Commit 2ce6c05

Browse files
ViralBShahclaude
andauthored
riscv: allow single-precision float ABI (lp64f / ilp32f) (#349)
* riscv: allow single-precision float ABI (lp64f / ilp32f) The header rejected __riscv_float_abi_single with an #error, but the F and D extensions share the same FCSR. The hard-float inline implementations below the guard use only csrr/csrw/csrc on fcsr and fflags, both of which are present whenever F is present. So lp64f / ilp32f can use the same code path as the double ABI. Closes #262. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * add CI coverage for the RISC-V single-float ABI (#262) The lp64f / ilp32f ABI used to be rejected by openlibm_fenv_riscv.h with an #error. Add a compile-only cross job that rebuilds the static library with -mabi=lp64f so the removed #error stays removed. A full lp64f shared-lib link or qemu run is impossible because Ubuntu's gcc-riscv64-linux-gnu ships only the lp64d sysroot; the static archive needs no libc link, so it still compiles riscv64/fenv.c (and every other source) under the single-float ABI. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9dc4c05 commit 2ce6c05

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

.github/workflows/cross.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,35 @@ jobs:
6666
QEMU_LD_PREFIX: /usr/${{ matrix.config.triple }}
6767
LD_LIBRARY_PATH: .
6868
run: make test ARCH=$ARCH TOOLPREFIX=$TRIPLE- ${CC:+CC=$CC} ${AR:+AR=$AR}
69+
70+
# Regression test for #262 / #349: the RISC-V single-float ABI (lp64f /
71+
# ilp32f) used to be rejected by include/openlibm_fenv_riscv.h with an
72+
# `#error`. This job rebuilds the whole library with `-mabi=lp64f` to make
73+
# sure the header (and the rest of openlibm) accepts that ABI.
74+
#
75+
# This is a COMPILE-ONLY check (build the static libopenlibm.a, no qemu run).
76+
# Ubuntu's gcc-riscv64-linux-gnu ships only the default lp64d sysroot, so a
77+
# full shared-library link or a qemu execution under lp64f is impossible
78+
# without a custom single-float sysroot the distro does not provide. Building
79+
# the static archive needs no libc/CRT link, so it compiles every source file
80+
# (including riscv64/fenv.c, which pulls in the fixed header) under the
81+
# single-float ABI and directly regresses the removed `#error`. Adding a
82+
# bespoke lp64f sysroot would be exactly the kind of fragile, unmaintainable
83+
# toolchain dependency that got mips64 disabled in #347, so we deliberately
84+
# avoid it.
85+
build-cross-riscv64-lp64f:
86+
runs-on: ubuntu-24.04
87+
timeout-minutes: 10
88+
name: build-cross-riscv64-lp64f
89+
steps:
90+
- uses: actions/checkout@v7
91+
- name: Install RISC-V toolchain
92+
run: |
93+
sudo apt update
94+
sudo apt install -y gcc-riscv64-linux-gnu
95+
- name: Build libopenlibm.a for the single-float ABI (lp64f)
96+
run: |
97+
make -j$(nproc) ARCH=riscv64 TOOLPREFIX=riscv64-linux-gnu- \
98+
CFLAGS_arch='-march=rv64imafc -mabi=lp64f' \
99+
SFLAGS_arch='-march=rv64imafc -mabi=lp64f' \
100+
libopenlibm.a

include/openlibm_fenv_riscv.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,10 @@ __BEGIN_DECLS
7474
extern const fenv_t __fe_dfl_env;
7575
#define FE_DFL_ENV (&__fe_dfl_env)
7676

77-
#if !defined(__riscv_float_abi_soft) && !defined(__riscv_float_abi_double)
78-
#if defined(__riscv_float_abi_single)
79-
#error single precision floating point ABI not supported
80-
#else
77+
#if !defined(__riscv_float_abi_soft) && !defined(__riscv_float_abi_double) && \
78+
!defined(__riscv_float_abi_single)
8179
#error compiler did not set soft/hard float macros
8280
#endif
83-
#endif
8481

8582
#ifndef __riscv_float_abi_soft
8683
#define __rfs(__fcsr) __asm __volatile("csrr %0, fcsr" : "=r" (__fcsr))

0 commit comments

Comments
 (0)