summaryrefslogtreecommitdiff
path: root/Core/MdePkg/Library/BaseMemoryLibSse2/X64
diff options
context:
space:
mode:
Diffstat (limited to 'Core/MdePkg/Library/BaseMemoryLibSse2/X64')
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/CompareMem.S59
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/CompareMem.asm54
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/CopyMem.S83
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/CopyMem.asm79
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem16.S56
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem16.asm53
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem32.S56
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem32.asm53
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem64.S56
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem64.asm53
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem8.S56
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem8.asm53
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem.S72
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem.asm69
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem16.S70
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem16.asm67
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem32.S69
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem32.asm66
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem64.S60
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem64.asm59
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/ZeroMem.S65
-rw-r--r--Core/MdePkg/Library/BaseMemoryLibSse2/X64/ZeroMem.asm63
22 files changed, 1371 insertions, 0 deletions
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/CompareMem.S b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/CompareMem.S
new file mode 100644
index 0000000000..26ed8dd866
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/CompareMem.S
@@ -0,0 +1,59 @@
+#
+# ConvertAsm.py: Automatically generated from CompareMem.asm
+#
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2009, 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:
+#
+# CompareMem.S
+#
+# Abstract:
+#
+# CompareMem function
+#
+# Notes:
+#
+# The following BaseMemoryLib instances contain the same copy of this file:
+#
+# BaseMemoryLibRepStr
+# BaseMemoryLibMmx
+# BaseMemoryLibSse2
+# BaseMemoryLibOptDxe
+# BaseMemoryLibOptPei
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# INTN
+# EFIAPI
+# InternalMemCompareMem (
+# IN CONST VOID *DestinationBuffer,
+# IN CONST VOID *SourceBuffer,
+# IN UINTN Length
+# );
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(InternalMemCompareMem)
+ASM_PFX(InternalMemCompareMem):
+ pushq %rsi
+ pushq %rdi
+ movq %rcx, %rsi
+ movq %rdx, %rdi
+ movq %r8, %rcx
+ repe cmpsb
+ movzbq -1(%rsi) , %rax
+ movzbq -1(%rdi) , %rdx
+ subq %rdx, %rax
+ popq %rdi
+ popq %rsi
+ ret
+
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/CompareMem.asm b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/CompareMem.asm
new file mode 100644
index 0000000000..0ef05b2fa2
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/CompareMem.asm
@@ -0,0 +1,54 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006 - 2008, 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:
+;
+; CompareMem.Asm
+;
+; Abstract:
+;
+; CompareMem function
+;
+; Notes:
+;
+; The following BaseMemoryLib instances contain the same copy of this file:
+;
+; BaseMemoryLibRepStr
+; BaseMemoryLibMmx
+; BaseMemoryLibSse2
+; BaseMemoryLibOptDxe
+; BaseMemoryLibOptPei
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;------------------------------------------------------------------------------
+; INTN
+; EFIAPI
+; InternalMemCompareMem (
+; IN CONST VOID *DestinationBuffer,
+; IN CONST VOID *SourceBuffer,
+; IN UINTN Length
+; );
+;------------------------------------------------------------------------------
+InternalMemCompareMem PROC USES rsi rdi
+ mov rsi, rcx
+ mov rdi, rdx
+ mov rcx, r8
+ repe cmpsb
+ movzx rax, byte ptr [rsi - 1]
+ movzx rdx, byte ptr [rdi - 1]
+ sub rax, rdx
+ ret
+InternalMemCompareMem ENDP
+
+ END
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/CopyMem.S b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/CopyMem.S
new file mode 100644
index 0000000000..d8a58a7070
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/CopyMem.S
@@ -0,0 +1,83 @@
+#
+# ConvertAsm.py: Automatically generated from CopyMem.asm
+#
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2009, 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:
+#
+# CopyMem.S
+#
+# Abstract:
+#
+# CopyMem function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID *
+# EFIAPI
+# InternalMemCopyMem (
+# IN VOID *Destination,
+# IN VOID *Source,
+# IN UINTN Count
+# )
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(InternalMemCopyMem)
+ASM_PFX(InternalMemCopyMem):
+ pushq %rsi
+ pushq %rdi
+ movq %rdx, %rsi # rsi <- Source
+ movq %rcx, %rdi # rdi <- Destination
+ leaq -1(%rsi, %r8,), %r9 # r9 <- Last byte of Source
+ cmpq %rdi, %rsi
+ movq %rdi, %rax # rax <- Destination as return value
+ jae L0 # Copy forward if Source > Destination
+ cmpq %rdi, %r9 # Overlapped?
+ jae L_CopyBackward # Copy backward if overlapped
+L0:
+ xorq %rcx, %rcx
+ subq %rdi, %rcx # rcx <- -rdi
+ andq $15, %rcx # rcx + rsi should be 16 bytes aligned
+ jz L1 # skip if rcx == 0
+ cmpq %r8, %rcx
+ cmova %r8, %rcx
+ subq %rcx, %r8
+ rep movsb
+L1:
+ movq %r8, %rcx
+ andq $15, %r8
+ shrq $4, %rcx # rcx <- # of DQwords to copy
+ jz L_CopyBytes
+ movdqa %xmm0, 0x18(%rsp) # save xmm0 on stack
+L2:
+ movdqu (%rsi), %xmm0 # rsi may not be 16-byte aligned
+ movntdq %xmm0, (%rdi) # rdi should be 16-byte aligned
+ addq $16, %rsi
+ addq $16, %rdi
+ loop L2
+ mfence
+ movdqa 0x18(%rsp), %xmm0 # restore xmm0
+ jmp L_CopyBytes # copy remaining bytes
+L_CopyBackward:
+ movq %r9, %rsi # rsi <- Last byte of Source
+ leaq -1(%rdi, %r8,), %rdi # rdi <- Last byte of Destination
+ std
+L_CopyBytes:
+ movq %r8, %rcx
+ rep movsb
+ cld
+ popq %rdi
+ popq %rsi
+ ret
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/CopyMem.asm b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/CopyMem.asm
new file mode 100644
index 0000000000..8bcaca7cbe
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/CopyMem.asm
@@ -0,0 +1,79 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006, 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:
+;
+; CopyMem.asm
+;
+; Abstract:
+;
+; CopyMem function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;------------------------------------------------------------------------------
+; VOID *
+; EFIAPI
+; InternalMemCopyMem (
+; IN VOID *Destination,
+; IN VOID *Source,
+; IN UINTN Count
+; );
+;------------------------------------------------------------------------------
+InternalMemCopyMem PROC USES rsi rdi
+ mov rsi, rdx ; rsi <- Source
+ mov rdi, rcx ; rdi <- Destination
+ lea r9, [rsi + r8 - 1] ; r9 <- Last byte of Source
+ cmp rsi, rdi
+ mov rax, rdi ; rax <- Destination as return value
+ jae @F ; Copy forward if Source > Destination
+ cmp r9, rdi ; Overlapped?
+ jae @CopyBackward ; Copy backward if overlapped
+@@:
+ xor rcx, rcx
+ sub rcx, rdi ; rcx <- -rdi
+ and rcx, 15 ; rcx + rsi should be 16 bytes aligned
+ jz @F ; skip if rcx == 0
+ cmp rcx, r8
+ cmova rcx, r8
+ sub r8, rcx
+ rep movsb
+@@:
+ mov rcx, r8
+ and r8, 15
+ shr rcx, 4 ; rcx <- # of DQwords to copy
+ jz @CopyBytes
+ movdqa [rsp + 18h], xmm0 ; save xmm0 on stack
+@@:
+ movdqu xmm0, [rsi] ; rsi may not be 16-byte aligned
+ movntdq [rdi], xmm0 ; rdi should be 16-byte aligned
+ add rsi, 16
+ add rdi, 16
+ loop @B
+ mfence
+ movdqa xmm0, [rsp + 18h] ; restore xmm0
+ jmp @CopyBytes ; copy remaining bytes
+@CopyBackward:
+ mov rsi, r9 ; rsi <- Last byte of Source
+ lea rdi, [rdi + r8 - 1] ; rdi <- Last byte of Destination
+ std
+@CopyBytes:
+ mov rcx, r8
+ rep movsb
+ cld
+ ret
+InternalMemCopyMem ENDP
+
+ END
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem16.S b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem16.S
new file mode 100644
index 0000000000..282dc3cd12
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem16.S
@@ -0,0 +1,56 @@
+#
+# ConvertAsm.py: Automatically generated from ScanMem16.asm
+#
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2009, 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:
+#
+# ScanMem16.S
+#
+# Abstract:
+#
+# ScanMem16 function
+#
+# Notes:
+#
+# The following BaseMemoryLib instances contain the same copy of this file:
+#
+# BaseMemoryLibRepStr
+# BaseMemoryLibMmx
+# BaseMemoryLibSse2
+# BaseMemoryLibOptDxe
+# BaseMemoryLibOptPei
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# CONST VOID *
+# EFIAPI
+# InternalMemScanMem16 (
+# IN CONST VOID *Buffer,
+# IN UINTN Length,
+# IN UINT16 Value
+# );
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(InternalMemScanMem16)
+ASM_PFX(InternalMemScanMem16):
+ pushq %rdi
+ movq %rcx, %rdi
+ movq %rdx, %rcx
+ movq %r8, %rax
+ repne scasw
+ leaq -2(%rdi), %rax
+ cmovnz %rcx, %rax # set rax to 0 if not found
+ popq %rdi
+ ret
+
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem16.asm b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem16.asm
new file mode 100644
index 0000000000..a6114db134
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem16.asm
@@ -0,0 +1,53 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006 - 2008, 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:
+;
+; ScanMem16.Asm
+;
+; Abstract:
+;
+; ScanMem16 function
+;
+; Notes:
+;
+; The following BaseMemoryLib instances contain the same copy of this file:
+;
+; BaseMemoryLibRepStr
+; BaseMemoryLibMmx
+; BaseMemoryLibSse2
+; BaseMemoryLibOptDxe
+; BaseMemoryLibOptPei
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;------------------------------------------------------------------------------
+; CONST VOID *
+; EFIAPI
+; InternalMemScanMem16 (
+; IN CONST VOID *Buffer,
+; IN UINTN Length,
+; IN UINT16 Value
+; );
+;------------------------------------------------------------------------------
+InternalMemScanMem16 PROC USES rdi
+ mov rdi, rcx
+ mov rax, r8
+ mov rcx, rdx
+ repne scasw
+ lea rax, [rdi - 2]
+ cmovnz rax, rcx
+ ret
+InternalMemScanMem16 ENDP
+
+ END
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem32.S b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem32.S
new file mode 100644
index 0000000000..eb91dafb85
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem32.S
@@ -0,0 +1,56 @@
+#
+# ConvertAsm.py: Automatically generated from ScanMem32.asm
+#
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2009, 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:
+#
+# ScanMem32.S
+#
+# Abstract:
+#
+# ScanMem32 function
+#
+# Notes:
+#
+# The following BaseMemoryLib instances contain the same copy of this file:
+#
+# BaseMemoryLibRepStr
+# BaseMemoryLibMmx
+# BaseMemoryLibSse2
+# BaseMemoryLibOptDxe
+# BaseMemoryLibOptPei
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# CONST VOID *
+# EFIAPI
+# InternalMemScanMem32 (
+# IN CONST VOID *Buffer,
+# IN UINTN Length,
+# IN UINT32 Value
+# );
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(InternalMemScanMem32)
+ASM_PFX(InternalMemScanMem32):
+ pushq %rdi
+ movq %rcx, %rdi
+ movq %rdx, %rcx
+ movq %r8, %rax
+ repne scasl
+ leaq -4(%rdi), %rax
+ cmovnz %rcx, %rax # set rax to 0 if not found
+ popq %rdi
+ ret
+
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem32.asm b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem32.asm
new file mode 100644
index 0000000000..40ff6c9e93
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem32.asm
@@ -0,0 +1,53 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006 - 2008, 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:
+;
+; ScanMem32.Asm
+;
+; Abstract:
+;
+; ScanMem32 function
+;
+; Notes:
+;
+; The following BaseMemoryLib instances contain the same copy of this file:
+;
+; BaseMemoryLibRepStr
+; BaseMemoryLibMmx
+; BaseMemoryLibSse2
+; BaseMemoryLibOptDxe
+; BaseMemoryLibOptPei
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;------------------------------------------------------------------------------
+; CONST VOID *
+; EFIAPI
+; InternalMemScanMem32 (
+; IN CONST VOID *Buffer,
+; IN UINTN Length,
+; IN UINT32 Value
+; );
+;------------------------------------------------------------------------------
+InternalMemScanMem32 PROC USES rdi
+ mov rdi, rcx
+ mov rax, r8
+ mov rcx, rdx
+ repne scasd
+ lea rax, [rdi - 4]
+ cmovnz rax, rcx
+ ret
+InternalMemScanMem32 ENDP
+
+ END
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem64.S b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem64.S
new file mode 100644
index 0000000000..20d20aa3c3
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem64.S
@@ -0,0 +1,56 @@
+#
+# ConvertAsm.py: Automatically generated from ScanMem64.asm
+#
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2009, 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:
+#
+# ScanMem64.S
+#
+# Abstract:
+#
+# ScanMem64 function
+#
+# Notes:
+#
+# The following BaseMemoryLib instances contain the same copy of this file:
+#
+# BaseMemoryLibRepStr
+# BaseMemoryLibMmx
+# BaseMemoryLibSse2
+# BaseMemoryLibOptDxe
+# BaseMemoryLibOptPei
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# CONST VOID *
+# EFIAPI
+# InternalMemScanMem64 (
+# IN CONST VOID *Buffer,
+# IN UINTN Length,
+# IN UINT64 Value
+# );
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(InternalMemScanMem64)
+ASM_PFX(InternalMemScanMem64):
+ pushq %rdi
+ movq %rcx, %rdi
+ movq %rdx, %rcx
+ movq %r8, %rax
+ repne scasq
+ leaq -8(%rdi), %rax
+ cmovnz %rcx, %rax # set rax to 0 if not found
+ popq %rdi
+ ret
+
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem64.asm b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem64.asm
new file mode 100644
index 0000000000..e78da7d019
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem64.asm
@@ -0,0 +1,53 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006 - 2008, 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:
+;
+; ScanMem64.Asm
+;
+; Abstract:
+;
+; ScanMem64 function
+;
+; Notes:
+;
+; The following BaseMemoryLib instances contain the same copy of this file:
+;
+; BaseMemoryLibRepStr
+; BaseMemoryLibMmx
+; BaseMemoryLibSse2
+; BaseMemoryLibOptDxe
+; BaseMemoryLibOptPei
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;------------------------------------------------------------------------------
+; CONST VOID *
+; EFIAPI
+; InternalMemScanMem64 (
+; IN CONST VOID *Buffer,
+; IN UINTN Length,
+; IN UINT64 Value
+; );
+;------------------------------------------------------------------------------
+InternalMemScanMem64 PROC USES rdi
+ mov rdi, rcx
+ mov rax, r8
+ mov rcx, rdx
+ repne scasq
+ lea rax, [rdi - 8]
+ cmovnz rax, rcx
+ ret
+InternalMemScanMem64 ENDP
+
+ END
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem8.S b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem8.S
new file mode 100644
index 0000000000..b1715ea728
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem8.S
@@ -0,0 +1,56 @@
+#
+# ConvertAsm.py: Automatically generated from ScanMem8.asm
+#
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2009, 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:
+#
+# ScanMem8.S
+#
+# Abstract:
+#
+# ScanMem8 function
+#
+# Notes:
+#
+# The following BaseMemoryLib instances contain the same copy of this file:
+#
+# BaseMemoryLibRepStr
+# BaseMemoryLibMmx
+# BaseMemoryLibSse2
+# BaseMemoryLibOptDxe
+# BaseMemoryLibOptPei
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# CONST VOID *
+# EFIAPI
+# InternalMemScanMem8 (
+# IN CONST VOID *Buffer,
+# IN UINTN Length,
+# IN UINT8 Value
+# );
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(InternalMemScanMem8)
+ASM_PFX(InternalMemScanMem8):
+ pushq %rdi
+ movq %rcx, %rdi
+ movq %rdx, %rcx
+ movq %r8, %rax
+ repne scasb
+ leaq -1(%rdi), %rax
+ cmovnz %rcx, %rax # set rax to 0 if not found
+ popq %rdi
+ ret
+
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem8.asm b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem8.asm
new file mode 100644
index 0000000000..fee239701d
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ScanMem8.asm
@@ -0,0 +1,53 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006 - 2008, 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:
+;
+; ScanMem8.Asm
+;
+; Abstract:
+;
+; ScanMem8 function
+;
+; Notes:
+;
+; The following BaseMemoryLib instances contain the same copy of this file:
+;
+; BaseMemoryLibRepStr
+; BaseMemoryLibMmx
+; BaseMemoryLibSse2
+; BaseMemoryLibOptDxe
+; BaseMemoryLibOptPei
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;------------------------------------------------------------------------------
+; CONST VOID *
+; EFIAPI
+; InternalMemScanMem8 (
+; IN CONST VOID *Buffer,
+; IN UINTN Length,
+; IN UINT8 Value
+; );
+;------------------------------------------------------------------------------
+InternalMemScanMem8 PROC USES rdi
+ mov rdi, rcx
+ mov rcx, rdx
+ mov rax, r8
+ repne scasb
+ lea rax, [rdi - 1]
+ cmovnz rax, rcx ; set rax to 0 if not found
+ ret
+InternalMemScanMem8 ENDP
+
+ END
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem.S b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem.S
new file mode 100644
index 0000000000..eb4ce80e1e
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem.S
@@ -0,0 +1,72 @@
+#
+# ConvertAsm.py: Automatically generated from SetMem.asm
+#
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2009, 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:
+#
+# SetMem.S
+#
+# Abstract:
+#
+# SetMem function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID *
+# EFIAPI
+# InternalMemSetMem (
+# IN VOID *Buffer,
+# IN UINTN Count,
+# IN UINT8 Value
+# )
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(InternalMemSetMem)
+ASM_PFX(InternalMemSetMem):
+ pushq %rdi
+ movq %rcx, %rdi # rdi <- Buffer
+ movb %r8b, %al # al <- Value
+ movq %rdi, %r9 # r9 <- Buffer as return value
+ xorq %rcx, %rcx
+ subq %rdi, %rcx
+ andq $15, %rcx # rcx + rdi aligns on 16-byte boundary
+ jz L0
+ cmpq %rdx, %rcx
+ cmova %rdx, %rcx
+ subq %rcx, %rdx
+ rep stosb
+L0:
+ movq %rdx, %rcx
+ andq $15, %rdx
+ shrq $4, %rcx
+ jz L_SetBytes
+ movb %al, %ah # ax <- Value repeats twice
+ movdqa %xmm0, 0x10(%rsp) # save xmm0
+ movd %eax, %xmm0 # xmm0[0..16] <- Value repeats twice
+ pshuflw $0, %xmm0, %xmm0 # xmm0[0..63] <- Value repeats 8 times
+ movlhps %xmm0, %xmm0 # xmm0 <- Value repeats 16 times
+L1:
+ movntdq %xmm0, (%rdi) # rdi should be 16-byte aligned
+ add $16, %rdi
+ loop L1
+ mfence
+ movdqa 0x10(%rsp), %xmm0 # restore xmm0
+L_SetBytes:
+ movl %edx, %ecx # high 32 bits of rcx are always zero
+ rep stosb
+ movq %r9, %rax # rax <- Return value
+ popq %rdi
+ ret
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem.asm b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem.asm
new file mode 100644
index 0000000000..52b069c2bc
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem.asm
@@ -0,0 +1,69 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006, 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:
+;
+; SetMem.asm
+;
+; Abstract:
+;
+; SetMem function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;------------------------------------------------------------------------------
+; VOID *
+; InternalMemSetMem (
+; IN VOID *Buffer,
+; IN UINTN Count,
+; IN UINT8 Value
+; )
+;------------------------------------------------------------------------------
+InternalMemSetMem PROC USES rdi
+ mov rdi, rcx ; rdi <- Buffer
+ mov al, r8b ; al <- Value
+ mov r9, rdi ; r9 <- Buffer as return value
+ xor rcx, rcx
+ sub rcx, rdi
+ and rcx, 15 ; rcx + rdi aligns on 16-byte boundary
+ jz @F
+ cmp rcx, rdx
+ cmova rcx, rdx
+ sub rdx, rcx
+ rep stosb
+@@:
+ mov rcx, rdx
+ and rdx, 15
+ shr rcx, 4
+ jz @SetBytes
+ mov ah, al ; ax <- Value repeats twice
+ movdqa [rsp + 10h], xmm0 ; save xmm0
+ movd xmm0, eax ; xmm0[0..16] <- Value repeats twice
+ pshuflw xmm0, xmm0, 0 ; xmm0[0..63] <- Value repeats 8 times
+ movlhps xmm0, xmm0 ; xmm0 <- Value repeats 16 times
+@@:
+ movntdq [rdi], xmm0 ; rdi should be 16-byte aligned
+ add rdi, 16
+ loop @B
+ mfence
+ movdqa xmm0, [rsp + 10h] ; restore xmm0
+@SetBytes:
+ mov ecx, edx ; high 32 bits of rcx are always zero
+ rep stosb
+ mov rax, r9 ; rax <- Return value
+ ret
+InternalMemSetMem ENDP
+
+ END
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem16.S b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem16.S
new file mode 100644
index 0000000000..74fef09255
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem16.S
@@ -0,0 +1,70 @@
+#
+# ConvertAsm.py: Automatically generated from SetMem16.asm
+#
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2009, 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:
+#
+# SetMem16.S
+#
+# Abstract:
+#
+# SetMem16 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID *
+# EFIAPI
+# InternalMemSetMem16 (
+# IN VOID *Buffer,
+# IN UINTN Count,
+# IN UINT16 Value
+# )
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(InternalMemSetMem16)
+ASM_PFX(InternalMemSetMem16):
+ pushq %rdi
+ movq %rcx, %rdi
+ movq %rdi, %r9
+ xorq %rcx, %rcx
+ subq %rdi, %rcx
+ andq $15, %rcx
+ movq %r8, %rax
+ jz L0
+ shrq $1, %rcx
+ cmpq %rdx, %rcx
+ cmova %rdx, %rcx
+ subq %rcx, %rdx
+ rep stosw
+L0:
+ movq %rdx, %rcx
+ andl $7, %edx
+ shrq $3, %rcx
+ jz L_SetWords
+ movd %eax, %xmm0
+ pshuflw $0, %xmm0, %xmm0
+ movlhps %xmm0, %xmm0
+L1:
+ movntdq %xmm0, (%rdi)
+ addq $16, %rdi
+ loop L1
+ mfence
+L_SetWords:
+ movl %edx, %ecx
+ rep stosw
+ movq %r9, %rax
+ popq %rdi
+ ret
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem16.asm b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem16.asm
new file mode 100644
index 0000000000..8cb09acc45
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem16.asm
@@ -0,0 +1,67 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006, 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:
+;
+; SetMem16.asm
+;
+; Abstract:
+;
+; SetMem16 function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;------------------------------------------------------------------------------
+; VOID *
+; InternalMemSetMem16 (
+; IN VOID *Buffer,
+; IN UINTN Count,
+; IN UINT16 Value
+; )
+;------------------------------------------------------------------------------
+InternalMemSetMem16 PROC USES rdi
+ mov rdi, rcx
+ mov r9, rdi
+ xor rcx, rcx
+ sub rcx, rdi
+ and rcx, 15
+ mov rax, r8
+ jz @F
+ shr rcx, 1
+ cmp rcx, rdx
+ cmova rcx, rdx
+ sub rdx, rcx
+ rep stosw
+@@:
+ mov rcx, rdx
+ and edx, 7
+ shr rcx, 3
+ jz @SetWords
+ movd xmm0, eax
+ pshuflw xmm0, xmm0, 0
+ movlhps xmm0, xmm0
+@@:
+ movntdq [rdi], xmm0
+ add rdi, 16
+ loop @B
+ mfence
+@SetWords:
+ mov ecx, edx
+ rep stosw
+ mov rax, r9
+ ret
+InternalMemSetMem16 ENDP
+
+ END
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem32.S b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem32.S
new file mode 100644
index 0000000000..24103cf509
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem32.S
@@ -0,0 +1,69 @@
+#
+# ConvertAsm.py: Automatically generated from SetMem32.asm
+#
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2009, 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:
+#
+# SetMem32.S
+#
+# Abstract:
+#
+# SetMem32 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID *
+# EFIAPI
+# InternalMemSetMem32 (
+# IN VOID *Buffer,
+# IN UINTN Count,
+# IN UINT32 Value
+# );
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(InternalMemSetMem32)
+ASM_PFX(InternalMemSetMem32):
+ pushq %rdi
+ movq %rcx, %rdi
+ movq %rdi, %r9
+ xorq %rcx, %rcx
+ subq %rdi, %rcx
+ andq $15, %rcx
+ movq %r8, %rax
+ jz L0
+ shrq $2, %rcx
+ cmpq %rdx, %rcx
+ cmova %rdx, %rcx
+ subq %rcx, %rdx
+ rep stosl
+L0:
+ movq %rdx, %rcx
+ andl $3, %edx
+ shrq $2, %rcx
+ jz L_SetDwords
+ movd %eax, %xmm0
+ pshufd $0, %xmm0, %xmm0
+L1:
+ movntdq %xmm0, (%rdi)
+ addq $16, %rdi
+ loop L1
+ mfence
+L_SetDwords:
+ movl %edx, %ecx
+ rep stosl
+ movq %r9, %rax
+ popq %rdi
+ ret
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem32.asm b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem32.asm
new file mode 100644
index 0000000000..92404a004d
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem32.asm
@@ -0,0 +1,66 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006, 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:
+;
+; SetMem32.asm
+;
+; Abstract:
+;
+; SetMem32 function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;------------------------------------------------------------------------------
+; VOID *
+; InternalMemSetMem32 (
+; IN VOID *Buffer,
+; IN UINTN Count,
+; IN UINT8 Value
+; )
+;------------------------------------------------------------------------------
+InternalMemSetMem32 PROC USES rdi
+ mov rdi, rcx
+ mov r9, rdi
+ xor rcx, rcx
+ sub rcx, rdi
+ and rcx, 15
+ mov rax, r8
+ jz @F
+ shr rcx, 2
+ cmp rcx, rdx
+ cmova rcx, rdx
+ sub rdx, rcx
+ rep stosd
+@@:
+ mov rcx, rdx
+ and edx, 3
+ shr rcx, 2
+ jz @SetDwords
+ movd xmm0, eax
+ pshufd xmm0, xmm0, 0
+@@:
+ movntdq [rdi], xmm0
+ add rdi, 16
+ loop @B
+ mfence
+@SetDwords:
+ mov ecx, edx
+ rep stosd
+ mov rax, r9
+ ret
+InternalMemSetMem32 ENDP
+
+ END
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem64.S b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem64.S
new file mode 100644
index 0000000000..c44ec08ae6
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem64.S
@@ -0,0 +1,60 @@
+#
+# ConvertAsm.py: Automatically generated from SetMem64.asm
+#
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2009, 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:
+#
+# SetMem64.S
+#
+# Abstract:
+#
+# SetMem64 function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID *
+# InternalMemSetMem64 (
+# IN VOID *Buffer,
+# IN UINTN Count,
+# IN UINT64 Value
+# )
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(InternalMemSetMem64)
+ASM_PFX(InternalMemSetMem64):
+ movq %rcx, %rax # rax <- Buffer
+ xchgq %rdx, %rcx # rcx <- Count & rdx <- Buffer
+ testb $8, %dl
+ movd %r8, %xmm0
+ jz L0
+ movq %r8, (%rdx)
+ addq $8, %rdx
+ decq %rcx
+L0:
+ shrq $1, %rcx
+ jz L_SetQwords
+ movlhps %xmm0, %xmm0
+L1:
+ movntdq %xmm0, (%rdx)
+ leaq 16(%rdx), %rdx
+ loop L1
+ mfence
+L_SetQwords:
+ jnc L2
+ movq %r8, (%rdx)
+L2:
+ ret
+
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem64.asm b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem64.asm
new file mode 100644
index 0000000000..5071f6771f
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/SetMem64.asm
@@ -0,0 +1,59 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006, 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:
+;
+; SetMem64.asm
+;
+; Abstract:
+;
+; SetMem64 function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;------------------------------------------------------------------------------
+; VOID *
+; InternalMemSetMem64 (
+; IN VOID *Buffer,
+; IN UINTN Count,
+; IN UINT64 Value
+; )
+;------------------------------------------------------------------------------
+InternalMemSetMem64 PROC
+ mov rax, rcx ; rax <- Buffer
+ xchg rcx, rdx ; rcx <- Count & rdx <- Buffer
+ test dl, 8
+ movd xmm0, r8
+ jz @F
+ mov [rdx], r8
+ add rdx, 8
+ dec rcx
+@@:
+ shr rcx, 1
+ jz @SetQwords
+ movlhps xmm0, xmm0
+@@:
+ movntdq [rdx], xmm0
+ lea rdx, [rdx + 16]
+ loop @B
+ mfence
+@SetQwords:
+ jnc @F
+ mov [rdx], r8
+@@:
+ ret
+InternalMemSetMem64 ENDP
+
+ END
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ZeroMem.S b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ZeroMem.S
new file mode 100644
index 0000000000..3b00ce7309
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ZeroMem.S
@@ -0,0 +1,65 @@
+#
+# ConvertAsm.py: Automatically generated from ZeroMem.asm
+#
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2009, 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:
+#
+# ZeroMem.S
+#
+# Abstract:
+#
+# ZeroMem function
+#
+# Notes:
+#
+#------------------------------------------------------------------------------
+
+
+#------------------------------------------------------------------------------
+# VOID *
+# InternalMemZeroMem (
+# IN VOID *Buffer,
+# IN UINTN Count
+# );
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(InternalMemZeroMem)
+ASM_PFX(InternalMemZeroMem):
+ pushq %rdi
+ movq %rcx, %rdi
+ xorq %rcx, %rcx
+ xorl %eax, %eax
+ subq %rdi, %rcx
+ andq $15, %rcx
+ movq %rdi, %r8
+ jz L0
+ cmpq %rdx, %rcx
+ cmova %rdx, %rcx
+ subq %rcx, %rdx
+ rep stosb
+L0:
+ movq %rdx, %rcx
+ andl $15, %edx
+ shrq $4, %rcx
+ jz L_ZeroBytes
+ pxor %xmm0, %xmm0
+L1:
+ movntdq %xmm0, (%rdi) # rdi should be 16-byte aligned
+ addq $16, %rdi
+ loop L1
+ mfence
+L_ZeroBytes:
+ movl %edx, %ecx
+ rep stosb
+ movq %r8, %rax
+ popq %rdi
+ ret
diff --git a/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ZeroMem.asm b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ZeroMem.asm
new file mode 100644
index 0000000000..d304729068
--- /dev/null
+++ b/Core/MdePkg/Library/BaseMemoryLibSse2/X64/ZeroMem.asm
@@ -0,0 +1,63 @@
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006, 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:
+;
+; ZeroMem.asm
+;
+; Abstract:
+;
+; ZeroMem function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;------------------------------------------------------------------------------
+; VOID *
+; InternalMemZeroMem (
+; IN VOID *Buffer,
+; IN UINTN Count
+; )
+;------------------------------------------------------------------------------
+InternalMemZeroMem PROC USES rdi
+ mov rdi, rcx
+ xor rcx, rcx
+ xor eax, eax
+ sub rcx, rdi
+ and rcx, 15
+ mov r8, rdi
+ jz @F
+ cmp rcx, rdx
+ cmova rcx, rdx
+ sub rdx, rcx
+ rep stosb
+@@:
+ mov rcx, rdx
+ and edx, 15
+ shr rcx, 4
+ jz @ZeroBytes
+ pxor xmm0, xmm0
+@@:
+ movntdq [rdi], xmm0 ; rdi should be 16-byte aligned
+ add rdi, 16
+ loop @B
+ mfence
+@ZeroBytes:
+ mov ecx, edx
+ rep stosb
+ mov rax, r8
+ ret
+InternalMemZeroMem ENDP
+
+ END