Update contrib.
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\euser\epoc\win32\uc_i64.cpp
21 #pragma warning ( disable : 4100 ) // unreferenced formal parameter
22 #pragma warning ( disable : 4414 ) // short jump to function converted to near
24 extern "C" void UDiv64();
29 EXPORT_C __NAKED__ void Math::Mul64(Int64 /*aX*/, Int64 /*aY*/, Int64& /*aOutH*/, Uint64& /*aOutL*/)
31 Multiply aX by aY to generate a 128 bit result.
33 The high order 64 bits of this calculation are stored in aOutH,
34 and the low order 64 bits are stored in aOutL.
36 @param aX The first 64-bit operand.
37 @param aY The second 64-bit operand.
38 @param aOutH The high order 64 bits of the result.
39 @param aOutL The low order 64 bits of the result.
43 _asm mul dword ptr [esp+12] // edx:eax = x0*y0
46 _asm push ebx // [esp+16]=&aX, [esp+24]=&aY, [esp+32]=&aOutH, [esp+36]=&aOutL
48 _asm mov ebx, edx // ebx:ecx = x0*y0
49 _asm mov eax, [esp+16]
50 _asm mul dword ptr [esp+28] // edx:eax = x0*y1
53 _asm adc esi, edx // esi:ebx:ecx = x0*y
54 _asm mov eax, [esp+20] // eax=x1
55 _asm imul dword ptr [esp+28] // edx:eax = x1*y1
58 _asm adc edi, 0 // partial result in edi:esi:ebx:ecx
59 _asm cmp dword ptr [esp+28], 0 // y<0 ?
61 _asm sub esi, [esp+16] // if so, subtract x0<<64
64 _asm mov eax, [esp+20] // eax=x1
65 _asm cmp eax, 0 // x<0 ?
67 _asm sub esi, [esp+24] // if so, subtract y0<<64
70 _asm mul dword ptr [esp+24] // edx:eax = x1*y0
72 _asm mov eax, [esp+32] // eax=&aOutH
74 _asm mov edx, [esp+36] // edx=&aOutL
75 _asm adc edi, 0 // full result now in edi:esi:ebx:ecx
77 _asm mov [eax+4], edi // store high 64
79 _asm mov [edx+4], ebx // store low 64
89 EXPORT_C __NAKED__ void Math::UMul64(Uint64 /*aX*/, Uint64 /*aY*/, Uint64& /*aOutH*/, Uint64& /*aOutL*/)
91 Multiply aX by aY to generate a 128 bit result.
93 The high order 64 bits of this calculation are stored in aOutH,
94 and the low order 64 bits are stored in aOutL.
96 @param aX The first 64-bit operand.
97 @param aY The second 64-bit operand.
98 @param aOutH The high order 64 bits of the result.
99 @param aOutL The low order 64 bits of the result.
102 _asm mov eax, [esp+4]
103 _asm mul dword ptr [esp+12] // edx:eax = x0*y0
106 _asm push ebx // [esp+16]=&aX, [esp+24]=&aY, [esp+32]=&aOutH, [esp+36]=&aOutL
108 _asm mov ebx, edx // ebx:ecx = x0*y0
109 _asm mov eax, [esp+16]
110 _asm mul dword ptr [esp+28] // edx:eax = x0*y1
113 _asm adc esi, edx // esi:ebx:ecx = x0*y
114 _asm mov eax, [esp+20] // eax=x1
115 _asm mul dword ptr [esp+28] // edx:eax = x1*y1
118 _asm adc edi, 0 // partial result in edi:esi:ebx:ecx
119 _asm mov eax, [esp+20]
120 _asm mul dword ptr [esp+24] // edx:eax = x1*y0
122 _asm mov eax, [esp+32] // eax=&aOutH
124 _asm mov edx, [esp+36] // edx=&aOutL
125 _asm adc edi, 0 // full result now in edi:esi:ebx:ecx
127 _asm mov [eax+4], edi // store high 64
129 _asm mov [edx+4], ebx // store low 64
139 EXPORT_C __NAKED__ Int64 Math::DivMod64(Int64 /*aDividend*/, Int64 /*aDivisor*/, Int64& /*aRemainder*/)
141 Divides aDividend by aDivisor.
143 The quotient is returned, and the remainder is stored in aRemainder.
144 The remainder has same sign as the dividend.
146 @param aDividend The 64-bit dividend.
147 @param aDivisor The 64-bit divisor.
148 @param aRemainder The 64-bit remainder.
150 @return The 64-bit quotient.
153 _asm mov eax, [esp+4]
154 _asm mov edx, [esp+8] // edx:eax = dividend
160 divmod64_0: // edx:eax = ABS(dividend)
165 _asm mov esi, [esp+28]
166 _asm mov edi, [esp+32] // edi:esi = dividend
171 _asm sbb edi, 0 // edi:esi = ABS(dividend)
173 _asm call UDiv64 // do division, quotient in ebx:eax remainder in edi:edx
174 _asm xchg ebx, edx // quotient in edx:eax, remainder in edi:ebx
175 _asm mov ecx, [esp+24] // ecx=dividend high
176 _asm xor ecx, [esp+32] // ecx=dividend high ^ divisor high
181 divmod64_2: // edx:eax = quotient with correct sign
182 _asm cmp dword ptr [esp+24], 0
187 divmod64_3: // edi:ebx = remainder with correct sign
188 _asm mov ecx, [esp+36] // ecx=&aRemainder
190 _asm mov [ecx+4], edi
201 EXPORT_C __NAKED__ Uint64 Math::UDivMod64(Uint64 /*aDividend*/, Uint64 /*aDivisor*/, Uint64& /*aRemainder*/)
203 Divides aDividend by aDivisor.
205 The quotient is returned, and the remainder is stored in aRemainder.
207 @param aDividend The 64-bit dividend.
208 @param aDivisor The 64-bit divisor.
209 @param aRemainder The 64-bit remainder.
211 @return The 64-bit quotient.
214 _asm mov eax, [esp+4]
215 _asm mov edx, [esp+8] // edx:eax = dividend
220 _asm mov esi, [esp+28]
221 _asm mov edi, [esp+32] // edi:esi = dividend
222 _asm call UDiv64 // do division, quotient in ebx:eax remainder in edi:edx
223 _asm xchg ebx, edx // quotient in edx:eax, remainder in edi:ebx
224 _asm mov ecx, [esp+36] // ecx=&aRemainder
226 _asm mov [ecx+4], edi
234 #pragma warning ( default : 4100 )
235 #pragma warning ( default : 4414 )