authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-01-21 16:05:39+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-02-04 19:09:31+01:00
log9f0227a326d84208e23e90c2a84ff95f734bd2ae
tree6f36c0a02705f45fe9dba6cc2827707d34d90c88
parent408c1172463429c1dcf675c41225100ebc750a78
signaturebadge-check Signed by SSH key SHA256:ZS52FNyUv2WUXvO4njmVaFVO46RHojFuOrxRc4LuKzg

spirv: vectorize int_cast, trunc


2 files changed, 27 insertions(+), 23 deletions(-)

src/codegen/spirv.zig+27-22
...@@ -3290,7 +3290,6 @@ const DeclGen = struct {...@@ -3290,7 +3290,6 @@ const DeclGen = struct {
3290 const operand_id = try self.resolve(ty_op.operand);3290 const operand_id = try self.resolve(ty_op.operand);
3291 const src_ty = self.typeOf(ty_op.operand);3291 const src_ty = self.typeOf(ty_op.operand);
3292 const dst_ty = self.typeOfIndex(inst);3292 const dst_ty = self.typeOfIndex(inst);
3293 const dst_ty_ref = try self.resolveType(dst_ty, .direct);
32943293
3295 const src_info = self.arithmeticTypeInfo(src_ty);3294 const src_info = self.arithmeticTypeInfo(src_ty);
3296 const dst_info = self.arithmeticTypeInfo(dst_ty);3295 const dst_info = self.arithmeticTypeInfo(dst_ty);
...@@ -3299,29 +3298,35 @@ const DeclGen = struct {...@@ -3299,29 +3298,35 @@ const DeclGen = struct {
3299 return operand_id;3298 return operand_id;
3300 }3299 }
33013300
3302 const result_id = self.spv.allocId();3301 var wip = try self.elementWise(dst_ty);
3303 switch (dst_info.signedness) {3302 defer wip.deinit();
3304 .signed => try self.func.body.emit(self.spv.gpa, .OpSConvert, .{3303 for (wip.results, 0..) |*result_id, i| {
3305 .id_result_type = self.typeId(dst_ty_ref),3304 const elem_id = try wip.elementAt(src_ty, operand_id, i);
3306 .id_result = result_id,3305 const value_id = self.spv.allocId();
3307 .signed_value = operand_id,3306 switch (dst_info.signedness) {
3308 }),3307 .signed => try self.func.body.emit(self.spv.gpa, .OpSConvert, .{
3309 .unsigned => try self.func.body.emit(self.spv.gpa, .OpUConvert, .{3308 .id_result_type = wip.scalar_ty_id,
3310 .id_result_type = self.typeId(dst_ty_ref),3309 .id_result = value_id,
3311 .id_result = result_id,3310 .signed_value = elem_id,
3312 .unsigned_value = operand_id,3311 }),
3313 }),3312 .unsigned => try self.func.body.emit(self.spv.gpa, .OpUConvert, .{
3314 }3313 .id_result_type = wip.scalar_ty_id,
3314 .id_result = value_id,
3315 .unsigned_value = elem_id,
3316 }),
3317 }
33153318
3316 // Make sure to normalize the result if shrinking.3319 // Make sure to normalize the result if shrinking.
3317 // Because strange ints are sign extended in their backing3320 // Because strange ints are sign extended in their backing
3318 // type, we don't need to normalize when growing the type. The3321 // type, we don't need to normalize when growing the type. The
3319 // representation is already the same.3322 // representation is already the same.
3320 if (dst_info.bits < src_info.bits) {3323 if (dst_info.bits < src_info.bits) {
3321 return try self.normalize(dst_ty_ref, result_id, dst_info);3324 result_id.* = try self.normalize(wip.scalar_ty_ref, value_id, dst_info);
3325 } else {
3326 result_id.* = value_id;
3327 }
3322 }3328 }
33233329 return try wip.finalize();
3324 return result_id;
3325 }3330 }
33263331
3327 fn intFromPtr(self: *DeclGen, operand_id: IdRef) !IdRef {3332 fn intFromPtr(self: *DeclGen, operand_id: IdRef) !IdRef {
test/behavior/truncate.zig-1
...@@ -69,7 +69,6 @@ test "truncate on vectors" {...@@ -69,7 +69,6 @@ test "truncate on vectors" {
69 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;69 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
70 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;70 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
71 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO71 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
72 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
7372
74 const S = struct {73 const S = struct {
75 fn doTheTest() !void {74 fn doTheTest() !void {