strcmp.S 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* $OpenBSD: strcmp.S,v 1.3 2014/12/09 15:13:57 reyk Exp $ */
  2. /* $NetBSD: strcmp.S,v 1.2 2014/03/22 19:16:34 jakllsch Exp $ */
  3. /*
  4. * Written by J.T. Conklin <jtc@acorntoolworks.com>
  5. * Public domain.
  6. */
  7. #include <machine/asm.h>
  8. ENTRY(strcmp)
  9. /*
  10. * Align s1 to word boundary.
  11. * Consider unrolling loop?
  12. */
  13. .Ls1align:
  14. testb $7,%dil
  15. je .Ls1aligned
  16. movb (%rdi),%al
  17. incq %rdi
  18. movb (%rsi),%dl
  19. incq %rsi
  20. testb %al,%al
  21. je .Ldone
  22. cmpb %al,%dl
  23. je .Ls1align
  24. jmp .Ldone
  25. /*
  26. * Check whether s2 is aligned to a word boundary. If it is, we
  27. * can compare by words. Otherwise we have to compare by bytes.
  28. */
  29. .Ls1aligned:
  30. testb $7,%sil
  31. jne .Lbyte_loop
  32. movabsq $0x0101010101010101,%r8
  33. subq $8,%rdi
  34. movabsq $0x8080808080808080,%r9
  35. subq $8,%rsi
  36. _ALIGN_TEXT
  37. .Lword_loop:
  38. movq 8(%rdi),%rax
  39. addq $8,%rdi
  40. movq 8(%rsi),%rdx
  41. addq $8,%rsi
  42. cmpq %rax,%rdx
  43. jne .Lbyte_loop
  44. subq %r8,%rdx
  45. notq %rax
  46. andq %rax,%rdx
  47. testq %r9,%rdx
  48. je .Lword_loop
  49. _ALIGN_TEXT
  50. .Lbyte_loop:
  51. movb (%rdi),%al
  52. incq %rdi
  53. movb (%rsi),%dl
  54. incq %rsi
  55. testb %al,%al
  56. je .Ldone
  57. cmpb %al,%dl
  58. je .Lbyte_loop
  59. .Ldone:
  60. movzbq %al,%rax
  61. movzbq %dl,%rdx
  62. subq %rdx,%rax
  63. ret