authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-05-16 14:52:11+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-05-16 14:52:11+02:00
log489b3ef7d47c877aa7e761ddf00763bfe1dc03a7
treee5544bbe6c27ca68832e722612c8565bb7909da0
parent585122b1ac51f9ac23bae537dfc40bbae1d7cb3c

SPIR-V: bool binary operations


1 files changed, 8 insertions(+), 3 deletions(-)

src/codegen/spirv.zig+8-3
......@@ -451,6 +451,8 @@ pub const DeclGen = struct {
451451 .cmp_gte => try self.genBinOp(inst.castTag(.cmp_gte).?),
452452 .cmp_lt => try self.genBinOp(inst.castTag(.cmp_lt).?),
453453 .cmp_lte => try self.genBinOp(inst.castTag(.cmp_lte).?),
454 .bool_and => try self.genBinOp(inst.castTag(.bool_and).?),
455 .bool_or => try self.genBinOp(inst.castTag(.bool_or).?),
454456 .arg => self.genArg(),
455457 // TODO: Breakpoints won't be supported in SPIR-V, but the compiler seems to insert them
456458 // throughout the IR.
......@@ -468,7 +470,7 @@ pub const DeclGen = struct {
468470 const lhs_id = try self.resolve(inst.lhs);
469471 const rhs_id = try self.resolve(inst.rhs);
470472
471 const binop_result_id = self.spv.allocResultId();
473 const result_id = self.spv.allocResultId();
472474 const result_type_id = try self.getOrGenType(inst.base.ty);
473475
474476 // TODO: Is the result the same as the argument types?
......@@ -516,16 +518,19 @@ pub const DeclGen = struct {
516518 .cmp_gte => if (is_float) Opcode.OpFOrdGreaterThanEqual else if (is_signed) Opcode.OpSGreaterThanEqual else Opcode.OpUGreaterThanEqual,
517519 .cmp_lt => if (is_float) Opcode.OpFOrdLessThan else if (is_signed) Opcode.OpSLessThan else Opcode.OpULessThan,
518520 .cmp_lte => if (is_float) Opcode.OpFOrdLessThanEqual else if (is_signed) Opcode.OpSLessThanEqual else Opcode.OpULessThanEqual,
521 // Bool -> bool operations.
522 .bool_and => Opcode.OpLogicalAnd,
523 .bool_or => Opcode.OpLogicalOr,
519524 else => unreachable,
520525 };
521526
522 try writeInstruction(&self.spv.fn_decls, opcode, &[_]u32{ result_type_id, binop_result_id, lhs_id, rhs_id });
527 try writeInstruction(&self.spv.fn_decls, opcode, &[_]u32{ result_type_id, result_id, lhs_id, rhs_id });
523528
524529 // TODO: Trap on overflow? Probably going to be annoying.
525530 // TODO: Look into NoSignedWrap/NoUnsignedWrap extensions.
526531
527532 if (info.class != .strange_integer)
528 return binop_result_id;
533 return result_id;
529534
530535 return self.fail(.{.node_offset = 0}, "TODO: SPIR-V backend: strange integer operation mask", .{});
531536 }