x86_64: rewrite scalar @shlWithOverflow

This commit is contained in:
Jacob Young 2025-04-17 21:34:49 -04:00
parent 8e72a25285
commit 932298679f
2 changed files with 3415 additions and 23 deletions

File diff suppressed because it is too large Load diff

View file

@ -5477,6 +5477,16 @@ test mulWithOverflow {
try test_mul_with_overflow.testInts();
}
inline fn shlWithOverflow(comptime Type: type, lhs: Type, rhs: Type) struct { Type, u1 } {
const bit_cast_rhs: @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(Type) } }) = @bitCast(rhs);
const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
return @shlWithOverflow(lhs, if (comptime cast(Log2Int(Type), @bitSizeOf(Type))) |bits| truncate_rhs % bits else truncate_rhs);
}
test shlWithOverflow {
const test_shl_with_overflow = binary(shlWithOverflow, .{});
try test_shl_with_overflow.testInts();
}
inline fn equal(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs == rhs) {
return lhs == rhs;
}