Skip to content
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

Use a C-safe return type for __rust_[ui]128_* overflowing intrinsics #735

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

tgross35
Copy link
Contributor

Most of our Rust-specific overflowing intrinsics currently return (i128, bool), which is not guaranteed to have a stable ABI. Switch to returning the overflow via a mutable parameter and only directly returning the integer result.

__rust_i128_mulo now matches the function signature of __muloti4, but they do not share the same ABI on Windows so we cannot easily deduplicate them.

tgross35 added a commit to tgross35/rust that referenced this pull request Dec 15, 2024
Combined with [1], this will change the overflowing multiplication
operations to return an `extern "C"`-safe type.

Link: rust-lang/compiler-builtins#735 [1]
@@ -66,31 +66,39 @@ intrinsics! {
AddSub::add(a,b)
}

pub extern "C" fn __rust_i128_addo(a: i128, b: i128) -> (i128, bool) {
a.addo(b)
pub extern "C" fn __rust_i128_addo(a: i128, b: i128, oflow: &mut i32) -> i128 {
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind keeping the existing functions for a bit and adding new functions with the new ABI? That way the cg_clif update and the compiler-builtins update don't have to be done at the exact same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do so if it helps, but why would this be needed? We pin the version of compiler_builtins with = now so it shouldn't get out of sync, and I won't merge this until the r-l/rust PR gets approved.

Copy link
Member

Choose a reason for hiding this comment

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

We pin the version of compiler_builtins with = now so it shouldn't get out of sync, and I won't merge this until the r-l/rust PR gets approved.

In that case I guess it is fine to keep as-is.

tgross35 added a commit to tgross35/rust that referenced this pull request Dec 17, 2024
Combined with [1], this will change the overflowing multiplication
operations to return an `extern "C"`-safe type.

Link: rust-lang/compiler-builtins#735 [1]
tgross35 added a commit to tgross35/rust that referenced this pull request Dec 17, 2024
Combined with [1], this will change the overflowing multiplication
operations to return an `extern "C"`-safe type.

Link: rust-lang/compiler-builtins#735 [1]
pub extern "C" fn __rust_u128_subo(a: u128, b: u128, oflow: &mut i32) -> u128 {
let (sub, o) = a.subo(b);
*oflow = o.into();
sub
Copy link
Member

Choose a reason for hiding this comment

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

cg_clif doesn't actually use the add/sub intrinsics, so I opened #745 to remove them.

Copy link
Member

@bjorn3 bjorn3 left a comment

Choose a reason for hiding this comment

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

Rustfmt doesn't work inside macros.

testcrate/tests/addsub.rs Show resolved Hide resolved
testcrate/tests/addsub.rs Show resolved Hide resolved
testcrate/tests/addsub.rs Show resolved Hide resolved
tgross35 added a commit to tgross35/rust that referenced this pull request Jan 9, 2025
Combined with [1], this will change the overflowing multiplication
operations to return an `extern "C"`-safe type.

Link: rust-lang/compiler-builtins#735 [1]
tgross35 added a commit to tgross35/rust that referenced this pull request Jan 10, 2025
Combined with [1], this will change the overflowing multiplication
operations to return an `extern "C"`-safe type.

Link: rust-lang/compiler-builtins#735 [1]
@tgross35
Copy link
Contributor Author

Thanks for the review. I won't merge this until bumping builtins is unblocked, and the rust-lang/rust PR is ready to go.

rust-cloud-vms bot pushed a commit to tgross35/rust that referenced this pull request Jan 11, 2025
Combined with [1], this will change the overflowing multiplication
operations to return an `extern "C"`-safe type.

Link: rust-lang/compiler-builtins#735 [1]
rust-cloud-vms bot pushed a commit to tgross35/rust that referenced this pull request Jan 11, 2025
Combined with [1], this will change the overflowing multiplication
operations to return an `extern "C"`-safe type.

Link: rust-lang/compiler-builtins#735 [1]
rust-cloud-vms bot pushed a commit to tgross35/rust that referenced this pull request Jan 11, 2025
Combined with [1], this will change the overflowing multiplication
operations to return an `extern "C"`-safe type.

Link: rust-lang/compiler-builtins#735 [1]
rust-cloud-vms bot pushed a commit to tgross35/rust that referenced this pull request Jan 12, 2025
Combined with [1], this will change the overflowing multiplication
operations to return an `extern "C"`-safe type.

Link: rust-lang/compiler-builtins#735 [1]
Most of our Rust-specific overflowing intrinsics currently return
`(i128, bool)`, which is not guaranteed to have a stable ABI. Switch to
returning the overflow via a mutable parameter and only directly
returning the integer result.

`__rust_i128_mulo` now matches the function signature of `__muloti4`,
but they do not share the same ABI on Windows so we cannot easily
deduplicate them.
@tgross35 tgross35 force-pushed the overflowing-c-safe-ret branch from ce68bb9 to a52b550 Compare January 15, 2025 03:45
@tgross35 tgross35 enabled auto-merge (rebase) January 15, 2025 03:48
@tgross35 tgross35 merged commit d1d275d into rust-lang:master Jan 15, 2025
26 checks passed
@tgross35 tgross35 deleted the overflowing-c-safe-ret branch January 15, 2025 03:53
tgross35 added a commit to tgross35/rust that referenced this pull request Jan 15, 2025
Combined with [1], this will change the overflowing multiplication
operations to return an `extern "C"`-safe type.

Link: rust-lang/compiler-builtins#735 [1]
jhpratt added a commit to jhpratt/rust that referenced this pull request Jan 15, 2025
…=bjorn3,antoyo

Use a C-safe return type for `__rust_[ui]128_*` overflowing intrinsics

Combined with [1], this will change the overflowing multiplication operations to return an `extern "C"`-safe type.

Link: rust-lang/compiler-builtins#735 [1]
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 15, 2025
Rollup merge of rust-lang#134338 - tgross35:overflowing-c-safe-ret, r=bjorn3,antoyo

Use a C-safe return type for `__rust_[ui]128_*` overflowing intrinsics

Combined with [1], this will change the overflowing multiplication operations to return an `extern "C"`-safe type.

Link: rust-lang/compiler-builtins#735 [1]
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this pull request Jan 16, 2025
Combined with [1], this will change the overflowing multiplication
operations to return an `extern "C"`-safe type.

Link: rust-lang/compiler-builtins#735 [1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants