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 {...@@ -451,6 +451,8 @@ pub const DeclGen = struct {
451 .cmp_gte => try self.genBinOp(inst.castTag(.cmp_gte).?),451 .cmp_gte => try self.genBinOp(inst.castTag(.cmp_gte).?),
452 .cmp_lt => try self.genBinOp(inst.castTag(.cmp_lt).?),452 .cmp_lt => try self.genBinOp(inst.castTag(.cmp_lt).?),
453 .cmp_lte => try self.genBinOp(inst.castTag(.cmp_lte).?),453 .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).?),
454 .arg => self.genArg(),456 .arg => self.genArg(),
455 // TODO: Breakpoints won't be supported in SPIR-V, but the compiler seems to insert them457 // TODO: Breakpoints won't be supported in SPIR-V, but the compiler seems to insert them
456 // throughout the IR.458 // throughout the IR.
...@@ -468,7 +470,7 @@ pub const DeclGen = struct {...@@ -468,7 +470,7 @@ pub const DeclGen = struct {
468 const lhs_id = try self.resolve(inst.lhs);470 const lhs_id = try self.resolve(inst.lhs);
469 const rhs_id = try self.resolve(inst.rhs);471 const rhs_id = try self.resolve(inst.rhs);
470472
471 const binop_result_id = self.spv.allocResultId();473 const result_id = self.spv.allocResultId();
472 const result_type_id = try self.getOrGenType(inst.base.ty);474 const result_type_id = try self.getOrGenType(inst.base.ty);
473475
474 // TODO: Is the result the same as the argument types?476 // TODO: Is the result the same as the argument types?
...@@ -516,16 +518,19 @@ pub const DeclGen = struct {...@@ -516,16 +518,19 @@ pub const DeclGen = struct {
516 .cmp_gte => if (is_float) Opcode.OpFOrdGreaterThanEqual else if (is_signed) Opcode.OpSGreaterThanEqual else Opcode.OpUGreaterThanEqual,518 .cmp_gte => if (is_float) Opcode.OpFOrdGreaterThanEqual else if (is_signed) Opcode.OpSGreaterThanEqual else Opcode.OpUGreaterThanEqual,
517 .cmp_lt => if (is_float) Opcode.OpFOrdLessThan else if (is_signed) Opcode.OpSLessThan else Opcode.OpULessThan,519 .cmp_lt => if (is_float) Opcode.OpFOrdLessThan else if (is_signed) Opcode.OpSLessThan else Opcode.OpULessThan,
518 .cmp_lte => if (is_float) Opcode.OpFOrdLessThanEqual else if (is_signed) Opcode.OpSLessThanEqual else Opcode.OpULessThanEqual,520 .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,
519 else => unreachable,524 else => unreachable,
520 };525 };
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
524 // TODO: Trap on overflow? Probably going to be annoying.529 // TODO: Trap on overflow? Probably going to be annoying.
525 // TODO: Look into NoSignedWrap/NoUnsignedWrap extensions.530 // TODO: Look into NoSignedWrap/NoUnsignedWrap extensions.
526531
527 if (info.class != .strange_integer)532 if (info.class != .strange_integer)
528 return binop_result_id;533 return result_id;
529534
530 return self.fail(.{.node_offset = 0}, "TODO: SPIR-V backend: strange integer operation mask", .{});535 return self.fail(.{.node_offset = 0}, "TODO: SPIR-V backend: strange integer operation mask", .{});
531 }536 }