5 // Copyright (C) 2000, 2001, Intel Corporation
6 // All rights reserved.
8 // Contributed 2/2/2000 by John Harrison, Ted Kubaska, Bob Norin, Shane Story,
9 // and Ping Tak Peter Tang of the Computational Software Lab, Intel Corporation.
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
15 // * Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
18 // * Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
22 // * The name of Intel Corporation may not be used to endorse or promote
23 // products derived from this software without specific prior written
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
34 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 // Intel Corporation is the author of this code, and requests that all
39 // problem reports or change requests be submitted to it directly at
40 // http://developer.intel.com/opensource.
44 //==============================================================
45 // 2/02/00 Initial revision
46 // 4/02/00 Unwind support added.
47 // 5/10/00 Improved speed with new algorithm.
48 // 8/08/00 Improved speed by avoiding SIR flush.
49 // 8/17/00 Changed predicate register macro-usage to direct predicate
50 // names due to an assembler bug.
51 // 8/30/00 Put sin_of_r before sin_tbl_S_cos_of_r to gain a cycle
52 // 1/02/00 Fixed flag settings, improved speed.
55 //==============================================================
56 // float sinf( float x);
57 // float cosf( float x);
60 #include "libm_support.h"
63 //==============================================================
68 // integer registers used
72 sin_GR_sincos_flag = r34
83 // floating point registers used
114 sin_tbl_S_tcube = f61
115 sin_tbl_S_cos_of_r = f62
137 ASM_TYPE_DIRECTIVE(sin_coeff_1_table,@object)
138 data8 0xBF56C16C16BF6462 // q3
139 data8 0x3EFA01A0128B9EBC // q4
140 data8 0xBE927E42FDF33FFE // q5
141 data8 0x3E21DA5C72A446F3 // q6
142 data8 0x3EC71DD1D5E421A4 // p4
143 data8 0xBE5AC5C9D0ACF95A // p5
144 data8 0xBFC55555555554CA // p1
145 data8 0x3F811111110F2395 // p2
146 data8 0xBFE0000000000000 // q1
147 data8 0x3FA55555555554EF // q2
148 data8 0xBF2A01A011232913 // p3
149 data8 0x0000000000000000 // pad
152 /////////////////////////////////////////
154 data8 0xBFE1A54991426566 //sin(-32)
155 data8 0x3FEAB1F5305DE8E5 //cos(-32)
156 data8 0x3FD9DBC0B640FC81 //sin(-31)
157 data8 0x3FED4591C3E12A20 //cos(-31)
158 data8 0x3FEF9DF47F1C903D //sin(-30)
159 data8 0x3FC3BE82F2505A52 //cos(-30)
160 data8 0x3FE53C7D20A6C9E7 //sin(-29)
161 data8 0xBFE7F01658314E47 //cos(-29)
162 data8 0xBFD156853B4514D6 //sin(-28)
163 data8 0xBFEECDAAD1582500 //cos(-28)
164 data8 0xBFEE9AA1B0E5BA30 //sin(-27)
165 data8 0xBFD2B266F959DED5 //cos(-27)
166 data8 0xBFE866E0FAC32583 //sin(-26)
167 data8 0x3FE4B3902691A9ED //cos(-26)
168 data8 0x3FC0F0E6F31E809D //sin(-25)
169 data8 0x3FEFB7EEF59504FF //cos(-25)
170 data8 0x3FECFA7F7919140F //sin(-24)
171 data8 0x3FDB25BFB50A609A //cos(-24)
172 data8 0x3FEB143CD0247D02 //sin(-23)
173 data8 0xBFE10CF7D591F272 //cos(-23)
174 data8 0x3F8220A29F6EB9F4 //sin(-22)
175 data8 0xBFEFFFADD8D4ACDA //cos(-22)
176 data8 0xBFEAC5E20BB0D7ED //sin(-21)
177 data8 0xBFE186FF83773759 //cos(-21)
178 data8 0xBFED36D8F55D3CE0 //sin(-20)
179 data8 0x3FDA1E043964A83F //cos(-20)
180 data8 0xBFC32F2D28F584CF //sin(-19)
181 data8 0x3FEFA377DE108258 //cos(-19)
182 data8 0x3FE8081668131E26 //sin(-18)
183 data8 0x3FE52150815D2470 //cos(-18)
184 data8 0x3FEEC3C4AC42882B //sin(-17)
185 data8 0xBFD19C46B07F58E7 //cos(-17)
186 data8 0x3FD26D02085F20F8 //sin(-16)
187 data8 0xBFEEA5257E962F74 //cos(-16)
188 data8 0xBFE4CF2871CEC2E8 //sin(-15)
189 data8 0xBFE84F5D069CA4F3 //cos(-15)
190 data8 0xBFEFB30E327C5E45 //sin(-14)
191 data8 0x3FC1809AEC2CA0ED //cos(-14)
192 data8 0xBFDAE4044881C506 //sin(-13)
193 data8 0x3FED09CDD5260CB7 //cos(-13)
194 data8 0x3FE12B9AF7D765A5 //sin(-12)
195 data8 0x3FEB00DA046B65E3 //cos(-12)
196 data8 0x3FEFFFEB762E93EB //sin(-11)
197 data8 0x3F7220AE41EE2FDF //cos(-11)
198 data8 0x3FE1689EF5F34F52 //sin(-10)
199 data8 0xBFEAD9AC890C6B1F //cos(-10)
200 data8 0xBFDA6026360C2F91 //sin( -9)
201 data8 0xBFED27FAA6A6196B //cos( -9)
202 data8 0xBFEFA8D2A028CF7B //sin( -8)
203 data8 0xBFC29FBEBF632F94 //cos( -8)
204 data8 0xBFE50608C26D0A08 //sin( -7)
205 data8 0x3FE81FF79ED92017 //cos( -7)
206 data8 0x3FD1E1F18AB0A2C0 //sin( -6)
207 data8 0x3FEEB9B7097822F5 //cos( -6)
208 data8 0x3FEEAF81F5E09933 //sin( -5)
209 data8 0x3FD22785706B4AD9 //cos( -5)
210 data8 0x3FE837B9DDDC1EAE //sin( -4)
211 data8 0xBFE4EAA606DB24C1 //cos( -4)
212 data8 0xBFC210386DB6D55B //sin( -3)
213 data8 0xBFEFAE04BE85E5D2 //cos( -3)
214 data8 0xBFED18F6EAD1B446 //sin( -2)
215 data8 0xBFDAA22657537205 //cos( -2)
216 data8 0xBFEAED548F090CEE //sin( -1)
217 data8 0x3FE14A280FB5068C //cos( -1)
218 data8 0x0000000000000000 //sin( 0)
219 data8 0x3FF0000000000000 //cos( 0)
220 data8 0x3FEAED548F090CEE //sin( 1)
221 data8 0x3FE14A280FB5068C //cos( 1)
222 data8 0x3FED18F6EAD1B446 //sin( 2)
223 data8 0xBFDAA22657537205 //cos( 2)
224 data8 0x3FC210386DB6D55B //sin( 3)
225 data8 0xBFEFAE04BE85E5D2 //cos( 3)
226 data8 0xBFE837B9DDDC1EAE //sin( 4)
227 data8 0xBFE4EAA606DB24C1 //cos( 4)
228 data8 0xBFEEAF81F5E09933 //sin( 5)
229 data8 0x3FD22785706B4AD9 //cos( 5)
230 data8 0xBFD1E1F18AB0A2C0 //sin( 6)
231 data8 0x3FEEB9B7097822F5 //cos( 6)
232 data8 0x3FE50608C26D0A08 //sin( 7)
233 data8 0x3FE81FF79ED92017 //cos( 7)
234 data8 0x3FEFA8D2A028CF7B //sin( 8)
235 data8 0xBFC29FBEBF632F94 //cos( 8)
236 data8 0x3FDA6026360C2F91 //sin( 9)
237 data8 0xBFED27FAA6A6196B //cos( 9)
238 data8 0xBFE1689EF5F34F52 //sin( 10)
239 data8 0xBFEAD9AC890C6B1F //cos( 10)
240 data8 0xBFEFFFEB762E93EB //sin( 11)
241 data8 0x3F7220AE41EE2FDF //cos( 11)
242 data8 0xBFE12B9AF7D765A5 //sin( 12)
243 data8 0x3FEB00DA046B65E3 //cos( 12)
244 data8 0x3FDAE4044881C506 //sin( 13)
245 data8 0x3FED09CDD5260CB7 //cos( 13)
246 data8 0x3FEFB30E327C5E45 //sin( 14)
247 data8 0x3FC1809AEC2CA0ED //cos( 14)
248 data8 0x3FE4CF2871CEC2E8 //sin( 15)
249 data8 0xBFE84F5D069CA4F3 //cos( 15)
250 data8 0xBFD26D02085F20F8 //sin( 16)
251 data8 0xBFEEA5257E962F74 //cos( 16)
252 data8 0xBFEEC3C4AC42882B //sin( 17)
253 data8 0xBFD19C46B07F58E7 //cos( 17)
254 data8 0xBFE8081668131E26 //sin( 18)
255 data8 0x3FE52150815D2470 //cos( 18)
256 data8 0x3FC32F2D28F584CF //sin( 19)
257 data8 0x3FEFA377DE108258 //cos( 19)
258 data8 0x3FED36D8F55D3CE0 //sin( 20)
259 data8 0x3FDA1E043964A83F //cos( 20)
260 data8 0x3FEAC5E20BB0D7ED //sin( 21)
261 data8 0xBFE186FF83773759 //cos( 21)
262 data8 0xBF8220A29F6EB9F4 //sin( 22)
263 data8 0xBFEFFFADD8D4ACDA //cos( 22)
264 data8 0xBFEB143CD0247D02 //sin( 23)
265 data8 0xBFE10CF7D591F272 //cos( 23)
266 data8 0xBFECFA7F7919140F //sin( 24)
267 data8 0x3FDB25BFB50A609A //cos( 24)
268 data8 0xBFC0F0E6F31E809D //sin( 25)
269 data8 0x3FEFB7EEF59504FF //cos( 25)
270 data8 0x3FE866E0FAC32583 //sin( 26)
271 data8 0x3FE4B3902691A9ED //cos( 26)
272 data8 0x3FEE9AA1B0E5BA30 //sin( 27)
273 data8 0xBFD2B266F959DED5 //cos( 27)
274 data8 0x3FD156853B4514D6 //sin( 28)
275 data8 0xBFEECDAAD1582500 //cos( 28)
276 data8 0xBFE53C7D20A6C9E7 //sin( 29)
277 data8 0xBFE7F01658314E47 //cos( 29)
278 data8 0xBFEF9DF47F1C903D //sin( 30)
279 data8 0x3FC3BE82F2505A52 //cos( 30)
280 data8 0xBFD9DBC0B640FC81 //sin( 31)
281 data8 0x3FED4591C3E12A20 //cos( 31)
282 data8 0x3FE1A54991426566 //sin( 32)
283 data8 0x3FEAB1F5305DE8E5 //cos( 32)
284 ASM_SIZE_DIRECTIVE(sin_coeff_1_table)
286 //////////////////////////////////////////
309 alloc r32 = ar.pfs,1,7,0,0
310 fcvt.fx.s1 sin_Mx = f8
311 cmp.ne p6,p7 = r0,r0 // p7 set if cos
314 addl SIN_AD_PQ_1 = @ltoff(sin_coeff_1_table),gp
315 fnorm.s0 SIN_NORM_f8 = f8 // Sets denormal or invalid
316 mov sin_GR_sincos_flag = 0x0
321 ld8 SIN_AD_PQ_1 = [SIN_AD_PQ_1]
322 fclass.m.unc p9,p0 = f8, 0x07
328 br.sptk L(SINCOSF_COMMON)
333 ASM_SIZE_DIRECTIVE(cosf)
348 alloc r32 = ar.pfs,1,7,0,0
349 fcvt.fx.s1 sin_Mx = f8
350 cmp.eq p6,p7 = r0,r0 // p6 set if sin
353 addl SIN_AD_PQ_1 = @ltoff(sin_coeff_1_table),gp
354 fnorm.s0 SIN_NORM_f8 = f8 // Sets denormal or invalid
355 mov sin_GR_sincos_flag = 0x1
360 ld8 SIN_AD_PQ_1 = [SIN_AD_PQ_1]
361 fclass.m.unc p8,p0 = f8, 0x07
367 br.sptk L(SINCOSF_COMMON)
374 // Here with p6 if sin, p7 if cos, p8 if sin(0), p9 if cos(0)
378 ldfpd sin_coeff_Q3, sin_coeff_Q4 = [SIN_AD_PQ_1], 16
380 fclass.m.unc p11,p0 = f8, 0x23 // Test for x=inf
385 ldfpd sin_coeff_Q5, sin_coeff_Q6 = [SIN_AD_PQ_1], 16
386 fclass.m.unc p10,p0 = f8, 0xc3 // Test for x=nan
387 (p8) br.ret.spnt b0 // Exit for sin(0)
391 (p9) fma.s f8 = f1,f1,f0
392 (p9) br.ret.spnt b0 // Exit for cos(0)
397 ldfpd sin_coeff_P4, sin_coeff_P5 = [SIN_AD_PQ_1], 16
399 fcvt.xf sin_Mfloat = sin_Mx
404 getf.sig sin_GR_Mint = sin_Mx
405 (p11) frcpa.s0 f8,p13 = f0,f0 // qnan indef if x=inf
409 ldfpd sin_coeff_P1, sin_coeff_P2 = [SIN_AD_PQ_1], 16
411 (p11) br.ret.spnt b0 // Exit for x=inf
416 ldfpd sin_coeff_Q1, sin_coeff_Q2 = [SIN_AD_PQ_1], 16
418 cmp.ge p8,p9 = -33,sin_GR_Mint
421 add sin_GR_index = 32,sin_GR_Mint
422 (p10) fma.s f8 = f8,f1,f0 // Force qnan if x=nan
423 (p10) br.ret.spnt b0 // Exit for x=nan
428 ldfd sin_coeff_P3 = [SIN_AD_PQ_1], 16
429 (p9) cmp.le p8,p0 = 33, sin_GR_Mint
430 shl sin_GR_index = sin_GR_index,4
436 setf.sig fp_tmp = gr_tmp // Create constant such that fmpy sets inexact
437 fnma.s1 sin_r = f1,sin_Mfloat,SIN_NORM_f8
438 (p8) cmp.eq.unc p11,p12=sin_GR_sincos_flag,r0 // p11 if must call dbl cos
439 // p12 if must call dbl sin
442 add SIN_AD_PQ_2 = sin_GR_index,SIN_AD_PQ_1
443 (p11) br.cond.spnt COS_DOUBLE
444 (p12) br.cond.spnt SIN_DOUBLE
448 .pred.rel "mutex",p6,p7 //SIN_Sin_Flag, SIN_Cos_Flag
450 (p6) ldfpd sin_tbl_S,sin_tbl_C = [SIN_AD_PQ_2]
451 (p7) ldfpd sin_tbl_C,sin_tbl_S = [SIN_AD_PQ_2]
458 (p6) fclass.m.unc p8,p0 = f8, 0x0b // If sin, note denormal input to set uflow
463 fma.s1 sin_t = sin_r,sin_r,f0
470 fma.s1 sin_rcube = sin_t,sin_r,f0
475 fma.s1 sin_tsq = sin_t,sin_t,f0
482 fma.s1 sin_poly_q3 = sin_t,sin_coeff_Q4,sin_coeff_Q3
487 fma.s1 sin_poly_q5 = sin_t,sin_coeff_Q6,sin_coeff_Q5
494 fma.s1 sin_poly_p1 = sin_t,sin_coeff_P5,sin_coeff_P4
499 fma.s1 sin_poly_p2 = sin_t,sin_coeff_P2,sin_coeff_P1
506 fma.s1 sin_poly_q1 = sin_t,sin_coeff_Q2,sin_coeff_Q1
511 fma.s1 sin_S_t = sin_t,sin_tbl_S,f0
518 (p8) fmpy.s.s0 fp_tmp2 = f8,f8 // Dummy mult to set underflow if sin(denormal)
523 fma.s1 sin_r7 = sin_rcube,sin_tsq,f0
530 fma.s1 sin_poly_q3456 = sin_tsq,sin_poly_q5,sin_poly_q3
537 fma.s1 sin_poly_p3 = sin_t,sin_poly_p1,sin_coeff_P3
542 fma.s1 sin_poly_p4 = sin_rcube,sin_poly_p2,sin_r
549 fma.s1 sin_tbl_S_tcube = sin_S_t,sin_tsq,f0
554 fma.s1 sin_poly_q12 = sin_S_t,sin_poly_q1,sin_tbl_S
561 fma.d.s1 sin_of_r = sin_r7,sin_poly_p3,sin_poly_p4
568 fma.d.s1 sin_tbl_S_cos_of_r = sin_tbl_S_tcube,sin_poly_q3456,sin_poly_q12
573 fmpy.s0 fp_tmp = fp_tmp, fp_tmp // Dummy mult to set inexact
579 .pred.rel "mutex",p6,p7 //SIN_Sin_Flag, SIN_Cos_Flag
582 //(SIN_Sin_Flag) fma.s f8 = sin_tbl_C,sin_of_r,sin_tbl_S_cos_of_r
583 (p6) fma.s f8 = sin_tbl_C,sin_of_r,sin_tbl_S_cos_of_r
588 //(SIN_Cos_Flag) fnma.s f8 = sin_tbl_C,sin_of_r,sin_tbl_S_cos_of_r
589 (p7) fnma.s f8 = sin_tbl_C,sin_of_r,sin_tbl_S_cos_of_r
594 ASM_SIZE_DIRECTIVE(sinf)
603 .save ar.pfs,GR_SAVE_PFS
604 mov GR_SAVE_PFS=ar.pfs
619 br.call.sptk.many b0=sin
633 (p0) mov ar.pfs = GR_SAVE_PFS
643 ASM_SIZE_DIRECTIVE(SIN_DOUBLE)
652 .save ar.pfs,GR_SAVE_PFS
653 mov GR_SAVE_PFS=ar.pfs
668 br.call.sptk.many b0=cos
682 (p0) mov ar.pfs = GR_SAVE_PFS
692 ASM_SIZE_DIRECTIVE(COS_DOUBLE)