ChessUSA.com TalkChess.com
Hosted by Your Move Chess & Games
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

New simple and fast bitboard move generator
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions Flat
View previous topic :: View next topic  
Author Message
Gerd Isenberg



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

PostPost subject: Re: New simple and fast bitboard move generator    Posted: Sun May 06, 2007 11:16 am Reply to topic Reply with quote

In assembly i would try something like this, to use a shared index array with preinitialized registers {0(implicit), 7, 56, 63} to distinguish between different directions if no inner blocking square is found by bitscan. That takes only max two cachelines (if properly 64-byte cacheline-aligned) for the four 2-byte index lookups:

Code:
_rookAttacks PROC
  shl  ecx, 5 ; sq*64

  mov  rax, rdx ; occ
  mov  r8, rdx
  mov  r9, rdx
  mov  r10d, 7
  mov  r11d, 56

  and  rax, QWORD PTR bits[rcx]
  and  r8,  QWORD PTR bits[rcx + 8]
  and  r9,  QWORD PTR bits[rcx + 16]
  and  rdx, QWORD PTR bits[rcx + 24]

  add  ecx, ecx ; *2 assumes short lookop

  bsf  rax, rax
  bsf  r10,  r8
  mov  r8d, 63
  bsr  r11,  r9
  bsr  r8, rdx

  movzx eax,WORD PTR index[rcx + 2*rax] ; *2 assumes short lookop
  or    ax, WORD PTR index[rcx + 2*r10]
  or    ax, WORD PTR index[rcx + 2*r11]
  or    ax, WORD PTR index[rcx + 2*r8]
 
  mov   rax, QWORD PTR rookLookup[8*rax]
  ret   0
_rookAttacks ENDP

But if i try this C-Code, the generated assembly unfortunately looks very ugly.

Code:
u64 rookAttacks(u64 occ, u32 sq) {
    unsigned long ln = 0, le = 7, ls = 56, lw = 63;
    _BitScanForward64(&ln, occ & bits[sq][0]);
    _BitScanForward64(&le, occ & bits[sq][1]);
    _BitScanReverse64(&ls, occ & bits[sq][2]);
    _BitScanReverse64(&lw, occ & bits[sq][3]);
    u32 idx = index[sq][ln] | index[sq][le] | index[sq][ls] | index[sq][lw];
    return rookLookup[idx];
}
Back to top
View user's profile Send private message
Display posts from previous:   
Subject Author Date/Time
New simple and fast bitboard move generator Michael Sherwin Sat May 05, 2007 3:52 pm
      Re: New simple and fast bitboard move generator Gerd Isenberg Sat May 05, 2007 5:43 pm
            Re: New simple and fast bitboard move generator Gerd Isenberg Sun May 06, 2007 8:52 am
                  Re: New simple and fast bitboard move generator Michael Sherwin Sun May 06, 2007 10:31 am
                        Re: New simple and fast bitboard move generator Gerd Isenberg Sun May 06, 2007 11:16 am
                              Re: New simple and fast bitboard move generator Michael Sherwin Sun May 06, 2007 1:21 pm
                                    Re: New simple and fast bitboard move generator Gerd Isenberg Sun May 06, 2007 1:52 pm
                                          Re: New simple and fast bitboard move generator Michael Sherwin Sun May 06, 2007 3:15 pm
                              Re: New simple and fast bitboard move generator Michael Sherwin Sun May 06, 2007 10:29 pm
                                    Re: New simple and fast bitboard move generator Gerd Isenberg Mon May 07, 2007 8:40 am
                                          Re: New simple and fast bitboard move generator Michael Sherwin Mon May 07, 2007 11:06 am
                                          Re: New simple and fast bitboard move generator Gerd Isenberg Mon May 07, 2007 8:08 pm
                                                Re: New simple and fast bitboard move generator Gerd Isenberg Mon May 07, 2007 11:22 pm
                                                      Re: New simple and fast bitboard move generator Michael Sherwin Tue May 08, 2007 3:18 am
                                                            Re: New simple and fast bitboard move generator Gerd Isenberg Tue May 08, 2007 6:11 am
                                                Re: New simple and fast bitboard move generator Michael Sherwin Tue May 08, 2007 9:25 pm
                                                      Re: New simple and fast bitboard move generator Michael Sherwin Tue May 08, 2007 10:55 pm
                                                      Re: New simple and fast bitboard move generator Gerd Isenberg Wed May 09, 2007 3:18 am
                                                            Re: New simple and fast bitboard move generator Tony Wed May 09, 2007 6:10 am
                                                                  Re: New simple and fast bitboard move generator Michael Sherwin Wed May 09, 2007 7:47 am
                                                                        Re: New simple and fast bitboard move generator Tony Wed May 09, 2007 8:24 am
                                                      Re: New simple and fast bitboard move generator Gerd Isenberg Wed May 09, 2007 7:31 pm
                                                            Re: New simple and fast bitboard move generator Michael Sherwin Wed May 09, 2007 11:30 pm
            Re: New simple and fast bitboard move generator Tony Mon May 07, 2007 6:46 am
                  Re: New simple and fast bitboard move generator Gerd Isenberg Mon May 07, 2007 8:51 am
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions

 
Jump to:  
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




Powered by phpBB © 2001, 2005 phpBB Group
Enhanced with Moby Threads