add IBM f128 type - #162156
add IBM f128 type#162156folkertdev wants to merge 7 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
2ef8b4a to
fbe3899
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d0e13f1 to
9251025
Compare
| #[inline] | ||
| fn eq(&self, other: &ppcf128) -> bool { | ||
| self.to_components() == other.to_components() | ||
| } |
There was a problem hiding this comment.
Equality and comparison is just defined on the components in the obvious way
It's unclear to me why these are libcalls at all (you're not saving much code really).
There was a problem hiding this comment.
Neither Clang nor GCC seem to actually call these libcalls; I think the advantage of using the LLVM intrinsic is that it would enable further LLVM optimisations, but that definitely isn't needed for this initial PR.
| #[unstable(feature = "powerpc_ppcf128", issue = "161787")] | ||
| #[allow(non_camel_case_types)] | ||
| #[doc(cfg(any(target_arch = "powerpc", target_arch = "powerpc64")))] | ||
| pub struct ppcf128(u128); |
There was a problem hiding this comment.
we may need/want to make this a #[align(16)] struct ppcf128([u8; 16]) instead to work around LLVM bitcast issues between i128 and ppcf128. We'll see.
There was a problem hiding this comment.
Wouldn't it make the most sense for it to be #[repr(C, align(16))] struct ppcf128(f64, f64)?
There was a problem hiding this comment.
Right, or [f64; 2]. repr(C) is not quite right though (neither is repr(Rust) I guess, but the array solves the field ordering problem)
There was a problem hiding this comment.
I opted for [f64; 2] because that is what Simd does too so it's less likely to cause issues.
There was a problem hiding this comment.
Sadly that runs into some asserts (when debug_assertions are on) on Scalars truly being scalar (and not a wrapper around some other BackendRepr). So, I've reverted to u128 for now. I don't think LLVM can currently see that in the syntax we're using u128, and we're careful to transmute to [f64; 2], never u128, so we're probably fine.
In any case, it's not really something I want to block the initial PR on.
|
r? tgross35 |
|
Some changes occurred in compiler/rustc_attr_ir cc @jdonszelmann, @JonathanBrouwer
This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a, @makai410
cc @bjorn3 |
| } else if large.is_infinite() && is_elfv2 { | ||
| small == 0.0 |
There was a problem hiding this comment.
32-bit PowerPC also requires small == 0.0 per it's ABI spec. While the ELFv1 ABI spec doesn't explicitly mention that small == 0.0, if small != 0.0 then expressions like x == ppcf128::INFINITY won't work (as compilers just compare both parts without ignoring the second if the first is infinity), so it seems likely it is de-facto required even though not explicitly stated. Therefore I think it's safest to always require that small == 0.0 for now and check with LLVM and GCC what their expectations are before stabilisation.
| } else if large.is_infinite() && is_elfv2 { | ||
| small == 0.0 | ||
| } else { | ||
| large.abs() > small.abs() && large + small == large |
There was a problem hiding this comment.
| large.abs() > small.abs() && large + small == large | |
| large + small == large |
large + small == large guarantees that large.abs() > small.abs().
|
|
||
| /// Negative infinity (−∞). | ||
| #[unstable(feature = "powerpc_ppcf128", issue = "161787")] | ||
| pub const NEG_INFINITY: Self = Self::from_components(f64::NEG_INFINITY, 0.0); |
There was a problem hiding this comment.
Could library support other than the type itself be split to a separate PR? There's enough to review on the compiler side and up to the codegen tests doesn't need any of this.
There was a problem hiding this comment.
Sure, I've split it out.
There was a problem hiding this comment.
Should probably have an asm test to go with it
There was a problem hiding this comment.
Sure, I've added one.
| /// it can be safely ignored by always picking i8. | ||
| hint_vector_elem: Primitive, | ||
| }, | ||
| } |
There was a problem hiding this comment.
This feels like an unusual addition since the other variants in this enum are scalar registers. Can we treat it more like a scalarpair or a struct { f64, f64 } for Rust's ABI purposes?
@RalfJung may have ideas
There was a problem hiding this comment.
I don't think that works, if you look at where this is needed (specifically in homogenous_aggregate).
Note that f16b actually runs into the same issue, I've just not been able to get it to miscompile but in aggregates bfloat turns into half, e.g. https://godbolt.org/z/Mxr7axj7z.
There was a problem hiding this comment.
The entire callconv system is terrible and needs to be redesigned from scratch. We're just making the inevitable rewrite harder by continuing to delay it. Now that we have people funded to work on rustc I hope we can get those funds to be used for less fun work such as a rewrite. :)
(Actually to me that sounds like very fun work. If I had the time I'd do it. But it's unlikely that I will have time time any time soon.)
In the mean time we can continue to add more hacks to the existing hacks. 🤷
There was a problem hiding this comment.
RegKind at the moment is more "primitive type passed to LLVM", so adding PpcF128 here isn't making the problem any worse (e.g. a RegKind::Integer can get split over multiple actual integer registers).
There was a problem hiding this comment.
That seems worth putting in a doc comment on this type.
There was a problem hiding this comment.
(To be slightly more precise, RegKind is the "kind" of LLVM type, which is combined with a Size to make Reg, which represents the "primitive type passed to LLVM".)
There was a problem hiding this comment.
I've added some brief comments (trying to use "backend" instead of "llvm").
There was a problem hiding this comment.
I think LLVM would be more honest here. ;) Other backends just somehow have to deal with this.
View all comments
tracking issue: #161787
aka
__ibm128,ppc_fp128, etc. Making this change without having settled on a final name is a bit awkward but hopefully we can get some rounds of review in anyway.