Here is the disassembly of 2 solutions (MSVC 2013)
Code: Select all
// We now know there are no friendly pawns beside or behind this
// pawn on adjacent files. We now check whether the pawn is
// backward by looking in the forward direction on the adjacent
// files, and picking the closest pawn there.
b = pawn_attack_span(Us, s) & (ourPawns | theirPawns);
000000013F7CBE22 mov r9,qword ptr [r11+rdx+2269E0h]
000000013F7CBE2A mov rax,r12
000000013F7CBE2D or rax,rsi
000000013F7CBE30 and rax,r9
b = pawn_attack_span(Us, s) & rank_bb(backmost_sq(Us, b));
000000013F7CBE33 bsf rax,rax
000000013F7CBE37 movsxd rcx,eax
000000013F7CBE3A sar rcx,3
000000013F7CBE3E mov rdx,qword ptr [rdx+rcx*8+13B6A0h]
000000013F7CBE46 and rdx,r9
// If we have an enemy pawn in the same or next rank, the pawn is
// backward because it cannot advance without being captured.
backward = (b | shift_bb<Up>(b)) & theirPawns;
000000013F7CBE49 movzx r9d,byte ptr [e]
000000013F7CBE4F mov rax,rdx
000000013F7CBE52 shl rax,8
000000013F7CBE56 or rax,rdx
000000013F7CBE59 test r12,rax
000000013F7CBE5C setne r12b
000000013F7CBE60 jmp `anonymous namespace'::evaluate<0>+1F5h (013F7CBE65h)
and yours:
Code: Select all
// We now know there are no friendly pawns beside or behind this
// pawn on adjacent files. We now check whether the pawn is
// backward by looking in the forward direction on the adjacent
// files, and picking the closest pawn there.
Rank ourRank = rank_of(backmost_sq(Us, pawn_attack_span(Us, s) & ourPawns));
000000013F7CBE25 mov rcx,qword ptr [r10+rax+2269E0h]
000000013F7CBE2D mov rax,rcx
000000013F7CBE30 and rcx,qword ptr [rsp+78h]
000000013F7CBE35 and rax,rdi
000000013F7CBE38 bsf rdx,rax
Rank theirRank = rank_of(backmost_sq(Us, pawn_attack_span(Us, s) & theirPawns));
000000013F7CBE3C bsf rax,rcx
000000013F7CBE40 sar edx,3
000000013F7CBE43 sar eax,3
backward = (Us == WHITE) ? (theirRank <= ourRank + 1) : (theirRank >= ourRank - 1);
000000013F7CBE46 inc edx
000000013F7CBE48 cmp eax,edx
000000013F7CBE4A setle bpl
000000013F7CBE4E jmp `anonymous namespace'::evaluate<0>+1E3h (013F7CBE53h)
backward = false;
000000013F7CBE50 xor bpl,bpl
Sorry I didn't do any speed test, also because you version is not functionally equivalent with original (bench signature of 7657127 instead of 8285241)