Rust-GPU / Rust-GPU/rust-gpu

array memset testing

Open
#596 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
3.4k
Forks
125
PR merge metrics
No merged PRs in 30d

Description

UPDATED: I tried a few mutations in PR which do not trigger any CI failures on my personal fork: https://github.com/brody2consult/rust-gpu/pull/2

diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
index d86db1cbd0..c2143f4436 100644
--- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
+++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
@@ -290,22 +290,15 @@ macro_rules! simple_uni_op {
 }
 
 fn memset_fill_u16(b: u8) -> u16 {
-    b as u16 | ((b as u16) << 8)
+    0xbad_u16 | ((b as u16) << 10)
 }
 
 fn memset_fill_u32(b: u8) -> u32 {
-    b as u32 | ((b as u32) << 8) | ((b as u32) << 16) | ((b as u32) << 24)
+    0xbad_u32 | ((b as u32) << 20)
 }
 
 fn memset_fill_u64(b: u8) -> u64 {
-    b as u64
-        | ((b as u64) << 8)
-        | ((b as u64) << 16)
-        | ((b as u64) << 24)
-        | ((b as u64) << 32)
-        | ((b as u64) << 40)
-        | ((b as u64) << 48)
-        | ((b as u64) << 56)
+    0xbad_u64 | ((b as u64) << 30)
 }
 
 fn memset_dynamic_scalar(
@@ -384,9 +377,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                 32 => self
                     .constant_u32(self.span(), memset_fill_u32(fill_byte))
                     .def(self),
-                64 => self
-                    .constant_u64(self.span(), memset_fill_u64(fill_byte))
-                    .def(self),
                 _ => self.fatal(format!(
                     "memset on integer width {width} not implemented yet"
                 )),
@@ -2911,7 +2901,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
         };
         let elem_ty_spv = self.lookup_type(elem_ty);
         let pat = match self.builder.lookup_const_scalar(fill_byte) {
-            Some(fill_byte) => self.memset_const_pattern(&elem_ty_spv, fill_byte as u8),
+            Some(_) => self.memset_const_pattern(&elem_ty_spv, 123),
             None => self.memset_dynamic_pattern(&elem_ty_spv, fill_byte.def(self)),
         }
         .with_type(elem_ty);

and some more that do not trigger any compiletest failures or difftest failures in my personal workarea:

diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
index d86db1cbd0..b6a867933f 100644
--- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
+++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
@@ -290,21 +290,16 @@ macro_rules! simple_uni_op {
 }
 
 fn memset_fill_u16(b: u8) -> u16 {
-    b as u16 | ((b as u16) << 8)
+    b as u16
 }
 
 fn memset_fill_u32(b: u8) -> u32 {
-    b as u32 | ((b as u32) << 8) | ((b as u32) << 16) | ((b as u32) << 24)
+    b as u32
 }
 
 fn memset_fill_u64(b: u8) -> u64 {
     b as u64
         | ((b as u64) << 8)
-        | ((b as u64) << 16)
-        | ((b as u64) << 24)
-        | ((b as u64) << 32)
-        | ((b as u64) << 40)
-        | ((b as u64) << 48)
         | ((b as u64) << 56)
 }

I discovered this while investigating possible testing for a more general solution to #594.

I suspect the test cases from PR #586 may be able to help avoid this issue if we can adapt these to test memset array fill for u64, i64, u32, etc & check the disassembly. This could give me some more confidence in case we would ever want to refactor some of this memset-related code (someday).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in crates/rustc_codegen_spirv/src/builder/builder_methods.rs and review the memset helpers and array-fill paths. Adapt the test cases from PR #586 to cover memset array fills for u64, i64, and u32, then check the generated disassembly. Done means the tests detect the mutations described in the issue without compiletest or difftest gaps.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.