Skip to content

Commit 4338bc6

Browse files
committed
add memset const and dynamic support for f16
1 parent c41db00 commit 4338bc6

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
407407
)),
408408
},
409409
SpirvType::Float(width) => match width {
410+
16 => {
411+
let ty = SpirvType::Float(16).def(self.span(), self);
412+
self.def_constant(ty, SpirvConst::Scalar(memset_fill_u16(fill_byte) as u128))
413+
.def(self)
414+
}
410415
32 => self
411416
.constant_f32(self.span(), f32::from_bits(memset_fill_u32(fill_byte)))
412417
.def(self),
@@ -461,6 +466,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
461466
)),
462467
},
463468
SpirvType::Float(width) => match width {
469+
16 => memset_dynamic_scalar(self, fill_var, 2, true),
464470
32 => memset_dynamic_scalar(self, fill_var, 4, true),
465471
64 => memset_dynamic_scalar(self, fill_var, 8, true),
466472
_ => self.fatal(format!("memset on float width {width} not implemented yet")),
@@ -2425,6 +2431,22 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
24252431
};
24262432
let dest_pointee_size = self.lookup_type(dest_pointee).sizeof(self);
24272433

2434+
// Casting to a pointer-to-ZST (e.g. `*f16 -> *()`) is a no-op from a
2435+
// memory standpoint: ZSTs have no fields and can never be loaded or
2436+
// stored. The only real use is address-level queries (null / alignment
2437+
// checks inside `ub_checks::assert_unsafe_precondition!`) which cannot
2438+
// be expressed in SPIR-V logical addressing anyway. Emit the bitcast
2439+
// directly without a `LogicalPtrCast` zombie so that UB-check
2440+
// boilerplate in the standard library doesn't produce spurious errors.
2441+
if dest_pointee_size == Some(Size::ZERO) {
2442+
let original_ptr = ptr.def(self);
2443+
return self
2444+
.emit()
2445+
.bitcast(dest_ty, None, original_ptr)
2446+
.unwrap()
2447+
.with_type(dest_ty);
2448+
}
2449+
24282450
if let Some((indices, _)) = self.recover_access_chain_from_offset(
24292451
ptr_pointee,
24302452
Size::ZERO,

0 commit comments

Comments
 (0)