+;------------------------------------------------------------------------------\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
+ DEFAULT REL\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 rdi\r
+ mov rdi, rcx ; rdi <- Buffer\r
+ xor rcx, rcx ; rcx <- 0\r
+ sub rcx, rdi\r
+ and rcx, 15 ; rcx + rdi aligns on 16-byte boundary\r
+ jz @Is16BytesZero\r
+ cmp rcx, rdx ; Length already in rdx\r
+ cmova rcx, rdx ; bytes before the 16-byte boundary\r
+ sub rdx, rcx\r
+ xor rax, rax ; rax <- 0, also set ZF\r
+ repe scasb\r
+ jnz @ReturnFalse ; ZF=0 means non-zero element found\r
+@Is16BytesZero:\r
+ mov rcx, rdx\r
+ and rdx, 15\r
+ shr rcx, 4\r
+ jz @IsBytesZero\r
+.0:\r
+ pxor xmm0, xmm0 ; xmm0 <- 0\r
+ pcmpeqb xmm0, [rdi] ; check zero for 16 bytes\r
+ pmovmskb eax, xmm0 ; eax <- compare results\r
+ ; nasm doesn't support 64-bit destination\r
+ ; for pmovmskb\r
+ cmp eax, 0xffff\r
+ jnz @ReturnFalse\r
+ add rdi, 16\r
+ loop .0\r
+@IsBytesZero:\r
+ mov rcx, rdx\r
+ xor rax, rax ; rax <- 0, also set ZF\r
+ repe scasb\r
+ jnz @ReturnFalse ; ZF=0 means non-zero element found\r
+ pop rdi\r
+ mov rax, 1 ; return TRUE\r
+ ret\r
+@ReturnFalse:\r
+ pop rdi\r
+ xor rax, rax\r
+ ret ; return FALSE\r
+\r