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 7#include <machine/asm.h> 8 9#if defined(LIBC_SCCS) 10 RCSID("$NetBSD: memcmp.S,v 1.3 2014/03/22 19:16:34 jakllsch Exp $") 11#endif 12 13ENTRY(memcmp) 14 movq %rdx,%rcx /* compare by longs */ 15 shrq $3,%rcx 16 repe 17 cmpsq 18 jne L5 /* do we match so far? */ 19 20 movq %rdx,%rcx /* compare remainder by bytes */ 21 andq $7,%rcx 22 repe 23 cmpsb 24 jne L6 /* do we match? */ 25 26 xorl %eax,%eax /* we match, return zero */ 27 ret 28 29L5: movl $8,%ecx /* We know that one of the next */ 30 subq %rcx,%rdi /* eight pairs of bytes do not */ 31 subq %rcx,%rsi /* match. */ 32 repe 33 cmpsb 34L6: xorl %eax,%eax /* Perform unsigned comparison */ 35 movb -1(%rdi),%al 36 xorl %edx,%edx 37 movb -1(%rsi),%dl 38 subl %edx,%eax 39 ret 40END(memcmp) 41