]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg BaseMemoryLib: Add assembly implementation of API IsZeroBuffer()
authorHao Wu <hao.a.wu@intel.com>
Wed, 17 Aug 2016 06:26:25 +0000 (14:26 +0800)
committerHao Wu <hao.a.wu@intel.com>
Mon, 22 Aug 2016 10:54:31 +0000 (18:54 +0800)
Add the implementation of API IsZeroBuffer() via assembly for the
following library instances:
BaseMemoryLibMmx
BaseMemoryLibOptDxe
BaseMemoryLibOptPei
BaseMemoryLibRepStr

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
20 files changed:
MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf
MdePkg/Library/BaseMemoryLibMmx/Ia32/IsZeroBuffer.nasm [new file with mode: 0644]
MdePkg/Library/BaseMemoryLibMmx/IsZeroBufferWrapper.c [new file with mode: 0644]
MdePkg/Library/BaseMemoryLibMmx/MemLibInternals.h
MdePkg/Library/BaseMemoryLibMmx/X64/IsZeroBuffer.nasm [new file with mode: 0644]
MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf
MdePkg/Library/BaseMemoryLibOptDxe/Ia32/IsZeroBuffer.nasm [new file with mode: 0644]
MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBufferWrapper.c [new file with mode: 0644]
MdePkg/Library/BaseMemoryLibOptDxe/MemLibInternals.h
MdePkg/Library/BaseMemoryLibOptDxe/X64/IsZeroBuffer.nasm [new file with mode: 0644]
MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf
MdePkg/Library/BaseMemoryLibOptPei/Ia32/IsZeroBuffer.nasm [new file with mode: 0644]
MdePkg/Library/BaseMemoryLibOptPei/IsZeroBufferWrapper.c [new file with mode: 0644]
MdePkg/Library/BaseMemoryLibOptPei/MemLibInternals.h
MdePkg/Library/BaseMemoryLibOptPei/X64/IsZeroBuffer.nasm [new file with mode: 0644]
MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf
MdePkg/Library/BaseMemoryLibRepStr/Ia32/IsZeroBuffer.nasm [new file with mode: 0644]
MdePkg/Library/BaseMemoryLibRepStr/IsZeroBufferWrapper.c [new file with mode: 0644]
MdePkg/Library/BaseMemoryLibRepStr/MemLibInternals.h
MdePkg/Library/BaseMemoryLibRepStr/X64/IsZeroBuffer.nasm [new file with mode: 0644]

index a609073fc43f1902dc2e3dcc5f91bcb2ad0a8474..af08b7d6d9bf8c315468ea843b953df36ecf00e8 100644 (file)
@@ -4,7 +4,7 @@
 #  Base Memory Library that uses MMX registers for high performance.\r
 #  Optimized for use in DXE.\r
 #\r
-#  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -46,6 +46,7 @@
   SetMem16Wrapper.c\r
   SetMemWrapper.c\r
   CopyMemWrapper.c\r
+  IsZeroBufferWrapper.c\r
   MemLibGuid.c\r
   MemLibInternals.h\r
 \r
@@ -94,6 +95,7 @@
   Ia32/SetMem.asm\r
   Ia32/CopyMem.nasm\r
   Ia32/CopyMem.asm\r
+  Ia32/IsZeroBuffer.nasm\r
 \r
 [Sources.X64]\r
   X64/ZeroMem.nasm\r
   X64/SetMem.S\r
   X64/CopyMem.nasm\r
   X64/CopyMem.S\r
