memcmp.S 733 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Written by J.T. Conklin <jtc@netbsd.org>.
  3. * Public domain.
  4. * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
  5. */
  6. #include <machine/asm.h>
  7. ENTRY(memcmp)
  8. movq %rdx,%rcx /* compare by longs */
  9. shrq $3,%rcx
  10. repe
  11. cmpsq
  12. jne L5 /* do we match so far? */
  13. movq %rdx,%rcx /* compare remainder by bytes */
  14. andq $7,%rcx
  15. repe
  16. cmpsb
  17. jne L6 /* do we match? */
  18. xorl %eax,%eax /* we match, return zero */
  19. ret
  20. L5: movl $8,%ecx /* We know that one of the next */
  21. subq %rcx,%rdi /* eight pairs of bytes do not */
  22. subq %rcx,%rsi /* match. */
  23. repe
  24. cmpsb
  25. L6: xorl %eax,%eax /* Perform unsigned comparison */
  26. movb -1(%rdi),%al
  27. xorl %edx,%edx
  28. movb -1(%rsi),%dl
  29. subl %edx,%eax
  30. ret