]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/DivU64x64Remainder.asm
Fixes for GCC.
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / DivU64x64Remainder.asm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2006, Intel Corporation
4 ; All rights reserved. This program and the accompanying materials
5 ; are licensed and made available under the terms and conditions of the BSD License
6 ; which accompanies this distribution. The full text of the license may be found at
7 ; http://opensource.org/licenses/bsd-license.php
8 ;
9 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 ;
12 ; Module Name:
13 ;
14 ; DivU64x64Remainder.asm
15 ;
16 ; Abstract:
17 ;
18 ; Calculate the quotient of a 64-bit integer by a 64-bit integer and returns
19 ; both the quotient and the remainder
20 ;
21 ;------------------------------------------------------------------------------
22
23 .386
24 .model flat,C
25 .code
26
27 EXTERN InternalMathDivRemU64x32:PROC
28
29 InternalMathDivRemU64x64 PROC
30 mov ecx, [esp + 16]
31 test ecx, ecx
32 jnz _@DivRemU64x64
33 mov ecx, [esp + 20]
34 jecxz @F
35 and dword ptr [ecx + 4], 0
36 mov [esp + 16], ecx
37 @@:
38 jmp InternalMathDivRemU64x32
39 InternalMathDivRemU64x64 ENDP
40
41 _@DivRemU64x64 PROC USES ebx esi edi
42 mov edx, dword ptr [esp + 20]
43 mov eax, dword ptr [esp + 16]
44 mov edi, edx
45 mov esi, eax
46 mov ebx, dword ptr [esp + 24]
47 @@:
48 shr edx, 1
49 rcr eax, 1
50 shrd ebx, ecx, 1
51 shr ecx, 1
52 jnz @B
53 div ebx
54 mov ebx, eax
55 mov ecx, [esp + 28]
56 mul dword ptr [esp + 24]
57 imul ecx, ebx
58 add edx, ecx
59 mov ecx, dword ptr [esp + 32]
60 jc @TooLarge
61 cmp edi, edx
62 ja @Correct
63 jb @TooLarge
64 cmp esi, eax
65 jae @Correct
66 @TooLarge:
67 dec ebx
68 jecxz @Return
69 sub eax, dword ptr [esp + 24]
70 sbb edx, dword ptr [esp + 28]
71 @Correct:
72 jecxz @Return
73 sub esi, eax
74 sbb edi, edx
75 mov [ecx], esi
76 mov [ecx + 4], edi
77 @Return:
78 mov eax, ebx
79 xor edx, edx
80 ret
81 _@DivRemU64x64 ENDP
82
83 END