Skip to content

Instantly share code, notes, and snippets.

@stepancheg
Created January 25, 2010 23:23
Show Gist options
  • Save stepancheg/286379 to your computer and use it in GitHub Desktop.
Save stepancheg/286379 to your computer and use it in GitHub Desktop.
%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