TalkChess.com
Hosted by Your Move Chess & Games

Author Message
Gerd Isenberg

Joined: 08 Mar 2006
Posts: 1786
Location: Hattingen, Germany

Post subject: Two small in-register-lookups    Posted: Mon Apr 23, 2007 10:28 pm

Color of square - assumes 32-bit shift by mod 32.
Is that portable for 32-bit ints?
(otherwise sq&31 or sq&15 is necessary)

 Code: unsigned int colorOfSquare (unsigned int sq) {    return  (0xAA55AA55 >> sq) & 1; }

Center-Distance in the 0..3 range as a folded [32]-element lookup of two bits:

 Code: 3 3 3 3 3 3 3 3  3 2 2 2 2 2 2 3  3 2 1 1 1 1 2 3  3 2 1 0 0 1 2 3  3 2 1 0 0 1 2 3  3 2 1 1 1 1 2 3  3 2 2 2 2 2 2 3  3 3 3 3 3 3 3 3

 Code: unsigned int centerDistance(unsigned int a) {     const u64 _13 = 0xffffeaabe55be41b;     a ^= (a - 32) >> 27;     return  (_13  >> 2*a) & 3; }

or 32-bit friendly:
 Code: unsigned int centerDistance(unsigned int a) {     a ^=  (a  -  32)  >> 27;     return ((-8274523 >> a) & 1)          | ((  -30842 >> a) & 2); }

Cheers,
Gerd
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
Subject Author Date/Time
Gerd Isenberg Mon Apr 23, 2007 10:28 pm
J. Wesley Cleveland Tue Apr 24, 2007 9:08 am
H.G.Muller Tue Apr 24, 2007 9:51 am
Gerd Isenberg Tue Apr 24, 2007 11:00 am
Gerd Isenberg Tue Apr 24, 2007 10:58 am
H.G.Muller Tue Apr 24, 2007 12:37 pm
Gerd Isenberg Tue Apr 24, 2007 6:36 pm
Gerd Isenberg Tue Apr 24, 2007 8:11 pm
H.G.Muller Tue Apr 24, 2007 9:48 pm
Gerd Isenberg Tue Apr 24, 2007 9:57 pm
Tord Romstad Wed Apr 25, 2007 7:40 am
H.G.Muller Wed Apr 25, 2007 9:49 am
Tord Romstad Wed Apr 25, 2007 10:53 am
H.G.Muller Wed Apr 25, 2007 12:01 pm
Gerd Isenberg Fri Apr 27, 2007 7:41 pm
Gerd Isenberg Fri Apr 27, 2007 7:44 pm

 Jump to: Select a forum Computer Chess Club Forums----------------Computer Chess Club: General TopicsComputer Chess Club: Tournaments and MatchesComputer Chess Club: Programming and Technical DiscussionsComputer Chess Club: Engine Origins Other Forums----------------Chess Thinkers ForumForum Help and Suggestions
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum