Haswell New Instructions

Discussion of chess software programming and technical issues.

Moderator: Ras

Gerd Isenberg
Posts: 2251
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Haswell New Instructions

Post by Gerd Isenberg »

Ok, the magic alternative with ~200 KB (< 10K for Bishops), preserving the input parameters, looks really promising:

Code: Select all

; input:  rcx square index 0..63
;         rdx occupancy
; output: rax rook attacks

  pext    rax, rdx, quad word ptr [rookMaskEx + 8*rcx]  ; 10,11,12 bits
  mov     r10, [rookSquarePointer + 8*rcx] ; pointer to square array
  movzx   rax, word ptr [r10 + 2*rax]
  pdep    rax, rax, quad word ptr [rookMask + 8*rcx]
Gerd Isenberg
Posts: 2251
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Haswell New Instructions

Post by Gerd Isenberg »

Or pext only with the conventional magic array sizes, pext saves "and", mul, shift, not to mention the lookup of the factor and variable shift:

Code: Select all

; input:  rcx square index 0..63
;         rdx occupancy
; output: rax rook attacks

  pext    rax, rdx, quad word ptr [rookMaskEx + 8*rcx]  ; 10,11,12 bits
  mov     r10, [rookSquarePointer + 8*rcx] ; pointer to square array
  mov     rax, word ptr [r10 + 8*rax]
ibid
Posts: 89
Joined: Mon Jun 13, 2011 12:09 pm

Re: Haswell New Instructions

Post by ibid »

Zach Wegner wrote:The instructions, particularly the bit manipulation instructions, look pretty awesome for chess. Check out PEXT/PDEP: instead of magic bitboards, you can just get the attack mask, extract out the relevant bits with PEXT, do a table lookup of a 2-byte value (just a compressed attack bitboard), and use PDEP to decompress back to an attack bitboard. Too bad there's not a vector version too :)
Excellent. I've been waiting for those two instructions for many years.
Always seemed like an "obvious" way to do it.

You can save a little memory on the 2-byte tables too. For example,
the rook tables for h1 and a8 would be identical. Doesn't seem to work
for many tables though.