]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/ia64/fpu/libm_sincos.S
2.5-18.1
[thirdparty/glibc.git] / sysdeps / ia64 / fpu / libm_sincos.S
CommitLineData
0ecb606c
JJ
1.file "libm_sincos.s"
2
3
4// Copyright (c) 2002 - 2005, Intel Corporation
5// All rights reserved.
6//
7// Contributed 2002 by the Intel Numerics Group, Intel Corporation
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12//
13// * Redistributions of source code must retain the above copyright
14// notice, this list of conditions and the following disclaimer.
15//
16// * Redistributions in binary form must reproduce the above copyright
17// notice, this list of conditions and the following disclaimer in the
18// documentation and/or other materials provided with the distribution.
19//
20// * The name of Intel Corporation may not be used to endorse or promote
21// products derived from this software without specific prior written
22// permission.
23
24// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
28// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
32// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
33// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35//
36// Intel Corporation is the author of this code, and requests that all
37// problem reports or change requests be submitted to it directly at
38// http://www.intel.com/software/products/opensource/libraries/num.htm.
39//
40// History
41//==============================================================
42// 02/01/02 Initial version
43// 02/18/02 Large arguments processing routine is excluded.
44// External interface entry points are added
45// 03/13/02 Corrected restore of predicate registers
46// 03/19/02 Added stack unwind around call to __libm_cis_large
47// 09/05/02 Work range is widened by reduction strengthen (3 parts of Pi/16)
48// 02/10/03 Reordered header: .section, .global, .proc, .align
49// 08/08/03 Improved performance
50// 02/11/04 cis is moved to the separate file.
51// 03/31/05 Reformatted delimiters between data tables
52//
53// API
54//==============================================================
55// 1) void sincos(double, double*s, double*c)
56// 2) __libm_sincos - internal LIBM function, that accepts
57// argument in f8 and returns cosine through f8, sine through f9
58//
59// Overview of operation
60//==============================================================
61//
62// Step 1
63// ======
64// Reduce x to region -1/2*pi/2^k ===== 0 ===== +1/2*pi/2^k where k=4
65// divide x by pi/2^k.
66// Multiply by 2^k/pi.
67// nfloat = Round result to integer (round-to-nearest)
68//
69// r = x - nfloat * pi/2^k
70// Do this as ((((x - nfloat * HIGH(pi/2^k))) -
71// nfloat * LOW(pi/2^k)) -
72// nfloat * LOWEST(pi/2^k) for increased accuracy.
73// pi/2^k is stored as two numbers that when added make pi/2^k.
74// pi/2^k = HIGH(pi/2^k) + LOW(pi/2^k)
75// HIGH and LOW parts are rounded to zero values,
76// and LOWEST is rounded to nearest one.
77//
78// x = (nfloat * pi/2^k) + r
79// r is small enough that we can use a polynomial approximation
80// and is referred to as the reduced argument.
81//
82// Step 3
83// ======
84// Take the unreduced part and remove the multiples of 2pi.
85// So nfloat = nfloat (with lower k+1 bits cleared) + lower k+1 bits
86//
87// nfloat (with lower k+1 bits cleared) is a multiple of 2^(k+1)
88// N * 2^(k+1)
89// nfloat * pi/2^k = N * 2^(k+1) * pi/2^k + (lower k+1 bits) * pi/2^k
90// nfloat * pi/2^k = N * 2 * pi + (lower k+1 bits) * pi/2^k
91// nfloat * pi/2^k = N2pi + M * pi/2^k
92//
93//
94// Sin(x) = Sin((nfloat * pi/2^k) + r)
95// = Sin(nfloat * pi/2^k) * Cos(r) + Cos(nfloat * pi/2^k) * Sin(r)
96//
97// Sin(nfloat * pi/2^k) = Sin(N2pi + Mpi/2^k)
98// = Sin(N2pi)Cos(Mpi/2^k) + Cos(N2pi)Sin(Mpi/2^k)
99// = Sin(Mpi/2^k)
100//
101// Cos(nfloat * pi/2^k) = Cos(N2pi + Mpi/2^k)
102// = Cos(N2pi)Cos(Mpi/2^k) + Sin(N2pi)Sin(Mpi/2^k)
103// = Cos(Mpi/2^k)
104//
105// Sin(x) = Sin(Mpi/2^k) Cos(r) + Cos(Mpi/2^k) Sin(r)
106//
107//
108// Step 4
109// ======
110// 0 <= M < 2^(k+1)
111// There are 2^(k+1) Sin entries in a table.
112// There are 2^(k+1) Cos entries in a table.
113//
114// Get Sin(Mpi/2^k) and Cos(Mpi/2^k) by table lookup.
115//
116//
117// Step 5
118// ======
119// Calculate Cos(r) and Sin(r) by polynomial approximation.
120//
121// Cos(r) = 1 + r^2 q1 + r^4 q2 + r^6 q3 + ... = Series for Cos
122// Sin(r) = r + r^3 p1 + r^5 p2 + r^7 p3 + ... = Series for Sin
123//
124// and the coefficients q1, q2, ... and p1, p2, ... are stored in a table
125//
126//
127// Calculate
128// Sin(x) = Sin(Mpi/2^k) Cos(r) + Cos(Mpi/2^k) Sin(r)
129//
130// as follows
131//
132// S[m] = Sin(Mpi/2^k) and C[m] = Cos(Mpi/2^k)
133// rsq = r*r
134//
135//
136// P = p1 + r^2p2 + r^4p3 + r^6p4
137// Q = q1 + r^2q2 + r^4q3 + r^6q4
138//
139// rcub = r * rsq
140// Sin(r) = r + rcub * P
141// = r + r^3p1 + r^5p2 + r^7p3 + r^9p4 + ... = Sin(r)
142//
143// The coefficients are not exactly these values, but almost.
144//
145// p1 = -1/6 = -1/3!
146// p2 = 1/120 = 1/5!
147// p3 = -1/5040 = -1/7!
148// p4 = 1/362889 = 1/9!
149//
150// P = r + rcub * P
151//
152// Answer = S[m] Cos(r) + C[m] P
153//
154// Cos(r) = 1 + rsq Q
155// Cos(r) = 1 + r^2 Q
156// Cos(r) = 1 + r^2 (q1 + r^2q2 + r^4q3 + r^6q4)
157// Cos(r) = 1 + r^2q1 + r^4q2 + r^6q3 + r^8q4 + ...
158//
159// S[m] Cos(r) = S[m](1 + rsq Q)
160// S[m] Cos(r) = S[m] + S[m] rsq Q
161// S[m] Cos(r) = S[m] + s_rsq Q
162// Q = S[m] + s_rsq Q
163//
164// Then,
165//
166// Answer = Q + C[m] P
167
168// Registers used
169//==============================================================
170// general input registers:
171// r14 -> r39
172
173// predicate registers used:
174// p6 -> p14
175//
176// floating-point registers used
177// f9 -> f15
178// f32 -> f67
179
180// Assembly macros
181//==============================================================
182
183cis_Arg = f8
184
185cis_Sin_res = f9
186cis_Cos_res = f8
187
188cis_NORM_f8 = f10
189cis_W = f11
190cis_int_Nfloat = f12
191cis_Nfloat = f13
192
193cis_r = f14
194cis_rsq = f15
195cis_rcub = f32
196
197cis_Inv_Pi_by_16 = f33
198cis_Pi_by_16_hi = f34
199cis_Pi_by_16_lo = f35
200
201cis_Inv_Pi_by_64 = f36
202cis_Pi_by_16_lowest = f37
203cis_r_exact = f38
204
205
206cis_P1 = f39
207cis_Q1 = f40
208cis_P2 = f41
209cis_Q2 = f42
210cis_P3 = f43
211cis_Q3 = f44
212cis_P4 = f45
213cis_Q4 = f46
214
215cis_P_temp1 = f47
216cis_P_temp2 = f48
217
218cis_Q_temp1 = f49
219cis_Q_temp2 = f50
220
221cis_P = f51
222
223cis_SIG_INV_PI_BY_16_2TO61 = f52
224cis_RSHF_2TO61 = f53
225cis_RSHF = f54
226cis_2TOM61 = f55
227cis_NFLOAT = f56
228cis_W_2TO61_RSH = f57
229
230cis_tmp = f58
231
232cis_Sm_sin = f59
233cis_Cm_sin = f60
234
235cis_Sm_cos = f61
236cis_Cm_cos = f62
237
238cis_srsq_sin = f63
239cis_srsq_cos = f64
240
241cis_Q_sin = f65
242cis_Q_cos = f66
243cis_Q = f67
244
245/////////////////////////////////////////////////////////////
246
247cis_pResSin = r33
248cis_pResCos = r34
249
250cis_GR_sig_inv_pi_by_16 = r14
251cis_GR_rshf_2to61 = r15
252cis_GR_rshf = r16
253cis_GR_exp_2tom61 = r17
254cis_GR_n = r18
255cis_GR_n_sin = r19
256cis_exp_limit = r20
257cis_r_signexp = r21
258cis_AD_1 = r22
259cis_r_sincos = r23
260cis_r_exp = r24
261cis_r_17_ones = r25
262cis_GR_m_sin = r26
263cis_GR_32m_sin = r26
264cis_GR_n_cos = r27
265cis_GR_m_cos = r28
266cis_GR_32m_cos = r28
267cis_AD_2_sin = r29
268cis_AD_2_cos = r30
269cis_gr_tmp = r31
270
271GR_SAVE_B0 = r35
272GR_SAVE_GP = r36
273rB0_SAVED = r37
274GR_SAVE_PFS = r38
275GR_SAVE_PR = r39
276
277RODATA
278
279.align 16
280// Pi/16 parts
281LOCAL_OBJECT_START(double_cis_pi)
282 data8 0xC90FDAA22168C234, 0x00003FFC // pi/16 1st part
283 data8 0xC4C6628B80DC1CD1, 0x00003FBC // pi/16 2nd part
284 data8 0xA4093822299F31D0, 0x00003F7A // pi/16 3rd part
285LOCAL_OBJECT_END(double_cis_pi)
286
287// Coefficients for polynomials
288LOCAL_OBJECT_START(double_cis_pq_k4)
289 data8 0x3EC71C963717C63A // P4
290 data8 0x3EF9FFBA8F191AE6 // Q4
291 data8 0xBF2A01A00F4E11A8 // P3
292 data8 0xBF56C16C05AC77BF // Q3
293 data8 0x3F8111111110F167 // P2
294 data8 0x3FA555555554DD45 // Q2
295 data8 0xBFC5555555555555 // P1
296 data8 0xBFDFFFFFFFFFFFFC // Q1
297LOCAL_OBJECT_END(double_cis_pq_k4)
298
299// Sincos table (S[m], C[m])
300LOCAL_OBJECT_START(double_sin_cos_beta_k4)
301data8 0x0000000000000000 , 0x00000000 // sin( 0 pi/16) S0
302data8 0x8000000000000000 , 0x00003fff // cos( 0 pi/16) C0
303//
304data8 0xc7c5c1e34d3055b3 , 0x00003ffc // sin( 1 pi/16) S1
305data8 0xfb14be7fbae58157 , 0x00003ffe // cos( 1 pi/16) C1
306//
307data8 0xc3ef1535754b168e , 0x00003ffd // sin( 2 pi/16) S2
308data8 0xec835e79946a3146 , 0x00003ffe // cos( 2 pi/16) C2
309//
310data8 0x8e39d9cd73464364 , 0x00003ffe // sin( 3 pi/16) S3
311data8 0xd4db3148750d181a , 0x00003ffe // cos( 3 pi/16) C3
312//
313data8 0xb504f333f9de6484 , 0x00003ffe // sin( 4 pi/16) S4
314data8 0xb504f333f9de6484 , 0x00003ffe // cos( 4 pi/16) C4
315//
316data8 0xd4db3148750d181a , 0x00003ffe // sin( 5 pi/16) C3
317data8 0x8e39d9cd73464364 , 0x00003ffe // cos( 5 pi/16) S3
318//
319data8 0xec835e79946a3146 , 0x00003ffe // sin( 6 pi/16) C2
320data8 0xc3ef1535754b168e , 0x00003ffd // cos( 6 pi/16) S2
321//
322data8 0xfb14be7fbae58157 , 0x00003ffe // sin( 7 pi/16) C1
323data8 0xc7c5c1e34d3055b3 , 0x00003ffc // cos( 7 pi/16) S1
324//
325data8 0x8000000000000000 , 0x00003fff // sin( 8 pi/16) C0
326data8 0x0000000000000000 , 0x00000000 // cos( 8 pi/16) S0
327//
328data8 0xfb14be7fbae58157 , 0x00003ffe // sin( 9 pi/16) C1
329data8 0xc7c5c1e34d3055b3 , 0x0000bffc // cos( 9 pi/16) -S1
330//
331data8 0xec835e79946a3146 , 0x00003ffe // sin(10 pi/16) C2
332data8 0xc3ef1535754b168e , 0x0000bffd // cos(10 pi/16) -S2
333//
334data8 0xd4db3148750d181a , 0x00003ffe // sin(11 pi/16) C3
335data8 0x8e39d9cd73464364 , 0x0000bffe // cos(11 pi/16) -S3
336//
337data8 0xb504f333f9de6484 , 0x00003ffe // sin(12 pi/16) S4
338data8 0xb504f333f9de6484 , 0x0000bffe // cos(12 pi/16) -S4
339//
340data8 0x8e39d9cd73464364 , 0x00003ffe // sin(13 pi/16) S3
341data8 0xd4db3148750d181a , 0x0000bffe // cos(13 pi/16) -C3
342//
343data8 0xc3ef1535754b168e , 0x00003ffd // sin(14 pi/16) S2
344data8 0xec835e79946a3146 , 0x0000bffe // cos(14 pi/16) -C2
345//
346data8 0xc7c5c1e34d3055b3 , 0x00003ffc // sin(15 pi/16) S1
347data8 0xfb14be7fbae58157 , 0x0000bffe // cos(15 pi/16) -C1
348//
349data8 0x0000000000000000 , 0x00000000 // sin(16 pi/16) S0
350data8 0x8000000000000000 , 0x0000bfff // cos(16 pi/16) -C0
351//
352data8 0xc7c5c1e34d3055b3 , 0x0000bffc // sin(17 pi/16) -S1
353data8 0xfb14be7fbae58157 , 0x0000bffe // cos(17 pi/16) -C1
354//
355data8 0xc3ef1535754b168e , 0x0000bffd // sin(18 pi/16) -S2
356data8 0xec835e79946a3146 , 0x0000bffe // cos(18 pi/16) -C2
357//
358data8 0x8e39d9cd73464364 , 0x0000bffe // sin(19 pi/16) -S3
359data8 0xd4db3148750d181a , 0x0000bffe // cos(19 pi/16) -C3
360//
361data8 0xb504f333f9de6484 , 0x0000bffe // sin(20 pi/16) -S4
362data8 0xb504f333f9de6484 , 0x0000bffe // cos(20 pi/16) -S4
363//
364data8 0xd4db3148750d181a , 0x0000bffe // sin(21 pi/16) -C3
365data8 0x8e39d9cd73464364 , 0x0000bffe // cos(21 pi/16) -S3
366//
367data8 0xec835e79946a3146 , 0x0000bffe // sin(22 pi/16) -C2
368data8 0xc3ef1535754b168e , 0x0000bffd // cos(22 pi/16) -S2
369//
370data8 0xfb14be7fbae58157 , 0x0000bffe // sin(23 pi/16) -C1
371data8 0xc7c5c1e34d3055b3 , 0x0000bffc // cos(23 pi/16) -S1
372//
373data8 0x8000000000000000 , 0x0000bfff // sin(24 pi/16) -C0
374data8 0x0000000000000000 , 0x00000000 // cos(24 pi/16) S0
375//
376data8 0xfb14be7fbae58157 , 0x0000bffe // sin(25 pi/16) -C1
377data8 0xc7c5c1e34d3055b3 , 0x00003ffc // cos(25 pi/16) S1
378//
379data8 0xec835e79946a3146 , 0x0000bffe // sin(26 pi/16) -C2
380data8 0xc3ef1535754b168e , 0x00003ffd // cos(26 pi/16) S2
381//
382data8 0xd4db3148750d181a , 0x0000bffe // sin(27 pi/16) -C3
383data8 0x8e39d9cd73464364 , 0x00003ffe // cos(27 pi/16) S3
384//
385data8 0xb504f333f9de6484 , 0x0000bffe // sin(28 pi/16) -S4
386data8 0xb504f333f9de6484 , 0x00003ffe // cos(28 pi/16) S4
387//
388data8 0x8e39d9cd73464364 , 0x0000bffe // sin(29 pi/16) -S3
389data8 0xd4db3148750d181a , 0x00003ffe // cos(29 pi/16) C3
390//
391data8 0xc3ef1535754b168e , 0x0000bffd // sin(30 pi/16) -S2
392data8 0xec835e79946a3146 , 0x00003ffe // cos(30 pi/16) C2
393//
394data8 0xc7c5c1e34d3055b3 , 0x0000bffc // sin(31 pi/16) -S1
395data8 0xfb14be7fbae58157 , 0x00003ffe // cos(31 pi/16) C1
396//
397data8 0x0000000000000000 , 0x00000000 // sin(32 pi/16) S0
398data8 0x8000000000000000 , 0x00003fff // cos(32 pi/16) C0
399LOCAL_OBJECT_END(double_sin_cos_beta_k4)
400
401.section .text
402
403GLOBAL_IEEE754_ENTRY(sincos)
404// cis_GR_sig_inv_pi_by_16 = significand of 16/pi
405{ .mlx
406 getf.exp cis_r_signexp = cis_Arg
407 movl cis_GR_sig_inv_pi_by_16 = 0xA2F9836E4E44152A
408
409}
410// cis_GR_rshf_2to61 = 1.1000 2^(63+63-2)
411{ .mlx
412 addl cis_AD_1 = @ltoff(double_cis_pi), gp
413 movl cis_GR_rshf_2to61 = 0x47b8000000000000
414};;
415
416{ .mfi
417 ld8 cis_AD_1 = [cis_AD_1]
418 fnorm.s1 cis_NORM_f8 = cis_Arg
419 cmp.eq p13, p14 = r0, r0 // p13 set for sincos
420}
421// cis_GR_exp_2tom61 = exponent of scaling factor 2^-61
422{ .mib
423 mov cis_GR_exp_2tom61 = 0xffff-61
424 nop.i 0
425 br.cond.sptk _CIS_COMMON
426};;
427GLOBAL_IEEE754_END(sincos)
428
429GLOBAL_LIBM_ENTRY(__libm_sincos)
430// cis_GR_sig_inv_pi_by_16 = significand of 16/pi
431{ .mlx
432 getf.exp cis_r_signexp = cis_Arg
433 movl cis_GR_sig_inv_pi_by_16 = 0xA2F9836E4E44152A
434}
435// cis_GR_rshf_2to61 = 1.1000 2^(63+63-2)
436{ .mlx
437 addl cis_AD_1 = @ltoff(double_cis_pi), gp
438 movl cis_GR_rshf_2to61 = 0x47b8000000000000
439};;
440
441// p14 set for __libm_sincos and cis
442{ .mfi
443 ld8 cis_AD_1 = [cis_AD_1]
444 fnorm.s1 cis_NORM_f8 = cis_Arg
445 cmp.eq p14, p13 = r0, r0
446}
447// cis_GR_exp_2tom61 = exponent of scaling factor 2^-61
448{ .mib
449 mov cis_GR_exp_2tom61 = 0xffff-61
450 nop.i 0
451 nop.b 0
452};;
453
454_CIS_COMMON:
455// Form two constants we need
456// 16/pi * 2^-2 * 2^63, scaled by 2^61 since we just loaded the significand
457// 1.1000...000 * 2^(63+63-2) to right shift int(W) into the low significand
458// fcmp used to set denormal, and invalid on snans
459{ .mfi
460 setf.sig cis_SIG_INV_PI_BY_16_2TO61 = cis_GR_sig_inv_pi_by_16
461 fclass.m p6,p0 = cis_Arg, 0xe7 // if x=0,inf,nan
462 addl cis_gr_tmp = -1, r0
463}
464// 1.1000 2^63 for right shift
465{ .mlx
466 setf.d cis_RSHF_2TO61 = cis_GR_rshf_2to61
467 movl cis_GR_rshf = 0x43e8000000000000
468};;
469
470// Form another constant
471// 2^-61 for scaling Nfloat
472// 0x1001a is register_bias + 27.
473// So if f8 >= 2^27, go to large arguments routine
474{ .mfi
475 alloc GR_SAVE_PFS = ar.pfs, 3, 5, 0, 0
476 fclass.m p11,p0 = cis_Arg, 0x0b // Test for x=unorm
477 mov cis_exp_limit = 0x1001a
478}
479{ .mib
480 setf.exp cis_2TOM61 = cis_GR_exp_2tom61
481 nop.i 0
482(p6) br.cond.spnt _CIS_SPECIAL_ARGS
483};;
484
485// Load the two pieces of pi/16
486// Form another constant
487// 1.1000...000 * 2^63, the right shift constant
488{ .mmb
489 ldfe cis_Pi_by_16_hi = [cis_AD_1],16
490 setf.d cis_RSHF = cis_GR_rshf
491(p11) br.cond.spnt _CIS_UNORM // Branch if x=unorm
492};;
493
494_CIS_COMMON2:
495// Return here if x=unorm
496// Create constant inexact set
497{ .mmi
498 ldfe cis_Pi_by_16_lo = [cis_AD_1],16
499 setf.sig cis_tmp = cis_gr_tmp
500 nop.i 0
501};;
502
503// Select exponent (17 lsb)
504{ .mfi
505 ldfe cis_Pi_by_16_lowest = [cis_AD_1],16
506 nop.f 0
507 dep.z cis_r_exp = cis_r_signexp, 0, 17
508};;
509
510// Start loading P, Q coefficients
511// p10 is true if we must call routines to handle larger arguments
512// p10 is true if f8 exp is > 0x1001a
513{ .mmb
514 ldfpd cis_P4,cis_Q4 = [cis_AD_1],16
515 cmp.ge p10, p0 = cis_r_exp, cis_exp_limit
516(p10) br.cond.spnt _CIS_LARGE_ARGS // go to |x| >= 2^27 path
517};;
518
519// cis_W = x * cis_Inv_Pi_by_16
520// Multiply x by scaled 16/pi and add large const to shift integer part of W to
521// rightmost bits of significand
522{ .mfi
523 ldfpd cis_P3,cis_Q3 = [cis_AD_1],16
524 fma.s1 cis_W_2TO61_RSH = cis_NORM_f8,cis_SIG_INV_PI_BY_16_2TO61,cis_RSHF_2TO61
525 nop.i 0
526};;
527
528// get N = (int)cis_int_Nfloat
529// cis_NFLOAT = Round_Int_Nearest(cis_W)
530{ .mmf
531 getf.sig cis_GR_n = cis_W_2TO61_RSH
532 ldfpd cis_P2,cis_Q2 = [cis_AD_1],16
533 fms.s1 cis_NFLOAT = cis_W_2TO61_RSH,cis_2TOM61,cis_RSHF
534};;
535
536// cis_r = -cis_Nfloat * cis_Pi_by_16_hi + x
537{ .mfi
538 ldfpd cis_P1,cis_Q1 = [cis_AD_1], 16
539 fnma.s1 cis_r = cis_NFLOAT,cis_Pi_by_16_hi,cis_NORM_f8
540 nop.i 0
541};;
542
543// Add 2^(k-1) (which is in cis_r_sincos) to N
544{ .mmi
545 add cis_GR_n_cos = 0x8, cis_GR_n
546;;
547//Get M (least k+1 bits of N)
548 and cis_GR_m_sin = 0x1f,cis_GR_n
549 and cis_GR_m_cos = 0x1f,cis_GR_n_cos
550};;
551
552{ .mmi
553 nop.m 0
554 nop.m 0
555 shl cis_GR_32m_sin = cis_GR_m_sin,5
556};;
557
558// Add 32*M to address of sin_cos_beta table
559// cis_r = cis_r -cis_Nfloat * cis_Pi_by_16_lo
560{ .mfi
561 add cis_AD_2_sin = cis_GR_32m_sin, cis_AD_1
562 fnma.s1 cis_r = cis_NFLOAT, cis_Pi_by_16_lo, cis_r
563 shl cis_GR_32m_cos = cis_GR_m_cos,5
564};;
565
566// Add 32*M to address of sin_cos_beta table
567{ .mmf
568 ldfe cis_Sm_sin = [cis_AD_2_sin],16
569 add cis_AD_2_cos = cis_GR_32m_cos, cis_AD_1
570 fclass.m.unc p10,p0 = cis_Arg,0x0b // den. input - uflow
571};;
572
573{ .mfi
574 ldfe cis_Sm_cos = [cis_AD_2_cos], 16
575 nop.i 0
576};;
577
578{ .mfi
579 ldfe cis_Cm_sin = [cis_AD_2_sin]
580 fma.s1 cis_rsq = cis_r, cis_r, f0 // get r^2
581 nop.i 0
582}
583// fmpy forces inexact flag
584{ .mfi
585 nop.m 0
586 fmpy.s0 cis_tmp = cis_tmp,cis_tmp
587 nop.i 0
588};;
589
590{ .mfi
591 nop.m 0
592 fnma.s1 cis_r_exact = cis_NFLOAT, cis_Pi_by_16_lowest, cis_r
593 nop.i 0
594};;
595
596{ .mfi
597 ldfe cis_Cm_cos = [cis_AD_2_cos]
598 fma.s1 cis_P_temp1 = cis_rsq, cis_P4, cis_P3
599 nop.i 0
600}
601
602{ .mfi
603 nop.m 0
604 fma.s1 cis_Q_temp1 = cis_rsq, cis_Q4, cis_Q3
605 nop.i 0
606};;
607
608{ .mfi
609 nop.m 0
610 fmpy.s1 cis_srsq_sin = cis_Sm_sin, cis_rsq
611 nop.i 0
612}
613{ .mfi
614 nop.m 0
615 fmpy.s1 cis_srsq_cos = cis_Sm_cos,cis_rsq
616 nop.i 0
617};;
618
619{ .mfi
620 nop.m 0
621 fma.s1 cis_Q_temp2 = cis_rsq, cis_Q_temp1, cis_Q2
622 nop.i 0
623}
624{ .mfi
625 nop.m 0
626 fma.s1 cis_P_temp2 = cis_rsq, cis_P_temp1, cis_P2
627 nop.i 0
628};;
629
630{ .mfi
631 nop.m 0
632 fmpy.s1 cis_rcub = cis_r_exact, cis_rsq // get r^3
633 nop.i 0
634};;
635
636{ .mfi
637 nop.m 0
638 fma.s1 cis_Q = cis_rsq, cis_Q_temp2, cis_Q1
639 nop.i 0
640}
641{ .mfi
642 nop.m 0
643 fma.s1 cis_P = cis_rsq, cis_P_temp2, cis_P1
644 nop.i 0
645};;
646
647{ .mfi
648 nop.m 0
649 fma.s1 cis_Q_sin = cis_srsq_sin,cis_Q, cis_Sm_sin
650 nop.i 0
651}
652{ .mfi
653 nop.m 0
654 fma.s1 cis_Q_cos = cis_srsq_cos,cis_Q, cis_Sm_cos
655 nop.i 0
656};;
657
658{ .mfi
659 nop.m 0
660 fma.s1 cis_P = cis_rcub,cis_P, cis_r_exact // final P
661 nop.i 0
662};;
663
664// If den. arg, force underflow to be set
665{ .mfi
666 nop.m 0
667(p10) fmpy.d.s0 cis_tmp = cis_Arg,cis_Arg
668 nop.i 0
669};;
670
671{ .mfi
672 nop.m 0
673 fma.d.s0 cis_Sin_res = cis_Cm_sin,cis_P,cis_Q_sin//Final sin
674 nop.i 0
675}
676{ .mfb
677 nop.m 0
678 fma.d.s0 cis_Cos_res = cis_Cm_cos,cis_P,cis_Q_cos//Final cos
679(p14) br.ret.sptk b0 // common exit for __libm_sincos and cis main path
680};;
681
682{ .mmb
683 stfd [cis_pResSin] = cis_Sin_res
684 stfd [cis_pResCos] = cis_Cos_res
685 br.ret.sptk b0 // common exit for sincos main path
686};;
687
688_CIS_SPECIAL_ARGS:
689// sin(+/-0) = +/-0
690// sin(Inf) = NaN
691// sin(NaN) = NaN
692{ .mfi
693 nop.m 999
694 fma.d.s0 cis_Sin_res = cis_Arg, f0, f0 // sinf(+/-0,NaN,Inf)
695 nop.i 999
696};;
697// cos(+/-0) = 1.0
698// cos(Inf) = NaN
699// cos(NaN) = NaN
700{ .mfb
701 nop.m 999
702 fma.d.s0 cis_Cos_res = cis_Arg, f0, f1 // cosf(+/-0,NaN,Inf)
703(p14) br.ret.sptk b0 //spec exit for __libm_sincos and cis main path
704};;
705
706{ .mmb
707 stfd [cis_pResSin] = cis_Sin_res
708 stfd [cis_pResCos] = cis_Cos_res
709 br.ret.sptk b0 // common exit for sincos main path
710};;
711
712_CIS_UNORM:
713// Here if x=unorm
714{ .mfb
715 getf.exp cis_r_signexp = cis_NORM_f8 // Get signexp of x
716 fcmp.eq.s0 p11,p0 = cis_Arg, f0 // Dummy op to set denorm
717 br.cond.sptk _CIS_COMMON2 // Return to main path
718};;
719
720GLOBAL_LIBM_END(__libm_sincos)
721
722//// |x| > 2^27 path ///////
723.proc _CIS_LARGE_ARGS
724_CIS_LARGE_ARGS:
725.prologue
726{ .mfi
727 nop.m 0
728 nop.f 0
729.save ar.pfs, GR_SAVE_PFS
730 mov GR_SAVE_PFS = ar.pfs
731}
732;;
733
734{ .mfi
735 mov GR_SAVE_GP = gp
736 nop.f 0
737.save b0, GR_SAVE_B0
738 mov GR_SAVE_B0 = b0
739};;
740
741.body
742// Call of huge arguments sincos
743{ .mib
744 nop.m 0
745 mov GR_SAVE_PR = pr
746 br.call.sptk b0 = __libm_sincos_large
747};;
748
749{ .mfi
750 mov gp = GR_SAVE_GP
751 nop.f 0
752 mov pr = GR_SAVE_PR, 0x1fffe
753}
754;;
755
756{ .mfi
757 nop.m 0
758 nop.f 0
759 mov b0 = GR_SAVE_B0
760}
761;;
762
763{ .mfi
764 nop.m 0
765 fma.d.s0 cis_Cos_res = cis_Cos_res, f1, f0
766 mov ar.pfs = GR_SAVE_PFS
767}
768{ .mfb
769 nop.m 0
770 fma.d.s0 cis_Sin_res = cis_Sin_res, f1, f0
771(p14) br.ret.sptk b0 // exit for |x| > 2^27 path (__libm_sincos and cis)
772};;
773
774{ .mmb
775 stfd [cis_pResSin] = cis_Sin_res
776 stfd [cis_pResCos] = cis_Cos_res
777 br.ret.sptk b0 // exit for sincos |x| > 2^27 path
778};;
779.endp _CIS_LARGE_ARGS
780
781.type __libm_sincos_large#,@function
782.global __libm_sincos_large#
783