authorgravatar for rekai@musuka.devRekai Musuka <rekai@musuka.dev> 2022-04-14 07:42:49-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-15 11:51:50-04:00
log02a43f325bfbccb73fb773f15b162d531c3c3ada
treedc0a17be1d2ed271ed62505e18e7b801265a9693
parent52c8ac1a847f893bc54cab5621738c0aa16f7c9d

std/math.zig: resolve missed optimization in rotates


1 files changed, 4 insertions(+), 4 deletions(-)

lib/std/math.zig+4-4
...@@ -548,8 +548,8 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {...@@ -548,8 +548,8 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
548 } else if (@typeInfo(T).Int.signedness == .signed) {548 } else if (@typeInfo(T).Int.signedness == .signed) {
549 @compileError("cannot rotate signed integer");549 @compileError("cannot rotate signed integer");
550 } else {550 } else {
551 const ar = @mod(r, @typeInfo(T).Int.bits);551 const ar = @intCast(Log2Int(T), @mod(r, @typeInfo(T).Int.bits));
552 return shr(T, x, ar) | shl(T, x, @typeInfo(T).Int.bits - ar);552 return x >> ar | x << (1 +% ~ar);
553 }553 }
554}554}
555555
...@@ -576,8 +576,8 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {...@@ -576,8 +576,8 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
576 } else if (@typeInfo(T).Int.signedness == .signed) {576 } else if (@typeInfo(T).Int.signedness == .signed) {
577 @compileError("cannot rotate signed integer");577 @compileError("cannot rotate signed integer");
578 } else {578 } else {
579 const ar = @mod(r, @typeInfo(T).Int.bits);579 const ar = @intCast(Log2Int(T), @mod(r, @typeInfo(T).Int.bits));
580 return shl(T, x, ar) | shr(T, x, @typeInfo(T).Int.bits - ar);580 return x << ar | x >> 1 +% ~ar;
581 }581 }
582}582}
583583