]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibSse2/Ia32/IsZeroBuffer.nasm
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibSse2 / Ia32 / IsZeroBuffer.nasm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
5 ;
6 ; Module Name:
7 ;
8 ; IsZeroBuffer.nasm
9 ;
10 ; Abstract:
11 ;
12 ; IsZeroBuffer function
13 ;
14 ; Notes:
15 ;
16 ;------------------------------------------------------------------------------
17
18 SECTION .text
19
20 ;------------------------------------------------------------------------------
21 ; BOOLEAN
22 ; EFIAPI
23 ; InternalMemIsZeroBuffer (
24 ; IN CONST VOID *Buffer,
25 ; IN UINTN Length
26 ; );
27 ;------------------------------------------------------------------------------
28 global ASM_PFX(InternalMemIsZeroBuffer)
29 ASM_PFX(InternalMemIsZeroBuffer):
30 push edi
31 mov edi, [esp + 8] ; edi <- Buffer
32 mov edx, [esp + 12] ; edx <- Length
33 xor ecx, ecx ; ecx <- 0
34 sub ecx, edi
35 and ecx, 15 ; ecx + edi aligns on 16-byte boundary
36 jz @Is16BytesZero
37 cmp ecx, edx
38 cmova ecx, edx ; bytes before the 16-byte boundary
39 sub edx, ecx
40 xor eax, eax ; eax <- 0, also set ZF
41 repe scasb
42 jnz @ReturnFalse ; ZF=0 means non-zero element found
43 @Is16BytesZero:
44 mov ecx, edx
45 and edx, 15
46 shr ecx, 4
47 jz @IsBytesZero
48 .0:
49 pxor xmm0, xmm0 ; xmm0 <- 0
50 pcmpeqb xmm0, [edi] ; check zero for 16 bytes
51 pmovmskb eax, xmm0 ; eax <- compare results
52 cmp eax, 0xffff
53 jnz @ReturnFalse
54 add edi, 16
55 loop .0
56 @IsBytesZero:
57 mov ecx, edx
58 xor eax, eax ; eax <- 0, also set ZF
59 repe scasb
60 jnz @ReturnFalse ; ZF=0 means non-zero element found
61 pop edi
62 mov eax, 1 ; return TRUE
63 ret
64 @ReturnFalse:
65 pop edi
66 xor eax, eax
67 ret ; return FALSE
68