]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseLib/Ia32/DivU64x64Remainder.S
temporary roll back build.exe because the some string definition are missed by strgat...
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / DivU64x64Remainder.S
CommitLineData
e1f414b6 1#------------------------------------------------------------------------------\r
2#\r
1f86b07d 3# Copyright (c) 2006 - 2008, Intel Corporation\r
e1f414b6 4# All rights reserved. This program and the accompanying materials\r
5# are licensed and made available under the terms and conditions of the BSD License\r
6# which accompanies this distribution. The full text of the license may be found at\r
7# http://opensource.org/licenses/bsd-license.php\r
8#\r
9# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11#\r
12# Module Name:\r
13#\r
1f86b07d 14# DivU64x64Remainder.S\r
e1f414b6 15#\r
16# Abstract:\r
17#\r
18# Calculate the quotient of a 64-bit integer by a 64-bit integer and returns\r
19# both the quotient and the remainder\r
20#\r
21#------------------------------------------------------------------------------\r
22\r
23.globl ASM_PFX(InternalMathDivRemU64x32), ASM_PFX(InternalMathDivRemU64x64)\r
24\r
25#------------------------------------------------------------------------------\r
26# UINT64\r
27# EFIAPI\r
28# InternalMathDivRemU64x64 (\r
29# IN UINT64 Dividend,\r
30# IN UINT64 Divisor,\r
31# OUT UINT64 *Remainder OPTIONAL\r
32# );\r
33#------------------------------------------------------------------------------\r
34ASM_PFX(InternalMathDivRemU64x64):\r
57246fe0 35 movl 16(%esp), %ecx # ecx <- divisor[32..63]\r
e1f414b6 36 testl %ecx, %ecx\r
57246fe0 37 jnz Hard # call _@DivRemU64x64 if Divisor > 2^32\r
e1f414b6 38 movl 20(%esp), %ecx\r
39 jecxz L1\r
57246fe0 40 and $0, 4(%ecx) # zero high dword of remainder\r
41 movl %ecx, 16(%esp) # set up stack frame to match DivRemU64x32\r
e1f414b6 42L1:\r
43 jmp ASM_PFX(InternalMathDivRemU64x32)\r
44Hard:\r
45 push %ebx\r
46 push %esi\r
47 push %edi\r
48 mov 20(%esp), %edx\r
57246fe0 49 mov 16(%esp), %eax # edx:eax <- dividend\r
e1f414b6 50 movl %edx, %edi\r
57246fe0 51 movl %eax, %esi # edi:esi <- dividend\r
52 mov 24(%esp), %ebx # ecx:ebx <- divisor\r
e1f414b6 53L2:\r
54 shrl %edx\r
55 rcrl $1, %eax\r
56 shrdl $1, %ecx, %ebx\r
57 shrl %ecx\r
58 jnz L2\r
59 divl %ebx\r
57246fe0 60 movl %eax, %ebx # ebx <- quotient \r
61 movl 28(%esp), %ecx # ecx <- high dword of divisor \r
62 mull 24(%esp) # edx:eax <- quotient * divisor[0..31]\r
63 imull %ebx, %ecx # ecx <- quotient * divisor[32..63] \r
64 addl %ecx, %edx # edx <- (quotient * divisor)[32..63] \r
65 mov 32(%esp), %ecx # ecx <- addr for Remainder \r
66 jc TooLarge # product > 2^64 \r
67 cmpl %edx, %edi # compare high 32 bits \r
68 ja Correct \r
69 jb TooLarge # product > dividend \r
70 cmpl %eax, %esi \r
71 jae Correct # product <= dividend \r
e1f414b6 72TooLarge:\r
57246fe0 73 decl %ebx # adjust quotient by -1 \r
74 jecxz Return # return if Remainder == NULL \r
75 sub 24(%esp), %eax \r
76 sbb 28(%esp), %edx # edx:eax <- (quotient - 1) * divisor\r
e1f414b6 77Correct:\r
78 jecxz Return\r
79 subl %eax, %esi\r
57246fe0 80 sbbl %edx, %edi # edi:esi <- remainder\r
e1f414b6 81 movl %esi, (%ecx)\r
82 movl %edi, 4(%ecx)\r
83Return:\r
57246fe0 84 movl %ebx, %eax # eax <- quotient \r
85 xorl %edx, %edx # quotient is 32 bits long\r
e1f414b6 86 pop %edi\r
87 pop %esi\r
88 pop %ebx\r
89 ret\r