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