1144782Salc/* 2144782Salc * Written by J.T. Conklin <jtc@NetBSD.org>. 3144782Salc * Public domain. 4144782Salc * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com> 5144782Salc */ 6144782Salc 7144782Salc#include <machine/asm.h> 8144782Salc__FBSDID("$FreeBSD: releng/10.3/lib/libc/amd64/string/memcmp.S 217106 2011-01-07 16:08:40Z kib $"); 9144782Salc 10144782Salc#if 0 11144782Salc RCSID("$NetBSD: memcmp.S,v 1.2 2003/07/26 19:24:39 salo Exp $") 12144782Salc#endif 13144782Salc 14144782SalcENTRY(memcmp) 15144782Salc cld /* set compare direction forward */ 16144782Salc movq %rdx,%rcx /* compare by longs */ 17144782Salc shrq $3,%rcx 18144782Salc repe 19144782Salc cmpsq 20144782Salc jne L5 /* do we match so far? */ 21144782Salc 22144782Salc movq %rdx,%rcx /* compare remainder by bytes */ 23144782Salc andq $7,%rcx 24144782Salc repe 25144782Salc cmpsb 26144782Salc jne L6 /* do we match? */ 27144782Salc 28144782Salc xorl %eax,%eax /* we match, return zero */ 29144782Salc ret 30144782Salc 31144782SalcL5: movl $8,%ecx /* We know that one of the next */ 32144782Salc subq %rcx,%rdi /* eight pairs of bytes do not */ 33144782Salc subq %rcx,%rsi /* match. */ 34144782Salc repe 35144782Salc cmpsb 36144782SalcL6: xorl %eax,%eax /* Perform unsigned comparison */ 37144782Salc movb -1(%rdi),%al 38144782Salc xorl %edx,%edx 39144782Salc movb -1(%rsi),%dl 40144782Salc subl %edx,%eax 41144782Salc ret 42184547SpeterEND(memcmp) 43217106Skib 44217106Skib .section .note.GNU-stack,"",%progbits 45