]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseLib/Ia32/DivU64x64Remainder.c
2 Calculate the quotient of a 64-bit integer by a 64-bit integer and returns
3 both the quotient and the remainderSet error flag for all division functions
5 Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "BaseLibInternals.h"
20 InternalMathDivRemU64x64 (
23 OUT UINT64
*Remainder OPTIONAL
27 mov edx
, dword ptr
[Dividend
+ 4]
28 mov eax
, dword ptr
[Dividend
+ 0] // edx:eax <- dividend
30 mov esi
, eax
// edi:esi <- dividend
31 mov ecx
, dword ptr
[Divisor
+ 4]
32 mov ebx
, dword ptr
[Divisor
+ 0] // ecx:ebx <- divisor
40 mov ebx
, eax
// ebx <- quotient
41 mov ecx
, dword ptr
[Divisor
+ 4]
42 mul dword ptr
[Divisor
]
46 jc TooLarge
// product > 2^64
47 cmp edi
, edx
// compare high 32 bits
49 jb TooLarge
// product > dividend
51 jae Correct
// product <= dividend
53 dec ebx
// adjust quotient by -1
54 jecxz Return
// return if Remainder == NULL
55 sub eax
, dword ptr
[Divisor
+ 0]
56 sbb edx
, dword ptr
[Divisor
+ 4]
60 sbb edi
, edx
// edi:esi <- remainder
64 mov eax
, ebx
// eax <- quotient