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 {
32903290 const operand_id = try self.resolve(ty_op.operand);
32913291 const src_ty = self.typeOf(ty_op.operand);
32923292 const dst_ty = self.typeOfIndex(inst);
3293 const dst_ty_ref = try self.resolveType(dst_ty, .direct);
32943293
32953294 const src_info = self.arithmeticTypeInfo(src_ty);
32963295 const dst_info = self.arithmeticTypeInfo(dst_ty);
......@@ -3299,29 +3298,35 @@ const DeclGen = struct {
32993298 return operand_id;
33003299 }
33013300
3302 const result_id = self.spv.allocId();
3303 switch (dst_info.signedness) {
3304 .signed => try self.func.body.emit(self.spv.gpa, .OpSConvert, .{
3305 .id_result_type = self.typeId(dst_ty_ref),
3306 .id_result = result_id,
3307 .signed_value = operand_id,
3308 }),
3309 .unsigned => try self.func.body.emit(self.spv.gpa, .OpUConvert, .{
3310 .id_result_type = self.typeId(dst_ty_ref),
3311 .id_result = result_id,
3312 .unsigned_value = operand_id,
3313 }),
3314 }
3301 var wip = try self.elementWise(dst_ty);
3302 defer wip.deinit();
3303 for (wip.results, 0..) |*result_id, i| {
3304 const elem_id = try wip.elementAt(src_ty, operand_id, i);
3305 const value_id = self.spv.allocId();
3306 switch (dst_info.signedness) {
3307 .signed => try self.func.body.emit(self.spv.gpa, .OpSConvert, .{
3308 .id_result_type = wip.scalar_ty_id,
3309 .id_result = value_id,
3310 .signed_value = elem_id,
3311 }),
3312 .unsigned => try self.func.body.emit(self.spv.gpa, .OpUConvert, .{
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.
3317 // Because strange ints are sign extended in their backing
3318 // type, we don't need to normalize when growing the type. The
3319 // representation is already the same.
3320 if (dst_info.bits < src_info.bits) {
3321 return try self.normalize(dst_ty_ref, result_id, dst_info);
3319 // Make sure to normalize the result if shrinking.
3320 // Because strange ints are sign extended in their backing
3321 // type, we don't need to normalize when growing the type. The
3322 // representation is already the same.
3323 if (dst_info.bits < src_info.bits) {
3324 result_id.* = try self.normalize(wip.scalar_ty_ref, value_id, dst_info);
3325 } else {
3326 result_id.* = value_id;
3327 }
33223328 }
3323
3324 return result_id;
3329 return try wip.finalize();
33253330 }
33263331
33273332 fn intFromPtr(self: *DeclGen, operand_id: IdRef) !IdRef {
test/behavior/truncate.zig-1
......@@ -69,7 +69,6 @@ test "truncate on vectors" {
6969 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
7070 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
7171 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
72 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
7372
7473 const S = struct {
7574 fn doTheTest() !void {