]>
Commit | Line | Data |
---|---|---|
3eb9473e | 1 | /*++\r |
2 | \r | |
4ea9375a HT |
3 | Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r |
4 | This program and the accompanying materials \r | |
3eb9473e | 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 | EfiZeroMemSSE2.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | This is the code that supports IA32-optimized ZeroMem service\r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
22 | #include "Tiano.h"\r | |
23 | \r | |
24 | VOID\r | |
25 | EfiCommonLibZeroMem (\r | |
26 | IN VOID *Buffer,\r | |
27 | IN UINTN Count\r | |
28 | )\r | |
29 | /*++\r | |
30 | \r | |
31 | Input: VOID *Buffer - Pointer to buffer to clear\r | |
32 | UINTN Count - Number of bytes to clear\r | |
33 | \r | |
34 | Output: None.\r | |
35 | \r | |
36 | Saves:\r | |
37 | \r | |
38 | Modifies:\r | |
39 | \r | |
40 | Description: This function is an optimized zero-memory function.\r | |
41 | \r | |
42 | Notes: This function tries to zero memory 8 bytes at a time. As a result, \r | |
43 | it first picks up any misaligned bytes, then words, before getting \r | |
44 | in the main loop that does the 8-byte clears.\r | |
45 | \r | |
46 | --*/\r | |
47 | {\r | |
48 | __asm {\r | |
49 | mov ecx, Count\r | |
50 | mov edi, Buffer\r | |
51 | \r | |
52 | ; Pick up misaligned start bytes (get pointer 4-byte aligned)\r | |
53 | _StartByteZero:\r | |
54 | mov eax, edi \r | |
55 | and al, 3 ; check lower 2 bits of address\r | |
56 | test al, al\r | |
57 | je _ZeroBlocks ; already aligned?\r | |
58 | cmp ecx, 0\r | |
59 | je _ZeroMemDone\r | |
60 | \r | |
61 | ; Clear the byte memory location\r | |
62 | mov BYTE PTR [edi], 0 \r | |
63 | inc edi\r | |
64 | \r | |
65 | ; Decrement our count\r | |
66 | dec ecx\r | |
67 | jmp _StartByteZero ; back to top of loop\r | |
68 | \r | |
69 | _ZeroBlocks:\r | |
70 | \r | |
71 | ; Compute how many 64-byte blocks we can clear \r | |
72 | mov edx, ecx\r | |
73 | shr ecx, 6 ; convert to 64-byte count\r | |
74 | shl ecx, 6 ; convert back to bytes\r | |
75 | sub edx, ecx ; subtract from the original count\r | |
76 | shr ecx, 6 ; and this is how many 64-byte blocks\r | |
77 | \r | |
78 | ; If no 64-byte blocks, then skip \r | |
79 | cmp ecx, 0\r | |
80 | je _ZeroRemaining\r | |
81 | \r | |
82 | xorps xmm1, xmm1\r | |
83 | \r | |
84 | _B:\r | |
85 | movdqu OWORD PTR ds:[edi], xmm1\r | |
86 | movdqu OWORD PTR ds:[edi+16], xmm1\r | |
87 | movdqu OWORD PTR ds:[edi+32], xmm1\r | |
88 | movdqu OWORD PTR ds:[edi+48], xmm1\r | |
89 | \r | |
90 | add edi, 64\r | |
91 | dec ecx\r | |
92 | jnz _B\r | |
93 | \r | |
94 | \r | |
95 | _ZeroRemaining:\r | |
96 | ; Zero out as many DWORDS as possible\r | |
97 | mov ecx, edx\r | |
98 | shr ecx, 2\r | |
99 | xor eax, eax\r | |
100 | \r | |
101 | rep stosd\r | |
102 | \r | |
103 | ; Zero out remaining as bytes\r | |
104 | mov ecx, edx\r | |
105 | and ecx, 03\r | |
106 | \r | |
107 | rep stosb\r | |
108 | \r | |
109 | _ZeroMemDone:\r | |
110 | }\r | |
111 | }\r |