fix: improve perf of instructions w/ rotr

This commit is contained in:
2022-03-16 22:28:24 -03:00
parent 1921218c7b
commit 39ab363afa
7 changed files with 33 additions and 13 deletions

View File

@@ -1,12 +1,21 @@
const std = @import("std");
const Log2Int = std.math.Log2Int;
pub fn sext(comptime bits: comptime_int, value: u32) u32 {
pub inline fn sext(comptime bits: comptime_int, value: u32) u32 {
comptime std.debug.assert(bits <= 32);
const amount = 32 - bits;
return @bitCast(u32, @bitCast(i32, value << amount) >> amount);
}
/// See https://godbolt.org/z/W3en9Eche
pub inline fn rotr(comptime T: type, value: T, r: anytype) T {
comptime std.debug.assert(@typeInfo(T).Int.signedness == .unsigned);
const ar = @truncate(Log2Int(T), r);
return value >> ar | value << @truncate(Log2Int(T), @typeInfo(T).Int.bits - @as(T, ar));
}
pub const FpsAverage = struct {
const Self = @This();