]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseMemoryLibMmx/Ia32/IsZeroBuffer.nasm
MdePkg BaseMemoryLib: Add assembly implementation of API IsZeroBuffer()
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibMmx / Ia32 / IsZeroBuffer.nasm
diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibMmx/Ia32/IsZeroBuffer.nasm
new file mode 100644 (file)
index 0000000..a2e56a1
--- /dev/null
@@ -0,0 +1,55 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+; This program and the accompanying materials\r
+; are licensed and made available under the terms and conditions of the BSD License\r
+; which accompanies this distribution.  The full text of the license may be found at\r
+; http://opensource.org/licenses/bsd-license.php.\r
+;\r
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;\r
+; Module Name:\r
+;\r
+;   IsZeroBuffer.nasm\r
+;\r
+; Abstract:\r
+;\r
+;   IsZeroBuffer function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+    SECTION .text\r
+\r
+;------------------------------------------------------------------------------\r
+;  BOOLEAN\r
+;  EFIAPI\r
+;  InternalMemIsZeroBuffer (\r
+;    IN CONST VOID  *Buffer,\r
+;    IN UINTN       Length\r
+;    );\r
+;------------------------------------------------------------------------------\r
+global ASM_PFX(InternalMemIsZeroBuffer)\r
+ASM_PFX(InternalMemIsZeroBuffer):\r
+    push    edi\r
+    mov     edi, [esp + 8]             ; edi <- Buffer\r
+    mov     ecx, [esp + 12]            ; ecx <- Length\r
+    mov     edx, ecx                   ; edx <- ecx\r
+    shr     ecx, 2                     ; ecx <- number of dwords\r
+    and     edx, 3                     ; edx <- number of trailing bytes\r
+    xor     eax, eax                   ; eax <- 0, also set ZF\r
+    repe    scasd\r
+    jnz     @ReturnFalse               ; ZF=0 means non-zero element found\r
+    mov     ecx, edx\r
+    repe    scasb\r
+    jnz     @ReturnFalse\r
+    pop     edi\r
+    mov     eax, 1                     ; return TRUE\r
+    ret\r
+@ReturnFalse:\r
+    pop     edi\r
+    xor     eax, eax\r
+    ret                                ; return FALSE\r
+\r