]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/DivU64x64Remainder.S
df1e6ad495c4028ca19482fdce6dfa96d6d3384a
[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 push %ebx
45 push %esi
46 push %edi
47 mov 20(%esp), %edx
48 mov 16(%esp), %eax
49 movl %edx,%edi
50 movl %eax,%esi
51 mov 24(%esp), %ebx
52 L2:
53 shrl %edx
54 rcrl $1,%eax
55 shrdl $1,%ecx,%ebx
56 shrl %ecx
57 jnz L2
58 divl %ebx
59 movl %eax,%ebx
60 movl 28(%esp),%ecx
61 mull 24(%esp)
62 imull %ebx,%ecx
63 addl %ecx,%edx
64 mov 32(%esp), %ecx
65 jc TooLarge
66 cmpl %edx,%edi
67 ja Correct
68 jb TooLarge
69 cmpl %eax,%esi
70 jae Correct
71 TooLarge:
72 decl %ebx
73 jecxz Return
74 sub 24(%esp), %eax
75 sbb 28(%esp), %edx
76 Correct:
77 jecxz Return
78 subl %eax,%esi
79 sbbl %edx,%edi
80 movl %esi,(%ecx)
81 movl %edi,4(%ecx)
82 Return:
83 movl %ebx,%eax
84 xorl %edx,%edx
85 push %edi
86 push %esi
87 push %ebx
88 ret