| ... | ... | @@ -230,6 +230,7 @@ pub const DeclGen = struct { |
| 230 | 230 | /// Generate a constant representing `val`. |
| 231 | 231 | /// TODO: Deduplication? |
| 232 | 232 | fn genConstant(self: *DeclGen, ty: Type, val: Value) Error!u32 { |
| 233 | const target = self.module.getTarget(); |
| 233 | 234 | const code = &self.spv.types_globals_constants; |
| 234 | 235 | const result_id = self.spv.allocResultId(); |
| 235 | 236 | const result_type_id = try self.getOrGenType(ty); |
| ... | ... | @@ -250,11 +251,11 @@ pub const DeclGen = struct { |
| 250 | 251 | |
| 251 | 252 | // f16 and f32 require one word of storage. f64 requires 2, low-order first. |
| 252 | 253 | |
| 253 | | switch (val.tag()) { |
| 254 | | .float_16 => try writeInstruction(code, .OpConstant, &[_]u32{ result_type_id, result_id, @bitCast(u16, val.castTag(.float_16).?.data) }), |
| 255 | | .float_32 => try writeInstruction(code, .OpConstant, &[_]u32{ result_type_id, result_id, @bitCast(u32, val.castTag(.float_32).?.data) }), |
| 256 | | .float_64 => { |
| 257 | | const float_bits = @bitCast(u64, val.castTag(.float_64).?.data); |
| 254 | switch (ty.floatBits(target)) { |
| 255 | 16 => try writeInstruction(code, .OpConstant, &[_]u32{ result_type_id, result_id, @bitCast(u16, val.toFloat(f16)) }), |
| 256 | 32 => try writeInstruction(code, .OpConstant, &[_]u32{ result_type_id, result_id, @bitCast(u32, val.toFloat(f32)) }), |
| 257 | 64 => { |
| 258 | const float_bits = @bitCast(u64, val.toFloat(f64)); |
| 258 | 259 | try writeInstruction(code, .OpConstant, &[_]u32{ |
| 259 | 260 | result_type_id, |
| 260 | 261 | result_id, |
| ... | ... | @@ -262,9 +263,9 @@ pub const DeclGen = struct { |
| 262 | 263 | @truncate(u32, float_bits >> 32), |
| 263 | 264 | }); |
| 264 | 265 | }, |
| 265 | | .float_128 => unreachable, // Filtered out in the call to getOrGenType. |
| 266 | | // TODO: What tags do we need to handle here anyway? |
| 267 | | else => return self.fail(.{ .node_offset = 0 }, "TODO: SPIR-V backend: float constant generation of value {s}\n", .{val.tag()}), |
| 266 | 128 => unreachable, // Filtered out in the call to getOrGenType. |
| 267 | // TODO: Insert case for long double when the layout for that is determined. |
| 268 | else => unreachable, |
| 268 | 269 | } |
| 269 | 270 | }, |
| 270 | 271 | else => return self.fail(.{ .node_offset = 0 }, "TODO: SPIR-V backend: constant generation of type {s}\n", .{ty.zigTypeTag()}), |