From: "Gerd Hoffmann" <kraxel@redhat.com>
To: devel@edk2.groups.io
Cc: Jian J Wang <jian.j.wang@intel.com>,
Jiaxin Wu <jiaxin.wu@intel.com>,
Sean Brogan <sean.brogan@microsoft.com>,
Anthony Perard <anthony.perard@citrix.com>,
Leif Lindholm <quic_llindhol@quicinc.com>,
Zhiguang Liu <zhiguang.liu@intel.com>,
Xiaoyu Lu <xiaoyu1.lu@intel.com>,
Pawel Polawski <ppolawsk@redhat.com>,
Sami Mujawar <sami.mujawar@arm.com>,
Maciej Rabeda <maciej.rabeda@linux.intel.com>,
Bob Feng <bob.c.feng@intel.com>,
Jiewen Yao <jiewen.yao@intel.com>, Andrew Fish <afish@apple.com>,
Bret Barkelew <Bret.Barkelew@microsoft.com>,
Alexei Fedorov <Alexei.Fedorov@arm.com>,
Guo Dong <guo.dong@intel.com>, Gerd Hoffmann <kraxel@redhat.com>,
kilian_kegel@hotmail.com, Maurice Ma <maurice.ma@intel.com>,
Siyuan Fu <siyuan.fu@intel.com>,
Abner Chang <abner.chang@hpe.com>,
Zhichao Gao <zhichao.gao@intel.com>, Wei6 Xu <wei6.xu@intel.com>,
Supreeth Venkatesh <supreeth.venkatesh@arm.com>,
Julien Grall <julien@xen.org>,
Daniel Schaefer <daniel.schaefer@hpe.com>,
Ard Biesheuvel <ardb+tianocore@kernel.org>,
Guomin Jiang <guomin.jiang@intel.com>,
Jordan Justen <jordan.l.justen@intel.com>,
Oliver Steffen <osteffen@redhat.com>,
Sebastien Boeuf <sebastien.boeuf@intel.com>,
Benjamin You <benjamin.you@intel.com>,
Min Xu <min.m.xu@intel.com>, Ray Ni <ray.ni@intel.com>,
Rebecca Cran <rebecca@bsdio.com>,
Nickle Wang <nickle.wang@hpe.com>,
Michael D Kinney <michael.d.kinney@intel.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
Sami Mujawar <Sami.Mujawar@arm.com>,
Peter Grehan <grehan@freebsd.org>,
Erdem Aktas <erdemaktas@google.com>,
Brijesh Singh <brijesh.singh@amd.com>,
James Bottomley <jejb@linux.ibm.com>,
Yuwei Chen <yuwei.chen@intel.com>,
Liming Gao <gaoliming@byosoft.com.cn>
Subject: [PATCH v4 5/9] MdePkg/CompilerIntrinsicsLib: copy over intrinsics from edk2-libc repo
Date: Fri, 3 Jun 2022 14:26:34 +0200 [thread overview]
Message-ID: <20220603122638.1547060-6-kraxel@redhat.com> (raw)
In-Reply-To: <20220603122638.1547060-1-kraxel@redhat.com>
Copy over unmodified (except for running through uncrustify and adding
SPDX licence tags), from
https://github.com/tianocore/edk2-libc/tree/master/StdLib/LibC/CRT
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Liming Gao <gaoliming@byosoft.com.cn>
---
.../Library/CompilerIntrinsicsLib/Ia32/Gcc.c | 285 ++++++++++++++++++
.../CompilerIntrinsicsLib/Ia32/lldiv.c | 100 ++++++
.../CompilerIntrinsicsLib/Ia32/lldvrm.c | 104 +++++++
.../CompilerIntrinsicsLib/Ia32/llmul.c | 84 ++++++
.../CompilerIntrinsicsLib/Ia32/llrem.c | 97 ++++++
.../CompilerIntrinsicsLib/Ia32/llshl.c | 59 ++++
.../CompilerIntrinsicsLib/Ia32/llshr.c | 63 ++++
.../CompilerIntrinsicsLib/Ia32/ulldiv.c | 91 ++++++
.../CompilerIntrinsicsLib/Ia32/ulldvrm.c | 104 +++++++
.../CompilerIntrinsicsLib/Ia32/ullrem.c | 97 ++++++
.../CompilerIntrinsicsLib/Ia32/ullshr.c | 62 ++++
.../CompilerIntrinsicsLib/Ia32/ashrdi3.S | 68 +++++
.../CompilerIntrinsicsLib/Ia32/mulll.S | 79 +++++
.../CompilerIntrinsicsLib/Ia32/shldi3.S | 64 ++++
.../CompilerIntrinsicsLib/Ia32/udivdi3.S | 85 ++++++
.../CompilerIntrinsicsLib/Ia32/umoddi3.S | 91 ++++++
16 files changed, 1533 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..bb211022c0e4
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/Gcc.c
@@ -0,0 +1,285 @@
+/** @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.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ 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..cf2eec2a70b4
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/lldiv.c
@@ -0,0 +1,100 @@
+/** @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.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ 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..1fbe11bea751
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/lldvrm.c
@@ -0,0 +1,104 @@
+/** @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.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ 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..3f9c54454128
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llmul.c
@@ -0,0 +1,84 @@
+/** @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.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ 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..5a73d539a650
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llrem.c
@@ -0,0 +1,97 @@
+/** @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.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ 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..665b628b4014
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llshl.c
@@ -0,0 +1,59 @@
+/** @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.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ 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..94b91d4ea3c7
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/llshr.c
@@ -0,0 +1,63 @@
+/** @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.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ 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..064e0e109b1d
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ulldiv.c
@@ -0,0 +1,91 @@
+/** @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.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ 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..37946b4edc94
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ulldvrm.c
@@ -0,0 +1,104 @@
+/** @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.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ 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..a5b65e600415
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ullrem.c
@@ -0,0 +1,97 @@
+/** @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.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ 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..1cfe781720ac
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ullshr.c
@@ -0,0 +1,62 @@
+/** @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.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ 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..f671d419e1f9
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/ashrdi3.S
@@ -0,0 +1,68 @@
+#------------------------------------------------------------------------------
+#
+# 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.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+# 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..c46d4ab82311
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/mulll.S
@@ -0,0 +1,79 @@
+#------------------------------------------------------------------------------
+#
+# 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.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+# 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..4e5ce03c40e6
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/shldi3.S
@@ -0,0 +1,64 @@
+#------------------------------------------------------------------------------
+#
+# 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.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+# 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..7dbae9c438a4
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/udivdi3.S
@@ -0,0 +1,85 @@
+#------------------------------------------------------------------------------
+#
+# 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.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+# 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..6907eaabccc7
--- /dev/null
+++ b/MdePkg/Library/CompilerIntrinsicsLib/Ia32/umoddi3.S
@@ -0,0 +1,91 @@
+#------------------------------------------------------------------------------
+#
+# 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.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+# 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.36.1
next prev parent reply other threads:[~2022-06-03 12:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-03 12:26 [PATCH v4 0/9] consolidate compiler intrinsics Gerd Hoffmann
2022-06-03 12:26 ` [PATCH v4 1/9] MdePkg: promote CompilerIntrinsicsLib from ArmPkg to MdePkg Gerd Hoffmann
2022-06-03 12:26 ` [PATCH v4 2/9] MdePkg/CompilerIntrinsicsLib: fix msft sources for x64 Gerd Hoffmann
2022-06-03 12:26 ` [PATCH v4 3/9] MdePkg/CompilerIntrinsicsLib: move size_t typedef to header file Gerd Hoffmann
2022-06-03 12:26 ` [PATCH v4 4/9] MdePkg/CompilerIntrinsicsLib: move ia32 intrinsics and strcmp Gerd Hoffmann
2022-06-09 3:57 ` Ni, Ray
2022-06-09 6:33 ` Gerd Hoffmann
2022-06-09 9:34 ` Ni, Ray
2022-06-09 10:41 ` Gerd Hoffmann
2022-06-03 12:26 ` Gerd Hoffmann [this message]
2022-06-03 12:26 ` [PATCH v4 6/9] MdePkg/CompilerIntrinsicsLib: drop include from Gcc.c Gerd Hoffmann
2022-06-03 12:26 ` [PATCH v4 7/9] MdePkg/CompilerIntrinsicsLib: drop debug logging " Gerd Hoffmann
2022-06-03 12:26 ` [PATCH v4 8/9] MdePkg/CompilerIntrinsicsLib: remove duplicate functions " Gerd Hoffmann
2022-06-03 12:26 ` [PATCH v4 9/9] MdePkg/CompilerIntrinsicsLib: add new sources to CompilerIntrinsicsLib.inf Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220603122638.1547060-6-kraxel@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox