about summary refs log tree commit diff
path: root/sysdeps/ia64/fpu/w_tgammaf.S
blob: 0fbd840adb8c80e186a6ccb6cd7acb0e5c9f3f97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
.file "tgammaf.s"


// Copyright (c) 2001 - 2005, Intel Corporation
// All rights reserved.
//
// Contributed 2001 by the Intel Numerics Group, Intel Corporation
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote
// products derived from this software without specific prior written
// permission.

// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,INCLUDING,BUT NOT
// LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT,INDIRECT,INCIDENTAL,SPECIAL,
// EXEMPLARY,OR CONSEQUENTIAL DAMAGES (INCLUDING,BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,DATA,OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY,WHETHER IN CONTRACT,STRICT LIABILITY OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE,EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Intel Corporation is the author of this code,and requests that all
// problem reports or change requests be submitted to it directly at
// http://www.intel.com/software/products/opensource/libraries/num.htm.
//
//*********************************************************************
//
// History:
// 11/30/01  Initial version
// 05/20/02  Cleaned up namespace and sf0 syntax
// 02/10/03  Reordered header: .section, .global, .proc, .align
// 04/04/03  Changed error codes for overflow and negative integers
// 04/10/03  Changed code for overflow near zero handling
// 12/16/03  Fixed parameter passing to/from error handling routine
// 03/31/05  Reformatted delimiters between data tables
//
//*********************************************************************
//
//*********************************************************************
//
// Function: tgammaf(x) computes the principle value of the GAMMA
// function of x.
//
//*********************************************************************
//
// Resources Used:
//
//    Floating-Point Registers: f8-f15
//                              f33-f75
//
//    General Purpose Registers:
//      r8-r11
//      r14-r29
//      r32-r36
//      r37-r40 (Used to pass arguments to error handling routine)
//
//    Predicate Registers:      p6-p15
//
//*********************************************************************
//
// IEEE Special Conditions:
//
//    tgammaf(+inf) = +inf
//    tgammaf(-inf) = QNaN
//    tgammaf(+/-0) = +/-inf
//    tgammaf(x<0, x - integer) = QNaN
//    tgammaf(SNaN) = QNaN
//    tgammaf(QNaN) = QNaN
//
//*********************************************************************
//
// Overview
//
// The method consists of three cases.
//
// If       2 <= x < OVERFLOW_BOUNDARY   use case tgamma_regular;
// else if  0 < x < 2                    use case tgamma_from_0_to_2;
// else if  -(i+1) <  x < -i, i = 0...43 use case tgamma_negatives;
//
// Case 2 <= x < OVERFLOW_BOUNDARY
// -------------------------------
//   Here we use algorithm based on the recursive formula
//   GAMMA(x+1) = x*GAMMA(x). For that we subdivide interval
//   [2; OVERFLOW_BOUNDARY] into intervals [8*n; 8*(n+1)] and
//   approximate GAMMA(x) by polynomial of 22th degree on each
//   [8*n; 8*n+1], recursive formula is used to expand GAMMA(x)
//   to [8*n; 8*n+1]. In other words we need to find n, i and r
//   such that x = 8 * n + i + r where n and i are integer numbers
//   and r is fractional part of x. So GAMMA(x) = GAMMA(8*n+i+r) =
//   = (x-1)*(x-2)*...*(x-i)*GAMMA(x-i) =
//   = (x-1)*(x-2)*...*(x-i)*GAMMA(8*n+r) ~
//   ~ (x-1)*(x-2)*...*(x-i)*P12n(r).
//
//   Step 1: Reduction
//   -----------------
//    N = [x] with truncate
//    r = x - N, note 0 <= r < 1
//
//    n = N & ~0xF - index of table that contains coefficient of
//                   polynomial approximation
//    i = N & 0xF  - is used in recursive formula
//
//
//   Step 2: Approximation
//   ---------------------
//    We use factorized minimax approximation polynomials
//    P12n(r) = A12*(r^2+C01(n)*r+C00(n))*
//              *(r^2+C11(n)*r+C10(n))*...*(r^2+C51(n)*r+C50(n))
//
//   Step 3: Recursion
//   -----------------
//    In case when i > 0 we need to multiply P12n(r) by product
//    R(i,x)=(x-1)*(x-2)*...*(x-i). To reduce number of fp-instructions
//    we can calculate R as follow:
//    R(i,x) = ((x-1)*(x-2))*((x-3)*(x-4))*...*((x-(i-1))*(x-i)) if i is
//    even or R = ((x-1)*(x-2))*((x-3)*(x-4))*...*((x-(i-2))*(x-(i-1)))*
//    *(i-1) if i is odd. In both cases we need to calculate
//    R2(i,x) = (x^2-3*x+2)*(x^2-7*x+12)*...*(x^2+x+2*j*(2*j-1)) =
//    = ((x^2-x)+2*(1-x))*((x^2-x)+6*(2-x))*...*((x^2-x)+2*(2*j-1)*(j-x)) =
//    = (RA+2*RB)*(RA+6*(1-RB))*...*(RA+2*(2*j-1)*(j-1+RB))
//    where j = 1..[i/2], RA = x^2-x, RB = 1-x.
//
//   Step 4: Reconstruction
//   ----------------------
//    Reconstruction is just simple multiplication i.e.
//    GAMMA(x) = P12n(r)*R(i,x)
//
// Case 0 < x < 2
// --------------
//    To calculate GAMMA(x) on this interval we do following
//        if 1.0  <= x < 1.25  than  GAMMA(x) = P7(x-1)
//        if 1.25 <= x < 1.5   than  GAMMA(x) = P7(x-x_min) where
//              x_min is point of local minimum on [1; 2] interval.
//        if 1.5  <= x < 1.75  than  GAMMA(x) = P7(x-1.5)
//        if 1.75 <= x < 2.0   than  GAMMA(x) = P7(x-1.5)
//    and
//        if 0 < x < 1 than GAMMA(x) = GAMMA(x+1)/x
//
// Case -(i+1) <  x < -i, i = 0...43
// ----------------------------------
//    Here we use the fact that GAMMA(-x) = PI/(x*GAMMA(x)*sin(PI*x)) and
//    so we need to calculate GAMMA(x), sin(PI*x)/PI. Calculation of
//    GAMMA(x) is described above.
//
//   Step 1: Reduction
//   -----------------
//    Note that period of sin(PI*x) is 2 and range reduction for
//    sin(PI*x) is like to range reduction for GAMMA(x)
//    i.e rs = x - round(x) and |rs| <= 0.5.
//
//   Step 2: Approximation
//   ---------------------
//    To approximate sin(PI*x)/PI = sin(PI*(2*n+rs))/PI =
//    = (-1)^n*sin(PI*rs)/PI Taylor series is used.
//    sin(PI*rs)/PI ~ S17(rs).
//
//   Step 3: Division
//   ----------------
//    To calculate 1/x and 1/(GAMMA(x)*S12(rs)) we use frcpa
//    instruction with following Newton-Raphson interations.
//
//
//*********************************************************************

GR_ad_Data              = r8
GR_TAG                  = r8
GR_SignExp              = r9
GR_Sig                  = r10
GR_ArgNz                = r10
GR_RqDeg                = r11

GR_NanBound             = r14
GR_ExpOf025             = r15
GR_ExpOf05              = r16
GR_ad_Co                = r17
GR_ad_Ce                = r18
GR_TblOffs              = r19
GR_Arg                  = r20
GR_Exp2Ind              = r21
GR_TblOffsMask          = r21
GR_Offs                 = r22
GR_OvfNzBound           = r23
GR_ZeroResBound         = r24
GR_ad_SinO              = r25
GR_ad_SinE              = r26
GR_Correction           = r27
GR_Tbl12Offs            = r28
GR_NzBound              = r28
GR_ExpOf1               = r29
GR_fpsr                 = r29

GR_SAVE_B0              = r33
GR_SAVE_PFS             = r34
GR_SAVE_GP              = r35
GR_SAVE_SP              = r36

GR_Parameter_X          = r37
GR_Parameter_Y          = r38
GR_Parameter_RESULT     = r39
GR_Parameter_TAG        = r40


FR_X                    = f10
FR_Y                    = f1
FR_RESULT               = f8

FR_iXt                  = f11
FR_Xt                   = f12
FR_r                    = f13
FR_r2                   = f14
FR_r4                   = f15

FR_C01                  = f33
FR_A7                   = f33
FR_C11                  = f34
FR_A6                   = f34
FR_C21                  = f35
FR_A5                   = f35
FR_C31                  = f36
FR_A4                   = f36
FR_C41                  = f37
FR_A3                   = f37
FR_C51                  = f38
FR_A2                   = f38

FR_C00                  = f39
FR_A1                   = f39
FR_C10                  = f40
FR_A0                   = f40
FR_C20                  = f41
FR_C30                  = f42
FR_C40                  = f43
FR_C50                  = f44
FR_An                   = f45
FR_OvfBound             = f46
FR_InvAn                = f47

FR_Multplr              = f48
FR_NormX                = f49
FR_X2mX                 = f50
FR_1mX                  = f51
FR_Rq0                  = f51
FR_Rq1                  = f52
FR_Rq2                  = f53
FR_Rq3                  = f54

FR_Rcp0                 = f55
FR_Rcp1                 = f56
FR_Rcp2                 = f57

FR_InvNormX1            = f58
FR_InvNormX2            = f59

FR_rs                   = f60
FR_rs2                  = f61

FR_LocalMin             = f62
FR_10                   = f63

FR_05                   = f64

FR_S32                  = f65
FR_S31                  = f66
FR_S01                  = f67
FR_S11                  = f68
FR_S21                  = f69
FR_S00                  = f70
FR_S10                  = f71
FR_S20                  = f72

FR_GAMMA                = f73
FR_2                    = f74
FR_6                    = f75




// Data tables
//==============================================================
RODATA
.align 16
LOCAL_OBJECT_START(tgammaf_data)
data8 0x3FDD8B618D5AF8FE // local minimum (0.461632144968362356785)
data8 0x4024000000000000 // 10.0
data8 0x3E90FC992FF39E13 // S32
data8 0xBEC144B2760626E2 // S31
//
//[2; 8)
data8 0x4009EFD1BA0CB3B4 // C01
data8 0x3FFFB35378FF4822 // C11
data8 0xC01032270413B896 // C41
data8 0xC01F171A4C0D6827 // C51
data8 0x40148F8E197396AC // C20
data8 0x401C601959F1249C // C30
data8 0x3EE21AD881741977 // An
data8 0x4041852200000000 // overflow boundary (35.04010009765625)
data8 0x3FD9CE68F695B198 // C21
data8 0xBFF8C30AC900DA03 // C31
data8 0x400E17D2F0535C02 // C00
data8 0x4010689240F7FAC8 // C10
data8 0x402563147DDCCF8D // C40
data8 0x4033406D0480A21C // C50
//
//[8; 16)
data8 0x4006222BAE0B793B // C01
data8 0x4002452733473EDA // C11
data8 0xC0010EF3326FDDB3 // C41
data8 0xC01492B817F99C0F // C51
data8 0x40099C905A249B75 // C20
data8 0x4012B972AE0E533D // C30
data8 0x3FE6F6DB91D0D4CC // An
data8 0x4041852200000000 // overflow boundary
data8 0x3FF545828F7B73C5 // C21
data8 0xBFBBD210578764DF // C31
data8 0x4000542098F53CFC // C00
data8 0x40032C1309AD6C81 // C10
data8 0x401D7331E19BD2E1 // C40
data8 0x402A06807295EF57 // C50
//
//[16; 24)
data8 0x4000131002867596 // C01
data8 0x3FFAA362D5D1B6F2 // C11
data8 0xBFFCB6985697DB6D // C41
data8 0xC0115BEE3BFC3B3B // C51
data8 0x3FFE62FF83456F73 // C20
data8 0x4007E33478A114C4 // C30
data8 0x41E9B2B73795ED57 // An
data8 0x4041852200000000 // overflow boundary
data8 0x3FEEB1F345BC2769 // C21
data8 0xBFC3BBE6E7F3316F // C31
data8 0x3FF14E07DA5E9983 // C00
data8 0x3FF53B76BF81E2C0 // C10
data8 0x4014051E0269A3DC // C40
data8 0x40229D4227468EDB // C50
//
//[24; 32)
data8 0x3FFAF7BD498384DE // C01
data8 0x3FF62AD8B4D1C3D2 // C11
data8 0xBFFABCADCD004C32 // C41
data8 0xC00FADE97C097EC9 // C51
data8 0x3FF6DA9ED737707E // C20
data8 0x4002A29E9E0C782C // C30
data8 0x44329D5B5167C6C3 // An
data8 0x4041852200000000 // overflow boundary
data8 0x3FE8943CBBB4B727 // C21
data8 0xBFCB39D466E11756 // C31
data8 0x3FE879AF3243D8C1 // C00
data8 0x3FEEC7DEBB14CE1E // C10
data8 0x401017B79BA80BCB // C40
data8 0x401E941DC3C4DE80 // C50
//
//[32; 40)
data8 0x3FF7ECB3A0E8FE5C // C01
data8 0x3FF3815A8516316B // C11
data8 0xBFF9ABD8FCC000C3 // C41
data8 0xC00DD89969A4195B // C51
data8 0x3FF2E43139CBF563 // C20
data8 0x3FFF96DC3474A606 // C30
data8 0x46AFF4CA9B0DDDF0 // An
data8 0x4041852200000000 // overflow boundary
data8 0x3FE4CE76DA1B5783 // C21
data8 0xBFD0524DB460BC4E // C31
data8 0x3FE35852DF14E200 // C00
data8 0x3FE8C7610359F642 // C10
data8 0x400BCF750EC16173 // C40
data8 0x401AC14E02EA701C // C50
//
//[40; 48)
data8 0x3FF5DCE4D8193097 // C01
data8 0x3FF1B0D8C4974FFA // C11
data8 0xBFF8FB450194CAEA // C41
data8 0xC00C9658E030A6C4 // C51
data8 0x3FF068851118AB46 // C20
data8 0x3FFBF7C7BB46BF7D // C30
data8 0x3FF0000000000000 // An
data8 0x4041852200000000 // overflow boundary
data8 0x3FE231DEB11D847A // C21
data8 0xBFD251ECAFD7E935 // C31
data8 0x3FE0368AE288F6BF // C00
data8 0x3FE513AE4215A70C // C10
data8 0x4008F960F7141B8B // C40
data8 0x40183BA08134397B // C50
//
//[1.0; 1.25)
data8 0xBFD9909648921868 // A7
data8 0x3FE96FFEEEA8520F // A6
data8 0xBFED0800D93449B8 // A3
data8 0x3FEFA648D144911C // A2
data8 0xBFEE3720F7720B4D // A5
data8 0x3FEF4857A010CA3B // A4
data8 0xBFE2788CCD545AA4 // A1
data8 0x3FEFFFFFFFE9209E // A0
//
//[1.25; 1.5)
data8 0xBFB421236426936C // A7
data8 0x3FAF237514F36691 // A6
data8 0xBFC0BADE710A10B9 // A3
data8 0x3FDB6C5465BBEF1F // A2
data8 0xBFB7E7F83A546EBE // A5
data8 0x3FC496A01A545163 // A4
data8 0xBDEE86A39D8452EB // A1
data8 0x3FEC56DC82A39AA2 // A0
//
//[1.5; 1.75)
data8 0xBF94730B51795867 // A7
data8 0x3FBF4203E3816C7B // A6
data8 0xBFE85B427DBD23E4 // A3
data8 0x3FEE65557AB26771 // A2
data8 0xBFD59D31BE3AB42A // A5
data8 0x3FE3C90CC8F09147 // A4
data8 0xBFE245971DF735B8 // A1
data8 0x3FEFFC613AE7FBC8 // A0
//
//[1.75; 2.0)
data8 0xBF7746A85137617E // A7
data8 0x3FA96E37D09735F3 // A6
data8 0xBFE3C24AC40AC0BB // A3
data8 0x3FEC56A80A977CA5 // A2
data8 0xBFC6F0E707560916 // A5
data8 0x3FDB262D949175BE // A4
data8 0xBFE1C1AEDFB25495 // A1
data8 0x3FEFEE1E644B2022 // A0
//
// sin(pi*x)/pi
data8 0xC026FB0D377656CC // S01
data8 0x3FFFB15F95A22324 // S11
data8 0x406CE58F4A41C6E7 // S10
data8 0x404453786302C61E // S20
data8 0xC023D59A47DBFCD3 // S21
data8 0x405541D7ABECEFCA // S00
//
// 1/An for [40; 48)
data8 0xCAA7576DE621FCD5, 0x3F68
LOCAL_OBJECT_END(tgammaf_data)

//==============================================================
// Code
//==============================================================

