From eb227e96bd06a5b0f2f933187a679e7fb3382cd9 Mon Sep 17 00:00:00 2001 From: bxing Date: Fri, 28 Jul 2006 07:28:19 +0000 Subject: 1. Updated function headers for all assembly function 2. Optimized register usage in SetMemXX functions in all lib instances 3. Fixed a logical error in CopyMem for all lib instances git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1139 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Library/BaseMemoryLibMmx/X64/CompareMem.asm | 9 ++++ MdePkg/Library/BaseMemoryLibMmx/X64/CopyMem.asm | 34 +++++++------- MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem16.asm | 9 ++++ MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem32.asm | 9 ++++ MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem64.asm | 9 ++++ MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem8.asm | 9 ++++ MdePkg/Library/BaseMemoryLibMmx/X64/SetMem.asm | 23 ++++++--- MdePkg/Library/BaseMemoryLibMmx/X64/SetMem16.asm | 21 ++++++--- MdePkg/Library/BaseMemoryLibMmx/X64/SetMem32.asm | 30 +++++++----- MdePkg/Library/BaseMemoryLibMmx/X64/SetMem64.asm | 21 ++++++--- MdePkg/Library/BaseMemoryLibMmx/X64/ZeroMem.asm | 54 ++++++++++++++++++++++ 11 files changed, 179 insertions(+), 49 deletions(-) create mode 100644 MdePkg/Library/BaseMemoryLibMmx/X64/ZeroMem.asm (limited to 'MdePkg/Library/BaseMemoryLibMmx/X64') diff --git a/MdePkg/Library/BaseMemoryLibMmx/X64/CompareMem.asm b/MdePkg/Library/BaseMemoryLibMmx/X64/CompareMem.asm index b8e289bb27..554bc07c64 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/X64/CompareMem.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/X64/CompareMem.asm @@ -29,6 +29,15 @@ .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 diff --git a/MdePkg/Library/BaseMemoryLibMmx/X64/CopyMem.asm b/MdePkg/Library/BaseMemoryLibMmx/X64/CopyMem.asm index 801cf92750..b57192edbe 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/X64/CopyMem.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/X64/CopyMem.asm @@ -23,42 +23,42 @@ .code +;------------------------------------------------------------------------------ +; VOID * +; EFIAPI +; InternalMemCopyMem ( +; OUT VOID *DestinationBuffer, +; IN CONST VOID *SourceBuffer, +; IN UINTN Length +; ); +;------------------------------------------------------------------------------ InternalMemCopyMem PROC USES rsi rdi mov rsi, rdx ; rsi <- Source mov rdi, rcx ; rdi <- Destination - lea r9, [rdi + r8 - 1] ; r9 <- End of Destination + lea r9, [rsi + r8 - 1] ; r9 <- End of Source cmp rsi, rdi mov rax, rdi ; rax <- Destination as return value jae @F - cmp r9, rsi + cmp r9, rdi jae @CopyBackward ; Copy backward if overlapped -@@: - xor rcx, rcx - sub rcx, rsi - and rcx, 7 ; rcx + rsi aligns on 8-byte boundary - jz @F - cmp rcx, r8 - cmova rcx, r8 - sub r8, rcx ; r8 <- remaining bytes to copy - rep movsb @@: mov rcx, r8 and r8, 7 shr rcx, 3 ; rcx <- # of Qwords to copy jz @CopyBytes - DB 49h, 0fh, 7eh, 0c2h ; movq r10, mm0 ; save mm0 + DB 49h, 0fh, 7eh, 0c2h ; movd r10, mm0 (Save mm0 in r10) @@: - DB 48h, 0fh, 6fh, 06h ; movq mm0, [rsi] - DB 48h, 0fh, 0e7h, 07h ; movntq [rdi], mm0 + DB 0fh, 6fh, 06h ; movd mm0, [rsi] + DB 0fh, 0e7h, 07h ; movntq [rdi], mm0 add rsi, 8 add rdi, 8 loop @B mfence - DB 49h, 0fh, 6eh, 0c2h ; movq mm0, r10 ; restore mm0 + DB 49h, 0fh, 6eh, 0c2h ; movd mm0, r10 (Restore mm0) jmp @CopyBytes @CopyBackward: - mov rdi, r9 ; rdi <- End of Destination - lea rsi, [rsi + r8 - 1] ; rsi <- End of Source + mov rsi, r9 ; rsi <- End of Source + lea rdi, [rdi + r8 - 1] ; rdi <- End of Destination std ; set direction flag @CopyBytes: mov rcx, r8 diff --git a/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem16.asm b/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem16.asm index 6af88fae5b..a2538c2cca 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem16.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem16.asm @@ -29,6 +29,15 @@ .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 diff --git a/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem32.asm b/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem32.asm index f9c9feb00e..e0523d8547 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem32.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem32.asm @@ -29,6 +29,15 @@ .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 diff --git a/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem64.asm b/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem64.asm index 2f286c9e2f..0e7e9c782f 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem64.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem64.asm @@ -29,6 +29,15 @@ .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 diff --git a/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem8.asm b/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem8.asm index 4027ece768..879273f960 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem8.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/X64/ScanMem8.asm @@ -29,6 +29,15 @@ .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 diff --git a/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem.asm b/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem.asm index 9688c3d65b..923beef6c1 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem.asm @@ -23,24 +23,33 @@ .code +;------------------------------------------------------------------------------ +; VOID * +; EFIAPI +; InternalMemSetMem ( +; OUT VOID *Buffer, +; IN UINTN Length, +; IN UINT8 Value +; ); +;------------------------------------------------------------------------------ InternalMemSetMem PROC USES rdi mov rax, r8 mov ah, al - DB 48h, 0fh, 6eh, 0c0h ; movq mm0, rax + DB 48h, 0fh, 6eh, 0c0h ; movd mm0, rax mov r8, rcx - mov rdi, r8 + mov rdi, r8 ; rdi <- Buffer mov rcx, rdx + and edx, 7 shr rcx, 3 jz @SetBytes - DB 0fh, 70h, 0C0h, 00h ; pshufw mm0, mm0, 0h -@@: - DB 48h, 0fh, 0e7h, 07h ; movntq [rdi], mm0 + DB 0fh, 70h, 0C0h, 00h ; pshufw mm0, mm0, 0h +@@: + DB 0fh, 0e7h, 07h ; movntq [rdi], mm0 add rdi, 8 loop @B mfence @SetBytes: - and rdx, 7 - mov rcx, rdx + mov ecx, edx rep stosb mov rax, r8 ret diff --git a/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem16.asm b/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem16.asm index a95020876c..01b72c55d5 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem16.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem16.asm @@ -23,23 +23,32 @@ .code +;------------------------------------------------------------------------------ +; VOID * +; EFIAPI +; InternalMemSetMem16 ( +; OUT VOID *Buffer, +; IN UINTN Length, +; IN UINT16 Value +; ); +;------------------------------------------------------------------------------ InternalMemSetMem16 PROC USES rdi mov rax, r8 - DB 48h, 0fh, 6eh, 0c0h ; movq mm0, rax + DB 48h, 0fh, 6eh, 0c0h ; movd mm0, rax mov r8, rcx mov rdi, r8 mov rcx, rdx - and rdx, 3 + and edx, 3 shr rcx, 2 jz @SetWords - DB 0fh, 70h, 0C0h, 00h ; pshufw mm0, mm0, 0h -@@: - DB 48h, 0fh, 0e7h, 07h ; movntq [rdi], mm0 + DB 0fh, 70h, 0C0h, 00h ; pshufw mm0, mm0, 0h +@@: + DB 0fh, 0e7h, 07h ; movntq [rdi], mm0 add rdi, 8 loop @B mfence @SetWords: - mov rcx, rdx + mov ecx, edx rep stosw mov rax, r8 ret diff --git a/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem32.asm b/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem32.asm index d835543767..89cf175608 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem32.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem32.asm @@ -23,23 +23,29 @@ .code -InternalMemSetMem32 PROC USES rdi - DB 49h, 0fh, 6eh, 0c0h ; movq mm0, r8 ; mm0 <- Value - mov rax, rcx ; rax <- Buffer - mov rdi, rax - mov rcx, rdx - shr rcx, 1 +;------------------------------------------------------------------------------ +; VOID * +; InternalMemSetMem32 ( +; IN VOID *Buffer, +; IN UINTN Count, +; IN UINT32 Value +; ) +;------------------------------------------------------------------------------ +InternalMemSetMem32 PROC + DB 49h, 0fh, 6eh, 0c0h ; movd mm0, r8 (Value) + mov rax, rcx ; rax <- Buffer + xchg rcx, rdx ; rcx <- Count rdx <- Buffer + shr rcx, 1 ; rcx <- # of qwords to set jz @SetDwords - DB 0fh, 70h, 0C0h, 44h ; pshufw mm0, mm0, 44h + DB 0fh, 70h, 0C0h, 44h ; pshufw mm0, mm0, 44h @@: - DB 48h, 0fh, 0e7h, 07h ; movntq [rdi], mm0 - add rdi, 8 + DB 0fh, 0e7h, 02h ; movntq [rdx], mm0 + lea rdx, [rdx + 8] ; use "lea" to avoid flag changes loop @B mfence @SetDwords: - test dl, 1 - jz @F - DB 0fh, 7eh, 07h ; movd [rdi], mm0 + jnc @F + DB 0fh, 7eh, 02h ; movd [rdx], mm0 @@: ret InternalMemSetMem32 ENDP diff --git a/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem64.asm b/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem64.asm index 5780647445..454d6234bf 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem64.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/X64/SetMem64.asm @@ -23,14 +23,21 @@ .code -InternalMemSetMem64 PROC USES rdi - DB 49h, 0fh, 6eh, 0c0h; movq mm0, r8 ; mm0 <- Value - mov rax, rcx ; rax <- Buffer - xchg rcx, rdx ; rcx <- Count - mov rdi, rax +;------------------------------------------------------------------------------ +; VOID * +; InternalMemSetMem64 ( +; IN VOID *Buffer, +; IN UINTN Count, +; IN UINT64 Value +; ) +;------------------------------------------------------------------------------ +InternalMemSetMem64 PROC + DB 49h, 0fh, 6eh, 0c0h ; movd mm0, r8 (Value) + mov rax, rcx ; rax <- Buffer + xchg rcx, rdx ; rcx <- Count @@: - DB 48h, 0fh, 0e7h, 07h; movntq [rdi], mm0 - add rdi, 8 + DB 0fh, 0e7h, 02h ; movntq [rdx], mm0 + add rdx, 8 loop @B mfence ret diff --git a/MdePkg/Library/BaseMemoryLibMmx/X64/ZeroMem.asm b/MdePkg/Library/BaseMemoryLibMmx/X64/ZeroMem.asm new file mode 100644 index 0000000000..e9035a3c14 --- /dev/null +++ b/MdePkg/Library/BaseMemoryLibMmx/X64/ZeroMem.asm @@ -0,0 +1,54 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2006, Intel Corporation +; All rights reserved. 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 + mov rcx, rdx + mov r8, rdi + and edx, 7 + shr rcx, 3 + jz @ZeroBytes + DB 0fh, 0efh, 0c0h ; pxor mm0, mm0 +@@: + DB 0fh, 0e7h, 7 ; movntq [rdi], mm0 + add rdi, 8 + loop @B + DB 0fh, 0aeh, 0f0h ; mfence +@ZeroBytes: + xor eax, eax + mov ecx, edx + rep stosb + mov rax, r8 + ret +InternalMemZeroMem ENDP + + END -- cgit v1.2.3