Created
January 25, 2010 23:23
-
-
Save stepancheg/286379 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%define EQUAL_EACH 1000b | |
%define NEGATIVE_POLARITY 010000b | |
EXPORT __strcmp_sse42 | |
mov rax, rdi | |
sub rax, rsi ; rax = rdi - rsi | |
sub rsi, 16 | |
@B: | |
add rsi, 16 | |
; compare strings | |
MovDqU xmm0, dqword[rsi] | |
PcmpIstrI xmm0, dqword[rsi + rax], EQUAL_EACH | NEGATIVE_POLARITY | |
jc @F | |
; testing for EOL | |
pxor xmm0, xmm0 | |
PcmpIstrI xmm0, dqword[rsi], EQUAL_EACH | |
jnz @B | |
; the strings are equal | |
mov rax, 0 | |
ret | |
@F: | |
; subtract the first different bytes | |
add rax, rsi | |
movzx rax, byte[rax + rcx] | |
movzx rsi, byte[rsi + rcx] | |
sub rax, rsi | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment