]>
Commit | Line | Data |
---|---|---|
1 | ;------------------------------------------------------------------------------\r | |
2 | ;\r | |
3 | ; Copyright (c) 2006, Intel Corporation\r | |
4 | ; All rights reserved. This program and the accompanying materials\r | |
5 | ; are licensed and made available under the terms and conditions of the BSD License\r | |
6 | ; which accompanies this distribution. The full text of the license may be found at\r | |
7 | ; http://opensource.org/licenses/bsd-license.php\r | |
8 | ;\r | |
9 | ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | ;\r | |
12 | ; Module Name:\r | |
13 | ;\r | |
14 | ; CopyMem.asm\r | |
15 | ;\r | |
16 | ; Abstract:\r | |
17 | ;\r | |
18 | ; CopyMem function\r | |
19 | ;\r | |
20 | ; Notes:\r | |
21 | ;\r | |
22 | ;------------------------------------------------------------------------------\r | |
23 | \r | |
24 | .686\r | |
25 | .model flat,C\r | |
26 | .xmm\r | |
27 | .code\r | |
28 | \r | |
29 | ;------------------------------------------------------------------------------\r | |
30 | ; VOID *\r | |
31 | ; InternalMemCopyMem (\r | |
32 | ; IN VOID *Destination,\r | |
33 | ; IN VOID *Source,\r | |
34 | ; IN UINTN Count\r | |
35 | ; );\r | |
36 | ;------------------------------------------------------------------------------\r | |
37 | InternalMemCopyMem PROC USES esi edi\r | |
38 | mov esi, [esp + 16] ; esi <- Source\r | |
39 | mov edi, [esp + 12] ; edi <- Destination\r | |
40 | mov edx, [esp + 20] ; edx <- Count\r | |
41 | lea eax, [esi + edx - 1] ; eax <- End of Source\r | |
42 | cmp esi, edi\r | |
43 | jae @F\r | |
44 | cmp eax, edi ; Overlapped?\r | |
45 | jae @CopyBackward ; Copy backward if overlapped\r | |
46 | @@:\r | |
47 | xor ecx, ecx\r | |
48 | sub ecx, edi\r | |
49 | and ecx, 15 ; ecx + edi aligns on 16-byte boundary\r | |
50 | jz @F\r | |
51 | cmp ecx, edx\r | |
52 | cmova ecx, edx\r | |
53 | sub edx, ecx ; edx <- remaining bytes to copy\r | |
54 | rep movsb\r | |
55 | @@:\r | |
56 | mov ecx, edx\r | |
57 | and edx, 15\r | |
58 | shr ecx, 4 ; ecx <- # of DQwords to copy\r | |
59 | jz @CopyBytes\r | |
60 | add esp, -16\r | |
61 | movdqu [esp], xmm0 ; save xmm0\r | |
62 | @@:\r | |
63 | movdqu xmm0, [esi] ; esi may not be 16-bytes aligned\r | |
64 | movntdq [edi], xmm0 ; edi should be 16-bytes aligned\r | |
65 | add esi, 16\r | |
66 | add edi, 16\r | |
67 | loop @B\r | |
68 | mfence\r | |
69 | movdqu xmm0, [esp] ; restore xmm0\r | |
70 | add esp, 16 ; stack cleanup\r | |
71 | jmp @CopyBytes\r | |
72 | @CopyBackward:\r | |
73 | mov esi, eax ; esi <- Last byte in Source\r | |
74 | lea edi, [edi + edx - 1] ; edi <- Last byte in Destination\r | |
75 | std\r | |
76 | @CopyBytes:\r | |
77 | mov ecx, edx\r | |
78 | rep movsb\r | |
79 | cld\r | |
80 | mov eax, [esp + 12] ; eax <- Destination as return value\r | |
81 | ret\r | |
82 | InternalMemCopyMem ENDP\r | |
83 | \r | |
84 | END\r |