lantonov / asmFish

A continuation of the nice project asmFish by Mohammed Li. Latest version: 07.08.2019
https://lantonov.github.io/asmFish/
Other
118 stars 49 forks source link

Attempt at Simplify Null Move Search condition #93

Closed lantonov closed 6 years ago

lantonov commented 6 years ago

Patch in Stockfish

    // Step 8. Null move search with verification search (is omitted in PV nodes)
      if (   !PvNode
          &&  eval >= beta
 -        && (ss->staticEval >= beta - 35 * (depth / ONE_PLY - 6) || depth >= 13 * ONE_PLY)
 +        &&  ss->staticEval >= beta - 36 * depth / ONE_PLY + 225
          &&  pos.non_pawn_material(pos.side_to_move()))
      {

The relevant asmFish code is at SearchMacros.asm:341

        ; Step 8. Null move search with verification search (is omitted in PV nodes)
  if PvNode = 0
                mov   edx, dword[.depth]
               imul   eax, edx, 35
                add   eax, dword[rbx+State.staticEval]
                mov   esi, dword[.beta]
                mov   ecx, dword[rbp+Pos.sideToMove]
                cmp   esi, dword[.evalu]
                 jg   .8skip
                add   esi, 35*6
    if USE_MATEFINDER = 0
......
    end if
                sub   edx, 13*ONE_PLY
                sub   eax, esi
                and   edx, eax
                 js   .8skip

My attempt

        ; Step 8. Null move search with verification search (is omitted in PV nodes)
  if PvNode = 0
                mov   edx, dword[.depth]
               imul   eax, edx, 36
                add   eax, dword[rbx+State.staticEval]
                mov   esi, dword[.beta]
                mov   ecx, dword[rbp+Pos.sideToMove]
                cmp   esi, dword[.evalu]
                 jg   .8skip
                add   esi, 225
    if USE_MATEFINDER = 0
........
    end if
                sub   eax, esi
                 js   .8skip

Bench is 5015773, the same as in the Stockfish patch Unfortunately, in armFish the same changes give bench 6845061

    ; Step 8. Null move search with verification search (is omitted in PV nodes)
  if PvNode = 0
            ldr  w2, [sp, .depth]
            mov  w4, 36
            mul  w0, w2, w4
            ldr  w4, [x21, State.staticEval]
            add  w0, w0, w4
            ldr  w26, [sp, .beta]
            ldr  w1, [x20, Pos.sideToMove]
            ldr  w4, [sp, .evalu]
            cmp  w26, w4
            bgt  .8skip
            add  w26, w26, 225
    if USE_MATEFINDER = 0
...........
    end if
            sub  w0, w0, w26
            bmi  .8skip
lantonov commented 6 years ago

Score of asmFishW_1663723_bmi2 vs stockfish-0a74c16: 192 - 192 - 616 [0.500] 1000 depth 14 Elo difference: 0.00 +/- 13.33 0/500 different results.txt

lantonov commented 6 years ago

For the next patch Always do MaxCardinality checks in ThreadPool.asm:219

    ; Skip TB probing when no TB found
        cmp   dword[options.multiPV], 1
        jne   .check_tb_ret
        mov   dl, byte[options.syzygy50MoveRule]
        mov   byte[Tablebase_RootInTB], 0
        mov   byte[Tablebase_UseRule50], dl
        mov   eax, dword[options.syzygyProbeLimit]
        mov   ecx, dword[options.syzygyProbeDepth]
        xor   edx, edx
        cmp   eax, dword[Tablebase_MaxCardinality]
          cmovg   eax, dword[Tablebase_MaxCardinality]
          cmovg   ecx, edx
        mov   dword[Tablebase_Cardinality], eax
        mov   dword[Tablebase_ProbeDepth], ecx

to

    ; Skip TB probing when no TB found
        mov   dl, byte[options.syzygy50MoveRule]
        mov   byte[Tablebase_RootInTB], 0
        mov   byte[Tablebase_UseRule50], dl
        mov   eax, dword[options.syzygyProbeLimit]
        mov   ecx, dword[options.syzygyProbeDepth]
        xor   edx, edx
        cmp   eax, dword[Tablebase_MaxCardinality]
          cmovg   eax, dword[Tablebase_MaxCardinality]
          cmovg   ecx, edx
        mov   dword[Tablebase_Cardinality], eax
        mov   dword[Tablebase_ProbeDepth], ecx
        cmp   dword[options.multiPV], 1
        jne   .check_tb_ret

Bench is the same 5015773

lantonov commented 6 years ago

Score of asmFishW_525856e_bmi2 vs stockfish-8cfcca1: 203 - 203 - 594 [0.500] 1000 depth 14 Elo difference: 0.00 +/- 13.71 0/500 different results.txt

lantonov commented 6 years ago

Capture Stat Simplification in C++

       {
                  if (!pos.capture_or_promotion(ttMove))
                      update_stats(pos, ss, ttMove, nullptr, 0, stat_bonus(depth));
 -                else
 -                    update_capture_stats(pos, ttMove, nullptr, 0, stat_bonus(depth));

                  // Extra penalty for a quiet TT move in previous ply when it gets refuted
                  if ((ss-1)->moveCount == 1 && !pos.captured_piece())

Relevant code at SearchMacros.asm:1377

          movzx   eax, byte[rbp+Pos.board+rax]
             or   al, byte[_CaptureOrPromotion_or+rdx]
           test   al, byte[_CaptureOrPromotion_and+rdx]
            jnz   .20Quiet_UpdateCaptureStats
    UpdateStats   r12d, .quietsSearched, dword[.quietCount], r11d, r10d, r15
            jmp   .20Quiet_UpdateStatsDone
.20Quiet_UpdateCaptureStats:
    UpdateCaptureStats   r12d, .capturesSearched, dword[.captureCount], r11d, r10d
.20Quiet_UpdateStatsDone:
            lea   r10d, [r10+2*(r13+1)+1]

I was not able to make bench 5363761 so far

lantonov commented 6 years ago

Code by @jdehorty at SearchMacros.asm:1513


             lea   r15d, [rax+rcx]
      ; r15d = offset of [piece_on(prevSq),prevSq]
             test   dl, dl
 -            jnz   .ReturnTTValue_UpdateCaptureStats
      UpdateStats   r12d, 0, 0, r11d, r10d, r15
 -            jmp   .ReturnTTValue_UpdateStatsDone
 -.ReturnTTValue_UpdateCaptureStats:
 -    UpdateCaptureStats  r12d, 0, 0, r11d, r10d
 +          jmp   .ReturnTTValue_UpdateStatsDone
  .ReturnTTValue_UpdateStatsDone:
              mov   eax, edi
              lea   r10d, [r10+2*(r13+1)+1]
tthsqe12 commented 6 years ago

In this part for arm sub w0, w0, w26 bmi .8skip The sub does not set the flags. You can use subs to set the flags.