.section .text
GLOBAL_LIBM_ENTRY(tgammaf)
{ .mfi
      getf.exp      GR_SignExp = f8
      fma.s1        FR_NormX = f8,f1,f0
      addl          GR_ad_Data = @ltoff(tgammaf_data), gp
}
{ .mfi
      mov           GR_ExpOf05 = 0xFFFE
      fcvt.fx.trunc.s1 FR_iXt = f8 // [x]
      mov           GR_Offs = 0 // 2 <= x < 8
};;
{ .mfi
      getf.d        GR_Arg = f8
      fcmp.lt.s1    p14,p15 = f8,f0
      mov           GR_Tbl12Offs = 0
}
{ .mfi
      setf.exp      FR_05 = GR_ExpOf05
      fma.s1        FR_2 = f1,f1,f1 // 2
      mov           GR_Correction = 0
};;
{ .mfi
      ld8           GR_ad_Data = [GR_ad_Data]
      fclass.m      p10,p0 = f8,0x1E7 // is x  NaTVal, NaN, +/-0 or +/-INF?
      tbit.z        p12,p13 = GR_SignExp,16 // p13 if |x| >= 2
}
{ .mfi
      mov           GR_ExpOf1 = 0xFFFF
      fcvt.fx.s1    FR_rs = f8 // round(x)
      and           GR_Exp2Ind = 7,GR_SignExp
};;
.pred.rel "mutex",p14,p15
{ .mfi
(p15) cmp.eq.unc    p11,p0 = GR_ExpOf1,GR_SignExp // p11 if 1 <= x < 2
(p14) fma.s1        FR_1mX = f1,f1,f8 // 1 - |x|
      mov           GR_Sig = 0 // if |x| < 2
}
{ .mfi
(p13) cmp.eq.unc    p7,p0 = 2,GR_Exp2Ind
(p15) fms.s1        FR_1mX = f1,f1,f8 // 1 - |x|
(p13) cmp.eq.unc    p8,p0 = 3,GR_Exp2Ind
};;
.pred.rel "mutex",p7,p8
{ .mfi
(p7)  mov           GR_Offs = 0x7    // 8 <= |x| < 16
      nop.f         0
(p8)  tbit.z.unc    p0,p6 = GR_Arg,51
}
{ .mib
(p13) cmp.lt.unc    p9,p0 = 3,GR_Exp2Ind
(p8)  mov           GR_Offs = 0xE // 16 <= |x| < 32
      // jump if x is NaTVal, NaN, +/-0 or +/-INF?
(p10) br.cond.spnt  tgammaf_spec_args
};;
.pred.rel "mutex",p14,p15
.pred.rel "mutex",p6,p9
{ .mfi
(p9)  mov           GR_Offs = 0x1C // 32 <= |x|
(p14) fma.s1        FR_X2mX = FR_NormX,FR_NormX,FR_NormX // x^2-|x|
(p9)  tbit.z.unc    p0,p8 = GR_Arg,50
}
{ .mfi
      ldfpd         FR_LocalMin,FR_10 = [GR_ad_Data],16
(p15) fms.s1        FR_X2mX = FR_NormX,FR_NormX,FR_NormX // x^2-|x|
(p6)  add           GR_Offs = 0x7,GR_Offs // 24 <= x < 32
};;
.pred.rel "mutex",p8,p12
{ .mfi
      add           GR_ad_Ce = 0x50,GR_ad_Data
(p15) fcmp.lt.unc.s1 p10,p0 = f8,f1 // p10 if 0 <= x < 1
      mov           GR_OvfNzBound = 2
}
{ .mib
      ldfpd         FR_S32,FR_S31 = [GR_ad_Data],16
(p8)  add           GR_Offs = 0x7,GR_Offs // 40 <= |x|
      // jump if 1 <= x < 2
(p11) br.cond.spnt  tgammaf_from_1_to_2
};;
{ .mfi
      shladd        GR_ad_Ce = GR_Offs,4,GR_ad_Ce
      fcvt.xf       FR_Xt = FR_iXt // [x]
(p13) cmp.eq.unc    p7,p0 = r0,GR_Offs // p7 if 2 <= |x| < 8
}
{ .mfi
      shladd        GR_ad_Co = GR_Offs,4,GR_ad_Data
      fma.s1        FR_6 = FR_2,FR_2,FR_2
      mov           GR_ExpOf05 = 0x7FC
};;
{ .mfi
(p13) getf.sig      GR_Sig = FR_iXt // if |x| >= 2
      frcpa.s1      FR_Rcp0,p0 = f1,FR_NormX
(p10) shr           GR_Arg = GR_Arg,51
}
{ .mib
      ldfpd         FR_C01,FR_C11 = [GR_ad_Co],16
(p7)  mov           GR_Correction = 2
      // jump if 0 < x < 1
(p10) br.cond.spnt  tgammaf_from_0_to_1
};;
{ .mfi
      ldfpd         FR_C21,FR_C31 = [GR_ad_Ce],16
      fma.s1        FR_Rq2 = f1,f1,FR_1mX // 2 - |x|
(p14) sub           GR_Correction = r0,GR_Correction
}
{ .mfi
      ldfpd         FR_C41,FR_C51 = [GR_ad_Co],16
(p14) fcvt.xf       FR_rs = FR_rs
(p14) add           GR_ad_SinO = 0x3A0,GR_ad_Data
};;
.pred.rel "mutex",p14,p15
{ .mfi
      ldfpd         FR_C00,FR_C10 = [GR_ad_Ce],16
      nop.f         0
(p14) sub           GR_Sig = GR_Correction,GR_Sig
}
{ .mfi
      ldfpd         FR_C20,FR_C30 = [GR_ad_Co],16
      fma.s1        FR_Rq1 = FR_1mX,FR_2,FR_X2mX // (x-1)*(x-2)
(p15) sub           GR_Sig = GR_Sig,GR_Correction
};;
{ .mfi
(p14) ldfpd         FR_S01,FR_S11 = [GR_ad_SinO],16
      fma.s1        FR_Rq3 = FR_2,f1,FR_1mX // 3 - |x|
      and           GR_RqDeg = 0x6,GR_Sig
}
{ .mfi
      ldfpd         FR_C40,FR_C50 = [GR_ad_Ce],16
(p14) fma.d.s0      FR_X = f0,f0,f8 // set deno flag
      mov           GR_NanBound = 0x30016 // -2^23
};;
.pred.rel "mutex",p14,p15
{ .mfi
(p14) add           GR_ad_SinE = 0x3C0,GR_ad_Data
(p15) fms.s1        FR_r = FR_NormX,f1,FR_Xt // r = x - [x]
      cmp.eq        p8,p0 = 2,GR_RqDeg
}
{ .mfi
      ldfpd         FR_An,FR_OvfBound = [GR_ad_Co]
(p14) fms.s1        FR_r = FR_Xt,f1,FR_NormX // r = |x - [x]|
      cmp.eq        p9,p0 = 4,GR_RqDeg
};;
.pred.rel "mutex",p8,p9
{ .mfi
(p14) ldfpd         FR_S21,FR_S00 = [GR_ad_SinE],16
(p8)  fma.s1        FR_Rq0 = FR_2,f1,FR_1mX // (3-x)
      tbit.z        p0,p6 = GR_Sig,0
}
{ .mfi
(p14) ldfpd         FR_S10,FR_S20 = [GR_ad_SinO],16
(p9)  fma.s1        FR_Rq0 = FR_2,FR_2,FR_1mX // (5-x)
      cmp.eq        p10,p0 = 6,GR_RqDeg
};;
{ .mfi
(p14) getf.s        GR_Arg = f8
(p14) fcmp.eq.unc.s1 p13,p0 = FR_NormX,FR_Xt
(p14) mov           GR_ZeroResBound = 0xC22C // -43
}
{ .mfi
(p14) ldfe          FR_InvAn = [GR_ad_SinE]
(p10) fma.s1        FR_Rq0 = FR_6,f1,FR_1mX // (7-x)
      cmp.eq        p7,p0 = r0,GR_RqDeg
};;
{ .mfi
(p14) cmp.ge.unc    p11,p0 = GR_SignExp,GR_NanBound
      fma.s1        FR_Rq2 = FR_Rq2,FR_6,FR_X2mX // (x-3)*(x-4)
(p14) shl           GR_ZeroResBound = GR_ZeroResBound,16
}
{ .mfb
(p14) mov           GR_OvfNzBound = 0x802
(p14) fms.s1        FR_rs = FR_rs,f1,FR_NormX // rs = round(x) - x
      // jump if  x < -2^23 i.e. x is negative integer
(p11) br.cond.spnt  tgammaf_singularity
};;
{ .mfi
      nop.m         0
(p7)  fma.s1        FR_Rq1 = f0,f0,f1
(p14) shl           GR_OvfNzBound = GR_OvfNzBound,20
}
{ .mfb
      nop.m         0
      fma.s1        FR_Rq3 = FR_Rq3,FR_10,FR_X2mX // (x-5)*(x-6)
      // jump if x is negative integer such that -2^23 < x < 0
(p13) br.cond.spnt  tgammaf_singularity
};;
{ .mfi
      nop.m         0
      fma.s1        FR_C01 = FR_C01,f1,FR_r
(p14) mov           GR_ExpOf05 = 0xFFFE
}
{ .mfi
(p14) cmp.eq.unc    p7,p0 = GR_Arg,GR_OvfNzBound
      fma.s1        FR_C11 = FR_C11,f1,FR_r
(p14) cmp.ltu.unc   p11,p0 = GR_Arg,GR_OvfNzBound
};;
{ .mfi
      nop.m         0
      fma.s1        FR_C21 = FR_C21,f1,FR_r
(p14) cmp.ltu.unc   p9,p0 = GR_ZeroResBound,GR_Arg
}
{ .mfb
      nop.m         0
      fma.s1        FR_C31 = FR_C31,f1,FR_r
      // jump if argument is close to 0 negative
(p11) br.cond.spnt  tgammaf_overflow
};;
{ .mfi
      nop.m         0
      fma.s1        FR_C41 = FR_C41,f1,FR_r
      nop.i         0
}
{ .mfb
      nop.m         0
      fma.s1        FR_C51 = FR_C51,f1,FR_r
      // jump if x is negative noninteger such that -2^23 < x < -43
(p9)  br.cond.spnt  tgammaf_underflow
};;
{ .mfi
      nop.m         0
(p14) fma.s1        FR_rs2 = FR_rs,FR_rs,f0
      nop.i         0
}
{ .mfb
      nop.m         0
(p14) fma.s1        FR_S01 = FR_rs,FR_rs,FR_S01
      // jump if argument is 0x80200000
(p7)  br.cond.spnt  tgammaf_overflow_near0_bound
};;
{ .mfi
      nop.m         0
(p6)  fnma.s1       FR_Rq1 = FR_Rq1,FR_Rq0,f0
      nop.i         0
}
{ .mfi
      nop.m         0
(p10) fma.s1        FR_Rq2 = FR_Rq2,FR_Rq3,f0
      and           GR_Sig = 0x7,GR_Sig
};;
{ .mfi
      nop.m         0
      fma.s1        FR_C01 = FR_C01,FR_r,FR_C00
      nop.i         0
}
{ .mfi
      nop.m         0
      fma.s1        FR_C11 = FR_C11,FR_r,FR_C10
      cmp.eq        p6,p7 = r0,GR_Sig // p6 if |x| from one of base intervals
};;
{ .mfi
      nop.m         0
      fma.s1        FR_C21 = FR_C21,FR_r,FR_C20
      nop.i         0
}
{ .mfi
      nop.m         0
      fma.s1        FR_C31 = FR_C31,FR_r,FR_C30
(p7)  cmp.lt.unc    p9,p0 = 2,GR_RqDeg
};;
{ .mfi
      nop.m         0
(p14) fma.s1        FR_S11 = FR_rs,FR_rs,FR_S11
      nop.i         0
}
{ .mfi
      nop.m         0
(p14) fma.s1        FR_S21 = FR_rs,FR_rs,FR_S21
      nop.i         0
};;
{ .mfi
      nop.m         0
      fma.s1        FR_C41 = FR_C41,FR_r,FR_C40
      nop.i         0
}
{ .mfi
      nop.m         0
(p14) fma.s1        FR_S32 = FR_rs2,FR_S32,FR_S31
      nop.i         0
};;
{ .mfi
      nop.m         0
(p9)  fma.s1        FR_Rq1 = FR_Rq1,FR_Rq2,f0
      nop.i         0
}
{ .mfi
      nop.m         0
      fma.s1        FR_C51 = FR_C51,FR_r,FR_C50
      nop.i         0
};;
{ .mfi
(p14) getf.exp      GR_SignExp = FR_rs
      fma.s1        FR_C01 = FR_C01,FR_C11,f0
      nop.i         0
}
{ .mfi
      nop.m         0
(p14) fma.s1        FR_S01 = FR_S01,FR_rs2,FR_S00
      nop.i         0
};;
{ .mfi
      nop.m         0
      fma.s1        FR_C21 = FR_C21,FR_C31,f0
      nop.i         0
}
{ .mfi
      nop.m         0
      // NR-iteration
(p14) fnma.s1       FR_InvNormX1 = FR_Rcp0,FR_NormX,f1
      nop.i         0
};;
{ .mfi
      nop.m         0
(p14) fma.s1        FR_S11 = FR_S11,FR_rs2,FR_S10
(p14) tbit.z.unc    p11,p12 = GR_SignExp,17
}
{ .mfi
      nop.m         0
(p14) fma.s1        FR_S21 = FR_S21,FR_rs2,FR_S20
      nop.i         0
};;
{ .mfi
      nop.m         0
(p15) fcmp.lt.unc.s1 p0,p13 = FR_NormX,FR_OvfBound
      nop.i         0
}
{ .mfi
      nop.m         0
(p14) fma.s1        FR_S32 = FR_rs2,FR_S32,f0
      nop.i         0
};;
{ .mfi
      nop.m         0
      fma.s1        FR_C41 = FR_C41,FR_C51,f0
      nop.i         0
}
{ .mfi
      nop.m         0
(p7)  fma.s1        FR_An = FR_Rq1,FR_An,f0
      nop.i         0
};;
{ .mfb
      nop.m         0
      nop.f         0
      // jump if x > 35.04010009765625
(p13) br.cond.spnt  tgammaf_overflow
};;
{ .mfi
      nop.m         0
      // NR-iteration
(p14) fma.s1        FR_InvNormX1 = FR_Rcp0,FR_InvNormX1,FR_Rcp0
      nop.i         0
};;
{ .mfi
      nop.m         0
(p14) fma.s1        FR_S01 = FR_S01,FR_S11,f0
      nop.i         0
};;
{ .mfi
      nop.m         0
(p14) fma.s1        FR_S21 = FR_S21,FR_S32,f0
      nop.i         0
};;
{ .mfi
(p14) getf.exp      GR_SignExp = FR_NormX
      fma.s1        FR_C01 = FR_C01,FR_C21,f0
      nop.i         0
}
{ .mfi
      nop.m         0
      fma.s1        FR_C41 = FR_C41,FR_An,f0
(p14) mov           GR_ExpOf1 = 0x2FFFF
};;
{ .mfi
      nop.m         0
      // NR-iteration
(p14) fnma.s1       FR_InvNormX2 = FR_InvNormX1,FR_NormX,f1
      nop.i         0
};;
.pred.rel "mutex",p11,p12
{ .mfi
      nop.m         0
(p12) fnma.s1       FR_S01 = FR_S01,FR_S21,f0
      nop.i         0
}
{ .mfi
      nop.m         0
(p11) fma.s1        FR_S01 = FR_S01,FR_S21,f0
      nop.i         0
};;

{ .mfi
      nop.m         0
(p14) fma.s1        FR_GAMMA = FR_C01,FR_C41,f0
(p14) tbit.z.unc    p6,p7 = GR_Sig,0
}
{ .mfb
      nop.m         0
(p15) fma.s.s0      f8 = FR_C01,FR_C41,f0
(p15) br.ret.spnt   b0 // exit for positives
};;
.pred.rel "mutex",p11,p12
{ .mfi
      nop.m         0
(p12) fms.s1        FR_S01 = FR_rs,FR_S01,FR_rs
      nop.i         0
}
{ .mfi
      nop.m         0
(p11) fma.s1        FR_S01 = FR_rs,FR_S01,FR_rs
      nop.i         0
};;
{ .mfi
      nop.m         0
      // NR-iteration
      fma.s1        FR_InvNormX2 = FR_InvNormX1,FR_InvNormX2,FR_InvNormX1
      cmp.eq        p10,p0 = 0x23,GR_Offs
};;
.pred.rel "mutex",p6,p7
{ .mfi
      nop.m         0
(p6)  fma.s1        FR_GAMMA = FR_S01,FR_GAMMA,f0
      cmp.gtu       p8,p0 = GR_SignExp,GR_ExpOf1
}
{ .mfi
      nop.m         0
(p7)  fnma.s1       FR_GAMMA = FR_S01,FR_GAMMA,f0
      cmp.eq        p9,p0 = GR_SignExp,GR_ExpOf1
};;
{ .mfi
      nop.m         0
      // NR-iteration
      fnma.s1       FR_InvNormX1 = FR_InvNormX2,FR_NormX,f1
      nop.i         0
}
{ .mfi
      nop.m         0
(p10) fma.s1        FR_InvNormX2 = FR_InvNormX2,FR_InvAn,f0
      nop.i         0
};;
{ .mfi
      nop.m         0
      frcpa.s1      FR_Rcp0,p0 = f1,FR_GAMMA
      nop.i         0
};;
{ .mfi
      nop.m         0
      fms.s1        FR_Multplr = FR_NormX,f1,f1 // x - 1
      nop.i         0
};;
{ .mfi
      nop.m         0
      // NR-iteration
      fnma.s1       FR_Rcp1 = FR_Rcp0,FR_GAMMA,f1
      nop.i         0
};;
.pred.rel "mutex",p8,p9
{ .mfi
      nop.m         0
      // 1/x or 1/(An*x)
(p8)  fma.s1        FR_Multplr = FR_InvNormX2,FR_InvNormX1,FR_InvNormX2
      nop.i         0
}
{ .mfi
      nop.m         0
(p9)  fma.s1        FR_Multplr = f1,f1,f0
      nop.i         0
};;
{ .mfi
      nop.m         0
      // NR-iteration
      fma.s1        FR_Rcp1 = FR_Rcp0,FR_Rcp1,FR_Rcp0
      nop.i         0
};;
{ .mfi
      nop.m         0
      // NR-iteration
      fnma.s1       FR_Rcp2 = FR_Rcp1,FR_GAMMA,f1
      nop.i         0
}
{ .mfi
      nop.m         0
      // NR-iteration
      fma.s1        FR_Rcp1 = FR_Rcp1,FR_Multplr,f0
      nop.i         0
};;
{ .mfb
      nop.m         0
      fma.s.s0      f8 = FR_Rcp1,FR_Rcp2,FR_Rcp1
      br.ret.sptk   b0
};;

