const Accumulator = struct {
acc1: u32,
acc2: u32,
acc3: u32,
acc4: u32,
fn init(seed: u32) Accumulator {
return .{
.acc1 = seed +% prime_1 +% prime_2,
.acc2 = seed +% prime_2,
.acc3 = seed,
.acc4 = seed -% prime_1,
};
}
fn updateEmpty(self: *Accumulator, input: anytype, comptime unroll_count: usize) usize {
var i: usize = 0;
if (unroll_count > 0) {
const unrolled_bytes = unroll_count * 16;
while (i + unrolled_bytes <= input.len) : (i += unrolled_bytes) {
inline for (0..unroll_count) |j| {
self.processStripe(input[i + j * 16 ..][0..16]);
}
}
}
while (i + 16 <= input.len) : (i += 16) {
self.processStripe(input[i..][0..16]);
}
return i;
}
fn processStripe(self: *Accumulator, buf: *const [16]u8) void {
self.acc1 = round(self.acc1, mem.readInt(u32, buf[0..4], .little));
self.acc2 = round(self.acc2, mem.readInt(u32, buf[4..8], .little));
self.acc3 = round(self.acc3, mem.readInt(u32, buf[8..12], .little));
self.acc4 = round(self.acc4, mem.readInt(u32, buf[12..16], .little));
}
fn merge(self: Accumulator) u32 {
return rotl(u32, self.acc1, 1) +% rotl(u32, self.acc2, 7) +%
rotl(u32, self.acc3, 12) +% rotl(u32, self.acc4, 18);
}
}