2006-04-22 00:54:32 +02:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; Copyright (c) 2006, Intel Corporation
|
|
|
|
; All rights reserved. This program and the accompanying materials
|
|
|
|
; are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
; which accompanies this distribution. The full text of the license may be found at
|
|
|
|
; http://opensource.org/licenses/bsd-license.php
|
|
|
|
;
|
|
|
|
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
;
|
|
|
|
; Module Name:
|
|
|
|
;
|
|
|
|
; DivU64x64Remainder.asm
|
|
|
|
;
|
|
|
|
; Abstract:
|
|
|
|
;
|
|
|
|
; Calculate the quotient of a 64-bit integer by a 64-bit integer and returns
|
|
|
|
; both the quotient and the remainder
|
|
|
|
;
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.386
|
|
|
|
.model flat,C
|
|
|
|
.code
|
|
|
|
|
|
|
|
EXTERN InternalMathDivRemU64x32:PROC
|
|
|
|
|
2006-07-21 10:47:38 +02:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; UINT64
|
|
|
|
; EFIAPI
|
|
|
|
; InternalMathDivRemU64x64 (
|
|
|
|
; IN UINT64 Dividend,
|
|
|
|
; IN UINT64 Divisor,
|
|
|
|
; OUT UINT64 *Remainder OPTIONAL
|
|
|
|
; );
|
|
|
|
;------------------------------------------------------------------------------
|
2006-04-22 00:54:32 +02:00
|
|
|
InternalMathDivRemU64x64 PROC
|
|
|
|
mov ecx, [esp + 16]
|
|
|
|
test ecx, ecx
|
2006-07-21 10:47:38 +02:00
|
|
|
jnz _@DivRemU64x64 ; call _@DivRemU64x64 if Divisor > 2^32
|
2006-04-22 00:54:32 +02:00
|
|
|
mov ecx, [esp + 20]
|
|
|
|
jecxz @F
|
|
|
|
and dword ptr [ecx + 4], 0
|
|
|
|
mov [esp + 16], ecx
|
|
|
|
@@:
|
|
|
|
jmp InternalMathDivRemU64x32
|
|
|
|
InternalMathDivRemU64x64 ENDP
|
|
|
|
|
|
|
|
_@DivRemU64x64 PROC USES ebx esi edi
|
|
|
|
mov edx, dword ptr [esp + 20]
|
2006-07-21 10:47:38 +02:00
|
|
|
mov eax, dword ptr [esp + 16] ; edx:eax <- dividend
|
2006-04-22 00:54:32 +02:00
|
|
|
mov edi, edx
|
2006-07-21 10:47:38 +02:00
|
|
|
mov esi, eax ; edi:esi <- dividend
|
|
|
|
mov ebx, dword ptr [esp + 24] ; ecx:ebx <- divisor
|
2006-04-22 00:54:32 +02:00
|
|
|
@@:
|
|
|
|
shr edx, 1
|
|
|
|
rcr eax, 1
|
|
|
|
shrd ebx, ecx, 1
|
|
|
|
shr ecx, 1
|
|
|
|
jnz @B
|
|
|
|
div ebx
|
2006-07-21 10:47:38 +02:00
|
|
|
mov ebx, eax ; ebx <- quotient
|
2006-04-22 00:54:32 +02:00
|
|
|
mov ecx, [esp + 28]
|
|
|
|
mul dword ptr [esp + 24]
|
|
|
|
imul ecx, ebx
|
|
|
|
add edx, ecx
|
|
|
|
mov ecx, dword ptr [esp + 32]
|
2006-07-21 10:47:38 +02:00
|
|
|
jc @TooLarge ; product > 2^64
|
|
|
|
cmp edi, edx ; compare high 32 bits
|
2006-04-22 00:54:32 +02:00
|
|
|
ja @Correct
|
2006-07-21 10:47:38 +02:00
|
|
|
jb @TooLarge ; product > dividend
|
2006-04-22 00:54:32 +02:00
|
|
|
cmp esi, eax
|
2006-07-21 10:47:38 +02:00
|
|
|
jae @Correct ; product <= dividend
|
2006-04-22 00:54:32 +02:00
|
|
|
@TooLarge:
|
2006-07-21 10:47:38 +02:00
|
|
|
dec ebx ; adjust quotient by -1
|
|
|
|
jecxz @Return ; return if Remainder == NULL
|
2006-04-22 00:54:32 +02:00
|
|
|
sub eax, dword ptr [esp + 24]
|
|
|
|
sbb edx, dword ptr [esp + 28]
|
|
|
|
@Correct:
|
|
|
|
jecxz @Return
|
|
|
|
sub esi, eax
|
2006-07-21 10:47:38 +02:00
|
|
|
sbb edi, edx ; edi:esi <- remainder
|
2006-04-22 00:54:32 +02:00
|
|
|
mov [ecx], esi
|
|
|
|
mov [ecx + 4], edi
|
|
|
|
@Return:
|
2006-07-21 10:47:38 +02:00
|
|
|
mov eax, ebx ; eax <- quotient
|
2006-04-22 00:54:32 +02:00
|
|
|
xor edx, edx
|
|
|
|
ret
|
|
|
|
_@DivRemU64x64 ENDP
|
|
|
|
|
|
|
|
END
|