1;------------------------------------------------------------------------------ 2; 3; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR> 4; This program and the accompanying materials 5; are licensed and made available under the terms and conditions of the BSD License 6; which accompanies this distribution. The full text of the license may be found at 7; http://opensource.org/licenses/bsd-license.php. 8; 9; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11; 12; Module Name: 13; 14; IsZeroBuffer.nasm 15; 16; Abstract: 17; 18; IsZeroBuffer function 19; 20; Notes: 21; 22;------------------------------------------------------------------------------ 23 24 SECTION .text 25 26;------------------------------------------------------------------------------ 27; BOOLEAN 28; EFIAPI 29; InternalMemIsZeroBuffer ( 30; IN CONST VOID *Buffer, 31; IN UINTN Length 32; ); 33;------------------------------------------------------------------------------ 34global ASM_PFX(InternalMemIsZeroBuffer) 35ASM_PFX(InternalMemIsZeroBuffer): 36 push edi 37 mov edi, [esp + 8] ; edi <- Buffer 38 mov edx, [esp + 12] ; edx <- Length 39 xor ecx, ecx ; ecx <- 0 40 sub ecx, edi 41 and ecx, 15 ; ecx + edi aligns on 16-byte boundary 42 jz @Is16BytesZero 43 cmp ecx, edx 44 cmova ecx, edx ; bytes before the 16-byte boundary 45 sub edx, ecx 46 xor eax, eax ; eax <- 0, also set ZF 47 repe scasb 48 jnz @ReturnFalse ; ZF=0 means non-zero element found 49@Is16BytesZero: 50 mov ecx, edx 51 and edx, 15 52 shr ecx, 4 53 jz @IsBytesZero 54.0: 55 pxor xmm0, xmm0 ; xmm0 <- 0 56 pcmpeqb xmm0, [edi] ; check zero for 16 bytes 57 pmovmskb eax, xmm0 ; eax <- compare results 58 cmp eax, 0xffff 59 jnz @ReturnFalse 60 add edi, 16 61 loop .0 62@IsBytesZero: 63 mov ecx, edx 64 xor eax, eax ; eax <- 0, also set ZF 65 repe scasb 66 jnz @ReturnFalse ; ZF=0 means non-zero element found 67 pop edi 68 mov eax, 1 ; return TRUE 69 ret 70@ReturnFalse: 71 pop edi 72 xor eax, eax 73 ret ; return FALSE 74 75