Skip to content

Commit 4afcd1b

Browse files
brody2consultFirestar99
authored andcommitted
support memset on 128bit integers
1 parent c904e5c commit 4afcd1b

4 files changed

Lines changed: 49 additions & 0 deletions

File tree

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

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

311+
fn memset_fill_u128(b: u8) -> u128 {
312+
let b64 = memset_fill_u64(b) as u128;
313+
b64 | b64 >> 64
314+
}
315+
311316
fn memset_dynamic_scalar(
312317
builder: &mut Builder<'_, '_>,
313318
fill_var: Word,
@@ -387,6 +392,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
387392
64 => self
388393
.constant_u64(self.span(), memset_fill_u64(fill_byte))
389394
.def(self),
395+
128 => self
396+
.constant_u128(self.span(), memset_fill_u128(fill_byte))
397+
.def(self),
390398
_ => self.fatal(format!(
391399
"memset on integer width {width} not implemented yet"
392400
)),
@@ -402,6 +410,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
402410
64 => self
403411
.constant_i64(self.span(), memset_fill_u64(fill_byte) as i64)
404412
.def(self),
413+
128 => self
414+
.constant_u128(self.span(), memset_fill_u128(fill_byte))
415+
.def(self),
405416
_ => self.fatal(format!(
406417
"memset on integer width {width} not implemented yet"
407418
)),

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// build-pass
2+
3+
use spirv_std::spirv;
4+
5+
pub fn u128_constant() -> [u128; 4] {
6+
return [0x123456789ABCDEF0123456789ABCDEF; 4];
7+
}
8+
9+
pub fn i128_constant() -> [i128; 4] {
10+
return [0x123456789ABCDEF0123456789ABCDEF; 4];
11+
}
12+
13+
#[spirv(fragment)]
14+
pub fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// build-pass
2+
3+
use spirv_std::spirv;
4+
5+
/// `crypto-common` has a proc macro to implement code for u8, u16, u32, u16 and u128, which means we need our codegen
6+
/// to handle the u128 case for the crate to even compile. Specifically, this calls `memset_const_pattern` with u128.
7+
///
8+
/// Note that the u128 path is unusable anyway as 128bit integer are not supported in SPIR-V. So if this is used nowhere
9+
/// in any entry point, our post-link DCE will remove the u128 code and the SPIR-V will be valid.
10+
/// <https://github.com/RustCrypto/traits/blob/f896a76d4468f1ff855b651124fd5b5378a3417f/crypto-common/src/hazmat.rs#L61-L83>
11+
pub fn u128_zero_fill() -> [u128; 4] {
12+
return [0; 4];
13+
}
14+
15+
pub fn i128_zero_fill() -> [i128; 4] {
16+
return [0; 4];
17+
}
18+
19+
#[spirv(fragment)]
20+
pub fn main() {}

0 commit comments

Comments
 (0)