Enforce deterministic signed zero behavior in float min/max and clamp#154157
Enforce deterministic signed zero behavior in float min/max and clamp#154157anmolxlight wants to merge 1 commit intorust-lang:mainfrom
Conversation
This drops the `nsz` tag from `minimum_number_nsz` and `maximum_number_nsz` intrinsics, and updates their fallback implementation in `core::intrinsics` to consistently order `-0.0 < +0.0`. `clamp` is also rewritten to use `self.max(min).min(max)` which uses the newly ordered min/max. Fixes rust-lang#154061
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred to the CTFE machinery Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter |
|
r? @scottmcm rustbot has assigned @scottmcm. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
|
This cannot land as-is since libs-api first has to agree that we even want this change. And for that we first need solid benchmarks (including some microbenchmarks) showing what the performance impact of this really is. I described all that in the issue you reference -- why did you ignore it all and not even mention it in the PR description? There's no point in doing all the work of renaming the intrinsic before we have team approval. Doing a good evaluation of the performance impact of this is a highly non-trivial task that requires, among other things, a solid understanding of x86 assembly. I don't have that understanding, so I won't try to do this and I can't help others do it either. I'd also recommend starting with just min and max, and worrying about clamp later. |
This PR fixes #154061 by dropping the
_nszflag inminimum_numberandmaximum_numberintrinsics.core::intrinsicsto properly order-0.0 < +0.0as required by the IEEE 754-2008 specification.clampinf32,f64,f16, andf128to useself.max(min).min(max)to take advantage of the deterministic behaviour.This guarantees deterministic output for signed zeros across all platforms, including x86 codegen.
Tested compilation locally.