4 // Copyright (c) 2001 - 2003, Intel Corporation
5 // All rights reserved.
7 // Contributed 2001 by the Intel Numerics Group, Intel Corporation
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
13 // * Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
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.
20 // * The name of Intel Corporation may not be used to endorse or promote
21 // products derived from this software without specific prior written
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.
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.
40 //*********************************************************************
43 // 11/30/01 Initial version
44 // 05/20/02 Cleaned up namespace and sf0 syntax
45 // 02/10/03 Reordered header: .section, .global, .proc, .align
46 // 04/04/03 Changed error codes for overflow and negative integers
47 // 04/10/03 Changed code for overflow near zero handling
49 //*********************************************************************
51 //*********************************************************************
53 // Function: tgammaf(x) computes the principle value of the GAMMA
56 //*********************************************************************
60 // Floating-Point Registers: f8-f15
63 // General Purpose Registers:
67 // r37-r40 (Used to pass arguments to error handling routine)
69 // Predicate Registers: p6-p15
71 //*********************************************************************
73 // IEEE Special Conditions:
75 // tgammaf(+inf) = +inf
76 // tgammaf(-inf) = QNaN
77 // tgammaf(+/-0) = +/-inf
78 // tgammaf(x<0, x - integer) = QNaN
79 // tgammaf(SNaN) = QNaN
80 // tgammaf(QNaN) = QNaN
82 //*********************************************************************
86 // The method consists of three cases.
88 // If 2 <= x < OVERFLOW_BOUNDARY use case tgamma_regular;
89 // else if 0 < x < 2 use case tgamma_from_0_to_2;
90 // else if -(i+1) < x < -i, i = 0...43 use case tgamma_negatives;
92 // Case 2 <= x < OVERFLOW_BOUNDARY
93 // -------------------------------
94 // Here we use algorithm based on the recursive formula
95 // GAMMA(x+1) = x*GAMMA(x). For that we subdivide interval
96 // [2; OVERFLOW_BOUNDARY] into intervals [8*n; 8*(n+1)] and
97 // approximate GAMMA(x) by polynomial of 22th degree on each
98 // [8*n; 8*n+1], recursive formula is used to expand GAMMA(x)
99 // to [8*n; 8*n+1]. In other words we need to find n, i and r
100 // such that x = 8 * n + i + r where n and i are integer numbers
101 // and r is fractional part of x. So GAMMA(x) = GAMMA(8*n+i+r) =
102 // = (x-1)*(x-2)*...*(x-i)*GAMMA(x-i) =
103 // = (x-1)*(x-2)*...*(x-i)*GAMMA(8*n+r) ~
104 // ~ (x-1)*(x-2)*...*(x-i)*P12n(r).
108 // N = [x] with truncate
109 // r = x - N, note 0 <= r < 1
111 // n = N & ~0xF - index of table that contains coefficient of
112 // polynomial approximation
113 // i = N & 0xF - is used in recursive formula
116 // Step 2: Approximation
117 // ---------------------
118 // We use factorized minimax approximation polynomials
119 // P12n(r) = A12*(r^2+C01(n)*r+C00(n))*
120 // *(r^2+C11(n)*r+C10(n))*...*(r^2+C51(n)*r+C50(n))
124 // In case when i > 0 we need to multiply P12n(r) by product
125 // R(i,x)=(x-1)*(x-2)*...*(x-i). To reduce number of fp-instructions
126 // we can calculate R as follow:
127 // R(i,x) = ((x-1)*(x-2))*((x-3)*(x-4))*...*((x-(i-1))*(x-i)) if i is
128 // even or R = ((x-1)*(x-2))*((x-3)*(x-4))*...*((x-(i-2))*(x-(i-1)))*
129 // *(i-1) if i is odd. In both cases we need to calculate
130 // R2(i,x) = (x^2-3*x+2)*(x^2-7*x+12)*...*(x^2+x+2*j*(2*j-1)) =
131 // = ((x^2-x)+2*(1-x))*((x^2-x)+6*(2-x))*...*((x^2-x)+2*(2*j-1)*(j-x)) =
132 // = (RA+2*RB)*(RA+6*(1-RB))*...*(RA+2*(2*j-1)*(j-1+RB))
133 // where j = 1..[i/2], RA = x^2-x, RB = 1-x.
135 // Step 4: Reconstruction
136 // ----------------------
137 // Reconstruction is just simple multiplication i.e.
138 // GAMMA(x) = P12n(r)*R(i,x)
142 // To calculate GAMMA(x) on this interval we do following
143 // if 1.0 <= x < 1.25 than GAMMA(x) = P7(x-1)
144 // if 1.25 <= x < 1.5 than GAMMA(x) = P7(x-x_min) where
145 // x_min is point of local minimum on [1; 2] interval.
146 // if 1.5 <= x < 1.75 than GAMMA(x) = P7(x-1.5)
147 // if 1.75 <= x < 2.0 than GAMMA(x) = P7(x-1.5)
149 // if 0 < x < 1 than GAMMA(x) = GAMMA(x+1)/x
151 // Case -(i+1) < x < -i, i = 0...43
152 // ----------------------------------
153 // Here we use the fact that GAMMA(-x) = PI/(x*GAMMA(x)*sin(PI*x)) and
154 // so we need to calculate GAMMA(x), sin(PI*x)/PI. Calculation of
155 // GAMMA(x) is described above.
159 // Note that period of sin(PI*x) is 2 and range reduction for
160 // sin(PI*x) is like to range reduction for GAMMA(x)
161 // i.e rs = x - round(x) and |rs| <= 0.5.
163 // Step 2: Approximation
164 // ---------------------
165 // To approximate sin(PI*x)/PI = sin(PI*(2*n+rs))/PI =
166 // = (-1)^n*sin(PI*rs)/PI Taylor series is used.
167 // sin(PI*rs)/PI ~ S17(rs).
171 // To calculate 1/x and 1/(GAMMA(x)*S12(rs)) we use frcpa
172 // instruction with following Newton-Raphson interations.
175 //*********************************************************************
195 GR_ZeroResBound = r24
211 GR_Parameter_RESULT = r39
212 GR_Parameter_TAG = r40
291 //==============================================================
294 LOCAL_OBJECT_START(tgammaf_data)
295 data8 0x3FDD8B618D5AF8FE // local minimum (0.461632144968362356785)
296 data8 0x4024000000000000 // 10.0
297 data8 0x3E90FC992FF39E13 // S32
298 data8 0xBEC144B2760626E2 // S31
301 data8 0x4009EFD1BA0CB3B4 // C01
302 data8 0x3FFFB35378FF4822 // C11
303 data8 0xC01032270413B896 // C41
304 data8 0xC01F171A4C0D6827 // C51
305 data8 0x40148F8E197396AC // C20
306 data8 0x401C601959F1249C // C30
307 data8 0x3EE21AD881741977 // An
308 data8 0x4041852200000000 // overflow boundary (35.04010009765625)
309 data8 0x3FD9CE68F695B198 // C21
310 data8 0xBFF8C30AC900DA03 // C31
311 data8 0x400E17D2F0535C02 // C00
312 data8 0x4010689240F7FAC8 // C10
313 data8 0x402563147DDCCF8D // C40
314 data8 0x4033406D0480A21C // C50
317 data8 0x4006222BAE0B793B // C01
318 data8 0x4002452733473EDA // C11
319 data8 0xC0010EF3326FDDB3 // C41
320 data8 0xC01492B817F99C0F // C51
321 data8 0x40099C905A249B75 // C20
322 data8 0x4012B972AE0E533D // C30
323 data8 0x3FE6F6DB91D0D4CC // An
324 data8 0x4041852200000000 // overflow boundary
325 data8 0x3FF545828F7B73C5 // C21
326 data8 0xBFBBD210578764DF // C31
327 data8 0x4000542098F53CFC // C00
328 data8 0x40032C1309AD6C81 // C10
329 data8 0x401D7331E19BD2E1 // C40
330 data8 0x402A06807295EF57 // C50
333 data8 0x4000131002867596 // C01
334 data8 0x3FFAA362D5D1B6F2 // C11
335 data8 0xBFFCB6985697DB6D // C41
336 data8 0xC0115BEE3BFC3B3B // C51
337 data8 0x3FFE62FF83456F73 // C20
338 data8 0x4007E33478A114C4 // C30
339 data8 0x41E9B2B73795ED57 // An
340 data8 0x4041852200000000 // overflow boundary
341 data8 0x3FEEB1F345BC2769 // C21
342 data8 0xBFC3BBE6E7F3316F // C31
343 data8 0x3FF14E07DA5E9983 // C00
344 data8 0x3FF53B76BF81E2C0 // C10
345 data8 0x4014051E0269A3DC // C40
346 data8 0x40229D4227468EDB // C50
349 data8 0x3FFAF7BD498384DE // C01
350 data8 0x3FF62AD8B4D1C3D2 // C11
351 data8 0xBFFABCADCD004C32 // C41
352 data8 0xC00FADE97C097EC9 // C51
353 data8 0x3FF6DA9ED737707E // C20
354 data8 0x4002A29E9E0C782C // C30
355 data8 0x44329D5B5167C6C3 // An
356 data8 0x4041852200000000 // overflow boundary
357 data8 0x3FE8943CBBB4B727 // C21
358 data8 0xBFCB39D466E11756 // C31
359 data8 0x3FE879AF3243D8C1 // C00
360 data8 0x3FEEC7DEBB14CE1E // C10
361 data8 0x401017B79BA80BCB // C40
362 data8 0x401E941DC3C4DE80 // C50
365 data8 0x3FF7ECB3A0E8FE5C // C01
366 data8 0x3FF3815A8516316B // C11
367 data8 0xBFF9ABD8FCC000C3 // C41
368 data8 0xC00DD89969A4195B // C51
369 data8 0x3FF2E43139CBF563 // C20
370 data8 0x3FFF96DC3474A606 // C30
371 data8 0x46AFF4CA9B0DDDF0 // An
372 data8 0x4041852200000000 // overflow boundary
373 data8 0x3FE4CE76DA1B5783 // C21
374 data8 0xBFD0524DB460BC4E // C31
375 data8 0x3FE35852DF14E200 // C00
376 data8 0x3FE8C7610359F642 // C10
377 data8 0x400BCF750EC16173 // C40
378 data8 0x401AC14E02EA701C // C50
381 data8 0x3FF5DCE4D8193097 // C01
382 data8 0x3FF1B0D8C4974FFA // C11
383 data8 0xBFF8FB450194CAEA // C41
384 data8 0xC00C9658E030A6C4 // C51
385 data8 0x3FF068851118AB46 // C20
386 data8 0x3FFBF7C7BB46BF7D // C30
387 data8 0x3FF0000000000000 // An
388 data8 0x4041852200000000 // overflow boundary
389 data8 0x3FE231DEB11D847A // C21
390 data8 0xBFD251ECAFD7E935 // C31
391 data8 0x3FE0368AE288F6BF // C00
392 data8 0x3FE513AE4215A70C // C10
393 data8 0x4008F960F7141B8B // C40
394 data8 0x40183BA08134397B // C50
397 data8 0xBFD9909648921868 // A7
398 data8 0x3FE96FFEEEA8520F // A6
399 data8 0xBFED0800D93449B8 // A3
400 data8 0x3FEFA648D144911C // A2
401 data8 0xBFEE3720F7720B4D // A5
402 data8 0x3FEF4857A010CA3B // A4
403 data8 0xBFE2788CCD545AA4 // A1
404 data8 0x3FEFFFFFFFE9209E // A0
407 data8 0xBFB421236426936C // A7
408 data8 0x3FAF237514F36691 // A6
409 data8 0xBFC0BADE710A10B9 // A3
410 data8 0x3FDB6C5465BBEF1F // A2
411 data8 0xBFB7E7F83A546EBE // A5
412 data8 0x3FC496A01A545163 // A4
413 data8 0xBDEE86A39D8452EB // A1
414 data8 0x3FEC56DC82A39AA2 // A0
417 data8 0xBF94730B51795867 // A7
418 data8 0x3FBF4203E3816C7B // A6
419 data8 0xBFE85B427DBD23E4 // A3
420 data8 0x3FEE65557AB26771 // A2
421 data8 0xBFD59D31BE3AB42A // A5
422 data8 0x3FE3C90CC8F09147 // A4
423 data8 0xBFE245971DF735B8 // A1
424 data8 0x3FEFFC613AE7FBC8 // A0
427 data8 0xBF7746A85137617E // A7
428 data8 0x3FA96E37D09735F3 // A6
429 data8 0xBFE3C24AC40AC0BB // A3
430 data8 0x3FEC56A80A977CA5 // A2
431 data8 0xBFC6F0E707560916 // A5
432 data8 0x3FDB262D949175BE // A4
433 data8 0xBFE1C1AEDFB25495 // A1
434 data8 0x3FEFEE1E644B2022 // A0
437 data8 0xC026FB0D377656CC // S01
438 data8 0x3FFFB15F95A22324 // S11
439 data8 0x406CE58F4A41C6E7 // S10
440 data8 0x404453786302C61E // S20
441 data8 0xC023D59A47DBFCD3 // S21
442 data8 0x405541D7ABECEFCA // S00
445 data8 0xCAA7576DE621FCD5, 0x3F68
446 LOCAL_OBJECT_END(tgammaf_data)
448 //==============================================================
450 //==============================================================
453 GLOBAL_LIBM_ENTRY(tgammaf)
455 getf.exp GR_SignExp = f8
456 fma.s1 FR_NormX = f8,f1,f0
457 addl GR_ad_Data = @ltoff(tgammaf_data), gp
460 mov GR_ExpOf05 = 0xFFFE
461 fcvt.fx.trunc.s1 FR_iXt = f8 // [x]
462 mov GR_Offs = 0 // 2 <= x < 8
466 fcmp.lt.s1 p14,p15 = f8,f0
470 setf.exp FR_05 = GR_ExpOf05
471 fma.s1 FR_2 = f1,f1,f1 // 2
472 mov GR_Correction = 0
475 ld8 GR_ad_Data = [GR_ad_Data]
476 fclass.m p10,p0 = f8,0x1E7 // is x NaTVal, NaN, +/-0 or +/-INF?
477 tbit.z p12,p13 = GR_SignExp,16 // p13 if |x| >= 2
480 mov GR_ExpOf1 = 0xFFFF
481 fcvt.fx.s1 FR_rs = f8 // round(x)
482 and GR_Exp2Ind = 7,GR_SignExp
484 .pred.rel "mutex",p14,p15
486 (p15) cmp.eq.unc p11,p0 = GR_ExpOf1,GR_SignExp // p11 if 1 <= x < 2
487 (p14) fma.s1 FR_1mX = f1,f1,f8 // 1 - |x|
488 mov GR_Sig = 0 // if |x| < 2
491 (p13) cmp.eq.unc p7,p0 = 2,GR_Exp2Ind
492 (p15) fms.s1 FR_1mX = f1,f1,f8 // 1 - |x|
493 (p13) cmp.eq.unc p8,p0 = 3,GR_Exp2Ind
495 .pred.rel "mutex",p7,p8
497 (p7) mov GR_Offs = 0x7 // 8 <= |x| < 16
499 (p8) tbit.z.unc p0,p6 = GR_Arg,51
502 (p13) cmp.lt.unc p9,p0 = 3,GR_Exp2Ind
503 (p8) mov GR_Offs = 0xE // 16 <= |x| < 32
504 // jump if x is NaTVal, NaN, +/-0 or +/-INF?
505 (p10) br.cond.spnt tgammaf_spec_args
507 .pred.rel "mutex",p14,p15
508 .pred.rel "mutex",p6,p9
510 (p9) mov GR_Offs = 0x1C // 32 <= |x|
511 (p14) fma.s1 FR_X2mX = FR_NormX,FR_NormX,FR_NormX // x^2-|x|
512 (p9) tbit.z.unc p0,p8 = GR_Arg,50
515 ldfpd FR_LocalMin,FR_10 = [GR_ad_Data],16
516 (p15) fms.s1 FR_X2mX = FR_NormX,FR_NormX,FR_NormX // x^2-|x|
517 (p6) add GR_Offs = 0x7,GR_Offs // 24 <= x < 32
519 .pred.rel "mutex",p8,p12
521 add GR_ad_Ce = 0x50,GR_ad_Data
522 (p15) fcmp.lt.unc.s1 p10,p0 = f8,f1 // p10 if 0 <= x < 1
523 mov GR_OvfNzBound = 2
526 ldfpd FR_S32,FR_S31 = [GR_ad_Data],16
527 (p8) add GR_Offs = 0x7,GR_Offs // 40 <= |x|
528 // jump if 1 <= x < 2
529 (p11) br.cond.spnt tgammaf_from_1_to_2
532 shladd GR_ad_Ce = GR_Offs,4,GR_ad_Ce
533 fcvt.xf FR_Xt = FR_iXt // [x]
534 (p13) cmp.eq.unc p7,p0 = r0,GR_Offs // p7 if 2 <= |x| < 8
537 shladd GR_ad_Co = GR_Offs,4,GR_ad_Data
538 fma.s1 FR_6 = FR_2,FR_2,FR_2
539 mov GR_ExpOf05 = 0x7FC
542 (p13) getf.sig GR_Sig = FR_iXt // if |x| >= 2
543 frcpa.s1 FR_Rcp0,p0 = f1,FR_NormX
544 (p10) shr GR_Arg = GR_Arg,51
547 ldfpd FR_C01,FR_C11 = [GR_ad_Co],16
548 (p7) mov GR_Correction = 2
550 (p10) br.cond.spnt tgammaf_from_0_to_1
553 ldfpd FR_C21,FR_C31 = [GR_ad_Ce],16
554 fma.s1 FR_Rq2 = f1,f1,FR_1mX // 2 - |x|
555 (p14) sub GR_Correction = r0,GR_Correction
558 ldfpd FR_C41,FR_C51 = [GR_ad_Co],16
559 (p14) fcvt.xf FR_rs = FR_rs
560 (p14) add GR_ad_SinO = 0x3A0,GR_ad_Data
562 .pred.rel "mutex",p14,p15
564 ldfpd FR_C00,FR_C10 = [GR_ad_Ce],16
566 (p14) sub GR_Sig = GR_Correction,GR_Sig
569 ldfpd FR_C20,FR_C30 = [GR_ad_Co],16
570 fma.s1 FR_Rq1 = FR_1mX,FR_2,FR_X2mX // (x-1)*(x-2)
571 (p15) sub GR_Sig = GR_Sig,GR_Correction
574 (p14) ldfpd FR_S01,FR_S11 = [GR_ad_SinO],16
575 fma.s1 FR_Rq3 = FR_2,f1,FR_1mX // 3 - |x|
576 and GR_RqDeg = 0x6,GR_Sig
579 ldfpd FR_C40,FR_C50 = [GR_ad_Ce],16
580 (p14) fma.d.s0 FR_X = f0,f0,f8 // set deno flag
581 mov GR_NanBound = 0x30016 // -2^23
583 .pred.rel "mutex",p14,p15
585 (p14) add GR_ad_SinE = 0x3C0,GR_ad_Data
586 (p15) fms.s1 FR_r = FR_NormX,f1,FR_Xt // r = x - [x]
587 cmp.eq p8,p0 = 2,GR_RqDeg
590 ldfpd FR_An,FR_OvfBound = [GR_ad_Co]
591 (p14) fms.s1 FR_r = FR_Xt,f1,FR_NormX // r = |x - [x]|
592 cmp.eq p9,p0 = 4,GR_RqDeg
594 .pred.rel "mutex",p8,p9
596 (p14) ldfpd FR_S21,FR_S00 = [GR_ad_SinE],16
597 (p8) fma.s1 FR_Rq0 = FR_2,f1,FR_1mX // (3-x)
598 tbit.z p0,p6 = GR_Sig,0
601 (p14) ldfpd FR_S10,FR_S20 = [GR_ad_SinO],16
602 (p9) fma.s1 FR_Rq0 = FR_2,FR_2,FR_1mX // (5-x)
603 cmp.eq p10,p0 = 6,GR_RqDeg
606 (p14) getf.s GR_Arg = f8
607 (p14) fcmp.eq.unc.s1 p13,p0 = FR_NormX,FR_Xt
608 (p14) mov GR_ZeroResBound = 0xC22C // -43
611 (p14) ldfe FR_InvAn = [GR_ad_SinE]
612 (p10) fma.s1 FR_Rq0 = FR_6,f1,FR_1mX // (7-x)
613 cmp.eq p7,p0 = r0,GR_RqDeg
616 (p14) cmp.ge.unc p11,p0 = GR_SignExp,GR_NanBound
617 fma.s1 FR_Rq2 = FR_Rq2,FR_6,FR_X2mX // (x-3)*(x-4)
618 (p14) shl GR_ZeroResBound = GR_ZeroResBound,16
621 (p14) mov GR_OvfNzBound = 0x802
622 (p14) fms.s1 FR_rs = FR_rs,f1,FR_NormX // rs = round(x) - x
623 // jump if x < -2^23 i.e. x is negative integer
624 (p11) br.cond.spnt tgammaf_singularity
628 (p7) fma.s1 FR_Rq1 = f0,f0,f1
629 (p14) shl GR_OvfNzBound = GR_OvfNzBound,20
633 fma.s1 FR_Rq3 = FR_Rq3,FR_10,FR_X2mX // (x-5)*(x-6)
634 // jump if x is negative integer such that -2^23 < x < 0
635 (p13) br.cond.spnt tgammaf_singularity
639 fma.s1 FR_C01 = FR_C01,f1,FR_r
640 (p14) mov GR_ExpOf05 = 0xFFFE
643 (p14) cmp.eq.unc p7,p0 = GR_Arg,GR_OvfNzBound
644 fma.s1 FR_C11 = FR_C11,f1,FR_r
645 (p14) cmp.ltu.unc p11,p0 = GR_Arg,GR_OvfNzBound
649 fma.s1 FR_C21 = FR_C21,f1,FR_r
650 (p14) cmp.ltu.unc p9,p0 = GR_ZeroResBound,GR_Arg
654 fma.s1 FR_C31 = FR_C31,f1,FR_r
655 // jump if argument is close to 0 negative
656 (p11) br.cond.spnt tgammaf_overflow
660 fma.s1 FR_C41 = FR_C41,f1,FR_r
665 fma.s1 FR_C51 = FR_C51,f1,FR_r
666 // jump if x is negative noninteger such that -2^23 < x < -43
667 (p9) br.cond.spnt tgammaf_underflow
671 (p14) fma.s1 FR_rs2 = FR_rs,FR_rs,f0
676 (p14) fma.s1 FR_S01 = FR_rs,FR_rs,FR_S01
677 // jump if argument is 0x80200000
678 (p7) br.cond.spnt tgammaf_overflow_near0_bound
682 (p6) fnma.s1 FR_Rq1 = FR_Rq1,FR_Rq0,f0
687 (p10) fma.s1 FR_Rq2 = FR_Rq2,FR_Rq3,f0
688 and GR_Sig = 0x7,GR_Sig
692 fma.s1 FR_C01 = FR_C01,FR_r,FR_C00
697 fma.s1 FR_C11 = FR_C11,FR_r,FR_C10
698 cmp.eq p6,p7 = r0,GR_Sig // p6 if |x| from one of base intervals
702 fma.s1 FR_C21 = FR_C21,FR_r,FR_C20
707 fma.s1 FR_C31 = FR_C31,FR_r,FR_C30
708 (p7) cmp.lt.unc p9,p0 = 2,GR_RqDeg
712 (p14) fma.s1 FR_S11 = FR_rs,FR_rs,FR_S11
717 (p14) fma.s1 FR_S21 = FR_rs,FR_rs,FR_S21
722 fma.s1 FR_C41 = FR_C41,FR_r,FR_C40
727 (p14) fma.s1 FR_S32 = FR_rs2,FR_S32,FR_S31
732 (p9) fma.s1 FR_Rq1 = FR_Rq1,FR_Rq2,f0
737 fma.s1 FR_C51 = FR_C51,FR_r,FR_C50
741 (p14) getf.exp GR_SignExp = FR_rs
742 fma.s1 FR_C01 = FR_C01,FR_C11,f0
747 (p14) fma.s1 FR_S01 = FR_S01,FR_rs2,FR_S00
752 fma.s1 FR_C21 = FR_C21,FR_C31,f0
758 (p14) fnma.s1 FR_InvNormX1 = FR_Rcp0,FR_NormX,f1
763 (p14) fma.s1 FR_S11 = FR_S11,FR_rs2,FR_S10
764 (p14) tbit.z.unc p11,p12 = GR_SignExp,17
768 (p14) fma.s1 FR_S21 = FR_S21,FR_rs2,FR_S20
773 (p15) fcmp.lt.unc.s1 p0,p13 = FR_NormX,FR_OvfBound
778 (p14) fma.s1 FR_S32 = FR_rs2,FR_S32,f0
783 fma.s1 FR_C41 = FR_C41,FR_C51,f0
788 (p7) fma.s1 FR_An = FR_Rq1,FR_An,f0
794 // jump if x > 35.04010009765625
795 (p13) br.cond.spnt tgammaf_overflow
800 (p14) fma.s1 FR_InvNormX1 = FR_Rcp0,FR_InvNormX1,FR_Rcp0
805 (p14) fma.s1 FR_S01 = FR_S01,FR_S11,f0
810 (p14) fma.s1 FR_S21 = FR_S21,FR_S32,f0
814 (p14) getf.exp GR_SignExp = FR_NormX
815 fma.s1 FR_C01 = FR_C01,FR_C21,f0
820 fma.s1 FR_C41 = FR_C41,FR_An,f0
821 (p14) mov GR_ExpOf1 = 0x2FFFF
826 (p14) fnma.s1 FR_InvNormX2 = FR_InvNormX1,FR_NormX,f1
829 .pred.rel "mutex",p11,p12
832 (p12) fnma.s1 FR_S01 = FR_S01,FR_S21,f0
837 (p11) fma.s1 FR_S01 = FR_S01,FR_S21,f0
843 (p14) fma.s1 FR_GAMMA = FR_C01,FR_C41,f0
844 (p14) tbit.z.unc p6,p7 = GR_Sig,0
848 (p15) fma.s.s0 f8 = FR_C01,FR_C41,f0
849 (p15) br.ret.spnt b0 // exit for positives
851 .pred.rel "mutex",p11,p12
854 (p12) fms.s1 FR_S01 = FR_rs,FR_S01,FR_rs
859 (p11) fma.s1 FR_S01 = FR_rs,FR_S01,FR_rs
865 fma.s1 FR_InvNormX2 = FR_InvNormX1,FR_InvNormX2,FR_InvNormX1
866 cmp.eq p10,p0 = 0x23,GR_Offs
868 .pred.rel "mutex",p6,p7
871 (p6) fma.s1 FR_GAMMA = FR_S01,FR_GAMMA,f0
872 cmp.gtu p8,p0 = GR_SignExp,GR_ExpOf1
876 (p7) fnma.s1 FR_GAMMA = FR_S01,FR_GAMMA,f0
877 cmp.eq p9,p0 = GR_SignExp,GR_ExpOf1
882 fnma.s1 FR_InvNormX1 = FR_InvNormX2,FR_NormX,f1
887 (p10) fma.s1 FR_InvNormX2 = FR_InvNormX2,FR_InvAn,f0
892 frcpa.s1 FR_Rcp0,p0 = f1,FR_GAMMA
897 fms.s1 FR_Multplr = FR_NormX,f1,f1 // x - 1
903 fnma.s1 FR_Rcp1 = FR_Rcp0,FR_GAMMA,f1
906 .pred.rel "mutex",p8,p9
910 (p8) fma.s1 FR_Multplr = FR_InvNormX2,FR_InvNormX1,FR_InvNormX2
915 (p9) fma.s1 FR_Multplr = f1,f1,f0
921 fma.s1 FR_Rcp1 = FR_Rcp0,FR_Rcp1,FR_Rcp0
927 fnma.s1 FR_Rcp2 = FR_Rcp1,FR_GAMMA,f1
933 fma.s1 FR_Rcp1 = FR_Rcp1,FR_Multplr,f0
938 fma.s.s0 f8 = FR_Rcp1,FR_Rcp2,FR_Rcp1
943 //--------------------------------------------------------------------
947 cmp.lt p7,p0 = GR_Arg,GR_ExpOf05
949 fnma.s1 FR_Rcp1 = FR_Rcp0,FR_NormX,f1
950 cmp.eq p8,p0 = GR_Arg,GR_ExpOf05
953 cmp.gt p9,p0 = GR_Arg,GR_ExpOf05
954 fma.s1 FR_r = f0,f0,FR_NormX // reduced arg for (0;1)
955 mov GR_ExpOf025 = 0x7FA
959 fma.d.s0 FR_X = f0,f0,f8 // set deno flag
960 shl GR_OvfNzBound = GR_OvfNzBound,20
963 (p8) mov GR_Tbl12Offs = 0x80 // 0.5 <= x < 0.75
965 (p7) cmp.ge.unc p6,p0 = GR_Arg,GR_ExpOf025
967 .pred.rel "mutex",p6,p9
969 (p9) mov GR_Tbl12Offs = 0xC0 // 0.75 <= x < 1
971 (p6) mov GR_Tbl12Offs = 0x40 // 0.25 <= x < 0.5
974 add GR_ad_Ce = 0x2C0,GR_ad_Data
976 add GR_ad_Co = 0x2A0,GR_ad_Data
979 add GR_ad_Co = GR_ad_Co,GR_Tbl12Offs
981 cmp.lt p12,p0 = GR_ArgNz,GR_OvfNzBound
984 add GR_ad_Ce = GR_ad_Ce,GR_Tbl12Offs
985 cmp.eq p7,p0 = GR_ArgNz,GR_OvfNzBound
986 // jump if argument is 0x00200000
987 (p7) br.cond.spnt tgammaf_overflow_near0_bound
990 ldfpd FR_A7,FR_A6 = [GR_ad_Co],16
991 ldfpd FR_A5,FR_A4 = [GR_ad_Ce],16
992 // jump if argument is close to 0 positive
993 (p12) br.cond.spnt tgammaf_overflow
996 ldfpd FR_A3,FR_A2 = [GR_ad_Co],16
998 fma.s1 FR_Rcp1 = FR_Rcp0,FR_Rcp1,FR_Rcp0
1002 ldfpd FR_A1,FR_A0 = [GR_ad_Ce],16
1004 br.cond.sptk tgamma_from_0_to_2
1007 // here if 1 < x < 2
1008 //--------------------------------------------------------------------
1010 tgammaf_from_1_to_2:
1012 add GR_ad_Co = 0x2A0,GR_ad_Data
1013 fms.s1 FR_r = f0,f0,FR_1mX
1014 shr GR_TblOffs = GR_Arg,47
1017 add GR_ad_Ce = 0x2C0,GR_ad_Data
1019 mov GR_TblOffsMask = 0x18
1024 and GR_TblOffs = GR_TblOffs,GR_TblOffsMask
1027 shladd GR_ad_Co = GR_TblOffs,3,GR_ad_Co
1032 shladd GR_ad_Ce = GR_TblOffs,3,GR_ad_Ce
1034 cmp.eq p6,p7 = 8,GR_TblOffs
1037 ldfpd FR_A7,FR_A6 = [GR_ad_Co],16
1038 ldfpd FR_A5,FR_A4 = [GR_ad_Ce],16
1042 ldfpd FR_A3,FR_A2 = [GR_ad_Co],16
1043 ldfpd FR_A1,FR_A0 = [GR_ad_Ce],16
1051 (p6) fms.s1 FR_r = FR_r,f1,FR_LocalMin
1057 (p10) fnma.s1 FR_Rcp2 = FR_Rcp1,FR_NormX,f1
1062 fms.s1 FR_r2 = FR_r,FR_r,f0
1067 fma.s1 FR_A7 = FR_A7,FR_r,FR_A6
1072 fma.s1 FR_A5 = FR_A5,FR_r,FR_A4
1077 fma.s1 FR_A3 = FR_A3,FR_r,FR_A2
1082 fma.s1 FR_A1 = FR_A1,FR_r,FR_A0
1088 (p10) fma.s1 FR_Rcp2 = FR_Rcp1,FR_Rcp2,FR_Rcp1
1093 fma.s1 FR_A7 = FR_A7,FR_r2,FR_A5
1098 fma.s1 FR_r4 = FR_r2,FR_r2,f0
1103 fma.s1 FR_A3 = FR_A3,FR_r2,FR_A1
1108 (p10) fma.s1 FR_GAMMA = FR_A7,FR_r4,FR_A3
1113 (p11) fma.s.s0 f8 = FR_A7,FR_r4,FR_A3
1118 (p10) fma.s.s0 f8 = FR_GAMMA,FR_Rcp2,f0
1124 //--------------------------------------------------------------------
1126 tgammaf_overflow_near0_bound:
1127 .pred.rel "mutex",p14,p15
1129 mov GR_fpsr = ar.fpsr
1131 (p15) mov r8 = 0x7f8
1136 (p14) mov r8 = 0xff8
1146 extr.u GR_fpsr = GR_fpsr,10,2 // rounding mode
1148 .pred.rel "mutex",p14,p15
1150 // set p8 to 0 in case of overflow and to 1 otherwise
1151 // for negative arg:
1152 // no overflow if rounding mode either Z or +Inf, i.e.
1154 (p14) cmp.lt p8,p0 = 1,GR_fpsr
1156 // for positive arg:
1157 // no overflow if rounding mode either Z or -Inf, i.e.
1158 // (GR_fpsr & 1) == 0
1159 (p15) tbit.z p0,p8 = GR_fpsr,0
1162 (p8) setf.s f8 = r8 // set result to 0x7f7fffff without
1163 // OVERFLOW flag raising
1177 fmerge.s FR_X = f8,f8
1180 .pred.rel "mutex",p14,p15
1183 (p14) fnma.s.s0 f8 = f9,f9,f0 // set I,O and -INF result
1184 mov GR_TAG = 261 // overflow
1188 (p15) fma.s.s0 f8 = f9,f9,f0 // set I,O and +INF result
1189 br.cond.sptk tgammaf_libm_err
1192 // x is negative integer or +/-0
1193 //--------------------------------------------------------------------
1195 tgammaf_singularity:
1198 fmerge.s FR_X = f8,f8
1199 mov GR_TAG = 262 // negative
1203 frcpa.s0 f8,p0 = f0,f0
1204 br.cond.sptk tgammaf_libm_err
1206 // x is negative noninteger with big absolute value
1207 //--------------------------------------------------------------------
1213 tbit.z p6,p7 = GR_Sig,0
1220 .pred.rel "mutex",p6,p7
1223 (p6) fms.s.s0 f8 = f9,f9,f9
1228 (p7) fma.s.s0 f8 = f9,f9,f9
1232 // x for natval, nan, +/-inf or +/-0
1233 //--------------------------------------------------------------------
1238 fclass.m p6,p0 = f8,0x1E1 // Test x for natval, nan, +inf
1243 fclass.m p7,p8 = f8,0x7 // +/-0
1248 fmerge.s FR_X = f8,f8
1253 (p6) fma.s.s0 f8 = f8,f1,f8
1256 .pred.rel "mutex",p7,p8
1258 (p7) mov GR_TAG = 262 // negative
1259 (p7) frcpa.s0 f8,p0 = f1,f8
1265 (p8) br.cond.spnt tgammaf_singularity
1271 alloc r32 = ar.pfs,1,4,4,0
1273 mov GR_Parameter_TAG = GR_TAG
1276 GLOBAL_LIBM_END(tgammaf)
1277 LOCAL_LIBM_ENTRY(__libm_error_region)
1280 add GR_Parameter_Y=-32,sp // Parameter 2 value
1282 .save ar.pfs,GR_SAVE_PFS
1283 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
1287 add sp=-64,sp // Create new stack
1289 mov GR_SAVE_GP=gp // Save gp
1292 stfd [GR_Parameter_Y] = FR_Y,16 // STORE Parameter 2 on stack
1293 add GR_Parameter_X = 16,sp // Parameter 1 address
1294 .save b0, GR_SAVE_B0
1295 mov GR_SAVE_B0=b0 // Save b0
1299 stfd [GR_Parameter_X] = FR_X // STORE Parameter 1 on stack
1300 add GR_Parameter_RESULT = 0,GR_Parameter_Y // Parameter 3 address
1304 stfd [GR_Parameter_Y] = FR_RESULT // STORE Parameter 3 on stack
1305 add GR_Parameter_Y = -16,GR_Parameter_Y
1306 br.call.sptk b0=__libm_error_support# // Call error handling function
1311 add GR_Parameter_RESULT = 48,sp
1314 ldfd f8 = [GR_Parameter_RESULT] // Get return result off stack
1316 add sp = 64,sp // Restore stack pointer
1317 mov b0 = GR_SAVE_B0 // Restore return address
1320 mov gp = GR_SAVE_GP // Restore gp
1321 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
1322 br.ret.sptk b0 // Return
1325 LOCAL_LIBM_END(__libm_error_region)
1326 .type __libm_error_support#,@function
1327 .global __libm_error_support#