MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / constant_int

Method constant_int

crates/rustc_codegen_spirv/src/codegen_cx/constant.rs:49–81  ·  view source on GitHub ↗
(&self, ty: Word, val: u64)

Source from the content-addressed store, hash-verified

47 }
48
49 pub fn constant_int(&self, ty: Word, val: u64) -> SpirvValue {
50 match self.lookup_type(ty) {
51 SpirvType::Integer(bits @ 8..=32, signed) => {
52 let size = Size::from_bits(bits);
53 let val = val as u128;
54 self.def_constant(
55 ty,
56 SpirvConst::U32(if signed {
57 size.sign_extend(val)
58 } else {
59 size.truncate(val)
60 } as u32),
61 )
62 }
63 SpirvType::Integer(64, _) => self.def_constant(ty, SpirvConst::U64(val)),
64 SpirvType::Bool => match val {
65 0 | 1 => self.def_constant(ty, SpirvConst::Bool(val != 0)),
66 _ => self
67 .tcx
68 .sess
69 .fatal(format!("Invalid constant value for bool: {val}")),
70 },
71 SpirvType::Integer(128, _) => {
72 let result = self.undef(ty);
73 self.zombie_no_span(result.def_cx(self), "u128 constant");
74 result
75 }
76 other => self.tcx.sess.fatal(format!(
77 "constant_int invalid on type {}",
78 other.debug(ty, self)
79 )),
80 }
81 }
82
83 pub fn constant_f32(&self, span: Span, val: f32) -> SpirvValue {
84 let ty = SpirvType::Float(32).def(span, self);

Callers 9

const_intMethod · 0.80
const_uintMethod · 0.80
const_uint_bigMethod · 0.80
const_usizeMethod · 0.80
scalar_to_backendMethod · 0.80
gep_helpMethod · 0.80
rotateMethod · 0.80
memset_dynamic_sizeMethod · 0.80
intcastMethod · 0.80

Calls 6

lookup_typeMethod · 0.80
def_constantMethod · 0.80
fatalMethod · 0.80
undefMethod · 0.80
zombie_no_spanMethod · 0.80
def_cxMethod · 0.80

Tested by

no test coverage detected