chore: change implementation of rotr
This commit is contained in:
parent
677eecad41
commit
ed896d976d
|
@ -9,11 +9,12 @@ pub inline fn sext(comptime bits: comptime_int, value: u32) u32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See https://godbolt.org/z/W3en9Eche
|
/// See https://godbolt.org/z/W3en9Eche
|
||||||
pub inline fn rotr(comptime T: type, value: T, r: anytype) T {
|
pub inline fn rotr(comptime T: type, x: T, r: anytype) T {
|
||||||
comptime std.debug.assert(@typeInfo(T).Int.signedness == .unsigned);
|
if (@typeInfo(T).Int.signedness == .signed)
|
||||||
const ar = @truncate(Log2Int(T), r);
|
@compileError("cannot rotate signed integer");
|
||||||
|
|
||||||
return value >> ar | value << @truncate(Log2Int(T), @typeInfo(T).Int.bits - @as(T, ar));
|
const ar = @intCast(Log2Int(T), @mod(r, @typeInfo(T).Int.bits));
|
||||||
|
return x >> ar | x << (1 +% ~ar);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const FpsAverage = struct {
|
pub const FpsAverage = struct {
|
||||||
|
|
Loading…
Reference in New Issue