]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EfiCommonLib/Ia32/DivU64x32.c
Maintainers.txt: Remove EdkCompatibilityPkg information
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EfiCommonLib / Ia32 / DivU64x32.c
CommitLineData
3eb9473e 1/*++\r
2\r
4ea9375a
HT
3Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials \r
3eb9473e 5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 DivU64x32.c\r
15\r
16Abstract:\r
17\r
18 64-bit division function for IA-32\r
19\r
20--*/\r
21\r
22#include "Tiano.h"\r
23\r
24UINT64\r
25DivU64x32 (\r
26 IN UINT64 Dividend,\r
27 IN UINTN Divisor,\r
28 OUT UINTN *Remainder OPTIONAL\r
29 )\r
30/*++\r
31\r
32Routine Description:\r
33\r
34 This routine allows a 64 bit value to be divided with a 32 bit value returns \r
35 64bit result and the Remainder.\r
36\r
37Arguments:\r
38\r
39 Dividend - dividend\r
40 Divisor - divisor\r
41 Remainder - buffer for remainder\r
42 \r
43Returns:\r
44\r
45 Dividend / Divisor\r
46 Remainder = Dividend mod Divisor\r
47 \r
48N.B. only works for 31bit divisors!!\r
49\r
50--*/\r
51{\r
52 __asm {\r
53 xor edx, edx ; Clear EDX\r
54\r
55 mov eax, dword ptr Dividend[4] ; Put high 32 bits of 64-bit dividend in EAX\r
56 mov ecx, Divisor ; Put 32 bits divisor in ECX\r
57 div ecx ; Dividend Divisor Quoitent...Remainder\r
58 ; 0:EAX / ECX = EAX EDX \r
59\r
60 push eax ; Push quoitent in stack\r
61\r
62 mov eax, dword ptr Dividend[0] ; Put low 32 bits of 64-bit dividend in EAX \r
63 div ecx ; Leave the REMAINDER in EDX as High 32-bit of new dividend\r
64 ; Dividend Divisor Quoitent...Remainder \r
65 ; EDX:EAX / ECX = EAX EDX \r
66\r
67 mov ecx, Remainder ; Put &REMAINDER to ecx\r
68\r
69 jecxz Label1 ; If ecx == 0, no remainder exist, return with quoitent in EDX directly \r
70 mov dword ptr [ecx], edx ; Put EDX through REMAINDER pointer in ECX \r
71\r
72Label1:\r
73 pop edx ; Pop High 32-bit QUOITENT to EDX\r
74 }\r
75}\r