Hacker News new | ask | show | jobs
by pjsg 260 days ago
I suspect that this unaligned read apporach doesn't work for a bit length of 59, 61, 62 and 63.

In the case of 63, reading out value at offset 1, requires two reads as it need 1 bit from the first byte, then 56 bits from the next 7 bytes and finally 6 bits from the 9th byte. Nine bytes cannot be loaded in a single u64 load.

1 comments

That's a good catch!! Thank you, you are right. I (incorrectly) assumed that a single u64 could capture the entire bit_width-value read starting from byte_pos. However, as you said, this assumption breaks for some large bit widths.

I already patched it, thanks again.