Skip to content

support memset on 128-bit integers - #595

Merged
Firestar99 merged 1 commit into
Rust-GPU:mainfrom
brody2consult:start-128-bit-array-fill
May 7, 2026
Merged

support memset on 128-bit integers#595
Firestar99 merged 1 commit into
Rust-GPU:mainfrom
brody2consult:start-128-bit-array-fill

Conversation

@brody2consult

@brody2consultbrody2consult commented May 5, 2026

Copy link
Copy Markdown
Contributor

resolves#594

This is a quick solution to support the case I described in #594:

pubfnnew_array_zero_fill_u128() -> [u128;4]{return[0;4];}

This proposal would help me get past the first build issue I have encountered with RustCrypto.

I would love to support non-zero memset fill for both u128 & i128 as discussed in #594, but this would involve some more work in testing to hopefully ensure that this is done correctly & not likely broken by potential future refactoring.

I would be happy to address any possible feedback on my first contribution to Rust-GPU.

TODO

  • squash commits before merging - Reviewers please let me know if you want me to do this or if you want to do this yourself

@brody2consultbrody2consult mentioned this pull request May 5, 2026
@brody2consultbrody2consult changed the title u128 array zero fillu128 array zero fill - quick solutionMay 5, 2026
@brody2consult
brody2consultforce-pushed the start-128-bit-array-fill branch from f2e86c0 to fbb18afCompareMay 5, 2026 20:33
@brody2consult
brody2consult marked this pull request as ready for review May 6, 2026 01:13

@brody2consultbrody2consult left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

A couple nits - I am already testing a resolution in personal PR: brody2consult#1 - now resolved ✅

I will push the updates to this PR if I do not encounter any failures in brody2consult#1 - now done ✅

Comment threadcrates/rustc_codegen_spirv/src/builder/builder_methods.rs Outdated
Comment threadtests/compiletests/ui/lang/core/array/new_array_zero_fill_u128.rs Outdated
@brody2consultbrody2consult changed the title u128 array zero fill - quick solutionu128 array zero fill (quick solution)May 6, 2026
@brody2consult
brody2consultforce-pushed the start-128-bit-array-fill branch from e8b869c to ae65a4cCompareMay 6, 2026 06:52
@Firestar99
Firestar99force-pushed the start-128-bit-array-fill branch from ae65a4c to 4afcd1bCompareMay 6, 2026 10:17
@Firestar99Firestar99 changed the title u128 array zero fill (quick solution)support memset on 128bit integersMay 6, 2026
@Firestar99

Copy link
Copy Markdown
Member

I've generalized it to work with arbitrary bitpatterns and on signed and unsigned 128 bit integers. If you could confirm this patch works for you, I'd be happy to merge it.

I wrote this into the compiletest:

crypto-common has a proc macro to implement code for u8, u16, u32, u16 and u128, which means we need our codegen
to handle the u128 case for the crate to even compile. Specifically, this calls memset_const_pattern with u128.

Note that the u128 path is unusable anyway as 128bit integer are not supported in SPIR-V. So if this is used nowhere
in any entry point, our post-link DCE will remove the u128 code and the SPIR-V will be valid.
https://github.com/RustCrypto/traits/blob/f896a76d4468f1ff855b651124fd5b5378a3417f/crypto-common/src/hazmat.rs#L61-L83

Generally, we do accept patches that do enable you to use crates that previously didn't compile, even if you can't use the u128bit path. In similar vein, we've added black_box support by just doing a noop, since we can't actually provide a proper black box in SPIR-V.

brody2consult

This comment was marked as outdated.

@brody2consultbrody2consult changed the title support memset on 128bit integerssupport memset on 128-bit integersMay 6, 2026
Co-authored-by: firestar99 <firestar99@vectorware.com>
@brody2consult
brody2consultforce-pushed the start-128-bit-array-fill branch from 4afcd1b to b4308b4CompareMay 6, 2026 18:21
@brody2consult

brody2consult commented May 6, 2026

Copy link
Copy Markdown
ContributorAuthor

I just force-pushed another update to update the test comments, use "128-bit" with hyphen in the title, and add you as co-author. I changed the link to link to the code that actually failed to compile. Good to go from my end assuming that the tests continue to succeed.

I have also updated the PR description to resolve issue #594.

I do think it would be ideal to show a build warning in case of compiling with non-working functionality, in a similar fashion to "warn on large non-zero fills" as proposed in PR #586. But I would be happy to defer this for now.

I did try the following code mutations which do not trigger any failures in compiletests:

diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
index 1bea4fedfe..29667d8ed3 100644
--- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs+++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs@@ -309,8 +309,8 @@ fn memset_fill_u64(b: u8) -> u64 {
}
fn memset_fill_u128(b: u8) -> u128 {
- let b64 = memset_fill_u64(b) as u128;- b64 | b64 >> 64+ let b64 = memset_fill_u32(b) as u128;+ b64 >> 20
}
fn memset_dynamic_scalar(

I don't think this should be any issue since this is non-working functionality anyways. But I had wanted to find a way to test my own work on this as discussed in #596.

Thanks for your quick handling of this contribution; I am extremely happy overall.

@Firestar99
Firestar99 added this pull request to the merge queueMay 7, 2026
Merged via the queue into Rust-GPU:main with commit 66b7eb3May 7, 2026
23 checks passed
@brody2consult
brody2consult deleted the start-128-bit-array-fill branch May 8, 2026 05:57
Sign up for freeto 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.

128-bit array memset fill

2 participants

@brody2consult@Firestar99