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