Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Mirroring a 32bit bitboard

Author: Gareth McCaughan

Date: 16:08:51 04/09/02

Go up one level in this thread


On April 09, 2002 at 18:22:10, Dann Corbit wrote:

>On April 09, 2002 at 17:32:15, Alvaro Jose Povoa Cardoso wrote:
>
>>Does anyone kow how to do a fast 32bit bitboard mirroring?
...
> 1. Swap 2 byte unsigned ints (unsavory union hack) {non-portable, allowed to
> cause nasal demons to fly out of your nose but works most of the time anyway}
> 2. Swap unsigned chars within those ints (same)
> 3. Swap bits within the bytes by table lookup of 256 entries.

I think using unsavory union hacks for steps 1-2 is a really bad idea.
Not just because it's unportable, liable to make demons fly out of your
nose, etc, but also because I suspect it will encourage the compiler
to put the data in memory rather than working with registers. (Maybe
all compilers these days are good at putting small structures into
registers, though?) And, finally, because it's just as easy to do it
safely and directly, and the code is easier to understand.

unsigned long reverse(unsigned long x) {
  return revbyte[x>>24] | (revbyte[(x>>16)&255]<<8)
       | (revbyte[(x>>8)&255]<<16) | (revbyte[x&255]<<24);
}

Building the |revbyte| array is left as an exercise for the
reader.

--
g



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.