Skip to content

Commit fbb18af

Browse files
committed
u128 array zero fill - quick solution
1 parent c904e5c commit fbb18af

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ fn memset_fill_u64(b: u8) -> u64 {
308308
| ((b as u64) << 56)
309309
}
310310

311+
fn zero_fill_u128() -> u128 {
312+
0 as u128
313+
}
314+
311315
fn memset_dynamic_scalar(
312316
builder: &mut Builder<'_, '_>,
313317
fill_var: Word,
@@ -387,6 +391,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
387391
64 => self
388392
.constant_u64(self.span(), memset_fill_u64(fill_byte))
389393
.def(self),
394+
128 => {
395+
// NOTE: This is a quick solution to support the following case from issue #594:
396+
// pub fn f() -> [u128; 2] { return [0; 2] }
397+
// This may be replaced by a more general memset fill solution in the future.
398+
if fill_byte != 0 {
399+
self.fatal("non-zero u128 array fill not implemented yet")
400+
}
401+
self.constant_u128(self.span(), zero_fill_u128()).def(self)
402+
}
390403
_ => self.fatal(format!(
391404
"memset on integer width {width} not implemented yet"
392405
)),

crates/rustc_codegen_spirv/src/codegen_cx/constant.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ impl<'tcx> CodegenCx<'tcx> {
5050
self.constant_int_from_native_unsigned(span, val)
5151
}
5252

53+
pub fn constant_u128(&self, span: Span, val: u128) -> SpirvValue {
54+
self.constant_int_from_native_unsigned(span, val)
55+
}
56+
5357
fn constant_int_from_native_unsigned(&self, span: Span, val: impl Into<u128>) -> SpirvValue {
5458
let size = Size::from_bytes(std::mem::size_of_val(&val));
5559
let ty = SpirvType::Integer(size.bits() as u32, false).def(span, self);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// build-pass
2+
3+
use spirv_std::spirv;
4+
5+
pub fn f() -> [u128; 2] { return [0; 2] }
6+
7+
#[spirv(fragment)]
8+
pub fn main() {}

0 commit comments

Comments
 (0)