memcmp.S 806 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* $OpenBSD: memcmp.S,v 1.2 2014/11/29 18:51:23 tedu Exp $ */
  2. /*
  3. * Written by J.T. Conklin <jtc@netbsd.org>.
  4. * Public domain.
  5. */
  6. #include <machine/asm.h>
  7. ENTRY(memcmp)
  8. pushl %edi
  9. pushl %esi
  10. movl 12(%esp),%edi
  11. movl 16(%esp),%esi
  12. movl 20(%esp),%ecx /* compare by words */
  13. shrl $2,%ecx
  14. repe
  15. cmpsl
  16. jne L5 /* do we match so far? */
  17. movl 20(%esp),%ecx /* compare remainder by bytes */
  18. andl $3,%ecx
  19. repe
  20. cmpsb
  21. jne L6 /* do we match? */
  22. xorl %eax,%eax /* we match, return zero */
  23. popl %esi
  24. popl %edi
  25. ret
  26. L5: movl $4,%ecx /* We know that one of the next */
  27. subl %ecx,%edi /* four pairs of bytes do not */
  28. subl %ecx,%esi /* match. */
  29. repe
  30. cmpsb
  31. L6: movzbl -1(%edi),%eax /* Perform unsigned comparison */
  32. movzbl -1(%esi),%edx
  33. subl %edx,%eax
  34. popl %esi
  35. popl %edi
  36. ret