mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
x86_64: rewrite scalar @shlWithOverflow
This commit is contained in:
parent
8e72a25285
commit
932298679f
2 changed files with 3415 additions and 23 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue