Reversing Bits in C
corner.squareup.com
Reversing Bits in C
1–10 of 91 posts
Re: Reversing Bits in C
#2Re: Reversing Bits in C
#3http://dalkescientific.com/writings/diary/archive/2008/07/03...
http://dalkescientific.com/writings/diary/archive/2008/07/05...
http://dalkescientific.com/writings/diary/archive/2011/11/02...
The Stanford Bit Hacks page linked in the original article is also very interesting reading for folks into this sort of stuff.
Re: Reversing Bits in C
#4http://stackoverflow.com/a/9040426
http://www.intel.com/content/www/us/en/processors/architectu... (it's on page 1256 of 3251).
Re: Reversing Bits in C
#5[1] : http://stackoverflow.com/questions/14547087/extracting-bits-...
Re: Reversing Bits in C
#6reverse: a! 16 push . 2 dup . . begin +x 2* 2* unext +x 2* a . + nip ;
In Intel x86/64, the fastest way I know of is to use SIMD instructions, and break the 64-bit word into 16 nibbles (4-bit pieces), and use PSHUFB to perform a parallel lookup against another 128-bit xmm register. Then you aggregate the nibbles in reverse order, using inclusive or and variants of the shuffle instruction.
Re: Reversing Bits in C
#7Interestingly, while x86-64 does not seem to have a single opcode for reversing bits in a byte, it has a function to arbitrarily shuffle around the 16 bytes in a 128bit SSE register [PSHUFB]. It just blows my mind how much data those SIMD instructions process or move around in relatively few clock-cycles. http://stackoverflow.com/a/9040426 http://www.intel.com/content/www/us/en/processors/architectu... (it's on page…
Re: Reversing Bits in C
#8Great analysis, although I'm curious how the idea that doing a bunch of 64 bit ops in order to accomplish byte arithmetic came about to begin with - was the function in question not written by a firmware guy?
Re: Reversing Bits in C
#9Great analysis, although I'm curious how the idea that doing a bunch of 64 bit ops in order to accomplish byte arithmetic came about to begin with - was the function in question not written by a firmware guy?
Re: Reversing Bits in C
#10Great analysis, although I'm curious how the idea that doing a bunch of 64 bit ops in order to accomplish byte arithmetic came about to begin with - was the function in question not written by a firmware guy?
I think this one goes back to PDP days and wasn't necessarily written to be the fastest possible implementation. The PDP could do 36*36 multiply into 72 bits. Not sure how the modulo instruction performed but there was a DIV instruction.