public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib
@ 2016-08-18  4:53 Hao Wu
  2016-08-18  4:53 ` [PATCH v2 1/6] MdePkg BaseMemoryLib: Add implementation of API IsZeroGuid() Hao Wu
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Hao Wu @ 2016-08-18  4:53 UTC (permalink / raw)
  To: edk2-devel, liming.gao; +Cc: Hao Wu

Changes made comparing V1:
1. Use assembly to implement the IsZeroBuffer() API for the following
library instances:
BaseMemoryLibMmx
BaseMemoryLibOptDxe
BaseMemoryLibOptPei
BaseMemoryLibRepStr
BaseMemoryLibSse2

2. Utilize XMM regesters and related instructions in assembly codes for
BaseMemoryLibSse2 library instance.

3. Modify patches for SecurityPkg to avoid breaking bisection between
patches.

Hao Wu (6):
  MdePkg BaseMemoryLib: Add implementation of API IsZeroGuid()
  SecurityPkg Tcg2: Rename internal API IsZeroBuffer to
    InternalIsZeroBuffer
  MdePkg BaseMemoryLib: Add C implementation of API IsZeroBuffer()
  MdePkg BaseMemoryLib: Add assembly implementation of API
    IsZeroBuffer()
  MdePkg BaseMemoryLibSse2: Add SSE2 implementation of API
    IsZeroBuffer()
  SecurityPkg Tcg2: Remove use of module internal API
    InternalIsZeroBuffer()

 MdePkg/Include/Library/BaseMemoryLib.h             | 45 ++++++++++++-
 MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf     |  3 +-
 MdePkg/Library/BaseMemoryLib/IsZeroBufferWrapper.c | 54 +++++++++++++++
 MdePkg/Library/BaseMemoryLib/MemLibGeneric.c       | 31 ++++++++-
 MdePkg/Library/BaseMemoryLib/MemLibGuid.c          | 31 ++++++++-
 MdePkg/Library/BaseMemoryLib/MemLibInternals.h     | 19 +++++-
 .../Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf  |  5 +-
 .../BaseMemoryLibMmx/Ia32/IsZeroBuffer.nasm        | 55 ++++++++++++++++
 .../Library/BaseMemoryLibMmx/IsZeroBufferWrapper.c | 54 +++++++++++++++
 MdePkg/Library/BaseMemoryLibMmx/MemLibGuid.c       | 31 ++++++++-
 MdePkg/Library/BaseMemoryLibMmx/MemLibInternals.h  | 19 +++++-
 .../Library/BaseMemoryLibMmx/X64/IsZeroBuffer.nasm | 55 ++++++++++++++++
 .../BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf    |  6 +-
 .../BaseMemoryLibOptDxe/Ia32/IsZeroBuffer.nasm     | 55 ++++++++++++++++
 .../BaseMemoryLibOptDxe/IsZeroBufferWrapper.c      | 54 +++++++++++++++
 MdePkg/Library/BaseMemoryLibOptDxe/MemLibGuid.c    | 31 ++++++++-
 .../Library/BaseMemoryLibOptDxe/MemLibInternals.h  | 19 +++++-
 .../BaseMemoryLibOptDxe/X64/IsZeroBuffer.nasm      | 55 ++++++++++++++++
 .../BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf    |  6 +-
 .../BaseMemoryLibOptPei/Ia32/IsZeroBuffer.nasm     | 55 ++++++++++++++++
 .../BaseMemoryLibOptPei/IsZeroBufferWrapper.c      | 54 +++++++++++++++
 MdePkg/Library/BaseMemoryLibOptPei/MemLibGuid.c    | 31 ++++++++-
 .../Library/BaseMemoryLibOptPei/MemLibInternals.h  | 19 +++++-
 .../BaseMemoryLibOptPei/X64/IsZeroBuffer.nasm      | 55 ++++++++++++++++
 .../BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf    |  5 +-
 .../BaseMemoryLibRepStr/Ia32/IsZeroBuffer.nasm     | 55 ++++++++++++++++
 .../BaseMemoryLibRepStr/IsZeroBufferWrapper.c      | 54 +++++++++++++++
 MdePkg/Library/BaseMemoryLibRepStr/MemLibGuid.c    | 31 ++++++++-
 .../Library/BaseMemoryLibRepStr/MemLibInternals.h  | 19 +++++-
 .../BaseMemoryLibRepStr/X64/IsZeroBuffer.nasm      | 55 ++++++++++++++++
 .../BaseMemoryLibSse2/BaseMemoryLibSse2.inf        |  5 +-
 .../BaseMemoryLibSse2/Ia32/IsZeroBuffer.nasm       | 74 +++++++++++++++++++++
 .../BaseMemoryLibSse2/IsZeroBufferWrapper.c        | 54 +++++++++++++++
 MdePkg/Library/BaseMemoryLibSse2/MemLibGuid.c      | 31 ++++++++-
 MdePkg/Library/BaseMemoryLibSse2/MemLibInternals.h | 19 +++++-
 .../BaseMemoryLibSse2/X64/IsZeroBuffer.nasm        | 76 ++++++++++++++++++++++
 MdePkg/Library/PeiMemoryLib/IsZeroBufferWrapper.c  | 54 +++++++++++++++
 MdePkg/Library/PeiMemoryLib/MemLibGeneric.c        | 31 ++++++++-
 MdePkg/Library/PeiMemoryLib/MemLibGuid.c           | 31 ++++++++-
 MdePkg/Library/PeiMemoryLib/MemLibInternals.h      | 19 +++++-
 MdePkg/Library/PeiMemoryLib/PeiMemoryLib.inf       |  3 +-
 MdePkg/Library/UefiMemoryLib/IsZeroBufferWrapper.c | 54 +++++++++++++++
 MdePkg/Library/UefiMemoryLib/MemLibGeneric.c       | 31 ++++++++-
 MdePkg/Library/UefiMemoryLib/MemLibGuid.c          | 31 ++++++++-
 MdePkg/Library/UefiMemoryLib/MemLibInternals.h     | 19 +++++-
 MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf     |  3 +-
 SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c        | 27 --------
 SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c                  | 27 --------
 SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c                  | 27 --------
 49 files changed, 1568 insertions(+), 109 deletions(-)
 create mode 100644 MdePkg/Library/BaseMemoryLib/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/BaseMemoryLibMmx/Ia32/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibMmx/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/BaseMemoryLibMmx/X64/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibOptDxe/Ia32/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/BaseMemoryLibOptDxe/X64/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibOptPei/Ia32/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibOptPei/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/BaseMemoryLibOptPei/X64/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibRepStr/Ia32/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibRepStr/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/BaseMemoryLibRepStr/X64/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibSse2/Ia32/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibSse2/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/BaseMemoryLibSse2/X64/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/PeiMemoryLib/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/UefiMemoryLib/IsZeroBufferWrapper.c

-- 
1.9.5.msysgit.0



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/6] MdePkg BaseMemoryLib: Add implementation of API IsZeroGuid()
  2016-08-18  4:53 [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib Hao Wu
@ 2016-08-18  4:53 ` Hao Wu
  2016-08-18  4:53 ` [PATCH v2 2/6] SecurityPkg Tcg2: Rename internal API IsZeroBuffer to InternalIsZeroBuffer Hao Wu
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Hao Wu @ 2016-08-18  4:53 UTC (permalink / raw)
  To: edk2-devel, liming.gao; +Cc: Hao Wu, Michael D Kinney, Jiewen Yao

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>
---
 MdePkg/Include/Library/BaseMemoryLib.h          | 22 +++++++++++++++++-
 MdePkg/Library/BaseMemoryLib/MemLibGuid.c       | 31 ++++++++++++++++++++++++-
 MdePkg/Library/BaseMemoryLibMmx/MemLibGuid.c    | 31 ++++++++++++++++++++++++-
 MdePkg/Library/BaseMemoryLibOptDxe/MemLibGuid.c | 31 ++++++++++++++++++++++++-
 MdePkg/Library/BaseMemoryLibOptPei/MemLibGuid.c | 31 ++++++++++++++++++++++++-
 MdePkg/Library/BaseMemoryLibRepStr/MemLibGuid.c | 31 ++++++++++++++++++++++++-
 MdePkg/Library/BaseMemoryLibSse2/MemLibGuid.c   | 31 ++++++++++++++++++++++++-
 MdePkg/Library/PeiMemoryLib/MemLibGuid.c        | 31 ++++++++++++++++++++++++-
 MdePkg/Library/UefiMemoryLib/MemLibGuid.c       | 31 ++++++++++++++++++++++++-
 9 files changed, 261 insertions(+), 9 deletions(-)

diff --git a/MdePkg/Include/Library/BaseMemoryLib.h b/MdePkg/Include/Library/BaseMemoryLib.h
index e3a46d0..ed7fa00 100644
--- a/MdePkg/Include/Library/BaseMemoryLib.h
+++ b/MdePkg/Include/Library/BaseMemoryLib.h
@@ -5,7 +5,7 @@
   These functions should be used in place of coding your own loops to do equivalent common functions. 
   This allows optimized library implementations to help increase performance. 
 
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials are licensed and made available under 
 the terms and conditions of the BSD License that accompanies this distribution.  
 The full text of the license may be found at
@@ -443,4 +443,24 @@ ScanGuid (
   IN CONST GUID  *Guid
   );
 
+/**
+  Checks if the given GUID is a zero GUID.
+
+  This function checks whether the given GUID is a zero GUID. If the GUID is
+  identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.
+
+  If Guid is NULL, then ASSERT().
+
+  @param  Guid        The pointer to a 128 bit GUID.
+
+  @retval TRUE        Guid is a zero GUID.
+  @retval FALSE       Guid is not a zero GUID.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroGuid (
+  IN CONST GUID  *Guid
+  );
+
 #endif
diff --git a/MdePkg/Library/BaseMemoryLib/MemLibGuid.c b/MdePkg/Library/BaseMemoryLib/MemLibGuid.c
index dc16bd5..b2590f8 100644
--- a/MdePkg/Library/BaseMemoryLib/MemLibGuid.c
+++ b/MdePkg/Library/BaseMemoryLib/MemLibGuid.c
@@ -12,7 +12,7 @@
     PeiMemoryLib
     UefiMemoryLib
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -140,3 +140,32 @@ ScanGuid (
   }
   return NULL;
 }
+
+/**
+  Checks if the given GUID is a zero GUID.
+
+  This function checks whether the given GUID is a zero GUID. If the GUID is
+  identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.
+
+  If Guid is NULL, then ASSERT().
+
+  @param  Guid        The pointer to a 128 bit GUID.
+
+  @retval TRUE        Guid is a zero GUID.
+  @retval FALSE       Guid is not a zero GUID.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroGuid (
+  IN CONST GUID  *Guid
+  )
+{
+  UINT64  LowPartOfGuid;
+  UINT64  HighPartOfGuid;
+
+  LowPartOfGuid  = ReadUnaligned64 ((CONST UINT64*) Guid);
+  HighPartOfGuid = ReadUnaligned64 ((CONST UINT64*) Guid + 1);
+
+  return (BOOLEAN) (LowPartOfGuid == 0 && HighPartOfGuid == 0);
+}
diff --git a/MdePkg/Library/BaseMemoryLibMmx/MemLibGuid.c b/MdePkg/Library/BaseMemoryLibMmx/MemLibGuid.c
index c04af6e..cbb385f 100644
--- a/MdePkg/Library/BaseMemoryLibMmx/MemLibGuid.c
+++ b/MdePkg/Library/BaseMemoryLibMmx/MemLibGuid.c
@@ -12,7 +12,7 @@
     PeiMemoryLib
     UefiMemoryLib
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -140,3 +140,32 @@ ScanGuid (
   }
   return NULL;
 }
+
+/**
+  Checks if the given GUID is a zero GUID.
+
+  This function checks whether the given GUID is a zero GUID. If the GUID is
+  identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.
+
+  If Guid is NULL, then ASSERT().
+
+  @param  Guid        The pointer to a 128 bit GUID.
+
+  @retval TRUE        Guid is a zero GUID.
+  @retval FALSE       Guid is not a zero GUID.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroGuid (
+  IN CONST GUID  *Guid
+  )
+{
+  UINT64  LowPartOfGuid;
+  UINT64  HighPartOfGuid;
+
+  LowPartOfGuid  = ReadUnaligned64 ((CONST UINT64*) Guid);
+  HighPartOfGuid = ReadUnaligned64 ((CONST UINT64*) Guid + 1);
+
+  return (BOOLEAN) (LowPartOfGuid == 0 && HighPartOfGuid == 0);
+}
diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/MemLibGuid.c b/MdePkg/Library/BaseMemoryLibOptDxe/MemLibGuid.c
index c04af6e..cbb385f 100644
--- a/MdePkg/Library/BaseMemoryLibOptDxe/MemLibGuid.c
+++ b/MdePkg/Library/BaseMemoryLibOptDxe/MemLibGuid.c
@@ -12,7 +12,7 @@
     PeiMemoryLib
     UefiMemoryLib
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -140,3 +140,32 @@ ScanGuid (
   }
   return NULL;
 }
+
+/**
+  Checks if the given GUID is a zero GUID.
+
+  This function checks whether the given GUID is a zero GUID. If the GUID is
+  identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.
+
+  If Guid is NULL, then ASSERT().
+
+  @param  Guid        The pointer to a 128 bit GUID.
+
+  @retval TRUE        Guid is a zero GUID.
+  @retval FALSE       Guid is not a zero GUID.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroGuid (
+  IN CONST GUID  *Guid
+  )
+{
+  UINT64  LowPartOfGuid;
+  UINT64  HighPartOfGuid;
+
+  LowPartOfGuid  = ReadUnaligned64 ((CONST UINT64*) Guid);
+  HighPartOfGuid = ReadUnaligned64 ((CONST UINT64*) Guid + 1);
+
+  return (BOOLEAN) (LowPartOfGuid == 0 && HighPartOfGuid == 0);
+}
diff --git a/MdePkg/Library/BaseMemoryLibOptPei/MemLibGuid.c b/MdePkg/Library/BaseMemoryLibOptPei/MemLibGuid.c
index 6f6edd0..cbb385f 100644
--- a/MdePkg/Library/BaseMemoryLibOptPei/MemLibGuid.c
+++ b/MdePkg/Library/BaseMemoryLibOptPei/MemLibGuid.c
@@ -12,7 +12,7 @@
     PeiMemoryLib
     UefiMemoryLib
 
-  Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -140,3 +140,32 @@ ScanGuid (
   }
   return NULL;
 }
+
+/**
+  Checks if the given GUID is a zero GUID.
+
+  This function checks whether the given GUID is a zero GUID. If the GUID is
+  identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.
+
+  If Guid is NULL, then ASSERT().
+
+  @param  Guid        The pointer to a 128 bit GUID.
+
+  @retval TRUE        Guid is a zero GUID.
+  @retval FALSE       Guid is not a zero GUID.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroGuid (
+  IN CONST GUID  *Guid
+  )
+{
+  UINT64  LowPartOfGuid;
+  UINT64  HighPartOfGuid;
+
+  LowPartOfGuid  = ReadUnaligned64 ((CONST UINT64*) Guid);
+  HighPartOfGuid = ReadUnaligned64 ((CONST UINT64*) Guid + 1);
+
+  return (BOOLEAN) (LowPartOfGuid == 0 && HighPartOfGuid == 0);
+}
diff --git a/MdePkg/Library/BaseMemoryLibRepStr/MemLibGuid.c b/MdePkg/Library/BaseMemoryLibRepStr/MemLibGuid.c
index 6f6edd0..cbb385f 100644
--- a/MdePkg/Library/BaseMemoryLibRepStr/MemLibGuid.c
+++ b/MdePkg/Library/BaseMemoryLibRepStr/MemLibGuid.c
@@ -12,7 +12,7 @@
     PeiMemoryLib
     UefiMemoryLib
 
-  Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -140,3 +140,32 @@ ScanGuid (
   }
   return NULL;
 }
+
+/**
+  Checks if the given GUID is a zero GUID.
+
+  This function checks whether the given GUID is a zero GUID. If the GUID is
+  identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.
+
+  If Guid is NULL, then ASSERT().
+
+  @param  Guid        The pointer to a 128 bit GUID.
+
+  @retval TRUE        Guid is a zero GUID.
+  @retval FALSE       Guid is not a zero GUID.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroGuid (
+  IN CONST GUID  *Guid
+  )
+{
+  UINT64  LowPartOfGuid;
+  UINT64  HighPartOfGuid;
+
+  LowPartOfGuid  = ReadUnaligned64 ((CONST UINT64*) Guid);
+  HighPartOfGuid = ReadUnaligned64 ((CONST UINT64*) Guid + 1);
+
+  return (BOOLEAN) (LowPartOfGuid == 0 && HighPartOfGuid == 0);
+}
diff --git a/MdePkg/Library/BaseMemoryLibSse2/MemLibGuid.c b/MdePkg/Library/BaseMemoryLibSse2/MemLibGuid.c
index c04af6e..cbb385f 100644
--- a/MdePkg/Library/BaseMemoryLibSse2/MemLibGuid.c
+++ b/MdePkg/Library/BaseMemoryLibSse2/MemLibGuid.c
@@ -12,7 +12,7 @@
     PeiMemoryLib
     UefiMemoryLib
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -140,3 +140,32 @@ ScanGuid (
   }
   return NULL;
 }
+
+/**
+  Checks if the given GUID is a zero GUID.
+
+  This function checks whether the given GUID is a zero GUID. If the GUID is
+  identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.
+
+  If Guid is NULL, then ASSERT().
+
+  @param  Guid        The pointer to a 128 bit GUID.
+
+  @retval TRUE        Guid is a zero GUID.
+  @retval FALSE       Guid is not a zero GUID.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroGuid (
+  IN CONST GUID  *Guid
+  )
+{
+  UINT64  LowPartOfGuid;
+  UINT64  HighPartOfGuid;
+
+  LowPartOfGuid  = ReadUnaligned64 ((CONST UINT64*) Guid);
+  HighPartOfGuid = ReadUnaligned64 ((CONST UINT64*) Guid + 1);
+
+  return (BOOLEAN) (LowPartOfGuid == 0 && HighPartOfGuid == 0);
+}
diff --git a/MdePkg/Library/PeiMemoryLib/MemLibGuid.c b/MdePkg/Library/PeiMemoryLib/MemLibGuid.c
index c04af6e..cbb385f 100644
--- a/MdePkg/Library/PeiMemoryLib/MemLibGuid.c
+++ b/MdePkg/Library/PeiMemoryLib/MemLibGuid.c
@@ -12,7 +12,7 @@
     PeiMemoryLib
     UefiMemoryLib
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -140,3 +140,32 @@ ScanGuid (
   }
   return NULL;
 }
+
+/**
+  Checks if the given GUID is a zero GUID.
+
+  This function checks whether the given GUID is a zero GUID. If the GUID is
+  identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.
+
+  If Guid is NULL, then ASSERT().
+
+  @param  Guid        The pointer to a 128 bit GUID.
+
+  @retval TRUE        Guid is a zero GUID.
+  @retval FALSE       Guid is not a zero GUID.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroGuid (
+  IN CONST GUID  *Guid
+  )
+{
+  UINT64  LowPartOfGuid;
+  UINT64  HighPartOfGuid;
+
+  LowPartOfGuid  = ReadUnaligned64 ((CONST UINT64*) Guid);
+  HighPartOfGuid = ReadUnaligned64 ((CONST UINT64*) Guid + 1);
+
+  return (BOOLEAN) (LowPartOfGuid == 0 && HighPartOfGuid == 0);
+}
diff --git a/MdePkg/Library/UefiMemoryLib/MemLibGuid.c b/MdePkg/Library/UefiMemoryLib/MemLibGuid.c
index 6f6edd0..cbb385f 100644
--- a/MdePkg/Library/UefiMemoryLib/MemLibGuid.c
+++ b/MdePkg/Library/UefiMemoryLib/MemLibGuid.c
@@ -12,7 +12,7 @@
     PeiMemoryLib
     UefiMemoryLib
 
-  Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -140,3 +140,32 @@ ScanGuid (
   }
   return NULL;
 }
+
+/**
+  Checks if the given GUID is a zero GUID.
+
+  This function checks whether the given GUID is a zero GUID. If the GUID is
+  identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.
+
+  If Guid is NULL, then ASSERT().
+
+  @param  Guid        The pointer to a 128 bit GUID.
+
+  @retval TRUE        Guid is a zero GUID.
+  @retval FALSE       Guid is not a zero GUID.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroGuid (
+  IN CONST GUID  *Guid
+  )
+{
+  UINT64  LowPartOfGuid;
+  UINT64  HighPartOfGuid;
+
+  LowPartOfGuid  = ReadUnaligned64 ((CONST UINT64*) Guid);
+  HighPartOfGuid = ReadUnaligned64 ((CONST UINT64*) Guid + 1);
+
+  return (BOOLEAN) (LowPartOfGuid == 0 && HighPartOfGuid == 0);
+}
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/6] SecurityPkg Tcg2: Rename internal API IsZeroBuffer to InternalIsZeroBuffer
  2016-08-18  4:53 [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib Hao Wu
  2016-08-18  4:53 ` [PATCH v2 1/6] MdePkg BaseMemoryLib: Add implementation of API IsZeroGuid() Hao Wu
@ 2016-08-18  4:53 ` Hao Wu
  2016-08-18  4:53 ` [PATCH v2 3/6] MdePkg BaseMemoryLib: Add C implementation of API IsZeroBuffer() Hao Wu
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Hao Wu @ 2016-08-18  4:53 UTC (permalink / raw)
  To: edk2-devel, liming.gao; +Cc: Hao Wu, Jiewen Yao, Chao Zhang

Before adding API IsZeroBuffer() in BaseMemoryLib at MdePkg, rename the
internal implementations of IsZeroBuffer() within SecurityPkg/Tcg modules
to avoid breaking bisection.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c |  4 ++--
 SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c           | 12 ++++++------
 SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c           | 12 ++++++------
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
index db38bd4..7a97f6b 100644
--- a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
+++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
@@ -626,7 +626,7 @@ FillBufferWithTCG2EventLogFormat (
   @retval FALSE Buffer is not all zero.
 **/
 BOOLEAN
-IsZeroBuffer (
+InternalIsZeroBuffer (
   IN VOID  *Buffer,
   IN UINTN BufferSize
   )
@@ -735,7 +735,7 @@ InstallTcg2ConfigForm (
   } else {
     TempBuffer[0] = 0;
     for (Index = 0; Index < Pcrs.count; Index++) {
-      if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+      if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
         AppendBufferWithTpmAlgHash (TempBuffer, sizeof(TempBuffer), Pcrs.pcrSelections[Index].hash);
       }
     }
diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
index 95219c0..5d97556 100644
--- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
+++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
@@ -211,7 +211,7 @@ InternalDumpHex (
   @retval FALSE Buffer is not all zero.
 **/
 BOOLEAN
-IsZeroBuffer (
+InternalIsZeroBuffer (
   IN VOID  *Buffer,
   IN UINTN BufferSize
   )
@@ -2471,31 +2471,31 @@ DriverEntry (
       switch (Pcrs.pcrSelections[Index].hash) {
       case TPM_ALG_SHA1:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SHA1;
-        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA1;
         }        
         break;
       case TPM_ALG_SHA256:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SHA256;
-        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA256;
         }
         break;
       case TPM_ALG_SHA384:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SHA384;
-        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA384;
         }
         break;
       case TPM_ALG_SHA512:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SHA512;
-        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA512;
         }
         break;
       case TPM_ALG_SM3_256:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SM3_256;
-        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SM3_256;
         }
         break;
diff --git a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
index a830ba8..2cffed4 100644
--- a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
+++ b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
@@ -234,7 +234,7 @@ EndofPeiSignalNotifyCallBack (
   @retval FALSE Buffer is not all zero.
 **/
 BOOLEAN
-IsZeroBuffer (
+InternalIsZeroBuffer (
   IN VOID  *Buffer,
   IN UINTN BufferSize
   )
@@ -383,27 +383,27 @@ SetTpm2HashMask (
       DEBUG ((EFI_D_INFO, "hash - %x\n", Pcrs.pcrSelections[Index].hash));
       switch (Pcrs.pcrSelections[Index].hash) {
       case TPM_ALG_SHA1:
-        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA1;
         }        
         break;
       case TPM_ALG_SHA256:
-        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA256;
         }
         break;
       case TPM_ALG_SHA384:
-        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA384;
         }
         break;
       case TPM_ALG_SHA512:
-        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA512;
         }
         break;
       case TPM_ALG_SM3_256:
-        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SM3_256;
         }
         break;
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/6] MdePkg BaseMemoryLib: Add C implementation of API IsZeroBuffer()
  2016-08-18  4:53 [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib Hao Wu
  2016-08-18  4:53 ` [PATCH v2 1/6] MdePkg BaseMemoryLib: Add implementation of API IsZeroGuid() Hao Wu
  2016-08-18  4:53 ` [PATCH v2 2/6] SecurityPkg Tcg2: Rename internal API IsZeroBuffer to InternalIsZeroBuffer Hao Wu
@ 2016-08-18  4:53 ` Hao Wu
  2016-08-18  4:53 ` [PATCH v2 4/6] MdePkg BaseMemoryLib: Add assembly " Hao Wu
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Hao Wu @ 2016-08-18  4:53 UTC (permalink / raw)
  To: edk2-devel, liming.gao; +Cc: Hao Wu, Michael D Kinney, Jiewen Yao

Add the implementation of API IsZeroBuffer() via C language for the
following library instances:
BaseMemoryLib
PeiMemoryLib
UefiMemoryLib

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>
---
 MdePkg/Include/Library/BaseMemoryLib.h             | 23 +++++++++
 MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf     |  3 +-
 MdePkg/Library/BaseMemoryLib/IsZeroBufferWrapper.c | 54 ++++++++++++++++++++++
 MdePkg/Library/BaseMemoryLib/MemLibGeneric.c       | 31 ++++++++++++-
 MdePkg/Library/BaseMemoryLib/MemLibInternals.h     | 19 +++++++-
 MdePkg/Library/PeiMemoryLib/IsZeroBufferWrapper.c  | 54 ++++++++++++++++++++++
 MdePkg/Library/PeiMemoryLib/MemLibGeneric.c        | 31 ++++++++++++-
 MdePkg/Library/PeiMemoryLib/MemLibInternals.h      | 19 +++++++-
 MdePkg/Library/PeiMemoryLib/PeiMemoryLib.inf       |  3 +-
 MdePkg/Library/UefiMemoryLib/IsZeroBufferWrapper.c | 54 ++++++++++++++++++++++
 MdePkg/Library/UefiMemoryLib/MemLibGeneric.c       | 31 ++++++++++++-
 MdePkg/Library/UefiMemoryLib/MemLibInternals.h     | 19 +++++++-
 MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf     |  3 +-
 13 files changed, 335 insertions(+), 9 deletions(-)
 create mode 100644 MdePkg/Library/BaseMemoryLib/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/PeiMemoryLib/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/UefiMemoryLib/IsZeroBufferWrapper.c

diff --git a/MdePkg/Include/Library/BaseMemoryLib.h b/MdePkg/Include/Library/BaseMemoryLib.h
index ed7fa00..0e565c1 100644
--- a/MdePkg/Include/Library/BaseMemoryLib.h
+++ b/MdePkg/Include/Library/BaseMemoryLib.h
@@ -463,4 +463,27 @@ IsZeroGuid (
   IN CONST GUID  *Guid
   );
 
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  );
+
 #endif
diff --git a/MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf b/MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
index 5dfab35..6d906e9 100644
--- a/MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
+++ b/MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
@@ -3,7 +3,7 @@
 #
 #  Base Memory Library implementation - no ASM.
 #
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -42,6 +42,7 @@
   SetMem16Wrapper.c
   SetMemWrapper.c
   CopyMemWrapper.c
+  IsZeroBufferWrapper.c
   MemLibGeneric.c
   MemLibGuid.c
   CopyMem.c
diff --git a/MdePkg/Library/BaseMemoryLib/IsZeroBufferWrapper.c b/MdePkg/Library/BaseMemoryLib/IsZeroBufferWrapper.c
new file mode 100644
index 0000000..c42c1aa
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLib/IsZeroBufferWrapper.c
@@ -0,0 +1,54 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "MemLibInternals.h"
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+  return InternalMemIsZeroBuffer (Buffer, Length);
+}
diff --git a/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c b/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c
index a977c4a..b058be8 100644
--- a/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c
+++ b/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c
@@ -6,7 +6,7 @@
     PeiMemoryLib
     UefiMemoryLib
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -262,3 +262,32 @@ InternalMemScanMem64 (
   } while (--Length != 0);
   return NULL;
 }
+
+/**
+  Checks whether the contents of a buffer are all zeros.
+
+  @param  Buffer  The pointer to the buffer to be checked.
+  @param  Length  The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE    Contents of the buffer are all zeros.
+  @retval FALSE   Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+InternalMemIsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  CONST UINT8 *BufferData;
+  UINTN       Index;
+
+  BufferData = Buffer;
+  for (Index = 0; Index < Length; Index++) {
+    if (BufferData[Index] != 0) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
diff --git a/MdePkg/Library/BaseMemoryLib/MemLibInternals.h b/MdePkg/Library/BaseMemoryLib/MemLibInternals.h
index 6f75839..7d8ecbe 100644
--- a/MdePkg/Library/BaseMemoryLib/MemLibInternals.h
+++ b/MdePkg/Library/BaseMemoryLib/MemLibInternals.h
@@ -9,7 +9,7 @@
     BaseMemoryLibOptDxe
     BaseMemoryLibOptPei
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -231,4 +231,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value
   );
 
+/**
+  Checks whether the contents of a buffer are all zeros.
+
+  @param  Buffer  The pointer to the buffer to be checked.
+  @param  Length  The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE    Contents of the buffer are all zeros.
+  @retval FALSE   Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+InternalMemIsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  );
+
 #endif
diff --git a/MdePkg/Library/PeiMemoryLib/IsZeroBufferWrapper.c b/MdePkg/Library/PeiMemoryLib/IsZeroBufferWrapper.c
new file mode 100644
index 0000000..c42c1aa
--- /dev/null
+++ b/MdePkg/Library/PeiMemoryLib/IsZeroBufferWrapper.c
@@ -0,0 +1,54 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "MemLibInternals.h"
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+  return InternalMemIsZeroBuffer (Buffer, Length);
+}
diff --git a/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c b/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c
index 53f1caf..490b244 100644
--- a/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c
+++ b/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c
@@ -6,7 +6,7 @@
     PeiMemoryLib
     UefiMemoryLib
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -258,3 +258,32 @@ InternalMemScanMem64 (
   } while (--Length != 0);
   return NULL;
 }
+
+/**
+  Checks whether the contents of a buffer are all zeros.
+
+  @param  Buffer  The pointer to the buffer to be checked.
+  @param  Length  The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE    Contents of the buffer are all zeros.
+  @retval FALSE   Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+InternalMemIsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  CONST UINT8 *BufferData;
+  UINTN       Index;
+
+  BufferData = Buffer;
+  for (Index = 0; Index < Length; Index++) {
+    if (BufferData[Index] != 0) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
diff --git a/MdePkg/Library/PeiMemoryLib/MemLibInternals.h b/MdePkg/Library/PeiMemoryLib/MemLibInternals.h
index 8a1e1df..85b4292 100644
--- a/MdePkg/Library/PeiMemoryLib/MemLibInternals.h
+++ b/MdePkg/Library/PeiMemoryLib/MemLibInternals.h
@@ -1,7 +1,7 @@
 /** @file
   Declaration of internal functions for Base Memory Library.
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -229,4 +229,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value
   );
 
+/**
+  Checks whether the contents of a buffer are all zeros.
+
+  @param  Buffer  The pointer to the buffer to be checked.
+  @param  Length  The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE    Contents of the buffer are all zeros.
+  @retval FALSE   Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+InternalMemIsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  );
+
 #endif
diff --git a/MdePkg/Library/PeiMemoryLib/PeiMemoryLib.inf b/MdePkg/Library/PeiMemoryLib/PeiMemoryLib.inf
index 58af9d0..56d584d 100644
--- a/MdePkg/Library/PeiMemoryLib/PeiMemoryLib.inf
+++ b/MdePkg/Library/PeiMemoryLib/PeiMemoryLib.inf
@@ -4,7 +4,7 @@
 # Base Memory Library implementation that uses PEI Services
 #  where possible for size reduction.
 #
-# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -42,6 +42,7 @@
   SetMem16Wrapper.c
   SetMemWrapper.c
   CopyMemWrapper.c
+  IsZeroBufferWrapper.c
   MemLibGeneric.c
   MemLibGuid.c
   MemLib.c
diff --git a/MdePkg/Library/UefiMemoryLib/IsZeroBufferWrapper.c b/MdePkg/Library/UefiMemoryLib/IsZeroBufferWrapper.c
new file mode 100644
index 0000000..c42c1aa
--- /dev/null
+++ b/MdePkg/Library/UefiMemoryLib/IsZeroBufferWrapper.c
@@ -0,0 +1,54 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "MemLibInternals.h"
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+  return InternalMemIsZeroBuffer (Buffer, Length);
+}
diff --git a/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c b/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c
index 1ec8bf6..da02b6c 100644
--- a/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c
+++ b/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c
@@ -6,7 +6,7 @@
     PeiMemoryLib
     UefiMemoryLib
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -258,3 +258,32 @@ InternalMemScanMem64 (
   } while (--Length != 0);
   return NULL;
 }
+
+/**
+  Checks whether the contents of a buffer are all zeros.
+
+  @param  Buffer  The pointer to the buffer to be checked.
+  @param  Length  The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE    Contents of the buffer are all zeros.
+  @retval FALSE   Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+InternalMemIsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  CONST UINT8 *BufferData;
+  UINTN       Index;
+
+  BufferData = Buffer;
+  for (Index = 0; Index < Length; Index++) {
+    if (BufferData[Index] != 0) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
diff --git a/MdePkg/Library/UefiMemoryLib/MemLibInternals.h b/MdePkg/Library/UefiMemoryLib/MemLibInternals.h
index 0443b50..cafbb4d 100644
--- a/MdePkg/Library/UefiMemoryLib/MemLibInternals.h
+++ b/MdePkg/Library/UefiMemoryLib/MemLibInternals.h
@@ -1,7 +1,7 @@
 /** @file
   Declaration of internal functions for Base Memory Library.
 
-  Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -229,4 +229,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value
   );
 
+/**
+  Checks whether the contents of a buffer are all zeros.
+
+  @param  Buffer  The pointer to the buffer to be checked.
+  @param  Length  The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE    Contents of the buffer are all zeros.
+  @retval FALSE   Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+InternalMemIsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  );
+
 #endif
diff --git a/MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf b/MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf
index e82732f..7382204 100644
--- a/MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf
+++ b/MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf
@@ -4,7 +4,7 @@
 # Base Memory Library implementation that uses EFI Boot Services
 #  where possible for size reduction.
 #
-# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -42,6 +42,7 @@
   SetMem16Wrapper.c
   SetMemWrapper.c
   CopyMemWrapper.c
+  IsZeroBufferWrapper.c
   MemLibGeneric.c
   MemLibGuid.c
   MemLib.c
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 4/6] MdePkg BaseMemoryLib: Add assembly implementation of API IsZeroBuffer()
  2016-08-18  4:53 [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib Hao Wu
                   ` (2 preceding siblings ...)
  2016-08-18  4:53 ` [PATCH v2 3/6] MdePkg BaseMemoryLib: Add C implementation of API IsZeroBuffer() Hao Wu
@ 2016-08-18  4:53 ` Hao Wu
  2016-08-18  4:53 ` [PATCH v2 5/6] MdePkg BaseMemoryLibSse2: Add SSE2 " Hao Wu
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Hao Wu @ 2016-08-18  4:53 UTC (permalink / raw)
  To: edk2-devel, liming.gao; +Cc: Hao Wu, Michael D Kinney, Jiewen Yao

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>
---
 .../Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf  |  5 +-
 .../BaseMemoryLibMmx/Ia32/IsZeroBuffer.nasm        | 55 ++++++++++++++++++++++
 .../Library/BaseMemoryLibMmx/IsZeroBufferWrapper.c | 54 +++++++++++++++++++++
 MdePkg/Library/BaseMemoryLibMmx/MemLibInternals.h  | 19 +++++++-
 .../Library/BaseMemoryLibMmx/X64/IsZeroBuffer.nasm | 55 ++++++++++++++++++++++
 .../BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf    |  6 ++-
 .../BaseMemoryLibOptDxe/Ia32/IsZeroBuffer.nasm     | 55 ++++++++++++++++++++++
 .../BaseMemoryLibOptDxe/IsZeroBufferWrapper.c      | 54 +++++++++++++++++++++
 .../Library/BaseMemoryLibOptDxe/MemLibInternals.h  | 19 +++++++-
 .../BaseMemoryLibOptDxe/X64/IsZeroBuffer.nasm      | 55 ++++++++++++++++++++++
 .../BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf    |  6 ++-
 .../BaseMemoryLibOptPei/Ia32/IsZeroBuffer.nasm     | 55 ++++++++++++++++++++++
 .../BaseMemoryLibOptPei/IsZeroBufferWrapper.c      | 54 +++++++++++++++++++++
 .../Library/BaseMemoryLibOptPei/MemLibInternals.h  | 19 +++++++-
 .../BaseMemoryLibOptPei/X64/IsZeroBuffer.nasm      | 55 ++++++++++++++++++++++
 .../BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf    |  5 +-
 .../BaseMemoryLibRepStr/Ia32/IsZeroBuffer.nasm     | 55 ++++++++++++++++++++++
 .../BaseMemoryLibRepStr/IsZeroBufferWrapper.c      | 54 +++++++++++++++++++++
 .../Library/BaseMemoryLibRepStr/MemLibInternals.h  | 19 +++++++-
 .../BaseMemoryLibRepStr/X64/IsZeroBuffer.nasm      | 55 ++++++++++++++++++++++
 20 files changed, 746 insertions(+), 8 deletions(-)
 create mode 100644 MdePkg/Library/BaseMemoryLibMmx/Ia32/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibMmx/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/BaseMemoryLibMmx/X64/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibOptDxe/Ia32/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/BaseMemoryLibOptDxe/X64/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibOptPei/Ia32/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibOptPei/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/BaseMemoryLibOptPei/X64/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibRepStr/Ia32/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibRepStr/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/BaseMemoryLibRepStr/X64/IsZeroBuffer.nasm

diff --git a/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf b/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf
index a609073..af08b7d 100644
--- a/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf
+++ b/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf
@@ -4,7 +4,7 @@
 #  Base Memory Library that uses MMX registers for high performance.
 #  Optimized for use in DXE.
 #
-#  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -46,6 +46,7 @@
   SetMem16Wrapper.c
   SetMemWrapper.c
   CopyMemWrapper.c
+  IsZeroBufferWrapper.c
   MemLibGuid.c
   MemLibInternals.h
 
@@ -94,6 +95,7 @@
   Ia32/SetMem.asm
   Ia32/CopyMem.nasm
   Ia32/CopyMem.asm
+  Ia32/IsZeroBuffer.nasm
 
 [Sources.X64]
   X64/ZeroMem.nasm
@@ -140,6 +142,7 @@
   X64/SetMem.S
   X64/CopyMem.nasm
   X64/CopyMem.S
+  X64/IsZeroBuffer.nasm
 
 
 [LibraryClasses]
diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibMmx/Ia32/IsZeroBuffer.nasm
new file mode 100644
index 0000000..a2e56a1
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/IsZeroBuffer.nasm
@@ -0,0 +1,55 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution.  The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+;   IsZeroBuffer.nasm
+;
+; Abstract:
+;
+;   IsZeroBuffer function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+    SECTION .text
+
+;------------------------------------------------------------------------------
+;  BOOLEAN
+;  EFIAPI
+;  InternalMemIsZeroBuffer (
+;    IN CONST VOID  *Buffer,
+;    IN UINTN       Length
+;    );
+;------------------------------------------------------------------------------
+global ASM_PFX(InternalMemIsZeroBuffer)
+ASM_PFX(InternalMemIsZeroBuffer):
+    push    edi
+    mov     edi, [esp + 8]             ; edi <- Buffer
+    mov     ecx, [esp + 12]            ; ecx <- Length
+    mov     edx, ecx                   ; edx <- ecx
+    shr     ecx, 2                     ; ecx <- number of dwords
+    and     edx, 3                     ; edx <- number of trailing bytes
+    xor     eax, eax                   ; eax <- 0, also set ZF
+    repe    scasd
+    jnz     @ReturnFalse               ; ZF=0 means non-zero element found
+    mov     ecx, edx
+    repe    scasb
+    jnz     @ReturnFalse
+    pop     edi
+    mov     eax, 1                     ; return TRUE
+    ret
+@ReturnFalse:
+    pop     edi
+    xor     eax, eax
+    ret                                ; return FALSE
+
diff --git a/MdePkg/Library/BaseMemoryLibMmx/IsZeroBufferWrapper.c b/MdePkg/Library/BaseMemoryLibMmx/IsZeroBufferWrapper.c
new file mode 100644
index 0000000..c42c1aa
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibMmx/IsZeroBufferWrapper.c
@@ -0,0 +1,54 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "MemLibInternals.h"
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+  return InternalMemIsZeroBuffer (Buffer, Length);
+}
diff --git a/MdePkg/Library/BaseMemoryLibMmx/MemLibInternals.h b/MdePkg/Library/BaseMemoryLibMmx/MemLibInternals.h
index 38bb975..cc89979 100644
--- a/MdePkg/Library/BaseMemoryLibMmx/MemLibInternals.h
+++ b/MdePkg/Library/BaseMemoryLibMmx/MemLibInternals.h
@@ -9,7 +9,7 @@
     BaseMemoryLibOptDxe
     BaseMemoryLibOptPei
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -231,4 +231,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value
   );
 
+/**
+  Checks whether the contents of a buffer are all zeros.
+
+  @param  Buffer  The pointer to the buffer to be checked.
+  @param  Length  The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE    Contents of the buffer are all zeros.
+  @retval FALSE   Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+InternalMemIsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  );
+
 #endif
diff --git a/MdePkg/Library/BaseMemoryLibMmx/X64/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibMmx/X64/IsZeroBuffer.nasm
new file mode 100644
index 0000000..00b1067
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibMmx/X64/IsZeroBuffer.nasm
@@ -0,0 +1,55 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution.  The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+;   IsZeroBuffer.nasm
+;
+; Abstract:
+;
+;   IsZeroBuffer function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+    DEFAULT REL
+    SECTION .text
+
+;------------------------------------------------------------------------------
+;  BOOLEAN
+;  EFIAPI
+;  InternalMemIsZeroBuffer (
+;    IN CONST VOID  *Buffer,
+;    IN UINTN       Length
+;    );
+;------------------------------------------------------------------------------
+global ASM_PFX(InternalMemIsZeroBuffer)
+ASM_PFX(InternalMemIsZeroBuffer):
+    push    rdi
+    mov     rdi, rcx                   ; rdi <- Buffer
+    mov     rcx, rdx                   ; rcx <- Length
+    shr     rcx, 3                     ; rcx <- number of qwords
+    and     rdx, 7                     ; rdx <- number of trailing bytes
+    xor     rax, rax                   ; rax <- 0, also set ZF
+    repe    scasq
+    jnz     @ReturnFalse               ; ZF=0 means non-zero element found
+    mov     rcx, rdx
+    repe    scasb
+    jnz     @ReturnFalse
+    pop     rdi
+    mov     rax, 1                     ; return TRUE
+    ret
+@ReturnFalse:
+    pop     rdi
+    xor     rax, rax
+    ret                                ; return FALSE
+
diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf b/MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf
index e637034..71691b9 100644
--- a/MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf
+++ b/MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf
@@ -4,7 +4,7 @@
 #  Base Memory Library that is optimized for use in DXE phase.  
 #  Uses REP, MMX, XMM registers as required for best performance.
 #
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -78,6 +78,7 @@
   Ia32/SetMem.asm
   Ia32/CopyMem.nasm
   Ia32/CopyMem.asm
+  Ia32/IsZeroBuffer.nasm
   ScanMem64Wrapper.c
   ScanMem32Wrapper.c
   ScanMem16Wrapper.c
@@ -89,6 +90,7 @@
   SetMem16Wrapper.c
   SetMemWrapper.c
   CopyMemWrapper.c
+  IsZeroBufferWrapper.c
   MemLibGuid.c
 
 [Sources.X64]
@@ -125,6 +127,7 @@
   X64/CopyMem.nasm
   X64/CopyMem.asm
   X64/CopyMem.S
+  X64/IsZeroBuffer.nasm
   ScanMem64Wrapper.c
   ScanMem32Wrapper.c
   ScanMem16Wrapper.c
@@ -136,6 +139,7 @@
   SetMem16Wrapper.c
   SetMemWrapper.c
   CopyMemWrapper.c
+  IsZeroBufferWrapper.c
   MemLibGuid.c
 
 [Packages]
diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/Ia32/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibOptDxe/Ia32/IsZeroBuffer.nasm
new file mode 100644
index 0000000..a2e56a1
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibOptDxe/Ia32/IsZeroBuffer.nasm
@@ -0,0 +1,55 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution.  The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+;   IsZeroBuffer.nasm
+;
+; Abstract:
+;
+;   IsZeroBuffer function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+    SECTION .text
+
+;------------------------------------------------------------------------------
+;  BOOLEAN
+;  EFIAPI
+;  InternalMemIsZeroBuffer (
+;    IN CONST VOID  *Buffer,
+;    IN UINTN       Length
+;    );
+;------------------------------------------------------------------------------
+global ASM_PFX(InternalMemIsZeroBuffer)
+ASM_PFX(InternalMemIsZeroBuffer):
+    push    edi
+    mov     edi, [esp + 8]             ; edi <- Buffer
+    mov     ecx, [esp + 12]            ; ecx <- Length
+    mov     edx, ecx                   ; edx <- ecx
+    shr     ecx, 2                     ; ecx <- number of dwords
+    and     edx, 3                     ; edx <- number of trailing bytes
+    xor     eax, eax                   ; eax <- 0, also set ZF
+    repe    scasd
+    jnz     @ReturnFalse               ; ZF=0 means non-zero element found
+    mov     ecx, edx
+    repe    scasb
+    jnz     @ReturnFalse
+    pop     edi
+    mov     eax, 1                     ; return TRUE
+    ret
+@ReturnFalse:
+    pop     edi
+    xor     eax, eax
+    ret                                ; return FALSE
+
diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBufferWrapper.c b/MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBufferWrapper.c
new file mode 100644
index 0000000..c42c1aa
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBufferWrapper.c
@@ -0,0 +1,54 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "MemLibInternals.h"
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+  return InternalMemIsZeroBuffer (Buffer, Length);
+}
diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/MemLibInternals.h b/MdePkg/Library/BaseMemoryLibOptDxe/MemLibInternals.h
index b15e3c1..7d310bb 100644
--- a/MdePkg/Library/BaseMemoryLibOptDxe/MemLibInternals.h
+++ b/MdePkg/Library/BaseMemoryLibOptDxe/MemLibInternals.h
@@ -9,7 +9,7 @@
     BaseMemoryLibOptDxe
     BaseMemoryLibOptPei
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -231,4 +231,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value
   );
 
+/**
+  Checks whether the contents of a buffer are all zeros.
+
+  @param  Buffer  The pointer to the buffer to be checked.
+  @param  Length  The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE    Contents of the buffer are all zeros.
+  @retval FALSE   Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+InternalMemIsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  );
+
 #endif
diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/X64/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibOptDxe/X64/IsZeroBuffer.nasm
new file mode 100644
index 0000000..00b1067
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibOptDxe/X64/IsZeroBuffer.nasm
@@ -0,0 +1,55 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution.  The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+;   IsZeroBuffer.nasm
+;
+; Abstract:
+;
+;   IsZeroBuffer function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+    DEFAULT REL
+    SECTION .text
+
+;------------------------------------------------------------------------------
+;  BOOLEAN
+;  EFIAPI
+;  InternalMemIsZeroBuffer (
+;    IN CONST VOID  *Buffer,
+;    IN UINTN       Length
+;    );
+;------------------------------------------------------------------------------
+global ASM_PFX(InternalMemIsZeroBuffer)
+ASM_PFX(InternalMemIsZeroBuffer):
+    push    rdi
+    mov     rdi, rcx                   ; rdi <- Buffer
+    mov     rcx, rdx                   ; rcx <- Length
+    shr     rcx, 3                     ; rcx <- number of qwords
+    and     rdx, 7                     ; rdx <- number of trailing bytes
+    xor     rax, rax                   ; rax <- 0, also set ZF
+    repe    scasq
+    jnz     @ReturnFalse               ; ZF=0 means non-zero element found
+    mov     rcx, rdx
+    repe    scasb
+    jnz     @ReturnFalse
+    pop     rdi
+    mov     rax, 1                     ; return TRUE
+    ret
+@ReturnFalse:
+    pop     rdi
+    xor     rax, rax
+    ret                                ; return FALSE
+
diff --git a/MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf b/MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf
index ff60e9e..21f060e 100644
--- a/MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf
+++ b/MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf
@@ -4,7 +4,7 @@
 #  Base Memory Library that is optimized for use in PEI phase.  
 #  Uses REP, MMX, XMM registers as required for best performance.
 #
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -78,6 +78,7 @@
   Ia32/SetMem.asm
   Ia32/CopyMem.nasm
   Ia32/CopyMem.asm
+  Ia32/IsZeroBuffer.nasm
   ScanMem64Wrapper.c
   ScanMem32Wrapper.c
   ScanMem16Wrapper.c
@@ -89,6 +90,7 @@
   SetMem16Wrapper.c
   SetMemWrapper.c
   CopyMemWrapper.c
+  IsZeroBufferWrapper.c
   MemLibGuid.c
 
 [Sources.X64]
@@ -125,6 +127,7 @@
   X64/CopyMem.nasm
   X64/CopyMem.asm
   X64/CopyMem.S
+  X64/IsZeroBuffer.nasm
   ScanMem64Wrapper.c
   ScanMem32Wrapper.c
   ScanMem16Wrapper.c
@@ -136,6 +139,7 @@
   SetMem16Wrapper.c
   SetMemWrapper.c
   CopyMemWrapper.c
+  IsZeroBufferWrapper.c
   MemLibGuid.c
 
 
diff --git a/MdePkg/Library/BaseMemoryLibOptPei/Ia32/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibOptPei/Ia32/IsZeroBuffer.nasm
new file mode 100644
index 0000000..a2e56a1
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibOptPei/Ia32/IsZeroBuffer.nasm
@@ -0,0 +1,55 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution.  The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+;   IsZeroBuffer.nasm
+;
+; Abstract:
+;
+;   IsZeroBuffer function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+    SECTION .text
+
+;------------------------------------------------------------------------------
+;  BOOLEAN
+;  EFIAPI
+;  InternalMemIsZeroBuffer (
+;    IN CONST VOID  *Buffer,
+;    IN UINTN       Length
+;    );
+;------------------------------------------------------------------------------
+global ASM_PFX(InternalMemIsZeroBuffer)
+ASM_PFX(InternalMemIsZeroBuffer):
+    push    edi
+    mov     edi, [esp + 8]             ; edi <- Buffer
+    mov     ecx, [esp + 12]            ; ecx <- Length
+    mov     edx, ecx                   ; edx <- ecx
+    shr     ecx, 2                     ; ecx <- number of dwords
+    and     edx, 3                     ; edx <- number of trailing bytes
+    xor     eax, eax                   ; eax <- 0, also set ZF
+    repe    scasd
+    jnz     @ReturnFalse               ; ZF=0 means non-zero element found
+    mov     ecx, edx
+    repe    scasb
+    jnz     @ReturnFalse
+    pop     edi
+    mov     eax, 1                     ; return TRUE
+    ret
+@ReturnFalse:
+    pop     edi
+    xor     eax, eax
+    ret                                ; return FALSE
+
diff --git a/MdePkg/Library/BaseMemoryLibOptPei/IsZeroBufferWrapper.c b/MdePkg/Library/BaseMemoryLibOptPei/IsZeroBufferWrapper.c
new file mode 100644
index 0000000..c42c1aa
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibOptPei/IsZeroBufferWrapper.c
@@ -0,0 +1,54 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "MemLibInternals.h"
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+  return InternalMemIsZeroBuffer (Buffer, Length);
+}
diff --git a/MdePkg/Library/BaseMemoryLibOptPei/MemLibInternals.h b/MdePkg/Library/BaseMemoryLibOptPei/MemLibInternals.h
index 34eff54..72a51f3 100644
--- a/MdePkg/Library/BaseMemoryLibOptPei/MemLibInternals.h
+++ b/MdePkg/Library/BaseMemoryLibOptPei/MemLibInternals.h
@@ -9,7 +9,7 @@
     BaseMemoryLibOptDxe
     BaseMemoryLibOptPei
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -231,4 +231,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value
   );
 
+/**
+  Checks whether the contents of a buffer are all zeros.
+
+  @param  Buffer  The pointer to the buffer to be checked.
+  @param  Length  The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE    Contents of the buffer are all zeros.
+  @retval FALSE   Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+InternalMemIsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  );
+
 #endif
diff --git a/MdePkg/Library/BaseMemoryLibOptPei/X64/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibOptPei/X64/IsZeroBuffer.nasm
new file mode 100644
index 0000000..00b1067
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibOptPei/X64/IsZeroBuffer.nasm
@@ -0,0 +1,55 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution.  The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+;   IsZeroBuffer.nasm
+;
+; Abstract:
+;
+;   IsZeroBuffer function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+    DEFAULT REL
+    SECTION .text
+
+;------------------------------------------------------------------------------
+;  BOOLEAN
+;  EFIAPI
+;  InternalMemIsZeroBuffer (
+;    IN CONST VOID  *Buffer,
+;    IN UINTN       Length
+;    );
+;------------------------------------------------------------------------------
+global ASM_PFX(InternalMemIsZeroBuffer)
+ASM_PFX(InternalMemIsZeroBuffer):
+    push    rdi
+    mov     rdi, rcx                   ; rdi <- Buffer
+    mov     rcx, rdx                   ; rcx <- Length
+    shr     rcx, 3                     ; rcx <- number of qwords
+    and     rdx, 7                     ; rdx <- number of trailing bytes
+    xor     rax, rax                   ; rax <- 0, also set ZF
+    repe    scasq
+    jnz     @ReturnFalse               ; ZF=0 means non-zero element found
+    mov     rcx, rdx
+    repe    scasb
+    jnz     @ReturnFalse
+    pop     rdi
+    mov     rax, 1                     ; return TRUE
+    ret
+@ReturnFalse:
+    pop     rdi
+    xor     rax, rax
+    ret                                ; return FALSE
+
diff --git a/MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf b/MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf
index 9d7ce4b..729e26a 100644
--- a/MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf
+++ b/MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf
@@ -4,7 +4,7 @@
 #  Base Memory Library that uses REP string instructions for
 #  high performance and small size. Optimized for use in PEI.
 #
-#  Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -43,6 +43,7 @@
   SetMem16Wrapper.c
   SetMemWrapper.c
   CopyMemWrapper.c
+  IsZeroBufferWrapper.c
   MemLibGuid.c
 
 [Sources.Ia32]
@@ -90,6 +91,7 @@
   Ia32/SetMem.asm
   Ia32/CopyMem.nasm
   Ia32/CopyMem.asm
+  Ia32/IsZeroBuffer.nasm
 
 [Sources.X64]
   X64/ScanMem64.nasm
@@ -136,6 +138,7 @@
   X64/SetMem.asm
   X64/CopyMem.nasm
   X64/CopyMem.asm
+  X64/IsZeroBuffer.nasm
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/MdePkg/Library/BaseMemoryLibRepStr/Ia32/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibRepStr/Ia32/IsZeroBuffer.nasm
new file mode 100644
index 0000000..a2e56a1
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibRepStr/Ia32/IsZeroBuffer.nasm
@@ -0,0 +1,55 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution.  The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+;   IsZeroBuffer.nasm
+;
+; Abstract:
+;
+;   IsZeroBuffer function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+    SECTION .text
+
+;------------------------------------------------------------------------------
+;  BOOLEAN
+;  EFIAPI
+;  InternalMemIsZeroBuffer (
+;    IN CONST VOID  *Buffer,
+;    IN UINTN       Length
+;    );
+;------------------------------------------------------------------------------
+global ASM_PFX(InternalMemIsZeroBuffer)
+ASM_PFX(InternalMemIsZeroBuffer):
+    push    edi
+    mov     edi, [esp + 8]             ; edi <- Buffer
+    mov     ecx, [esp + 12]            ; ecx <- Length
+    mov     edx, ecx                   ; edx <- ecx
+    shr     ecx, 2                     ; ecx <- number of dwords
+    and     edx, 3                     ; edx <- number of trailing bytes
+    xor     eax, eax                   ; eax <- 0, also set ZF
+    repe    scasd
+    jnz     @ReturnFalse               ; ZF=0 means non-zero element found
+    mov     ecx, edx
+    repe    scasb
+    jnz     @ReturnFalse
+    pop     edi
+    mov     eax, 1                     ; return TRUE
+    ret
+@ReturnFalse:
+    pop     edi
+    xor     eax, eax
+    ret                                ; return FALSE
+
diff --git a/MdePkg/Library/BaseMemoryLibRepStr/IsZeroBufferWrapper.c b/MdePkg/Library/BaseMemoryLibRepStr/IsZeroBufferWrapper.c
new file mode 100644
index 0000000..c42c1aa
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibRepStr/IsZeroBufferWrapper.c
@@ -0,0 +1,54 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "MemLibInternals.h"
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+  return InternalMemIsZeroBuffer (Buffer, Length);
+}
diff --git a/MdePkg/Library/BaseMemoryLibRepStr/MemLibInternals.h b/MdePkg/Library/BaseMemoryLibRepStr/MemLibInternals.h
index cfca474..f795e83 100644
--- a/MdePkg/Library/BaseMemoryLibRepStr/MemLibInternals.h
+++ b/MdePkg/Library/BaseMemoryLibRepStr/MemLibInternals.h
@@ -9,7 +9,7 @@
     BaseMemoryLibOptDxe
     BaseMemoryLibOptPei
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -231,4 +231,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value
   );
 
+/**
+  Checks whether the contents of a buffer are all zeros.
+
+  @param  Buffer  The pointer to the buffer to be checked.
+  @param  Length  The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE    Contents of the buffer are all zeros.
+  @retval FALSE   Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+InternalMemIsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  );
+
 #endif
diff --git a/MdePkg/Library/BaseMemoryLibRepStr/X64/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibRepStr/X64/IsZeroBuffer.nasm
new file mode 100644
index 0000000..00b1067
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibRepStr/X64/IsZeroBuffer.nasm
@@ -0,0 +1,55 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution.  The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+;   IsZeroBuffer.nasm
+;
+; Abstract:
+;
+;   IsZeroBuffer function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+    DEFAULT REL
+    SECTION .text
+
+;------------------------------------------------------------------------------
+;  BOOLEAN
+;  EFIAPI
+;  InternalMemIsZeroBuffer (
+;    IN CONST VOID  *Buffer,
+;    IN UINTN       Length
+;    );
+;------------------------------------------------------------------------------
+global ASM_PFX(InternalMemIsZeroBuffer)
+ASM_PFX(InternalMemIsZeroBuffer):
+    push    rdi
+    mov     rdi, rcx                   ; rdi <- Buffer
+    mov     rcx, rdx                   ; rcx <- Length
+    shr     rcx, 3                     ; rcx <- number of qwords
+    and     rdx, 7                     ; rdx <- number of trailing bytes
+    xor     rax, rax                   ; rax <- 0, also set ZF
+    repe    scasq
+    jnz     @ReturnFalse               ; ZF=0 means non-zero element found
+    mov     rcx, rdx
+    repe    scasb
+    jnz     @ReturnFalse
+    pop     rdi
+    mov     rax, 1                     ; return TRUE
+    ret
+@ReturnFalse:
+    pop     rdi
+    xor     rax, rax
+    ret                                ; return FALSE
+
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 5/6] MdePkg BaseMemoryLibSse2: Add SSE2 implementation of API IsZeroBuffer()
  2016-08-18  4:53 [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib Hao Wu
                   ` (3 preceding siblings ...)
  2016-08-18  4:53 ` [PATCH v2 4/6] MdePkg BaseMemoryLib: Add assembly " Hao Wu
@ 2016-08-18  4:53 ` Hao Wu
  2016-08-18  4:54 ` [PATCH v2 6/6] SecurityPkg Tcg2: Remove use of module internal API InternalIsZeroBuffer() Hao Wu
  2016-08-22  6:12 ` [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib Gao, Liming
  6 siblings, 0 replies; 9+ messages in thread
From: Hao Wu @ 2016-08-18  4:53 UTC (permalink / raw)
  To: edk2-devel, liming.gao; +Cc: Hao Wu, Michael D Kinney, Jiewen Yao

Add the implementation of API IsZeroBuffer() via assembly in
BaseMemoryLibSse2.

The assembly codes use SSE2 XMM registers and related instructions.

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>
---
 .../BaseMemoryLibSse2/BaseMemoryLibSse2.inf        |  5 +-
 .../BaseMemoryLibSse2/Ia32/IsZeroBuffer.nasm       | 74 +++++++++++++++++++++
 .../BaseMemoryLibSse2/IsZeroBufferWrapper.c        | 54 +++++++++++++++
 MdePkg/Library/BaseMemoryLibSse2/MemLibInternals.h | 19 +++++-
 .../BaseMemoryLibSse2/X64/IsZeroBuffer.nasm        | 76 ++++++++++++++++++++++
 5 files changed, 226 insertions(+), 2 deletions(-)
 create mode 100644 MdePkg/Library/BaseMemoryLibSse2/Ia32/IsZeroBuffer.nasm
 create mode 100644 MdePkg/Library/BaseMemoryLibSse2/IsZeroBufferWrapper.c
 create mode 100644 MdePkg/Library/BaseMemoryLibSse2/X64/IsZeroBuffer.nasm

diff --git a/MdePkg/Library/BaseMemoryLibSse2/BaseMemoryLibSse2.inf b/MdePkg/Library/BaseMemoryLibSse2/BaseMemoryLibSse2.inf
index a78d823..fc82b16 100644
--- a/MdePkg/Library/BaseMemoryLibSse2/BaseMemoryLibSse2.inf
+++ b/MdePkg/Library/BaseMemoryLibSse2/BaseMemoryLibSse2.inf
@@ -3,7 +3,7 @@
 #
 #  Base Memory Library that uses SSE2 registers for high performance.
 #
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -42,6 +42,7 @@
   SetMem16Wrapper.c
   SetMemWrapper.c
   CopyMemWrapper.c
+  IsZeroBufferWrapper.c
   MemLibGuid.c
 
 [Sources.Ia32]
@@ -89,6 +90,7 @@
   Ia32/SetMem.asm
   Ia32/CopyMem.nasm
   Ia32/CopyMem.asm
+  Ia32/IsZeroBuffer.nasm
 
 [Sources.X64]
   X64/ScanMem64.nasm
@@ -135,6 +137,7 @@
   X64/SetMem.S
   X64/CopyMem.nasm
   X64/CopyMem.S
+  X64/IsZeroBuffer.nasm
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/MdePkg/Library/BaseMemoryLibSse2/Ia32/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibSse2/Ia32/IsZeroBuffer.nasm
new file mode 100644
index 0000000..68c09fe
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibSse2/Ia32/IsZeroBuffer.nasm
@@ -0,0 +1,74 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution.  The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+;   IsZeroBuffer.nasm
+;
+; Abstract:
+;
+;   IsZeroBuffer function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+    SECTION .text
+
+;------------------------------------------------------------------------------
+;  BOOLEAN
+;  EFIAPI
+;  InternalMemIsZeroBuffer (
+;    IN CONST VOID  *Buffer,
+;    IN UINTN       Length
+;    );
+;------------------------------------------------------------------------------
+global ASM_PFX(InternalMemIsZeroBuffer)
+ASM_PFX(InternalMemIsZeroBuffer):
+    push         edi
+    mov          edi, [esp + 8]        ; edi <- Buffer
+    mov          edx, [esp + 12]       ; edx <- Length
+    xor          ecx, ecx              ; ecx <- 0
+    sub          ecx, edi
+    and          ecx, 15               ; ecx + edi aligns on 16-byte boundary
+    jz           @Is16BytesZero
+    cmp          ecx, edx
+    cmova        ecx, edx              ; bytes before the 16-byte boundary
+    sub          edx, ecx
+    xor          eax, eax              ; eax <- 0, also set ZF
+    repe         scasb
+    jnz          @ReturnFalse          ; ZF=0 means non-zero element found
+@Is16BytesZero:
+    mov          ecx, edx
+    and          edx, 15
+    shr          ecx, 4
+    jz           @IsBytesZero
+.0:
+    pxor         xmm0, xmm0            ; xmm0 <- 0
+    pcmpeqb      xmm0, [edi]           ; check zero for 16 bytes
+    pmovmskb     eax, xmm0             ; eax <- compare results
+    cmp          eax, 0xffff
+    jnz          @ReturnFalse
+    add          edi, 16
+    loop         .0
+@IsBytesZero:
+    mov          ecx, edx
+    xor          eax, eax              ; eax <- 0, also set ZF
+    repe         scasb
+    jnz          @ReturnFalse          ; ZF=0 means non-zero element found
+    pop          edi
+    mov          eax, 1                ; return TRUE
+    ret
+@ReturnFalse:
+    pop          edi
+    xor          eax, eax
+    ret                                ; return FALSE
+
diff --git a/MdePkg/Library/BaseMemoryLibSse2/IsZeroBufferWrapper.c b/MdePkg/Library/BaseMemoryLibSse2/IsZeroBufferWrapper.c
new file mode 100644
index 0000000..c42c1aa
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibSse2/IsZeroBufferWrapper.c
@@ -0,0 +1,54 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "MemLibInternals.h"
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+  return InternalMemIsZeroBuffer (Buffer, Length);
+}
diff --git a/MdePkg/Library/BaseMemoryLibSse2/MemLibInternals.h b/MdePkg/Library/BaseMemoryLibSse2/MemLibInternals.h
index c8e80af..99fd515 100644
--- a/MdePkg/Library/BaseMemoryLibSse2/MemLibInternals.h
+++ b/MdePkg/Library/BaseMemoryLibSse2/MemLibInternals.h
@@ -9,7 +9,7 @@
     BaseMemoryLibOptDxe
     BaseMemoryLibOptPei
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -231,4 +231,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value
   );
 
+/**
+  Checks whether the contents of a buffer are all zeros.
+
+  @param  Buffer  The pointer to the buffer to be checked.
+  @param  Length  The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE    Contents of the buffer are all zeros.
+  @retval FALSE   Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+InternalMemIsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  );
+
 #endif
diff --git a/MdePkg/Library/BaseMemoryLibSse2/X64/IsZeroBuffer.nasm b/MdePkg/Library/BaseMemoryLibSse2/X64/IsZeroBuffer.nasm
new file mode 100644
index 0000000..3a0dc6f
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibSse2/X64/IsZeroBuffer.nasm
@@ -0,0 +1,76 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution.  The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+;   IsZeroBuffer.nasm
+;
+; Abstract:
+;
+;   IsZeroBuffer function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+    DEFAULT REL
+    SECTION .text
+
+;------------------------------------------------------------------------------
+;  BOOLEAN
+;  EFIAPI
+;  InternalMemIsZeroBuffer (
+;    IN CONST VOID  *Buffer,
+;    IN UINTN       Length
+;    );
+;------------------------------------------------------------------------------
+global ASM_PFX(InternalMemIsZeroBuffer)
+ASM_PFX(InternalMemIsZeroBuffer):
+    push         rdi
+    mov          rdi, rcx              ; rdi <- Buffer
+    xor          rcx, rcx              ; rcx <- 0
+    sub          rcx, rdi
+    and          rcx, 15               ; rcx + rdi aligns on 16-byte boundary
+    jz           @Is16BytesZero
+    cmp          rcx, rdx              ; Length already in rdx
+    cmova        rcx, rdx              ; bytes before the 16-byte boundary
+    sub          rdx, rcx
+    xor          rax, rax              ; rax <- 0, also set ZF
+    repe         scasb
+    jnz          @ReturnFalse          ; ZF=0 means non-zero element found
+@Is16BytesZero:
+    mov          rcx, rdx
+    and          rdx, 15
+    shr          rcx, 4
+    jz           @IsBytesZero
+.0:
+    pxor         xmm0, xmm0            ; xmm0 <- 0
+    pcmpeqb      xmm0, [rdi]           ; check zero for 16 bytes
+    pmovmskb     eax, xmm0             ; eax <- compare results
+                                       ; nasm doesn't support 64-bit destination
+                                       ; for pmovmskb
+    cmp          eax, 0xffff
+    jnz          @ReturnFalse
+    add          rdi, 16
+    loop         .0
+@IsBytesZero:
+    mov          rcx, rdx
+    xor          rax, rax              ; rax <- 0, also set ZF
+    repe         scasb
+    jnz          @ReturnFalse          ; ZF=0 means non-zero element found
+    pop          rdi
+    mov          rax, 1                ; return TRUE
+    ret
+@ReturnFalse:
+    pop          rdi
+    xor          rax, rax
+    ret                                ; return FALSE
+
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 6/6] SecurityPkg Tcg2: Remove use of module internal API InternalIsZeroBuffer()
  2016-08-18  4:53 [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib Hao Wu
                   ` (4 preceding siblings ...)
  2016-08-18  4:53 ` [PATCH v2 5/6] MdePkg BaseMemoryLibSse2: Add SSE2 " Hao Wu
@ 2016-08-18  4:54 ` Hao Wu
  2016-08-18  5:05   ` Zhang, Chao B
  2016-08-22  6:12 ` [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib Gao, Liming
  6 siblings, 1 reply; 9+ messages in thread
From: Hao Wu @ 2016-08-18  4:54 UTC (permalink / raw)
  To: edk2-devel, liming.gao; +Cc: Hao Wu, Jiewen Yao, Chao Zhang

This commit removes the internal implementation of the function
InternalIsZeroBuffer(). Instead, it will use the API IsZeroBuffer() from
BaseMemoryLib in MdePkg.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c | 29 +---------------------
 SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c           | 37 ++++-------------------------
 SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c           | 37 ++++-------------------------
 3 files changed, 11 insertions(+), 92 deletions(-)

diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
index 7a97f6b..5f4420c 100644
--- a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
+++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
@@ -617,33 +617,6 @@ FillBufferWithTCG2EventLogFormat (
 }
 
 /**
-  Check if buffer is all zero.
-
-  @param[in] Buffer      Buffer to be checked.
-  @param[in] BufferSize  Size of buffer to be checked.
-
-  @retval TRUE  Buffer is all zero.
-  @retval FALSE Buffer is not all zero.
-**/
-BOOLEAN
-InternalIsZeroBuffer (
-  IN VOID  *Buffer,
-  IN UINTN BufferSize
-  )
-{
-  UINT8 *BufferData;
-  UINTN Index;
-
-  BufferData = Buffer;
-  for (Index = 0; Index < BufferSize; Index++) {
-    if (BufferData[Index] != 0) {
-      return FALSE;
-    }
-  }
-  return TRUE;
-}
-
-/**
   This function publish the TCG2 configuration Form for TPM device.
 
   @param[in, out]  PrivateData   Points to TCG2 configuration private data.
@@ -735,7 +708,7 @@ InstallTcg2ConfigForm (
   } else {
     TempBuffer[0] = 0;
     for (Index = 0; Index < Pcrs.count; Index++) {
-      if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+      if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
         AppendBufferWithTpmAlgHash (TempBuffer, sizeof(TempBuffer), Pcrs.pcrSelections[Index].hash);
       }
     }
diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
index 5d97556..319f245 100644
--- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
+++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
@@ -202,33 +202,6 @@ InternalDumpHex (
 }
 
 /**
-  Check if buffer is all zero.
-
-  @param[in] Buffer      Buffer to be checked.
-  @param[in] BufferSize  Size of buffer to be checked.
-
-  @retval TRUE  Buffer is all zero.
-  @retval FALSE Buffer is not all zero.
-**/
-BOOLEAN
-InternalIsZeroBuffer (
-  IN VOID  *Buffer,
-  IN UINTN BufferSize
-  )
-{
-  UINT8 *BufferData;
-  UINTN Index;
-
-  BufferData = Buffer;
-  for (Index = 0; Index < BufferSize; Index++) {
-    if (BufferData[Index] != 0) {
-      return FALSE;
-    }
-  }
-  return TRUE;
-}
-
-/**
   Get All processors EFI_CPU_LOCATION in system. LocationBuf is allocated inside the function
   Caller is responsible to free LocationBuf.
 
@@ -2471,31 +2444,31 @@ DriverEntry (
       switch (Pcrs.pcrSelections[Index].hash) {
       case TPM_ALG_SHA1:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SHA1;
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA1;
         }        
         break;
       case TPM_ALG_SHA256:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SHA256;
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA256;
         }
         break;
       case TPM_ALG_SHA384:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SHA384;
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA384;
         }
         break;
       case TPM_ALG_SHA512:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SHA512;
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA512;
         }
         break;
       case TPM_ALG_SM3_256:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SM3_256;
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SM3_256;
         }
         break;
diff --git a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
index 2cffed4..0d779f1 100644
--- a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
+++ b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
@@ -225,33 +225,6 @@ EndofPeiSignalNotifyCallBack (
 }
 
 /**
-  Check if buffer is all zero.
-
-  @param[in] Buffer      Buffer to be checked.
-  @param[in] BufferSize  Size of buffer to be checked.
-
-  @retval TRUE  Buffer is all zero.
-  @retval FALSE Buffer is not all zero.
-**/
-BOOLEAN
-InternalIsZeroBuffer (
-  IN VOID  *Buffer,
-  IN UINTN BufferSize
-  )
-{
-  UINT8 *BufferData;
-  UINTN Index;
-
-  BufferData = Buffer;
-  for (Index = 0; Index < BufferSize; Index++) {
-    if (BufferData[Index] != 0) {
-      return FALSE;
-    }
-  }
-  return TRUE;
-}
-
-/**
   Get TPML_DIGEST_VALUES data size.
 
   @param[in]     DigestList    TPML_DIGEST_VALUES data.
@@ -383,27 +356,27 @@ SetTpm2HashMask (
       DEBUG ((EFI_D_INFO, "hash - %x\n", Pcrs.pcrSelections[Index].hash));
       switch (Pcrs.pcrSelections[Index].hash) {
       case TPM_ALG_SHA1:
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA1;
         }        
         break;
       case TPM_ALG_SHA256:
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA256;
         }
         break;
       case TPM_ALG_SHA384:
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA384;
         }
         break;
       case TPM_ALG_SHA512:
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA512;
         }
         break;
       case TPM_ALG_SM3_256:
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SM3_256;
         }
         break;
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 6/6] SecurityPkg Tcg2: Remove use of module internal API InternalIsZeroBuffer()
  2016-08-18  4:54 ` [PATCH v2 6/6] SecurityPkg Tcg2: Remove use of module internal API InternalIsZeroBuffer() Hao Wu
@ 2016-08-18  5:05   ` Zhang, Chao B
  0 siblings, 0 replies; 9+ messages in thread
From: Zhang, Chao B @ 2016-08-18  5:05 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org, Gao, Liming; +Cc: Yao, Jiewen

Serial reviewed-by: Chao Zhang<chao.b.zhang@intel.om>





Thanks & Best regards
Chao Zhang

-----Original Message-----
From: Wu, Hao A 
Sent: Thursday, August 18, 2016 12:54 PM
To: edk2-devel@lists.01.org; Gao, Liming
Cc: Wu, Hao A; Yao, Jiewen; Zhang, Chao B
Subject: [PATCH v2 6/6] SecurityPkg Tcg2: Remove use of module internal API InternalIsZeroBuffer()

This commit removes the internal implementation of the function
InternalIsZeroBuffer(). Instead, it will use the API IsZeroBuffer() from
BaseMemoryLib in MdePkg.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c | 29 +---------------------
 SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c           | 37 ++++-------------------------
 SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c           | 37 ++++-------------------------
 3 files changed, 11 insertions(+), 92 deletions(-)

diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
index 7a97f6b..5f4420c 100644
--- a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
+++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
@@ -617,33 +617,6 @@ FillBufferWithTCG2EventLogFormat (
 }
 
 /**
-  Check if buffer is all zero.
-
-  @param[in] Buffer      Buffer to be checked.
-  @param[in] BufferSize  Size of buffer to be checked.
-
-  @retval TRUE  Buffer is all zero.
-  @retval FALSE Buffer is not all zero.
-**/
-BOOLEAN
-InternalIsZeroBuffer (
-  IN VOID  *Buffer,
-  IN UINTN BufferSize
-  )
-{
-  UINT8 *BufferData;
-  UINTN Index;
-
-  BufferData = Buffer;
-  for (Index = 0; Index < BufferSize; Index++) {
-    if (BufferData[Index] != 0) {
-      return FALSE;
-    }
-  }
-  return TRUE;
-}
-
-/**
   This function publish the TCG2 configuration Form for TPM device.
 
   @param[in, out]  PrivateData   Points to TCG2 configuration private data.
@@ -735,7 +708,7 @@ InstallTcg2ConfigForm (
   } else {
     TempBuffer[0] = 0;
     for (Index = 0; Index < Pcrs.count; Index++) {
-      if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+      if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
         AppendBufferWithTpmAlgHash (TempBuffer, sizeof(TempBuffer), Pcrs.pcrSelections[Index].hash);
       }
     }
diff --git a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
index 5d97556..319f245 100644
--- a/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
+++ b/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c
@@ -202,33 +202,6 @@ InternalDumpHex (
 }
 
 /**
-  Check if buffer is all zero.
-
-  @param[in] Buffer      Buffer to be checked.
-  @param[in] BufferSize  Size of buffer to be checked.
-
-  @retval TRUE  Buffer is all zero.
-  @retval FALSE Buffer is not all zero.
-**/
-BOOLEAN
-InternalIsZeroBuffer (
-  IN VOID  *Buffer,
-  IN UINTN BufferSize
-  )
-{
-  UINT8 *BufferData;
-  UINTN Index;
-
-  BufferData = Buffer;
-  for (Index = 0; Index < BufferSize; Index++) {
-    if (BufferData[Index] != 0) {
-      return FALSE;
-    }
-  }
-  return TRUE;
-}
-
-/**
   Get All processors EFI_CPU_LOCATION in system. LocationBuf is allocated inside the function
   Caller is responsible to free LocationBuf.
 
@@ -2471,31 +2444,31 @@ DriverEntry (
       switch (Pcrs.pcrSelections[Index].hash) {
       case TPM_ALG_SHA1:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SHA1;
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA1;
         }        
         break;
       case TPM_ALG_SHA256:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SHA256;
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA256;
         }
         break;
       case TPM_ALG_SHA384:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SHA384;
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA384;
         }
         break;
       case TPM_ALG_SHA512:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SHA512;
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA512;
         }
         break;
       case TPM_ALG_SM3_256:
         TpmHashAlgorithmBitmap |= EFI_TCG2_BOOT_HASH_ALG_SM3_256;
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePCRBanks |= EFI_TCG2_BOOT_HASH_ALG_SM3_256;
         }
         break;
diff --git a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
index 2cffed4..0d779f1 100644
--- a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
+++ b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c
@@ -225,33 +225,6 @@ EndofPeiSignalNotifyCallBack (
 }
 
 /**
-  Check if buffer is all zero.
-
-  @param[in] Buffer      Buffer to be checked.
-  @param[in] BufferSize  Size of buffer to be checked.
-
-  @retval TRUE  Buffer is all zero.
-  @retval FALSE Buffer is not all zero.
-**/
-BOOLEAN
-InternalIsZeroBuffer (
-  IN VOID  *Buffer,
-  IN UINTN BufferSize
-  )
-{
-  UINT8 *BufferData;
-  UINTN Index;
-
-  BufferData = Buffer;
-  for (Index = 0; Index < BufferSize; Index++) {
-    if (BufferData[Index] != 0) {
-      return FALSE;
-    }
-  }
-  return TRUE;
-}
-
-/**
   Get TPML_DIGEST_VALUES data size.
 
   @param[in]     DigestList    TPML_DIGEST_VALUES data.
@@ -383,27 +356,27 @@ SetTpm2HashMask (
       DEBUG ((EFI_D_INFO, "hash - %x\n", Pcrs.pcrSelections[Index].hash));
       switch (Pcrs.pcrSelections[Index].hash) {
       case TPM_ALG_SHA1:
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA1;
         }        
         break;
       case TPM_ALG_SHA256:
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA256;
         }
         break;
       case TPM_ALG_SHA384:
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA384;
         }
         break;
       case TPM_ALG_SHA512:
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SHA512;
         }
         break;
       case TPM_ALG_SM3_256:
-        if (!InternalIsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
+        if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
           ActivePcrBanks |= EFI_TCG2_BOOT_HASH_ALG_SM3_256;
         }
         break;
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib
  2016-08-18  4:53 [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib Hao Wu
                   ` (5 preceding siblings ...)
  2016-08-18  4:54 ` [PATCH v2 6/6] SecurityPkg Tcg2: Remove use of module internal API InternalIsZeroBuffer() Hao Wu
@ 2016-08-22  6:12 ` Gao, Liming
  6 siblings, 0 replies; 9+ messages in thread
From: Gao, Liming @ 2016-08-22  6:12 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org; +Cc: Wu, Hao A

Reviewed-by: Liming Gao <liming.gao@intel.com>

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Hao Wu
> Sent: Thursday, August 18, 2016 12:54 PM
> To: edk2-devel@lists.01.org; Gao, Liming <liming.gao@intel.com>
> Cc: Wu, Hao A <hao.a.wu@intel.com>
> Subject: [edk2] [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in
> BaseMemoryLib
> 
> Changes made comparing V1:
> 1. Use assembly to implement the IsZeroBuffer() API for the following
> library instances:
> BaseMemoryLibMmx
> BaseMemoryLibOptDxe
> BaseMemoryLibOptPei
> BaseMemoryLibRepStr
> BaseMemoryLibSse2
> 
> 2. Utilize XMM regesters and related instructions in assembly codes for
> BaseMemoryLibSse2 library instance.
> 
> 3. Modify patches for SecurityPkg to avoid breaking bisection between
> patches.
> 
> Hao Wu (6):
>   MdePkg BaseMemoryLib: Add implementation of API IsZeroGuid()
>   SecurityPkg Tcg2: Rename internal API IsZeroBuffer to
>     InternalIsZeroBuffer
>   MdePkg BaseMemoryLib: Add C implementation of API IsZeroBuffer()
>   MdePkg BaseMemoryLib: Add assembly implementation of API
>     IsZeroBuffer()
>   MdePkg BaseMemoryLibSse2: Add SSE2 implementation of API
>     IsZeroBuffer()
>   SecurityPkg Tcg2: Remove use of module internal API
>     InternalIsZeroBuffer()
> 
>  MdePkg/Include/Library/BaseMemoryLib.h             | 45 ++++++++++++-
>  MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf     |  3 +-
>  MdePkg/Library/BaseMemoryLib/IsZeroBufferWrapper.c | 54
> +++++++++++++++
>  MdePkg/Library/BaseMemoryLib/MemLibGeneric.c       | 31 ++++++++-
>  MdePkg/Library/BaseMemoryLib/MemLibGuid.c          | 31 ++++++++-
>  MdePkg/Library/BaseMemoryLib/MemLibInternals.h     | 19 +++++-
>  .../Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf  |  5 +-
>  .../BaseMemoryLibMmx/Ia32/IsZeroBuffer.nasm        | 55
> ++++++++++++++++
>  .../Library/BaseMemoryLibMmx/IsZeroBufferWrapper.c | 54
> +++++++++++++++
>  MdePkg/Library/BaseMemoryLibMmx/MemLibGuid.c       | 31 ++++++++-
>  MdePkg/Library/BaseMemoryLibMmx/MemLibInternals.h  | 19 +++++-
>  .../Library/BaseMemoryLibMmx/X64/IsZeroBuffer.nasm | 55
> ++++++++++++++++
>  .../BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf    |  6 +-
>  .../BaseMemoryLibOptDxe/Ia32/IsZeroBuffer.nasm     | 55
> ++++++++++++++++
>  .../BaseMemoryLibOptDxe/IsZeroBufferWrapper.c      | 54
> +++++++++++++++
>  MdePkg/Library/BaseMemoryLibOptDxe/MemLibGuid.c    | 31 ++++++++-
>  .../Library/BaseMemoryLibOptDxe/MemLibInternals.h  | 19 +++++-
>  .../BaseMemoryLibOptDxe/X64/IsZeroBuffer.nasm      | 55
> ++++++++++++++++
>  .../BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf    |  6 +-
>  .../BaseMemoryLibOptPei/Ia32/IsZeroBuffer.nasm     | 55
> ++++++++++++++++
>  .../BaseMemoryLibOptPei/IsZeroBufferWrapper.c      | 54
> +++++++++++++++
>  MdePkg/Library/BaseMemoryLibOptPei/MemLibGuid.c    | 31 ++++++++-
>  .../Library/BaseMemoryLibOptPei/MemLibInternals.h  | 19 +++++-
>  .../BaseMemoryLibOptPei/X64/IsZeroBuffer.nasm      | 55
> ++++++++++++++++
>  .../BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf    |  5 +-
>  .../BaseMemoryLibRepStr/Ia32/IsZeroBuffer.nasm     | 55
> ++++++++++++++++
>  .../BaseMemoryLibRepStr/IsZeroBufferWrapper.c      | 54
> +++++++++++++++
>  MdePkg/Library/BaseMemoryLibRepStr/MemLibGuid.c    | 31 ++++++++-
>  .../Library/BaseMemoryLibRepStr/MemLibInternals.h  | 19 +++++-
>  .../BaseMemoryLibRepStr/X64/IsZeroBuffer.nasm      | 55
> ++++++++++++++++
>  .../BaseMemoryLibSse2/BaseMemoryLibSse2.inf        |  5 +-
>  .../BaseMemoryLibSse2/Ia32/IsZeroBuffer.nasm       | 74
> +++++++++++++++++++++
>  .../BaseMemoryLibSse2/IsZeroBufferWrapper.c        | 54 +++++++++++++++
>  MdePkg/Library/BaseMemoryLibSse2/MemLibGuid.c      | 31 ++++++++-
>  MdePkg/Library/BaseMemoryLibSse2/MemLibInternals.h | 19 +++++-
>  .../BaseMemoryLibSse2/X64/IsZeroBuffer.nasm        | 76
> ++++++++++++++++++++++
>  MdePkg/Library/PeiMemoryLib/IsZeroBufferWrapper.c  | 54
> +++++++++++++++
>  MdePkg/Library/PeiMemoryLib/MemLibGeneric.c        | 31 ++++++++-
>  MdePkg/Library/PeiMemoryLib/MemLibGuid.c           | 31 ++++++++-
>  MdePkg/Library/PeiMemoryLib/MemLibInternals.h      | 19 +++++-
>  MdePkg/Library/PeiMemoryLib/PeiMemoryLib.inf       |  3 +-
>  MdePkg/Library/UefiMemoryLib/IsZeroBufferWrapper.c | 54
> +++++++++++++++
>  MdePkg/Library/UefiMemoryLib/MemLibGeneric.c       | 31 ++++++++-
>  MdePkg/Library/UefiMemoryLib/MemLibGuid.c          | 31 ++++++++-
>  MdePkg/Library/UefiMemoryLib/MemLibInternals.h     | 19 +++++-
>  MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf     |  3 +-
>  SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c        | 27 --------
>  SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c                  | 27 --------
>  SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c                  | 27 --------
>  49 files changed, 1568 insertions(+), 109 deletions(-)
>  create mode 100644
> MdePkg/Library/BaseMemoryLib/IsZeroBufferWrapper.c
>  create mode 100644
> MdePkg/Library/BaseMemoryLibMmx/Ia32/IsZeroBuffer.nasm
>  create mode 100644
> MdePkg/Library/BaseMemoryLibMmx/IsZeroBufferWrapper.c
>  create mode 100644
> MdePkg/Library/BaseMemoryLibMmx/X64/IsZeroBuffer.nasm
>  create mode 100644
> MdePkg/Library/BaseMemoryLibOptDxe/Ia32/IsZeroBuffer.nasm
>  create mode 100644
> MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBufferWrapper.c
>  create mode 100644
> MdePkg/Library/BaseMemoryLibOptDxe/X64/IsZeroBuffer.nasm
>  create mode 100644
> MdePkg/Library/BaseMemoryLibOptPei/Ia32/IsZeroBuffer.nasm
>  create mode 100644
> MdePkg/Library/BaseMemoryLibOptPei/IsZeroBufferWrapper.c
>  create mode 100644
> MdePkg/Library/BaseMemoryLibOptPei/X64/IsZeroBuffer.nasm
>  create mode 100644
> MdePkg/Library/BaseMemoryLibRepStr/Ia32/IsZeroBuffer.nasm
>  create mode 100644
> MdePkg/Library/BaseMemoryLibRepStr/IsZeroBufferWrapper.c
>  create mode 100644
> MdePkg/Library/BaseMemoryLibRepStr/X64/IsZeroBuffer.nasm
>  create mode 100644
> MdePkg/Library/BaseMemoryLibSse2/Ia32/IsZeroBuffer.nasm
>  create mode 100644
> MdePkg/Library/BaseMemoryLibSse2/IsZeroBufferWrapper.c
>  create mode 100644
> MdePkg/Library/BaseMemoryLibSse2/X64/IsZeroBuffer.nasm
>  create mode 100644 MdePkg/Library/PeiMemoryLib/IsZeroBufferWrapper.c
>  create mode 100644
> MdePkg/Library/UefiMemoryLib/IsZeroBufferWrapper.c
> 
> --
> 1.9.5.msysgit.0
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-08-22  6:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-18  4:53 [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib Hao Wu
2016-08-18  4:53 ` [PATCH v2 1/6] MdePkg BaseMemoryLib: Add implementation of API IsZeroGuid() Hao Wu
2016-08-18  4:53 ` [PATCH v2 2/6] SecurityPkg Tcg2: Rename internal API IsZeroBuffer to InternalIsZeroBuffer Hao Wu
2016-08-18  4:53 ` [PATCH v2 3/6] MdePkg BaseMemoryLib: Add C implementation of API IsZeroBuffer() Hao Wu
2016-08-18  4:53 ` [PATCH v2 4/6] MdePkg BaseMemoryLib: Add assembly " Hao Wu
2016-08-18  4:53 ` [PATCH v2 5/6] MdePkg BaseMemoryLibSse2: Add SSE2 " Hao Wu
2016-08-18  4:54 ` [PATCH v2 6/6] SecurityPkg Tcg2: Remove use of module internal API InternalIsZeroBuffer() Hao Wu
2016-08-18  5:05   ` Zhang, Chao B
2016-08-22  6:12 ` [PATCH v2 0/6] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox