]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/DivU64x64Remainder.S
Import some basic libraries instances for Mde Packages.
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / DivU64x64Remainder.S
1 //
2 // Include common header file for this module.
3 //
4 #include "CommonHeader.h"
5
6 #------------------------------------------------------------------------------
7 #
8 # Copyright (c) 2006, Intel Corporation
9 # All rights reserved. This program and the accompanying materials
10 # are licensed and made available under the terms and conditions of the BSD License
11 # which accompanies this distribution. The full text of the license may be found at
12 # http://opensource.org/licenses/bsd-license.php
13 #
14 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #
17 # Module Name:
18 #
19 # DivU64x64Remainder.asm
20 #
21 # Abstract:
22 #
23 # Calculate the quotient of a 64-bit integer by a 64-bit integer and returns
24 # both the quotient and the remainder
25 #
26 #------------------------------------------------------------------------------
27
28 .globl ASM_PFX(InternalMathDivRemU64x32), ASM_PFX(InternalMathDivRemU64x64)
29
30 #------------------------------------------------------------------------------
31 # UINT64
32 # EFIAPI
33 # InternalMathDivRemU64x64 (
34 # IN UINT64 Dividend,
35 # IN UINT64 Divisor,
36 # OUT UINT64 *Remainder OPTIONAL
37 # );
38 #------------------------------------------------------------------------------
39 ASM_PFX(InternalMathDivRemU64x64):
40 movl 16(%esp), %ecx
41 testl %ecx, %ecx
42 jnz Hard
43 movl 20(%esp), %ecx
44 jecxz L1
45 and $0, 4(%ecx)
46 movl %ecx, 16(%esp)
47 L1:
48 jmp ASM_PFX(InternalMathDivRemU64x32)
49 Hard:
50 push %ebx
51 push %esi
52 push %edi
53 mov 20(%esp), %edx
54 mov 16(%esp), %eax
55 movl %edx, %edi
56 movl %eax, %esi
57 mov 24(%esp), %ebx
58 L2:
59 shrl %edx
60 rcrl $1, %eax
61 shrdl $1, %ecx, %ebx
62 shrl %ecx
63 jnz L2
64 divl %ebx
65 movl %eax, %ebx
66 movl 28(%esp), %ecx
67 mull 24(%esp)
68 imull %ebx, %ecx
69 addl %ecx, %edx
70 mov 32(%esp), %ecx
71 jc TooLarge
72 cmpl %edx, %edi
73 ja Correct
74 jb TooLarge
75 cmpl %eax, %esi
76 jae Correct
77 TooLarge:
78 decl %ebx
79 jecxz Return
80 sub 24(%esp), %eax
81 sbb 28(%esp), %edx
82 Correct:
83 jecxz Return
84 subl %eax, %esi
85 sbbl %edx, %edi
86 movl %esi, (%ecx)
87 movl %edi, 4(%ecx)
88 Return:
89 movl %ebx, %eax
90 xorl %edx, %edx
91 pop %edi
92 pop %esi
93 pop %ebx
94 ret