memcpy

fastest strstr

Mar 12th, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Prototype : char *asm_str_str(const char *s1, const char *s2)
  3.  * Input     : s1 (rdi), s2 (rsi)  
  4.  * Output    : char * (rax)
  5.  * Clobber   : rbx, rcx
  6.  */
  7.  
  8. .globl _asm_str_str
  9. _asm_str_str:
  10.     movq    $-0x1, %rcx
  11. .s_len:
  12.     incq    %rcx
  13.     cmpb    $0x0, (%rsi, %rcx, 0x1)
  14.     jne .s_len
  15.     cmpq    $0x0, %rcx
  16.     je  .s_out
  17. .s_loop:
  18.     cmpq    $0x8, %rcx
  19.     jl  .s_cmp_0x1
  20. .s_cmp_0x8:
  21.     movq    -0x8(%rdi, %rcx, 0x1), %rbx
  22.     cmpq    %rbx, -0x8(%rsi, %rcx, 0x1)
  23.     jne .s_inc
  24.     subq    $0x8, %rcx
  25.         cmpq    $0x7, %rcx
  26.     jg  .s_cmp_0x8
  27. .s_cmp_0x1:
  28.     movb    -0x1(%rdi, %rcx, 0x1), %bl
  29.     cmpb    %bl, -0x1(%rsi, %rcx, 0x1)
  30.     jne .s_inc
  31.     decq    %rcx
  32.     jg  .s_cmp_0x1
  33.     jmp .s_out
  34. .s_inc:
  35.     incq    %rdi
  36.     cmpb    $0x0, -0x1(%rdi)
  37.     jne .s_loop
  38.     xorq    %rdi, %rdi
  39. .s_out:
  40.     movq    %rdi, %rax
  41.     ret
Advertisement
Add Comment
Please, Sign In to add comment