[edk2-devel] [PATCH v3 05/10] MdePkg/CompilerIntrinsicsLib: copy over intrinsics from edk2-libc repo

Leif Lindholm quic_llindhol at quicinc.com
Thu May 5 09:50:27 UTC 2022


Apologies for late feedback.

I'm super happy with this set, but...

On Fri, Apr 29, 2022 at 12:20:14 +0200, Gerd Hoffmann wrote:
> Copy over unmodified (except for running through uncrustify), from
> https://github.com/tianocore/edk2-libc/tree/master/StdLib/LibC/CRT

...I think these files should also be given the SPDX treatment, and
while doing that have the explicit patent grant added by changing them
from BSD2 to BSD+Patent.

/
    Leif

> Signed-off-by: Gerd Hoffmann <kraxel at redhat.com>
> Acked-by: Liming Gao <gaoliming at byosoft.com.cn>
> ---
>  .../Library/CompilerIntrinsicsLib/Ia32/Gcc.c  | 283 ++++++++++++++++++
>  .../CompilerIntrinsicsLib/Ia32/lldiv.c        |  98 ++++++
>  .../CompilerIntrinsicsLib/Ia32/lldvrm.c       | 102 +++++++
>  .../CompilerIntrinsicsLib/Ia32/llmul.c        |  82 +++++
>  .../CompilerIntrinsicsLib/Ia32/llrem.c        |  95 ++++++
>  .../CompilerIntrinsicsLib/Ia32/llshl.c        |  57 ++++
>  .../CompilerIntrinsicsLib/Ia32/llshr.c        |  61 ++++
>  .../CompilerIntrinsicsLib/Ia32/ulldiv.c       |  89 ++++++
>  .../CompilerIntrinsicsLib/Ia32/ulldvrm.c      | 102 +++++++
>  .../CompilerIntrinsicsLib/Ia32/ullrem.c       |  95 ++++++
>  .../CompilerIntrinsicsLib/Ia32/ullshr.c       |  60 ++++
>  .../CompilerIntrinsicsLib/Ia32/ashrdi3.S      |  66 ++++
>  .../CompilerIntrinsicsLib/Ia32/mulll.S        |  77 +++++
>  .../CompilerIntrinsicsLib/Ia32/shldi3.S       |  62 ++++
>  .../CompilerIntrinsicsLib/Ia32/udivdi3.S      |  83 +++++
>  .../CompilerIntrinsicsLib/Ia32/umoddi3.S      |  89 ++++++
>  16 files changed, 1501 insertions(+)
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/Gcc.c
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/lldiv.c
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/lldvrm.c
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/llmul.c
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/llrem.c
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/llshl.c
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/llshr.c
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/ulldiv.c
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/ulldvrm.c
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/ullrem.c
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/ullshr.c
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/ashrdi3.S
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/mulll.S
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/shldi3.S
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/udivdi3.S
>  create mode 100644 MdePkg/Library/CompilerIntrinsicsLib/Ia32/umoddi3.S
> 
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/Gcc.c b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/Gcc.c
> new file mode 100644
> index 000000000000..430139fc5ee0
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/Gcc.c
> @@ -0,0 +1,283 @@
> +/** @file
> +  Integer Arithmetic Run-time support functions for GCC.
> +  The integer arithmetic routines are used on platforms that don't provide
> +  hardware support for arithmetic operations on some modes..
> +
> +  Copyright (c) 2009 - 2011, 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.
> +
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +
> +**/
> +#include <Uefi.h>
> +#include <Library/DebugLib.h>
> +#include <sys/EfiCdefs.h>
> +
> +#include <Library/BaseLib.h>
> +
> +// Shift Datum left by Count bits.
> +// ===========================================================================
> +int
> +__ashlsi3 (
> +  int  Datum,
> +  int  Count
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (int)LShiftU64 ((UINT64)Datum, (UINTN)Count);
> +}
> +
> +long
> +__ashldi3 (
> +  long  Datum,
> +  int   Count
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (long)LShiftU64 ((UINT64)Datum, (UINTN)Count);
> +}
> +
> +long long
> +__ashlti3 (
> +  long long  Datum,
> +  int        Count
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (long long)LShiftU64 ((UINT64)Datum, (UINTN)Count);
> +}
> +
> +// Arithmetically shift Datum right by Count bits.
> +// ===========================================================================
> +int
> +__ashrsi3 (
> +  int  Datum,
> +  int  Count
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (int)ARShiftU64 ((UINT64)Datum, (UINTN)Count);
> +}
> +
> +long
> +__ashrdi3 (
> +  long  Datum,
> +  int   Count
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (long)ARShiftU64 ((UINT64)Datum, (UINTN)Count);
> +}
> +
> +long long
> +__ashrti3 (
> +  long long  Datum,
> +  int        Count
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (long long)ARShiftU64 ((UINT64)Datum, (UINTN)Count);
> +}
> +
> +// Return the quotient of the signed division of Dividend and Divisor
> +// ===========================================================================
> +int
> +__divsi3 (
> +  int  Dividend,
> +  int  Divisor
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (int)DivS64x64Remainder ((INT64)Dividend, (INT64)Divisor, NULL);
> +}
> +
> +INT64
> +__divdi3 (
> +  INT64  Dividend,
> +  INT64  Divisor
> +  )
> +{
> +  INT64  Quotient;
> +
> +  Quotient = DivS64x64Remainder ((INT64)Dividend, (INT64)Divisor, NULL);
> +  DEBUG ((DEBUG_INFO, "%a: %Ld / %Ld = %Ld\n", __func__, Dividend, Divisor, Quotient));
> +
> +  return Quotient;
> +}
> +
> +long long
> +__divti3 (
> +  long long  Dividend,
> +  long long  Divisor
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (long long)DivS64x64Remainder ((INT64)Dividend, (INT64)Divisor, NULL);
> +}
> +
> +// Logically shift Datum right by Count bits
> +// ===========================================================================
> +int
> +__lshrsi3 (
> +  int  Datum,
> +  int  Count
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (int)RShiftU64 ((UINT64)Datum, (UINTN)Count);
> +}
> +
> +long
> +__lshrdi3 (
> +  int  Datum,
> +  int  Count
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (long)RShiftU64 ((UINT64)Datum, (UINTN)Count);
> +}
> +
> +long long
> +__lshrti3 (
> +  int  Datum,
> +  int  Count
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (long long)RShiftU64 ((UINT64)Datum, (UINTN)Count);
> +}
> +
> +// Return the remainder of the signed division of Dividend and Divisor
> +// ===========================================================================
> +int
> +__modsi3 (
> +  int  Dividend,
> +  int  Divisor
> +  )
> +{
> +  INT64  Remainder;
> +
> +  (void)DivS64x64Remainder ((INT64)Dividend, (INT64)Divisor, &Remainder);
> +  DEBUG ((DEBUG_INFO, "modsi3: %d %% %d = %d\n", Dividend, Divisor, (int)Remainder));
> +
> +  return (int)Remainder;
> +}
> +
> +INT64
> +__moddi3 (
> +  INT64  Dividend,
> +  INT64  Divisor
> +  )
> +{
> +  INT64  Remainder;
> +
> +  (void)DivS64x64Remainder ((INT64)Dividend, (INT64)Divisor, &Remainder);
> +  DEBUG ((DEBUG_INFO, "moddi3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder));
> +
> +  return Remainder;
> +}
> +
> +long long
> +__modti3 (
> +  long long  Dividend,
> +  long long  Divisor
> +  )
> +{
> +  INT64  Remainder;
> +
> +  (void)DivS64x64Remainder ((INT64)Dividend, (INT64)Divisor, &Remainder);
> +  DEBUG ((DEBUG_INFO, "modti3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder));
> +
> +  return (long long)Remainder;
> +}
> +
> +// These functions return the product of the Multiplicand and Multiplier.
> +// ===========================================================================
> +long long
> +__multi3 (
> +  long long  Multiplicand,
> +  long long  Multiplier
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (long long)MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier);
> +}
> +
> +// Return the quotient of the unsigned division of a and b.
> +// ===========================================================================
> +unsigned int
> +__udivsi3 (
> +  unsigned int  Dividend,
> +  unsigned int  Divisor
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (int)DivU64x64Remainder ((UINT64)Dividend, (UINT64)Divisor, NULL);
> +}
> +
> +unsigned long
> +__udivdi3 (
> +  unsigned long  Dividend,
> +  unsigned long  Divisor
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (long)DivU64x64Remainder ((UINT64)Dividend, (UINT64)Divisor, NULL);
> +}
> +
> +unsigned long long
> +__udivti3 (
> +  unsigned long long  Dividend,
> +  unsigned long long  Divisor
> +  )
> +{
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  return (long long)DivU64x64Remainder ((UINT64)Dividend, (UINT64)Divisor, NULL);
> +}
> +
> +// ===========================================================================
> +unsigned int
> +__umodsi3 (
> +  unsigned int  Dividend,
> +  unsigned int  Divisor
> +  )
> +{
> +  UINT64  Remainder;
> +
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  (void)DivU64x64Remainder ((UINT64)Dividend, (UINT64)Divisor, &Remainder);
> +
> +  return (unsigned int)Remainder;
> +}
> +
> +unsigned long
> +__umoddi3 (
> +  unsigned long  Dividend,
> +  unsigned long  Divisor
> +  )
> +{
> +  UINT64  Remainder;
> +
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  (void)DivU64x64Remainder ((UINT64)Dividend, (UINT64)Divisor, &Remainder);
> +
> +  return (unsigned long)Remainder;
> +}
> +
> +unsigned long long
> +__umodti3 (
> +  unsigned long long  Dividend,
> +  unsigned long long  Divisor
> +  )
> +{
> +  UINT64  Remainder;
> +
> +  DEBUG ((DEBUG_INFO, "%a:\n", __func__));
> +  (void)DivU64x64Remainder ((UINT64)Dividend, (UINT64)Divisor, &Remainder);
> +
> +  return (unsigned long long)Remainder;
> +}
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/lldiv.c b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/lldiv.c
> new file mode 100644
> index 000000000000..792974d7b119
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/lldiv.c
> @@ -0,0 +1,98 @@
> +/** @file
> +  64-bit Math Worker Function.
> +  The 32-bit versions of C compiler generate calls to library routines
> +  to handle 64-bit math. These functions use non-standard calling conventions.
> +
> +  Copyright (c) 2009 - 2011, 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.
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +
> +/*
> + * Divides a 64-bit signed value with a 64-bit signed value and returns
> + * a 64-bit signed result.
> + */
> +__declspec(naked) void __cdecl
> +_alldiv (
> +  void
> +  )
> +{
> +  //
> +  // Wrapper Implementation over EDKII DivS64x64Remainder() routine
> +  //    INT64
> +  //    EFIAPI
> +  //    DivS64x64Remainder (
> +  //      IN      UINT64     Dividend,
> +  //      IN      UINT64     Divisor,
> +  //      OUT     UINT64     *Remainder  OPTIONAL
> +  //      )
> +  //
> +  _asm {
> +    ;Entry:
> +    ;       Arguments are passed on the stack:
> +    ;               1st pushed: divisor (QWORD)
> +    ;               2nd pushed: dividend (QWORD)
> +    ;
> +    ;Exit:
> +    ;       EDX:EAX contains the quotient (dividend/  divisor)
> +    ;       NOTE: this routine removes the parameters from the stack.
> +      ;
> +    ; Original local stack when calling _alldiv
> +    ;               -----------------
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--  Divisor  --|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--  Dividend --|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |  ReturnAddr** |
> +    ;       ESP---->|---------------|
> +    ;
> +
> +    ;
> +    ; Set up the local stack for NULL Reminder pointer
> +    ;
> +    xor  eax, eax
> +    push eax
> +
> +    ;
> +    ; Set up the local stack for Divisor parameter
> +    ;
> +    mov  eax, [esp + 20]
> +    push eax
> +    mov  eax, [esp + 20]
> +    push eax
> +
> +    ;
> +    ; Set up the local stack for Dividend parameter
> +    ;
> +    mov  eax, [esp + 20]
> +    push eax
> +    mov  eax, [esp + 20]
> +    push eax
> +
> +    ;
> +    ; Call native DivS64x64Remainder of BaseLib
> +    ;
> +    call DivS64x64Remainder
> +
> +    ;
> +    ; Adjust stack
> +    ;
> +    add  esp, 20
> +
> +    ret  16
> +  }
> +}
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/lldvrm.c b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/lldvrm.c
> new file mode 100644
> index 000000000000..a1f87f6af5c3
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/lldvrm.c
> @@ -0,0 +1,102 @@
> +/** @file
> +  64-bit Math Worker Function.
> +  The 32-bit versions of C compiler generate calls to library routines
> +  to handle 64-bit math. These functions use non-standard calling conventions.
> +
> +  Copyright (c) 2009 - 2011, 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.
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +
> +/*
> + * Divides a 64-bit signed value by another 64-bit signed value and returns
> + * the 64-bit signed result and the 64-bit signed remainder.
> + */
> +__declspec(naked) void __cdecl
> +_alldvrm (
> +  void
> +  )
> +{
> +  //
> +  // Wrapper Implementation over EDKII DivS64x64Remainder() routine
> +  //    INT64
> +  //    EFIAPI
> +  //    DivS64x64Remainder (
> +  //      IN      INT64     Dividend,
> +  //      IN      INT64     Divisor,
> +  //      OUT     INT64     *Remainder
> +  //      )
> +  //
> +  _asm {
> +    ; Original local stack when calling _alldvrm
> +    ;               -----------------
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--  Divisor  --|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--  Dividend --|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |  ReturnAddr** |
> +    ;       ESP---->|---------------|
> +    ;
> +    ;
> +    ; On Exit:
> +    ;       EDX:EAX contains the quotient (dividend/  divisor)
> +    ;       EBX:ECX contains the remainder (divided %  divisor)
> +    ;       NOTE: this routine removes the parameters from the stack.
> +      ;
> +
> +    ;
> +    ; Set up the local stack for Reminder pointer
> +    ;
> +    sub  esp, 8
> +    push esp
> +
> +    ;
> +    ; Set up the local stack for Divisor parameter
> +    ;
> +    mov  eax, [esp + 28]
> +    push eax
> +    mov  eax, [esp + 28]
> +    push eax
> +
> +    ;
> +    ; Set up the local stack for Dividend parameter
> +    ;
> +    mov  eax, [esp + 28]
> +    push eax
> +    mov  eax, [esp + 28]
> +    push eax
> +
> +    ;
> +    ; Call native DivS64x64Remainder of BaseLib
> +    ;
> +    call DivS64x64Remainder
> +
> +    ;
> +    ; EDX:EAX contains the quotient (dividend/  divisor)
> +    ; Put the Remainder in EBX:ECX
> +    ;
> +    mov  ecx, [esp + 20]
> +    mov  ebx, [esp + 24]
> +
> +    ;
> +    ; Adjust stack
> +    ;
> +    add  esp, 28
> +
> +    ret  16
> +  }
> +}
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llmul.c b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llmul.c
> new file mode 100644
> index 000000000000..61a5c416b912
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llmul.c
> @@ -0,0 +1,82 @@
> +/** @file
> +  64-bit Math Worker Function.
> +  The 32-bit versions of C compiler generate calls to library routines
> +  to handle 64-bit math. These functions use non-standard calling conventions.
> +
> +  Copyright (c) 2009 - 2011, 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.
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +
> +/*
> + * Multiplies a 64-bit signed or unsigned value by a 64-bit signed or unsigned value
> + * and returns a 64-bit result.
> + */
> +__declspec(naked) void __cdecl
> +_allmul (
> +  void
> +  )
> +{
> +  //
> +  // Wrapper Implementation over EDKII MultS64x64() routine
> +  //    INT64
> +  //    EFIAPI
> +  //    MultS64x64 (
> +  //      IN      INT64      Multiplicand,
> +  //      IN      INT64      Multiplier
> +  //      )
> +  //
> +  _asm {
> +    ; Original local stack when calling _allmul
> +    ;               -----------------
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--Multiplier --|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--Multiplicand-|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |  ReturnAddr** |
> +    ;       ESP---->|---------------|
> +    ;
> +
> +    ;
> +    ; Set up the local stack for Multiplicand parameter
> +    ;
> +    mov  eax, [esp + 16]
> +    push eax
> +    mov  eax, [esp + 16]
> +    push eax
> +
> +    ;
> +    ; Set up the local stack for Multiplier parameter
> +    ;
> +    mov  eax, [esp + 16]
> +    push eax
> +    mov  eax, [esp + 16]
> +    push eax
> +
> +    ;
> +    ; Call native MulS64x64 of BaseLib
> +    ;
> +    call MultS64x64
> +
> +    ;
> +    ; Adjust stack
> +    ;
> +    add  esp, 16
> +
> +    ret  16
> +  }
> +}
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llrem.c b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llrem.c
> new file mode 100644
> index 000000000000..f415fe82dd59
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llrem.c
> @@ -0,0 +1,95 @@
> +/** @file
> +  64-bit Math Worker Function.
> +  The 32-bit versions of C compiler generate calls to library routines
> +  to handle 64-bit math. These functions use non-standard calling conventions.
> +
> +  Copyright (c) 2009 - 2011, 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.
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +
> +/*
> + * Divides a 64-bit signed value by another 64-bit signed value and returns
> + * the 64-bit signed remainder.
> + */
> +__declspec(naked) void __cdecl
> +_allrem (
> +  void
> +  )
> +{
> +  //
> +  // Wrapper Implementation over EDKII DivS64x64Remainder() routine
> +  //    UINT64
> +  //    EFIAPI
> +  //    DivS64x64Remainder (
> +  //      IN      UINT64     Dividend,
> +  //      IN      UINT64     Divisor,
> +  //      OUT     UINT64     *Remainder
> +  //      )
> +  //
> +  _asm {
> +    ; Original local stack when calling _allrem
> +    ;               -----------------
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--  Divisor  --|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--  Dividend --|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |  ReturnAddr** |
> +    ;       ESP---->|---------------|
> +    ;
> +
> +    ;
> +    ; Set up the local stack for Reminder pointer
> +    ;
> +    sub  esp, 8
> +    push esp
> +
> +    ;
> +    ; Set up the local stack for Divisor parameter
> +    ;
> +    mov  eax, [esp + 28]
> +    push eax
> +    mov  eax, [esp + 28]
> +    push eax
> +
> +    ;
> +    ; Set up the local stack for Dividend parameter
> +    ;
> +    mov  eax, [esp + 28]
> +    push eax
> +    mov  eax, [esp + 28]
> +    push eax
> +
> +    ;
> +    ; Call native DivS64x64Remainder of BaseLib
> +    ;
> +    call DivS64x64Remainder
> +
> +    ;
> +    ; Put the Reminder in EDX:EAX as return value
> +    ;
> +    mov  eax, [esp + 20]
> +    mov  edx, [esp + 24]
> +
> +    ;
> +    ; Adjust stack
> +    ;
> +    add  esp, 28
> +
> +    ret  16
> +  }
> +}
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llshl.c b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llshl.c
> new file mode 100644
> index 000000000000..f2121a713bd7
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llshl.c
> @@ -0,0 +1,57 @@
> +/** @file
> +  64-bit Math Worker Function.
> +  The 32-bit versions of C compiler generate calls to library routines
> +  to handle 64-bit math. These functions use non-standard calling conventions.
> +
> +  Copyright (c) 2009 - 2011, 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.
> +
> +**/
> +
> +/*
> + * Shifts a 64-bit signed value left by a particular number of bits.
> + */
> +__declspec(naked) void __cdecl
> +_allshl (
> +  void
> +  )
> +{
> +  _asm {
> +    ;
> +    ; Handle shifting of 64 or more bits (return 0)
> +    ;
> +
> +    cmp     cl, 64
> +    jae     short ReturnZero
> +
> +    ;
> +    ; Handle shifting of between 0 and 31 bits
> +    ;
> +    cmp     cl, 32
> +    jae     short More32
> +    shld    edx, eax, cl
> +    shl     eax, cl
> +    ret
> +
> +    ;
> +    ; Handle shifting of between 32 and 63 bits
> +    ;
> +More32:
> +    mov     edx, eax
> +    xor     eax, eax
> +    and     cl, 31
> +    shl     edx, cl
> +    ret
> +
> +ReturnZero:
> +    xor     eax,eax
> +    xor     edx,edx
> +    ret
> +  }
> +}
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llshr.c b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llshr.c
> new file mode 100644
> index 000000000000..ba60aaafada5
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llshr.c
> @@ -0,0 +1,61 @@
> +/** @file
> +  64-bit Math Worker Function.
> +  The 32-bit versions of C compiler generate calls to library routines
> +  to handle 64-bit math. These functions use non-standard calling conventions.
> +
> +  Copyright (c) 2009 - 2011, 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.
> +
> +**/
> +
> +/*
> + * Shifts a 64-bit signed value right by a particular number of bits.
> + */
> +__declspec(naked) void __cdecl
> +_allshr (
> +  void
> +  )
> +{
> +  _asm {
> +    ;
> +    ; Handle shifts of 64 bits or more (if shifting 64 bits or more, the result
> +      ; depends only on the high order bit of edx).
> +      ;
> +
> +    cmp     cl,64
> +    jae     short SIGNRETURN
> +
> +    ;
> +    ; Handle shifts of between 0 and 31 bits
> +    ;
> +    cmp     cl, 32
> +    jae     short MORE32
> +    shrd    eax,edx,cl
> +    sar     edx,cl
> +    ret
> +
> +    ;
> +    ; Handle shifts of between 32 and 63 bits
> +    ;
> +MORE32:
> +    mov     eax,edx
> +    sar     edx,31
> +    and     cl,31
> +    sar     eax,cl
> +    ret
> +
> +    ;
> +    ; Return double precision 0 or -1, depending on the sign of edx
> +    ;
> +SIGNRETURN:
> +    sar     edx,31
> +    mov     eax,edx
> +    ret
> +  }
> +}
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ulldiv.c b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ulldiv.c
> new file mode 100644
> index 000000000000..287af8562839
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ulldiv.c
> @@ -0,0 +1,89 @@
> +/** @file
> +  64-bit Math Worker Function.
> +  The 32-bit versions of C compiler generate calls to library routines
> +  to handle 64-bit math. These functions use non-standard calling conventions.
> +
> +  Copyright (c) 2009 - 2011, 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.
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +
> +/*
> + * Divides a 64-bit unsigned value with a 64-bit unsigned value and returns
> + * a 64-bit unsigned result.
> + */
> +__declspec(naked) void __cdecl
> +_aulldiv (
> +  void
> +  )
> +{
> +  //
> +  // Wrapper Implementation over EDKII DivU64x64Reminder() routine
> +  //    UINT64
> +  //    EFIAPI
> +  //    DivU64x64Remainder (
> +  //      IN      UINT64     Dividend,
> +  //      IN      UINT64     Divisor,
> +  //      OUT     UINT64     *Remainder  OPTIONAL
> +  //      )
> +  //
> +  _asm {
> +    ; Original local stack when calling _aulldiv
> +    ;               -----------------
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--  Divisor  --|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--  Dividend --|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |  ReturnAddr** |
> +    ;       ESP---->|---------------|
> +    ;
> +
> +    ;
> +    ; Set up the local stack for NULL Reminder pointer
> +    ;
> +    xor  eax, eax
> +    push eax
> +
> +    ;
> +    ; Set up the local stack for Divisor parameter
> +    ;
> +    mov  eax, [esp + 20]
> +    push eax
> +    mov  eax, [esp + 20]
> +    push eax
> +
> +    ;
> +    ; Set up the local stack for Dividend parameter
> +    ;
> +    mov  eax, [esp + 20]
> +    push eax
> +    mov  eax, [esp + 20]
> +    push eax
> +
> +    ;
> +    ; Call native DivU64x64Remainder of BaseLib
> +    ;
> +    call DivU64x64Remainder
> +
> +    ;
> +    ; Adjust stack
> +    ;
> +    add  esp, 20
> +
> +    ret  16
> +  }
> +}
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ulldvrm.c b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ulldvrm.c
> new file mode 100644
> index 000000000000..378cdec115e5
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ulldvrm.c
> @@ -0,0 +1,102 @@
> +/** @file
> +  64-bit Math Worker Function.
> +  The 32-bit versions of C compiler generate calls to library routines
> +  to handle 64-bit math. These functions use non-standard calling conventions.
> +
> +  Copyright (c) 2009 - 2011, 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.
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +
> +/*
> + * Divides a 64-bit signed value by another 64-bit signed value and returns
> + * the 64-bit signed result and the 64-bit signed remainder.
> + */
> +__declspec(naked) void __cdecl
> +_aulldvrm (
> +  void
> +  )
> +{
> +  //
> +  // Wrapper Implementation over EDKII DivU64x64Remainder() routine
> +  //    UINT64
> +  //    EFIAPI
> +  //    DivU64x64Remainder (
> +  //      IN      UINT64     Dividend,
> +  //      IN      UINT64     Divisor,
> +  //      OUT     UINT64     *Remainder
> +  //      )
> +  //
> +  _asm {
> +    ; Original local stack when calling _aulldvrm
> +    ;               -----------------
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--  Divisor  --|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--  Dividend --|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |  ReturnAddr** |
> +    ;       ESP---->|---------------|
> +    ;
> +    ;
> +    ; On Exit:
> +    ;       EDX:EAX contains the quotient (dividend/  divisor)
> +    ;       EBX:ECX contains the remainder (divided %  divisor)
> +    ;       NOTE: this routine removes the parameters from the stack.
> +      ;
> +
> +    ;
> +    ; Set up the local stack for Remainder pointer
> +    ;
> +    sub  esp, 8
> +    push esp
> +
> +    ;
> +    ; Set up the local stack for Divisor parameter
> +    ;
> +    mov  eax, [esp + 28]
> +    push eax
> +    mov  eax, [esp + 28]
> +    push eax
> +
> +    ;
> +    ; Set up the local stack for Dividend parameter
> +    ;
> +    mov  eax, [esp + 28]
> +    push eax
> +    mov  eax, [esp + 28]
> +    push eax
> +
> +    ;
> +    ; Call native DivU64x64Remainder of BaseLib
> +    ;
> +    call DivU64x64Remainder
> +
> +    ;
> +    ; EDX:EAX contains the quotient (dividend/  divisor)
> +    ; Put the Remainder in EBX:ECX
> +    ;
> +    mov  ecx, [esp + 20]
> +    mov  ebx, [esp + 24]
> +
> +    ;
> +    ; Adjust stack
> +    ;
> +    add  esp, 28
> +
> +    ret  16
> +  }
> +}
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ullrem.c b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ullrem.c
> new file mode 100644
> index 000000000000..49d0064b0f03
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ullrem.c
> @@ -0,0 +1,95 @@
> +/** @file
> +  64-bit Math Worker Function.
> +  The 32-bit versions of C compiler generate calls to library routines
> +  to handle 64-bit math. These functions use non-standard calling conventions.
> +
> +  Copyright (c) 2009 - 2011, 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.
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +
> +/*
> + * Divides a 64-bit unsigned value by another 64-bit unsigned value and returns
> + * the 64-bit unsigned remainder.
> + */
> +__declspec(naked) void __cdecl
> +_aullrem (
> +  void
> +  )
> +{
> +  //
> +  // Wrapper Implementation over EDKII DivU64x64Remainder() routine
> +  //    UINT64
> +  //    EFIAPI
> +  //    DivU64x64Remainder (
> +  //      IN      UINT64     Dividend,
> +  //      IN      UINT64     Divisor,
> +  //      OUT     UINT64     *Remainder  OPTIONAL
> +  //      )
> +  //
> +  _asm {
> +    ; Original local stack when calling _aullrem
> +    ;               -----------------
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--  Divisor  --|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |               |
> +    ;               |--  Dividend --|
> +    ;               |               |
> +    ;               |---------------|
> +    ;               |  ReturnAddr** |
> +    ;       ESP---->|---------------|
> +    ;
> +
> +    ;
> +    ; Set up the local stack for Reminder pointer
> +    ;
> +    sub  esp, 8
> +    push esp
> +
> +    ;
> +    ; Set up the local stack for Divisor parameter
> +    ;
> +    mov  eax, [esp + 28]
> +    push eax
> +    mov  eax, [esp + 28]
> +    push eax
> +
> +    ;
> +    ; Set up the local stack for Dividend parameter
> +    ;
> +    mov  eax, [esp + 28]
> +    push eax
> +    mov  eax, [esp + 28]
> +    push eax
> +
> +    ;
> +    ; Call native DivU64x64Remainder of BaseLib
> +    ;
> +    call DivU64x64Remainder
> +
> +    ;
> +    ; Put the Reminder in EDX:EAX as return value
> +    ;
> +    mov  eax, [esp + 20]
> +    mov  edx, [esp + 24]
> +
> +    ;
> +    ; Adjust stack
> +    ;
> +    add  esp, 28
> +
> +    ret  16
> +  }
> +}
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ullshr.c b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ullshr.c
> new file mode 100644
> index 000000000000..3c21b45941a1
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ullshr.c
> @@ -0,0 +1,60 @@
> +/** @file
> +  64-bit Math Worker Function.
> +  The 32-bit versions of C compiler generate calls to library routines
> +  to handle 64-bit math. These functions use non-standard calling conventions.
> +
> +  Copyright (c) 2009 - 2011, 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.
> +
> +**/
> +
> +/*
> + * Shifts a 64-bit unsigned value right by a certain number of bits.
> + */
> +__declspec(naked) void __cdecl
> +_aullshr (
> +  void
> +  )
> +{
> +  _asm {
> +    ;
> +    ; Checking: Only handle 64bit shifting or more
> +    ;
> +    cmp     cl, 64
> +    jae     _Exit
> +
> +    ;
> +    ; Handle shifting between 0 and 31 bits
> +    ;
> +    cmp     cl, 32
> +    jae     More32
> +    shrd    eax, edx, cl
> +    shr     edx, cl
> +    ret
> +
> +    ;
> +    ; Handle shifting of 32-63 bits
> +    ;
> +More32:
> +    mov     eax, edx
> +    xor     edx, edx
> +    and     cl, 31
> +    shr     eax, cl
> +    ret
> +
> +    ;
> +    ; Invalid number (less  then 32bits), return 0
> +    ;
> +
> +_Exit:
> +    xor     eax, eax
> +    xor     edx, edx
> +    ret
> +  }
> +}
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ashrdi3.S b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ashrdi3.S
> new file mode 100644
> index 000000000000..1c629dc23bf5
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ashrdi3.S
> @@ -0,0 +1,66 @@
> +#------------------------------------------------------------------------------
> +#
> +# Copyright (c) 2009 - 2011, 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:
> +#
> +#   MathRShiftU64.S
> +#
> +# Abstract:
> +#
> +#   64-bit Math Worker Function.
> +#   Shifts a 64-bit unsigned value right by a certain number of bits.
> +#
> +#------------------------------------------------------------------------------
> +
> +
> +    .686:
> +    .code:
> +
> +ASM_GLOBAL ASM_PFX(__ashrdi3)
> +
> +#------------------------------------------------------------------------------
> +#
> +# void __cdecl __ashrdi3 (void)
> +#
> +#------------------------------------------------------------------------------
> +ASM_PFX(__ashrdi3):
> +    #
> +    # Checking: Only handle 64bit shifting or more
> +    #
> +    cmpb    $64, %cl
> +    jae     _Exit
> +
> +    #
> +    # Handle shifting between 0 and 31 bits
> +    #
> +    cmpb    $32, %cl
> +    jae     More32
> +    shrd    %cl, %edx, %eax
> +    shr     %cl, %edx
> +    ret
> +
> +    #
> +    # Handle shifting of 32-63 bits
> +    #
> +More32:
> +    movl    %edx, %eax
> +    xor     %edx, %edx
> +    and     $32, %cl
> +    shr     %cl, %eax
> +    ret
> +
> +    #
> +    # Invalid number (less then 32bits), return 0
> +    #
> +_Exit:
> +    xor     %eax, %eax
> +    xor     %edx, %edx
> +    ret
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/mulll.S b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/mulll.S
> new file mode 100644
> index 000000000000..333fdfbb9f58
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/mulll.S
> @@ -0,0 +1,77 @@
> +#------------------------------------------------------------------------------
> +#
> +# Copyright (c) 2009 - 2011, 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:
> +#
> +#   MathMultS64x64.S
> +#
> +# Abstract:
> +#
> +#   64-bit Math Worker Function.
> +#   Multiplies a 64-bit signed or unsigned value by a 64-bit signed or unsigned value
> +#   and returns a 64-bit result
> +#
> +#------------------------------------------------------------------------------
> +
> +    .686:
> +    .code:
> +
> +ASM_GLOBAL ASM_PFX(_mulll), ASM_PFX(MultS64x64)
> +
> +#------------------------------------------------------------------------------
> +#
> +# void __cdecl __mulll (void)
> +#
> +#------------------------------------------------------------------------------
> +ASM_PFX(__mulll):
> +    # Original local stack when calling __mulll
> +    #               -----------------
> +    #               |               |
> +    #               |---------------|
> +    #               |               |
> +    #               |--Multiplier --|
> +    #               |               |
> +    #               |---------------|
> +    #               |               |
> +    #               |--Multiplicand-|
> +    #               |               |
> +    #               |---------------|
> +    #               |  ReturnAddr** |
> +    #       ESP---->|---------------|
> +    #
> +
> +    #
> +    # Set up the local stack for Multiplicand parameter
> +    #
> +    movl    16(%esp), %eax
> +    push    %eax
> +    movl    16(%esp), %eax
> +    push    %eax
> +
> +    #
> +    # Set up the local stack for Multiplier parameter
> +    #
> +    movl    16(%esp), %eax
> +    push    %eax
> +    movl    16(%esp), %eax
> +    push    %eax
> +
> +    #
> +    # Call native MulS64x64 of BaseLib
> +    #
> +    jmp     ASM_PFX(MultS64x64)
> +
> +    #
> +    # Adjust stack
> +    #
> +    add     $16, %esp
> +
> +    ret     $16
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/shldi3.S b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/shldi3.S
> new file mode 100644
> index 000000000000..b2a03d98337e
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/shldi3.S
> @@ -0,0 +1,62 @@
> +#------------------------------------------------------------------------------
> +#
> +# Copyright (c) 2009 - 2011, 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:
> +#
> +#   MathLShiftS64.S
> +#
> +# Abstract:
> +#
> +#   64-bit Math Worker Function.
> +#   Shifts a 64-bit signed value left by a certain number of bits.
> +#
> +#------------------------------------------------------------------------------
> +
> +    .686:
> +    .code:
> +
> +ASM_GLOBAL ASM_PFX(__ashldi3)
> +
> +#------------------------------------------------------------------------------
> +#
> +# void __cdecl __ashldi3 (void)
> +#
> +#------------------------------------------------------------------------------
> +ASM_PFX(__ashldi3):
> +    #
> +    # Handle shifting of 64 or more bits (return 0)
> +    #
> +    cmpb    $64, %cl
> +    jae     ReturnZero
> +
> +    #
> +    # Handle shifting of between 0 and 31 bits
> +    #
> +    cmpb    $32, %cl
> +    jae     More32
> +    shld    %cl, %eax, %edx
> +    shl     %cl, %eax
> +    ret
> +
> +    #
> +    # Handle shifting of between 32 and 63 bits
> +    #
> +More32:
> +    movl    %eax, %edx
> +    xor     %eax, %eax
> +    and     $31, %cl
> +    shl     %cl, %edx
> +    ret
> +
> +ReturnZero:
> +    xor     %eax, %eax
> +    xor     %edx, %edx
> +    ret
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/udivdi3.S b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/udivdi3.S
> new file mode 100644
> index 000000000000..336d75ee7c30
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/udivdi3.S
> @@ -0,0 +1,83 @@
> +#------------------------------------------------------------------------------
> +#
> +# Copyright (c) 2009 - 2011, 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:
> +#
> +#   MathDivU64x64.S
> +#
> +# Abstract:
> +#
> +#   64-bit Math Worker Function.
> +#   Divides a 64-bit unsigned value with a 64-bit unsigned value and returns
> +#   a 64-bit unsigned result.
> +#
> +#------------------------------------------------------------------------------
> +
> +    .686:
> +    .code:
> +
> +ASM_GLOBAL ASM_PFX(__udivdi3), ASM_PFX(DivU64x64Remainder)
> +
> +#------------------------------------------------------------------------------
> +#
> +# void __cdecl __udivdi3 (void)
> +#
> +#------------------------------------------------------------------------------
> +ASM_PFX(__udivdi3):
> +    # Original local stack when calling __udivdi3
> +    #               -----------------
> +    #               |               |
> +    #               |---------------|
> +    #               |               |
> +    #               |--  Divisor  --|
> +    #               |               |
> +    #               |---------------|
> +    #               |               |
> +    #               |--  Dividend --|
> +    #               |               |
> +    #               |---------------|
> +    #               |  ReturnAddr** |
> +    #       ESP---->|---------------|
> +    #
> +
> +    #
> +    # Set up the local stack for NULL Reminder pointer
> +    #
> +    xorl    %eax, %eax
> +    push    %eax
> +
> +    #
> +    # Set up the local stack for Divisor parameter
> +    #
> +    movl    20(%esp), %eax
> +    push    %eax
> +    movl    20(%esp), %eax
> +    push    %eax
> +
> +    #
> +    # Set up the local stack for Dividend parameter
> +    #
> +    movl    20(%esp), %eax
> +    push    %eax
> +    movl    20(%esp), %eax
> +    push    %eax
> +
> +    #
> +    # Call native DivU64x64Remainder of BaseLib
> +    #
> +    jmp     ASM_PFX(DivU64x64Remainder)
> +
> +    #
> +    # Adjust stack
> +    #
> +    addl    $20, %esp
> +
> +    ret     $16
> diff --git a/MdePkg/Library/CompilerIntrinsicsLib/Ia32/umoddi3.S b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/umoddi3.S
> new file mode 100644
> index 000000000000..9b72e918a4ba
> --- /dev/null
> +++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/umoddi3.S
> @@ -0,0 +1,89 @@
> +#------------------------------------------------------------------------------
> +#
> +# Copyright (c) 2009 - 2011, 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:
> +#
> +#   MathReminderU64x64.S
> +#
> +# Abstract:
> +#
> +#   64-bit Math Worker Function.
> +#   Divides a 64-bit unsigned value by another 64-bit unsigned value and returns
> +#   the 64-bit unsigned remainder
> +#
> +#------------------------------------------------------------------------------
> +
> +    .686:
> +    .code:
> +
> +ASM_GLOBAL ASM_PFX(__umoddi3), ASM_PFX(DivU64x64Remainder)
> +
> +#------------------------------------------------------------------------------
> +#
> +# void __cdecl __umoddi3 (void)
> +#
> +#------------------------------------------------------------------------------
> +ASM_PFX(__umoddi3):
> +    # Original local stack when calling __umoddi3
> +    #               -----------------
> +    #               |               |
> +    #               |---------------|
> +    #               |               |
> +    #               |--  Divisor  --|
> +    #               |               |
> +    #               |---------------|
> +    #               |               |
> +    #               |--  Dividend --|
> +    #               |               |
> +    #               |---------------|
> +    #               |  ReturnAddr** |
> +    #       ESP---->|---------------|
> +    #
> +
> +    #
> +    # Set up the local stack for Reminder pointer
> +    #
> +    sub     $8, %esp
> +    push    %esp
> +
> +    #
> +    # Set up the local stack for Divisor parameter
> +    #
> +    movl    28(%esp), %eax
> +    push    %eax
> +    movl    28(%esp), %eax
> +    push    %eax
> +
> +    #
> +    # Set up the local stack for Dividend parameter
> +    #
> +    movl    28(%esp), %eax
> +    push    %eax
> +    movl    28(%esp), %eax
> +    push    %eax
> +
> +    #
> +    # Call native DivU64x64Remainder of BaseLib
> +    #
> +    jmp     ASM_PFX(DivU64x64Remainder)
> +
> +    #
> +    # Put the Reminder in EDX:EAX as return value
> +    #
> +    movl    20(%esp), %eax
> +    movl    24(%esp), %edx
> +
> +    #
> +    # Adjust stack
> +    #
> +    add     $28, %esp
> +
> +    ret     $16
> -- 
> 2.35.1
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#89532): https://edk2.groups.io/g/devel/message/89532
Mute This Topic: https://groups.io/mt/90772975/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list