Skip to content

Conversation

@chenx97
Copy link
Contributor

@chenx97 chenx97 commented Oct 30, 2025

MIPS64 needs to put a padding argument before an aggregate argument when
this argument is in an odd-number position, starting from 0, and has an
alignment of 16 bytes or higher, e.g.
void foo(int a, max_align_t b); is the same as
void foo(int a, long _padding, max_align_t b);

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 30, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@chenx97 chenx97 marked this pull request as draft October 31, 2025 11:47
@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 31, 2025
@chenx97

This comment was marked as resolved.

@chenx97 chenx97 force-pushed the mips64-padding-aggregate-args branch from fa68eff to 2b8161f Compare November 2, 2025 16:34
@chenx97 chenx97 marked this pull request as ready for review November 2, 2025 16:35
@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 Nov 2, 2025
@chenx97
Copy link
Contributor Author

chenx97 commented Nov 4, 2025

r? @workingjubilee

@rustbot
Copy link
Collaborator

rustbot commented Nov 4, 2025

workingjubilee is currently at their maximum review capacity.
They may take a while to respond.

@chenx97 chenx97 force-pushed the mips64-padding-aggregate-args branch from 2b8161f to 4c08196 Compare November 7, 2025 09:33
@rustbot

This comment has been minimized.

@chenx97
Copy link
Contributor Author

chenx97 commented Nov 13, 2025

r? @petrochenkov

@petrochenkov
Copy link
Contributor

r? @workingjubilee
I've stolen one PR from workingjubilee's queue instead.

@rustbot
Copy link
Collaborator

rustbot commented Nov 13, 2025

workingjubilee is currently at their maximum review capacity.
They may take a while to respond.

@workingjubilee
Copy link
Member

Fair trade.

@workingjubilee
Copy link
Member

workingjubilee commented Nov 13, 2025

@chenx97 re: your PR message: a is an alignment, and a is (8 < a) && (a <= 16)? Since 8 is not less than a if a == 8, then doesn't that mean a == 16? Or do you mean let 8 | 16 = a;?

Comment on lines 88 to 89
let align = arg.layout.align.abi.max(dl.i64_align).min(dl.i128_align);
let pad_i32 = !offset.is_aligned(align);
Copy link
Member

Choose a reason for hiding this comment

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

So we take the max of align_of::<ArgType>() and align_of::<i64>(), guaranteeing it is at least align_of::<i64>(), and then we take the minimum of align_of::<i128>() and align_of::<ArgType>(), guaranteeing it is no more than align_of::<i128>()...

So, is there a reason this isn't just Ord::clamp(arg.layout.align.abi, dl.i64_align, dl.128_align)?

And then we ask if the offset is aligned to this? ... but we're changing the alignment so that u8, u16, etc. don't align...? You can easily convince me this PR is correct for MIPS, but I'm not sure how much this makes sense with respect to the PR description.

Copy link
Contributor Author

@chenx97 chenx97 Nov 14, 2025

Choose a reason for hiding this comment

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

So, is there a reason this isn't just Ord::clamp(arg.layout.align.abi, dl.i64_align, dl.128_align)?

There is no reason other than that this line comes from existing code in mips.rs:28. I'll update this patch accordingly.

but we're changing the alignment so that u8, u16, etc. don't align...?

The offset starts from 0 and only increments in an aligned manner, and u8, u16 and u32 are always as aligned as u64: *offset = offset.align_to(align) + size.align_to(align);

You can easily convince me this PR is correct for MIPS, but I'm not sure how much this makes sense with respect to the PR description.

In that case, I need help with improving my description and commit message.

Copy link
Member

@workingjubilee workingjubilee Nov 14, 2025

Choose a reason for hiding this comment

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

Well, usually when I note a value is in a range, even though it's a commit message or PR, I deliberately use Rust's range syntax and say it's in the range instead of < or <=, because I make mistakes like the one you made if I don't.

Similar to mips, mips64 also adds a padding register when an aggregate argument is not passed with an aligned offset,

I do not think "add a padding register when an aggregate argument is not passed with an aligned offset" is quite right. That makes it sound a bit like when you pass a 1-byte struct, it uses 9 bytes, that byte plus an entire register! It's more like, "pads aggregates up to the 64-bit register size", right?

@chenx97 chenx97 force-pushed the mips64-padding-aggregate-args branch from 4c08196 to e03382d Compare November 14, 2025 06:13
@rustbot
Copy link
Collaborator

rustbot commented Nov 14, 2025

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

MIPS64 needs to put a padding argument before an aggregate argument when
this argument is in an odd-number position, starting from 0, and has an
alignment of 16 bytes or higher, e.g.
`void foo(int a, max_align_t b);` is the same as
`void foo(int a, long _padding, max_align_t b);`

This fix uses an i32 padding, but it should work just fine because i32 is
aligned like i64 for arguments.
@chenx97 chenx97 force-pushed the mips64-padding-aggregate-args branch from e03382d to a23c4cc Compare November 14, 2025 06:20
@chenx97 chenx97 changed the title callconv: adapt mips padding logic to mips64 callconv: fix mips64 aggregate argument passing for C FFI Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants