Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ fn memset_fill_u64(b: u8) -> u64 {
| ((b as u64) << 56)
}

fn memset_fill_u128(b: u8) -> u128 {
let b64 = memset_fill_u64(b) as u128;
b64 | b64 >> 64
}

fn memset_dynamic_scalar(
builder: &mut Builder<'_, '_>,
fill_var: Word,
Expand Down Expand Up @@ -387,6 +392,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
64 => self
.constant_u64(self.span(), memset_fill_u64(fill_byte))
.def(self),
128 => self
.constant_u128(self.span(), memset_fill_u128(fill_byte))
.def(self),
_ => self.fatal(format!(
"memset on integer width {width} not implemented yet"
)),
Expand All @@ -402,6 +410,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
64 => self
.constant_i64(self.span(), memset_fill_u64(fill_byte) as i64)
.def(self),
128 => self
.constant_u128(self.span(), memset_fill_u128(fill_byte))
.def(self),
_ => self.fatal(format!(
"memset on integer width {width} not implemented yet"
)),
Expand Down
4 changes: 4 additions & 0 deletions crates/rustc_codegen_spirv/src/codegen_cx/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ impl<'tcx> CodegenCx<'tcx> {
self.constant_int_from_native_unsigned(span, val)
}

pub fn constant_u128(&self, span: Span, val: u128) -> SpirvValue {
self.constant_int_from_native_unsigned(span, val)
}

fn constant_int_from_native_unsigned(&self, span: Span, val: impl Into<u128>) -> SpirvValue {
let size = Size::from_bytes(std::mem::size_of_val(&val));
let ty = SpirvType::Integer(size.bits() as u32, false).def(span, self);
Expand Down
14 changes: 14 additions & 0 deletions tests/compiletests/ui/lang/core/array/init_array_i128.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// build-pass

use spirv_std::spirv;

pub fn u128_constant() -> [u128; 4] {
return [0x123456789ABCDEF0123456789ABCDEF; 4];
}

pub fn i128_constant() -> [i128; 4] {
return [0x123456789ABCDEF0123456789ABCDEF; 4];
}

#[spirv(fragment)]
pub fn main() {}
20 changes: 20 additions & 0 deletions tests/compiletests/ui/lang/core/array/init_array_i128_zeroed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// build-pass

use spirv_std::spirv;

/// `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>
pub fn u128_zero_fill() -> [u128; 4] {
return [0; 4];
}

pub fn i128_zero_fill() -> [i128; 4] {
return [0; 4];
}

#[spirv(fragment)]
pub fn main() {}
Loading