]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/DivU64x32Remainder.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / DivU64x32Remainder.c
1 /** @file
2 Set error flag for all division functions
3
4 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 /**
10 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and
11 generates a 64-bit unsigned result and an optional 32-bit unsigned remainder.
12
13 This function divides the 64-bit unsigned value Dividend by the 32-bit
14 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
15 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
16 This function returns the 64-bit unsigned quotient.
17
18 @param Dividend A 64-bit unsigned value.
19 @param Divisor A 32-bit unsigned value.
20 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
21 optional and may be NULL.
22
23 @return Dividend / Divisor
24
25 **/
26 UINT64
27 EFIAPI
28 InternalMathDivRemU64x32 (
29 IN UINT64 Dividend,
30 IN UINT32 Divisor,
31 OUT UINT32 *Remainder
32 )
33 {
34 _asm {
35 mov ecx, Divisor
36 mov eax, dword ptr [Dividend + 4]
37 xor edx, edx
38 div ecx
39 push eax
40 mov eax, dword ptr [Dividend + 0]
41 div ecx
42 mov ecx, Remainder
43 jecxz RemainderNull // abandon remainder if Remainder == NULL
44 mov [ecx], edx
45 RemainderNull:
46 pop edx
47 }
48 }
49