Skip to content

simd intrinsics with mask: accept unsigned integer masks, and fix some of the errors #137953

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

Merged
merged 1 commit into from
Apr 21, 2025

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Mar 3, 2025

It's not clear at all why the mask would have to be signed, it is anyway interpreted bitwise. The backend should just make sure that works no matter the surface-level type; our LLVM backend already does this correctly. The note of "the mask may be widened, which only has the correct behavior for signed integers" explains... nothing? Why can't the code do the widening correctly? If necessary, just cast to the signed type first...

Also while we are at it, fix the errors. For simd_masked_load/store, the errors talked about the "third argument" but they meant the first argument (the mask is the first argument there). They also used the wrong type for expected_element.

I have extremely low confidence in the GCC part of this PR.

See discussion on Zulip

@rustbot
Copy link
Collaborator

rustbot commented Mar 3, 2025

r? @Nadrieril

rustbot has assigned @Nadrieril.
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

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 3, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 3, 2025

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Some changes occurred to the platform-builtins intrinsics. Make sure the
LLVM backend as well as portable-simd gets adapted for the changes.

cc @antoyo, @GuillaumeGomez, @bjorn3, @calebzulawski, @programmerjake

@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the simd-intrinsic-masks branch from 48bc564 to 26cb001 Compare March 3, 2025 18:00
@RalfJung
Copy link
Member Author

RalfJung commented Mar 3, 2025

@bjorn3 anything we have to do here in cranelift?

@RalfJung RalfJung force-pushed the simd-intrinsic-masks branch from 26cb001 to fa396bc Compare March 4, 2025 07:32
@Nadrieril
Copy link
Member

r? codegen

@rustbot rustbot assigned workingjubilee and unassigned Nadrieril Mar 5, 2025
@RalfJung RalfJung force-pushed the simd-intrinsic-masks branch from fa396bc to edadfc4 Compare March 19, 2025 19:24
@rustbot
Copy link
Collaborator

rustbot commented Mar 19, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@RalfJung
Copy link
Member Author

@workingjubilee this has been sitting here for a while. Should I roll another reviewer? :)

Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

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

r=me with/out the nit

@@ -133,8 +133,7 @@ codegen_ssa_invalid_monomorphization_inserted_type = invalid monomorphization of

codegen_ssa_invalid_monomorphization_invalid_bitmask = invalid monomorphization of `{$name}` intrinsic: invalid bitmask `{$mask_ty}`, expected `u{$expected_int_bits}` or `[u8; {$expected_bytes}]`

codegen_ssa_invalid_monomorphization_mask_type = invalid monomorphization of `{$name}` intrinsic: found mask element type is `{$ty}`, expected a signed integer type
.note = the mask may be widened, which only has the correct behavior for signed integers
codegen_ssa_invalid_monomorphization_mask_wrong_element_type = invalid monomorphization of `{$name}` intrinsic: found mask element type is `{$ty}`, expected an integer type
Copy link
Member

Choose a reason for hiding this comment

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

nit: the more common order is expected: ..., found: ..., not found: ..., expected: ... like here.

@bjorn3
Copy link
Member

bjorn3 commented Apr 18, 2025

@bjorn3 anything we have to do here in cranelift?

I don't think so. cg_clif doesn't actually check the lane type in many cases. Just that the vector argument is actually a vector.

@RalfJung RalfJung force-pushed the simd-intrinsic-masks branch from edadfc4 to 566dfd1 Compare April 20, 2025 10:25
@RalfJung
Copy link
Member Author

@bors r=WaffleLapkin

@bors
Copy link
Collaborator

bors commented Apr 20, 2025

📌 Commit 566dfd1 has been approved by WaffleLapkin

It is now in the queue for this repository.

@bors bors 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 Apr 20, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 20, 2025
…enton

Rollup of 5 pull requests

Successful merges:

 - rust-lang#137953 (simd intrinsics with mask: accept unsigned integer masks, and fix some of the errors)
 - rust-lang#139990 (transmutability: remove NFA intermediate representation)
 - rust-lang#140044 (rustc-dev-guide subtree update)
 - rust-lang#140051 (Switch exploit mitigations to mdbook footnotes)
 - rust-lang#140054 (docs: fix typo change from inconstants to invariants)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 20, 2025
…enton

Rollup of 5 pull requests

Successful merges:

 - rust-lang#137953 (simd intrinsics with mask: accept unsigned integer masks, and fix some of the errors)
 - rust-lang#139990 (transmutability: remove NFA intermediate representation)
 - rust-lang#140044 (rustc-dev-guide subtree update)
 - rust-lang#140051 (Switch exploit mitigations to mdbook footnotes)
 - rust-lang#140054 (docs: fix typo change from inconstants to invariants)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 20, 2025
…enton

Rollup of 5 pull requests

Successful merges:

 - rust-lang#137953 (simd intrinsics with mask: accept unsigned integer masks, and fix some of the errors)
 - rust-lang#139990 (transmutability: remove NFA intermediate representation)
 - rust-lang#140044 (rustc-dev-guide subtree update)
 - rust-lang#140051 (Switch exploit mitigations to mdbook footnotes)
 - rust-lang#140054 (docs: fix typo change from inconstants to invariants)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d15c603 into rust-lang:master Apr 21, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 21, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 21, 2025
Rollup merge of rust-lang#137953 - RalfJung:simd-intrinsic-masks, r=WaffleLapkin

simd intrinsics with mask: accept unsigned integer masks, and fix some of the errors

It's not clear at all why the mask would have to be signed, it is anyway interpreted bitwise. The backend should just make sure that works no matter the surface-level type; our LLVM backend already does this correctly. The note of "the mask may be widened, which only has the correct behavior for signed integers" explains... nothing? Why can't the code do the widening correctly? If necessary, just cast to the signed type first...

Also while we are at it, fix the errors. For simd_masked_load/store, the errors talked about the "third argument" but they meant the first argument (the mask is the first argument there). They also used the wrong type for `expected_element`.

I have extremely low confidence in the GCC part of this PR.

See [discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/257879-project-portable-simd/topic/On.20the.20sign.20of.20masks)
@RalfJung RalfJung deleted the simd-intrinsic-masks branch April 22, 2025 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

10 participants