Skip to content

fix(vfp): correct f32/f64 rounding for ceil/floor/nearest#51

Merged
avrabe merged 2 commits intomainfrom
fix/vfp-rounding
Mar 17, 2026
Merged

fix(vfp): correct f32/f64 rounding for ceil/floor/nearest#51
avrabe merged 2 commits intomainfrom
fix/vfp-rounding

Conversation

@avrabe
Copy link
Contributor

@avrabe avrabe commented Mar 17, 2026

Summary

ceil/floor/nearest all produced truncation — ignored rounding mode param and had ceil/floor FPSCR values swapped. Fixed both f32 and f64 encoders to manipulate FPSCR rounding bits correctly.

Test plan

  • 663 tests pass
  • clippy/fmt clean

🤖 Generated with Claude Code

avrabe and others added 2 commits March 17, 2026 20:04
PR #47 implemented f32 rounding pseudo-ops but had two bugs:
1. The rounding mode values for ceil (0b01) and floor (0b10) were swapped
2. All rounding modes used VCVTR.S32.F32 which always truncates toward
   zero, ignoring the mode parameter entirely

Fix by properly manipulating the FPSCR rounding mode bits [23:22]
for ceil/floor/nearest, using the non-R variant of VCVT.S32.F32
(bit[7]=0) which honours the FPSCR rounding mode, then restoring
FPSCR afterward. Trunc continues to use VCVTR (the R variant).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Same bug as f32: the f64 rounding encoder ignored the mode parameter
and always truncated toward zero. Also ceil/floor mode values were
swapped (ceil had 0b10 instead of 0b01, floor had 0b01 instead of
0b10).

Applies the same FPSCR rounding-mode manipulation fix to both ARM32
and Thumb-2 f64 encoders.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@avrabe avrabe merged commit dfb28ba into main Mar 17, 2026
5 checks passed
@avrabe avrabe deleted the fix/vfp-rounding branch March 17, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant