]>
Commit | Line | Data |
---|---|---|
102b4c7c HW |
1 | ;------------------------------------------------------------------------------\r |
2 | ;\r | |
3 | ; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r | |
9344f092 | 4 | ; SPDX-License-Identifier: BSD-2-Clause-Patent\r |
102b4c7c HW |
5 | ;\r |
6 | ; Module Name:\r | |
7 | ;\r | |
8 | ; IsZeroBuffer.nasm\r | |
9 | ;\r | |
10 | ; Abstract:\r | |
11 | ;\r | |
12 | ; IsZeroBuffer function\r | |
13 | ;\r | |
14 | ; Notes:\r | |
15 | ;\r | |
16 | ;------------------------------------------------------------------------------\r | |
17 | \r | |
18 | DEFAULT REL\r | |
19 | SECTION .text\r | |
20 | \r | |
21 | ;------------------------------------------------------------------------------\r | |
22 | ; BOOLEAN\r | |
23 | ; EFIAPI\r | |
24 | ; InternalMemIsZeroBuffer (\r | |
25 | ; IN CONST VOID *Buffer,\r | |
26 | ; IN UINTN Length\r | |
27 | ; );\r | |
28 | ;------------------------------------------------------------------------------\r | |
29 | global ASM_PFX(InternalMemIsZeroBuffer)\r | |
30 | ASM_PFX(InternalMemIsZeroBuffer):\r | |
31 | push rdi\r | |
32 | mov rdi, rcx ; rdi <- Buffer\r | |
33 | xor rcx, rcx ; rcx <- 0\r | |
34 | sub rcx, rdi\r | |
35 | and rcx, 15 ; rcx + rdi aligns on 16-byte boundary\r | |
36 | jz @Is16BytesZero\r | |
37 | cmp rcx, rdx ; Length already in rdx\r | |
38 | cmova rcx, rdx ; bytes before the 16-byte boundary\r | |
39 | sub rdx, rcx\r | |
40 | xor rax, rax ; rax <- 0, also set ZF\r | |
41 | repe scasb\r | |
42 | jnz @ReturnFalse ; ZF=0 means non-zero element found\r | |
43 | @Is16BytesZero:\r | |
44 | mov rcx, rdx\r | |
45 | and rdx, 15\r | |
46 | shr rcx, 4\r | |
47 | jz @IsBytesZero\r | |
48 | .0:\r | |
49 | pxor xmm0, xmm0 ; xmm0 <- 0\r | |
50 | pcmpeqb xmm0, [rdi] ; check zero for 16 bytes\r | |
51 | pmovmskb eax, xmm0 ; eax <- compare results\r | |
52 | ; nasm doesn't support 64-bit destination\r | |
53 | ; for pmovmskb\r | |
54 | cmp eax, 0xffff\r | |
55 | jnz @ReturnFalse\r | |
56 | add rdi, 16\r | |
57 | loop .0\r | |
58 | @IsBytesZero:\r | |
59 | mov rcx, rdx\r | |
60 | xor rax, rax ; rax <- 0, also set ZF\r | |
61 | repe scasb\r | |
62 | jnz @ReturnFalse ; ZF=0 means non-zero element found\r | |
63 | pop rdi\r | |
64 | mov rax, 1 ; return TRUE\r | |
65 | ret\r | |
66 | @ReturnFalse:\r | |
67 | pop rdi\r | |
68 | xor rax, rax\r | |
69 | ret ; return FALSE\r | |
70 | \r |