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 "i386mach.h" 12 13 .global SYM (memmove) 14 SOTYPE_FUNCTION(memmove) 15 16SYM (memmove): 17 18 pushl ebp 19 movl esp,ebp 20 pushl esi 21 pushl edi 22 pushl ebx 23 movl 8(ebp),edi 24 movl 16(ebp),ecx 25 movl 12(ebp),esi 26 27/* check for destructive overlap (src < dst && dst < src + length) */ 28 29 cld 30 cmpl edi,esi 31 jae .L2 32 leal -1(ecx,esi),ebx 33 cmpl ebx,edi 34 ja .L2 35 36/* IF: destructive overlap, must copy backwards */ 37 38 addl ecx,esi 39 addl ecx,edi 40 std 41 42#ifndef __OPTIMIZE_SIZE__ 43 44 cmpl $8,ecx 45 jbe .L13 46.L18: 47 48/* move trailing bytes in reverse until destination address is long word aligned */ 49 50 movl edi,edx 51 movl ecx,ebx 52 andl $3,edx 53 jz .L21 54 55 movl edx,ecx 56 decl esi 57 decl edi 58 subl ecx,ebx 59 rep 60 movsb 61 62 mov ebx,ecx 63 incl esi 64 incl edi 65 66.L21: 67 68/* move bytes in reverse, a long word at a time */ 69 70 shrl $2,ecx 71 subl $4,esi 72 subl $4,edi 73 rep 74 movsl 75 76 addl $4,esi 77 addl $4,edi 78 movl ebx,ecx 79 andl $3,ecx 80 81#endif /* !__OPTIMIZE_SIZE__ */ 82 83/* handle any remaining bytes not on a long word boundary */ 84 85.L13: 86 decl esi 87 decl edi 88 89.L15: 90 rep 91 movsb 92 jmp .L5 93 .p2align 4,,7 94 95/* ELSE: no destructive overlap so we copy forwards */ 96 97.L2: 98 99#ifndef __OPTIMIZE_SIZE__ 100 101 cmpl $8,ecx 102 jbe .L3 103 104/* move any preceding bytes until destination address is long word aligned */ 105 106 movl edi,edx 107 movl ecx,ebx 108 andl $3,edx 109 jz .L11 110 movl $4,ecx 111 subl edx,ecx 112 andl $3,ecx 113 subl ecx,ebx 114 rep 115 movsb 116 117 mov ebx,ecx 118 119/* move bytes a long word at a time */ 120 121.L11: 122 shrl $2,ecx 123 .p2align 2 124 rep 125 movsl 126 127 movl ebx,ecx 128 andl $3,ecx 129 130#endif /* !__OPTIMIZE_SIZE__ */ 131 132/* handle any remaining bytes */ 133 134.L3: 135 rep 136 movsb 137.L5: 138 movl 8(ebp),eax 139 cld 140 141 leal -12(ebp),esp 142 popl ebx 143 popl edi 144 popl esi 145 leave 146 ret 147