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\arm\uc_i64.cia
21 #if defined(__GCC32__)
22 extern "C" void __division_by_zero();
23 #define DIV_BY_ZERO " __division_by_zero "
24 #elif defined(__ARMCC__)
25 extern "C" void __rt_div0 (void);
26 #define DIV_BY_ZERO " __cpp(__rt_div0) "
32 EXPORT_C __NAKED__ void Math::Mul64(Int64 /*aX*/, Int64 /*aY*/, Int64& /*aOutH*/, Uint64& /*aOutL*/)
34 Multiply aX by aY to generate a 128 bit result.
36 The high order 64 bits of this calculation are stored in aOutH,
37 and the low order 64 bits are stored in aOutL.
39 @param aX The first 64-bit operand.
40 @param aY The second 64-bit operand.
41 @param aOutH The high order 64 bits of the result.
42 @param aOutL The low order 64 bits of the result.
45 // Enter with r1:r0=aX, r3:r2=aY, [sp]=&aOutH, [sp+4]=&aOutL
46 asm("stmfd sp!, {r4-r5,lr} ");
47 asm("umull r4, r5, r0, r2 "); // r5:r4 = x0 * y0
48 asm("mov r12, #0 "); // clear r12 initially
49 asm("umlal r5, r12, r0, r3 "); // r12:r5:r4 = x0 * y
50 asm("mov r14, #0 "); // clear r14 initially
51 asm("smlal r12, r14, r1, r3 "); // r14:r12:r5:r4 = x0 * y + (x1*y1)<<64
52 asm("and r3, r0, r3, asr #32 "); // if aY<0, r3=x0 else r3=0
53 asm("and r0, r2, r1, asr #32 "); // if aX<0, r0=y0 else r0=0
54 asm("subs r12, r12, r3 ");
55 asm("sbcs r14, r14, #0 ");
56 asm("subs r12, r12, r0 ");
57 asm("sbcs r14, r14, #0 ");
58 asm("umull r0, r3, r1, r2 "); // r3:r0 = x1 * y0
59 asm("ldr r1, [sp, #12] "); // r1=&aOutH
60 asm("ldr r2, [sp, #16] "); // r1=&aOutL
61 asm("adds r5, r5, r0 "); // shift left by 32 and add to give final result
62 asm("adcs r12, r12, r3 ");
63 asm("adcs r14, r14, #0 "); // final result now in r14:r12:r5:r4
64 asm("stmia r2, {r4,r5} "); // store low 64
65 asm("stmia r1, {r12,r14} "); // store high 64
72 EXPORT_C __NAKED__ void Math::UMul64(Uint64 /*aX*/, Uint64 /*aY*/, Uint64& /*aOutH*/, Uint64& /*aOutL*/)
74 Multiply aX by aY to generate a 128 bit result.
76 The high order 64 bits of this calculation are stored in aOutH,
77 and the low order 64 bits are stored in aOutL.
79 @param aX The first 64-bit operand.
80 @param aY The second 64-bit operand.
81 @param aOutH The high order 64 bits of the result.
82 @param aOutL The low order 64 bits of the result.
85 // Enter with r1:r0=aX, r3:r2=aY, [sp]=&aOutH, [sp+4]=&aOutL
86 asm("stmfd sp!, {r4-r5,lr} ");
87 asm("umull r4, r5, r0, r2 "); // r5:r4 = x0 * y0
88 asm("mov r12, #0 "); // clear r12 initially
89 asm("umlal r5, r12, r0, r3 "); // r12:r5:r4 = x0 * y
90 asm("mov r14, #0 "); // clear r14 initially
91 asm("umlal r12, r14, r1, r3 "); // r14:r12:r5:r4 = x0 * y + (x1*y1)<<64
92 // r0, r3 no longer required
93 asm("umull r0, r3, r1, r2 "); // r3:r0 = x1 * y0
94 asm("ldr r1, [sp, #12] "); // r1=&aOutH
95 asm("ldr r2, [sp, #16] "); // r1=&aOutL
96 asm("adds r5, r5, r0 "); // shift left by 32 and add to give final result
97 asm("adcs r12, r12, r3 ");
98 asm("adcs r14, r14, #0 "); // final result now in r14:r12:r5:r4
99 asm("stmia r2, {r4,r5} "); // store low 64
100 asm("stmia r1, {r12,r14} "); // store high 64
107 EXPORT_C __NAKED__ Int64 Math::DivMod64(Int64 /*aDividend*/, Int64 /*aDivisor*/, Int64& /*aRemainder*/)
109 Divides aDividend by aDivisor.
111 The quotient is returned, and the remainder is stored in aRemainder.
112 The remainder has same sign as the dividend.
114 @param aDividend The 64-bit dividend.
115 @param aDivisor The 64-bit divisor.
116 @param aRemainder The 64-bit remainder.
118 @return The 64-bit quotient.
121 // Enter with: r1:r0=dividend, r3:r2=divisor, [sp]=&aRemainder
122 // Return quotient in r1:r0
123 asm("stmfd sp!, {r4-r8,lr} ");
124 __EH_FRAME_PUSH2(r4-r8,lr)
125 asm("mov r8, r1, asr #1 "); // r8 bit 31 = r8 bit 30 = dividend sign
126 asm("eor r8, r8, r3, lsr #1 "); // r8 bit 31 = dividend sign, r8 bit 30 = quotient sign
129 asm("rsbs r0, r0, #0 "); // r1:r0=ABS(dividend)
130 asm("rscs r1, r1, #0 ");
134 asm("rsbs r2, r2, #0 "); // r3:r2=ABS(divisor)
135 asm("rscs r3, r3, #0 ");
138 asm(".extern UDiv01 ");
139 asm("bl UDiv01 "); // do division, quotient->r5:r4, rem->r6:r3
140 asm("mov r2, r3"); // move to make regs same as EABI function
145 asm(".extern __aeabi_uldivmod ");
146 asm("bl __aeabi_uldivmod "); // do division, quotient->r1:r0, rem->r3:r2
148 asm("add ip, r8, r8 "); // ip bit 31 = quotient sign
149 asm("ldr r6, [sp, #24] "); // r6 = &aRemainder
150 asm("eors r4, r0, ip, asr #32 "); // quotient into r5:r4, inverted if quotient -ve
151 asm("eors r5, r1, ip, asr #32 ");
152 asm("adcs r0, r4, #0 "); // if quotient -ve, add 1 whilst moving back to r1:r0
153 asm("adcs r1, r5, #0 ");
156 asm("rsbs r2, r2, #0 "); // if dividend -ve, negate remainder
157 asm("rscs r3, r3, #0 ");
159 asm("stmia r6, {r2,r3} "); // store remainder
166 EXPORT_C __NAKED__ Uint64 Math::UDivMod64(Uint64 /*aDividend*/, Uint64 /*aDivisor*/, Uint64& /*aRemainder*/)
168 Divides aDividend by aDivisor.
170 The quotient is returned, and the remainder is stored in aRemainder.
172 @param aDividend The 64-bit dividend.
173 @param aDivisor The 64-bit divisor.
174 @param aRemainder The 64-bit remainder.
176 @return The 64-bit quotient.
179 // Enter with: r1:r0=dividend, r3:r2=divisor, [sp]=&aRemainder
180 // Return quotient in r1:r0
182 // need to keep sp 8-byte aligned
183 asm("stmfd sp!, {r4-r8,lr} ");
184 __EH_FRAME_PUSH2(r4-r8,lr)
186 asm("stmfd sp!, {r4-r7,lr} ");
190 asm(".extern UDiv01 ");
191 asm("bl UDiv01 "); // do division, quotient->r5:r4, rem->r6:r3
192 asm("mov r2, r3"); // move to make regs same as EABI function
197 asm("bl __aeabi_uldivmod "); // do division, quotient->r1:r0, rem->r3:r2
201 asm("ldr r6, [sp, #24] "); // r6 = &aRemainder
203 asm("ldr r6, [sp, #20] "); // r6 = &aRemainder
206 asm("stmia r6, {r2,r3} "); // store remainder