// here if 0 < x < 1
//--------------------------------------------------------------------
.align 32
tgammaf_from_0_to_1:
{ .mfi
      cmp.lt        p7,p0 = GR_Arg,GR_ExpOf05
      // NR-iteration
      fnma.s1       FR_Rcp1 = FR_Rcp0,FR_NormX,f1
      cmp.eq        p8,p0 = GR_Arg,GR_ExpOf05
}
{ .mfi
      cmp.gt        p9,p0 = GR_Arg,GR_ExpOf05
      fma.s1        FR_r = f0,f0,FR_NormX // reduced arg for (0;1)
      mov           GR_ExpOf025 = 0x7FA
};;
{ .mfi
      getf.s        GR_ArgNz = f8
      fma.d.s0      FR_X = f0,f0,f8 // set deno flag
      shl           GR_OvfNzBound = GR_OvfNzBound,20
}
{ .mfi
(p8)  mov           GR_Tbl12Offs = 0x80 // 0.5 <= x < 0.75
      nop.f         0
(p7)  cmp.ge.unc    p6,p0 = GR_Arg,GR_ExpOf025
};;
.pred.rel "mutex",p6,p9
{ .mfi
(p9)  mov           GR_Tbl12Offs = 0xC0 // 0.75 <= x < 1
      nop.f         0
(p6)  mov           GR_Tbl12Offs = 0x40 // 0.25 <= x < 0.5
}
{ .mfi
      add           GR_ad_Ce = 0x2C0,GR_ad_Data
      nop.f         0
      add           GR_ad_Co = 0x2A0,GR_ad_Data
};;
{ .mfi
      add           GR_ad_Co = GR_ad_Co,GR_Tbl12Offs
      nop.f         0
      cmp.lt        p12,p0 = GR_ArgNz,GR_OvfNzBound
}
{ .mib
      add           GR_ad_Ce = GR_ad_Ce,GR_Tbl12Offs
      cmp.eq        p7,p0 = GR_ArgNz,GR_OvfNzBound
      // jump if argument is 0x00200000
(p7)  br.cond.spnt  tgammaf_overflow_near0_bound
};;
{ .mmb
      ldfpd         FR_A7,FR_A6 = [GR_ad_Co],16
      ldfpd         FR_A5,FR_A4 = [GR_ad_Ce],16
      // jump if argument is close to 0 positive
(p12) br.cond.spnt  tgammaf_overflow
};;
{ .mfi
      ldfpd         FR_A3,FR_A2 = [GR_ad_Co],16
      // NR-iteration
      fma.s1        FR_Rcp1 = FR_Rcp0,FR_Rcp1,FR_Rcp0
      nop.i         0
}
{ .mfb
      ldfpd         FR_A1,FR_A0 = [GR_ad_Ce],16
      nop.f         0
      br.cond.sptk  tgamma_from_0_to_2
};;

