Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Compute quickly the byte lengths without look-ups #12
Comments
|
The length is 1 + the rightmost index in the decoding shuffle, which is within the last four entries. |
added a commit
that referenced
this issue
Nov 7, 2017
|
|
It is definitely susceptible to various bithacks. I used the permutation table since it's available, but the 2-bit fields could also be summed in a few instructions. mod15 compiles to a multiply and some shifts and subtracts, so it may be decomposable into fewer instructions in this context. Generally I would spread the bitfields out and use a multiply to sum them into something like the most significant byte; that's what I do in the compressor when I have the 2-bit fields already spread out. Your method of multiplying by 0x401 and masking looks promising -- they're far enough apart to sum into a nybble at that point. Multiplying by (1<<28)|(1<<24)|(1<<16)|(1<<12) should drop them on top of each other in the high nybble, if I've got those shifts right. |
|
I ran some numbers on my blog: Bit hacking versus memoization: a Stream VByte example. |
lemire commentedNov 7, 2017
Some look-ups could be efficiently replaced by fast instructions such as a
pdepfollowed by a multiplication and a shift. It is unlikely to be generally faster than a look-up, but it might be worth exploring.