blob: eae161e5a456474aa94915c97c4302e6f6a46ecd [file] [log] [blame]
Lucas Crowthersc6684cd2012-06-15 19:27:46 -04001@ Copyright (c) 2012, The Linux Foundation. All rights reserved.
2@
3@ Redistribution and use in source and binary forms, with or without
4@ modification, are permitted provided that the following conditions are
5@ met:
6@ * Redistributions of source code must retain the above copyright
7@ notice, this list of conditions and the following disclaimer.
8@ * Redistributions in binary form must reproduce the above
9@ copyright notice, this list of conditions and the following
10@ disclaimer in the documentation and/or other materials provided
11@ with the distribution.
12@ * Neither the name of The Linux Foundation nor the names of its
13@ contributors may be used to endorse or promote products derived
14@ from this software without specific prior written permission.
15@
16@ THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17@ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19@ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20@ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22@ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23@ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25@ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27@
28@ Additional notices preserved for attributions purposes only.
29@
30@ ====================================================
31@ Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
32@
33@ Developed at SunSoft, a Sun Microsystems, Inc. business.
34@ Permission to use, copy, modify, and distribute this
35@ software is freely granted, provided that this notice
36@ is preserved.
37@ ====================================================
38@
39@ ====================================================
40@ Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
41@
42@ Developed at SunPro, a Sun Microsystems, Inc. business.
43@ Permission to use, copy, modify, and distribute this
44@ software is freely granted, provided that this notice
45@ is preserved.
46@ ====================================================
47
48#include <private/bionic_asm.h>
49#include <private/libc_events.h>
50
51#define vmov_f64 fconstd
52
53ENTRY(cosl)
54END(cosl)
55ENTRY(cos)
56 push {r4, r6, r7, lr}
57 vmov d0, r0, r1
58 mov r2, r0
59 mov r3, r1
60 movw r1, #0x21fb
61 movt r1, #0x3fe9
62 mov r4, r3
63 bic r3, r3, #0x80000000
64 sub sp, sp, #48
65 cmp r3, r1
66 bgt .Lxgtpio4
67 cmp r3, #0x3e400000
68 bge .Lxnottiny
69 vcvt.s32.f64 s15, d0
70 vmov r3, s15
71 cmp r3, #0
72 beq .Lreturnone
73.Lxnottiny:
74 vmov.i64 d1, #0
75 bl __kernel_cos
76.Lleave_cos:
77 vmov r0, r1, d0
78.Lleave_cos_direct:
79 add sp, sp, #48
80 pop {r4, r6, r7, pc}
81.Lxgtpio4:
82 movw r2, #0xffff
83 movt r2, #0x7fef
84 cmp r3, r2
85 bgt .LxisNaN
86 movw r0, #0xd97b
87 movt r0, #0x4002
88 cmp r3, r0
89 movw r2, #0x21fb
90 bgt .Lxge3pio4
91 cmp r4, #0
92 movt r2, #0x3ff9
93 ble .Lsmallxisnegative
94 vldr d16, .Lpio2_1
95 cmp r3, r2
96 vsub.f64 d16, d0, d16
97 beq .Lxnearpio2
98 vldr d17, .Lpio2_1t
99.Lfinalizesmallxremainder:
100 vsub.f64 d0, d16, d17
101 vsub.f64 d16, d16, d0
102 vstr d0, [sp, #8]
103 vsub.f64 d1, d16, d17
104 vstr d1, [sp, #16]
105.Lnmod3is1:
106 mov r0, #1
107 bl __kernel_sin
108 vneg.f64 d0, d0
109 b .Lleave_cos
110.Lreturnone:
111 mov r0, #0
112 movw r1, #0x0000
113 movt r1, #0x3ff0
114 vmov_f64 d0, #0x70
115 b .Lleave_cos_direct
116.LxisNaN:
117 vsub.f64 d0, d0, d0
118 b .Lleave_cos
119.Lxge3pio4:
120 movt r2, #0x4139
121 cmp r3, r2
122 bgt .Lxgigantic
123 vmov_f64 d3, #0x60
124 vldr d2, .Linvpio2
125 vldr d18, .Lpio2_1
126 vabs.f64 d16, d0
127 vmla.f64 d3, d16, d2
128 vcvt.s32.f64 s3, d3
129 vcvt.f64.s32 d17, s3
130 vmov r0, s3
131 cmp r0, #31
132 vmls.f64 d16, d17, d18
133 vldr d18, .Lpio2_1t
134 vmul.f64 d18, d17, d18
135 bgt .Lcomputeremainder
136 ldr r2, .Lnpio2_hw_ptr
137 sub lr, r0, #1
138.LPICnpio2_hw0:
139 add r12, pc, r2
140 ldr r1, [r12, lr, lsl #2]
141 cmp r3, r1
142 beq .Lcomputeremainder
143.Lfinishthirditeration:
144 vsub.f64 d0, d16, d18
145 vstr d0, [sp, #8]
146.Lfinishcomputingremainder:
147 vsub.f64 d16, d16, d0
148 cmp r4, #0
149 vsub.f64 d1, d16, d18
150 vstr d1, [sp, #16]
151 blt .Lhandlenegativex
152.Lselectregion:
153 and r0, r0, #3
154 cmp r0, #1
155 beq .Lnmod3is1
156 cmp r0, #2
157 beq .Lnmod3is2
158 cmp r0, #0
159 bne .Lnmod3is0
160 bl __kernel_cos
161 b .Lleave_cos
162.Lxgigantic:
163 asr r2, r3, #20
164 vmov r6, r7, d0
165 sub r2, r2, #1040
166 mov r0, r6
167 sub r2, r2, #6
168 vldr d16, .Ltwo24
169 sub r1, r3, r2, lsl #20
170 vmov d18, r0, r1
171 vcvt.s32.f64 s15, d18
172 add r1, sp, #48
173 mov r3, #3
174 vcvt.f64.s32 d17, s15
175 vsub.f64 d18, d18, d17
176 vstr d17, [sp, #24]
177 vmul.f64 d18, d18, d16
178 vcvt.s32.f64 s15, d18
179 vcvt.f64.s32 d17, s15
180 vsub.f64 d18, d18, d17
181 vstr d17, [sp, #32]
182 vmul.f64 d16, d18, d16
183 fcmpzd d16
184 vstmdb r1!, {d16}
185 vmrs APSR_nzcv, fpscr
186 bne .Lprocessnonzeroterm
187.Lskipzeroterms:
188 vldmdb r1!, {d16}
189 sub r3, r3, #1
190 fcmpzd d16
191 vmrs APSR_nzcv, fpscr
192 beq .Lskipzeroterms
193.Lprocessnonzeroterm:
194 ldr r12, .Ltwo_over_pi_ptr
195 add r0, sp, #24
196 add r1, sp, #8
197.LPICtwo_over_pi0:
198 add lr, pc, r12
199 mov r12, #2
200 str lr, [sp, #4]
201 str r12, [sp]
202 bl __kernel_rem_pio2
203 cmp r4, #0
204 vldr d0, [sp, #8]
205 blt .Lhandlenegativxalso
206 vldr d1, [sp, #16]
207 b .Lselectregion
208.Lxnearpio2:
209 vldr d17, .Lpio2_2
210 vsub.f64 d16, d16, d17
211 vldr d17, .Lpio2_2t
212 b .Lfinalizesmallxremainder
213.Lsmallxisnegative:
214 vldr d1, .Lpio2_1
215 cmp r3, r2
216 vadd.f64 d16, d0, d1
217 beq .Lxnearnegpio2
218 vldr d17, .Lpio2_1t
219.Lfinalizesmallnegxremainder:
220 vadd.f64 d0, d16, d17
221 vsub.f64 d16, d16, d0
222 vstr d0, [sp, #8]
223 vadd.f64 d1, d16, d17
224 vstr d1, [sp, #16]
225.Lnmod3is0:
226 mov r0, #1
227 bl __kernel_sin
228 b .Lleave_cos
229.Lnmod3is2:
230 bl __kernel_cos
231 vneg.f64 d0, d0
232 b .Lleave_cos
233.Lcomputeremainder:
234 vsub.f64 d0, d16, d18
235 asr r1, r3, #20
236 vmov r2, r3, d0
237 ubfx r3, r3, #20, #11
238 rsb r3, r3, r1
239 vstr d0, [sp, #8]
240 cmp r3, #16
241 ble .Lfinishcomputingremainder
242 vldr d18, .Lpio2_2
243 vmul.f64 d20, d17, d18
244 vsub.f64 d19, d16, d20
245 vsub.f64 d16, d16, d19
246 vsub.f64 d18, d16, d20
247 vldr d16, .Lpio2_2t
248 vnmls.f64 d18, d17, d16
249 vsub.f64 d0, d19, d18
250 vmov r2, r3, d0
251 ubfx r3, r3, #20, #11
252 rsb r1, r3, r1
253 vstr d0, [sp, #8]
254 cmp r1, #49
255 ble .Lfinishseconditeration
256 vldr d5, .Lpio2_3
257 vmul.f64 d20, d17, d5
258 vsub.f64 d16, d19, d20
259 vsub.f64 d4, d19, d16
260 vldr d19, .Lpio2_3t
261 vsub.f64 d18, d4, d20
262 vnmls.f64 d18, d17, d19
263 b .Lfinishthirditeration
264.Lhandlenegativex:
265 vneg.f64 d0, d0
266 rsb r0, r0, #0
267 vneg.f64 d1, d1
268 vstr d0, [sp, #8]
269 vstr d1, [sp, #16]
270 b .Lselectregion
271.Lfinishseconditeration:
272 vmov d16, d19
273 b .Lfinishcomputingremainder
274.Lxnearnegpio2:
275 vldr d0, .Lpio2_2
276 vldr d17, .Lpio2_2t
277 vadd.f64 d16, d16, d0
278 b .Lfinalizesmallnegxremainder
279.Lhandlenegativxalso:
280 vldr d6, [sp, #16]
281 vneg.f64 d0, d0
282 rsb r0, r0, #0
283 vneg.f64 d1, d6
284 vstr d0, [sp, #8]
285 vstr d1, [sp, #16]
286 b .Lselectregion
287
288.align 3
289.Lpio2_1:
290 .word 0x54400000, 0x3ff921fb
291.Lpio2_1t:
292 .word 0x1a626331, 0x3dd0b461
293.Linvpio2:
294 .word 0x6dc9c883, 0x3fe45f30
295.Ltwo24:
296 .word 0x00000000, 0x41700000
297.Lpio2_2:
298 .word 0x1a600000, 0x3dd0b461
299.Lpio2_2t:
300 .word 0x2e037073, 0x3ba3198a
301.Lpio2_3:
302 .word 0x2e000000, 0x3ba3198a
303.Lpio2_3t:
304 .word 0x252049c1, 0x397b839a
305.Lnpio2_hw_ptr:
306 .word .Lnpio2_hw-(.LPICnpio2_hw0+8)
307.Ltwo_over_pi_ptr:
308 .word .Ltwo_over_pi-(.LPICtwo_over_pi0+8)
309END(cos)
310
311 .section .rodata.npio2_hw,"a",%progbits
312 .align 2
313.Lnpio2_hw = . + 0
314 .type npio2_hw, %object
315 .size npio2_hw, 128
316npio2_hw:
317 .word 0x3ff921fb
318 .word 0x400921fb
319 .word 0x4012d97c
320 .word 0x401921fb
321 .word 0x401f6a7a
322 .word 0x4022d97c
323 .word 0x4025fdbb
324 .word 0x402921fb
325 .word 0x402c463a
326 .word 0x402f6a7a
327 .word 0x4031475c
328 .word 0x4032d97c
329 .word 0x40346b9c
330 .word 0x4035fdbb
331 .word 0x40378fdb
332 .word 0x403921fb
333 .word 0x403ab41b
334 .word 0x403c463a
335 .word 0x403dd85a
336 .word 0x403f6a7a
337 .word 0x40407e4c
338 .word 0x4041475c
339 .word 0x4042106c
340 .word 0x4042d97c
341 .word 0x4043a28c
342 .word 0x40446b9c
343 .word 0x404534ac
344 .word 0x4045fdbb
345 .word 0x4046c6cb
346 .word 0x40478fdb
347 .word 0x404858eb
348 .word 0x404921fb
349
350 .section .rodata.two_over_pi,"a",%progbits
351 .align 2
352.Ltwo_over_pi = . + 0
353 .type two_over_pi, %object
354 .size two_over_pi, 264
355two_over_pi:
356 .word 0x00a2f983
357 .word 0x006e4e44
358 .word 0x001529fc
359 .word 0x002757d1
360 .word 0x00f534dd
361 .word 0x00c0db62
362 .word 0x0095993c
363 .word 0x00439041
364 .word 0x00fe5163
365 .word 0x00abdebb
366 .word 0x00c561b7
367 .word 0x00246e3a
368 .word 0x00424dd2
369 .word 0x00e00649
370 .word 0x002eea09
371 .word 0x00d1921c
372 .word 0x00fe1deb
373 .word 0x001cb129
374 .word 0x00a73ee8
375 .word 0x008235f5
376 .word 0x002ebb44
377 .word 0x0084e99c
378 .word 0x007026b4
379 .word 0x005f7e41
380 .word 0x003991d6
381 .word 0x00398353
382 .word 0x0039f49c
383 .word 0x00845f8b
384 .word 0x00bdf928
385 .word 0x003b1ff8
386 .word 0x0097ffde
387 .word 0x0005980f
388 .word 0x00ef2f11
389 .word 0x008b5a0a
390 .word 0x006d1f6d
391 .word 0x00367ecf
392 .word 0x0027cb09
393 .word 0x00b74f46
394 .word 0x003f669e
395 .word 0x005fea2d
396 .word 0x007527ba
397 .word 0x00c7ebe5
398 .word 0x00f17b3d
399 .word 0x000739f7
400 .word 0x008a5292
401 .word 0x00ea6bfb
402 .word 0x005fb11f
403 .word 0x008d5d08
404 .word 0x00560330
405 .word 0x0046fc7b
406 .word 0x006babf0
407 .word 0x00cfbc20
408 .word 0x009af436
409 .word 0x001da9e3
410 .word 0x0091615e
411 .word 0x00e61b08
412 .word 0x00659985
413 .word 0x005f14a0
414 .word 0x0068408d
415 .word 0x00ffd880
416 .word 0x004d7327
417 .word 0x00310606
418 .word 0x001556ca
419 .word 0x0073a8c9
420 .word 0x0060e27b
421 .word 0x00c08c6b