sl@0
|
1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\mmu\t_imb.cia
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32test.h>
|
sl@0
|
19 |
#include <u32std.h>
|
sl@0
|
20 |
#include <e32math.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
#ifdef __CPU_ARM
|
sl@0
|
23 |
__NAKED__ TInt Sqrt(TReal& /*aDest*/, const TReal& /*aSrc*/)
|
sl@0
|
24 |
{
|
sl@0
|
25 |
// r0=address of aDest, r1=address of aSrc
|
sl@0
|
26 |
asm("stmfd sp!, {r4-r10,lr} ");
|
sl@0
|
27 |
#ifdef __DOUBLE_WORDS_SWAPPED__
|
sl@0
|
28 |
asm("ldmia r1, {r3,r4} "); // low mant into r4, sign:exp:high mant into r3
|
sl@0
|
29 |
#else
|
sl@0
|
30 |
asm("ldr r3, [r1, #4] ");
|
sl@0
|
31 |
asm("ldr r4, [r1, #0] ");
|
sl@0
|
32 |
#endif
|
sl@0
|
33 |
asm("bic r5, r3, #0xFF000000 ");
|
sl@0
|
34 |
asm("bic r5, r5, #0x00F00000 "); // high word of mantissa into r5
|
sl@0
|
35 |
asm("mov r2, r3, lsr #20 ");
|
sl@0
|
36 |
asm("bics r2, r2, #0x800 "); // exponent now in r2
|
sl@0
|
37 |
asm("beq fastsqrt1 "); // branch if exponent zero (zero or denormal)
|
sl@0
|
38 |
asm("mov r6, #0xFF ");
|
sl@0
|
39 |
asm("orr r6, r6, #0x700 ");
|
sl@0
|
40 |
asm("cmp r2, r6 "); // check for infinity or NaN
|
sl@0
|
41 |
asm("beq fastsqrt2 "); // branch if infinity or NaN
|
sl@0
|
42 |
asm("movs r3, r3 "); // test sign
|
sl@0
|
43 |
asm("bmi fastsqrtn "); // branch if negative
|
sl@0
|
44 |
asm("sub r2, r2, #0xFF "); // unbias the exponent
|
sl@0
|
45 |
asm("sub r2, r2, #0x300 "); //
|
sl@0
|
46 |
asm("fastsqrtd1: ");
|
sl@0
|
47 |
asm("mov r1, #0x40000000 "); // value for comparison
|
sl@0
|
48 |
asm("mov r3, #27 "); // loop counter (number of bits/2)
|
sl@0
|
49 |
asm("movs r2, r2, asr #1 "); // divide exponent by 2, LSB into CF
|
sl@0
|
50 |
asm("movcs r7, r5, lsl #11 "); // mantissa into r6,r7 with MSB in MSB of r7
|
sl@0
|
51 |
asm("orrcs r7, r7, r4, lsr #21 ");
|
sl@0
|
52 |
asm("movcs r6, r4, lsl #11 ");
|
sl@0
|
53 |
asm("movcs r4, #0 "); // r4, r5 will hold result mantissa
|
sl@0
|
54 |
asm("orrcs r7, r7, #0x80000000 "); // if exponent odd, restore MSB of mantissa
|
sl@0
|
55 |
asm("movcc r7, r5, lsl #12 "); // mantissa into r6,r7 with MSB in MSB of r7
|
sl@0
|
56 |
asm("orrcc r7, r7, r4, lsr #20 "); // if exponent even, shift mantissa left an extra
|
sl@0
|
57 |
asm("movcc r6, r4, lsl #12 "); // place, lose top bit, and
|
sl@0
|
58 |
asm("movcc r4, #1 "); // set MSB of result, and
|
sl@0
|
59 |
asm("mov r5, #0 "); // r4, r5 will hold result mantissa
|
sl@0
|
60 |
asm("mov r8, #0 "); // r8, r9 will be comparison accumulator
|
sl@0
|
61 |
asm("mov r9, #0 ");
|
sl@0
|
62 |
asm("bcc fastsqrt4 "); // if exponent even, calculate one less bit
|
sl@0
|
63 |
// as result MSB already known
|
sl@0
|
64 |
|
sl@0
|
65 |
// Main mantissa square-root loop
|
sl@0
|
66 |
asm("fastsqrt3: "); // START OF MAIN LOOP
|
sl@0
|
67 |
asm("subs r10, r7, r1 "); // subtract result:01 from acc:mant
|
sl@0
|
68 |
asm("sbcs r12, r8, r4 "); // result into r14:r12:r10
|
sl@0
|
69 |
asm("sbcs r14, r9, r5 ");
|
sl@0
|
70 |
asm("movcs r7, r10 "); // if no borrow replace accumulator with result
|
sl@0
|
71 |
asm("movcs r8, r12 ");
|
sl@0
|
72 |
asm("movcs r9, r14 ");
|
sl@0
|
73 |
asm("adcs r4, r4, r4 "); // shift result left one, putting in next bit
|
sl@0
|
74 |
asm("adcs r5, r5, r5 ");
|
sl@0
|
75 |
asm("mov r9, r9, lsl #2 "); // shift acc:mant left by 2 bits
|
sl@0
|
76 |
asm("orr r9, r9, r8, lsr #30 ");
|
sl@0
|
77 |
asm("mov r8, r8, lsl #2 ");
|
sl@0
|
78 |
asm("orr r8, r8, r7, lsr #30 ");
|
sl@0
|
79 |
asm("mov r7, r7, lsl #2 ");
|
sl@0
|
80 |
asm("orr r7, r7, r6, lsr #30 ");
|
sl@0
|
81 |
asm("mov r6, r6, lsl #2 ");
|
sl@0
|
82 |
asm("fastsqrt4: "); // Come in here if we need to do one less iteration
|
sl@0
|
83 |
asm("subs r10, r7, r1 "); // subtract result:01 from acc:mant
|
sl@0
|
84 |
asm("sbcs r12, r8, r4 "); // result into r14:r12:r10
|
sl@0
|
85 |
asm("sbcs r14, r9, r5 ");
|
sl@0
|
86 |
asm("movcs r7, r10 "); // if no borrow replace accumulator with result
|
sl@0
|
87 |
asm("movcs r8, r12 ");
|
sl@0
|
88 |
asm("movcs r9, r14 ");
|
sl@0
|
89 |
asm("adcs r4, r4, r4 "); // shift result left one, putting in next bit
|
sl@0
|
90 |
asm("adcs r5, r5, r5 ");
|
sl@0
|
91 |
asm("mov r9, r9, lsl #2 "); // shift acc:mant left by 2 bits
|
sl@0
|
92 |
asm("orr r9, r9, r8, lsr #30 ");
|
sl@0
|
93 |
asm("mov r8, r8, lsl #2 ");
|
sl@0
|
94 |
asm("orr r8, r8, r7, lsr #30 ");
|
sl@0
|
95 |
asm("mov r7, r7, lsl #2 ");
|
sl@0
|
96 |
asm("orr r7, r7, r6, lsr #30 ");
|
sl@0
|
97 |
asm("mov r6, r6, lsl #2 ");
|
sl@0
|
98 |
asm("subs r3, r3, #1 "); // decrement loop counter
|
sl@0
|
99 |
asm("bne fastsqrt3 "); // do necessary number of iterations
|
sl@0
|
100 |
|
sl@0
|
101 |
asm("movs r4, r4, lsr #1 "); // shift result mantissa right 1 place
|
sl@0
|
102 |
asm("orr r4, r4, r5, lsl #31 "); // LSB (=rounding bit) into carry
|
sl@0
|
103 |
asm("mov r5, r5, lsr #1 ");
|
sl@0
|
104 |
asm("adcs r4, r4, #0 "); // round the mantissa to 53 bits
|
sl@0
|
105 |
asm("adcs r5, r5, #0 ");
|
sl@0
|
106 |
asm("cmp r5, #0x00200000 "); // check for mantissa overflow
|
sl@0
|
107 |
asm("addeq r2, r2, #1 "); // if so, increment exponent - can never overflow
|
sl@0
|
108 |
asm("bic r5, r5, #0x00300000 "); // remove top bit of mantissa - it is implicit
|
sl@0
|
109 |
asm("add r2, r2, #0xFF "); // re-bias the exponent
|
sl@0
|
110 |
asm("add r3, r2, #0x300 "); // and move into r3
|
sl@0
|
111 |
asm("orr r3, r5, r3, lsl #20 "); // r3 now contains exponent + top of mantissa
|
sl@0
|
112 |
asm("fastsqrt_ok: ");
|
sl@0
|
113 |
#ifdef __DOUBLE_WORDS_SWAPPED__
|
sl@0
|
114 |
asm("stmia r0, {r3,r4} "); // store the result
|
sl@0
|
115 |
#else
|
sl@0
|
116 |
asm("str r3, [r0, #4] ");
|
sl@0
|
117 |
asm("str r4, [r0, #0] ");
|
sl@0
|
118 |
#endif
|
sl@0
|
119 |
asm("mov r0, #0 "); // error code KErrNone
|
sl@0
|
120 |
__POPRET("r4-r10,");
|
sl@0
|
121 |
|
sl@0
|
122 |
asm("fastsqrt1: ");
|
sl@0
|
123 |
asm("orrs r6, r5, r4 "); // exponent zero - test mantissa
|
sl@0
|
124 |
asm("beq fastsqrt_ok "); // if zero, return 0
|
sl@0
|
125 |
|
sl@0
|
126 |
asm("movs r3, r3 "); // denormal - test sign
|
sl@0
|
127 |
asm("bmi fastsqrtn "); // branch out if negative
|
sl@0
|
128 |
asm("sub r2, r2, #0xFE "); // unbias the exponent
|
sl@0
|
129 |
asm("sub r2, r2, #0x300 "); //
|
sl@0
|
130 |
asm("fastsqrtd: ");
|
sl@0
|
131 |
asm("adds r4, r4, r4 "); // shift mantissa left
|
sl@0
|
132 |
asm("adcs r5, r5, r5 ");
|
sl@0
|
133 |
asm("sub r2, r2, #1 "); // and decrement exponent
|
sl@0
|
134 |
asm("tst r5, #0x00100000 "); // test if normalised
|
sl@0
|
135 |
asm("beq fastsqrtd "); // loop until normalised
|
sl@0
|
136 |
asm("b fastsqrtd1 "); // now treat as a normalised number
|
sl@0
|
137 |
asm("fastsqrt2: "); // get here if infinity or NaN
|
sl@0
|
138 |
asm("orrs r6, r5, r4 "); // if mantissa zero, infinity
|
sl@0
|
139 |
asm("bne fastsqrtnan "); // branch if not - must be NaN
|
sl@0
|
140 |
asm("movs r3, r3 "); // test sign of infinity
|
sl@0
|
141 |
asm("bmi fastsqrtn "); // branch if -ve
|
sl@0
|
142 |
#ifdef __DOUBLE_WORDS_SWAPPED__
|
sl@0
|
143 |
asm("stmia r0, {r3,r4} "); // store the result
|
sl@0
|
144 |
#else
|
sl@0
|
145 |
asm("str r3, [r0, #4] ");
|
sl@0
|
146 |
asm("str r4, [r0, #0] ");
|
sl@0
|
147 |
#endif
|
sl@0
|
148 |
asm("mov r0, #-9 "); // return KErrOverflow
|
sl@0
|
149 |
asm("b fastsqrt_end ");
|
sl@0
|
150 |
|
sl@0
|
151 |
asm("fastsqrtn: "); // get here if negative or QNaN operand
|
sl@0
|
152 |
asm("mov r3, #0xFF000000 "); // generate "real indefinite" QNaN
|
sl@0
|
153 |
asm("orr r3, r3, #0x00F80000 "); // sign=1, exp=7FF, mantissa = 1000...0
|
sl@0
|
154 |
asm("mov r4, #0 ");
|
sl@0
|
155 |
asm("fastsqrtxa: ");
|
sl@0
|
156 |
#ifdef __DOUBLE_WORDS_SWAPPED__
|
sl@0
|
157 |
asm("stmia r0, {r3,r4} "); // store the result
|
sl@0
|
158 |
#else
|
sl@0
|
159 |
asm("str r3, [r0, #4] ");
|
sl@0
|
160 |
asm("str r4, [r0, #0] ");
|
sl@0
|
161 |
#endif
|
sl@0
|
162 |
asm("mov r0, #-6 "); // return KErrArgument
|
sl@0
|
163 |
asm("fastsqrt_end: ");
|
sl@0
|
164 |
__POPRET("r4-r10,");
|
sl@0
|
165 |
|
sl@0
|
166 |
asm("fastsqrtnan: "); // operand is a NaN
|
sl@0
|
167 |
asm("tst r5, #0x00080000 "); // test MSB of mantissa
|
sl@0
|
168 |
asm("bne fastsqrtn "); // if set it is a QNaN - so return "real indefinite"
|
sl@0
|
169 |
asm("bic r3, r3, #0x00080000 "); // else convert SNaN to QNaN
|
sl@0
|
170 |
asm("b fastsqrtxa "); // and return KErrArgument
|
sl@0
|
171 |
|
sl@0
|
172 |
asm("Sqrt__FRdRCd_end: ");
|
sl@0
|
173 |
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|
sl@0
|
176 |
__NAKED__ TUint Sqrt_Length()
|
sl@0
|
177 |
{
|
sl@0
|
178 |
asm("adr r0, Sqrt__FRdRCd_end ");
|
sl@0
|
179 |
asm("adr r1, Sqrt__FRdRCd ");
|
sl@0
|
180 |
asm("sub r0, r0, r1 ");
|
sl@0
|
181 |
__JUMP(,lr);
|
sl@0
|
182 |
}
|
sl@0
|
183 |
|
sl@0
|
184 |
__NAKED__ TInt Divide(TRealX& /*aDividend*/, const TRealX& /*aDivisor*/)
|
sl@0
|
185 |
{
|
sl@0
|
186 |
asm("stmfd sp!, {r0,r4-r9,lr} ");
|
sl@0
|
187 |
asm("ldmia r1, {r4,r5,r6} ");
|
sl@0
|
188 |
asm("ldmia r0, {r1,r2,r3} ");
|
sl@0
|
189 |
asm("bl TRealXDivide ");
|
sl@0
|
190 |
asm("ldmfd sp!, {r0,r4-r9,lr} ");
|
sl@0
|
191 |
asm("stmia r0, {r1,r2,r3} ");
|
sl@0
|
192 |
asm("mov r0, r12 ");
|
sl@0
|
193 |
__JUMP(,lr);
|
sl@0
|
194 |
|
sl@0
|
195 |
// TRealX division r1,r2,r3 / r4,r5,r6 result in r1,r2,r3
|
sl@0
|
196 |
// Error code returned in r12
|
sl@0
|
197 |
// Registers r0-r9,r12 modified
|
sl@0
|
198 |
// NB This function is purely internal to EUSER and therefore IS ONLY EVER CALLED IN ARM MODE.
|
sl@0
|
199 |
asm("TRealXDivide: ");
|
sl@0
|
200 |
asm("mov r12, #0 "); // initialise return value to KErrNone
|
sl@0
|
201 |
asm("bic r3, r3, #0x300 "); // clear rounding flags
|
sl@0
|
202 |
asm("tst r6, #1 ");
|
sl@0
|
203 |
asm("eorne r3, r3, #1 "); // Exclusive-OR signs
|
sl@0
|
204 |
asm("cmn r3, #0x10000 "); // check if dividend is NaN or infinity
|
sl@0
|
205 |
asm("bcs TRealXDivide1 "); // branch if it is
|
sl@0
|
206 |
asm("cmn r6, #0x10000 "); // check if divisor is NaN or infinity
|
sl@0
|
207 |
asm("bcs TRealXDivide2 "); // branch if it is
|
sl@0
|
208 |
asm("cmp r6, #0x10000 "); // check if divisor zero
|
sl@0
|
209 |
asm("bcc TRealXDivide3 "); // branch if it is
|
sl@0
|
210 |
asm("cmp r3, #0x10000 "); // check if dividend zero
|
sl@0
|
211 |
__JUMP(cc,lr); // if zero, exit
|
sl@0
|
212 |
asm("tst r3, #1 ");
|
sl@0
|
213 |
asm("orrne lr, lr, #1 "); // save sign in bottom bit of lr
|
sl@0
|
214 |
|
sl@0
|
215 |
// calculate result exponent
|
sl@0
|
216 |
asm("mov r0, r3, lsr #16 "); // r0=dividend exponent
|
sl@0
|
217 |
asm("sub r0, r0, r6, lsr #16 "); // r0=dividend exponent - divisor exponent
|
sl@0
|
218 |
asm("add r0, r0, #0x7F00 ");
|
sl@0
|
219 |
asm("add r0, r0, #0x00FF "); // r0 now contains result exponent
|
sl@0
|
220 |
asm("mov r6, r1 "); // move dividend into r6,r7,r8
|
sl@0
|
221 |
asm("mov r7, r2 ");
|
sl@0
|
222 |
asm("mov r8, #0 "); // use r8 to hold extra bit shifted up
|
sl@0
|
223 |
// r2:r1 will hold result mantissa
|
sl@0
|
224 |
asm("mov r2, #1 "); // we will make sure first bit is 1
|
sl@0
|
225 |
asm("cmp r7, r5 "); // compare dividend mantissa to divisor mantissa
|
sl@0
|
226 |
asm("cmpeq r6, r4 ");
|
sl@0
|
227 |
asm("bcs TRealXDivide4 "); // branch if dividend >= divisor
|
sl@0
|
228 |
asm("adds r6, r6, r6 "); // else shift dividend left one
|
sl@0
|
229 |
asm("adcs r7, r7, r7 "); // ignore carry here
|
sl@0
|
230 |
asm("sub r0, r0, #1 "); // decrement result exponent by one
|
sl@0
|
231 |
asm("TRealXDivide4: ");
|
sl@0
|
232 |
asm("subs r6, r6, r4 "); // subtract divisor from dividend
|
sl@0
|
233 |
asm("sbcs r7, r7, r5 ");
|
sl@0
|
234 |
|
sl@0
|
235 |
// Main mantissa division code
|
sl@0
|
236 |
// First calculate the top 32 bits of the result
|
sl@0
|
237 |
// Top bit is 1, do 10 lots of 3 bits the one more bit
|
sl@0
|
238 |
asm("mov r12, #10 ");
|
sl@0
|
239 |
asm("TRealXDivide5: ");
|
sl@0
|
240 |
asm("adds r6, r6, r6 "); // shift accumulator left by one
|
sl@0
|
241 |
asm("adcs r7, r7, r7 ");
|
sl@0
|
242 |
asm("adcs r8, r8, r8 ");
|
sl@0
|
243 |
asm("subs r9, r6, r4 "); // subtract divisor from accumulator, result in r9,r3
|
sl@0
|
244 |
asm("sbcs r3, r7, r5 ");
|
sl@0
|
245 |
asm("movccs r8, r8, lsr #1 "); // if borrow, check for carry from shift
|
sl@0
|
246 |
asm("movcs r6, r9 "); // if no borrow, replace accumulator with result
|
sl@0
|
247 |
asm("movcs r7, r3 ");
|
sl@0
|
248 |
asm("adcs r2, r2, r2 "); // shift in new result bit
|
sl@0
|
249 |
asm("adds r6, r6, r6 "); // shift accumulator left by one
|
sl@0
|
250 |
asm("adcs r7, r7, r7 ");
|
sl@0
|
251 |
asm("adcs r8, r8, r8 ");
|
sl@0
|
252 |
asm("subs r9, r6, r4 "); // subtract divisor from accumulator, result in r9,r3
|
sl@0
|
253 |
asm("sbcs r3, r7, r5 ");
|
sl@0
|
254 |
asm("movccs r8, r8, lsr #1 "); // if borrow, check for carry from shift
|
sl@0
|
255 |
asm("movcs r6, r9 "); // if no borrow, replace accumulator with result
|
sl@0
|
256 |
asm("movcs r7, r3 ");
|
sl@0
|
257 |
asm("adcs r2, r2, r2 "); // shift in new result bit
|
sl@0
|
258 |
asm("adds r6, r6, r6 "); // shift accumulator left by one
|
sl@0
|
259 |
asm("adcs r7, r7, r7 ");
|
sl@0
|
260 |
asm("adcs r8, r8, r8 ");
|
sl@0
|
261 |
asm("subs r9, r6, r4 "); // subtract divisor from accumulator, result in r9,r3
|
sl@0
|
262 |
asm("sbcs r3, r7, r5 ");
|
sl@0
|
263 |
asm("movccs r8, r8, lsr #1 "); // if borrow, check for carry from shift
|
sl@0
|
264 |
asm("movcs r6, r9 "); // if no borrow, replace accumulator with result
|
sl@0
|
265 |
asm("movcs r7, r3 ");
|
sl@0
|
266 |
asm("adcs r2, r2, r2 "); // shift in new result bit
|
sl@0
|
267 |
asm("subs r12, r12, #1 ");
|
sl@0
|
268 |
asm("bne TRealXDivide5 "); // iterate the loop
|
sl@0
|
269 |
asm("adds r6, r6, r6 "); // shift accumulator left by one
|
sl@0
|
270 |
asm("adcs r7, r7, r7 ");
|
sl@0
|
271 |
asm("adcs r8, r8, r8 ");
|
sl@0
|
272 |
asm("subs r9, r6, r4 "); // subtract divisor from accumulator, result in r9,r3
|
sl@0
|
273 |
asm("sbcs r3, r7, r5 ");
|
sl@0
|
274 |
asm("movccs r8, r8, lsr #1 "); // if borrow, check for carry from shift
|
sl@0
|
275 |
asm("movcs r6, r9 "); // if no borrow, replace accumulator with result
|
sl@0
|
276 |
asm("movcs r7, r3 ");
|
sl@0
|
277 |
asm("adcs r2, r2, r2 "); // shift in new result bit - now have 32 bits
|
sl@0
|
278 |
|
sl@0
|
279 |
// Now calculate the bottom 32 bits of the result
|
sl@0
|
280 |
// Do 8 lots of 4 bits
|
sl@0
|
281 |
asm("mov r12, #8 ");
|
sl@0
|
282 |
asm("TRealXDivide5a: ");
|
sl@0
|
283 |
asm("adds r6, r6, r6 "); // shift accumulator left by one
|
sl@0
|
284 |
asm("adcs r7, r7, r7 ");
|
sl@0
|
285 |
asm("adcs r8, r8, r8 ");
|
sl@0
|
286 |
asm("subs r9, r6, r4 "); // subtract divisor from accumulator, result in r9,r3
|
sl@0
|
287 |
asm("sbcs r3, r7, r5 ");
|
sl@0
|
288 |
asm("movccs r8, r8, lsr #1 "); // if borrow, check for carry from shift
|
sl@0
|
289 |
asm("movcs r6, r9 "); // if no borrow, replace accumulator with result
|
sl@0
|
290 |
asm("movcs r7, r3 ");
|
sl@0
|
291 |
asm("adcs r1, r1, r1 "); // shift in new result bit
|
sl@0
|
292 |
asm("adds r6, r6, r6 "); // shift accumulator left by one
|
sl@0
|
293 |
asm("adcs r7, r7, r7 ");
|
sl@0
|
294 |
asm("adcs r8, r8, r8 ");
|
sl@0
|
295 |
asm("subs r9, r6, r4 "); // subtract divisor from accumulator, result in r9,r3
|
sl@0
|
296 |
asm("sbcs r3, r7, r5 ");
|
sl@0
|
297 |
asm("movccs r8, r8, lsr #1 "); // if borrow, check for carry from shift
|
sl@0
|
298 |
asm("movcs r6, r9 "); // if no borrow, replace accumulator with result
|
sl@0
|
299 |
asm("movcs r7, r3 ");
|
sl@0
|
300 |
asm("adcs r1, r1, r1 "); // shift in new result bit
|
sl@0
|
301 |
asm("adds r6, r6, r6 "); // shift accumulator left by one
|
sl@0
|
302 |
asm("adcs r7, r7, r7 ");
|
sl@0
|
303 |
asm("adcs r8, r8, r8 ");
|
sl@0
|
304 |
asm("subs r9, r6, r4 "); // subtract divisor from accumulator, result in r9,r3
|
sl@0
|
305 |
asm("sbcs r3, r7, r5 ");
|
sl@0
|
306 |
asm("movccs r8, r8, lsr #1 "); // if borrow, check for carry from shift
|
sl@0
|
307 |
asm("movcs r6, r9 "); // if no borrow, replace accumulator with result
|
sl@0
|
308 |
asm("movcs r7, r3 ");
|
sl@0
|
309 |
asm("adcs r1, r1, r1 "); // shift in new result bit
|
sl@0
|
310 |
asm("adds r6, r6, r6 "); // shift accumulator left by one
|
sl@0
|
311 |
asm("adcs r7, r7, r7 ");
|
sl@0
|
312 |
asm("adcs r8, r8, r8 ");
|
sl@0
|
313 |
asm("subs r9, r6, r4 "); // subtract divisor from accumulator, result in r9,r3
|
sl@0
|
314 |
asm("sbcs r3, r7, r5 ");
|
sl@0
|
315 |
asm("movccs r8, r8, lsr #1 "); // if borrow, check for carry from shift
|
sl@0
|
316 |
asm("movcs r6, r9 "); // if no borrow, replace accumulator with result
|
sl@0
|
317 |
asm("movcs r7, r3 ");
|
sl@0
|
318 |
asm("adcs r1, r1, r1 "); // shift in new result bit
|
sl@0
|
319 |
asm("subs r12, r12, #1 ");
|
sl@0
|
320 |
asm("bne TRealXDivide5a "); // iterate the loop
|
sl@0
|
321 |
|
sl@0
|
322 |
// r2:r1 now contains a 64-bit normalised mantissa
|
sl@0
|
323 |
// need to do rounding now
|
sl@0
|
324 |
asm("and r3, lr, #1 "); // result sign back into r3
|
sl@0
|
325 |
asm("orrs r9, r6, r7 "); // check if accumulator zero
|
sl@0
|
326 |
asm("beq TRealXDivide6 "); // if it is, result is exact, else generate next bit
|
sl@0
|
327 |
asm("adds r6, r6, r6 "); // shift accumulator left by one
|
sl@0
|
328 |
asm("adcs r7, r7, r7 ");
|
sl@0
|
329 |
asm("adcs r8, r8, r8 ");
|
sl@0
|
330 |
asm("subs r6, r6, r4 "); // subtract divisor from accumulator
|
sl@0
|
331 |
asm("sbcs r7, r7, r5 ");
|
sl@0
|
332 |
asm("movccs r8, r8, lsr #1 "); // if borrow, check for carry from shift
|
sl@0
|
333 |
asm("orrcc r3, r3, #0x100 "); // if borrow, round down and set round-down flag
|
sl@0
|
334 |
asm("bcc TRealXDivide6 ");
|
sl@0
|
335 |
asm("orrs r9, r6, r7 "); // if no borrow, check if exactly half-way
|
sl@0
|
336 |
asm("moveqs r9, r1, lsr #1 "); // if exactly half-way, round to even
|
sl@0
|
337 |
asm("orrcc r3, r3, #0x100 "); // if C=0, round result down and set round-down flag
|
sl@0
|
338 |
asm("bcc TRealXDivide6 ");
|
sl@0
|
339 |
asm("orr r3, r3, #0x200 "); // else set round-up flag
|
sl@0
|
340 |
asm("adds r1, r1, #1 "); // and round mantissa up
|
sl@0
|
341 |
asm("adcs r2, r2, #0 ");
|
sl@0
|
342 |
asm("movcs r2, #0x80000000 "); // if carry, mantissa = 80000000 00000000
|
sl@0
|
343 |
asm("addcs r0, r0, #1 "); // and increment exponent
|
sl@0
|
344 |
|
sl@0
|
345 |
// check for overflow or underflow and assemble final result
|
sl@0
|
346 |
asm("TRealXDivide6: ");
|
sl@0
|
347 |
asm("add r4, r0, #1 "); // need to add 1 to get usable threshold
|
sl@0
|
348 |
asm("cmp r4, #0x10000 "); // check if exponent >= 0xFFFF
|
sl@0
|
349 |
asm("bge TRealXMultiply6 "); // if so, overflow
|
sl@0
|
350 |
asm("cmp r0, #0 "); // check for underflow
|
sl@0
|
351 |
asm("orrgt r3, r3, r0, lsl #16 "); // if no underflow, result exponent into r3, ...
|
sl@0
|
352 |
asm("movgt r12, #0 "); // ... return KErrNone ...
|
sl@0
|
353 |
__JUMP(gt,lr);
|
sl@0
|
354 |
|
sl@0
|
355 |
// underflow
|
sl@0
|
356 |
asm("and r3, r3, #1 "); // set exponent=0, keep sign
|
sl@0
|
357 |
asm("mvn r12, #9 "); // return KErrUnderflow
|
sl@0
|
358 |
__JUMP(,lr);
|
sl@0
|
359 |
|
sl@0
|
360 |
// come here if divisor is zero, dividend finite
|
sl@0
|
361 |
asm("TRealXDivide3: ");
|
sl@0
|
362 |
asm("cmp r3, #0x10000 "); // check if dividend also zero
|
sl@0
|
363 |
asm("bcc TRealXRealIndefinite "); // if so, return 'real indefinite'
|
sl@0
|
364 |
asm("orr r3, r3, #0xFF000000 "); // else return infinity with xor sign
|
sl@0
|
365 |
asm("orr r3, r3, #0x00FF0000 ");
|
sl@0
|
366 |
asm("mov r2, #0x80000000 ");
|
sl@0
|
367 |
asm("mov r1, #0 ");
|
sl@0
|
368 |
asm("mvn r12, #40 "); // return KErrDivideByZero
|
sl@0
|
369 |
__JUMP(,lr);
|
sl@0
|
370 |
|
sl@0
|
371 |
// Dividend is NaN or infinity
|
sl@0
|
372 |
asm("TRealXDivide1: ");
|
sl@0
|
373 |
asm("cmp r2, #0x80000000 "); // check for infinity
|
sl@0
|
374 |
asm("cmpeq r1, #0 ");
|
sl@0
|
375 |
asm("bne TRealXBinOpNan "); // branch if NaN
|
sl@0
|
376 |
asm("cmn r6, #0x10000 "); // check 2nd operand for NaN/infinity
|
sl@0
|
377 |
asm("mvncc r12, #8 "); // if not, return KErrOverflow
|
sl@0
|
378 |
__JUMP(cc,lr);
|
sl@0
|
379 |
|
sl@0
|
380 |
// Dividend=infinity, divisor=NaN or infinity
|
sl@0
|
381 |
asm("cmp r5, #0x80000000 "); // check 2nd operand for infinity
|
sl@0
|
382 |
asm("cmpeq r4, #0 ");
|
sl@0
|
383 |
asm("bne TRealXBinOpNan "); // branch if NaN
|
sl@0
|
384 |
asm("b TRealXRealIndefinite "); // else return 'real indefinite'
|
sl@0
|
385 |
|
sl@0
|
386 |
// Divisor is NaN or infinity, dividend finite
|
sl@0
|
387 |
asm("TRealXDivide2: ");
|
sl@0
|
388 |
asm("cmp r5, #0x80000000 "); // check for infinity
|
sl@0
|
389 |
asm("cmpeq r4, #0 ");
|
sl@0
|
390 |
asm("bne TRealXBinOpNan "); // branch if NaN
|
sl@0
|
391 |
asm("and r3, r3, #1 "); // else return zero with xor sign
|
sl@0
|
392 |
__JUMP(,lr);
|
sl@0
|
393 |
|
sl@0
|
394 |
asm("TRealXBinOpNan: "); // generic routine to process NaNs in binary
|
sl@0
|
395 |
// operations
|
sl@0
|
396 |
asm("cmn r3, #0x10000 "); // check if first operand is NaN
|
sl@0
|
397 |
asm("movcc r0, r1 "); // if not, swap the operands
|
sl@0
|
398 |
asm("movcc r1, r4 ");
|
sl@0
|
399 |
asm("movcc r4, r0 ");
|
sl@0
|
400 |
asm("movcc r0, r2 ");
|
sl@0
|
401 |
asm("movcc r2, r5 ");
|
sl@0
|
402 |
asm("movcc r5, r0 ");
|
sl@0
|
403 |
asm("movcc r0, r3 ");
|
sl@0
|
404 |
asm("movcc r3, r6 ");
|
sl@0
|
405 |
asm("movcc r6, r0 ");
|
sl@0
|
406 |
asm("cmn r6, #0x10000 "); // both operands NaNs?
|
sl@0
|
407 |
asm("bcc TRealXBinOpNan1 "); // skip if not
|
sl@0
|
408 |
asm("cmp r2, r5 "); // if so, compare the significands
|
sl@0
|
409 |
asm("cmpeq r1, r4 ");
|
sl@0
|
410 |
asm("movcc r1, r4 "); // r1,r2,r3 will get NaN with larger significand
|
sl@0
|
411 |
asm("movcc r2, r5 ");
|
sl@0
|
412 |
asm("movcc r3, r6 ");
|
sl@0
|
413 |
asm("TRealXBinOpNan1: ");
|
sl@0
|
414 |
asm("orr r2, r2, #0x40000000 "); // convert an SNaN to a QNaN
|
sl@0
|
415 |
asm("mvn r12, #5 "); // return KErrArgument
|
sl@0
|
416 |
__JUMP(,lr);
|
sl@0
|
417 |
|
sl@0
|
418 |
// Return 'real indefinite'
|
sl@0
|
419 |
asm("TRealXRealIndefinite: ");
|
sl@0
|
420 |
asm("ldr r3, __RealIndefiniteExponent ");
|
sl@0
|
421 |
asm("mov r2, #0xC0000000 ");
|
sl@0
|
422 |
asm("mov r1, #0 ");
|
sl@0
|
423 |
asm("mvn r12, #5 "); // return KErrArgument
|
sl@0
|
424 |
__JUMP(,lr);
|
sl@0
|
425 |
|
sl@0
|
426 |
// overflow
|
sl@0
|
427 |
asm("TRealXMultiply6: ");
|
sl@0
|
428 |
asm("bic r3, r3, #0x0000FF00 "); // clear rounding flags
|
sl@0
|
429 |
asm("orr r3, r3, #0xFF000000 "); // make exponent FFFF for infinity
|
sl@0
|
430 |
asm("orr r3, r3, #0x00FF0000 ");
|
sl@0
|
431 |
asm("mov r2, #0x80000000 "); // mantissa = 80000000 00000000
|
sl@0
|
432 |
asm("mov r1, #0 ");
|
sl@0
|
433 |
asm("mvn r12, #8 "); // return KErrOverflow
|
sl@0
|
434 |
__JUMP(,lr);
|
sl@0
|
435 |
|
sl@0
|
436 |
asm("__RealIndefiniteExponent: ");
|
sl@0
|
437 |
asm(".word 0xFFFF0001 ");
|
sl@0
|
438 |
|
sl@0
|
439 |
asm("Divide__FR6TRealXRC6TRealX_end: ");
|
sl@0
|
440 |
}
|
sl@0
|
441 |
|
sl@0
|
442 |
__NAKED__ TUint Divide_Length()
|
sl@0
|
443 |
{
|
sl@0
|
444 |
asm("adr r0, Divide__FR6TRealXRC6TRealX_end ");
|
sl@0
|
445 |
asm("adr r1, Divide__FR6TRealXRC6TRealX ");
|
sl@0
|
446 |
asm("sub r0, r0, r1 ");
|
sl@0
|
447 |
__JUMP(,lr);
|
sl@0
|
448 |
}
|
sl@0
|
449 |
|
sl@0
|
450 |
__NAKED__ TInt SDummy(TInt)
|
sl@0
|
451 |
{
|
sl@0
|
452 |
__JUMP(,lr);
|
sl@0
|
453 |
asm("SDummy__Fi_end: ");
|
sl@0
|
454 |
}
|
sl@0
|
455 |
|
sl@0
|
456 |
__NAKED__ TUint SDummy_Length()
|
sl@0
|
457 |
{
|
sl@0
|
458 |
asm("adr r0, SDummy__Fi_end ");
|
sl@0
|
459 |
asm("adr r1, SDummy__Fi ");
|
sl@0
|
460 |
asm("sub r0, r0, r1 ");
|
sl@0
|
461 |
__JUMP(,lr);
|
sl@0
|
462 |
}
|
sl@0
|
463 |
|
sl@0
|
464 |
__NAKED__ TInt Increment(TInt)
|
sl@0
|
465 |
{
|
sl@0
|
466 |
asm("add r0, r0, #1 ");
|
sl@0
|
467 |
__JUMP(,lr);
|
sl@0
|
468 |
asm("Increment__Fi_end: ");
|
sl@0
|
469 |
}
|
sl@0
|
470 |
|
sl@0
|
471 |
__NAKED__ TUint Increment_Length()
|
sl@0
|
472 |
{
|
sl@0
|
473 |
asm("adr r0, Increment__Fi_end ");
|
sl@0
|
474 |
asm("adr r1, Increment__Fi ");
|
sl@0
|
475 |
asm("sub r0, r0, r1 ");
|
sl@0
|
476 |
__JUMP(,lr);
|
sl@0
|
477 |
}
|
sl@0
|
478 |
|
sl@0
|
479 |
#endif
|