Skip to content

Instantly share code, notes, and snippets.

@adamsitnik
Last active January 9, 2016 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamsitnik/9d4f0107bdc15a802bbf to your computer and use it in GitHub Desktop.
Save adamsitnik/9d4f0107bdc15a802bbf to your computer and use it in GitHub Desktop.
x86 JIT: break; produces jne to loops end, when return false gives je to next comparison. My guess is that the number of jumps taken hurt performance by impairing the instruction pipeline.
x86 version with break;
if (*((void**)firstPointer + 0) != *((void**)secondPointer + 0)) break;
010B3577 mov eax,dword ptr [ebp-10h]
{
if (*((void**)firstPointer + 0) != *((void**)secondPointer + 0)) break;
010B357A mov eax,dword ptr [eax]
010B357C mov edx,dword ptr [ebp-14h]
010B357F cmp eax,dword ptr [edx]
010B3581 jne 010B360F
if (*((void**)firstPointer + 1) != *((void**)secondPointer + 1)) break;
010B3587 mov eax,dword ptr [ebp-10h]
010B358A mov eax,dword ptr [eax+4]
010B358D mov edx,dword ptr [ebp-14h]
010B3590 cmp eax,dword ptr [edx+4]
010B3593 jne 010B360F
if (*((void**)firstPointer + 2) != *((void**)secondPointer + 2)) break;
010B3595 mov eax,dword ptr [ebp-10h]
010B3598 mov edx,4
010B359D add edx,edx
010B359F mov eax,dword ptr [eax+edx]
010B35A2 mov edx,dword ptr [ebp-14h]
010B35A5 mov ecx,4
010B35AA add ecx,ecx
010B35AC cmp eax,dword ptr [edx+ecx]
010B35AF jne 010B360F
if (*((void**)firstPointer + 3) != *((void**)secondPointer + 3)) break;
010B35B1 mov eax,dword ptr [ebp-10h]
010B35B4 mov edx,3
010B35B9 mov ecx,4
010B35BE imul edx,ecx
010B35C1 mov eax,dword ptr [eax+edx]
010B35C4 mov edx,dword ptr [ebp-14h]
010B35C7 mov ecx,3
010B35CC mov ebx,4
010B35D1 imul ecx,ebx
010B35D4 cmp eax,dword ptr [edx+ecx]
010B35D7 jne 010B360F
if (*((void**)firstPointer + 4) != *((void**)secondPointer + 4)) break;
010B35D9 mov eax,dword ptr [ebp-10h]
010B35DC mov edx,4
010B35E1 shl edx,2
010B35E4 mov eax,dword ptr [eax+edx]
010B35E7 mov edx,dword ptr [ebp-14h]
010B35EA mov ecx,4
010B35EF shl ecx,2
010B35F2 cmp eax,dword ptr [edx+ecx]
010B35F5 jne 010B360F
firstPointer += step;
010B35F7 mov eax,dword ptr [ebp-18h]
010B35FA add dword ptr [ebp-10h],eax
secondPointer += step;
010B35FD mov eax,dword ptr [ebp-18h]
010B3600 add dword ptr [ebp-14h],eax
{
while (firstPointer < firstPointerLimit)
010B3603 mov eax,dword ptr [ebp-10h]
010B3606 cmp eax,dword ptr [ebp-1Ch]
010B3609 jb 010B3577
}
if (firstPointer < firstPointerLimit) // the upper loop ended with break;
010B360F mov eax,dword ptr [ebp-10h]
010B3612 cmp eax,dword ptr [ebp-1Ch]
010B3615 jae 010B361F
{
return false;
010B3617 xor edx,edx
010B3619 mov dword ptr [ebp-20h],edx
010B361C nop
010B361D jmp 010B3655
}
x86 with return false;
if (*((void**)firstPointer + 0) != *((void**)secondPointer + 0)) return false;
02A73583 xor edx,edx
02A73585 mov dword ptr [ebp-20h],edx
02A73588 nop
02A73589 jmp 02A73672
if (*((void**)firstPointer + 1) != *((void**)secondPointer + 1)) return false;
02A7358E mov eax,dword ptr [ebp-10h]
02A73591 mov eax,dword ptr [eax+4]
02A73594 mov edx,dword ptr [ebp-14h]
02A73597 cmp eax,dword ptr [edx+4]
02A7359A je 02A735A7
02A7359C xor edx,edx
02A7359E mov dword ptr [ebp-20h],edx
02A735A1 nop
02A735A2 jmp 02A73672
if (*((void**)firstPointer + 2) != *((void**)secondPointer + 2)) return false;
02A735A7 mov eax,dword ptr [ebp-10h]
02A735AA mov edx,4
02A735AF add edx,edx
02A735B1 mov eax,dword ptr [eax+edx]
02A735B4 mov edx,dword ptr [ebp-14h]
02A735B7 mov ecx,4
02A735BC add ecx,ecx
02A735BE cmp eax,dword ptr [edx+ecx]
02A735C1 je 02A735CE
02A735C3 xor edx,edx
02A735C5 mov dword ptr [ebp-20h],edx
02A735C8 nop
02A735C9 jmp 02A73672
if (*((void**)firstPointer + 3) != *((void**)secondPointer + 3)) return false;
02A735CE mov eax,dword ptr [ebp-10h]
02A735D1 mov edx,3
02A735D6 mov ecx,4
02A735DB imul edx,ecx
02A735DE mov eax,dword ptr [eax+edx]
02A735E1 mov edx,dword ptr [ebp-14h]
02A735E4 mov ecx,3
02A735E9 mov ebx,4
02A735EE imul ecx,ebx
02A735F1 cmp eax,dword ptr [edx+ecx]
02A735F4 je 02A735FE
02A735F6 xor edx,edx
02A735F8 mov dword ptr [ebp-20h],edx
02A735FB nop
02A735FC jmp 02A73672
if (*((void**)firstPointer + 4) != *((void**)secondPointer + 4)) return false;
02A735FE mov eax,dword ptr [ebp-10h]
02A73601 mov edx,4
02A73606 shl edx,2
02A73609 mov eax,dword ptr [eax+edx]
02A7360C mov edx,dword ptr [ebp-14h]
02A7360F mov ecx,4
02A73614 shl ecx,2
02A73617 cmp eax,dword ptr [edx+ecx]
02A7361A je 02A73624
02A7361C xor edx,edx
02A7361E mov dword ptr [ebp-20h],edx
02A73621 nop
02A73622 jmp 02A73672
firstPointer += step;
02A73624 mov eax,dword ptr [ebp-18h]
02A73627 add dword ptr [ebp-10h],eax
secondPointer += step;
02A7362A mov eax,dword ptr [ebp-18h]
02A7362D add dword ptr [ebp-14h],eax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment