-
Notifications
You must be signed in to change notification settings - Fork 71
Unordered float comparisons are emitted as normal, ordered comparisons #626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Are you sure this is actually caused by this bug and not #75? |
#75 seems to just describe the same issue, namely that The logic in |
This is possible, but as I mentioned in issue #75, I thought this was caused by the fact that GCC and clang give a different result for Maybe I'm wrong about this, though. |
Also, as mentioned here:
So, I'm not sure what to do about this if there's no guarantee. |
I don't think the sign should be relevant. This line
should evaluate to |
Ok. |
Ok, I'll try that. Do you have tips for faster test feedback? I think I'll add a |
Those tests are not ran via |
In other words, I've checked and ordered vs. non-ordered is not respected:
rustc_codegen_gcc/src/builder.rs
Lines 2391 to 2413 in cb499a2
That means that various operations involving
NaN
behave incorrectly: the unordered comparisons always return true when one of the arguments isNaN
, while the ordered ones return false. The easiest way I've found to verify the behavior is the expressionf64::NAN as u64
, which should evaluate to0u64
, but the GCC backend in debug mode evaluates to some large constant.When does this actually cause issues
From what I can tell, unordered comparisons, today, are used in two cases:
RealULT
: in therustc_codegen_gcc
functionfptoint_sat
RealUNE
: in the lowering of!=
on floats (inbin_op_to_fcmp_predicate
inrustc_codegen_ssa
)The behavior of
!=
seems correct to me, so the only problematic case isfptoint_sat
So, now what?
It looks like GCC just does not have the unordered comparisons
https://github.com/gcc-mirror/gcc/blob/3880271e94b7598b4f5d98c615b7fcddddee6d4c/gcc/jit/libgccjit.h#L1263-L1282
My suggestion is to map these operators to unreachable (they are not used today besides in
fptoint_sat
)and in
fptoint_sat
, use the logic currently only used for signed integers also for unsigned integers, to correct the nan caserustc_codegen_gcc/src/builder.rs
Lines 1883 to 1892 in cb499a2
Alternatively,
fcmp
could correct the result for unordered operationsI'd be happy to implement either of these options (or something else, if I'm missing something here)
sidenote: is there a quick way to use
./y test
to run tests in a particular file intests/run
? or just all the tests intests/
? Currently std is rebuilt every time and many tests build/run, and that's not a great feedback loop.The text was updated successfully, but these errors were encountered: