(&self, ty: Word, val: u64)
| 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); |
no test coverage detected