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