Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"03-15-14 - Bit IO of Elias Gamma"

5 Comments -

1 – 5 of 5
Blogger Fabian 'ryg' Giesen said...

http://fgiesen.wordpress.com/2011/01/19/a-small-note-on-the-elias-gamma-cod/ :)

While working on Bink 2 which uses LSB-first bottom-justified bit packing, I realized unary is easy there too: calculate "x & -x" (clears all but the lowest set bit in x) and then you can do "32 - clz32" (see also "http://fgiesen.wordpress.com/2013/10/18/bit-scanning-equivalencies/"). A bit more work but still short and branch-free. You do lose the super-nice Gamma decoder though.

March 15, 2014 at 9:54 PM

Blogger Fabian 'ryg' Giesen said...

Eh, 31 - clz32 and 63 - clz64 respectively. You get the idea.

March 15, 2014 at 9:55 PM

Blogger cbloom said...

Ah yes. At least I didn't cover it before on my own blog, which I've been known to do.

One nice thing about 64-bit BITIO and the grab-8 method of refilling is that you always have >= 57 bits available, which means you don't need to even check for the overflow case for typical value ranges.

March 16, 2014 at 11:08 AM

Blogger Fabian 'ryg' Giesen said...

Yup. With 64-bit BitIO I'm always torn between byte-based refills (sooo many spare bits to work with, so many refill checks that can be skipped!) and 32-bit-at-a-time refills (nice predictable rare branch, always do 32-bit aligned accesses).

With old school-ish RISCs (especially if they don't have good branch predictors), I think 32-bit aligned is superior; on x86/ARM with their fast support for unaligned reads it's a bit more complicated.

GCN GPUs have "alignbit" and "alignbyte":

v_alignbit_b32 dest, s0, s1, s2

dest = (s0 | (s1 << 32)) >> (s2 & 31)

v_alignbyte_b32 dest, s0, s1, s2

dest = (s0 | (s1 << 32)) >> (8 * (s2 & 3))

I'd sure like to have those on general-purpose CPUs...

March 16, 2014 at 5:19 PM

Blogger cbloom said...

Added Exp Golomb to the post.

March 16, 2014 at 6:24 PM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.