riscv: include negative minimum values in FCVT fit checks - #282
Open
carlosqwqqwq wants to merge 1 commit into
Open
riscv: include negative minimum values in FCVT fit checks#282carlosqwqqwq wants to merge 1 commit into
carlosqwqqwq wants to merge 1 commit into
Conversation
Collaborator
|
You can speed up this check with something like return (bit_rotl32(f, 1) ^ 1) <= 0x9E000000U;Technically you can remove yet another instruction on x86 by going shl f, 1
sbc f, 0x9E000000
jb ...but it's messy in C, can't be implemented efficiently on ARM, and is deoptimized by GCC, so the _Bool fpu_f32_fits_i32_yuki(unsigned f) {
unsigned twof;
_Bool carry_in = __builtin_add_overflow(f, f, &twof);
unsigned carry_out;
__builtin_subc(twof, 0x9E000000U, carry_in, &carry_out);
return carry_out;
} |
The fits checks previously rejected the exact negative minimum (-2^31 for i32, -2^63 for i64) because the (value << 1) comparison cannot distinguish it from the positive bound. Fold the sign bit with a rotate so a single comparison covers both bounds, per review suggestion.
carlosqwqqwq
force-pushed
the
fix/fcvt-negative-min-fit
branch
from
August 13, 2026 00:01
e09c4ad to
73e78e1
Compare
Author
|
Thanks for the suggestion! Adopted the rotate-based check in all four fits helpers: (bit_rotl32(u, 1) ^ 1) <= 0x9E000000U for f32/i32, and the rotl64 counterparts for f64/i32 and the i64 pairs. Verified bit-exact equivalence against the previous two-comparison form over the full exponent/mantissa grids (zero mismatches), rebuilt cleanly, and force-pushed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
riscv: include negative minimum values in FCVT fit checks
Fixes #277
Commit message
Description
The float-to-integer fit predicates use a strict magnitude comparison and classify exactly representable
-2^31/-2^63inputs as invalid. Include the negative minimum bit patterns while retaining the positive overflow checks. The change is limited to the four fit predicates insrc/util/fpu_lib.h. It does not include the probe or research logs in the upstream change.Validation