1.file "sincosf.s"
2
3
4// Copyright (c) 2000 - 2005, Intel Corporation
5// All rights reserved.
6//
7//
8// Redistribution and use in source and binary forms, with or without
9// modification, are permitted provided that the following conditions are
10// met:
11//
12// * Redistributions of source code must retain the above copyright
13// notice, this list of conditions and the following disclaimer.
14//
15// * Redistributions in binary form must reproduce the above copyright
16// notice, this list of conditions and the following disclaimer in the
17// documentation and/or other materials provided with the distribution.
18//
19// * The name of Intel Corporation may not be used to endorse or promote
20// products derived from this software without specific prior written
21// permission.
22
23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
27// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
31// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
32// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34//
35// Intel Corporation is the author of this code, and requests that all
36// problem reports or change requests be submitted to it directly at
37// http://www.intel.com/software/products/opensource/libraries/num.htm.
38//
39// History
40//==============================================================
41// 02/02/00 Initial version
42// 04/02/00 Unwind support added.
43// 06/16/00 Updated tables to enforce symmetry
44// 08/31/00 Saved 2 cycles in main path, and 9 in other paths.
45// 09/20/00 The updated tables regressed to an old version, so reinstated them
46// 10/18/00 Changed one table entry to ensure symmetry
47// 01/03/01 Improved speed, fixed flag settings for small arguments.
48// 02/18/02 Large arguments processing routine excluded
49// 05/20/02 Cleaned up namespace and sf0 syntax
50// 06/03/02 Insure inexact flag set for large arg result
51// 09/05/02 Single precision version is made using double precision one as base
52// 02/10/03 Reordered header: .section, .global, .proc, .align
53// 03/31/05 Reformatted delimiters between data tables
54//
55// API
56//==============================================================
57// float sinf( float x);
58// float cosf( float x);
59//
60// Overview of operation
61//==============================================================
62//
63// Step 1
64// ======
65// Reduce x to region -1/2*pi/2^k ===== 0 ===== +1/2*pi/2^k  where k=4
66//    divide x by pi/2^k.
67//    Multiply by 2^k/pi.
68//    nfloat = Round result to integer (round-to-nearest)
69//
70// r = x -  nfloat * pi/2^k
71//    Do this as (x -  nfloat * HIGH(pi/2^k)) - nfloat * LOW(pi/2^k)
72
73//    for increased accuracy.
74//    pi/2^k is stored as two numbers that when added make pi/2^k.
75//       pi/2^k = HIGH(pi/2^k) + LOW(pi/2^k)
76//    HIGH part is rounded to zero, LOW - to nearest
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  = Series for Cos
122// Sin(r) = r + r^3 p1  + r^5 p2  = 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^2*P2
137//    Q = Q1 + r^2*Q2
138//
139//       rcub = r * rsq
140//       Sin(r) = r + rcub * P
141//              = r + r^3p1  + r^5p2 = 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 + r^3 * 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)
157//       Cos(r) = 1 + r^2q1 + r^4q2
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
169// Registers used
170//==============================================================
171// general input registers:
172// r14 -> r19
173// r32 -> r45
174
175// predicate registers used:
176// p6 -> p14
177
178// floating-point registers used
179// f9 -> f15
180// f32 -> f61
181
182// Assembly macros
183//==============================================================
184sincosf_NORM_f8                 = f9
185sincosf_W                       = f10
186sincosf_int_Nfloat              = f11
187sincosf_Nfloat                  = f12
188
189sincosf_r                       = f13
190sincosf_rsq                     = f14
191sincosf_rcub                    = f15
192sincosf_save_tmp                = f15
193
194sincosf_Inv_Pi_by_16            = f32
195sincosf_Pi_by_16_1              = f33
196sincosf_Pi_by_16_2              = f34
197
198sincosf_Inv_Pi_by_64            = f35
199
200sincosf_Pi_by_16_3              = f36
201
202sincosf_r_exact                 = f37
203
204sincosf_Sm                      = f38
205sincosf_Cm                      = f39
206
207sincosf_P1                      = f40
208sincosf_Q1                      = f41
209sincosf_P2                      = f42
210sincosf_Q2                      = f43
211sincosf_P3                      = f44
212sincosf_Q3                      = f45
213sincosf_P4                      = f46
214sincosf_Q4                      = f47
215
216sincosf_P_temp1                 = f48
217sincosf_P_temp2                 = f49
218
219sincosf_Q_temp1                 = f50
220sincosf_Q_temp2                 = f51
221
222sincosf_P                       = f52
223sincosf_Q                       = f53
224
225sincosf_srsq                    = f54
226
227sincosf_SIG_INV_PI_BY_16_2TO61  = f55
228sincosf_RSHF_2TO61              = f56
229sincosf_RSHF                    = f57
230sincosf_2TOM61                  = f58
231sincosf_NFLOAT                  = f59
232sincosf_W_2TO61_RSH             = f60
233
234fp_tmp                          = f61
235
236/////////////////////////////////////////////////////////////
237
238sincosf_AD_1                    = r33
239sincosf_AD_2                    = r34
240sincosf_exp_limit               = r35
241sincosf_r_signexp               = r36
242sincosf_AD_beta_table           = r37
243sincosf_r_sincos                = r38
244
245sincosf_r_exp                   = r39
246sincosf_r_17_ones               = r40
247
248sincosf_GR_sig_inv_pi_by_16     = r14
249sincosf_GR_rshf_2to61           = r15
250sincosf_GR_rshf                 = r16
251sincosf_GR_exp_2tom61           = r17
252sincosf_GR_n                    = r18
253sincosf_GR_m                    = r19
254sincosf_GR_32m                  = r19
255sincosf_GR_all_ones             = r19
256
257gr_tmp                          = r41
258GR_SAVE_PFS                     = r41
259GR_SAVE_B0                      = r42
260GR_SAVE_GP                      = r43
261
262RODATA
263.align 16
264
265// Pi/16 parts
266LOCAL_OBJECT_START(double_sincosf_pi)
267   data8 0xC90FDAA22168C234, 0x00003FFC // pi/16 1st part
268   data8 0xC4C6628B80DC1CD1, 0x00003FBC // pi/16 2nd part
269LOCAL_OBJECT_END(double_sincosf_pi)
270
271// Coefficients for polynomials
272LOCAL_OBJECT_START(double_sincosf_pq_k4)
273   data8 0x3F810FABB668E9A2 // P2
274   data8 0x3FA552E3D6DE75C9 // Q2
275   data8 0xBFC555554447BC7F // P1
276   data8 0xBFDFFFFFC447610A // Q1
277LOCAL_OBJECT_END(double_sincosf_pq_k4)
278
279// Sincos table (S[m], C[m])
280LOCAL_OBJECT_START(double_sin_cos_beta_k4)
281    data8 0x0000000000000000 // sin ( 0 Pi / 16 )
282    data8 0x3FF0000000000000 // cos ( 0 Pi / 16 )
283//
284    data8 0x3FC8F8B83C69A60B // sin ( 1 Pi / 16 )
285    data8 0x3FEF6297CFF75CB0 // cos ( 1 Pi / 16 )
286//
287    data8 0x3FD87DE2A6AEA963 // sin ( 2 Pi / 16 )
288    data8 0x3FED906BCF328D46 // cos ( 2 Pi / 16 )
289//
290    data8 0x3FE1C73B39AE68C8 // sin ( 3 Pi / 16 )
291    data8 0x3FEA9B66290EA1A3 // cos ( 3 Pi / 16 )
292//
293    data8 0x3FE6A09E667F3BCD // sin ( 4 Pi / 16 )
294    data8 0x3FE6A09E667F3BCD // cos ( 4 Pi / 16 )
295//
296    data8 0x3FEA9B66290EA1A3 // sin ( 5 Pi / 16 )
297    data8 0x3FE1C73B39AE68C8 // cos ( 5 Pi / 16 )
298//
299    data8 0x3FED906BCF328D46 // sin ( 6 Pi / 16 )
300    data8 0x3FD87DE2A6AEA963 // cos ( 6 Pi / 16 )
301//
302    data8 0x3FEF6297CFF75CB0 // sin ( 7 Pi / 16 )
303    data8 0x3FC8F8B83C69A60B // cos ( 7 Pi / 16 )
304//
305    data8 0x3FF0000000000000 // sin ( 8 Pi / 16 )
306    data8 0x0000000000000000 // cos ( 8 Pi / 16 )
307//
308    data8 0x3FEF6297CFF75CB0 // sin ( 9 Pi / 16 )
309    data8 0xBFC8F8B83C69A60B // cos ( 9 Pi / 16 )
310//
311    data8 0x3FED906BCF328D46 // sin ( 10 Pi / 16 )
312    data8 0xBFD87DE2A6AEA963 // cos ( 10 Pi / 16 )
313//
314    data8 0x3FEA9B66290EA1A3 // sin ( 11 Pi / 16 )
315    data8 0xBFE1C73B39AE68C8 // cos ( 11 Pi / 16 )
316//
317    data8 0x3FE6A09E667F3BCD // sin ( 12 Pi / 16 )
318    data8 0xBFE6A09E667F3BCD // cos ( 12 Pi / 16 )
319//
320    data8 0x3FE1C73B39AE68C8 // sin ( 13 Pi / 16 )
321    data8 0xBFEA9B66290EA1A3 // cos ( 13 Pi / 16 )
322//
323    data8 0x3FD87DE2A6AEA963 // sin ( 14 Pi / 16 )
324    data8 0xBFED906BCF328D46 // cos ( 14 Pi / 16 )
325//
326    data8 0x3FC8F8B83C69A60B // sin ( 15 Pi / 16 )
327    data8 0xBFEF6297CFF75CB0 // cos ( 15 Pi / 16 )
328//
329    data8 0x0000000000000000 // sin ( 16 Pi / 16 )
330    data8 0xBFF0000000000000 // cos ( 16 Pi / 16 )
331//
332    data8 0xBFC8F8B83C69A60B // sin ( 17 Pi / 16 )
333    data8 0xBFEF6297CFF75CB0 // cos ( 17 Pi / 16 )
334//
335    data8 0xBFD87DE2A6AEA963 // sin ( 18 Pi / 16 )
336    data8 0xBFED906BCF328D46 // cos ( 18 Pi / 16 )
337//
338    data8 0xBFE1C73B39AE68C8 // sin ( 19 Pi / 16 )
339    data8 0xBFEA9B66290EA1A3 // cos ( 19 Pi / 16 )
340//
341    data8 0xBFE6A09E667F3BCD // sin ( 20 Pi / 16 )
342    data8 0xBFE6A09E667F3BCD // cos ( 20 Pi / 16 )
343//
344    data8 0xBFEA9B66290EA1A3 // sin ( 21 Pi / 16 )
345    data8 0xBFE1C73B39AE68C8 // cos ( 21 Pi / 16 )
346//
347    data8 0xBFED906BCF328D46 // sin ( 22 Pi / 16 )
348    data8 0xBFD87DE2A6AEA963 // cos ( 22 Pi / 16 )
349//
350    data8 0xBFEF6297CFF75CB0 // sin ( 23 Pi / 16 )
351    data8 0xBFC8F8B83C69A60B // cos ( 23 Pi / 16 )
352//
353    data8 0xBFF0000000000000 // sin ( 24 Pi / 16 )
354    data8 0x0000000000000000 // cos ( 24 Pi / 16 )
355//
356    data8 0xBFEF6297CFF75CB0 // sin ( 25 Pi / 16 )
357    data8 0x3FC8F8B83C69A60B // cos ( 25 Pi / 16 )
358//
359    data8 0xBFED906BCF328D46 // sin ( 26 Pi / 16 )
360    data8 0x3FD87DE2A6AEA963 // cos ( 26 Pi / 16 )
361//
362    data8 0xBFEA9B66290EA1A3 // sin ( 27 Pi / 16 )
363    data8 0x3FE1C73B39AE68C8 // cos ( 27 Pi / 16 )
364//
365    data8 0xBFE6A09E667F3BCD // sin ( 28 Pi / 16 )
366    data8 0x3FE6A09E667F3BCD // cos ( 28 Pi / 16 )
367//
368    data8 0xBFE1C73B39AE68C8 // sin ( 29 Pi / 16 )
369    data8 0x3FEA9B66290EA1A3 // cos ( 29 Pi / 16 )
370//
371    data8 0xBFD87DE2A6AEA963 // sin ( 30 Pi / 16 )
372    data8 0x3FED906BCF328D46 // cos ( 30 Pi / 16 )
373//
374    data8 0xBFC8F8B83C69A60B // sin ( 31 Pi / 16 )
375    data8 0x3FEF6297CFF75CB0 // cos ( 31 Pi / 16 )
376//
377    data8 0x0000000000000000 // sin ( 32 Pi / 16 )
378    data8 0x3FF0000000000000 // cos ( 32 Pi / 16 )
379LOCAL_OBJECT_END(double_sin_cos_beta_k4)
380
381.section .text
382
383////////////////////////////////////////////////////////
384// There are two entry points: sin and cos
385// If from sin, p8 is true
386// If from cos, p9 is true
387
388GLOBAL_IEEE754_ENTRY(sinf)
389
390{ .mlx
391      alloc         r32                 = ar.pfs,1,13,0,0
392      movl  sincosf_GR_sig_inv_pi_by_16 = 0xA2F9836E4E44152A //signd of 16/pi
393}
394{ .mlx
395      addl         sincosf_AD_1         = @ltoff(double_sincosf_pi), gp
396      movl  sincosf_GR_rshf_2to61       = 0x47b8000000000000 // 1.1 2^(63+63-2)
397};;
398
399{ .mfi
400      ld8           sincosf_AD_1        = [sincosf_AD_1]
401      fnorm.s1      sincosf_NORM_f8     = f8     // Normalize argument
402      cmp.eq        p8,p9               = r0, r0 // set p8 (clear p9) for sin
403}
404{ .mib
405      mov           sincosf_GR_exp_2tom61 = 0xffff-61 // exponent of scale 2^-61
406      mov           sincosf_r_sincos      = 0x0       // 0 for sin
407      br.cond.sptk  _SINCOSF_COMMON                 // go to common part
408};;
409
410GLOBAL_IEEE754_END(sinf)
411libm_alias_float_other (__sin, sin)
412
413GLOBAL_IEEE754_ENTRY(cosf)
414
415{ .mlx
416      alloc         r32                 = ar.pfs,1,13,0,0
417      movl  sincosf_GR_sig_inv_pi_by_16 = 0xA2F9836E4E44152A //signd of 16/pi
418}
419{ .mlx
420      addl          sincosf_AD_1        = @ltoff(double_sincosf_pi), gp
421      movl  sincosf_GR_rshf_2to61       = 0x47b8000000000000 // 1.1 2^(63+63-2)
422};;
423
424{ .mfi
425      ld8           sincosf_AD_1        = [sincosf_AD_1]
426      fnorm.s1      sincosf_NORM_f8     = f8        // Normalize argument
427      cmp.eq        p9,p8               = r0, r0    // set p9 (clear p8) for cos
428}
429{ .mib
430      mov           sincosf_GR_exp_2tom61 = 0xffff-61 // exponent of scale 2^-61
431      mov           sincosf_r_sincos      = 0x8       // 8 for cos
432      nop.b         999
433};;
434
435////////////////////////////////////////////////////////
436// All entry points end up here.
437// If from sin, sincosf_r_sincos is 0 and p8 is true
438// If from cos, sincosf_r_sincos is 8 = 2^(k-1) and p9 is true
439// We add sincosf_r_sincos to N
440
441///////////// Common sin and cos part //////////////////
442_SINCOSF_COMMON:
443
444//  Form two constants we need
445//  16/pi * 2^-2 * 2^63, scaled by 2^61 since we just loaded the significand
446//  1.1000...000 * 2^(63+63-2) to right shift int(W) into the low significand
447//  fcmp used to set denormal, and invalid on snans
448{ .mfi
449      setf.sig      sincosf_SIG_INV_PI_BY_16_2TO61 = sincosf_GR_sig_inv_pi_by_16
450      fclass.m      p6,p0                          = f8, 0xe7 // if x=0,inf,nan
451      mov           sincosf_exp_limit              = 0x10017
452}
453{ .mlx
454      setf.d        sincosf_RSHF_2TO61  = sincosf_GR_rshf_2to61
455      movl          sincosf_GR_rshf     = 0x43e8000000000000 // 1.1000 2^63
456};;                                                          // Right shift
457
458//  Form another constant
459//  2^-61 for scaling Nfloat
460//  0x10017 is register_bias + 24.
461//  So if f8 >= 2^24, go to large argument routines
462{ .mmi
463      getf.exp      sincosf_r_signexp   = f8
464      setf.exp      sincosf_2TOM61      = sincosf_GR_exp_2tom61
465      addl          gr_tmp              = -1,r0 // For "inexect" constant create
466};;
467
468// Load the two pieces of pi/16
469// Form another constant
470//  1.1000...000 * 2^63, the right shift constant
471{ .mmb
472      ldfe          sincosf_Pi_by_16_1  = [sincosf_AD_1],16
473      setf.d        sincosf_RSHF        = sincosf_GR_rshf
474(p6)  br.cond.spnt  _SINCOSF_SPECIAL_ARGS
475};;
476
477// Getting argument's exp for "large arguments" filtering
478{ .mmi
479      ldfe          sincosf_Pi_by_16_2  = [sincosf_AD_1],16
480      setf.sig      fp_tmp              = gr_tmp // constant for inexact set
481      nop.i         999
482};;
483
484// Polynomial coefficients (Q2, Q1, P2, P1) loading
485{ .mmi
486      ldfpd         sincosf_P2,sincosf_Q2 = [sincosf_AD_1],16
487      nop.m         999
488      nop.i         999
489};;
490
491// Select exponent (17 lsb)
492{ .mmi
493      ldfpd         sincosf_P1,sincosf_Q1 = [sincosf_AD_1],16
494      nop.m         999
495      dep.z         sincosf_r_exp         = sincosf_r_signexp, 0, 17
496};;
497
498// p10 is true if we must call routines to handle larger arguments
499// p10 is true if f8 exp is >= 0x10017 (2^24)
500{ .mfb
501      cmp.ge        p10,p0              = sincosf_r_exp,sincosf_exp_limit
502      nop.f         999
503(p10) br.cond.spnt  _SINCOSF_LARGE_ARGS // Go to "large args" routine
504};;
505
506// sincosf_W          = x * sincosf_Inv_Pi_by_16
507// Multiply x by scaled 16/pi and add large const to shift integer part of W to
508//   rightmost bits of significand
509{ .mfi
510      nop.m         999
511      fma.s1 sincosf_W_2TO61_RSH = sincosf_NORM_f8, sincosf_SIG_INV_PI_BY_16_2TO61, sincosf_RSHF_2TO61
512      nop.i         999
513};;
514
515// sincosf_NFLOAT = Round_Int_Nearest(sincosf_W)
516// This is done by scaling back by 2^-61 and subtracting the shift constant
517{ .mfi
518      nop.m         999
519      fms.s1 sincosf_NFLOAT = sincosf_W_2TO61_RSH,sincosf_2TOM61,sincosf_RSHF
520      nop.i         999
521};;
522
523// get N = (int)sincosf_int_Nfloat
524{ .mfi
525      getf.sig      sincosf_GR_n        = sincosf_W_2TO61_RSH // integer N value
526      nop.f         999
527      nop.i         999
528};;
529
530// Add 2^(k-1) (which is in sincosf_r_sincos=8) to N
531// sincosf_r          = -sincosf_Nfloat * sincosf_Pi_by_16_1 + x
532{ .mfi
533      add           sincosf_GR_n        = sincosf_GR_n, sincosf_r_sincos
534      fnma.s1 sincosf_r = sincosf_NFLOAT, sincosf_Pi_by_16_1, sincosf_NORM_f8
535      nop.i         999
536};;
537
538// Get M (least k+1 bits of N)
539{ .mmi
540      and           sincosf_GR_m        = 0x1f,sincosf_GR_n // Put mask 0x1F  -
541      nop.m         999                                     // - select k+1 bits
542      nop.i         999
543};;
544
545// Add 16*M to address of sin_cos_beta table
546{ .mfi
547      shladd        sincosf_AD_2        = sincosf_GR_32m, 4, sincosf_AD_1
548(p8)  fclass.m.unc  p10,p0              = f8,0x0b  // If sin denormal input -
549      nop.i         999
550};;
551
552// Load Sin and Cos table value using obtained index m  (sincosf_AD_2)
553{ .mfi
554      ldfd          sincosf_Sm          = [sincosf_AD_2],8 // Sin value S[m]
555(p9)  fclass.m.unc  p11,p0              = f8,0x0b  // If cos denormal input -
556      nop.i         999                            // - set denormal
557};;
558
559// sincosf_r          = sincosf_r -sincosf_Nfloat * sincosf_Pi_by_16_2
560{ .mfi
561      ldfd          sincosf_Cm          = [sincosf_AD_2] // Cos table value C[m]
562      fnma.s1  sincosf_r_exact = sincosf_NFLOAT, sincosf_Pi_by_16_2, sincosf_r
563      nop.i         999
564}
565// get rsq = r*r
566{ .mfi
567      nop.m         999
568      fma.s1        sincosf_rsq         = sincosf_r, sincosf_r,  f0 // r^2 = r*r
569      nop.i         999
570};;
571
572{ .mfi
573      nop.m         999
574      fmpy.s0       fp_tmp              = fp_tmp, fp_tmp // forces inexact flag
575      nop.i         999
576};;
577
578// Polynomials calculation
579// Q = Q2*r^2 + Q1
580// P = P2*r^2 + P1
581{ .mfi
582      nop.m         999
583      fma.s1        sincosf_Q           = sincosf_rsq, sincosf_Q2, sincosf_Q1
584      nop.i         999
585}
586{ .mfi
587      nop.m         999
588      fma.s1        sincosf_P           = sincosf_rsq, sincosf_P2, sincosf_P1
589      nop.i         999
590};;
591
592// get rcube and S[m]*r^2
593{ .mfi
594      nop.m         999
595      fmpy.s1       sincosf_srsq        = sincosf_Sm,sincosf_rsq // r^2*S[m]
596      nop.i         999
597}
598{ .mfi
599      nop.m         999
600      fmpy.s1       sincosf_rcub        = sincosf_r_exact, sincosf_rsq
601      nop.i         999
602};;
603
604// Get final P and Q
605// Q = Q*S[m]*r^2 + S[m]
606// P = P*r^3 + r
607{ .mfi
608      nop.m         999
609      fma.s1        sincosf_Q           = sincosf_srsq,sincosf_Q, sincosf_Sm
610      nop.i         999
611}
612{ .mfi
613      nop.m         999
614      fma.s1        sincosf_P           = sincosf_rcub,sincosf_P,sincosf_r_exact
615      nop.i         999
616};;
617
618// If sinf(denormal) - force underflow to be set
619.pred.rel "mutex",p10,p11
620{ .mfi
621      nop.m         999
622(p10) fmpy.s.s0     fp_tmp              = f8,f8 // forces underflow flag
623      nop.i         999                         // for denormal sine args
624}
625// If cosf(denormal) - force denormal to be set
626{ .mfi
627      nop.m         999
628(p11) fma.s.s0     fp_tmp              = f8, f1, f8 // forces denormal flag
629      nop.i         999                              // for denormal cosine args
630};;
631
632
633// Final calculation
634// result = C[m]*P + Q
635{ .mfb
636      nop.m         999
637      fma.s.s0      f8                  = sincosf_Cm, sincosf_P, sincosf_Q
638      br.ret.sptk   b0 // Exit for common path
639};;
640
641////////// x = 0/Inf/NaN path //////////////////
642_SINCOSF_SPECIAL_ARGS:
643.pred.rel "mutex",p8,p9
644// sinf(+/-0) = +/-0
645// sinf(Inf)  = NaN
646// sinf(NaN)  = NaN
647{ .mfi
648      nop.m         999
649(p8)  fma.s.s0      f8                  = f8, f0, f0 // sinf(+/-0,NaN,Inf)
650      nop.i         999
651}
652// cosf(+/-0) = 1.0
653// cosf(Inf)  = NaN
654// cosf(NaN)  = NaN
655{ .mfb
656      nop.m         999
657(p9)  fma.s.s0      f8                  = f8, f0, f1 // cosf(+/-0,NaN,Inf)
658      br.ret.sptk   b0 // Exit for x = 0/Inf/NaN path
659};;
660
661GLOBAL_IEEE754_END(cosf)
662libm_alias_float_other (__cos, cos)
663
664//////////// x >= 2^24 - large arguments routine call ////////////
665LOCAL_LIBM_ENTRY(__libm_callout_sincosf)
666_SINCOSF_LARGE_ARGS:
667.prologue
668{ .mfi
669      mov           sincosf_GR_all_ones = -1 // 0xffffffff
670      nop.f         999
671.save ar.pfs,GR_SAVE_PFS
672      mov           GR_SAVE_PFS         = ar.pfs
673}
674;;
675
676{ .mfi
677      mov           GR_SAVE_GP          = gp
678      nop.f         999
679.save b0, GR_SAVE_B0
680      mov           GR_SAVE_B0          = b0
681}
682.body
683
684{ .mbb
685      setf.sig      sincosf_save_tmp    = sincosf_GR_all_ones  // inexact set
686      nop.b         999
687(p8)  br.call.sptk.many b0              = __libm_sin_large# // sinf(large_X)
688};;
689
690{ .mbb
691      cmp.ne        p9,p0               = sincosf_r_sincos, r0 // set p9 if cos
692      nop.b         999
693(p9)  br.call.sptk.many b0              = __libm_cos_large# // cosf(large_X)
694};;
695
696{ .mfi
697      mov           gp                  = GR_SAVE_GP
698      fma.s.s0      f8                  = f8, f1, f0 // Round result to single
699      mov           b0                  = GR_SAVE_B0
700}
701{ .mfi // force inexact set
702      nop.m         999
703      fmpy.s0       sincosf_save_tmp    = sincosf_save_tmp, sincosf_save_tmp
704      nop.i         999
705};;
706
707{ .mib
708      nop.m         999
709      mov           ar.pfs              = GR_SAVE_PFS
710      br.ret.sptk   b0 // Exit for large arguments routine call
711};;
712LOCAL_LIBM_END(__libm_callout_sincosf)
713
714.type    __libm_sin_large#, @function
715.global  __libm_sin_large#
716.type    __libm_cos_large#, @function
717.global  __libm_cos_large#
718