-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Add fallback for intrinsics::fabs
#159605
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3628,9 +3628,13 @@ pub const fn maximumf128(x: f128, y: f128) -> f128 { | |
| /// The stabilized versions of this intrinsic are available on the float | ||
| /// primitives via the `abs` method. For example, [`f32::abs`]. | ||
| #[rustc_nounwind] | ||
| #[rustc_const_unstable(feature = "core_intrinsics", issue = "none")] | ||
| #[rustc_intrinsic_const_stable_indirect] | ||
| #[rustc_intrinsic] | ||
| pub const fn fabs<T: bounds::FloatPrimitive>(x: T) -> T; | ||
| #[miri::intrinsic_fallback_is_spec] | ||
| pub const fn fabs<T: const bounds::FloatPrimitive>(x: T) -> T { | ||
| T::from_bits(x.to_bits() & !T::SIGN_MASK) | ||
| } | ||
|
Comment on lines
+3634
to
+3637
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RalfJung does this spark joy? I'd much rather have the one-liner duplicated 4 times than the (trivial, but still)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The question is whether it sparks more or less joy than copy-paste. The status quo is definitely not joyful. ;) But yeah I agree needing unsafe is pretty bad.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it spark joy now ? ^-^ pub const fn fabs<T: const bounds::FloatPrimitive>(x: T) -> T {
T::from_bits(x.to_bits() & !T::SIGN_MASK)
}
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that seems exactly as readable as the per-type version, just less duplicated :) |
||
|
|
||
| /// Copies the sign from `y` to `x` for `f16` values. | ||
| /// | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be macro'd if you'd rather i have no strong opinions on that
View changes since the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's hold off on using macros, this seems manageable now and a macro won't work for fallbacks that need a per-type implementation (e.g.
sinorfma)