Repository navigation
Description
The Zfh format-conversion tests pass when FCVT.S.H, FCVT.H.S, FCVT.D.H, and FCVT.H.D copy their input register bits unchanged. Each helper widens a half-precision input and narrows it again, then checks only the final half-precision bits and accrued flags. Neither conversion is checked independently.
The affected code is fcvt.S cases 10 and 11, the RV32 wrapper, and TEST_FCVT_H_S / TEST_FCVT_H_D.
Tested riscv-tests 7b68f7b91f827f8d94cc1c57ff123752c5c8f704 with environment 6de71edb142be36319e380ce782c3d1830c65d68. Spike was 1.1.1-dev at 17e8a69fb75546dea445cfc0fb78769d2510f339. RISC-V GCC was 13.2.0 (13.2.0-11ubuntu1+12), GNU assembler was 2.42 (2.42-1ubuntu1+6), and Python was 3.12.3. QEMU 8.2.2 (1:8.2.2+ds-0ubuntu1.18) cross-checked the substituted programs and controls.
The specification is Volume I, 20240411, Zfh 1.0, source 6ee57d8997021aaa8025e208164763fe12e03c19. The conversion definitions require numerical conversion into the destination format.
With the attached repro/half-convert-roundtrip/ bundle, run on Ubuntu 24.04 with the toolchain and Spike build dependencies installed:
cd repro/half-convert-roundtrip
export JOB_WORK="$PWD/work"
ulimit -v 5242880
bash setup.sh
python3 expected.py
python3 reproduce.py --tests "$JOB_WORK/riscv-tests" \
--spike "$JOB_WORK/spike-build/spike" --work "$JOB_WORK/half-spike-repro"The script retains all comparisons and integer-to-half conversions. The original RV32 and RV64 programs exit 0. They still exit 0 after both RV32 format-conversion sites and all four RV64 sites become full-register copies. Each of the four one-way controls exits 0 with the real conversion and exits 1 at the result check with a raw copy. The script exits 0 after checking those outcomes.
For the exactly representable value -1.5, the required destination encodings are be00 for binary16, bfc00000 for binary32, and bff8000000000000 for binary64. All four conversions must leave fflags=0.
The FCVT.S.H core of verified oneway.S is below. The bundle includes all four directions, startup, and linker script. Inline control examples are offered under CC0-1.0.
csrwi fcsr, 0
la t0, input
flh f10, 0(t0)
fcvt.s.h f13, f10
fmv.x.w a0, f13
li a1, -1077936128 # sign-extended 0xbfc00000
bne a0, a1, fail
csrr a0, fflags
bnez a0, fail
# input, aligned to 8 bytes:
# .half 0xbe00The minimal test change is a direct one-way check for each conversion using valid source-format -1.5. Check the destination bits and flags before any inverse conversion. This catches unchanged copies in either direction.
The verifier modified Spike only locally so its four conversion handlers copied the whole source register. Both unchanged upstream ELFs still passed and all four unchanged one-way controls failed. All 66 supported F/D/Zfh scalar source programs passed this global fault. Existing D/S recoding checks did not cover these Zfh conversions.
This is a test coverage gap. No defective stock Spike or real processor is claimed. The experiment enabled F/D/Zfh with FLEN=64 and used aligned loads in software simulation. RV64 Zfh is registered by default. RV32 Zfh was an additional source check because its Makefrag is not registered by the top-level ISA Makefile. Other extensions and rounding-boundary cases were outside this check. No formal or hardware run was performed.
— ChipLab · CLAB-2026-893
Activity