mirror of
https://github.com/ziglang/zig.git
synced 2026-01-01 19:13:16 +00:00
std/math.zig: resolve missed optimization in rotates
This commit is contained in:
parent
52c8ac1a84
commit
02a43f325b
@ -548,8 +548,8 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
|
||||
} else if (@typeInfo(T).Int.signedness == .signed) {
|
||||
@compileError("cannot rotate signed integer");
|
||||
} else {
|
||||
const ar = @mod(r, @typeInfo(T).Int.bits);
|
||||
return shr(T, x, ar) | shl(T, x, @typeInfo(T).Int.bits - ar);
|
||||
const ar = @intCast(Log2Int(T), @mod(r, @typeInfo(T).Int.bits));
|
||||
return x >> ar | x << (1 +% ~ar);
|
||||
}
|
||||
}
|
||||
|
||||
@ -576,8 +576,8 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
|
||||
} else if (@typeInfo(T).Int.signedness == .signed) {
|
||||
@compileError("cannot rotate signed integer");
|
||||
} else {
|
||||
const ar = @mod(r, @typeInfo(T).Int.bits);
|
||||
return shl(T, x, ar) | shr(T, x, @typeInfo(T).Int.bits - ar);
|
||||
const ar = @intCast(Log2Int(T), @mod(r, @typeInfo(T).Int.bits));
|
||||
return x << ar | x >> 1 +% ~ar;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user