Skip to content

Commit

Permalink
Make kingRing always 8 squares bench 5934104
Browse files Browse the repository at this point in the history
5934103 is the official bench but 5934104 is correct since official-stockfish/Stockfish@59d1037 was skipped in asmFish. See discussion at lantonov#165 for more details.
  • Loading branch information
CounterPly committed Jun 10, 2018
1 parent cb7c53d commit 3d30473
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 34 deletions.
97 changes: 63 additions & 34 deletions x86/Evaluate.asm
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,79 @@ macro EvalInit Us
local Them, Down
local NotUsed, PinnedLoop, NoPinned, YesPinned

if Us = White
Them = Black
Down = DELTA_S
else
Them = White
Down = DELTA_N
end if

if Us = White
Them = Black
Up = DELTA_S
Down = DELTA_N
West = DELTA_W
East = DELTA_E
else
Them = White
Up = DELTA_N
Down = DELTA_S
West = DELTA_W
East = DELTA_E
end if

; Assert e, rdi, qword[.ei.pi], 'assertion rdi = ei.pi failed in EvalInit'

movzx ecx, word[rbx+State.npMaterial+2*Us]

movzx eax, byte[rbp+Pos.pieceList+16*(8*Them+King)]
if Them = White
cmp eax, SQ_A2
setb al
else
cmp eax, SQ_A8
setae al
end if

mov r9, qword[.ei.attackedBy+8*(8*Them+King)]
or qword[.ei.attackedBy+8*(8*Them+0)], r9
mov r10, qword[rdi+PawnEntry.pawnAttacks+8*Us]
mov qword[.ei.attackedBy+8*(8*Us+Pawn)], r10
or qword[.ei.attackedBy+8*(8*Us+0)], r10
; rdx = b

xor r8, r8
xor edx, edx
movzx ecx, word[rbx+State.npMaterial+2*Us]
movzx eax, byte[rbp+Pos.pieceList+16*(8*Them+King)]
mov r11d, eax
mov r9, qword[.ei.attackedBy+8*(8*Them+King)]
or qword[.ei.attackedBy+8*(8*Them+0)], r9
mov r10, qword[rdi+PawnEntry.pawnAttacks+8*Us]
mov qword[.ei.attackedBy+8*(8*Us+Pawn)], r10
or qword[.ei.attackedBy+8*(8*Us+0)], r10
xor r8, r8
xor edx, edx
cmp ecx, RookValueMg + KnightValueMg
jb NotUsed
jb @1f

; if (relative_rank(Us, pos.square<KING>) == RANK_1)
if Them = White
cmp eax, SQ_A2
setb al
else
cmp eax, SQ_A8
setae al
end if

; kingRing[Us] |= shift<Up>(kingRing[Us]);
mov r8, r9
neg rax
ShiftBB Down, r8
ShiftBB Up, r8
and r8, rax
or r8, r9
or r8, r9
mov rdx, r8
; r8 = kingRing

; if (file_of(pos.square<KING>) == FILE_H)
mov eax, r11d
and eax, 7
cmp eax, 7
jne @f
ShiftBB West, r8, rcx
or r8, rdx
mov rdx, r8

@@:
; if (file_of(pos.square<KING>) == FILE_A)
and r11d, 7 ; hammers r11 but saves an instruction
test r11d, r11d
jnz @f
ShiftBB East, r8, rcx
or r8, rdx

@@:
and r9, r10
_popcnt rdx, r9, rcx
_popcnt rdx, r9, rcx
xor eax, eax
mov dword[.ei.kingAttackersWeight+4*Us], eax
mov dword[.ei.kingAdjacentZoneAttacksCount+4*Us], eax
NotUsed:

@1:
mov qword[.ei.kingRing+8*Them], r8
mov dword[.ei.kingAttackersCount+4*Us], edx
and r10, qword[.ei.attackedBy+8*(8*Us+King)]
Expand Down
8 changes: 8 additions & 0 deletions x86/GenMacros.asm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ macro ShiftBB delta, b, t
shl b, 8
else if delta = DELTA_S
shr b, 8
else if delta = DELTA_E
mov t, not FileHBB
and b, t
shl b, 1
else if delta = DELTA_W
mov t, not FileABB
and b, t
shr b, 1
else if delta = DELTA_NE
mov t, not FileHBB
and b, t
Expand Down

0 comments on commit 3d30473

Please sign in to comment.