// here if 1 < x < 2
//--------------------------------------------------------------------
.align 32
tgammaf_from_1_to_2:
{ .mfi
      add           GR_ad_Co = 0x2A0,GR_ad_Data
      fms.s1        FR_r = f0,f0,FR_1mX
      shr           GR_TblOffs = GR_Arg,47
}
{ .mfi
      add           GR_ad_Ce = 0x2C0,GR_ad_Data
      nop.f         0
      mov           GR_TblOffsMask = 0x18
};;
{ .mfi
      nop.m         0
      nop.f         0
      and           GR_TblOffs = GR_TblOffs,GR_TblOffsMask
};;
{ .mfi
      shladd        GR_ad_Co = GR_TblOffs,3,GR_ad_Co
      nop.f         0
      nop.i         0
}
{ .mfi
      shladd        GR_ad_Ce = GR_TblOffs,3,GR_ad_Ce
      nop.f         0
      cmp.eq        p6,p7 = 8,GR_TblOffs
};;
{ .mmi
      ldfpd         FR_A7,FR_A6 = [GR_ad_Co],16
      ldfpd         FR_A5,FR_A4 = [GR_ad_Ce],16
      nop.i         0
};;
{ .mmi
      ldfpd         FR_A3,FR_A2 = [GR_ad_Co],16
      ldfpd         FR_A1,FR_A0 = [GR_ad_Ce],16
      nop.i         0
};;

.align 32
tgamma_from_0_to_2:
{ .mfi
      nop.m         0
(p6)  fms.s1        FR_r = FR_r,f1,FR_LocalMin
      nop.i         0
};;
{ .mfi
      nop.m         0
      // NR-iteration
(p10) fnma.s1       FR_Rcp2 = FR_Rcp1,FR_NormX,f1
      nop.i         0
};;
{ .mfi
      nop.m         0
      fms.s1        FR_r2 = FR_r,FR_r,f0
      nop.i         0
};;
{ .mfi
      nop.m         0
      fma.s1        FR_A7 = FR_A7,FR_r,FR_A6
      nop.i         0
}
{ .mfi
      nop.m         0
      fma.s1        FR_A5 = FR_A5,FR_r,FR_A4
      nop.i         0
};;
{ .mfi
      nop.m         0
      fma.s1        FR_A3 = FR_A3,FR_r,FR_A2
      nop.i         0
}
{ .mfi
      nop.m         0
      fma.s1        FR_A1 = FR_A1,FR_r,FR_A0
      nop.i         0
};;
{ .mfi
      nop.m         0
      // NR-iteration
(p10) fma.s1        FR_Rcp2 = FR_Rcp1,FR_Rcp2,FR_Rcp1
      nop.i         0
};;
{ .mfi
      nop.m         0
      fma.s1        FR_A7 = FR_A7,FR_r2,FR_A5
      nop.i         0
}
{ .mfi
      nop.m         0
      fma.s1        FR_r4 = FR_r2,FR_r2,f0
      nop.i         0
};;
{ .mfi
      nop.m         0
      fma.s1        FR_A3 = FR_A3,FR_r2,FR_A1
      nop.i         0
};;
{ .mfi
      nop.m         0
(p10) fma.s1        FR_GAMMA = FR_A7,FR_r4,FR_A3
      nop.i         0
}
{ .mfi
      nop.m         0
(p11) fma.s.s0      f8 = FR_A7,FR_r4,FR_A3
      nop.i         0
};;
{ .mfb
      nop.m         0
(p10) fma.s.s0      f8 = FR_GAMMA,FR_Rcp2,f0
      br.ret.sptk   b0
};;


