]>
Commit | Line | Data |
---|---|---|
432a73f7 UD |
1 | /* Copy memory block and return pointer to beginning of destination block |
2 | For Intel 80x86, x>=6. | |
3 | This file is part of the GNU C Library. | |
2b778ceb | 4 | Copyright (C) 2003-2021 Free Software Foundation, Inc. |
432a73f7 UD |
5 | |
6 | The GNU C Library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Lesser General Public | |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
10 | ||
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 | 17 | License along with the GNU C Library; if not, see |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
432a73f7 UD |
19 | |
20 | #include <sysdep.h> | |
21 | #include "asm-syntax.h" | |
432a73f7 | 22 | |
2366713d | 23 | #define PARMS 4+4 /* one spilled register */ |
432a73f7 | 24 | #define RTN PARMS |
432a73f7 UD |
25 | |
26 | .text | |
3af48cbd L |
27 | |
28 | #ifdef USE_AS_BCOPY | |
2366713d JM |
29 | # define SRC RTN |
30 | # define DEST SRC+4 | |
31 | # define LEN DEST+4 | |
3af48cbd | 32 | #else |
2366713d JM |
33 | # define DEST RTN |
34 | # define SRC DEST+4 | |
35 | # define LEN SRC+4 | |
3af48cbd | 36 | |
4f41c682 | 37 | # if defined PIC && IS_IN (libc) |
3af48cbd | 38 | ENTRY_CHK (__memmove_chk) |
b5cc329c UD |
39 | movl 12(%esp), %eax |
40 | cmpl %eax, 16(%esp) | |
41 | jb HIDDEN_JUMPTARGET (__chk_fail) | |
3af48cbd L |
42 | END_CHK (__memmove_chk) |
43 | # endif | |
b5cc329c | 44 | #endif |
3af48cbd | 45 | |
2366713d | 46 | ENTRY (memmove) |
432a73f7 UD |
47 | |
48 | pushl %edi | |
1ad9da69 | 49 | cfi_adjust_cfa_offset (4) |
432a73f7 UD |
50 | |
51 | movl LEN(%esp), %ecx | |
52 | movl DEST(%esp), %edi | |
1ad9da69 | 53 | cfi_rel_offset (edi, 0) |
432a73f7 UD |
54 | movl %esi, %edx |
55 | movl SRC(%esp), %esi | |
1ad9da69 | 56 | cfi_register (esi, edx) |
432a73f7 UD |
57 | |
58 | movl %edi, %eax | |
59 | subl %esi, %eax | |
66671c84 YK |
60 | cmpl %eax, %ecx |
61 | ja 3f | |
432a73f7 UD |
62 | |
63 | cld | |
64 | shrl $1, %ecx | |
65 | jnc 1f | |
66 | movsb | |
67 | 1: shrl $1, %ecx | |
68 | jnc 2f | |
69 | movsw | |
70 | 2: rep | |
71 | movsl | |
72 | movl %edx, %esi | |
1ad9da69 | 73 | cfi_restore (esi) |
3af48cbd | 74 | #ifndef USE_AS_BCOPY |
432a73f7 | 75 | movl DEST(%esp), %eax |
3af48cbd | 76 | #endif |
432a73f7 UD |
77 | |
78 | popl %edi | |
1ad9da69 UD |
79 | cfi_adjust_cfa_offset (-4) |
80 | cfi_restore (edi) | |
432a73f7 | 81 | |
2366713d | 82 | ret |
432a73f7 | 83 | |
fee732e5 UD |
84 | cfi_adjust_cfa_offset (4) |
85 | cfi_rel_offset (edi, 0) | |
86 | cfi_register (esi, edx) | |
87 | ||
432a73f7 UD |
88 | /* Backward copying. */ |
89 | 3: std | |
90 | leal -1(%edi, %ecx), %edi | |
91 | leal -1(%esi, %ecx), %esi | |
92 | shrl $1, %ecx | |
93 | jnc 1f | |
94 | movsb | |
95 | 1: subl $1, %edi | |
96 | subl $1, %esi | |
97 | shrl $1, %ecx | |
98 | jnc 2f | |
99 | movsw | |
100 | 2: subl $2, %edi | |
101 | subl $2, %esi | |
102 | rep | |
103 | movsl | |
104 | movl %edx, %esi | |
1ad9da69 | 105 | cfi_restore (esi) |
3af48cbd | 106 | #ifndef USE_AS_BCOPY |
432a73f7 | 107 | movl DEST(%esp), %eax |
3af48cbd | 108 | #endif |
432a73f7 UD |
109 | |
110 | cld | |
111 | popl %edi | |
1ad9da69 UD |
112 | cfi_adjust_cfa_offset (-4) |
113 | cfi_restore (edi) | |
432a73f7 | 114 | |
2366713d JM |
115 | ret |
116 | END (memmove) | |
3af48cbd | 117 | #ifndef USE_AS_BCOPY |
85dd1003 | 118 | libc_hidden_builtin_def (memmove) |
3af48cbd | 119 | #endif |