From 3eb9473ea9a949badfe06ae61d2d3fcfa53651c7 Mon Sep 17 00:00:00 2001 From: qwang12 Date: Thu, 28 Jun 2007 07:00:39 +0000 Subject: Add in the 1st version of ECP. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2832 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Library/CompilerStub/CompilerStubLib.inf | 61 +++++++++++++++ .../Library/CompilerStub/Ia32/memcpy.asm | 81 ++++++++++++++++++++ .../Library/CompilerStub/Ia32/memcpySSE2.asm | 86 ++++++++++++++++++++++ .../Library/CompilerStub/Ia32/memset.asm | 72 ++++++++++++++++++ .../Library/CompilerStub/Ia32/memsetSSE2.asm | 74 +++++++++++++++++++ .../Foundation/Library/CompilerStub/memcpy.c | 46 ++++++++++++ .../Foundation/Library/CompilerStub/memset.c | 45 +++++++++++ .../Foundation/Library/CompilerStub/x64/memcpy.asm | 73 ++++++++++++++++++ .../Library/CompilerStub/x64/memcpySSE2.asm | 80 ++++++++++++++++++++ .../Foundation/Library/CompilerStub/x64/memset.asm | 62 ++++++++++++++++ .../Library/CompilerStub/x64/memsetSSE2.asm | 74 +++++++++++++++++++ 11 files changed, 754 insertions(+) create mode 100644 EdkCompatibilityPkg/Foundation/Library/CompilerStub/CompilerStubLib.inf create mode 100644 EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memcpy.asm create mode 100644 EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memcpySSE2.asm create mode 100644 EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memset.asm create mode 100644 EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memsetSSE2.asm create mode 100644 EdkCompatibilityPkg/Foundation/Library/CompilerStub/memcpy.c create mode 100644 EdkCompatibilityPkg/Foundation/Library/CompilerStub/memset.c create mode 100644 EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memcpy.asm create mode 100644 EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memcpySSE2.asm create mode 100644 EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memset.asm create mode 100644 EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memsetSSE2.asm (limited to 'EdkCompatibilityPkg/Foundation/Library/CompilerStub') diff --git a/EdkCompatibilityPkg/Foundation/Library/CompilerStub/CompilerStubLib.inf b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/CompilerStubLib.inf new file mode 100644 index 0000000000..b80e6faca3 --- /dev/null +++ b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/CompilerStubLib.inf @@ -0,0 +1,61 @@ +#/*++ +# +# Copyright (c) 2006 - 2007, 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: +# +# CompilerStubLib.inf +# +# Abstract: +# +# Component description file for the CompilerStub. +# +#--*/ + +[defines] +BASE_NAME = CompilerStub +COMPONENT_TYPE = LIBRARY + +[sources.common] + +[sources.ia32] + Ia32\memcpy.asm + Ia32\memset.asm + +[sources.x64] + x64\memcpy.asm + x64\memset.asm + +[sources.Ipf] + memcpy.c + memset.c + +[includes.common] + $(EDK_SOURCE)\Foundation + $(EDK_SOURCE)\Foundation\Framework + $(EDK_SOURCE)\Foundation\Efi + $(EDK_SOURCE)\Foundation\Include + $(EDK_SOURCE)\Foundation\Efi\Include + $(EDK_SOURCE)\Foundation\Framework\Include + $(EDK_SOURCE)\Foundation\Include\IndustryStandard + $(EDK_SOURCE) + $(EDK_SOURCE)\Foundation\Core\Dxe + $(EDK_SOURCE)\Foundation\Library\Dxe\Include + $(EDK_SOURCE)\Foundation\Include\Pei + $(EDK_SOURCE)\Foundation\Library\Pei\Include + $(EDK_SOURCE)\Foundation\Framework\Ppi\CpuIo + $(EDK_SOURCE)\Foundation\Framework + +[libraries.common] + +[nmake.common] + +[nmake.ia32,nmake.x64] + C_FLAGS= $(C_FLAGS) /GL- diff --git a/EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memcpy.asm b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memcpy.asm new file mode 100644 index 0000000000..37b505678a --- /dev/null +++ b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memcpy.asm @@ -0,0 +1,81 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2007, 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: +; +; CopyMem.asm +; +; Abstract: +; +; memcpy function +; +; Notes: +; +;------------------------------------------------------------------------------ + + .686 + .model flat,C + .mmx + .code + +;------------------------------------------------------------------------------ +; VOID * +; memcpy ( +; IN VOID *Destination, +; IN VOID *Source, +; IN UINTN Count +; ); +;------------------------------------------------------------------------------ +memcpy PROC USES esi edi + mov esi, [esp + 16] ; esi <- Source + mov edi, [esp + 12] ; edi <- Destination + mov edx, [esp + 20] ; edx <- Count + lea eax, [esi + edx - 1] ; eax <- End of Source + cmp esi, edi + je @CopyMemDone + cmp edx, 0 + je @CopyMemDone + cmp esi, edi + jae @F + cmp eax, edi ; Overlapped? + jae @CopyBackward ; Copy backward if overlapped +@@: + mov ecx, edx + and edx, 7 + shr ecx, 3 ; ecx <- # of Qwords to copy + jz @CopyBytes + push eax + push eax + movq [esp], mm0 ; save mm0 +@@: + movq mm0, [esi] + movq [edi], mm0 + add esi, 8 + add edi, 8 + loop @B + movq mm0, [esp] ; restore mm0 + pop ecx ; stack cleanup + pop ecx ; stack cleanup + jmp @CopyBytes +@CopyBackward: + mov esi, eax ; esi <- Last byte in Source + lea edi, [edi + edx - 1] ; edi <- Last byte in Destination + std +@CopyBytes: + mov ecx, edx + rep movsb + cld +@CopyMemDone: + mov eax, [esp + 12] + ret +memcpy ENDP + + END diff --git a/EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memcpySSE2.asm b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memcpySSE2.asm new file mode 100644 index 0000000000..5ae5752a57 --- /dev/null +++ b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memcpySSE2.asm @@ -0,0 +1,86 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2007, 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: +; +; CopyMem.asm +; +; Abstract: +; +; memcpy function +; +; Notes: +; +;------------------------------------------------------------------------------ + + .686 + .model flat,C + .xmm + .code + +;------------------------------------------------------------------------------ +; VOID * +; memcpy ( +; IN VOID *Destination, +; IN VOID *Source, +; IN UINTN Count +; ); +;------------------------------------------------------------------------------ +memcpy PROC USES esi edi + mov esi, [esp + 16] ; esi <- Source + mov edi, [esp + 12] ; edi <- Destination + mov edx, [esp + 20] ; edx <- Count + lea eax, [esi + edx - 1] ; eax <- End of Source + cmp esi, edi + je @CopyMemDone + cmp edx, 0 + je @CopyMemDone + cmp esi, edi + jae @F + cmp eax, edi ; Overlapped? + jae @CopyBackward ; Copy backward if overlapped +@@: + xor ecx, ecx + sub ecx, edi + and ecx, 15 ; ecx + edi aligns on 16-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, 15 + shr ecx, 4 ; ecx <- # of DQwords to copy + jz @CopyBytes + add esp, -16 +@@: + movdqu xmm0, [esi] ; esi may not be 16-bytes aligned + movdqa [edi], xmm0 ; edi should be 16-bytes aligned + add esi, 16 + add edi, 16 + loop @B + add esp, 16 ; stack cleanup + jmp @CopyBytes +@CopyBackward: + mov esi, eax ; esi <- Last byte in Source + lea edi, [edi + edx - 1] ; edi <- Last byte in Destination + std +@CopyBytes: + mov ecx, edx + rep movsb + cld +@CopyMemDone: + mov eax, [esp + 12] + ret +memcpy ENDP + + END diff --git a/EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memset.asm b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memset.asm new file mode 100644 index 0000000000..3dbf920da8 --- /dev/null +++ b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memset.asm @@ -0,0 +1,72 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2007, 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: +; +; SetMem.asm +; +; Abstract: +; +; memset function +; +; Notes: +; +;------------------------------------------------------------------------------ + + .686 + .model flat,C + .mmx + .code + +;------------------------------------------------------------------------------ +; VOID * +; memset ( +; OUT VOID *Buffer, +; IN UINT8 Value, +; IN UINTN Count +; ) +;------------------------------------------------------------------------------ +memset PROC USES edi + mov al, [esp + 12] + mov ah, al + shrd edx, eax, 16 + shld eax, edx, 16 + mov ecx, [esp + 16] ; ecx <- Count + cmp ecx, 0 ; if Count == 0, do nothing + je @SetDone + mov edi, [esp + 8] ; edi <- Buffer + mov edx, ecx + and edx, 7 + shr ecx, 3 ; # of Qwords to set + jz @SetBytes + add esp, -10h + movq [esp], mm0 ; save mm0 + movq [esp + 8], mm1 ; save mm1 + movd mm0, eax + movd mm1, eax + psllq mm0, 32 + por mm0, mm1 ; fill mm0 with 8 Value's +@@: + movq [edi], mm0 + add edi, 8 + loop @B + movq mm0, [esp] ; restore mm0 + movq mm1, [esp + 8] ; restore mm1 + add esp, 10h ; stack cleanup +@SetBytes: + mov ecx, edx + rep stosb +@SetDone: + mov eax, [esp + 8] ; eax <- Buffer as return value + ret +memset ENDP + + END diff --git a/EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memsetSSE2.asm b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memsetSSE2.asm new file mode 100644 index 0000000000..ce9ba64fea --- /dev/null +++ b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/Ia32/memsetSSE2.asm @@ -0,0 +1,74 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2007, 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: +; +; SetMem.asm +; +; Abstract: +; +; memset function +; +; Notes: +; +;------------------------------------------------------------------------------ + + .686 + .model flat,C + .xmm + .code + +;------------------------------------------------------------------------------ +; VOID * +; memset ( +; OUT VOID *Buffer, +; IN UINT8 Value, +; IN UINTN Count +; ) +;------------------------------------------------------------------------------ +memset PROC USES edi + mov edx, [esp + 16] ; edx <- Count + cmp edx, 0 ; if Count == 0, do nothing + je @SetDone + mov edi, [esp + 8] ; edi <- Buffer + mov al, [esp + 12] ; al <- Value + xor ecx, ecx + sub ecx, edi + and ecx, 15 ; ecx + edi aligns on 16-byte boundary + jz @F + cmp ecx, edx + cmova ecx, edx + sub edx, ecx + rep stosb +@@: + mov ecx, edx + and edx, 15 + shr ecx, 4 ; ecx <- # of DQwords to set + jz @SetBytes + mov ah, al ; ax <- Value | (Value << 8) + add esp, -16 + movd xmm0, eax + pshuflw xmm0, xmm0, 0 ; xmm0[0..63] <- Value repeats 8 times + movlhps xmm0, xmm0 ; xmm0 <- Value repeats 16 times +@@: + movdqa [edi], xmm0 ; edi should be 16-byte aligned + add edi, 16 + loop @B + add esp, 16 ; stack cleanup +@SetBytes: + mov ecx, edx + rep stosb +@SetDone: + mov eax, [esp + 8] ; eax <- Buffer as return value + ret +memset ENDP + + END diff --git a/EdkCompatibilityPkg/Foundation/Library/CompilerStub/memcpy.c b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/memcpy.c new file mode 100644 index 0000000000..300724a132 --- /dev/null +++ b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/memcpy.c @@ -0,0 +1,46 @@ +/*++ + +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: + memcpy.c + +Abstract: + + The Microsoft compiler inlines memcpy and we can not stop it. + These routines allow the code to link! + + There is no *.h definition of these modules as they are well known by the + compiler. See Microsoft documentation for more details! + + volatile is used to prevent the compiler from trying to implement these + C functions as inline functions. + +--*/ + +#include "Tiano.h" + +VOID * +memcpy ( + OUT VOID *Dest, + IN const VOID *Src, + IN UINTN Count + ) +{ + volatile UINT8 *Ptr; + const UINT8 *Source; + + for (Ptr = Dest, Source = Src; Count > 0; Count--, Source++, Ptr++) { + *Ptr = *Source; + } + + return Dest; +} + diff --git a/EdkCompatibilityPkg/Foundation/Library/CompilerStub/memset.c b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/memset.c new file mode 100644 index 0000000000..0f0f40db97 --- /dev/null +++ b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/memset.c @@ -0,0 +1,45 @@ +/*++ + +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: + memset.c + +Abstract: + + The Microsoft compiler inlines memset and we can not stop it. + These routines allow the code to link! + + There is no *.h definition of these modules as they are well known by the + compiler. See Microsoft documentation for more details! + + volatile is used to prevent the compiler from trying to implement these + C functions as inline functions. + +--*/ + +#include "Tiano.h" + +VOID * +memset ( + OUT VOID *Dest, + IN UINTN Char, + IN UINTN Count + ) +{ + volatile UINT8 *Ptr; + + for (Ptr = Dest; Count > 0; Count--, Ptr++) { + *Ptr = (UINT8) Char; + } + + return Dest; +} + diff --git a/EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memcpy.asm b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memcpy.asm new file mode 100644 index 0000000000..7e04431459 --- /dev/null +++ b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memcpy.asm @@ -0,0 +1,73 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2007, 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: +; +; CopyMem.asm +; +; Abstract: +; +; memcpy function +; +; Notes: +; +;------------------------------------------------------------------------------ + + .code + +;------------------------------------------------------------------------------ +; VOID * +; memcpy ( +; OUT VOID *DestinationBuffer, +; IN CONST VOID *SourceBuffer, +; IN UINTN Length +; ); +;------------------------------------------------------------------------------ +memcpy PROC USES rsi rdi + mov rax, rcx ; rax <- Destination as return value + cmp rdx, rcx ; if Source == Destination, do nothing + je @CopyMemDone + cmp r8, 0 ; if Count == 0, do nothing + je @CopyMemDone + mov rsi, rdx ; rsi <- Source + mov rdi, rcx ; rdi <- Destination + lea r9, [rsi + r8 - 1] ; r9 <- End of Source + cmp rsi, rdi + jae @F + cmp r9, rdi + jae @CopyBackward ; Copy backward if overlapped +@@: + mov rcx, r8 + and r8, 7 + shr rcx, 3 ; rcx <- # of Qwords to copy + jz @CopyBytes + DB 49h, 0fh, 7eh, 0c2h ; movd r10, mm0 (Save mm0 in r10) +@@: + DB 0fh, 6fh, 06h ; movd mm0, [rsi] + DB 48h, 0fh, 7eh, 07h ; movd [rdi], mm0 + add rsi, 8 + add rdi, 8 + loop @B + DB 49h, 0fh, 6eh, 0c2h ; movd mm0, r10 (Restore mm0) + jmp @CopyBytes +@CopyBackward: + mov rsi, r9 ; rsi <- End of Source + lea rdi, [rdi + r8 - 1] ; rdi <- End of Destination + std ; set direction flag +@CopyBytes: + mov rcx, r8 + rep movsb ; Copy bytes backward + cld +@CopyMemDone: + ret +memcpy ENDP + + END diff --git a/EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memcpySSE2.asm b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memcpySSE2.asm new file mode 100644 index 0000000000..15bdf37ffb --- /dev/null +++ b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memcpySSE2.asm @@ -0,0 +1,80 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2007, 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: +; +; CopyMem.asm +; +; Abstract: +; +; memcpy function +; +; Notes: +; +;------------------------------------------------------------------------------ + + .code + +;------------------------------------------------------------------------------ +; VOID * +; memcpy ( +; OUT VOID *DestinationBuffer, +; IN CONST VOID *SourceBuffer, +; IN UINTN Length +; ); +;------------------------------------------------------------------------------ +memcpy PROC USES rsi rdi + mov rax, rcx ; rax <- Destination as return value + cmp rdx, rcx ; if Source == Destination, do nothing + je @CopyMemDone + cmp r8, 0 ; if Count == 0, do nothing + je @CopyMemDone + mov rsi, rdx ; rsi <- Source + mov rdi, rcx ; rdi <- Destination + lea r9, [rsi + r8 - 1] ; r9 <- Last byte of Source + cmp rsi, rdi + 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 +@@: + movdqu xmm0, [rsi] ; rsi may not be 16-byte aligned + movdqa [rdi], xmm0 ; rdi should be 16-byte aligned + add rsi, 16 + add rdi, 16 + loop @B + 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 +@CopyMemDone: + ret +memcpy ENDP + + END diff --git a/EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memset.asm b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memset.asm new file mode 100644 index 0000000000..134700d912 --- /dev/null +++ b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memset.asm @@ -0,0 +1,62 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2007, 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: +; +; SetMem.asm +; +; Abstract: +; +; memset function +; +; Notes: +; +;------------------------------------------------------------------------------ + + .code + +;------------------------------------------------------------------------------ +; VOID * +; memset ( +; OUT VOID *Buffer, --> rcx +; IN UINT8 Value, --> rdx +; IN UINTN Length --> r8 +; ); +;------------------------------------------------------------------------------ +memset PROC USES rdi + mov rax, rcx + cmp r8, 0 ; if Size == 0, do nothing + je @SetDone + mov rax, rdx ; rdx <-> r8 + mov rdx, r8 ; rdx <- Length + mov r8, rax ; r8 <- Value + mov ah, al + DB 48h, 0fh, 6eh, 0c0h ; movd mm0, rax + mov r8, rcx + 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, 7eh, 07h ; movd [rdi], mm0 + add rdi, 8 + loop @B +@SetBytes: + mov ecx, edx + rep stosb + mov rax, r8 +@SetDone: + ret +memset ENDP + + END diff --git a/EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memsetSSE2.asm b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memsetSSE2.asm new file mode 100644 index 0000000000..0370c9be71 --- /dev/null +++ b/EdkCompatibilityPkg/Foundation/Library/CompilerStub/x64/memsetSSE2.asm @@ -0,0 +1,74 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2007, 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: +; +; SetMem.asm +; +; Abstract: +; +; memset function +; +; Notes: +; +;------------------------------------------------------------------------------ + + .code + +;------------------------------------------------------------------------------ +; VOID * +; memset ( +; OUT VOID *Buffer, --> rcx +; IN UINT8 Value, --> rdx +; IN UINTN Length --> r8 +; ); +;------------------------------------------------------------------------------ +memset PROC USES rdi + mov rax, rcx + cmp r8, 0 ; if Size == 0, do nothing + je @SetDone + mov rax, rdx ; rdx <-> r8 + mov rdx, r8 ; rdx <- Length + mov r8, rax ; r8 <- Value + + 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 + 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 +@@: + movdqa [rdi], xmm0 ; rdi should be 16-byte aligned + add rdi, 16 + loop @B +@SetBytes: + mov ecx, edx ; high 32 bits of rcx are always zero + rep stosb + mov rax, r9 ; rax <- Return value +@SetDone: + ret +memset ENDP + + END -- cgit v1.2.3