Skip to content

add IBM f128 type - #162156

Open
folkertdev wants to merge 7 commits into
rust-lang:mainfrom
folkertdev:ppcf128
Open

folkertdev wants to merge 7 commits into
rust-lang:mainfrom
folkertdev:ppcf128

Conversation

@folkertdev

@folkertdev folkertdev commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

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.

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-core-stubs` PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Sep 1, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Sep 2, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rust-bors

This comment has been minimized.

@folkertdev
folkertdev force-pushed the ppcf128 branch 2 times, most recently from 2ef8b4a to fbe3899 Compare September 21, 2026 17:11
@folkertdev folkertdev added the F-c_longdouble `#![feature(c_longdouble)]` label Sep 21, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@folkertdev
folkertdev force-pushed the ppcf128 branch 2 times, most recently from d0e13f1 to 9251025 Compare September 21, 2026 22:01
Comment on lines +179 to +182
#[inline]
fn eq(&self, other: &ppcf128) -> bool {
self.to_components() == other.to_components()
}

@folkertdev folkertdev Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equality and comparison is just defined on the components in the obvious way

https://github.com/gcc-mirror/gcc/blob/c4a80f2d336b8fb78cc97f9107981119b1eff30b/libgcc/config/rs6000/ibm-ldouble.c#L280-L287

It's unclear to me why these are libcalls at all (you're not saving much code really).

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

@folkertdev folkertdev Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make the most sense for it to be #[repr(C, align(16))] struct ppcf128(f64, f64)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted for [f64; 2] because that is what Simd does too so it's less likely to cause issues.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread compiler/rustc_abi/src/callconv/reg.rs Outdated
@folkertdev

Copy link
Copy Markdown
Contributor Author

r? tgross35

@folkertdev
folkertdev marked this pull request as ready for review September 21, 2026 22:36
@rustbot

rustbot commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_ir

cc @jdonszelmann, @JonathanBrouwer

stdarch is developed in its own repository. If possible, consider making this change to rust-lang/stdarch instead.

cc @Amanieu, @sayantn

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a, @makai410

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

rustc_codegen_cranelift is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_cranelift instead.

cc @bjorn3

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 21, 2026
Comment thread compiler/rustc_abi/src/callconv/reg.rs Outdated
Comment thread compiler/rustc_codegen_llvm/src/llvm/ffi.rs Outdated
Comment on lines +96 to +97
} else if large.is_infinite() && is_elfv2 {
small == 0.0

@beetrees beetrees Sep 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review

} else if large.is_infinite() && is_elfv2 {
small == 0.0
} else {
large.abs() > small.abs() && large + small == large

@beetrees beetrees Sep 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
large.abs() > small.abs() && large + small == large
large + small == large

large + small == large guarantees that large.abs() > small.abs().

View changes since the review


/// Negative infinity (−∞).
#[unstable(feature = "powerpc_ppcf128", issue = "161787")]
pub const NEG_INFINITY: Self = Self::from_components(f64::NEG_INFINITY, 0.0);

@tgross35 tgross35 Sep 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I've split it out.

@tgross35 tgross35 Sep 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably have an asm test to go with it

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I've added one.

/// it can be safely ignored by always picking i8.
hint_vector_elem: Primitive,
},
}

@tgross35 tgross35 Sep 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@RalfJung RalfJung Sep 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 🤷

@beetrees beetrees Sep 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems worth putting in a doc comment on this type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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".)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some brief comments (trying to use "backend" instead of "llvm").

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think LLVM would be more honest here. ;) Other backends just somehow have to deal with this.

@rust-log-analyzer

This comment has been minimized.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-core-stubs` F-c_longdouble `#![feature(c_longdouble)]` PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants