aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2023-10-18 16:28:13 +0200
committerGitHub <noreply@github.com>2023-10-18 16:28:13 +0200
commitc3120d5089df155937a2ab78140cbe8c0b215e06 (patch)
treefe882b14542253d978db92d765cb6d14a612ecfe /src/codegen/spirv.zig
parente8f3c4c4b12f59ac6fb1c2045a0635ce8f3d0dac (diff)
parente5d5c1d423c73c94d6c3e9d26bd904eb3807b489 (diff)
downloadzig-c3120d5089df155937a2ab78140cbe8c0b215e06.tar.gz
zig-c3120d5089df155937a2ab78140cbe8c0b215e06.zip
Merge pull request #17577 from alichraghi/spirv-1
spirv: switch on bool
Diffstat (limited to 'src/codegen/spirv.zig')
-rw-r--r--src/codegen/spirv.zig8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig
index 7ee281c466..ded73d6afd 100644
--- a/src/codegen/spirv.zig
+++ b/src/codegen/spirv.zig
@@ -4139,11 +4139,13 @@ const DeclGen = struct {
fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void {
const mod = self.module;
const pl_op = self.air.instructions.items(.data)[inst].pl_op;
- const cond = try self.resolve(pl_op.operand);
const cond_ty = self.typeOf(pl_op.operand);
+ const cond = try self.resolve(pl_op.operand);
+ const cond_indirect = try self.convertToIndirect(cond_ty, cond);
const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
const cond_words: u32 = switch (cond_ty.zigTypeTag(mod)) {
+ .Bool => 1,
.Int => blk: {
const bits = cond_ty.intInfo(mod).bits;
const backing_bits = self.backingIntBits(bits) orelse {
@@ -4187,7 +4189,7 @@ const DeclGen = struct {
// Emit the instruction before generating the blocks.
try self.func.body.emitRaw(self.spv.gpa, .OpSwitch, 2 + (cond_words + 1) * num_conditions);
- self.func.body.writeOperand(IdRef, cond);
+ self.func.body.writeOperand(IdRef, cond_indirect);
self.func.body.writeOperand(IdRef, default);
// Emit each of the cases
@@ -4208,7 +4210,7 @@ const DeclGen = struct {
return self.todo("switch on runtime value???", .{});
};
const int_val = switch (cond_ty.zigTypeTag(mod)) {
- .Int => if (cond_ty.isSignedInt(mod)) @as(u64, @bitCast(value.toSignedInt(mod))) else value.toUnsignedInt(mod),
+ .Bool, .Int => if (cond_ty.isSignedInt(mod)) @as(u64, @bitCast(value.toSignedInt(mod))) else value.toUnsignedInt(mod),
.Enum => blk: {
// TODO: figure out of cond_ty is correct (something with enum literals)
break :blk (try value.intFromEnum(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants