authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-01-21 22:48:31+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-02-04 19:09:33+01:00
log1d548aa2aab472f14013e67e29c6d898a7b31998
treef95034497764e5488ed29ed651cb73dbd0e06ff7
parent76d5696434095e39d9aaae92c1533b2d016c1a31
signaturebadge-check Signed by SSH key SHA256:ZS52FNyUv2WUXvO4njmVaFVO46RHojFuOrxRc4LuKzg

spirv: air splat


2 files changed, 15 insertions(+), 1 deletions(-)

src/codegen/spirv.zig+15
...@@ -2195,6 +2195,7 @@ const DeclGen = struct {...@@ -2195,6 +2195,7 @@ const DeclGen = struct {
21952195
2196 .mul_add => try self.airMulAdd(inst),2196 .mul_add => try self.airMulAdd(inst),
21972197
2198 .splat => try self.airSplat(inst),
2198 .reduce, .reduce_optimized => try self.airReduce(inst),2199 .reduce, .reduce_optimized => try self.airReduce(inst),
2199 .shuffle => try self.airShuffle(inst),2200 .shuffle => try self.airShuffle(inst),
22002201
...@@ -2603,6 +2604,7 @@ const DeclGen = struct {...@@ -2603,6 +2604,7 @@ const DeclGen = struct {
2603 // Idk why spir-v doesn't have a dedicated abs() instruction in the base2604 // Idk why spir-v doesn't have a dedicated abs() instruction in the base
2604 // instruction set. For now we're just going to negate and check to avoid2605 // instruction set. For now we're just going to negate and check to avoid
2605 // importing the extinst.2606 // importing the extinst.
2607 // TODO: Make this a call to compiler rt / ext inst
2606 const neg_id = self.spv.allocId();2608 const neg_id = self.spv.allocId();
2607 const args = .{2609 const args = .{
2608 .id_result_type = self.typeId(operand_scalar_ty_ref),2610 .id_result_type = self.typeId(operand_scalar_ty_ref),
...@@ -2877,6 +2879,19 @@ const DeclGen = struct {...@@ -2877,6 +2879,19 @@ const DeclGen = struct {
2877 return try wip.finalize();2879 return try wip.finalize();
2878 }2880 }
28792881
2882 fn airSplat(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
2883 if (self.liveness.isUnused(inst)) return null;
2884 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2885 const operand_id = try self.resolve(ty_op.operand);
2886 const result_ty = self.typeOfIndex(inst);
2887 var wip = try self.elementWise(result_ty);
2888 defer wip.deinit();
2889 for (wip.results) |*result_id| {
2890 result_id.* = operand_id;
2891 }
2892 return try wip.finalize();
2893 }
2894
2880 fn airReduce(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {2895 fn airReduce(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
2881 if (self.liveness.isUnused(inst)) return null;2896 if (self.liveness.isUnused(inst)) return null;
2882 const mod = self.module;2897 const mod = self.module;
test/behavior/vector.zig-1
...@@ -326,7 +326,6 @@ test "vector @splat" {...@@ -326,7 +326,6 @@ test "vector @splat" {
326 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO326 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
327 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO327 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
328 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO328 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
329 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
330329
331 if (builtin.zig_backend == .stage2_llvm and330 if (builtin.zig_backend == .stage2_llvm and
332 builtin.os.tag == .macos)331 builtin.os.tag == .macos)