memchr.S 566 B

123456789101112131415161718192021222324252627
  1. /* $OpenBSD: memchr.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(memchr)
  8. pushl %edi
  9. movl 8(%esp),%edi /* string address */
  10. movl 12(%esp),%eax /* set character to search for */
  11. movl 16(%esp),%ecx /* set length of search */
  12. testl %ecx,%ecx /* test for len == 0 */
  13. jz L1
  14. repne /* search! */
  15. scasb
  16. jne L1 /* scan failed, return null */
  17. leal -1(%edi),%eax /* adjust result of scan */
  18. popl %edi
  19. ret
  20. .align 2,0x90
  21. L1: xorl %eax,%eax
  22. popl %edi
  23. ret