+  X64/IsZeroBuffer.nasm\r
 \r
 \r
 [LibraryClasses]\r
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
diff --git a/MdePkg/Library/BaseMemoryLibMmx/IsZeroBufferWrapper.c b/MdePkg/Library/BaseMemoryLibMmx/IsZeroBufferWrapper.c
new file mode 100644 (file)
index 0000000..c42c1aa
--- /dev/null
@@ -0,0 +1,54 @@
+/** @file\r
+  Implementation of IsZeroBuffer function.\r
+\r
+  The following BaseMemoryLib instances contain the same copy of this file:\r
+\r
+    BaseMemoryLib\r
+    BaseMemoryLibMmx\r
+    BaseMemoryLibSse2\r
+    BaseMemoryLibRepStr\r
+    BaseMemoryLibOptDxe\r
+    BaseMemoryLibOptPei\r
+    PeiMemoryLib\r
+    UefiMemoryLib\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
+**/\r
+\r
+#include "MemLibInternals.h"\r
+\r
+/**\r
+  Checks if the contents of a buffer are all zeros.\r
+\r
+  This function checks whether the contents of a buffer are all zeros. If the\r
+  contents are all zeros, return TRUE. Otherwise, return FALSE.\r
+\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+\r
+  @param  Buffer      The pointer to the buffer to be checked.\r
+  @param  Length      The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE        Contents of the buffer are all zeros.\r
+  @retval FALSE       Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  )\r
+{\r
+  ASSERT (!(Buffer == NULL && Length > 0));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
+  return InternalMemIsZeroBuffer (Buffer, Length);\r
+}\r
index 38bb9751b7303dfd8052ce0d3a3f781a31375a48..cc8997963c212e965f4854a9f9171864e5036ca9 100644 (file)
@@ -9,7 +9,7 @@
     BaseMemoryLibOptDxe\r
     BaseMemoryLibOptPei\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 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
@@ -231,4 +231,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value\r
   );\r
 \r
+/**\r
+  Checks whether the contents of a buffer are all zeros.\r
+\r
+  @param  Buffer  The pointer to the buffer to be checked.\r
+  @param  Length  The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE    Contents of the buffer are all zeros.\r
+  @retval FALSE   Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalMemIsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  );\r
+\r
 #endif\r
diff --git a/MdePkg/Library/BaseMemoryLibMmx/X64/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibMmx/X64/IsZeroBuffer.nasm
new file mode 100644 (file)
index 0000000..00b1067
--- /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
+    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
+    mov     rcx, rdx                   ; rcx <- Length\r
+    shr     rcx, 3                     ; rcx <- number of qwords\r
+    and     rdx, 7                     ; rdx <- number of trailing bytes\r
+    xor     rax, rax                   ; rax <- 0, also set ZF\r
+    repe    scasq\r
+    jnz     @ReturnFalse               ; ZF=0 means non-zero element found\r
+    mov     rcx, rdx\r
+    repe    scasb\r
+    jnz     @ReturnFalse\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
index e6370344c4282fd205faacc09c65650f7bbbdc83..71691b9859e33cfc54f330dfbe124c3f2410c918 100644 (file)
@@ -4,7 +4,7 @@
 #  Base Memory Library that is optimized for use in DXE phase.  \r
 #  Uses REP, MMX, XMM registers as required for best performance.\r
 #\r
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -78,6 +78,7 @@
   Ia32/SetMem.asm\r
   Ia32/CopyMem.nasm\r
   Ia32/CopyMem.asm\r
+  Ia32/IsZeroBuffer.nasm\r
   ScanMem64Wrapper.c\r
   ScanMem32Wrapper.c\r
   ScanMem16Wrapper.c\r
@@ -89,6 +90,7 @@
   SetMem16Wrapper.c\r
   SetMemWrapper.c\r
   CopyMemWrapper.c\r
+  IsZeroBufferWrapper.c\r
   MemLibGuid.c\r
 \r
 [Sources.X64]\r
   X64/CopyMem.nasm\r
   X64/CopyMem.asm\r
   X64/CopyMem.S\r
+  X64/IsZeroBuffer.nasm\r
   ScanMem64Wrapper.c\r
   ScanMem32Wrapper.c\r
   ScanMem16Wrapper.c\r
   SetMem16Wrapper.c\r
   SetMemWrapper.c\r
   CopyMemWrapper.c\r
+  IsZeroBufferWrapper.c\r
   MemLibGuid.c\r
 \r
 [Packages]\r
diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/Ia32/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibOptDxe/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
diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBufferWrapper.c b/MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBufferWrapper.c
new file mode 100644 (file)
index 0000000..c42c1aa
--- /dev/null
@@ -0,0 +1,54 @@
+/** @file\r
+  Implementation of IsZeroBuffer function.\r
+\r
+  The following BaseMemoryLib instances contain the same copy of this file:\r
+\r
+    BaseMemoryLib\r
+    BaseMemoryLibMmx\r
+    BaseMemoryLibSse2\r
+    BaseMemoryLibRepStr\r
+    BaseMemoryLibOptDxe\r
+    BaseMemoryLibOptPei\r
+    PeiMemoryLib\r
+    UefiMemoryLib\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
+**/\r
+\r
+#include "MemLibInternals.h"\r
+\r
+/**\r
+  Checks if the contents of a buffer are all zeros.\r
+\r
+  This function checks whether the contents of a buffer are all zeros. If the\r
+  contents are all zeros, return TRUE. Otherwise, return FALSE.\r
+\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+\r
+  @param  Buffer      The pointer to the buffer to be checked.\r
+  @param  Length      The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE        Contents of the buffer are all zeros.\r
+  @retval FALSE       Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  )\r
+{\r
+  ASSERT (!(Buffer == NULL && Length > 0));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
+  return InternalMemIsZeroBuffer (Buffer, Length);\r
+}\r
index b15e3c1706717fe740416064034f0cd40cfec8c1..7d310bb625b6a2f4f36d23bc3eaf30cb3c0dc98b 100644 (file)
@@ -9,7 +9,7 @@
     BaseMemoryLibOptDxe\r
     BaseMemoryLibOptPei\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 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
@@ -231,4 +231,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value\r
   );\r
 \r
+/**\r
+  Checks whether the contents of a buffer are all zeros.\r
+\r
+  @param  Buffer  The pointer to the buffer to be checked.\r
+  @param  Length  The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE    Contents of the buffer are all zeros.\r
+  @retval FALSE   Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalMemIsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  );\r
+\r
 #endif\r
diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/X64/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibOptDxe/X64/IsZeroBuffer.nasm
new file mode 100644 (file)
index 0000000..00b1067
--- /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
+    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
+    mov     rcx, rdx                   ; rcx <- Length\r
+    shr     rcx, 3                     ; rcx <- number of qwords\r
+    and     rdx, 7                     ; rdx <- number of trailing bytes\r
+    xor     rax, rax                   ; rax <- 0, also set ZF\r
+    repe    scasq\r
+    jnz     @ReturnFalse               ; ZF=0 means non-zero element found\r
+    mov     rcx, rdx\r
+    repe    scasb\r
+    jnz     @ReturnFalse\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
index ff60e9ed1c35083295825c7556e3fdc23add7d72..21f060ebcf67d0d14f1356cf3fd64c0ecd52cf24 100644 (file)
@@ -4,7 +4,7 @@
 #  Base Memory Library that is optimized for use in PEI phase.  \r
 #  Uses REP, MMX, XMM registers as required for best performance.\r
 #\r
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -78,6 +78,7 @@
   Ia32/SetMem.asm\r
   Ia32/CopyMem.nasm\r
   Ia32/CopyMem.asm\r
+  Ia32/IsZeroBuffer.nasm\r
   ScanMem64Wrapper.c\r
   ScanMem32Wrapper.c\r
   ScanMem16Wrapper.c\r
@@ -89,6 +90,7 @@
   SetMem16Wrapper.c\r
   SetMemWrapper.c\r
   CopyMemWrapper.c\r
+  IsZeroBufferWrapper.c\r
   MemLibGuid.c\r
 \r
 [Sources.X64]\r
   X64/CopyMem.nasm\r
   X64/CopyMem.asm\r
   X64/CopyMem.S\r
+  X64/IsZeroBuffer.nasm\r
   ScanMem64Wrapper.c\r
   ScanMem32Wrapper.c\r
   ScanMem16Wrapper.c\r
   SetMem16Wrapper.c\r
   SetMemWrapper.c\r
   CopyMemWrapper.c\r
+  IsZeroBufferWrapper.c\r
   MemLibGuid.c\r
 \r
 \r
diff --git a/MdePkg/Library/BaseMemoryLibOptPei/Ia32/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibOptPei/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
diff --git a/MdePkg/Library/BaseMemoryLibOptPei/IsZeroBufferWrapper.c b/MdePkg/Library/BaseMemoryLibOptPei/IsZeroBufferWrapper.c
new file mode 100644 (file)
index 0000000..c42c1aa
--- /dev/null
@@ -0,0 +1,54 @@
+/** @file\r
+  Implementation of IsZeroBuffer function.\r
+\r
+  The following BaseMemoryLib instances contain the same copy of this file:\r
+\r
+    BaseMemoryLib\r
+    BaseMemoryLibMmx\r
+    BaseMemoryLibSse2\r
+    BaseMemoryLibRepStr\r
+    BaseMemoryLibOptDxe\r
+    BaseMemoryLibOptPei\r
+    PeiMemoryLib\r
+    UefiMemoryLib\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
+**/\r
+\r
+#include "MemLibInternals.h"\r
+\r
+/**\r
+  Checks if the contents of a buffer are all zeros.\r
+\r
+  This function checks whether the contents of a buffer are all zeros. If the\r
+  contents are all zeros, return TRUE. Otherwise, return FALSE.\r
+\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+\r
+  @param  Buffer      The pointer to the buffer to be checked.\r
+  @param  Length      The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE        Contents of the buffer are all zeros.\r
+  @retval FALSE       Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  )\r
+{\r
+  ASSERT (!(Buffer == NULL && Length > 0));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
+  return InternalMemIsZeroBuffer (Buffer, Length);\r
+}\r
index 34eff54bfb6c357d539102c7b931f1d5fe17b29a..72a51f30d99b3e596fcbf3df1af757d0a6a3d4dc 100644 (file)
@@ -9,7 +9,7 @@
     BaseMemoryLibOptDxe\r
     BaseMemoryLibOptPei\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 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
@@ -231,4 +231,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value\r
   );\r
 \r
+/**\r
+  Checks whether the contents of a buffer are all zeros.\r
+\r
+  @param  Buffer  The pointer to the buffer to be checked.\r
+  @param  Length  The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE    Contents of the buffer are all zeros.\r
+  @retval FALSE   Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalMemIsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  );\r
+\r
 #endif\r
diff --git a/MdePkg/Library/BaseMemoryLibOptPei/X64/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibOptPei/X64/IsZeroBuffer.nasm
new file mode 100644 (file)
index 0000000..00b1067
--- /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
+    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
+    mov     rcx, rdx                   ; rcx <- Length\r
+    shr     rcx, 3                     ; rcx <- number of qwords\r
+    and     rdx, 7                     ; rdx <- number of trailing bytes\r
+    xor     rax, rax                   ; rax <- 0, also set ZF\r
+    repe    scasq\r
+    jnz     @ReturnFalse               ; ZF=0 means non-zero element found\r
+    mov     rcx, rdx\r
+    repe    scasb\r
+    jnz     @ReturnFalse\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
index 9d7ce4b1fe61e008606b67fc0e810e0547a69d9c..729e26a492c359b3f7ca409ae47a9b918074aa3d 100644 (file)
@@ -4,7 +4,7 @@
 #  Base Memory Library that uses REP string instructions for\r
 #  high performance and small size. Optimized for use in PEI.\r
 #\r
-#  Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -43,6 +43,7 @@
   SetMem16Wrapper.c\r
   SetMemWrapper.c\r
   CopyMemWrapper.c\r
+  IsZeroBufferWrapper.c\r
   MemLibGuid.c\r
 \r
 [Sources.Ia32]\r
@@ -90,6 +91,7 @@
   Ia32/SetMem.asm\r
   Ia32/CopyMem.nasm\r
   Ia32/CopyMem.asm\r
+  Ia32/IsZeroBuffer.nasm\r
 \r
 [Sources.X64]\r
   X64/ScanMem64.nasm\r
   X64/SetMem.asm\r
   X64/CopyMem.nasm\r
   X64/CopyMem.asm\r
+  X64/IsZeroBuffer.nasm\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
diff --git a/MdePkg/Library/BaseMemoryLibRepStr/Ia32/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibRepStr/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
diff --git a/MdePkg/Library/BaseMemoryLibRepStr/IsZeroBufferWrapper.c b/MdePkg/Library/BaseMemoryLibRepStr/IsZeroBufferWrapper.c
new file mode 100644 (file)
index 0000000..c42c1aa
--- /dev/null
@@ -0,0 +1,54 @@
+/** @file\r
+  Implementation of IsZeroBuffer function.\r
+\r
+  The following BaseMemoryLib instances contain the same copy of this file:\r
+\r
+    BaseMemoryLib\r
+    BaseMemoryLibMmx\r
+    BaseMemoryLibSse2\r
+    BaseMemoryLibRepStr\r
+    BaseMemoryLibOptDxe\r
+    BaseMemoryLibOptPei\r
+    PeiMemoryLib\r
+    UefiMemoryLib\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
+**/\r
+\r
+#include "MemLibInternals.h"\r
+\r
+/**\r
+  Checks if the contents of a buffer are all zeros.\r
+\r
+  This function checks whether the contents of a buffer are all zeros. If the\r
+  contents are all zeros, return TRUE. Otherwise, return FALSE.\r
+\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+\r
+  @param  Buffer      The pointer to the buffer to be checked.\r
+  @param  Length      The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE        Contents of the buffer are all zeros.\r
+  @retval FALSE       Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  )\r
+{\r
+  ASSERT (!(Buffer == NULL && Length > 0));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
+  return InternalMemIsZeroBuffer (Buffer, Length);\r
+}\r
index cfca47416e07b0f2e44cd24f4e3ece562419b8e1..f795e83a2a2c816bf528adbede79113cd8bcba28 100644 (file)
@@ -9,7 +9,7 @@
     BaseMemoryLibOptDxe\r
     BaseMemoryLibOptPei\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 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
@@ -231,4 +231,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value\r
   );\r
 \r
+/**\r
+  Checks whether the contents of a buffer are all zeros.\r
+\r
+  @param  Buffer  The pointer to the buffer to be checked.\r
+  @param  Length  The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE    Contents of the buffer are all zeros.\r
+  @retval FALSE   Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalMemIsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  );\r
+\r
 #endif\r
diff --git a/MdePkg/Library/BaseMemoryLibRepStr/X64/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibRepStr/X64/IsZeroBuffer.nasm
new file mode 100644 (file)
index 0000000..00b1067
--- /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
+    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
+    mov     rcx, rdx                   ; rcx <- Length\r
+    shr     rcx, 3                     ; rcx <- number of qwords\r
+    and     rdx, 7                     ; rdx <- number of trailing bytes\r
+    xor     rax, rax                   ; rax <- 0, also set ZF\r
+    repe    scasq\r
+    jnz     @ReturnFalse               ; ZF=0 means non-zero element found\r
+    mov     rcx, rdx\r
+    repe    scasb\r
+    jnz     @ReturnFalse\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