]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/DivU64x64Remainder.s
Fixes for GCC.
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / DivU64x64Remainder.s
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
24
25
26
27 .extern _InternalMathDivRemU64x32
28
29 .global _InternalMathDivRemU64x64
30 _InternalMathDivRemU64x64:
31 movl 16(%esp),%ecx
32 testl %ecx,%ecx
33 jnz _DivRemU64x64
34 movl 20(%esp),%ecx
35 jecxz L1
36 and $0,4(%ecx)
37 movl %ecx,16(%esp)
38 L1:
39 jmp _InternalMathDivRemU64x32
40
41
42 .global DivRemU64x64
43 DivRemU64x64:
44 # MISMATCH: "DivRemU64x64: USES ebx esi edi"
45 push %ebx
46 push %esi
47 push %edi
48 mov 20(%esp), %edx
49 mov 16(%esp), %eax
50 movl %edx,%edi
51 movl %eax,%esi
52 mov 24(%esp), %ebx
53 L2:
54 shrl %edx
55 rcrl $1,%eax
56 shrdl $1,%ecx,%ebx
57 shrl %ecx
58 jnz L2
59 divl %ebx
60 movl %eax,%ebx
61 movl 28(%esp),%ecx
62 mull 24(%esp)
63 imull %ebx,%ecx
64 addl %ecx,%edx
65 mov 32(%esp), %ecx
66 jc TooLarge
67 cmpl %edx,%edi
68 ja Correct
69 jb TooLarge
70 cmpl %eax,%esi
71 jae Correct
72 TooLarge:
73 decl %ebx
74 jecxz Return
75 sub 24(%esp), %eax
76 sbb 28(%esp), %edx
77 Correct:
78 jecxz Return
79 subl %eax,%esi
80 sbbl %edx,%edi
81 movl %esi,(%ecx)
82 movl %edi,4(%ecx)
83 Return:
84 movl %ebx,%eax
85 xorl %edx,%edx
86 push %edi
87 push %esi
88 push %ebx
89 ret