VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/string/memmove.asm@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 3.8 KB
Line 
1; $Id: memmove.asm 96407 2022-08-22 17:43:14Z vboxsync $
2;; @file
3; IPRT - No-CRT memmove - AMD64 & X86.
4;
5
6;
7; Copyright (C) 2006-2022 Oracle and/or its affiliates.
8;
9; This file is part of VirtualBox base platform packages, as
10; available from https://www.virtualbox.org.
11;
12; This program is free software; you can redistribute it and/or
13; modify it under the terms of the GNU General Public License
14; as published by the Free Software Foundation, in version 3 of the
15; License.
16;
17; This program is distributed in the hope that it will be useful, but
18; WITHOUT ANY WARRANTY; without even the implied warranty of
19; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20; General Public License for more details.
21;
22; You should have received a copy of the GNU General Public License
23; along with this program; if not, see <https://www.gnu.org/licenses>.
24;
25; The contents of this file may alternatively be used under the terms
26; of the Common Development and Distribution License Version 1.0
27; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28; in the VirtualBox distribution, in which case the provisions of the
29; CDDL are applicable instead of those of the GPL.
30;
31; You may elect to license modified versions of this file under the
32; terms and conditions of either the GPL or the CDDL or both.
33;
34; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35;
36
37%include "iprt/asmdefs.mac"
38
39BEGINCODE
40
41;;
42; @param pvDst gcc: rdi msc: rcx x86:[esp+4] wcall: eax
43; @param pvSrc gcc: rsi msc: rdx x86:[esp+8] wcall: edx
44; @param cb gcc: rdx msc: r8 x86:[esp+0ch] wcall: ebx
45RT_NOCRT_BEGINPROC memmove
46 ; Prolog.
47%ifdef RT_ARCH_AMD64
48 %ifdef ASM_CALL64_MSC
49 mov r10, rdi ; save
50 mov r11, rsi ; save
51 mov rdi, rcx
52 mov rsi, rdx
53 mov rcx, r8
54 mov rdx, r8
55 %else
56 mov rcx, rdx
57 %endif
58 mov rax, rdi ; save the return value
59%else
60 push edi
61 push esi
62 %ifdef ASM_CALL32_WATCOM
63 mov edi, eax
64 mov esi, edx
65 mov ecx, ebx
66 mov edx, ebx
67 %else
68 mov edi, [esp + 04h + 8]
69 mov esi, [esp + 08h + 8]
70 mov ecx, [esp + 0ch + 8]
71 mov edx, ecx
72 mov eax, edi ; save the return value
73 %endif
74%endif
75
76 ;
77 ; Decide which direction to perform the copy in.
78 ;
79%if 1 ; keep it simple for now.
80 cmp xDI, xSI
81 jnb .backward
82
83 ;
84 ; Slow/simple forward copy.
85 ;
86 cld
87 rep movsb
88 jmp .epilog
89
90%else ; disabled - it seems to work, but play safe for now.
91 ;sub xAX, xSI
92 ;jnb .backward
93 cmp xDI, xSI
94 jnb .backward
95
96 ;
97 ; Fast forward copy.
98 ;
99.fast_forward:
100 cld
101%ifdef RT_ARCH_AMD64
102 shr rcx, 3
103 rep movsq
104%else
105 shr ecx, 2
106 rep movsd
107%endif
108
109 ; The remaining bytes.
110%ifdef RT_ARCH_AMD64
111 test dl, 4
112 jz .forward_dont_move_dword
113 movsd
114%endif
115.forward_dont_move_dword:
116 test dl, 2
117 jz .forward_dont_move_word
118 movsw
119.forward_dont_move_word:
120 test dl, 1
121 jz .forward_dont_move_byte
122 movsb
123.forward_dont_move_byte:
124
125%endif ; disabled
126
127 ;
128 ; The epilog.
129 ;
130.epilog:
131%ifdef RT_ARCH_AMD64
132 %ifdef ASM_CALL64_MSC
133 mov rdi, r10
134 mov rsi, r11
135 %endif
136%else
137 pop esi
138 pop edi
139%endif
140 ret
141
142 ;
143 ; Slow/simple backward copy.
144 ;
145ALIGNCODE(16)
146.backward:
147 ;; @todo check if they overlap.
148 lea xDI, [xDI + xCX - 1]
149 lea xSI, [xSI + xCX - 1]
150 std
151 rep movsb
152 cld
153 jmp .epilog
154ENDPROC RT_NOCRT(memmove)
155
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette