From 6074ca7022d034f4d5134996d3aef4a55b38fe5d Mon Sep 17 00:00:00 2001 From: Jordan Justen Date: Mon, 30 May 2016 18:51:53 -0700 Subject: [PATCH] MdePkg BaseLib: Convert Ia32/DivU64x64Remainder.asm to NASM The BaseTools/Scripts/ConvertMasmToNasm.py script was used to convert Ia32/DivU64x64Remainder.asm to Ia32/DivU64x64Remainder.nasm Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jordan Justen --- MdePkg/Library/BaseLib/BaseLib.inf | 3 + .../BaseLib/Ia32/DivU64x64Remainder.nasm | 94 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 MdePkg/Library/BaseLib/Ia32/DivU64x64Remainder.nasm diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/BaseLib.inf index 33f17f43ea..7f511ee520 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -145,6 +145,7 @@ Ia32/EnablePaging32.c | MSFT Ia32/EnableInterrupts.c | MSFT Ia32/EnableDisableInterrupts.c | MSFT + Ia32/DivU64x64Remainder.nasm| MSFT Ia32/DivU64x64Remainder.asm | MSFT Ia32/DivU64x32Remainder.c | MSFT Ia32/DivU64x32.c | MSFT @@ -240,6 +241,7 @@ Ia32/EnablePaging32.asm | INTEL Ia32/EnableInterrupts.asm | INTEL Ia32/EnableDisableInterrupts.asm | INTEL + Ia32/DivU64x64Remainder.nasm| INTEL Ia32/DivU64x64Remainder.asm | INTEL Ia32/DivU64x32Remainder.asm | INTEL Ia32/DivU64x32.asm | INTEL @@ -271,6 +273,7 @@ Ia32/LongJump.S | GCC Ia32/SetJump.S | GCC Ia32/SwapBytes64.S | GCC + Ia32/DivU64x64Remainder.nasm| GCC Ia32/DivU64x64Remainder.S | GCC Ia32/DivU64x32Remainder.S | GCC Ia32/ModU64x32.S | GCC diff --git a/MdePkg/Library/BaseLib/Ia32/DivU64x64Remainder.nasm b/MdePkg/Library/BaseLib/Ia32/DivU64x64Remainder.nasm new file mode 100644 index 0000000000..7188199bfb --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/DivU64x64Remainder.nasm @@ -0,0 +1,94 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2006, Intel Corporation. All rights reserved.
+; This program and the accompanying materials +; are licensed and made available under the terms and conditions of the BSD License +; which accompanies this distribution. The full text of the license may be found at +; http://opensource.org/licenses/bsd-license.php. +; +; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +; +; Module Name: +; +; DivU64x64Remainder.nasm +; +; Abstract: +; +; Calculate the quotient of a 64-bit integer by a 64-bit integer and returns +; both the quotient and the remainder +; +;------------------------------------------------------------------------------ + + SECTION .text + +extern ASM_PFX(InternalMathDivRemU64x32) + +;------------------------------------------------------------------------------ +; UINT64 +; EFIAPI +; InternalMathDivRemU64x64 ( +; IN UINT64 Dividend, +; IN UINT64 Divisor, +; OUT UINT64 *Remainder OPTIONAL +; ); +;------------------------------------------------------------------------------ +global ASM_PFX(InternalMathDivRemU64x64) +ASM_PFX(InternalMathDivRemU64x64): + mov ecx, [esp + 16] ; ecx <- divisor[32..63] + test ecx, ecx + jnz _@DivRemU64x64 ; call _@DivRemU64x64 if Divisor > 2^32 + mov ecx, [esp + 20] + jecxz .0 + and dword [ecx + 4], 0 ; zero high dword of remainder + mov [esp + 16], ecx ; set up stack frame to match DivRemU64x32 +.0: + jmp ASM_PFX(InternalMathDivRemU64x32) + +_@DivRemU64x64: + push ebx + push esi + push edi + mov edx, dword [esp + 20] + mov eax, dword [esp + 16] ; edx:eax <- dividend + mov edi, edx + mov esi, eax ; edi:esi <- dividend + mov ebx, dword [esp + 24] ; ecx:ebx <- divisor +.1: + shr edx, 1 + rcr eax, 1 + shrd ebx, ecx, 1 + shr ecx, 1 + jnz .1 + div ebx + mov ebx, eax ; ebx <- quotient + mov ecx, [esp + 28] ; ecx <- high dword of divisor + mul dword [esp + 24] ; edx:eax <- quotient * divisor[0..31] + imul ecx, ebx ; ecx <- quotient * divisor[32..63] + add edx, ecx ; edx <- (quotient * divisor)[32..63] + mov ecx, dword [esp + 32] ; ecx <- addr for Remainder + jc @TooLarge ; product > 2^64 + cmp edi, edx ; compare high 32 bits + ja @Correct + jb @TooLarge ; product > dividend + cmp esi, eax + jae @Correct ; product <= dividend +@TooLarge: + dec ebx ; adjust quotient by -1 + jecxz @Return ; return if Remainder == NULL + sub eax, dword [esp + 24] + sbb edx, dword [esp + 28] ; edx:eax <- (quotient - 1) * divisor +@Correct: + jecxz @Return + sub esi, eax + sbb edi, edx ; edi:esi <- remainder + mov [ecx], esi + mov [ecx + 4], edi +@Return: + mov eax, ebx ; eax <- quotient + xor edx, edx ; quotient is 32 bits long + pop edi + pop esi + pop ebx + ret + -- 2.39.2