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
This commit is contained in:
bxing
2006-07-28 07:28:19 +00:00
parent 27169a56e6
commit eb227e96bd
106 changed files with 1006 additions and 457 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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