-
Notifications
You must be signed in to change notification settings - Fork 13.3k
simd_select_bitmask: the 'padding' bits in the mask are just ignored #140034
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
Conversation
Some changes occurred to the platform-builtins intrinsics. Make sure the cc @antoyo, @GuillaumeGomez, @bjorn3, @calebzulawski, @programmerjake The Miri subtree was changed cc @rust-lang/miri Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter |
/// | ||
/// The bitmask bit order matches `simd_bitmask`. | ||
/// | ||
/// # Safety | ||
/// Padding bits must be all zero. | ||
#[rustc_intrinsic] | ||
#[rustc_nounwind] | ||
pub unsafe fn simd_select_bitmask<M, T>(m: M, yes: T, no: T) -> T; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still unsafe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can intrinsics be safe? I think it would be safe with the expected generic arguments but could still raise mono errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we have allowed marking intrinsics as safe for a couple of years now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many SIMD intrinsics could be safe, but none are. I don't think this PR is the right place to change that.
Hmm. Yeah, this seems good to me. There was indeed a "wait... what are the semantics if there's ambiguity?" moment combined with "fuck it, make it UB", if I recall correctly. I remember extended arguments about other mask operations, but not this one. Those arguments were about why certain masks should require all-0s or all-1s for masks with elements of 1 or more bytes. Those arguments apply to those cases because whether the bits are taken from the top or bottom shouldn't really matter according to the semantics of those things and the behavior does get hardware specific. But those arguments can't apply to this one because the operation is on a "per bit" basis here to begin with. I think The only thing I remember being specifically about Thanks! @bors r+ rollup |
…ng, r=workingjubilee simd_select_bitmask: the 'padding' bits in the mask are just ignored Fixes rust-lang#137942: we documented simd_select_bitmask to require the 'padding' bits in the mask (the mask can sometimes be longer than the vector; I am referring to these extra bits as 'padding' here) to be zero, mostly because nobody felt like doing the research for what should be done when they are non-zero. However, codegen is already perfectly happy just ignoring them, so in practice they can have any value. Some of the intrinsic wrappers in stdarch have trouble ensuring that they are zero. So let's just adjust the docs and Miri to permit non-zero 'padding' bits. Cc `@Amanieu` `@workingjubilee`
Rollup of 11 pull requests Successful merges: - rust-lang#134034 (handle paren in macro expand for let-init-else expr) - rust-lang#138703 (chore: remove redundant words in comment) - rust-lang#139186 (Refactor `diy_float`) - rust-lang#139343 (Change signature of File::try_lock and File::try_lock_shared) - rust-lang#139780 (docs: Add example to `Iterator::take` with `by_ref`) - rust-lang#139802 (Fix some grammar errors and hyperlinks in doc for `trait Allocator`) - rust-lang#140034 (simd_select_bitmask: the 'padding' bits in the mask are just ignored) - rust-lang#140062 (std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently written into) - rust-lang#140485 (Optimize the codegen for `Span::from_expansion`) - rust-lang#140505 (linker: Quote symbol names in .def files) - rust-lang#140521 (interpret: better error message for out-of-bounds pointer arithmetic and accesses) r? `@ghost` `@rustbot` modify labels: rollup
…ng, r=workingjubilee simd_select_bitmask: the 'padding' bits in the mask are just ignored Fixes rust-lang#137942: we documented simd_select_bitmask to require the 'padding' bits in the mask (the mask can sometimes be longer than the vector; I am referring to these extra bits as 'padding' here) to be zero, mostly because nobody felt like doing the research for what should be done when they are non-zero. However, codegen is already perfectly happy just ignoring them, so in practice they can have any value. Some of the intrinsic wrappers in stdarch have trouble ensuring that they are zero. So let's just adjust the docs and Miri to permit non-zero 'padding' bits. Cc ``@Amanieu`` ``@workingjubilee``
Rollup of 10 pull requests Successful merges: - rust-lang#134034 (handle paren in macro expand for let-init-else expr) - rust-lang#138703 (chore: remove redundant words in comment) - rust-lang#139186 (Refactor `diy_float`) - rust-lang#139343 (Change signature of File::try_lock and File::try_lock_shared) - rust-lang#139780 (docs: Add example to `Iterator::take` with `by_ref`) - rust-lang#139802 (Fix some grammar errors and hyperlinks in doc for `trait Allocator`) - rust-lang#140034 (simd_select_bitmask: the 'padding' bits in the mask are just ignored) - rust-lang#140062 (std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently written into) - rust-lang#140485 (Optimize the codegen for `Span::from_expansion`) - rust-lang#140521 (interpret: better error message for out-of-bounds pointer arithmetic and accesses) r? `@ghost` `@rustbot` modify labels: rollup
…ng, r=workingjubilee simd_select_bitmask: the 'padding' bits in the mask are just ignored Fixes rust-lang#137942: we documented simd_select_bitmask to require the 'padding' bits in the mask (the mask can sometimes be longer than the vector; I am referring to these extra bits as 'padding' here) to be zero, mostly because nobody felt like doing the research for what should be done when they are non-zero. However, codegen is already perfectly happy just ignoring them, so in practice they can have any value. Some of the intrinsic wrappers in stdarch have trouble ensuring that they are zero. So let's just adjust the docs and Miri to permit non-zero 'padding' bits. Cc ```@Amanieu``` ```@workingjubilee```
…llaumeGomez Rollup of 12 pull requests Successful merges: - rust-lang#138703 (chore: remove redundant words in comment) - rust-lang#139186 (Refactor `diy_float`) - rust-lang#139343 (Change signature of File::try_lock and File::try_lock_shared) - rust-lang#139780 (docs: Add example to `Iterator::take` with `by_ref`) - rust-lang#139802 (Fix some grammar errors and hyperlinks in doc for `trait Allocator`) - rust-lang#140034 (simd_select_bitmask: the 'padding' bits in the mask are just ignored) - rust-lang#140062 (std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently written into) - rust-lang#140420 (rustdoc: Fix doctest heuristic for main fn wrapping) - rust-lang#140460 (Fix handling of LoongArch target features not supported by LLVM 19) - rust-lang#140538 (rustc-dev-guide subtree update) - rust-lang#140552 (allow `#[rustc_std_internal_symbol]` in combination with `#[naked]`) - rust-lang#140556 (Improve error output in case `nodejs` or `npm` is not installed for rustdoc-gui test suite) r? `@ghost` `@rustbot` modify labels: rollup
…llaumeGomez Rollup of 12 pull requests Successful merges: - rust-lang#138703 (chore: remove redundant words in comment) - rust-lang#139186 (Refactor `diy_float`) - rust-lang#139780 (docs: Add example to `Iterator::take` with `by_ref`) - rust-lang#139802 (Fix some grammar errors and hyperlinks in doc for `trait Allocator`) - rust-lang#140034 (simd_select_bitmask: the 'padding' bits in the mask are just ignored) - rust-lang#140062 (std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently written into) - rust-lang#140420 (rustdoc: Fix doctest heuristic for main fn wrapping) - rust-lang#140460 (Fix handling of LoongArch target features not supported by LLVM 19) - rust-lang#140538 (rustc-dev-guide subtree update) - rust-lang#140544 (Clean up "const" situation in format_args!(). ) - rust-lang#140552 (allow `#[rustc_std_internal_symbol]` in combination with `#[naked]`) - rust-lang#140556 (Improve error output in case `nodejs` or `npm` is not installed for rustdoc-gui test suite) r? `@ghost` `@rustbot` modify labels: rollup
…ng, r=workingjubilee simd_select_bitmask: the 'padding' bits in the mask are just ignored Fixes rust-lang#137942: we documented simd_select_bitmask to require the 'padding' bits in the mask (the mask can sometimes be longer than the vector; I am referring to these extra bits as 'padding' here) to be zero, mostly because nobody felt like doing the research for what should be done when they are non-zero. However, codegen is already perfectly happy just ignoring them, so in practice they can have any value. Some of the intrinsic wrappers in stdarch have trouble ensuring that they are zero. So let's just adjust the docs and Miri to permit non-zero 'padding' bits. Cc `@Amanieu` `@workingjubilee`
…uillaumeGomez Rollup of 12 pull requests Successful merges: - rust-lang#138703 (chore: remove redundant words in comment) - rust-lang#139186 (Refactor `diy_float`) - rust-lang#139780 (docs: Add example to `Iterator::take` with `by_ref`) - rust-lang#139802 (Fix some grammar errors and hyperlinks in doc for `trait Allocator`) - rust-lang#140034 (simd_select_bitmask: the 'padding' bits in the mask are just ignored) - rust-lang#140062 (std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently written into) - rust-lang#140420 (rustdoc: Fix doctest heuristic for main fn wrapping) - rust-lang#140460 (Fix handling of LoongArch target features not supported by LLVM 19) - rust-lang#140538 (rustc-dev-guide subtree update) - rust-lang#140544 (Clean up "const" situation in format_args!(). ) - rust-lang#140552 (allow `#[rustc_std_internal_symbol]` in combination with `#[naked]`) - rust-lang#140556 (Improve error output in case `nodejs` or `npm` is not installed for rustdoc-gui test suite) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#140034 - RalfJung:simd_select_bitmask-padding, r=workingjubilee simd_select_bitmask: the 'padding' bits in the mask are just ignored Fixes rust-lang#137942: we documented simd_select_bitmask to require the 'padding' bits in the mask (the mask can sometimes be longer than the vector; I am referring to these extra bits as 'padding' here) to be zero, mostly because nobody felt like doing the research for what should be done when they are non-zero. However, codegen is already perfectly happy just ignoring them, so in practice they can have any value. Some of the intrinsic wrappers in stdarch have trouble ensuring that they are zero. So let's just adjust the docs and Miri to permit non-zero 'padding' bits. Cc ````@Amanieu```` ````@workingjubilee````
Fixes #137942: we documented simd_select_bitmask to require the 'padding' bits in the mask (the mask can sometimes be longer than the vector; I am referring to these extra bits as 'padding' here) to be zero, mostly because nobody felt like doing the research for what should be done when they are non-zero. However, codegen is already perfectly happy just ignoring them, so in practice they can have any value. Some of the intrinsic wrappers in stdarch have trouble ensuring that they are zero. So let's just adjust the docs and Miri to permit non-zero 'padding' bits.
Cc @Amanieu @workingjubilee