1/* 2 * Written by J.T. Conklin <jtc@NetBSD.org>. 3 * Public domain. 4 */ 5 6#include <machine/asm.h> 7 8#if defined(LIBC_SCCS) 9 RCSID("$NetBSD: memcmp.S,v 1.3 2014/03/22 19:38:46 jakllsch Exp $") 10#endif 11 12ENTRY(memcmp) 13 pushl %edi 14 pushl %esi 15 movl 12(%esp),%edi 16 movl 16(%esp),%esi 17 18 movl 20(%esp),%ecx /* compare by words */ 19 shrl $2,%ecx 20 repe 21 cmpsl 22 jne L5 /* do we match so far? */ 23 24 movl 20(%esp),%ecx /* compare remainder by bytes */ 25 andl $3,%ecx 26 repe 27 cmpsb 28 jne L6 /* do we match? */ 29 30 xorl %eax,%eax /* we match, return zero */ 31 popl %esi 32 popl %edi 33 ret 34 35L5: movl $4,%ecx /* We know that one of the next */ 36 subl %ecx,%edi /* four pairs of bytes do not */ 37 subl %ecx,%esi /* match. */ 38 repe 39 cmpsb 40L6: xorl %eax,%eax /* Perform unsigned comparison */ 41 movb -1(%edi),%al 42 xorl %edx,%edx 43 movb -1(%esi),%dl 44 subl %edx,%eax 45 popl %esi 46 popl %edi 47 ret 48END(memcmp) 49