| ... | @@ -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); | | |
| 3294 | | 3293 | |
| 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 | } |
| 3301 | | 3300 | |
| 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 | } |
| 3315 | | 3318 | |
| 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 backing | 3320 | // Because strange ints are sign extended in their backing |
| 3318 | // type, we don't need to normalize when growing the type. The | 3321 | // 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 | } |
| 3323 | | 3329 | return try wip.finalize(); |
| 3324 | return result_id; | | |
| 3325 | } | 3330 | } |
| 3326 | | 3331 | |
| 3327 | fn intFromPtr(self: *DeclGen, operand_id: IdRef) !IdRef { | 3332 | fn intFromPtr(self: *DeclGen, operand_id: IdRef) !IdRef { |