Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Quick bit extraction question

Author: Scott Gasch

Date: 18:54:02 07/20/04

Go up one level in this thread


A lot of people have suggested & and >> etc... bitwise operations.

You might also look at using bitfields in structs and letting the compiler
figure out the bit twiddling.  It involves some trust in the compiler which is
hard for many people... but it should produce the same code.  I think it ends up
more readable and gives the compiler the chance to be smart (do things better if
it knows how).  That said, I would also take a hard look at the code the below
generates and go to macros with >> and & in them if I was dissatisfied.

typedef struct _MOVE
{
    UCHAR uFrom : 7;
    UCHAR uTo : 7;
    ...
} MOVE;

---

MOVE mv;

mv.uFrom = D2;
mv.uTo = D4;

etc.

I don't know this for sure but I also greatly suspect that you'll get better,
faster code if you devote 8 bits to the from/to parts.  That aligns them on CHAR
boundaries...

Good luck,
Scott



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.