authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2022-11-27 15:04:16+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-09 01:51:50+02:00
log205d928b24d46fd1fd5798c5d66e66ef25aa013f
tree238905b6b43ce9bd909f6fc5b9cb83c0b5339858
parentea97966c9e76727e7f7e4c0a2c4578f64b608001
signaturelock-open Commit is signed but in an unrecognized format.

spirv: left shift

Implements the AIR left_shift operation for the SPIR-V backend.

1 files changed, 27 insertions(+), 0 deletions(-)

src/codegen/spirv.zig+27
......@@ -850,6 +850,8 @@ pub const DeclGen = struct {
850850 .bool_and => try self.airBinOpSimple(inst, .OpLogicalAnd),
851851 .bool_or => try self.airBinOpSimple(inst, .OpLogicalOr),
852852
853 .shl => try self.airShift(inst, .OpShiftLeftLogical),
854
853855 .bitcast => try self.airBitcast(inst),
854856 .intcast => try self.airIntcast(inst),
855857 .not => try self.airNot(inst),
......@@ -928,6 +930,31 @@ pub const DeclGen = struct {
928930 return result_id.toRef();
929931 }
930932
933 fn airShift(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef {
934 if (self.liveness.isUnused(inst)) return null;
935 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
936 const lhs_id = try self.resolve(bin_op.lhs);
937 const rhs_id = try self.resolve(bin_op.rhs);
938 const result_type_id = try self.resolveTypeId(self.air.typeOfIndex(inst));
939
940 // the shift and the base must be the same type in SPIR-V, but in Zig the shift is a smaller int.
941 const shift_id = self.spv.allocId();
942 try self.func.body.emit(self.spv.gpa, .OpUConvert, .{
943 .id_result_type = result_type_id,
944 .id_result = shift_id,
945 .unsigned_value = rhs_id,
946 });
947
948 const result_id = self.spv.allocId();
949 try self.func.body.emit(self.spv.gpa, opcode, .{
950 .id_result_type = result_type_id,
951 .id_result = result_id,
952 .base = lhs_id,
953 .shift = shift_id.toRef(),
954 });
955 return result_id.toRef();
956 }
957
931958 fn maskStrangeInt(self: *DeclGen, ty_id: IdResultType, int_id: IdRef, bits: u16) !IdRef {
932959 const backing_bits = self.backingIntBits(bits).?;
933960 const mask_value = if (bits == 64) 0xFFFF_FFFF_FFFF_FFFF else (@as(u64, 1) << @intCast(u6, bits)) - 1;