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. 4 Copyright (C) 2003-2021 Free Software Foundation, Inc. 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 17 License along with the GNU C Library; if not, see 18 <https://www.gnu.org/licenses/>. */ 19 20#include <sysdep.h> 21#include "asm-syntax.h" 22 23#define PARMS 4+4 /* one spilled register */ 24#define RTN PARMS 25 26 .text 27 28#ifdef USE_AS_BCOPY 29# define SRC RTN 30# define DEST SRC+4 31# define LEN DEST+4 32#else 33# define DEST RTN 34# define SRC DEST+4 35# define LEN SRC+4 36 37# if defined PIC && IS_IN (libc) 38ENTRY_CHK (__memmove_chk) 39 movl 12(%esp), %eax 40 cmpl %eax, 16(%esp) 41 jb HIDDEN_JUMPTARGET (__chk_fail) 42END_CHK (__memmove_chk) 43# endif 44#endif 45 46ENTRY (memmove) 47 48 pushl %edi 49 cfi_adjust_cfa_offset (4) 50 51 movl LEN(%esp), %ecx 52 movl DEST(%esp), %edi 53 cfi_rel_offset (edi, 0) 54 movl %esi, %edx 55 movl SRC(%esp), %esi 56 cfi_register (esi, edx) 57 58 movl %edi, %eax 59 subl %esi, %eax 60 cmpl %eax, %ecx 61 ja 3f 62 63 cld 64 shrl $1, %ecx 65 jnc 1f 66 movsb 671: shrl $1, %ecx 68 jnc 2f 69 movsw 702: rep 71 movsl 72 movl %edx, %esi 73 cfi_restore (esi) 74#ifndef USE_AS_BCOPY 75 movl DEST(%esp), %eax 76#endif 77 78 popl %edi 79 cfi_adjust_cfa_offset (-4) 80 cfi_restore (edi) 81 82 ret 83 84 cfi_adjust_cfa_offset (4) 85 cfi_rel_offset (edi, 0) 86 cfi_register (esi, edx) 87 88 /* Backward copying. */ 893: std 90 leal -1(%edi, %ecx), %edi 91 leal -1(%esi, %ecx), %esi 92 shrl $1, %ecx 93 jnc 1f 94 movsb 951: subl $1, %edi 96 subl $1, %esi 97 shrl $1, %ecx 98 jnc 2f 99 movsw 1002: subl $2, %edi 101 subl $2, %esi 102 rep 103 movsl 104 movl %edx, %esi 105 cfi_restore (esi) 106#ifndef USE_AS_BCOPY 107 movl DEST(%esp), %eax 108#endif 109 110 cld 111 popl %edi 112 cfi_adjust_cfa_offset (-4) 113 cfi_restore (edi) 114 115 ret 116END (memmove) 117#ifndef USE_AS_BCOPY 118libc_hidden_builtin_def (memmove) 119#endif 120