authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-18 16:28:13+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-10-18 16:28:13+02:00
logc3120d5089df155937a2ab78140cbe8c0b215e06
treefe882b14542253d978db92d765cb6d14a612ecfe
parente8f3c4c4b12f59ac6fb1c2045a0635ce8f3d0dac
parente5d5c1d423c73c94d6c3e9d26bd904eb3807b489
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #17577 from alichraghi/spirv-1

spirv: switch on bool

4 files changed, 5 insertions(+), 6 deletions(-)

src/codegen/spirv.zig+5-3
......@@ -4139,11 +4139,13 @@ const DeclGen = struct {
41394139 fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void {
41404140 const mod = self.module;
41414141 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
4142 const cond = try self.resolve(pl_op.operand);
41434142 const cond_ty = self.typeOf(pl_op.operand);
4143 const cond = try self.resolve(pl_op.operand);
4144 const cond_indirect = try self.convertToIndirect(cond_ty, cond);
41444145 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
41454146
41464147 const cond_words: u32 = switch (cond_ty.zigTypeTag(mod)) {
4148 .Bool => 1,
41474149 .Int => blk: {
41484150 const bits = cond_ty.intInfo(mod).bits;
41494151 const backing_bits = self.backingIntBits(bits) orelse {
......@@ -4187,7 +4189,7 @@ const DeclGen = struct {
41874189
41884190 // Emit the instruction before generating the blocks.
41894191 try self.func.body.emitRaw(self.spv.gpa, .OpSwitch, 2 + (cond_words + 1) * num_conditions);
4190 self.func.body.writeOperand(IdRef, cond);
4192 self.func.body.writeOperand(IdRef, cond_indirect);
41914193 self.func.body.writeOperand(IdRef, default);
41924194
41934195 // Emit each of the cases
......@@ -4208,7 +4210,7 @@ const DeclGen = struct {
42084210 return self.todo("switch on runtime value???", .{});
42094211 };
42104212 const int_val = switch (cond_ty.zigTypeTag(mod)) {
4211 .Int => if (cond_ty.isSignedInt(mod)) @as(u64, @bitCast(value.toSignedInt(mod))) else value.toUnsignedInt(mod),
4213 .Bool, .Int => if (cond_ty.isSignedInt(mod)) @as(u64, @bitCast(value.toSignedInt(mod))) else value.toUnsignedInt(mod),
42124214 .Enum => blk: {
42134215 // TODO: figure out of cond_ty is correct (something with enum literals)
42144216 break :blk (try value.intFromEnum(cond_ty, mod)).toUnsignedInt(mod); // TODO: composite integer constants
test/behavior/basic.zig-1
......@@ -715,7 +715,6 @@ test "result location is optional inside error union" {
715715 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
716716 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
717717 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
718 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
719718
720719 const x = maybe(true) catch unreachable;
721720 try expect(x.? == 42);
test/behavior/inline_switch.zig-1
......@@ -72,7 +72,6 @@ test "inline switch unions" {
7272test "inline else bool" {
7373 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
7474 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
75 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
7675
7776 var a = true;
7877 switch (a) {
test/behavior/switch.zig-1
......@@ -118,7 +118,6 @@ fn trueIfBoolFalseOtherwise(comptime T: type) bool {
118118
119119test "switching on booleans" {
120120 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
121 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
122121
123122 try testSwitchOnBools();
124123 try comptime testSwitchOnBools();