Skip to content

c-variadic: support ppcf128 - #164004

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
folkertdev:ppcf128-c-variadic
Oct 18, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
folkertdev:ppcf128-c-variadic

Conversation

@folkertdev

@folkertdev folkertdev commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

tracking issue: #163323
cc #161787

On powerpc64 this needs a change to lower the alignment of ppcf128 to only 8 when read from a VaList.

On powerpc this needs some additional changes to the logic to match GCC. Of course, in clang the ABI of this type is completely broken, we'll see if my fix for that gets merged llvm/llvm-project#225956.

@folkertdev folkertdev added O-PowerPC Target: PowerPC processors F-c_longdouble `#![feature(c_longdouble)]` labels Oct 8, 2026
@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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. labels Oct 8, 2026
Comment on lines +199 to +228
// POWERPC: stwu 1, -32(1)
// POWERPC: lbz 5, 1(3)
// POWERPC-NEXT: cmplwi 5, 6
// POWERPC-NEXT: bgt 0, .LBB3_2
// POWERPC-NEXT: lwz 4, 8(3)
// POWERPC-NEXT: rlwinm 6, 5, 3, 24, 28
// POWERPC-NEXT: addi 5, 5, 2
// POWERPC-NEXT: add 4, 4, 6
// POWERPC-NEXT: addi 4, 4, 32
// POWERPC-NEXT: b .LBB3_3
// POWERPC-NEXT: .LBB3_2:
// POWERPC-NEXT: lwz 4, 4(3)
// POWERPC-NEXT: addi 4, 4, 7
// POWERPC-NEXT: rlwinm 4, 4, 0, 0, 28
// POWERPC-NEXT: addi 5, 4, 16
// POWERPC-NEXT: stw 5, 4(3)
// POWERPC-NEXT: li 5, 8
// POWERPC-NEXT: .LBB3_3:
// POWERPC-NEXT: lwz 6, 4(4)
// POWERPC-NEXT: stb 5, 1(3)
// POWERPC-NEXT: stw 6, 28(1)
// POWERPC-NEXT: lwz 3, 0(4)
// POWERPC-NEXT: stw 3, 24(1)
// POWERPC-NEXT: lwz 3, 12(4)
// POWERPC-NEXT: lfd 1, 24(1)
// POWERPC-NEXT: stw 3, 20(1)
// POWERPC-NEXT: lwz 3, 8(4)
// POWERPC-NEXT: stw 3, 16(1)
// POWERPC-NEXT: lfd 2, 16(1)
// POWERPC-NEXT: addi 1, 1, 32

@folkertdev folkertdev Oct 8, 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.

LLVM does a poor job here, GCC produces way fewer instructions https://godbolt.org/z/4xE4e9f5d.

View changes since the review

@folkertdev

Copy link
Copy Markdown
Contributor Author

r? beetrees
cc @tgross35

I've tested this with abi-cafe. Testing e.g. with the roundtrip test we have is inconvenient because we currently don't have any constructors.

@folkertdev
folkertdev marked this pull request as ready for review October 9, 2026 07:22
@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 Oct 9, 2026

@beetrees beetrees left a comment •

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.

The 32-bit soft-float case isn't quite right, but the hard-float case LGTM. For the rountrip test, couldn't we use transmute for now and leave a FIXME to replace with from_components once #164021 is merged?

View changes since this review


// "Align" the register count when the type is passed as `i64`.
if is_i64 || (is_f64 && is_soft_float_abi) {
if is_i64 || ((is_f64 || is_ppcf128) && is_soft_float_abi) {

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.

The ABI spec says that QUAD_GP (which is what ppcf128 falls into on soft float) is not aligned when passed in registers.

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 think that means we can read it as 2 f64 values? Because if it's not aligned it might be split between gpr and the overflow_arg_area?

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.

It's not aligned, but if there aren't 4 available GPRs the whole thing is passed in the overflow area. It's the same concept as passing it in FPRs, just with 4 registers instead of 2.

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
if is_i64 || ((is_f64 || is_ppcf128) && is_soft_float_abi) {
if is_i64 || (is_f64 && is_soft_float_abi) {

Since we're leaving soft-float support for later and this is against the specification, may as well not add is_ppcf128 here.

Comment thread compiler/rustc_codegen_llvm/src/va_arg.rs Outdated
Comment thread compiler/rustc_codegen_llvm/src/va_arg.rs Outdated
Comment thread compiler/rustc_codegen_llvm/src/va_arg.rs Outdated
Comment thread compiler/rustc_codegen_llvm/src/va_arg.rs Outdated
Float::F16 | Float::F16B | Float::F32 => unreachable!(),
Float::F64 | Float::F128 | Float::PpcF128 => { /* fall through */ }
Float::F64 | Float::F128 => { /* fall through */ }
Float::PpcF128 => return Align::EIGHT,

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.

Per the ABI spec, on soft float ppcf128 arguments are only passed with an alignment of 4. 8 is correct for hard float.

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 suspect we'll just read it as two f64 values

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 15, 2026
@rustbot

rustbot commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@folkertdev

Copy link
Copy Markdown
Contributor Author

We don't actually support any true softfloat targets (and the va_arg logic asserts this). We do have spe targets though, which are (from what I understand) kinda softfloat, but maybe not entirely?

So, I guess we try to properly support spe now? Those targets are extremely tier 3 though. I'd kinda rather do it as a follow-up?

@beetrees

Copy link
Copy Markdown
Contributor

Leaving soft-float for later is fine - just leave a FIXME for it next to the assert!(!is_soft_float_abi);.

@folkertdev folkertdev left a comment •

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 don't even have PartialEq for the type right now. We'll definitely come back to it when adding c_longdouble.

@rustbot ready

View changes since this review

Float::F16 | Float::F16B | Float::F32 => unreachable!(),
Float::F64 | Float::F128 | Float::PpcF128 => { /* fall through */ }
Float::F64 | Float::F128 => { /* fall through */ }
Float::PpcF128 => return Align::EIGHT,

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 suspect we'll just read it as two f64 values

@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 Oct 16, 2026
@rust-log-analyzer

This comment has been minimized.

@beetrees beetrees left a comment •

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.

Since we're leaving the roundtrip test for later, could you add a FIXME in tests/ui/c-variadic/roundtrip.rs for testing ppcf128<->__ibm128. Otherwise just two things:

View changes since this review


// "Align" the register count when the type is passed as `i64`.
if is_i64 || (is_f64 && is_soft_float_abi) {
if is_i64 || ((is_f64 || is_ppcf128) && is_soft_float_abi) {

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
if is_i64 || ((is_f64 || is_ppcf128) && is_soft_float_abi) {
if is_i64 || (is_f64 && is_soft_float_abi) {

Since we're leaving soft-float support for later and this is against the specification, may as well not add is_ppcf128 here.

Comment thread compiler/rustc_codegen_llvm/src/va_arg.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 16, 2026
@rust-log-analyzer

This comment has been minimized.

@folkertdev

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@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 Oct 17, 2026
Comment thread compiler/rustc_codegen_llvm/src/va_arg.rs Outdated
Comment thread compiler/rustc_codegen_llvm/src/va_arg.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 17, 2026
@folkertdev
folkertdev force-pushed the ppcf128-c-variadic branch 2 times, most recently from c441d90 to 8af06b3 Compare October 17, 2026 16:11

@folkertdev folkertdev left a comment •

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.

Sorry about that, that's what I get for doing it manually instead of copying from github.

@rustbot ready

View changes since this review

let max_regs = 8u8;
let use_regs = bx.icmp(IntPredicate::IntULT, num_regs, bx.const_u8(max_regs));
let reg_size = if is_passed_in_fprs { 8 } else { 4 };
let reg_incr = layout.size.bytes().div_ceil(u64::from(reg_size)) as u8;

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 went with naming it reg_incr because we already have num_regs so also having n_reg could cause confusion.

Comment on lines +119 to +129
// POWERPC-NEXT: .LBB2_2:
// POWERPC-NEXT: lwz 3, 4(5)
// POWERPC-NEXT: li 6, 8
// POWERPC-NEXT: addi 3, 3, 7
// POWERPC-NEXT: rlwinm 4, 3, 0, 0, 28
// POWERPC-NEXT: addi 3, 4, 8
// POWERPC-NEXT: stw 3, 4(5)
// POWERPC-NEXT: lwz 3, 0(4)
// POWERPC-NEXT: lwz 4, 4(4)
// POWERPC-NEXT: stb 6, 0(5)
// POWERPC-NEXT: blr

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 noticed some check lines were missing

Comment on lines -103 to +112
// POWERPC-NEXT: clrlwi 4, 3, 24
// POWERPC-NEXT: cmplwi 4, 7
// POWERPC-NEXT: rlwinm 4, 3, 0, 24, 30
// POWERPC-NEXT: cmplwi 4, 6
// POWERPC-NEXT: bgt 0, .LBB2_2
// POWERPC-NEXT: lwz 4, 8(5)
// POWERPC-NEXT: rlwinm 6, 3, 0, 29, 30
// POWERPC-NEXT: rlwinm 3, 3, 2, 27, 28
// POWERPC-NEXT: rlwinm 6, 3, 0, 0, 30
// POWERPC-NEXT: rlwinm 3, 3, 2, 24, 28

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.

The assembly changed a bit here, but I believe this is equivalent in practice. At least, the code seems correct, abi-cafe is happy, so this must be right. This is slightly different from clang/gcc though

https://godbolt.org/z/PqahaPhzo

@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 Oct 17, 2026

@beetrees beetrees left a comment •

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.

@rust-bors

rust-bors Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 24f5f82 has been tentatively approved by beetrees

It will be put into the queue for this repository once PR CI succeeds.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 17, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 18, 2026
@rust-bors

rust-bors Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: beetrees
Duration: 3h 19m 29s
Pushing 02fb0a1 to main...

@rust-bors
rust-bors Bot merged commit 02fb0a1 into rust-lang:main Oct 18, 2026
15 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor
What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 8006091 (parent) -> 02fb0a1 (this PR)

Test differences

Show 2 test diffs

2 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 02fb0a16311c3411fa373627706da085cd8fbd3c --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. test-x86_64-mingw-1: 1h 47m -> 3h 18m (+84.9%)
  2. dist-x86_64-msvc-alt: 1h 41m -> 2h 56m (+74.3%)
  3. test-i686-msvc: 1h 33m -> 2h 31m (+62.6%)
  4. dist-armhf-linux: 1h 3m -> 1h 30m (+42.9%)
  5. test-i686-gnu-nopt-1: 2h 22m -> 1h 22m (-42.5%)
  6. test-x86_64-rust-for-linux: 59m 30s -> 34m 32s (-42.0%)
  7. dist-powerpc64-linux-musl: 1h 9m -> 1h 37m (+41.4%)
  8. dist-arm-linux-musl: 1h 17m -> 1h 48m (+40.3%)
  9. dist-x86_64-netbsd: 1h 7m -> 1h 32m (+37.2%)
  10. test-x86_64-gnu-gcc-core-tests: 13m 57s -> 9m 7s (-34.6%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (02fb0a1): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.5%, -0.0%] 9
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary 5.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
5.0% [5.0%, 5.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results (secondary 3.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.3% [3.3%, 3.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

Results (primary 0.0%, secondary 0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.0% [0.0%, 0.0%] 1
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [0.0%, 0.0%] 1

Bootstrap: 491.611s -> 489.75s (-0.38%)
Artifact size: 408.96 MiB -> 409.00 MiB (0.01%)

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

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-c_longdouble `#![feature(c_longdouble)]` merged-by-bors This PR was explicitly merged by bors. O-PowerPC Target: PowerPC processors 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants