diff options
author | bxing <bxing@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-07-28 07:28:19 +0000 |
---|---|---|
committer | bxing <bxing@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-07-28 07:28:19 +0000 |
commit | eb227e96bd06a5b0f2f933187a679e7fb3382cd9 (patch) | |
tree | b16e46f494d8d9d8552d8d0e882ad78019934071 /MdePkg/Library/BaseMemoryLibMmx | |
parent | 27169a56e67556796ab0410c8917436dc9aa2abf (diff) | |
download | edk2-platforms-eb227e96bd06a5b0f2f933187a679e7fb3382cd9.tar.xz |
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
Diffstat (limited to 'MdePkg/Library/BaseMemoryLibMmx')
35 files changed, 418 insertions, 242 deletions
diff --git a/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.msa b/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.msa index 978a3628a6..78eae20544 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.msa +++ b/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.msa @@ -89,6 +89,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. <Filename SupArchList="X64">X64/ScanMem16.asm</Filename>
<Filename SupArchList="X64">X64/ScanMem32.asm</Filename>
<Filename SupArchList="X64">X64/ScanMem64.asm</Filename>
+ <Filename SupArchList="X64">X64/ZeroMem.asm</Filename>
</SourceFiles>
<PackageDependencies>
<Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/CompareMem.S b/MdePkg/Library/BaseMemoryLibMmx/Ia32/CompareMem.S index c7e0b8a2a1..7901b82a44 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/CompareMem.S +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/CompareMem.S @@ -27,11 +27,17 @@ # #------------------------------------------------------------------------------ - .686: - #.MODEL flat,C - .code: - .global _InternalMemCompareMem + +#------------------------------------------------------------------------------ +# INTN +# EFIAPI +# InternalMemCompareMem ( +# IN CONST VOID *DestinationBuffer, +# IN CONST VOID *SourceBuffer, +# IN UINTN Length +# ); +#------------------------------------------------------------------------------ _InternalMemCompareMem: push %esi push %edi @@ -45,5 +51,3 @@ _InternalMemCompareMem: pop %edi pop %esi ret - - diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/CompareMem.asm b/MdePkg/Library/BaseMemoryLibMmx/Ia32/CompareMem.asm index 3cf6fe7f73..1d0e7fad39 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/CompareMem.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/CompareMem.asm @@ -31,6 +31,15 @@ .model flat,C
.code
+;------------------------------------------------------------------------------
+; INTN
+; EFIAPI
+; InternalMemCompareMem (
+; IN CONST VOID *DestinationBuffer,
+; IN CONST VOID *SourceBuffer,
+; IN UINTN Length
+; );
+;------------------------------------------------------------------------------
InternalMemCompareMem PROC USES esi edi
mov esi, [esp + 12]
mov edi, [esp + 16]
diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/CopyMem.S b/MdePkg/Library/BaseMemoryLibMmx/Ia32/CopyMem.S index fff8bde5ea..d644b34675 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/CopyMem.S +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/CopyMem.S @@ -21,32 +21,29 @@ # #------------------------------------------------------------------------------ - .686: - #.MODEL flat,C - .xmm: - .code: +.global _InternalMemCopyMem #------------------------------------------------------------------------------ # VOID * -# _mem_CopyMem ( +# EFIAPI +# InternalMemCopyMem ( # IN VOID *Destination, # IN VOID *Source, # IN UINTN Count -# ) +# ); #------------------------------------------------------------------------------ -.global _InternalMemCopyMem _InternalMemCopyMem: push %esi push %edi movl 16(%esp), %esi # esi <- Source movl 12(%esp), %edi # edi <- Destination movl 20(%esp), %edx # edx <- Count - leal -1(%edi,%edx,), %eax # eax <- End of Destination + leal -1(%esi,%edx,), %eax # eax <- End of Source cmpl %edi, %esi jae L0 - cmpl %esi, %eax # Overlapped? + cmpl %edi, %eax # Overlapped? jae @CopyBackward # Copy backward if overlapped -L0: +L0: xorl %ecx, %ecx subl %esi, %ecx andl $7, %ecx # ecx + esi aligns on 8-byte boundary @@ -56,7 +53,7 @@ L0: subl %ecx, %edx # edx <- remaining bytes to copy rep movsb -L1: +L1: movl %edx, %ecx andl $7, %edx shrl $3, %ecx # ecx <- # of Qwords to copy @@ -64,22 +61,21 @@ L1: pushl %eax pushl %eax movq %mm0, (%esp) # save mm0 -L2: +L2: movq (%esi), %mm0 - movntq %mm0, (%edi) + movq %mm0, (%edi) addl $8, %esi addl $8, %edi loop L2 - mfence movq (%esp), %mm0 # restore mm0 popl %ecx # stack cleanup popl %ecx # stack cleanup jmp @CopyBytes -@CopyBackward: - movl %eax, %edi # edi <- Last byte in Destination - leal -1(%esi,%edx,), %esi # esi <- Last byte in Source +@CopyBackward: + movl %eax, %esi # esi <- Last byte in Source + leal -1(%edi,%edx,), %edi # edi <- Last byte in Destination std -@CopyBytes: +@CopyBytes: movl %edx, %ecx rep movsb diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/CopyMem.asm b/MdePkg/Library/BaseMemoryLibMmx/Ia32/CopyMem.asm index b709a809d5..1b8b3c5dcd 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/CopyMem.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/CopyMem.asm @@ -23,36 +23,28 @@ .686
.model flat,C
- .xmm
+ .mmx
.code
;------------------------------------------------------------------------------
; VOID *
-; _mem_CopyMem (
+; EFIAPI
+; InternalMemCopyMem (
; IN VOID *Destination,
; IN VOID *Source,
; IN UINTN Count
-; )
+; );
;------------------------------------------------------------------------------
InternalMemCopyMem PROC USES esi edi
mov esi, [esp + 16] ; esi <- Source
mov edi, [esp + 12] ; edi <- Destination
mov edx, [esp + 20] ; edx <- Count
- lea eax, [edi + edx - 1] ; eax <- End of Destination
+ lea eax, [esi + edx - 1] ; eax <- End of Source
cmp esi, edi
jae @F
- cmp eax, esi ; Overlapped?
+ cmp eax, edi ; Overlapped?
jae @CopyBackward ; Copy backward if overlapped
@@:
- xor ecx, ecx
- sub ecx, esi
- and ecx, 7 ; ecx + esi aligns on 8-byte boundary
- jz @F
- cmp ecx, edx
- cmova ecx, edx
- sub edx, ecx ; edx <- remaining bytes to copy
- rep movsb
-@@:
mov ecx, edx
and edx, 7
shr ecx, 3 ; ecx <- # of Qwords to copy
@@ -62,18 +54,17 @@ InternalMemCopyMem PROC USES esi edi movq [esp], mm0 ; save mm0
@@:
movq mm0, [esi]
- movntq [edi], mm0
+ movq [edi], mm0
add esi, 8
add edi, 8
loop @B
- mfence
movq mm0, [esp] ; restore mm0
pop ecx ; stack cleanup
pop ecx ; stack cleanup
jmp @CopyBytes
@CopyBackward:
- mov edi, eax ; edi <- Last byte in Destination
- lea esi, [esi + edx - 1] ; esi <- Last byte in Source
+ mov esi, eax ; esi <- Last byte in Source
+ lea edi, [edi + edx - 1] ; edi <- Last byte in Destination
std
@CopyBytes:
mov ecx, edx
diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem16.S b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem16.S index e23799e773..1e83064573 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem16.S +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem16.S @@ -27,11 +27,17 @@ # #------------------------------------------------------------------------------ - .686: - #.MODEL flat,C - .code: - .global _InternalMemScanMem16 + +#------------------------------------------------------------------------------ +# CONST VOID * +# EFIAPI +# InternalMemScanMem16 ( +# IN CONST VOID *Buffer, +# IN UINTN Length, +# IN UINT16 Value +# ); +#------------------------------------------------------------------------------ _InternalMemScanMem16: push %edi movl 12(%esp), %ecx @@ -42,5 +48,3 @@ _InternalMemScanMem16: cmovnz %ecx, %eax pop %edi ret - - diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem16.asm b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem16.asm index 7071942ede..57fab61b77 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem16.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem16.asm @@ -31,6 +31,15 @@ .model flat,C
.code
+;------------------------------------------------------------------------------
+; CONST VOID *
+; EFIAPI
+; InternalMemScanMem16 (
+; IN CONST VOID *Buffer,
+; IN UINTN Length,
+; IN UINT16 Value
+; );
+;------------------------------------------------------------------------------
InternalMemScanMem16 PROC USES edi
mov ecx, [esp + 12]
mov edi, [esp + 8]
diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem32.S b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem32.S index 6b4a919dde..b7b93d9c0c 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem32.S +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem32.S @@ -27,11 +27,17 @@ # #------------------------------------------------------------------------------ - .686: - #.MODEL flat,C - .code: - .global _InternalMemScanMem32 + +#------------------------------------------------------------------------------ +# CONST VOID * +# EFIAPI +# InternalMemScanMem32 ( +# IN CONST VOID *Buffer, +# IN UINTN Length, +# IN UINT32 Value +# ); +#------------------------------------------------------------------------------ _InternalMemScanMem32: push %edi movl 12(%esp), %ecx diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem32.asm b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem32.asm index e6aaf02bc3..6ac857ce16 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem32.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem32.asm @@ -31,6 +31,15 @@ .model flat,C
.code
+;------------------------------------------------------------------------------
+; CONST VOID *
+; EFIAPI
+; InternalMemScanMem32 (
+; IN CONST VOID *Buffer,
+; IN UINTN Length,
+; IN UINT32 Value
+; );
+;------------------------------------------------------------------------------
InternalMemScanMem32 PROC USES edi
mov ecx, [esp + 12]
mov edi, [esp + 8]
diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem64.S b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem64.S index 00f6d74436..6bbb18a334 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem64.S +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem64.S @@ -27,18 +27,24 @@ # #------------------------------------------------------------------------------ - .686: - #.MODEL flat,C - .code: - .global _InternalMemScanMem64 + +#------------------------------------------------------------------------------ +# CONST VOID * +# EFIAPI +# InternalMemScanMem64 ( +# IN CONST VOID *Buffer, +# IN UINTN Length, +# IN UINT64 Value +# ); +#------------------------------------------------------------------------------ _InternalMemScanMem64: push %edi movl 12(%esp), %ecx movl 16(%esp), %eax movl 20(%esp), %edx movl 8(%esp), %edi -L0: +L0: cmpl (%edi), %eax leal 8(%edi), %edi loopne L0 @@ -46,7 +52,7 @@ L0: cmpl -4(%edi), %edx jecxz L1 jne L0 -L1: +L1: leal -8(%edi), %eax cmovne %ecx, %eax pop %edi diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem64.asm b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem64.asm index f9725a4a5d..ca54f13738 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem64.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem64.asm @@ -31,6 +31,15 @@ .model flat,C
.code
+;------------------------------------------------------------------------------
+; CONST VOID *
+; EFIAPI
+; InternalMemScanMem64 (
+; IN CONST VOID *Buffer,
+; IN UINTN Length,
+; IN UINT64 Value
+; );
+;------------------------------------------------------------------------------
InternalMemScanMem64 PROC USES edi
mov ecx, [esp + 12]
mov eax, [esp + 16]
diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem8.S b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem8.S index 57640378b4..fe678fac26 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem8.S +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem8.S @@ -27,11 +27,17 @@ # #------------------------------------------------------------------------------ - .686: - #.MODEL flat,C - .code: - .global _InternalMemScanMem8 + +#------------------------------------------------------------------------------ +# CONST VOID * +# EFIAPI +# InternalMemScanMem8 ( +# IN CONST VOID *Buffer, +# IN UINTN Length, +# IN UINT8 Value +# ); +#------------------------------------------------------------------------------ _InternalMemScanMem8: push %edi movl 12(%esp), %ecx diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem8.asm b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem8.asm index 6ae1900189..a3f65b64fa 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem8.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ScanMem8.asm @@ -31,6 +31,15 @@ .model flat,C
.code
+;------------------------------------------------------------------------------
+; CONST VOID *
+; EFIAPI
+; InternalMemScanMem8 (
+; IN CONST VOID *Buffer,
+; IN UINTN Length,
+; IN UINT8 Value
+; );
+;------------------------------------------------------------------------------
InternalMemScanMem8 PROC USES edi
mov ecx, [esp + 12]
mov edi, [esp + 8]
diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem.S b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem.S index 8a893f893a..4e93915caa 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem.S +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem.S @@ -21,44 +21,43 @@ # #------------------------------------------------------------------------------ - .686: - #.MODEL flat,C - .xmm: - .code: +.global _InternalMemSetMem #------------------------------------------------------------------------------ # VOID * -# _mem_SetMem ( +# InternalMemSetMem ( # IN VOID *Buffer, # IN UINTN Count, # IN UINT8 Value # ) #------------------------------------------------------------------------------ -.global _InternalMemSetMem _InternalMemSetMem: push %edi + movb 16(%esp), %al + movb %al, %ah + shrdl $16, %eax, %edx + shldl $16, %edx, %eax movl 12(%esp), %ecx # ecx <- Count movl 8(%esp), %edi # edi <- Buffer movl %ecx, %edx + andl $7, %edx shrl $3, %ecx # # of Qwords to set - movb 16(%esp), %al # al <- Value - jz @SetBytes - movb %al, %ah # ax <- Value | (Value << 8) - pushl %ecx - pushl %ecx + jz L1 + addl $0x-10, %esp movq %mm0, (%esp) # save mm0 + movq %mm1, 8(%esp) # save mm1 movd %eax, %mm0 - pshufw $0x0,%mm0,%mm0 -L0: - movntq %mm0, (%edi) + movd %eax, %mm1 + psllq $32, %mm0 + por %mm1, %mm0 # fill mm0 with 8 Value's +L0: + movq %mm0, (%edi) addl $8, %edi - loop L0 - mfence + loopl L0 movq (%esp), %mm0 # restore mm0 - popl %ecx # stack cleanup - popl %ecx -@SetBytes: - andl $7, %edx + movq 8(%esp), %mm1 # restore mm1 + addl $0x10, %esp # stack cleanup +L1: movl %edx, %ecx rep stosb diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem.asm b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem.asm index f2c55f1296..c9c48ecf9d 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem.asm @@ -23,40 +23,44 @@ .686
.model flat,C
- .xmm
+ .mmx
.code
;------------------------------------------------------------------------------
; VOID *
-; _mem_SetMem (
+; EFIAPI
+; InternalMemSetMem (
; IN VOID *Buffer,
; IN UINTN Count,
; IN UINT8 Value
; )
;------------------------------------------------------------------------------
InternalMemSetMem PROC USES edi
+ mov al, [esp + 16]
+ mov ah, al
+ shrd edx, eax, 16
+ shld eax, edx, 16
mov ecx, [esp + 12] ; ecx <- Count
mov edi, [esp + 8] ; edi <- Buffer
mov edx, ecx
+ and edx, 7
shr ecx, 3 ; # of Qwords to set
- mov al, [esp + 16] ; al <- Value
jz @SetBytes
- mov ah, al ; ax <- Value | (Value << 8)
- push ecx
- push ecx
+ add esp, -10h
movq [esp], mm0 ; save mm0
+ movq [esp + 8], mm1 ; save mm1
movd mm0, eax
- pshufw mm0, mm0, 0 ; fill mm0 with 8 Value's
+ movd mm1, eax
+ psllq mm0, 32
+ por mm0, mm1 ; fill mm0 with 8 Value's
@@:
- movntq [edi], mm0
+ movq [edi], mm0
add edi, 8
loop @B
- mfence
movq mm0, [esp] ; restore mm0
- pop ecx ; stack cleanup
- pop ecx
+ movq mm1, [esp + 8] ; restore mm1
+ add esp, 10h ; stack cleanup
@SetBytes:
- and edx, 7
mov ecx, edx
rep stosb
mov eax, [esp + 8] ; eax <- Buffer as return value
diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem16.S b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem16.S index bcbd49e442..9898d28f98 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem16.S +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem16.S @@ -21,37 +21,36 @@ # #------------------------------------------------------------------------------ - .686: - #.MODEL flat,C - .xmm: - .code: +.global _InternalMemSetMem16 #------------------------------------------------------------------------------ # VOID * -# _mem_SetMem16 ( +# InternalMemSetMem16 ( # IN VOID *Buffer, # IN UINTN Count, # IN UINT16 Value # ) #------------------------------------------------------------------------------ -.global _InternalMemSetMem16 _InternalMemSetMem16: push %edi + movl 16(%esp), %eax + shrdl $16, %eax, %edx + shldl $16, %edx, %eax movl 12(%esp), %edx movl 8(%esp), %edi movl %edx, %ecx andl $3, %edx shrl $2, %ecx - movl 16(%esp), %eax - jz @SetWords + jz L1 movd %eax, %mm0 - pshufw $0, %mm0, %mm0 -L0: - movntq %mm0, (%edi) + movd %eax, %mm1 + psllq $32, %mm0 + por %mm1, %mm0 +L0: + movq %mm0, (%edi) addl $8, %edi - loop L0 - mfence -@SetWords: + loopl L0 +L1: movl %edx, %ecx rep stosw diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem16.asm b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem16.asm index f9dc533fd8..e934226658 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem16.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem16.asm @@ -23,32 +23,36 @@ .686
.model flat,C
- .xmm
+ .mmx
.code
;------------------------------------------------------------------------------
; VOID *
-; _mem_SetMem16 (
+; EFIAPI
+; InternalMemSetMem16 (
; IN VOID *Buffer,
; IN UINTN Count,
; IN UINT16 Value
; )
;------------------------------------------------------------------------------
InternalMemSetMem16 PROC USES edi
+ mov eax, [esp + 16]
+ shrd edx, eax, 16
+ shld eax, edx, 16
mov edx, [esp + 12]
mov edi, [esp + 8]
mov ecx, edx
and edx, 3
shr ecx, 2
- mov eax, [esp + 16]
jz @SetWords
movd mm0, eax
- pshufw mm0, mm0, 0
+ movd mm1, eax
+ psllq mm0, 32
+ por mm0, mm1
@@:
- movntq [edi], mm0
+ movq [edi], mm0
add edi, 8
loop @B
- mfence
@SetWords:
mov ecx, edx
rep stosw
diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem32.S b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem32.S index 27fd6174bd..8281652ad9 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem32.S +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem32.S @@ -21,39 +21,32 @@ # #------------------------------------------------------------------------------ - .686: - #.MODEL flat,C - .xmm: - .code: +.global _InternalMemSetMem32 #------------------------------------------------------------------------------ # VOID * -# _mem_SetMem32 ( +# InternalMemSetMem32 ( # IN VOID *Buffer, # IN UINTN Count, # IN UINT32 Value # ) #------------------------------------------------------------------------------ -.global _InternalMemSetMem32 _InternalMemSetMem32: - push %edi - movl 12(%esp), %edx - movl 8(%esp), %edi - movl %edx, %ecx + movl 4(%esp), %eax + movl 8(%esp), %ecx + movd 12(%esp), %mm0 shrl %ecx - movd 16(%esp), %mm0 - movl %edi, %eax - jz @SetDwords - pshufw $0x44, %mm0, %mm0 -L0: - movntq %mm0, (%edi) - addl $8, %edi - loopl L0 - mfence -@SetDwords: - testb $1, %dl + movl %eax, %edx jz L1 - movd %mm0, (%edi) -L1: - pop %edi + movq %mm0, %mm1 + psllq $32, %mm1 + por %mm1, %mm0 +L0: + movq %mm0, (%edx) + lea 8(%edx), %edx + loopl L0 +L1: + jnc L2 + movd %mm0, (%edx) +L2: ret diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem32.asm b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem32.asm index 7f24fcd744..c2e4869e47 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem32.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem32.asm @@ -23,35 +23,35 @@ .686
.model flat,C
- .xmm
+ .mmx
.code
;------------------------------------------------------------------------------
; VOID *
-; _mem_SetMem32 (
+; EFIAPI
+; InternalMemSetMem32 (
; IN VOID *Buffer,
; IN UINTN Count,
; IN UINT32 Value
-; )
+; );
;------------------------------------------------------------------------------
-InternalMemSetMem32 PROC USES edi
- mov edx, [esp + 12]
- mov edi, [esp + 8]
- mov ecx, edx
- shr ecx, 1
- movd mm0, [esp + 16]
- mov eax, edi
+InternalMemSetMem32 PROC
+ mov eax, [esp + 4] ; eax <- Buffer as return value
+ mov ecx, [esp + 8] ; ecx <- Count
+ movd mm0, [esp + 12] ; mm0 <- Value
+ shr ecx, 1 ; ecx <- number of qwords to set
+ mov edx, eax ; edx <- Buffer
jz @SetDwords
- pshufw mm0, mm0, 44h
+ movq mm1, mm0
+ psllq mm1, 32
+ por mm0, mm1
@@:
- movntq [edi], mm0
- add edi, 8
+ movq [edx], mm0
+ lea edx, [edx + 8] ; use "lea" to avoid change in flags
loop @B
- mfence
@SetDwords:
- test dl, 1
- jz @F
- movd [edi], mm0
+ jnc @F
+ movd [edx], mm0
@@:
ret
InternalMemSetMem32 ENDP
diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem64.S b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem64.S index 9699581606..5eef027e57 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem64.S +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem64.S @@ -21,30 +21,23 @@ # #------------------------------------------------------------------------------ - .686: - #.MODEL flat,C - .xmm: - .code: +.global _InternalMemSetMem64 #------------------------------------------------------------------------------ # VOID * -# _mem_SetMem64 ( +# InternalMemSetMem64 ( # IN VOID *Buffer, # IN UINTN Count, # IN UINT64 Value # ) #------------------------------------------------------------------------------ -.global _InternalMemSetMem64 _InternalMemSetMem64: - push %edi - movq 16(%esp), %mm0 - movl 12(%esp), %ecx - movl 8(%esp), %edi - movl %edi, %eax -L0: - movntq %mm0, (%edi) - addl $8, %edi + movl 4(%esp), %eax + movl 8(%esp), %ecx + movq 12(%esp), %mm0 + movl %eax, %edx +L0: + movq %mm0, (%edx) + lea 8(%edx), %edx loopl L0 - mfence - pop %edi ret diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem64.asm b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem64.asm index 310f418d0c..027483ba3f 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem64.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/SetMem64.asm @@ -23,12 +23,13 @@ .686
.model flat,C
- .xmm
+ .mmx
.code
;------------------------------------------------------------------------------
; VOID *
-; _mem_SetMem64 (
+; EFIAPI
+; InternalMemSetMem64 (
; IN VOID *Buffer,
; IN UINTN Count,
; IN UINT64 Value
@@ -40,10 +41,9 @@ InternalMemSetMem64 PROC movq mm0, [esp + 12]
mov edx, eax
@@:
- movntq [edx], mm0
+ movq [edx], mm0
add edx, 8
loop @B
- mfence
ret
InternalMemSetMem64 ENDP
diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ZeroMem.S b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ZeroMem.S index 0bb19c7da2..f51ce8f98e 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ZeroMem.S +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ZeroMem.S @@ -21,19 +21,16 @@ # #------------------------------------------------------------------------------ - .686: - #.MODEL flat,C - .xmm: - .code: +.global _InternalMemZeroMem #------------------------------------------------------------------------------ # VOID * -# _mem_ZeroMem ( +# EFIAPI +# InternalMemZeroMem ( # IN VOID *Buffer, # IN UINTN Count -# ) +# ); #------------------------------------------------------------------------------ -.global _InternalMemZeroMem _InternalMemZeroMem: push %edi movl 8(%esp), %edi @@ -42,12 +39,11 @@ _InternalMemZeroMem: shrl $3, %ecx jz @ZeroBytes pxor %mm0, %mm0 -L0: - movntq %mm0, (%edi) +L0: + movq %mm0, (%edi) addl $8, %edi loop L0 - mfence -@ZeroBytes: +@ZeroBytes: andl $7, %edx xorl %eax, %eax movl %edx, %ecx diff --git a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ZeroMem.asm b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ZeroMem.asm index 31ef120525..a75480bd40 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/Ia32/ZeroMem.asm +++ b/MdePkg/Library/BaseMemoryLibMmx/Ia32/ZeroMem.asm @@ -23,15 +23,15 @@ .686
.model flat,C
- .xmm
+ .mmx
.code
;------------------------------------------------------------------------------
; VOID *
-; _mem_ZeroMem (
+; InternalMemZeroMem (
; IN VOID *Buffer,
; IN UINTN Count
-; )
+; );
;------------------------------------------------------------------------------
InternalMemZeroMem PROC USES edi
mov edi, [esp + 8]
@@ -41,10 +41,9 @@ InternalMemZeroMem PROC USES edi jz @ZeroBytes
pxor mm0, mm0
@@:
- movntq [edi], mm0
+ movq [edi], mm0
add edi, 8
loop @B
- mfence
@ZeroBytes:
and edx, 7
xor eax, eax
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
diff --git a/MdePkg/Library/BaseMemoryLibMmx/ZeroMemWrapper.c b/MdePkg/Library/BaseMemoryLibMmx/ZeroMemWrapper.c index 08247681c5..e2ffb5c3c2 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/ZeroMemWrapper.c +++ b/MdePkg/Library/BaseMemoryLibMmx/ZeroMemWrapper.c @@ -30,7 +30,7 @@ This function fills Length bytes of Buffer with zeros, and returns Buffer.
If Length > 0 and Buffer is NULL, then ASSERT().
- If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT().
+ If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT().
@param Buffer Pointer to the target buffer to fill with zeros.
@param Length Number of bytes in Buffer to fill with zeros.
@@ -47,5 +47,5 @@ ZeroMem ( {
ASSERT (!(Buffer == NULL && Length > 0));
ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));
- return InternalMemSetMem (Buffer, Length, 0);
+ return InternalMemZeroMem (Buffer, Length);
}
|