1/* 2 * ==================================================== 3 * Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and distribute this 6 * software is freely granted, provided that this notice 7 * is preserved. 8 * ==================================================== 9 */ 10 11#include <picolibc.h> 12 13 #include "i386mach.h" 14 15 .global SYM (memcmp) 16 SOTYPE_FUNCTION(memcmp) 17 18SYM (memcmp): 19 20#ifdef __iamcu__ 21 pushl edi 22 pushl esi 23 movl eax,edi 24 movl edx,esi 25 cld 26 27/* check if length is zero in which case just return 0 */ 28 29 xorl eax,eax 30 testl ecx,ecx 31 jz L4 32 33/* compare any unaligned bytes or remainder bytes */ 34 repz 35 cmpsb 36 37/* set output to be < 0 if less than, 0 if equal, or > 0 if greater than */ 38 xorl edx,edx 39 movb -1(esi),dl 40 movb -1(edi),al 41 subl edx,eax 42 43L4: 44 popl esi 45 popl edi 46#else 47 pushl ebp 48 movl esp,ebp 49 subl $16,esp 50 pushl ebx 51 pushl edi 52 pushl esi 53 movl 8(ebp),edi 54 movl 12(ebp),esi 55 movl 16(ebp),ecx 56 cld 57 58/* check if length is zero in which case just return 0 */ 59 60 xorl eax,eax 61 testl ecx,ecx 62 jz L4 63 64#ifndef __OPTIMIZE_SIZE__ 65 66/* if aligned on long boundary, compare doublewords at a time first */ 67 68 movl edi,eax 69 orl esi,eax 70 testb $3,al 71 jne BYTECMP 72 movl ecx,ebx 73 shrl $2,ecx /* calculate number of long words to compare */ 74 repz 75 cmpsl 76 jz L5 77 subl $4,esi 78 subl $4,edi 79 movl $4,ecx 80 jmp BYTECMP 81L5: 82 andl $3,ebx /* calculate number of remaining bytes */ 83 movl ebx,ecx 84 85#endif /* not __OPTIMIZE_SIZE__ */ 86 87BYTECMP: /* compare any unaligned bytes or remainder bytes */ 88 repz 89 cmpsb 90 91/* set output to be < 0 if less than, 0 if equal, or > 0 if greater than */ 92L3: 93 xorl edx,edx 94 movb -1(esi),dl 95 xorl eax,eax 96 movb -1(edi),al 97 subl edx,eax 98 99L4: 100 leal -28(ebp),esp 101 popl esi 102 popl edi 103 popl ebx 104 leave 105#endif 106 ret 107 108#if defined(__linux__) && defined(__ELF__) 109.section .note.GNU-stack,"",%progbits 110#endif 111