Repository navigation
riscv: avoid FMA error recovery for directed fmadd.s - #315
carlosqwqqwq wants to merge 4 commits into
Conversation
|
The result is correct, but flags regress: Only NX raised by fadd64 is kept, the NX/UF raised by f64->f32 is discarded. Whenever the f64 sum is exact but not representable in f32, NX is lost. if (mode == FPU_LIB_ROUND_TZ || mode == FPU_LIB_ROUND_DN || mode == FPU_LIB_ROUND_UP) {
ret = fpu_fcvt_f64_to_f32(sum);
if ((fpu_get_exceptions() & ~old_exceptions & FPU_LIB_FLAG_NX)
&& (fpu_bit_f32_to_u32(ret) & FPU_LIB_FP32_NOSIGNED_MASK) < FPU_LIB_FP32_MINIMUM_NORM) {
fpu_raise_exceptions(FPU_LIB_FLAG_UF); // Inexact and tiny after rounding
}
} else {
err = fpu_add_error64(sum, mul, add);
ret = fpu_fcvt_f64_to_f32(fpu_odd_round64(sum, err));
} |
10e7174 to
4ce7e73
Compare
16fb092 to
6a7d73a
Compare
|
Rebased onto current |
|
The first CI run for |
|
Follow-up: the latest head is |
|
Guest probe matrix rerun against this exact head (
So the directed path this PR changes is fully aligned with QEMU in both RVVM modes; the remaining RNE-only flag delta belongs to the separate spurious-NX report (#310 / PR #316), not to the directed fix here. |
riscv: avoid FMA error recovery for directed fmadd.s
Fixes #309
Commit message
Description
The
fpu_fma32error-recovery calculation is exact only for RNE. For directed modes it can cross an f32 grid point and mishandleNX/UF. Convert the f64 sum directly in directed modes, keep the stickyNXflag untouched, and addUFonly when this operation newly raisesNXand produces a subnormal result. Compute the TwoSum correction only for the nearest modes. The change is limited tosrc/util/fpu_lib.h.Validation
staging(e7214efa), head8f60a966; x86_64make binpasses and the builtin-FMA-Werrorwarning is fixed.old_exceptions, leaves stickyNXuntouched, and skips TwoSum in directed modes.8f60a966(no-JIT and JIT shims vsqemu-riscv64):f32_single_probe(16 lines),fma_f32_rdn_probe(24 lines),f32_min_probe(1 line): 0 differences from QEMU in both modes.fma_f32_random_probe(16000 lines): everyrtz/rdn/ruprow matches QEMU bit-for-bit including flags; the 663 differing rows are allrneand belong to the separate round-to-nearest spurious-NXreport (FMA raises spurious NX for exact fused results #310 / PR riscv: don't leak spurious NX from the FMA error-recovery path #316).The patch is independently applicable to the
stagingbranch. Its scope is finitefmadd.sdirected rounding under RTZ/RDN/RUP; other FMA root causes remain outside this patch.