fn readFixed(bc: *BitcodeReader, comptime T: type, bits: u7) !T bc: *BitcodeReaderT: typebits: u7399
400
401
402
403
404
405
406
407
408
409
410
411
412
413fn readFixed(bc: *BitcodeReader, comptime T: type, bits: u7) !T {
var result: T = 0;
var shift: std.math.Log2IntCeil(T) = 0;
var remaining = bits;
while (remaining > 0) {
if (bc.bit_offset == 0) bc.bit_buffer = try bc.read32Bits();
const chunk_len = @min(@as(u6, 32) - bc.bit_offset, remaining);
const chunk_mask = @as(u32, std.math.maxInt(u32)) >> @intCast(32 - chunk_len);
result |= @as(T, @intCast(bc.bit_buffer >> bc.bit_offset & chunk_mask)) << @intCast(shift);
shift += @intCast(chunk_len);
remaining -= chunk_len;
bc.bit_offset = @truncate(bc.bit_offset + chunk_len);
}
return result;
}