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 // 10/12/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: tgamma(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 // tgamma(+inf) = +inf
76 // tgamma(-inf) = QNaN
77 // tgamma(+/-0) = +/-inf
78 // tgamma(x<0, x - integer) = QNaN
79 // tgamma(SNaN) = QNaN
80 // tgamma(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...184 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 [16*n; 16*(n+1)] and
97 // approximate GAMMA(x) by polynomial of 22th degree on each
98 // [16*n; 16*n+1], recursive formula is used to expand GAMMA(x)
99 // to [16*n; 16*n+1]. In other words we need to find n, i and r
100 // such that x = 16 * n + i + r where n and i are integer numbers
101 // and r is fractional part of x. So GAMMA(x) = GAMMA(16*n+i+r) =
102 // = (x-1)*(x-2)*...*(x-i)*GAMMA(x-i) =
103 // = (x-1)*(x-2)*...*(x-i)*GAMMA(16*n+r) ~
104 // ~ (x-1)*(x-2)*...*(x-i)*P22n(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 // P22n(r) = A22*(r^2+C01(n)*R+C00(n))*
120 // *(r^2+C11(n)*R+C10(n))*...*(r^2+CA1(n)*R+CA0(n))
124 // In case when i > 0 we need to multiply P22n(r) by product
125 // R(i)=(x-1)*(x-2)*...*(x-i). To reduce number of fp-instructions
126 // we can calculate R as follow:
127 // R(i) = ((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^2-3*x+2)*(x^2-7*x+12)*...*(x^2+x+2*j*(2*j-1)) =
131 // = (x^2-3*x+2)*(x^2-7*x+12)*...*((x^2+x)+2*j*(2*(j-1)+(1-2*x))) =
132 // = (RA+2*(2-RB))*(RA+4*(4-RB))*...*(RA+2*j*(2*(j-1)+RB))
133 // where j = 1..[i/2], RA = x^2+x, RB = 1-2*x.
135 // Step 4: Reconstruction
136 // ----------------------
137 // Reconstruction is just simple multiplication i.e.
138 // GAMMA(x) = P22n(r)*R(i)
142 // To calculate GAMMA(x) on this interval we do following
143 // if 1 <= x < 1.25 than GAMMA(x) = P15(x-1)
144 // if 1.25 <= x < 1.5 than GAMMA(x) = P15(x-x_min) where
145 // x_min is point of local minimum on [1; 2] interval.
146 // if 1.5 <= x < 2.0 than GAMMA(x) = P15(x-1.5)
148 // if 0 < x < 1 than GAMMA(x) = GAMMA(x+1)/x
150 // Case -(i+1) < x < -i, i = 0...184
151 // ----------------------------------
152 // Here we use the fact that GAMMA(-x) = PI/(x*GAMMA(x)*sin(PI*x)) and
153 // so we need to calculate GAMMA(x), sin(PI*x)/PI. Calculation of
154 // GAMMA(x) is described above.
158 // Note that period of sin(PI*x) is 2 and range reduction for
159 // sin(PI*x) is like to range reduction for GAMMA(x)
160 // i.e r = x - [x] with exception of cases
161 // when r > 0.5 (in such cases r = 1 - (x - [x])).
163 // Step 2: Approximation
164 // ---------------------
165 // To approximate sin(PI*x)/PI = sin(PI*(2*n+r))/PI =
166 // = (-1)^n*sin(PI*r)/PI Taylor series is used.
167 // sin(PI*r)/PI ~ S21(r).
171 // To calculate 1/(x*GAMMA(x)*S21(r)) we use frcpa instruction
172 // with following Newton-Raphson interations.
175 //*********************************************************************
216 GR_Parameter_RESULT = r39
217 GR_Parameter_TAG = r40
222 FR_Y = f1 // tgamma is single argument function
328 //==============================================================
332 LOCAL_OBJECT_START(tgamma_data)
333 data8 0x406573FAE561F648 // overflow boundary (171.624376956302739927196)
334 data8 0x3FDD8B618D5AF8FE // point of local minium (0.461632144968362356785)
337 data8 0xEF0E85C9AE40ABE2,0x00004000 // C01
338 data8 0xCA2049DDB4096DD8,0x00004000 // C11
339 data8 0x99A203B4DC2D1A8C,0x00004000 // C21
340 data8 0xBF5D9D9C0C295570,0x00003FFF // C31
341 data8 0xE8DD037DEB833BAB,0x00003FFD // C41
342 data8 0xB6AE39A2A36AA03A,0x0000BFFE // C51
343 data8 0x804960DC2850277B,0x0000C000 // C61
344 data8 0xD9F3973841C09F80,0x0000C000 // C71
345 data8 0x9C198A676F8A2239,0x0000C001 // C81
346 data8 0xC98B7DAE02BE3226,0x0000C001 // C91
347 data8 0xE9CAF31AC69301BA,0x0000C001 // CA1
348 data8 0xFBBDD58608A0D172,0x00004000 // C00
349 data8 0xFDD0316D1E078301,0x00004000 // C10
350 data8 0x8630B760468C15E4,0x00004001 // C20
351 data8 0x93EDE20E47D9152E,0x00004001 // C30
352 data8 0xA86F3A38C77D6B19,0x00004001 // C40
354 data8 0xF87F757F365EE813,0x00004000 // C01
355 data8 0xECA84FBA92759DA4,0x00004000 // C11
356 data8 0xD4E0A55E07A8E913,0x00004000 // C21
357 data8 0xB0EB45E94C8A5F7B,0x00004000 // C31
358 data8 0x8050D6B4F7C8617D,0x00004000 // C41
359 data8 0x8471B111AA691E5A,0x00003FFF // C51
360 data8 0xADAF462AF96585C9,0x0000BFFC // C61
361 data8 0xD327C7A587A8C32B,0x0000BFFF // C71
362 data8 0xDEF5192B4CF5E0F1,0x0000C000 // C81
363 data8 0xBADD64BB205AEF02,0x0000C001 // C91
364 data8 0x9330A24AA67D6860,0x0000C002 // CA1
365 data8 0xF57EEAF36D8C47BE,0x00004000 // C00
366 data8 0x807092E12A251B38,0x00004001 // C10
367 data8 0x8C458F80DEE7ED1C,0x00004001 // C20
368 data8 0x9F30C731DC77F1A6,0x00004001 // C30
369 data8 0xBAC4E7E099C3A373,0x00004001 // C40
371 data8 0xC3059A415F142DEF,0x00004000 // C01
372 data8 0xB9C1DAC24664587A,0x00004000 // C11
373 data8 0xA7101D910992FFB2,0x00004000 // C21
374 data8 0x8A9522B8E4AA0AB4,0x00004000 // C31
375 data8 0xC76A271E4BA95DCC,0x00003FFF // C41
376 data8 0xC5D6DE2A38DB7FF2,0x00003FFE // C51
377 data8 0xDBA42086997818B2,0x0000BFFC // C61
378 data8 0xB8EDDB1424C1C996,0x0000BFFF // C71
379 data8 0xBF7372FB45524B5D,0x0000C000 // C81
380 data8 0xA03DDE759131580A,0x0000C001 // C91
381 data8 0xFDA6FC4022C1FFE3,0x0000C001 // CA1
382 data8 0x9759ABF797B2533D,0x00004000 // C00
383 data8 0x9FA160C6CF18CEC5,0x00004000 // C10
384 data8 0xB0EFF1E3530E0FCD,0x00004000 // C20
385 data8 0xCCD60D5C470165D1,0x00004000 // C30
386 data8 0xF5E53F6307B0B1C1,0x00004000 // C40
388 data8 0xAABE577FBCE37F5E,0x00004000 // C01
389 data8 0xA274CAEEB5DF7172,0x00004000 // C11
390 data8 0x91B90B6646C1B924,0x00004000 // C21
391 data8 0xF06718519CA256D9,0x00003FFF // C31
392 data8 0xAA9EE181C0E30263,0x00003FFF // C41
393 data8 0xA07BDB5325CB28D2,0x00003FFE // C51
394 data8 0x86C8B873204F9219,0x0000BFFD // C61
395 data8 0xB0192C5D3E4787D6,0x0000BFFF // C71
396 data8 0xB1E0A6263D4C19EF,0x0000C000 // C81
397 data8 0x93BA32A118EAC9AE,0x0000C001 // C91
398 data8 0xE942A39CD9BEE887,0x0000C001 // CA1
399 data8 0xE838B0957B0D3D0D,0x00003FFF // C00
400 data8 0xF60E0F00074FCF34,0x00003FFF // C10
401 data8 0x89869936AE00C2A5,0x00004000 // C20
402 data8 0xA0FE4E8AA611207F,0x00004000 // C30
403 data8 0xC3B1229CFF1DDAFE,0x00004000 // C40
405 data8 0x9C00DDF75CDC6183,0x00004000 // C01
406 data8 0x9446AE9C0F6A833E,0x00004000 // C11
407 data8 0x84ABC5083310B774,0x00004000 // C21
408 data8 0xD9BA3A0977B1ED83,0x00003FFF // C31
409 data8 0x989B18C99411D300,0x00003FFF // C41
410 data8 0x886E66402318CE6F,0x00003FFE // C51
411 data8 0x99028C2468F18F38,0x0000BFFD // C61
412 data8 0xAB72D17DCD40CCE1,0x0000BFFF // C71
413 data8 0xA9D9AC9BE42C2EF9,0x0000C000 // C81
414 data8 0x8C11D983AA177AD2,0x0000C001 // C91
415 data8 0xDC779E981C1F0F06,0x0000C001 // CA1
416 data8 0xC1FD4AC85965E8D6,0x00003FFF // C00
417 data8 0xCE3D2D909D389EC2,0x00003FFF // C10
418 data8 0xE7F79980AD06F5D8,0x00003FFF // C20
419 data8 0x88DD9F73C8680B5D,0x00004000 // C30
420 data8 0xA7D6CB2CB2D46F9D,0x00004000 // C40
422 data8 0x91C7FF4E993430D0,0x00004000 // C01
423 data8 0x8A6E7AB83E45A7E9,0x00004000 // C11
424 data8 0xF72D6382E427BEA9,0x00003FFF // C21
425 data8 0xC9E2E4F9B3B23ED6,0x00003FFF // C31
426 data8 0x8BEFEF56AE05D775,0x00003FFF // C41
427 data8 0xEE9666AB6A185560,0x00003FFD // C51
428 data8 0xA6AFAF5CEFAEE04D,0x0000BFFD // C61
429 data8 0xA877EAFEF1F9C880,0x0000BFFF // C71
430 data8 0xA45BD433048ECA15,0x0000C000 // C81
431 data8 0x86BD1636B774CC2E,0x0000C001 // C91
432 data8 0xD3721BE006E10823,0x0000C001 // CA1
433 data8 0xA97EFABA91854208,0x00003FFF // C00
434 data8 0xB4AF0AEBB3F97737,0x00003FFF // C10
435 data8 0xCC38241936851B0B,0x00003FFF // C20
436 data8 0xF282A6261006EA84,0x00003FFF // C30
437 data8 0x95B8E9DB1BD45BAF,0x00004000 // C40
439 data8 0x8A1FA3171B35A106,0x00004000 // C01
440 data8 0x830D5B8843890F21,0x00004000 // C11
441 data8 0xE98B0F1616677A23,0x00003FFF // C21
442 data8 0xBDF8347F5F67D4EC,0x00003FFF // C31
443 data8 0x825F15DE34EC055D,0x00003FFF // C41
444 data8 0xD4846186B8AAC7BE,0x00003FFD // C51
445 data8 0xB161093AB14919B1,0x0000BFFD // C61
446 data8 0xA65758EEA4800EF4,0x0000BFFF // C71
447 data8 0xA046B67536FA329C,0x0000C000 // C81
448 data8 0x82BBEC1BCB9E9068,0x0000C001 // C91
449 data8 0xCC9DE2B23BA91B0B,0x0000C001 // CA1
450 data8 0x983B16148AF77F94,0x00003FFF // C00
451 data8 0xA2A4D8EE90FEE5DD,0x00003FFF // C10
452 data8 0xB89446FA37FF481C,0x00003FFF // C20
453 data8 0xDC5572648485FB01,0x00003FFF // C30
454 data8 0x88CD5D7DB976129A,0x00004000 // C40
456 data8 0x8417098FD62AC5E3,0x00004000 // C01
457 data8 0xFA7896486B779CBB,0x00003FFF // C11
458 data8 0xDEC98B14AF5EEBD1,0x00003FFF // C21
459 data8 0xB48E153C6BF0B5A3,0x00003FFF // C31
460 data8 0xF597B038BC957582,0x00003FFE // C41
461 data8 0xBFC6F0884A415694,0x00003FFD // C51
462 data8 0xBA075A1392BDB5E5,0x0000BFFD // C61
463 data8 0xA4B79E01B44C7DB4,0x0000BFFF // C71
464 data8 0x9D12FA7711BFAB0F,0x0000C000 // C81
465 data8 0xFF24C47C8E108AB4,0x0000C000 // C91
466 data8 0xC7325EC86562606A,0x0000C001 // CA1
467 data8 0x8B47DCD9E1610938,0x00003FFF // C00
468 data8 0x9518B111B70F88B8,0x00003FFF // C10
469 data8 0xA9CC197206F68682,0x00003FFF // C20
470 data8 0xCB98294CC0D7A6A6,0x00003FFF // C30
471 data8 0xFE09493EA9165181,0x00003FFF // C40
473 data8 0xFE53D03442270D90,0x00003FFF // C01
474 data8 0xF0F857BAEC1993E4,0x00003FFF // C11
475 data8 0xD5FF6D70DBBC2FD3,0x00003FFF // C21
476 data8 0xACDAA5F4988B1074,0x00003FFF // C31
477 data8 0xE92E069F8AD75B54,0x00003FFE // C41
478 data8 0xAEBB64645BD94234,0x00003FFD // C51
479 data8 0xC13746249F39B43C,0x0000BFFD // C61
480 data8 0xA36B74F5B6297A1F,0x0000BFFF // C71
481 data8 0x9A77860DF180F6E5,0x0000C000 // C81
482 data8 0xF9F8457D84410A0C,0x0000C000 // C91
483 data8 0xC2BF44C649EB8597,0x0000C001 // CA1
484 data8 0x81225E7489BCDC0E,0x00003FFF // C00
485 data8 0x8A788A09CE0EED11,0x00003FFF // C10
486 data8 0x9E2E6F86D1B1D89C,0x00003FFF // C20
487 data8 0xBE6866B21CF6CCB5,0x00003FFF // C30
488 data8 0xEE94426EC1486AAE,0x00003FFF // C40
490 data8 0xF6113E09732A6497,0x00003FFF // C01
491 data8 0xE900D45931B04FC8,0x00003FFF // C11
492 data8 0xCE9FD58F745EBA5D,0x00003FFF // C21
493 data8 0xA663A9636C864C86,0x00003FFF // C31
494 data8 0xDEBF5315896CE629,0x00003FFE // C41
495 data8 0xA05FEA415EBD7737,0x00003FFD // C51
496 data8 0xC750F112BD9C4031,0x0000BFFD // C61
497 data8 0xA2593A35C51C6F6C,0x0000BFFF // C71
498 data8 0x9848E1DA7FB40C8C,0x0000C000 // C81
499 data8 0xF59FEE87A5759A4B,0x0000C000 // C91
500 data8 0xBF00203909E45A1D,0x0000C001 // CA1
501 data8 0xF1D8E157200127E5,0x00003FFE // C00
502 data8 0x81DD5397CB08D487,0x00003FFF // C10
503 data8 0x94C1DC271A8B766F,0x00003FFF // C20
504 data8 0xB3AFAF9B5D6EDDCF,0x00003FFF // C30
505 data8 0xE1FB4C57CA81BE1E,0x00003FFF // C40
507 data8 0xEEFFE5122AC72FFD,0x00003FFF // C01
508 data8 0xE22F70BB52AD54B3,0x00003FFF // C11
509 data8 0xC84FF021FE993EEA,0x00003FFF // C21
510 data8 0xA0DA2208EB5B2752,0x00003FFF // C31
511 data8 0xD5CDD2FCF8AD2DF5,0x00003FFE // C41
512 data8 0x940BEC6DCD811A59,0x00003FFD // C51
513 data8 0xCC954EF4FD4EBB81,0x0000BFFD // C61
514 data8 0xA1712E29A8C04554,0x0000BFFF // C71
515 data8 0x966B55DFB243521A,0x0000C000 // C81
516 data8 0xF1E6A2B9CEDD0C4C,0x0000C000 // C91
517 data8 0xBBC87BCC031012DB,0x0000C001 // CA1
518 data8 0xE43974E6D2818583,0x00003FFE // C00
519 data8 0xF5702A516B64C5B7,0x00003FFE // C10
520 data8 0x8CEBCB1B32E19471,0x00003FFF // C20
521 data8 0xAAC10F05BB77E0AF,0x00003FFF // C30
522 data8 0xD776EFCAB205CC58,0x00003FFF // C40
524 data8 0xE8DA614119811E5D,0x00003FFF // C01
525 data8 0xDC415E0288B223D8,0x00003FFF // C11
526 data8 0xC2D2243E44EC970E,0x00003FFF // C21
527 data8 0x9C086664B5307BEA,0x00003FFF // C31
528 data8 0xCE03D7A08B461156,0x00003FFE // C41
529 data8 0x894BE3BAAAB66ADC,0x00003FFD // C51
530 data8 0xD131EDD71A702D4D,0x0000BFFD // C61
531 data8 0xA0A907CDDBE10898,0x0000BFFF // C71
532 data8 0x94CC3CD9C765C808,0x0000C000 // C81
533 data8 0xEEA85F237815FC0D,0x0000C000 // C91
534 data8 0xB8FA04B023E43F91,0x0000C001 // CA1
535 data8 0xD8B2C7D9FCBD7EF9,0x00003FFE // C00
536 data8 0xE9566E93AAE7E38F,0x00003FFE // C10
537 data8 0x8646E78AABEF0255,0x00003FFF // C20
538 data8 0xA32AEDB62E304345,0x00003FFF // C30
539 data8 0xCE83E40280EE7DF0,0x00003FFF // C40
543 data8 0xC44FB47E90584083,0x00004001 // C50
544 data8 0xE863EE77E1C45981,0x00004001 // C60
545 data8 0x8AC15BE238B9D70E,0x00004002 // C70
546 data8 0xA5D94B6592350EF4,0x00004002 // C80
547 data8 0xC379DB3E20A148B3,0x00004002 // C90
548 data8 0xDACA49B73974F6C9,0x00004002 // CA0
549 data8 0x810E496A1AFEC895,0x00003FE1 // An
551 data8 0xE17C0357AAF3F817,0x00004001 // C50
552 data8 0x8BA8804750FBFBFE,0x00004002 // C60
553 data8 0xB18EAB3CB64BEBEE,0x00004002 // C70
554 data8 0xE90AB7015AF1C28F,0x00004002 // C80
555 data8 0xA0AB97CE9E259196,0x00004003 // C90
556 data8 0xF5E0E0A000C2D720,0x00004003 // CA0
557 data8 0xD97F0F87EC791954,0x00004005 // An
559 data8 0x980C293F3696040D,0x00004001 // C50
560 data8 0xC0DBFFBB948A9A4E,0x00004001 // C60
561 data8 0xFAB54625E9A588A2,0x00004001 // C70
562 data8 0xA7E08176D6050FBF,0x00004002 // C80
563 data8 0xEBAAEC4952270A9F,0x00004002 // C90
564 data8 0xB7479CDAD20550FE,0x00004003 // CA0
565 data8 0xAACD45931C3FF634,0x00004054 // An
567 data8 0xF5180F0000419AD5,0x00004000 // C50
568 data8 0x9D507D07BFBB2273,0x00004001 // C60
569 data8 0xCEB53F7A13A383E3,0x00004001 // C70
570 data8 0x8BAFEF9E0A49128F,0x00004002 // C80
571 data8 0xC58EF912D39E228C,0x00004002 // C90
572 data8 0x9A88118422BA208E,0x00004003 // CA0
573 data8 0xBD6C0E2477EC12CB,0x000040AC // An
575 data8 0xD410AC48BF7748DA,0x00004000 // C50
576 data8 0x89399B90AFEBD931,0x00004001 // C60
577 data8 0xB596DF8F77EB8560,0x00004001 // C70
578 data8 0xF6D9445A047FB4A6,0x00004001 // C80
579 data8 0xAF52F0DD65221357,0x00004002 // C90
580 data8 0x8989B45BFC881989,0x00004003 // CA0
581 data8 0xB7FCAE86E6E10D5A,0x0000410B // An
583 data8 0xBE759740E3B5AA84,0x00004000 // C50
584 data8 0xF8037B1B07D27609,0x00004000 // C60
585 data8 0xA4F6F6C7F0977D4F,0x00004001 // C70
586 data8 0xE131960233BF02C4,0x00004001 // C80
587 data8 0xA06DF43D3922BBE2,0x00004002 // C90
588 data8 0xFC266AB27255A360,0x00004002 // CA0
589 data8 0xD9F4B012EDAFEF2F,0x0000416F // An
591 data8 0xAEFC84CDA8E1EAA6,0x00004000 // C50
592 data8 0xE5009110DB5F3C8A,0x00004000 // C60
593 data8 0x98F5F48738E7B232,0x00004001 // C70
594 data8 0xD17EE64E21FFDC6B,0x00004001 // C80
595 data8 0x9596F7A7E36145CC,0x00004002 // C90
596 data8 0xEB64DBE50E125CAF,0x00004002 // CA0
597 data8 0xA090530D79E32D2E,0x000041D8 // An
599 data8 0xA33AEA22A16B2655,0x00004000 // C50
600 data8 0xD682B93BD7D7945C,0x00004000 // C60
601 data8 0x8FC854C6E6E30CC3,0x00004001 // C70
602 data8 0xC5754D828AFFDC7A,0x00004001 // C80
603 data8 0x8D41216B397139C2,0x00004002 // C90
604 data8 0xDE78D746848116E5,0x00004002 // CA0
605 data8 0xB8A297A2DC0630DB,0x00004244 // An
607 data8 0x99EB00F11D95E292,0x00004000 // C50
608 data8 0xCB005CB911EB779A,0x00004000 // C60
609 data8 0x8879AA2FDFF3A37A,0x00004001 // C70
610 data8 0xBBDA538AD40CAC2C,0x00004001 // C80
611 data8 0x8696D849D311B9DE,0x00004002 // C90
612 data8 0xD41E1C041481199F,0x00004002 // CA0
613 data8 0xEBA1A43D34EE61EE,0x000042B3 // An
615 data8 0x924F822578AA9F3D,0x00004000 // C50
616 data8 0xC193FAF9D3B36960,0x00004000 // C60
617 data8 0x827AE3A6B68ED0CA,0x00004001 // C70
618 data8 0xB3F52A27EED23F0B,0x00004001 // C80
619 data8 0x811A079FB3C94D79,0x00004002 // C90
620 data8 0xCB94415470B6F8D2,0x00004002 // CA0
621 data8 0x80A0260DCB3EC9AC,0x00004326 // An
623 data8 0x8BF24091E88B331D,0x00004000 // C50
624 data8 0xB9ADE01187E65201,0x00004000 // C60
625 data8 0xFAE4508F6E7625FE,0x00004000 // C70
626 data8 0xAD516668AD6D7367,0x00004001 // C80
627 data8 0xF8F5FF171154F637,0x00004001 // C90
628 data8 0xC461321268990C82,0x00004002 // CA0
629 data8 0xC3B693F344B0E6FE,0x0000439A // An
632 data8 0x868545EB42A258ED,0x00004000 // C50
633 data8 0xB2EF04ACE8BA0E6E,0x00004000 // C60
634 data8 0xF247D22C22E69230,0x00004000 // C70
635 data8 0xA7A1AB93E3981A90,0x00004001 // C80
636 data8 0xF10951733E2C697F,0x00004001 // C90
637 data8 0xBE3359BFAD128322,0x00004002 // CA0
638 data8 0x8000000000000000,0x00003fff
640 //[160; 161] for negatives
641 data8 0xA76DBD55B2E32D71,0x00003C63 // 1/An
644 data8 0xBCBC4342112F52A2,0x00003FDE // S21
645 data8 0xFAFCECB86536F655,0x0000BFE3 // S19
646 data8 0x87E4C97F9CF09B92,0x00003FE9 // S17
647 data8 0xEA124C68E704C5CB,0x0000BFED // S15
648 data8 0x9BA38CFD59C8AA1D,0x00003FF2 // S13
649 data8 0x99C0B552303D5B21,0x0000BFF6 // S11
651 //[176; 177] for negatives
652 data8 0xBA5D5869211696FF,0x00003BEC // 1/An
655 data8 0xD63402E79A853175,0x00003FF9 // S9
656 data8 0xC354723906DB36BA,0x0000BFFC // S7
657 data8 0xCFCE5A015E236291,0x00003FFE // S5
658 data8 0xD28D3312983E9918,0x0000BFFF // S3
662 data8 0xA405530B067ECD3C,0x0000BFFC // A15
663 data8 0xF5B5413F95E1C282,0x00003FFD // A14
664 data8 0xC4DED71C782F76C8,0x0000BFFE // A13
665 data8 0xECF7DDDFD27C9223,0x00003FFE // A12
666 data8 0xFB73D31793068463,0x0000BFFE // A11
667 data8 0xFF173B7E66FD1D61,0x00003FFE // A10
668 data8 0xFFA5EF3959089E94,0x0000BFFE // A9
669 data8 0xFF8153BD42E71A4F,0x00003FFE // A8
670 data8 0xFEF9CAEE2CB5B533,0x0000BFFE // A7
671 data8 0xFE3F02E5EDB6811E,0x00003FFE // A6
672 data8 0xFB64074CED2658FB,0x0000BFFE // A5
673 data8 0xFB52882A095B18A4,0x00003FFE // A4
674 data8 0xE8508C7990A0DAC0,0x0000BFFE // A3
675 data8 0xFD32C611D8A881D0,0x00003FFE // A2
676 data8 0x93C467E37DB0C536,0x0000BFFE // A1
677 data8 0x8000000000000000,0x00003FFF // A0
680 data8 0xD038092400619677,0x0000BFF7 // A15
681 data8 0xEA6DE925E6EB8C8F,0x00003FF3 // A14
682 data8 0xC53F83645D4597FC,0x0000BFF7 // A13
683 data8 0xE366DB2FB27B7ECD,0x00003FF7 // A12
684 data8 0xAC8FD5E11F6EEAD8,0x0000BFF8 // A11
685 data8 0xFB14010FB3697785,0x00003FF8 // A10
686 data8 0xB6F91CB5C371177B,0x0000BFF9 // A9
687 data8 0x85A262C6F8FEEF71,0x00003FFA // A8
688 data8 0xC038E6E3261568F9,0x0000BFFA // A7
689 data8 0x8F4BDE8883232364,0x00003FFB // A6
690 data8 0xBCFBBD5786537E9A,0x0000BFFB // A5
691 data8 0xA4C08BAF0A559479,0x00003FFC // A4
692 data8 0x85D74FA063E81476,0x0000BFFC // A3
693 data8 0xDB629FB9BBDC1C4E,0x00003FFD // A2
694 data8 0xF4F8FBC7C0C9D317,0x00003FC6 // A1
695 data8 0xE2B6E4153A57746C,0x00003FFE // A0
698 data8 0x9533F9D3723B448C,0x0000BFF2 // A15
699 data8 0xF1F75D3C561CBBAF,0x00003FF5 // A14
700 data8 0xBA55A9A1FC883523,0x0000BFF8 // A13
701 data8 0xB5D5E9E5104FA995,0x00003FFA // A12
702 data8 0xFD84F35B70CD9AE2,0x0000BFFB // A11
703 data8 0x87445235F4688CC5,0x00003FFD // A10
704 data8 0xE7F236EBFB9F774E,0x0000BFFD // A9
705 data8 0xA6605F2721F787CE,0x00003FFE // A8
706 data8 0xCF579312AD7EAD72,0x0000BFFE // A7
707 data8 0xE96254A2407A5EAC,0x00003FFE // A6
708 data8 0xF41312A8572ED346,0x0000BFFE // A5
709 data8 0xF9535027C1B1F795,0x00003FFE // A4
710 data8 0xE7E82D0C613A8DE4,0x0000BFFE // A3
711 data8 0xFD23CD9741B460B8,0x00003FFE // A2
712 data8 0x93C30FD9781DBA88,0x0000BFFE // A1
713 data8 0xFFFFF1781FDBEE84,0x00003FFE // A0
714 LOCAL_OBJECT_END(tgamma_data)
717 //==============================================================
719 //==============================================================
722 GLOBAL_LIBM_ENTRY(tgamma)
724 getf.exp GR_Sign_Exp = f8
725 fma.s1 FR_1m2X = f8,f1,f8 // 2x
726 addl GR_ad_Data = @ltoff(tgamma_data), gp
729 mov GR_ExpOf8 = 0x10002 // 8
730 fcvt.fx.trunc.s1 FR_iXt = f8 // [x]
731 mov GR_ExpOf05 = 0xFFFE // 0.5
735 fma.s1 FR_2 = f1,f1,f1 // 2
736 mov GR_Addr_Mask1 = 0x780
739 setf.exp FR_8 = GR_ExpOf8
740 movl GR_10 = 0x4024000000000000
743 ld8 GR_ad_Data = [GR_ad_Data]
744 fcmp.lt.s1 p14,p15 = f8,f0
745 tbit.z p12,p13 = GR_Sign_Exp,0x10 // p13 if x >= 2
748 and GR_Bit2 = 4,GR_Sign_Exp
749 movl GR_12 = 0x4028000000000000
753 fma.s1 FR_r02 = f8,f1,f0
754 extr.u GR_Tbl_Offs = GR_Sig,58,6
757 (p12) mov GR_Addr_Mask1 = r0
758 fma.s1 FR_NormX = f8,f1,f0
759 cmp.ne p8,p0 = GR_Bit2,r0
762 (p8) shladd GR_Tbl_Offs = GR_Tbl_Offs,4,r0
763 fclass.m p10,p0 = f8,0x1E7 // Test x for NaTVal, NaN, +/-0, +/-INF
764 tbit.nz p11,p0 = GR_Sign_Exp,1
767 add GR_Addr_Mask2 = GR_Addr_Mask1,GR_Addr_Mask1
768 movl GR_14 = 0x402C000000000000
770 .pred.rel "mutex",p14,p15
773 (p14) fma.s1 FR_1m2X = f1,f1,FR_1m2X // RB=1-2|x|
774 tbit.nz p8,p9 = GR_Sign_Exp,0
777 ldfpd FR_OvfBound,FR_Xmin = [GR_ad_Data],16
778 (p15) fms.s1 FR_1m2X = f1,f1,FR_1m2X // RB=1-2|x|
779 (p11) shladd GR_Tbl_Offs = GR_Tbl_Offs,2,r0
781 .pred.rel "mutex",p9,p8
784 fma.s1 FR_4 = FR_2,FR_2,f0
785 (p8) and GR_Tbl_Offs = GR_Tbl_Offs, GR_Addr_Mask1
788 setf.exp FR_05 = GR_ExpOf05
789 fma.s1 FR_6 = FR_2,FR_2,FR_2
790 (p9) and GR_Tbl_Offs = GR_Tbl_Offs, GR_Addr_Mask2
792 .pred.rel "mutex",p9,p8
794 (p8) shladd GR_ad_Co = GR_Tbl_Offs,1,GR_ad_Data
795 fcvt.xf FR_Xt = FR_iXt // [x]
796 (p15) tbit.z.unc p11,p0 = GR_Sign_Exp,0x10 // p11 if 0 < x < 2
799 (p9) add GR_ad_Co = GR_ad_Data,GR_Tbl_Offs
800 fma.s1 FR_5 = FR_2,FR_2,f1
801 (p15) cmp.lt.unc p7,p6 = GR_ExpOf05,GR_Sign_Exp // p7 if 0 < x < 1
804 add GR_ad_Ce = 16,GR_ad_Co
805 (p11) frcpa.s1 FR_Rcp0,p0 = f1,f8
806 sub GR_Tbl_Offs = GR_ad_Co,GR_ad_Data
809 ldfe FR_C01 = [GR_ad_Co],32
810 (p7) fms.s1 FR_r02 = FR_r02,f1,f1
811 // jump if x is NaTVal, NaN, +/-0, +/-INF
812 (p10) br.cond.spnt tgamma_spec
814 .pred.rel "mutex",p14,p15
816 ldfe FR_C11 = [GR_ad_Ce],32
817 (p14) fms.s1 FR_X2pX = f8,f8,f8 // RA=x^2+|x|
818 shr GR_Tbl_Ind = GR_Tbl_Offs,8
821 ldfe FR_C21 = [GR_ad_Co],32
822 (p15) fma.s1 FR_X2pX = f8,f8,f8 // RA=x^2+x
824 (p11) br.cond.spnt tgamma_from_0_to_2
827 ldfe FR_C31 = [GR_ad_Ce],32
828 fma.s1 FR_Rq2 = FR_2,f1,FR_1m2X // 2 + B
829 cmp.ltu p7,p0=0xB,GR_Tbl_Ind
832 ldfe FR_C41 = [GR_ad_Co],32
833 fma.s1 FR_Rq3 = FR_2,FR_2,FR_1m2X // 4 + B
834 // jump if GR_Tbl_Ind > 11, i.e |x| is more than 192
835 (p7) br.cond.spnt tgamma_spec_res
838 ldfe FR_C51 = [GR_ad_Ce],32
839 fma.s1 FR_Rq4 = FR_6,f1,FR_1m2X // 6 + B
840 shr GR_Tbl_Offs = GR_Tbl_Offs,1
843 ldfe FR_C61 = [GR_ad_Co],32
844 fma.s1 FR_Rq5 = FR_4,FR_2,FR_1m2X // 8 + B
848 ldfe FR_C71 = [GR_ad_Ce],32
849 (p14) fms.s1 FR_r = FR_Xt,f1,f8 // r = |x| - [|x|]
850 shr GR_Tbl_16xInd = GR_Tbl_Offs,3
853 ldfe FR_C81 = [GR_ad_Co],32
854 (p15) fms.s1 FR_r = f8,f1,FR_Xt // r = x - [x]
855 add GR_ad_Data = 0xC00,GR_ad_Data
858 ldfe FR_C91 = [GR_ad_Ce],32
859 fma.s1 FR_Rq6 = FR_5,FR_2,FR_1m2X // 10 + B
860 (p14) mov GR_0x30033 = 0x30033
863 ldfe FR_CA1 = [GR_ad_Co],32
864 fma.s1 FR_Rq7 = FR_6,FR_2,FR_1m2X // 12 + B
865 sub GR_Tbl_Offs = GR_Tbl_Offs,GR_Tbl_16xInd
868 ldfe FR_C00 = [GR_ad_Ce],32
869 fma.s1 FR_Rq1 = FR_Rq1,FR_2,FR_X2pX // (x-1)*(x-2)
870 (p13) cmp.eq.unc p8,p0 = r0,GR_Tbl_16xInd // index is 0 i.e. arg from [2;16)
873 ldfe FR_C10 = [GR_ad_Co],32
874 (p14) fms.s1 FR_AbsX = f0,f0,FR_NormX // absolute value of argument
875 add GR_ad_Co7 = GR_ad_Data,GR_Tbl_Offs
878 ldfe FR_C20 = [GR_ad_Ce],32
879 fma.s1 FR_Rq2 = FR_Rq2,FR_4,FR_X2pX // (x-3)*(x-4)
880 add GR_ad_Ce7 = 16,GR_ad_Co7
883 ldfe FR_C30 = [GR_ad_Co],32
884 fma.s1 FR_Rq3 = FR_Rq3,FR_6,FR_X2pX // (x-5)*(x-6)
888 ldfe FR_C40 = [GR_ad_Ce],32
889 fma.s1 FR_Rq4 = FR_Rq4,FR_8,FR_X2pX // (x-7)*(x-8)
890 (p14) cmp.leu.unc p7,p0 = GR_0x30033,GR_Sign_Exp
893 ldfe FR_C50 = [GR_ad_Co7],32
894 fma.s1 FR_Rq5 = FR_Rq5,FR_10,FR_X2pX // (x-9)*(x-10)
895 // jump if x is less or equal to -2^52, i.e. x is big negative integer
896 (p7) br.cond.spnt tgamma_singularity
899 ldfe FR_C60 = [GR_ad_Ce7],32
900 fma.s1 FR_C01 = FR_C01,f1,FR_r
901 add GR_ad_Ce = 0x560,GR_ad_Data
904 ldfe FR_C70 = [GR_ad_Co7],32
905 fma.s1 FR_rs = f0,f0,FR_r // reduced arg for sin(pi*x)
906 add GR_ad_Co = 0x550,GR_ad_Data
909 ldfe FR_C80 = [GR_ad_Ce7],32
910 fma.s1 FR_C11 = FR_C11,f1,FR_r
914 ldfe FR_C90 = [GR_ad_Co7],32
915 fma.s1 FR_C21 = FR_C21,f1,FR_r
918 .pred.rel "mutex",p12,p13
920 (p13) getf.sig GR_iSig = FR_iXt
921 fcmp.lt.s1 p11,p0 = FR_05,FR_r
926 fma.s1 FR_Rq6 = FR_Rq6,FR_12,FR_X2pX // (x-11)*(x-12)
930 ldfe FR_CA0 = [GR_ad_Ce7],32
931 fma.s1 FR_C31 = FR_C31,f1,FR_r
932 (p12) mov GR_iSig = 0
935 ldfe FR_An = [GR_ad_Co7],0x80
936 fma.s1 FR_C41 = FR_C41,f1,FR_r
940 (p14) getf.sig GR_Sig = FR_r
941 fma.s1 FR_C51 = FR_C51,f1,FR_r
942 (p14) sub GR_iSig = r0,GR_iSig
945 ldfe FR_S21 = [GR_ad_Co],32
946 fma.s1 FR_C61 = FR_C61,f1,FR_r
950 ldfe FR_S19 = [GR_ad_Ce],32
951 fma.s1 FR_C71 = FR_C71,f1,FR_r
952 and GR_SigRqLin = 0xF,GR_iSig
955 ldfe FR_S17 = [GR_ad_Co],32
956 fma.s1 FR_C81 = FR_C81,f1,FR_r
960 (p14) ldfe FR_InvAn = [GR_ad_Co7]
961 fma.s1 FR_C91 = FR_C91,f1,FR_r
962 // if significand of r is 0 tnan argument is negative integer
963 (p14) cmp.eq.unc p12,p0 = r0,GR_Sig
966 (p8) sub GR_SigRqLin = GR_SigRqLin,GR_2 // subtract 2 if 2 <= x < 16
967 fma.s1 FR_CA1 = FR_CA1,f1,FR_r
968 // jump if x is negative integer such that -2^52 < x < -185
969 (p12) br.cond.spnt tgamma_singularity
972 setf.sig FR_Xt = GR_SigRqLin
973 (p11) fms.s1 FR_rs = f1,f1,FR_r
974 (p14) cmp.ltu.unc p7,p0 = GR_185,GR_iSig
977 ldfe FR_S15 = [GR_ad_Ce],32
978 fma.s1 FR_Rq7 = FR_Rq7,FR_14,FR_X2pX // (x-13)*(x-14)
979 // jump if x is noninteger such that -2^52 < x < -185
980 (p7) br.cond.spnt tgamma_underflow
983 ldfe FR_S13 = [GR_ad_Co],48
984 fma.s1 FR_C01 = FR_C01,FR_r,FR_C00
985 and GR_Sig2 = 0xE,GR_SigRqLin
988 ldfe FR_S11 = [GR_ad_Ce],48
989 fma.s1 FR_C11 = FR_C11,FR_r,FR_C10
993 ldfe FR_S9 = [GR_ad_Co],32
994 fma.s1 FR_C21 = FR_C21,FR_r,FR_C20
995 // should we mul by polynomial of recursion?
996 cmp.eq p13,p12 = r0,GR_SigRqLin
999 ldfe FR_S7 = [GR_ad_Ce],32
1000 fma.s1 FR_C31 = FR_C31,FR_r,FR_C30
1004 ldfe FR_S5 = [GR_ad_Co],32
1005 fma.s1 FR_C41 = FR_C41,FR_r,FR_C40
1009 ldfe FR_S3 = [GR_ad_Ce],32
1010 fma.s1 FR_C51 = FR_C51,FR_r,FR_C50
1015 fma.s1 FR_C61 = FR_C61,FR_r,FR_C60
1020 fma.s1 FR_C71 = FR_C71,FR_r,FR_C70
1025 fma.s1 FR_C81 = FR_C81,FR_r,FR_C80
1030 fma.s1 FR_C91 = FR_C91,FR_r,FR_C90
1035 fma.s1 FR_CA1 = FR_CA1,FR_r,FR_CA0
1040 fma.s1 FR_C01 = FR_C01,FR_C11,f0
1045 fma.s1 FR_C21 = FR_C21,FR_C31,f0
1050 fma.s1 FR_rs2 = FR_rs,FR_rs,f0
1051 (p12) cmp.lt.unc p7,p0 = 2,GR_Sig2 // should mul by FR_Rq2?
1055 fma.s1 FR_C41 = FR_C41,FR_C51,f0
1060 (p7) fma.s1 FR_Rq1 = FR_Rq1,FR_Rq2,f0
1061 (p12) cmp.lt.unc p9,p0 = 6,GR_Sig2 // should mul by FR_Rq4?
1065 fma.s1 FR_C61 = FR_C61,FR_C71,f0
1066 (p15) cmp.eq p11,p0 = r0,r0
1070 (p9) fma.s1 FR_Rq3 = FR_Rq3,FR_Rq4,f0
1071 (p12) cmp.lt.unc p8,p0 = 10,GR_Sig2 // should mul by FR_Rq6?
1075 fma.s1 FR_C81 = FR_C81,FR_C91,f0
1080 (p8) fma.s1 FR_Rq5 = FR_Rq5,FR_Rq6,f0
1081 (p14) cmp.ltu p0,p11 = 0x9,GR_Tbl_Ind
1085 fcvt.xf FR_RqLin = FR_Xt
1090 (p11) fma.s1 FR_CA1 = FR_CA1,FR_An,f0
1095 fma.s1 FR_S21 = FR_S21,FR_rs2,FR_S19
1100 fma.s1 FR_S17 = FR_S17,FR_rs2,FR_S15
1105 fma.s1 FR_C01 = FR_C01,FR_C21,f0
1110 fma.s1 FR_rs4 = FR_rs2,FR_rs2,f0
1111 (p12) cmp.lt.unc p8,p0 = 4,GR_Sig2 // should mul by FR_Rq3?
1115 (p8) fma.s1 FR_Rq1 = FR_Rq1,FR_Rq3,f0
1120 fma.s1 FR_S13 = FR_S13,FR_rs2,FR_S11
1121 (p12) cmp.lt.unc p9,p0 = 12,GR_Sig2 // should mul by FR_Rq7?
1125 fma.s1 FR_C41 = FR_C41,FR_C61,f0
1130 (p9) fma.s1 FR_Rq5 = FR_Rq5,FR_Rq7,f0
1135 fma.s1 FR_C81 = FR_C81,FR_CA1,f0
1140 fma.s1 FR_S9 = FR_S9,FR_rs2,FR_S7
1145 fma.s1 FR_S5 = FR_S5,FR_rs2,FR_S3
1150 fma.s1 FR_rs3 = FR_rs2,FR_rs,f0
1151 (p12) tbit.nz.unc p6,p0 = GR_SigRqLin,0
1155 fma.s1 FR_rs8 = FR_rs4,FR_rs4,f0
1160 fma.s1 FR_S21 = FR_S21,FR_rs4,FR_S17
1161 mov GR_ExpOf1 = 0x2FFFF
1165 (p6) fms.s1 FR_RqLin = FR_AbsX,f1,FR_RqLin
1166 (p12) cmp.lt.unc p8,p0 = 8,GR_Sig2 // should mul by FR_Rq5?
1170 fma.s1 FR_C01 = FR_C01,FR_C41,f0
1175 (p8) fma.s1 FR_Rq1 = FR_Rq1,FR_Rq5,f0
1176 (p14) cmp.gtu.unc p7,p0 = GR_Sign_Exp,GR_ExpOf1
1180 fma.s1 FR_S13 = FR_S13,FR_rs4,FR_S9
1185 (p7) fma.s1 FR_C81 = FR_C81,FR_AbsX,f0
1190 (p14) fma.s1 FR_AbsXp1 = f1,f1,FR_AbsX // |x|+1
1195 (p15) fcmp.lt.unc.s1 p0,p10 = FR_AbsX,FR_OvfBound // x >= overflow_boundary
1200 fma.s1 FR_rs7 = FR_rs4,FR_rs3,f0
1205 fma.s1 FR_S5 = FR_S5,FR_rs3,FR_rs
1209 (p14) cmp.lt p13,p0 = r0,r0 // set p13 to 0 if x < 0
1210 (p12) cmp.eq.unc p8,p9 = 1,GR_SigRqLin
1211 (p10) br.cond.spnt tgamma_spec_res
1214 getf.sig GR_Sig = FR_iXt
1215 (p6) fma.s1 FR_Rq1 = FR_Rq1,FR_RqLin,f0
1216 // should we mul by polynomial of recursion?
1217 (p15) cmp.eq.unc p0,p11 = r0,GR_SigRqLin
1221 fma.s1 FR_GAMMA = FR_C01,FR_C81,f0
1222 (p11) br.cond.spnt tgamma_positives
1226 fma.s1 FR_S21 = FR_S21,FR_rs8,FR_S13
1231 (p13) fma.d.s0 f8 = FR_C01,FR_C81,f0
1232 (p13) br.ret.spnt b0
1234 .pred.rel "mutex",p8,p9
1237 (p9) fma.s1 FR_GAMMA = FR_GAMMA,FR_Rq1,f0
1238 tbit.z p6,p7 = GR_Sig,0 // p6 if sin<0, p7 if sin>0
1242 (p8) fma.s1 FR_GAMMA = FR_GAMMA,FR_RqLin,f0
1247 fma.s1 FR_S21 = FR_S21,FR_rs7,FR_S5
1250 .pred.rel "mutex",p6,p7
1253 (p6) fnma.s1 FR_GAMMA = FR_GAMMA,FR_S21,f0
1258 (p7) fma.s1 FR_GAMMA = FR_GAMMA,FR_S21,f0
1263 frcpa.s1 FR_Rcp0,p0 = f1,FR_GAMMA
1264 cmp.ltu p13,p0 = GR_Sign_Exp,GR_ExpOf1
1266 // NR method: ineration #1
1268 (p13) getf.exp GR_Sign_Exp = FR_AbsX
1269 fnma.s1 FR_Rcp1 = FR_Rcp0,FR_GAMMA,f1 // t = 1 - r0*x
1270 (p13) shl GR_Sig2 = GR_Sig2,63
1273 (p13) getf.sig GR_Sig = FR_AbsX
1275 (p13) mov GR_NzOvfBound = 0xFBFF
1278 (p13) cmp.ltu.unc p8,p0 = GR_Sign_Exp,GR_NzOvfBound // p8 <- overflow
1280 (p13) cmp.eq.unc p9,p0 = GR_Sign_Exp,GR_NzOvfBound
1284 (p13) fma.d.s0 FR_X = f1,f1,f8 // set deno & inexact flags
1285 (p8) br.cond.spnt tgamma_ovf_near_0 //tgamma_neg_overflow
1289 (p9) cmp.eq.unc p8,p0 = GR_Sig,GR_Sig2
1290 (p8) br.cond.spnt tgamma_ovf_near_0_boundary //tgamma_neg_overflow
1294 fma.s1 FR_Rcp1 = FR_Rcp0,FR_Rcp1,FR_Rcp0
1297 // NR method: ineration #2
1300 fnma.s1 FR_Rcp2 = FR_Rcp1,FR_GAMMA,f1 // t = 1 - r1*x
1305 fma.s1 FR_Rcp2 = FR_Rcp1,FR_Rcp2,FR_Rcp1
1308 // NR method: ineration #3
1311 fnma.s1 FR_Rcp3 = FR_Rcp2,FR_GAMMA,f1 // t = 1 - r2*x
1316 (p13) fma.s1 FR_Rcp2 = FR_Rcp2,FR_AbsXp1,f0
1317 (p14) cmp.ltu p10,p11 = 0x9,GR_Tbl_Ind
1319 .pred.rel "mutex",p10,p11
1322 (p10) fma.s1 FR_GAMMA = FR_Rcp2,FR_Rcp3,FR_Rcp2
1327 (p11) fma.d.s0 f8 = FR_Rcp2,FR_Rcp3,FR_Rcp2
1332 (p10) fma.d.s0 f8 = FR_GAMMA,FR_InvAn,f0
1338 //--------------------------------------------------------------------
1341 .pred.rel "mutex",p8,p9
1344 (p9) fma.d.s0 f8 = FR_GAMMA,FR_Rq1,f0
1349 (p8) fma.d.s0 f8 = FR_GAMMA,FR_RqLin,f0
1353 // here if 0 < x < 1
1354 //--------------------------------------------------------------------
1358 getf.exp GR_Sign_Exp = FR_r02
1359 fms.s1 FR_r = FR_r02,f1,FR_Xmin
1360 mov GR_ExpOf025 = 0xFFFD
1363 add GR_ad_Co = 0x1200,GR_ad_Data
1364 (p6) fnma.s1 FR_Rcp1 = FR_Rcp0,FR_NormX,f1 // t = 1 - r0*x
1365 (p6) mov GR_Sig2 = 1
1368 (p6) getf.sig GR_Sig = FR_NormX
1370 (p6) shl GR_Sig2 = GR_Sig2,63
1373 add GR_ad_Ce = 0x1210,GR_ad_Data
1375 (p6) mov GR_NzOvfBound = 0xFBFF
1378 cmp.eq p8,p0 = GR_Sign_Exp,GR_ExpOf05 // r02 >= 1/2
1380 cmp.eq p9,p10 = GR_Sign_Exp,GR_ExpOf025 // r02 >= 1/4
1383 (p6) cmp.ltu.unc p11,p0 = GR_Sign_Exp,GR_NzOvfBound // p11 <- overflow
1385 (p6) cmp.eq.unc p12,p0 = GR_Sign_Exp,GR_NzOvfBound
1387 .pred.rel "mutex",p8,p9
1389 (p8) add GR_ad_Co = 0x200,GR_ad_Co
1390 (p6) fma.d.s0 FR_X = f1,f1,f8 // set deno & inexact flags
1391 (p9) add GR_ad_Co = 0x100,GR_ad_Co
1394 (p8) add GR_ad_Ce = 0x200,GR_ad_Ce
1395 (p9) add GR_ad_Ce = 0x100,GR_ad_Ce
1396 (p11) br.cond.spnt tgamma_ovf_near_0 //tgamma_spec_res
1399 ldfe FR_A15 = [GR_ad_Co],32
1401 (p12) cmp.eq.unc p13,p0 = GR_Sig,GR_Sig2
1404 ldfe FR_A14 = [GR_ad_Ce],32
1406 (p13) br.cond.spnt tgamma_ovf_near_0_boundary //tgamma_spec_res
1409 ldfe FR_A13 = [GR_ad_Co],32
1414 ldfe FR_A12 = [GR_ad_Ce],32
1418 .pred.rel "mutex",p9,p10
1420 ldfe FR_A11 = [GR_ad_Co],32
1421 (p10) fma.s1 FR_r2 = FR_r02,FR_r02,f0
1425 ldfe FR_A10 = [GR_ad_Ce],32
1426 (p9) fma.s1 FR_r2 = FR_r,FR_r,f0
1430 ldfe FR_A9 = [GR_ad_Co],32
1431 (p6) fma.s1 FR_Rcp1 = FR_Rcp0,FR_Rcp1,FR_Rcp0
1435 ldfe FR_A8 = [GR_ad_Ce],32
1436 (p10) fma.s1 FR_r = f0,f0,FR_r02
1440 ldfe FR_A7 = [GR_ad_Co],32
1445 ldfe FR_A6 = [GR_ad_Ce],32
1450 ldfe FR_A5 = [GR_ad_Co],32
1455 ldfe FR_A4 = [GR_ad_Ce],32
1460 ldfe FR_A3 = [GR_ad_Co],32
1465 ldfe FR_A2 = [GR_ad_Ce],32
1470 ldfe FR_A1 = [GR_ad_Co],32
1471 fma.s1 FR_r4 = FR_r2,FR_r2,f0
1475 ldfe FR_A0 = [GR_ad_Ce],32
1481 (p6) fnma.s1 FR_Rcp2 = FR_Rcp1,FR_NormX,f1 // t = 1 - r1*x
1486 fma.s1 FR_A15 = FR_A15,FR_r,FR_A14
1491 fma.s1 FR_A11 = FR_A11,FR_r,FR_A10
1496 fma.s1 FR_r8 = FR_r4,FR_r4,f0
1501 (p6) fma.s1 FR_Rcp2 = FR_Rcp1,FR_Rcp2,FR_Rcp1
1506 fma.s1 FR_A7 = FR_A7,FR_r,FR_A6
1511 fma.s1 FR_A3 = FR_A3,FR_r,FR_A2
1516 fma.s1 FR_A15 = FR_A15,FR_r,FR_A13
1521 fma.s1 FR_A11 = FR_A11,FR_r,FR_A9
1526 (p6) fnma.s1 FR_Rcp3 = FR_Rcp2,FR_NormX,f1 // t = 1 - r1*x
1531 fma.s1 FR_A7 = FR_A7,FR_r,FR_A5
1536 fma.s1 FR_A3 = FR_A3,FR_r,FR_A1
1541 fma.s1 FR_A15 = FR_A15,FR_r,FR_A12
1546 fma.s1 FR_A11 = FR_A11,FR_r,FR_A8
1551 (p6) fma.s1 FR_Rcp3 = FR_Rcp2,FR_Rcp3,FR_Rcp2
1556 fma.s1 FR_A7 = FR_A7,FR_r,FR_A4
1561 fma.s1 FR_A3 = FR_A3,FR_r,FR_A0
1566 fma.s1 FR_A15 = FR_A15,FR_r4,FR_A11
1571 fma.s1 FR_A7 = FR_A7,FR_r4,FR_A3
1574 .pred.rel "mutex",p6,p7
1577 (p6) fma.s1 FR_A15 = FR_A15,FR_r8,FR_A7
1582 (p7) fma.d.s0 f8 = FR_A15,FR_r8,FR_A7
1587 (p6) fma.d.s0 f8 = FR_A15,FR_Rcp3,f0
1592 //--------------------------------------------------------------------
1594 tgamma_ovf_near_0_boundary:
1595 .pred.rel "mutex",p14,p15
1597 mov GR_fpsr = ar.fpsr
1599 (p15) mov r8 = 0x7ff
1604 (p14) mov r8 = 0xfff
1614 extr.u GR_fpsr = GR_fpsr,10,2 // rounding mode
1616 .pred.rel "mutex",p14,p15
1618 // set p8 to 0 in case of overflow and to 1 otherwise
1619 // for negative arg:
1620 // no overflow if rounding mode either Z or +Inf, i.e.
1622 (p14) cmp.lt p8,p0 = 1,GR_fpsr
1624 // for positive arg:
1625 // no overflow if rounding mode either Z or -Inf, i.e.
1626 // (GR_fpsr & 1) == 0
1627 (p15) tbit.z p0,p8 = GR_fpsr,0
1630 (p8) setf.d f8 = r8 // set result to 0x7fefffffffffffff without
1631 // OVERFLOW flag raising
1644 fmerge.s FR_X = f8,f8
1645 mov GR_TAG = 258 // overflow
1647 .pred.rel "mutex",p14,p15
1650 (p15) fma.d.s0 f8 = f9,f9,f0 // Set I,O and +INF result
1655 (p14) fnma.d.s0 f8 = f9,f9,f0 // Set I,O and -INF result
1656 br.cond.sptk tgamma_libm_err
1658 // overflow or absolute value of x is too big
1659 //--------------------------------------------------------------------
1663 mov GR_0x30033 = 0x30033
1664 (p14) fcmp.eq.unc.s1 p10,p11 = f8,FR_Xt
1665 (p15) mov r8 = 0x1FFFE
1668 (p15) setf.exp f9 = r8
1673 (p11) cmp.ltu.unc p7,p8 = GR_0x30033,GR_Sign_Exp
1675 (p10) br.cond.spnt tgamma_singularity
1677 .pred.rel "mutex",p7,p8
1680 (p7) br.cond.spnt tgamma_singularity
1681 (p8) br.cond.spnt tgamma_underflow
1685 fmerge.s FR_X = f8,f8
1686 mov GR_TAG = 258 // overflow
1690 (p15) fma.d.s0 f8 = f9,f9,f0 // Set I,O and +INF result
1691 br.cond.sptk tgamma_libm_err
1694 // x is negative integer or +/-0
1695 //--------------------------------------------------------------------
1700 fmerge.s FR_X = f8,f8
1701 mov GR_TAG = 259 // negative
1705 frcpa.s0 f8,p0 = f0,f0
1706 br.cond.sptk tgamma_libm_err
1708 // x is negative noninteger with big absolute value
1709 //--------------------------------------------------------------------
1713 getf.sig GR_Sig = FR_iXt
1725 tbit.z p6,p7 = GR_Sig,0
1727 .pred.rel "mutex",p6,p7
1730 (p6) fms.d.s0 f8 = f9,f9,f9
1735 (p7) fma.d.s0 f8 = f9,f9,f9
1739 // x for natval, nan, +/-inf or +/-0
1740 //--------------------------------------------------------------------
1745 fclass.m p6,p0 = f8,0x1E1 // Test x for natval, nan, +inf
1750 fclass.m p7,p8 = f8,0x7 // +/-0
1755 fmerge.s FR_X = f8,f8
1760 (p6) fma.d.s0 f8 = f8,f1,f8
1763 .pred.rel "mutex",p7,p8
1765 (p7) mov GR_TAG = 259 // negative
1766 (p7) frcpa.s0 f8,p0 = f1,f8
1772 (p8) br.cond.spnt tgamma_singularity
1778 alloc r32 = ar.pfs,1,4,4,0
1780 mov GR_Parameter_TAG = GR_TAG
1783 GLOBAL_LIBM_END(tgamma)
1784 LOCAL_LIBM_ENTRY(__libm_error_region)
1787 add GR_Parameter_Y=-32,sp // Parameter 2 value
1789 .save ar.pfs,GR_SAVE_PFS
1790 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
1794 add sp=-64,sp // Create new stack
1796 mov GR_SAVE_GP=gp // Save gp
1799 stfd [GR_Parameter_Y] = FR_Y,16 // STORE Parameter 2 on stack
1800 add GR_Parameter_X = 16,sp // Parameter 1 address
1801 .save b0, GR_SAVE_B0
1802 mov GR_SAVE_B0=b0 // Save b0
1806 stfd [GR_Parameter_X] = FR_X // STORE Parameter 1 on stack
1807 add GR_Parameter_RESULT = 0,GR_Parameter_Y // Parameter 3 address
1811 stfd [GR_Parameter_Y] = FR_RESULT // STORE Parameter 3 on stack
1812 add GR_Parameter_Y = -16,GR_Parameter_Y
1813 br.call.sptk b0=__libm_error_support# // Call error handling function
1818 add GR_Parameter_RESULT = 48,sp
1821 ldfd f8 = [GR_Parameter_RESULT] // Get return result off stack
1823 add sp = 64,sp // Restore stack pointer
1824 mov b0 = GR_SAVE_B0 // Restore return address
1827 mov gp = GR_SAVE_GP // Restore gp
1828 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
1829 br.ret.sptk b0 // Return
1832 LOCAL_LIBM_END(__libm_error_region)
1833 .type __libm_error_support#,@function
1834 .global __libm_error_support#