// overflow
//--------------------------------------------------------------------
.align 32
tgammaf_overflow_near0_bound:
.pred.rel "mutex",p14,p15
{ .mfi
	  mov           GR_fpsr = ar.fpsr
	  nop.f         0
(p15) mov           r8 = 0x7f8
}
{ .mfi
      nop.m         0
      nop.f         0
(p14) mov           r8 = 0xff8
};;
{ .mfi
	  nop.m         0
	  nop.f         0
	  shl           r8 = r8,20
};;
{ .mfi
      sub           r8 = r8,r0,1
      nop.f         0
	  extr.u        GR_fpsr = GR_fpsr,10,2 // rounding mode
};;
.pred.rel "mutex",p14,p15
{ .mfi
      // set p8 to 0 in case of overflow and to 1 otherwise
	  // for negative arg:
	  //    no overflow if rounding mode either Z or +Inf, i.e.
	  //    GR_fpsr > 1
(p14) cmp.lt        p8,p0 = 1,GR_fpsr
      nop.f         0
	  // for positive arg:
	  //    no overflow if rounding mode either Z or -Inf, i.e.
	  //    (GR_fpsr & 1) == 0
(p15) tbit.z        p0,p8 = GR_fpsr,0
};;
{ .mib
(p8)  setf.s        f8 = r8 // set result to 0x7f7fffff without
                            // OVERFLOW flag raising
      nop.i         0
(p8)  br.ret.sptk   b0
};;

.align 32
tgammaf_overflow:
{ .mfi
      nop.m         0
      nop.f         0
      mov           r8 = 0x1FFFE
};;
{ .mfi
      setf.exp      f9 = r8
      fmerge.s      FR_X = f8,f8
      nop.i         0
};;
.pred.rel "mutex",p14,p15
{ .mfi
      nop.m         0
(p14) fnma.s.s0     f8 = f9,f9,f0 // set I,O and -INF result
      mov           GR_TAG = 261 // overflow
}
{ .mfb
      nop.m         0
(p15) fma.s.s0      f8 = f9,f9,f0 // set I,O and +INF result
      br.cond.sptk  tgammaf_libm_err
};;

// x is negative integer or +/-0
//--------------------------------------------------------------------
.align 32
tgammaf_singularity:
{ .mfi
      nop.m         0
      fmerge.s      FR_X = f8,f8
      mov           GR_TAG = 262 // negative
}
{ .mfb
      nop.m         0
      frcpa.s0      f8,p0 = f0,f0
      br.cond.sptk  tgammaf_libm_err
};;
// x is negative noninteger with big absolute value
//--------------------------------------------------------------------
.align 32
tgammaf_underflow:
{ .mfi
      mov           r8 = 0x00001
      nop.f         0
      tbit.z        p6,p7 = GR_Sig,0
};;
{ .mfi
      setf.exp      f9 = r8
      nop.f         0
      nop.i         0
};;
.pred.rel "mutex",p6,p7
{ .mfi
      nop.m         0
(p6)  fms.s.s0      f8 = f9,f9,f9
      nop.i         0
}
{ .mfb
      nop.m         0
(p7)  fma.s.s0      f8 = f9,f9,f9
      br.ret.sptk   b0
};;

//  x for natval, nan, +/-inf or +/-0
//--------------------------------------------------------------------
.align 32
tgammaf_spec_args:
{ .mfi
      nop.m         0
      fclass.m      p6,p0 =  f8,0x1E1 // Test x for natval, nan, +inf
      nop.i         0
};;
{ .mfi
      nop.m         0
      fclass.m      p7,p8 =  f8,0x7 // +/-0
      nop.i         0
};;
{ .mfi
      nop.m         0
      fmerge.s      FR_X = f8,f8
      nop.i         0
}
{ .mfb
      nop.m         0
(p6)  fma.s.s0      f8 = f8,f1,f8
(p6)  br.ret.spnt   b0
};;
.pred.rel "mutex",p7,p8
{ .mfi
(p7)  mov           GR_TAG = 262 // negative
(p7)  frcpa.s0      f8,p0 = f1,f8
      nop.i         0
}
{ .mib
      nop.m         0
      nop.i         0
(p8)  br.cond.spnt  tgammaf_singularity
};;

.align 32
tgammaf_libm_err:
{ .mfi
      alloc        r32 = ar.pfs,1,4,4,0
      nop.f        0
      mov          GR_Parameter_TAG = GR_TAG
};;

GLOBAL_LIBM_END(tgammaf)

LOCAL_LIBM_ENTRY(__libm_error_region)
.prologue
{ .mfi
        add   GR_Parameter_Y=-32,sp             // Parameter 2 value
        nop.f 0
.save   ar.pfs,GR_SAVE_PFS
        mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
}
{ .mfi
.fframe 64
        add sp=-64,sp                           // Create new stack
        nop.f 0
        mov GR_SAVE_GP=gp                       // Save gp
};;
{ .mmi
        stfs [GR_Parameter_Y] = FR_Y,16         // STORE Parameter 2 on stack
        add GR_Parameter_X = 16,sp              // Parameter 1 address
.save   b0, GR_SAVE_B0
        mov GR_SAVE_B0=b0                       // Save b0
};;
.body
{ .mib
        stfs [GR_Parameter_X] = FR_X           // STORE Parameter 1 on stack
        add   GR_Parameter_RESULT = 0,GR_Parameter_Y  // Parameter 3 address
        nop.b 0
}
{ .mib
        stfs [GR_Parameter_Y] = FR_RESULT      // STORE Parameter 3 on stack
        add   GR_Parameter_Y = -16,GR_Parameter_Y
        br.call.sptk b0=__libm_error_support# // Call error handling function
};;
{ .mmi
        nop.m 0
        nop.m 0
        add   GR_Parameter_RESULT = 48,sp
};;
{ .mmi
        ldfs  f8 = [GR_Parameter_RESULT]       // Get return result off stack
.restore sp
        add   sp = 64,sp                       // Restore stack pointer
        mov   b0 = GR_SAVE_B0                  // Restore return address
};;
{ .mib
        mov   gp = GR_SAVE_GP                  // Restore gp
        mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
        br.ret.sptk     b0                     // Return
};;

LOCAL_LIBM_END(__libm_error_region)
.type   __libm_error_support#,@function
.global __libm_error_support#