about summary refs log tree commit diff
path: root/sysdeps/ia64/fpu/s_atanl.S
blob: 721a38c10826ef45bb5d3272dd409eb0e638d666 (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
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
.file "atanl.s"


// Copyright (c) 2000 - 2003, Intel Corporation
// All rights reserved.
//
// Contributed 2000 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
// 02/02/00 (hand-optimized)
// 04/04/00 Unwind support added
// 08/15/00 Bundle added after call to __libm_error_support to properly
//          set [the previously overwritten] GR_Parameter_RESULT.
// 03/13/01 Fixed flags when denormal raised on intermediate result
// 01/08/02 Improved speed.
// 02/06/02 Corrected .section statement
// 05/20/02 Cleaned up namespace and sf0 syntax
// 02/10/03 Reordered header: .section, .global, .proc, .align;
//          used data8 for long double table values
//
//*********************************************************************
//
// Function:   atanl(x) = inverse tangent(x), for double extended x values
// Function:   atan2l(y,x) = atan(y/x), for double extended y, x values
//
// API
//
//  long double atanl  (long double x)
//  long double atan2l (long double y, long double x)
//
//*********************************************************************
//
// Resources Used:
//
//    Floating-Point Registers: f8 (Input and Return Value)
//                              f9 (Input for atan2l)
//                              f10-f15, f32-f83
//
//    General Purpose Registers:
//      r32-r51
//      r49-r52 (Arguments to error support for 0,0 case)
//
//    Predicate Registers:      p6-p15
//
//*********************************************************************
//
// IEEE Special Conditions:
//
//    Denormal fault raised on denormal inputs
//    Underflow exceptions may occur 
//    Special error handling for the y=0 and x=0 case
//    Inexact raised when appropriate by algorithm
//
//    atanl(SNaN) = QNaN
//    atanl(QNaN) = QNaN
//    atanl(+/-0) = +/- 0
//    atanl(+/-Inf) = +/-pi/2 
//
//    atan2l(Any NaN for x or y) = QNaN
//    atan2l(+/-0,x) = +/-0 for x > 0 
//    atan2l(+/-0,x) = +/-pi for x < 0 
//    atan2l(+/-0,+0) = +/-0 
//    atan2l(+/-0,-0) = +/-pi 
//    atan2l(y,+/-0) = pi/2 y > 0
//    atan2l(y,+/-0) = -pi/2 y < 0
//    atan2l(+/-y, Inf) = +/-0 for finite y > 0
//    atan2l(+/-Inf, x) = +/-pi/2 for finite x 
//    atan2l(+/-y, -Inf) = +/-pi for finite  y > 0 
//    atan2l(+/-Inf, Inf) = +/-pi/4
//    atan2l(+/-Inf, -Inf) = +/-3pi/4
//
//*********************************************************************
//
// Mathematical Description
// ---------------------------
//
// The function ATANL( Arg_Y, Arg_X ) returns the "argument"
// or the "phase" of the complex number
//
//           Arg_X + i Arg_Y
//
// or equivalently, the angle in radians from the positive
// x-axis to the line joining the origin and the point
// (Arg_X,Arg_Y)
//
//
//        (Arg_X, Arg_Y) x
//                        \
//                \
//                 \
//                  \
//                   \ angle between is ATANL(Arg_Y,Arg_X)




//                    \
//                     ------------------> X-axis

//                   Origin
//
// Moreover, this angle is reported in the range [-pi,pi] thus
//
//      -pi <= ATANL( Arg_Y, Arg_X ) <= pi.
//
// From the geometry, it is easy to define ATANL when one of
// Arg_X or Arg_Y is +-0 or +-inf:
//
//
//      \ Y |
//     X \  |  +0  | -0  |  +inf |  -inf  |  finite non-zero
//        \ |      |     |       |        |
//    ______________________________________________________
//          |            |       |        |
//     +-0  |   Invalid/ |  pi/2 | -pi/2  |  sign(Y)*pi/2
//          |    qNaN    |       |        |
//  --------------------------------------------------------
//          |      |     |       |        |
//     +inf |  +0  | -0  |  pi/4 | -pi/4  |  sign(Y)*0
//  --------------------------------------------------------
//          |      |     |       |        |
//     -inf |  +pi | -pi | 3pi/4 | -3pi/4 |  sign(Y)*pi
//  --------------------------------------------------------
//   finite |    X>0?    |  pi/2 | -pi/2  |  normal case
//  non-zero| sign(Y)*0: |       |        |
//       | sign(Y)*pi |       |        |
//
//
// One must take note that ATANL is NOT the arctangent of the
// value Arg_Y/Arg_X; but rather ATANL and arctan are related
// in a slightly more complicated way as follows:
//
// Let U := max(|Arg_X|, |Arg_Y|);  V := min(|Arg_X|, |Arg_Y|);
// sign_X be the sign bit of Arg_X, i.e., sign_X is 0 or 1;
// s_X    be the sign     of Arg_X, i.e., s_X = (-1)^sign_X;
//
// sign_Y be the sign bit of Arg_Y, i.e., sign_Y is 0 or 1;
// s_Y    be the sign     of Arg_Y, i.e., s_Y = (-1)^sign_Y;
//
// swap   be 0  if |Arg_X| >= |Arg_Y|  and 1 otherwise.
//
// Then, ATANL(Arg_Y, Arg_X) =
//
//       /    arctan(V/U)     \      sign_X = 0 & swap = 0
//       | pi/2 - arctan(V/U) |      sign_X = 0 & swap = 1
// s_Y * |                    |
//       |  pi  - arctan(V/U) |      sign_X = 1 & swap = 0
//       \ pi/2 + arctan(V/U) /      sign_X = 1 & swap = 1
//
//
// This relationship also suggest that the algorithm's major
// task is to calculate arctan(V/U) for 0 < V <= U; and the
// final Result is given by
//
//      s_Y * { (P_hi + P_lo) + sigma * arctan(V/U) }
//
// where
//
//   (P_hi,P_lo) represents M(sign_X,swap)*(pi/2) accurately
//
//   M(sign_X,swap) = 0  for sign_X = 0 and swap = 0
//              1  for swap   = 1
//              2  for sign_X = 1 and swap = 0
//
// and
//
//   sigma = { (sign_X  XOR  swap) :  -1.0 : 1.0 }
//
//      =  (-1) ^ ( sign_X XOR swap )
//
// Both (P_hi,P_lo) and sigma can be stored in a table and fetched
// using (sign_X,swap) as an index. (P_hi, P_lo) can be stored as a
// double-precision, and single-precision pair; and sigma can
// obviously be just a single-precision number.
//
// In the algorithm we propose, arctan(V/U) is calculated to high accuracy
// as A_hi + A_lo. Consequently, the Result ATANL( Arg_Y, Arg_X ) is
// given by
//
//    s_Y*P_hi + s_Y*sigma*A_hi + s_Y*(sigma*A_lo + P_lo)
//
// We now discuss the calculation of arctan(V/U) for 0 < V <= U.
//
// For (V/U) < 2^(-3), we use a simple polynomial of the form
//
//      z + z^3*(P_1 + z^2*(P_2 + z^2*(P_3 + ... + P_8)))
//
// where z = V/U.
//
// For the sake of accuracy, the first term "z" must approximate V/U to
// extra precision. For z^3 and higher power, a working precision
// approximation to V/U suffices. Thus, we obtain:
//
//      z_hi + z_lo = V/U  to extra precision and
//      z           = V/U  to working precision
//
// The value arctan(V/U) is delivered as two pieces (A_hi, A_lo)
//
//      (A_hi,A_lo) = (z_hi, z^3*(P_1 + ... + P_8) + z_lo).
//
//
// For 2^(-3) <= (V/U) <= 1, we use a table-driven approach.
// Consider
//
//      (V/U) = 2^k * 1.b_1 b_2 .... b_63 b_64 b_65 ....
//
// Define
//
//       z_hi = 2^k * 1.b_1 b_2 b_3 b_4 1
//
// then
//                                            /                \
//                                            |  (V/U) - z_hi  |

//      arctan(V/U) = arctan(z_hi) + acrtan| -------------- |
//                                            | 1 + (V/U)*z_hi |
//                                            \                /
//
//                                            /                \
//                                            |   V - z_hi*U   |

//                  = arctan(z_hi) + acrtan| -------------- |
//                                            |   U + V*z_hi   |
//                                            \                /
//
//                  = arctan(z_hi) + acrtan( V' / U' )
//
//
// where
//
//      V' = V - U*z_hi;   U' = U + V*z_hi.
//
// Let
//
//      w_hi + w_lo  = V'/U' to extra precision and
//           w       = V'/U' to working precision
//
// then we can approximate arctan(V'/U') by
//
//      arctan(V'/U') = w_hi + w_lo
//                     + w^3*(Q_1 + w^2*(Q_2 + w^2*(Q_3 + w^2*Q_4)))
//
//                       = w_hi + w_lo + poly
//
// Finally, arctan(z_hi) is calculated beforehand and stored in a table
// as Tbl_hi, Tbl_lo. Thus,
//
//      (A_hi, A_lo) = (Tbl_hi, w_hi+(poly+(w_lo+Tbl_lo)))
//
// This completes the mathematical description.
//
//
// Algorithm
// -------------
//
// Step 0. Check for unsupported format.
//
//    If
//       ( expo(Arg_X) not zero AND msb(Arg_X) = 0 ) OR
//       ( expo(Arg_Y) not zero AND msb(Arg_Y) = 0 )
//
//    then one of the arguments is unsupported. Generate an
//    invalid and return qNaN.
//
// Step 1. Initialize
//
//    Normalize Arg_X and Arg_Y and set the following
//
//    sign_X :=  sign_bit(Arg_X)
//    s_Y    := (sign_bit(Arg_Y)==0? 1.0 : -1.0)
//    swap   := (|Arg_X| >= |Arg_Y|?   0 :  1  )
//    U      := max( |Arg_X|, |Arg_Y| )
//    V      := min( |Arg_X|, |Arg_Y| )
//
//    execute: frcpa E, pred, V, U
//    If pred is 0, go to Step 5 for special cases handling.
//
// Step 2. Decide on branch.
//
//    Q := E * V
//    If Q < 2^(-3) go to Step 4 for simple polynomial case.
//
// Step 3. Table-driven algorithm.
//
//    Q is represented as
//
//      2^(-k) * 1.b_1 b_2 b_3 ... b_63; k = 0,-1,-2,-3
//
// and that if k = 0, b_1 = b_2 = b_3 = b_4 = 0.
//
// Define
//
//      z_hi := 2^(-k) * 1.b_1 b_2 b_3 b_4 1
//
// (note that there are 49 possible values of z_hi).
//
//      ...We now calculate V' and U'. While V' is representable
//      ...as a 64-bit number because of cancellation, U' is
//      ...not in general a 64-bit number. Obtaining U' accurately
//      ...requires two working precision numbers
//
//      U_prime_hi := U + V * z_hi            ...WP approx. to U'
//      U_prime_lo := ( U - U_prime_hi ) + V*z_hi ...observe order
//      V_prime    := V - U * z_hi             ...this is exact
//
//         C_hi := frcpa (1.0, U_prime_hi)  ...C_hi approx 1/U'_hi
//
//      loop 3 times
//         C_hi := C_hi + C_hi*(1.0 - C_hi*U_prime_hi)
//
//      ...at this point C_hi is (1/U_prime_hi) to roughly 64 bits
//
//      w_hi := V_prime * C_hi     ...w_hi is V_prime/U_prime to
//                     ...roughly working precision
//
//         ...note that we want w_hi + w_lo to approximate
//      ...V_prime/(U_prime_hi + U_prime_lo) to extra precision
//         ...but for now, w_hi is good enough for the polynomial
//      ...calculation.
//
//         wsq  := w_hi*w_hi
//      poly := w_hi*wsq*(Q_1 + wsq*(Q_2 + wsq*(Q_3 + wsq*Q_4)))
//
//      Fetch
//      (Tbl_hi, Tbl_lo) = atan(z_hi) indexed by (k,b_1,b_2,b_3,b_4)
//      ...Tbl_hi is a double-precision number
//      ...Tbl_lo is a single-precision number
//
//         (P_hi, P_lo) := M(sign_X,swap)*(Pi_by_2_hi, Pi_by_2_lo)
//      ...as discussed previous. Again; the implementation can
//      ...chose to fetch P_hi and P_lo from a table indexed by
//      ...(sign_X, swap).
//      ...P_hi is a double-precision number;
//      ...P_lo is a single-precision number.
//
//      ...calculate w_lo so that w_hi + w_lo is V'/U' accurately
//         w_lo := ((V_prime - w_hi*U_prime_hi) -
//              w_hi*U_prime_lo) * C_hi     ...observe order
//
//
//      ...Ready to deliver arctan(V'/U') as A_hi, A_lo
//      A_hi := Tbl_hi
//      A_lo := w_hi + (poly + (Tbl_lo + w_lo)) ...observe order
//
//      ...Deliver final Result
//      ...s_Y*P_hi + s_Y*sigma*A_hi + s_Y*(sigma*A_lo + P_lo)
//
//      sigma := ( (sign_X XOR swap) ? -1.0 : 1.0 )
//      ...sigma can be obtained by a table lookup using
//      ...(sign_X,swap) as index and stored as single precision
//         ...sigma should be calculated earlier
//
//      P_hi := s_Y*P_hi
//      A_hi := s_Y*A_hi
//
//      Res_hi := P_hi + sigma*A_hi     ...this is exact because
//                          ...both P_hi and Tbl_hi
//                          ...are double-precision
//                          ...and |Tbl_hi| > 2^(-4)
//                          ...P_hi is either 0 or
//                          ...between (1,4)
//
//      Res_lo := sigma*A_lo + P_lo
//
//      Return Res_hi + s_Y*Res_lo in user-defined rounding control
//
// Step 4. Simple polynomial case.
//
//    ...E and Q are inherited from Step 2.
//
//    A_hi := Q     ...Q is inherited from Step 2 Q approx V/U
//
//    loop 3 times
//       E := E + E2(1.0 - E*U1
//    ...at this point E approximates 1/U to roughly working precision
//
//    z := V * E     ...z approximates V/U to roughly working precision
//    zsq := z * z
//    z4 := zsq * zsq; z8 := z4 * z4
//
//    poly1 := P_4 + zsq*(P_5 + zsq*(P_6 + zsq*(P_7 + zsq*P_8)))
//    poly2 := zsq*(P_1 + zsq*(P_2 + zsq*P_3))
//
//    poly  := poly1 + z8*poly2
//
//    z_lo := (V - A_hi*U)*E
//
//    A_lo := z*poly + z_lo
//    ...A_hi, A_lo approximate arctan(V/U) accurately
//
//    (P_hi, P_lo) := M(sign_X,swap)*(Pi_by_2_hi, Pi_by_2_lo)
//    ...one can store the M(sign_X,swap) as single precision
//    ...values
//
//    ...Deliver final Result
//    ...s_Y*P_hi + s_Y*sigma*A_hi + s_Y*(sigma*A_lo + P_lo)
//
//    sigma := ( (sign_X XOR swap) ? -1.0 : 1.0 )
//    ...sigma can be obtained by a table lookup using
//    ...(sign_X,swap) as index and stored as single precision
//    ...sigma should be calculated earlier
//
//    P_hi := s_Y*P_hi
//    A_hi := s_Y*A_hi
//
//    Res_hi := P_hi + sigma*A_hi          ...need to compute
//                          ...P_hi + sigma*A_hi
//                          ...exactly
//
//    tmp    := (P_hi - Res_hi) + sigma*A_hi
//
//    Res_lo := s_Y*(sigma*A_lo + P_lo) + tmp
//
//    Return Res_hi + Res_lo in user-defined rounding control
//
// Step 5. Special Cases
//
//    These are detected early in the function by fclass instructions.
//
//    We are in one of those special cases when X or Y is 0,+-inf or NaN
//
//    If one of X and Y is NaN, return X+Y (which will generate
//    invalid in case one is a signaling NaN). Otherwise,
//    return the Result as described in the table
//
//
//
//      \ Y |
//     X \  |  +0  | -0  |  +inf |  -inf  |  finite non-zero
//        \ |      |     |       |        |
//    ______________________________________________________
//          |            |       |        |
//     +-0  |   Invalid/ |  pi/2 | -pi/2  |  sign(Y)*pi/2
//          |    qNaN    |       |        |
//  --------------------------------------------------------
//          |      |     |       |        |
//     +inf |  +0  | -0  |  pi/4 | -pi/4  |  sign(Y)*0
//  --------------------------------------------------------
//          |      |     |       |        |
//     -inf |  +pi | -pi | 3pi/4 | -3pi/4 |  sign(Y)*pi
//  --------------------------------------------------------
//   finite |    X>0?    |  pi/2 | -pi/2  |
//  non-zero| sign(Y)*0: |       |        |      N/A
//       | sign(Y)*pi |       |        |
//
//

ArgY_orig   =   f8
Result      =   f8
FR_RESULT   =   f8
ArgX_orig   =   f9
ArgX        =   f10
FR_X        =   f10
ArgY        =   f11
FR_Y        =   f11
s_Y         =   f12
U           =   f13
V           =   f14
E           =   f15
Q           =   f32
z_hi        =   f33
U_prime_hi  =   f34
U_prime_lo  =   f35
V_prime     =   f36
C_hi        =   f37
w_hi        =   f38
w_lo        =   f39
wsq         =   f40
poly        =   f41
Tbl_hi      =   f42
Tbl_lo      =   f43
P_hi        =   f44
P_lo        =   f45
A_hi        =   f46
A_lo        =   f47
sigma       =   f48
Res_hi      =   f49
Res_lo      =   f50
Z           =   f52
zsq         =   f53
z4          =   f54
z8          =   f54
poly1       =   f55
poly2       =   f56
z_lo        =   f57
tmp         =   f58
P_1         =   f59
Q_1         =   f60
P_2         =   f61
Q_2         =   f62
P_3         =   f63
Q_3         =   f64
P_4         =   f65
Q_4         =   f66
P_5         =   f67
P_6         =   f68
P_7         =   f69
P_8         =   f70
U_hold      =   f71
TWO_TO_NEG3 =   f72
C_hi_hold   =   f73
E_hold      =   f74
M           =   f75
ArgX_abs    =   f76
ArgY_abs    =   f77
Result_lo   =   f78
A_temp      =   f79
FR_temp     =   f80
Xsq         =   f81
Ysq         =   f82
tmp_small   =   f83

GR_SAVE_PFS   = r33
GR_SAVE_B0    = r34
GR_SAVE_GP    = r35
sign_X        = r36
sign_Y        = r37 
swap          = r38 
table_ptr1    = r39 
table_ptr2    = r40 
k             = r41 
lookup        = r42 
exp_ArgX      = r43 
exp_ArgY      = r44 
exponent_Q    = r45 
significand_Q = r46 
special       = r47 
sp_exp_Q      = r48 
sp_exp_4sig_Q = r49 
table_base    = r50 
int_temp      = r51

GR_Parameter_X      = r49
GR_Parameter_Y      = r50
GR_Parameter_RESULT = r51
GR_Parameter_TAG    = r52
GR_temp             = r52

RODATA
.align 16 

LOCAL_OBJECT_START(Constants_atan)
//       double pi/2
data8 0x3FF921FB54442D18
//       single lo_pi/2, two**(-3)
data4 0x248D3132, 0x3E000000
data8 0xAAAAAAAAAAAAAAA3, 0xBFFD // P_1
data8 0xCCCCCCCCCCCC54B2, 0x3FFC // P_2
data8 0x9249249247E4D0C2, 0xBFFC // P_3
data8 0xE38E38E058870889, 0x3FFB // P_4
data8 0xBA2E895B290149F8, 0xBFFB // P_5
data8 0x9D88E6D4250F733D, 0x3FFB // P_6
data8 0x884E51FFFB8745A0, 0xBFFB // P_7
data8 0xE1C7412B394396BD, 0x3FFA // P_8
data8 0xAAAAAAAAAAAAA52F, 0xBFFD // Q_1
data8 0xCCCCCCCCC75B60D3, 0x3FFC // Q_2
data8 0x924923AD011F1940, 0xBFFC // Q_3
data8 0xE36F716D2A5F89BD, 0x3FFB // Q_4
//
//    Entries Tbl_hi  (double precision)
//    B = 1+Index/16+1/32  Index = 0
//    Entries Tbl_lo (single precision)
//    B = 1+Index/16+1/32  Index = 0
//
data8 0x3FE9A000A935BD8E 
data4 0x23ACA08F, 0x00000000
//
//    Entries Tbl_hi  (double precision) Index = 0,1,...,15
//    B = 2^(-1)*(1+Index/16+1/32)
//    Entries Tbl_lo (single precision)
//    Index = 0,1,...,15  B = 2^(-1)*(1+Index/16+1/32)
//
data8 0x3FDE77EB7F175A34 
data4 0x238729EE, 0x00000000
data8 0x3FE0039C73C1A40B 
data4 0x249334DB, 0x00000000
data8 0x3FE0C6145B5B43DA 
data4 0x22CBA7D1, 0x00000000
data8 0x3FE1835A88BE7C13 
data4 0x246310E7, 0x00000000
data8 0x3FE23B71E2CC9E6A 
data4 0x236210E5, 0x00000000
data8 0x3FE2EE628406CBCA 
data4 0x2462EAF5, 0x00000000
data8 0x3FE39C391CD41719 
data4 0x24B73EF3, 0x00000000
data8 0x3FE445065B795B55 
data4 0x24C11260, 0x00000000
data8 0x3FE4E8DE5BB6EC04 
data4 0x242519EE, 0x00000000
data8 0x3FE587D81F732FBA 
data4 0x24D4346C, 0x00000000
data8 0x3FE6220D115D7B8D 
data4 0x24ED487B, 0x00000000
data8 0x3FE6B798920B3D98 
data4 0x2495FF1E, 0x00000000
data8 0x3FE748978FBA8E0F 
data4 0x223D9531, 0x00000000
data8 0x3FE7D528289FA093 
data4 0x242B0411, 0x00000000
data8 0x3FE85D69576CC2C5 
data4 0x2335B374, 0x00000000
data8 0x3FE8E17AA99CC05D 
data4 0x24C27CFB, 0x00000000
//
//    Entries Tbl_hi  (double precision) Index = 0,1,...,15
//    B = 2^(-2)*(1+Index/16+1/32)
//    Entries Tbl_lo (single precision)
//    Index = 0,1,...,15  B = 2^(-2)*(1+Index/16+1/32)
//
data8 0x3FD025FA510665B5 
data4 0x24263482, 0x00000000
data8 0x3FD1151A362431C9
data4 0x242C8DC9, 0x00000000
data8 0x3FD2025567E47C95
data4 0x245CF9BA, 0x00000000
data8 0x3FD2ED987A823CFE
data4 0x235C892C, 0x00000000
data8 0x3FD3D6D129271134
data4 0x2389BE52, 0x00000000
data8 0x3FD4BDEE586890E6
data4 0x24436471, 0x00000000
data8 0x3FD5A2E0175E0F4E
data4 0x2389DBD4, 0x00000000
data8 0x3FD685979F5FA6FD
data4 0x2476D43F, 0x00000000
data8 0x3FD7660752817501
data4 0x24711774, 0x00000000
data8 0x3FD84422B8DF95D7
data4 0x23EBB501, 0x00000000
data8 0x3FD91FDE7CD0C662
data4 0x23883A0C, 0x00000000
data8 0x3FD9F93066168001
data4 0x240DF63F, 0x00000000
data8 0x3FDAD00F5422058B
data4 0x23FE261A, 0x00000000
data8 0x3FDBA473378624A5
data4 0x23A8CD0E, 0x00000000
data8 0x3FDC76550AAD71F8
data4 0x2422D1D0, 0x00000000
data8 0x3FDD45AEC9EC862B
data4 0x2344A109, 0x00000000
//
//    Entries Tbl_hi  (double precision) Index = 0,1,...,15
//    B = 2^(-3)*(1+Index/16+1/32)
//    Entries Tbl_lo (single precision)
//    Index = 0,1,...,15  B = 2^(-3)*(1+Index/16+1/32)
//
data8 0x3FC068D584212B3D
data4 0x239874B6, 0x00000000
data8 0x3FC1646541060850
data4 0x2335E774, 0x00000000
data8 0x3FC25F6E171A535C
data4 0x233E36BE, 0x00000000
data8 0x3FC359E8EDEB99A3
data4 0x239680A3, 0x00000000
data8 0x3FC453CEC6092A9E
data4 0x230FB29E, 0x00000000
data8 0x3FC54D18BA11570A
data4 0x230C1418, 0x00000000
data8 0x3FC645BFFFB3AA73
data4 0x23F0564A, 0x00000000
data8 0x3FC73DBDE8A7D201
data4 0x23D4A5E1, 0x00000000
data8 0x3FC8350BE398EBC7
data4 0x23D4ADDA, 0x00000000
data8 0x3FC92BA37D050271
data4 0x23BCB085, 0x00000000
data8 0x3FCA217E601081A5
data4 0x23BC841D, 0x00000000
data8 0x3FCB1696574D780B
data4 0x23CF4A8E, 0x00000000
data8 0x3FCC0AE54D768466
data4 0x23BECC90, 0x00000000
data8 0x3FCCFE654E1D5395
data4 0x2323DCD2, 0x00000000
data8 0x3FCDF110864C9D9D
data4 0x23F53F3A, 0x00000000
data8 0x3FCEE2E1451D980C
data4 0x23CCB11F, 0x00000000
//
data8 0x400921FB54442D18, 0x3CA1A62633145C07 // PI two doubles
data8 0x3FF921FB54442D18, 0x3C91A62633145C07 // PI_by_2 two dbles
data8 0x3FE921FB54442D18, 0x3C81A62633145C07 // PI_by_4 two dbles
data8 0x4002D97C7F3321D2, 0x3C9A79394C9E8A0A // 3PI_by_4 two dbles
LOCAL_OBJECT_END(Constants_atan)


.section .text
GLOBAL_IEEE754_ENTRY(atanl)

// Use common code with atan2l after setting x=1.0
{ .mfi
      alloc r32 = ar.pfs, 0, 17, 4, 0
      fma.s1 Ysq = ArgY_orig, ArgY_orig, f0          // Form y*y
      nop.i 999
}
{ .mfi
      addl table_ptr1 = @ltoff(Constants_atan#), gp  // Address of table pointer
      fma.s1 Xsq = f1, f1, f0                        // Form x*x
      nop.i 999
}
;;

{ .mfi
      ld8 table_ptr1 = [table_ptr1]                  // Get table pointer
      fnorm.s1 ArgY = ArgY_orig
      nop.i 999
}
{ .mfi
      nop.m 999
      fnorm.s1 ArgX = f1
      nop.i 999
}
;;

{ .mfi
      getf.exp sign_X = f1               // Get signexp of x
      fmerge.s ArgX_abs = f0, f1         // Form |x|
      nop.i 999
}
{ .mfi
      nop.m 999
      fnorm.s1 ArgX_orig = f1
      nop.i 999
}
;;

{ .mfi
      getf.exp sign_Y = ArgY_orig        // Get signexp of y
      fmerge.s ArgY_abs = f0, ArgY_orig  // Form |y|
      mov table_base = table_ptr1        // Save base pointer to tables
}
;;

{ .mfi
      ldfd P_hi = [table_ptr1],8         // Load double precision hi part of pi
      fclass.m p8,p0 = ArgY_orig, 0x1e7  // Test y natval, nan, inf, zero
      nop.i 999 
}
;;

{ .mfi
      ldfps P_lo, TWO_TO_NEG3 = [table_ptr1], 8 // Load P_lo and constant 2^-3
      nop.f 999 
      nop.i 999 
}
{ .mfi
      nop.m 999
      fma.s1 M = f1, f1, f0              // Set M = 1.0
      nop.i 999 
}
;;

//
//     Check for everything - if false, then must be pseudo-zero
//     or pseudo-nan (IA unsupporteds).
//
{ .mfb
      nop.m 999
      fclass.m p0,p12 = f1, 0x1FF        // Test x unsupported
(p8)  br.cond.spnt ATANL_Y_SPECIAL       // Branch if y natval, nan, inf, zero
}
;;

//     U = max(ArgX_abs,ArgY_abs)
//     V = min(ArgX_abs,ArgY_abs)
{ .mfi
      nop.m 999
      fcmp.ge.s1 p6,p7 = Xsq, Ysq        // Test for |x| >= |y| using squares
      nop.i 999 
}
{ .mfb
      nop.m 999
      fma.s1 V = ArgX_abs, f1, f0        // Set V assuming |x| < |y|
      br.cond.sptk ATANL_COMMON          // Branch to common code
}
;;

GLOBAL_IEEE754_END(atanl)

GLOBAL_IEEE754_ENTRY(atan2l)

{ .mfi
      alloc r32 = ar.pfs, 0, 17, 4, 0
      fma.s1 Ysq = ArgY_orig, ArgY_orig, f0          // Form y*y
      nop.i 999
}
{ .mfi
      addl table_ptr1 = @ltoff(Constants_atan#), gp  // Address of table pointer
      fma.s1 Xsq = ArgX_orig, ArgX_orig, f0          // Form x*x
      nop.i 999
}
;;

{ .mfi
      ld8 table_ptr1 = [table_ptr1]                  // Get table pointer
      fnorm.s1 ArgY = ArgY_orig
      nop.i 999
}
{ .mfi
      nop.m 999
      fnorm.s1 ArgX = ArgX_orig
      nop.i 999
}
;;

{ .mfi
      getf.exp sign_X = ArgX_orig        // Get signexp of x
      fmerge.s ArgX_abs = f0, ArgX_orig  // Form |x|
      nop.i 999
}
;;

{ .mfi
      getf.exp sign_Y = ArgY_orig        // Get signexp of y
      fmerge.s ArgY_abs = f0, ArgY_orig  // Form |y|
      mov table_base = table_ptr1        // Save base pointer to tables
}
;;

{ .mfi
      ldfd P_hi = [table_ptr1],8         // Load double precision hi part of pi
      fclass.m p8,p0 = ArgY_orig, 0x1e7  // Test y natval, nan, inf, zero
      nop.i 999 
}
;;

{ .mfi
      ldfps P_lo, TWO_TO_NEG3 = [table_ptr1], 8 // Load P_lo and constant 2^-3
      fclass.m p9,p0 = ArgX_orig, 0x1e7  // Test x natval, nan, inf, zero
      nop.i 999 
}
{ .mfi
      nop.m 999
      fma.s1 M = f1, f1, f0              // Set M = 1.0
      nop.i 999 
}
;;

//
//     Check for everything - if false, then must be pseudo-zero
//     or pseudo-nan (IA unsupporteds).
//
{ .mfb
      nop.m 999
      fclass.m p0,p12 = ArgX_orig, 0x1FF // Test x unsupported
(p8)  br.cond.spnt ATANL_Y_SPECIAL       // Branch if y natval, nan, inf, zero
}
;;

//     U = max(ArgX_abs,ArgY_abs)
//     V = min(ArgX_abs,ArgY_abs)
{ .mfi
      nop.m 999
      fcmp.ge.s1 p6,p7 = Xsq, Ysq        // Test for |x| >= |y| using squares
      nop.i 999 
}
{ .mfb
      nop.m 999
      fma.s1 V = ArgX_abs, f1, f0        // Set V assuming |x| < |y|
(p9)  br.cond.spnt ATANL_X_SPECIAL       // Branch if x natval, nan, inf, zero
}
;;

// Now common code for atanl and atan2l
ATANL_COMMON:
{ .mfi
      nop.m 999
      fclass.m p0,p13 = ArgY_orig, 0x1FF // Test y unsupported
      shr sign_X = sign_X, 17            // Get sign bit of x
}
{ .mfi
      nop.m 999
      fma.s1 U = ArgY_abs, f1, f0        // Set U assuming |x| < |y|
      adds table_ptr1 = 176, table_ptr1  // Point to Q4
}
;;

{ .mfi
(p6)  add swap = r0, r0                  // Set swap=0 if |x| >= |y|
(p6)  frcpa.s1 E, p0 = ArgY_abs, ArgX_abs // Compute E if |x| >= |y|
      shr sign_Y = sign_Y, 17            // Get sign bit of y
}
{ .mfb
      nop.m 999
(p6)  fma.s1 V = ArgY_abs, f1, f0        // Set V if |x| >= |y|
(p12) br.cond.spnt ATANL_UNSUPPORTED     // Branch if x unsupported
}
;;

// Set p8 if y >=0
// Set p9 if y < 0
// Set p10 if |x| >= |y| and x >=0
// Set p11 if |x| >= |y| and x < 0
{ .mfi
      cmp.eq p8, p9 = 0, sign_Y          // Test for y >= 0
(p7)  frcpa.s1 E, p0 = ArgX_abs, ArgY_abs // Compute E if |x| < |y|
(p7)  add swap = 1, r0                   // Set swap=1 if |x| < |y|
}
{ .mfb
(p6)  cmp.eq.unc p10, p11 = 0, sign_X    // If |x| >= |y|, test for x >= 0
(p6)  fma.s1 U = ArgX_abs, f1, f0        // Set U if |x| >= |y|
(p13) br.cond.spnt ATANL_UNSUPPORTED     // Branch if y unsupported
}
;;

//
//     if p8, s_Y = 1.0
//     if p9, s_Y = -1.0
//
.pred.rel "mutex",p8,p9
{ .mfi
      nop.m 999
(p8)  fadd.s1 s_Y = f0, f1               // If y >= 0 set s_Y = 1.0
      nop.i 999
}
{ .mfi
      nop.m 999
(p9)  fsub.s1 s_Y = f0, f1               // If y < 0 set s_Y = -1.0
      nop.i 999
}
;;

.pred.rel "mutex",p10,p11
{ .mfi
      nop.m 999
(p10) fsub.s1 M = M, f1                  // If |x| >= |y| and x >=0, set M=0
      nop.i 999
}
{ .mfi
      nop.m 999
(p11) fadd.s1 M = M, f1                  // If |x| >= |y| and x < 0, set M=2.0
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fcmp.eq.s0 p0, p9 = ArgX_orig, ArgY_orig // Dummy to set denormal flag
      nop.i 999
}
// *************************************************
// ********************* STEP2 *********************
// *************************************************
//
//     Q = E * V
//
{ .mfi
      nop.m 999
      fmpy.s1 Q = E, V
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fnma.s1 E_hold = E, U, f1           // E_hold = 1.0 - E*U (1) if POLY path
      nop.i 999
}
;;

// Create a single precision representation of the signexp of Q with the 
// 4 most significant bits of the significand followed by a 1 and then 18 0's
{ .mfi
      nop.m 999
      fmpy.s1 P_hi = M, P_hi
      dep.z special = 0x1, 18, 1           // Form 0x0000000000040000
}
{ .mfi
      nop.m 999
      fmpy.s1 P_lo = M, P_lo
      add table_ptr2 = 32, table_ptr1
}
;;

{ .mfi
      nop.m 999
      fma.s1 A_temp = Q, f1, f0            // Set A_temp if POLY path
      nop.i 999
}
{ .mfi
      nop.m 999
      fma.s1 E = E, E_hold, E              // E = E + E*E_hold (1) if POLY path
      nop.i 999
}
;;

//
//     Is Q < 2**(-3)?
//     swap = xor(swap,sign_X)
//
{ .mfi
      nop.m 999
      fcmp.lt.s1 p9, p0 = Q, TWO_TO_NEG3    // Test Q < 2^-3
      xor swap = sign_X, swap
}
;;

//     P_hi = s_Y * P_hi
{ .mmf
      getf.exp exponent_Q =  Q              // Get signexp of Q
      cmp.eq.unc p7, p6 = 0x00000, swap
      fmpy.s1 P_hi = s_Y, P_hi
}
;;

//
//     if (PR_1) sigma = -1.0
//     if (PR_2) sigma =  1.0
//
{ .mfi
      getf.sig significand_Q = Q            // Get significand of Q
(p6)  fsub.s1 sigma = f0, f1
      nop.i 999
}
{ .mfb
(p9)  add table_ptr1 = 128, table_base      // Point to P8 if POLY path
(p7)  fadd.s1 sigma = f0, f1
(p9)  br.cond.spnt ATANL_POLY               // Branch to POLY if 0 < Q < 2^-3
}
;;

//
// *************************************************
// ******************** STEP3 **********************
// *************************************************
//
//     lookup = b_1 b_2 b_3 B_4
//
{ .mmi
      nop.m 999
      nop.m 999
      andcm k = 0x0003, exponent_Q  // k=0,1,2,3 for exp_Q=0,-1,-2,-3
}
;;

//
//  Generate sign_exp_Q b_1 b_2 b_3 b_4 1 0 0 0 ... 0  in single precision 
//  representation.  Note sign of Q is always 0.
//
{ .mfi
      cmp.eq p8, p9 = 0x0000, k             // Test k=0
      nop.f 999
      extr.u lookup = significand_Q, 59, 4  // Extract b_1 b_2 b_3 b_4 for index
}
{ .mfi
      sub sp_exp_Q = 0x7f, k                // Form single prec biased exp of Q
      nop.f 999
      sub k = k, r0, 1                      // Decrement k
}
;;

//     Form pointer to B index table
{ .mfi
      ldfe Q_4 = [table_ptr1], -16          // Load Q_4
      nop.f 999
(p9)  shl k = k, 8                          // k = 0, 256, or 512
}
{ .mfi
(p9)  shladd table_ptr2 = lookup, 4, table_ptr2
      nop.f 999
      shladd sp_exp_4sig_Q = sp_exp_Q, 4, lookup // Shift and add in 4 high bits
}
;;

{ .mmi
(p8)  add table_ptr2 = -16, table_ptr2      // Pointer if original k was 0
(p9)  add table_ptr2 = k, table_ptr2        // Pointer if k was 1, 2, 3
      dep special = sp_exp_4sig_Q, special, 19, 13 // Form z_hi as single prec
}
;;

//     z_hi = s exp 1.b_1 b_2 b_3 b_4 1 0 0 0 ... 0
{ .mmi
      ldfd Tbl_hi = [table_ptr2], 8         // Load Tbl_hi from index table
;;
      setf.s z_hi = special                 // Form z_hi
      nop.i 999
}
{ .mmi
      ldfs Tbl_lo = [table_ptr2], 8         // Load Tbl_lo from index table
;;
      ldfe Q_3 = [table_ptr1], -16          // Load Q_3
      nop.i 999
}
;;

{ .mmi
      ldfe Q_2 = [table_ptr1], -16          // Load Q_2
      nop.m 999
      nop.i 999
}
;;

{ .mmf
      ldfe Q_1 = [table_ptr1], -16          // Load Q_1
      nop.m 999
      nop.f 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 U_prime_hi = V, z_hi, U        // U_prime_hi = U + V * z_hi
      nop.i 999
}
{ .mfi
      nop.m 999
      fnma.s1 V_prime = U, z_hi, V          // V_prime =  V - U * z_hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      mov A_hi = Tbl_hi                     // Start with A_hi = Tbl_hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fsub.s1 U_hold = U, U_prime_hi        // U_hold = U - U_prime_hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      frcpa.s1 C_hi, p0 = f1, U_prime_hi    // C_hi = frcpa(1,U_prime_hi)
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fmpy.s1 A_hi = s_Y, A_hi              // A_hi = s_Y * A_hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 U_prime_lo = z_hi, V, U_hold   // U_prime_lo =  U_hold + V * z_hi
      nop.i 999
}
;;

//     C_hi_hold = 1 - C_hi * U_prime_hi (1)
{ .mfi
      nop.m 999
      fnma.s1 C_hi_hold = C_hi, U_prime_hi, f1 
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 Res_hi = sigma, A_hi, P_hi   // Res_hi = P_hi + sigma * A_hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 C_hi = C_hi_hold, C_hi, C_hi // C_hi = C_hi + C_hi * C_hi_hold (1)
      nop.i 999
}
;;

//     C_hi_hold = 1 - C_hi * U_prime_hi (2)
{ .mfi
      nop.m 999
      fnma.s1 C_hi_hold = C_hi, U_prime_hi, f1
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 C_hi = C_hi_hold, C_hi, C_hi // C_hi = C_hi + C_hi * C_hi_hold (2)
      nop.i 999
}
;;

//     C_hi_hold = 1 - C_hi * U_prime_hi (3)
{ .mfi
      nop.m 999
      fnma.s1 C_hi_hold = C_hi, U_prime_hi, f1 
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 C_hi = C_hi_hold, C_hi, C_hi // C_hi = C_hi + C_hi * C_hi_hold (3)
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fmpy.s1 w_hi = V_prime, C_hi           // w_hi = V_prime * C_hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fmpy.s1 wsq = w_hi, w_hi               // wsq = w_hi * w_hi
      nop.i 999
}
{ .mfi
      nop.m 999
      fnma.s1 w_lo = w_hi, U_prime_hi, V_prime // w_lo = V_prime-w_hi*U_prime_hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 poly =  wsq, Q_4, Q_3           // poly = Q_3 + wsq * Q_4
      nop.i 999
}
{ .mfi
      nop.m 999
      fnma.s1 w_lo = w_hi, U_prime_lo, w_lo  // w_lo = w_lo - w_hi * U_prime_lo
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 poly = wsq, poly, Q_2           // poly = Q_2 + wsq * poly
      nop.i 999
}
{ .mfi
      nop.m 999
      fmpy.s1 w_lo = C_hi, w_lo              // w_lo =  = w_lo * C_hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 poly = wsq, poly, Q_1           // poly = Q_1 + wsq * poly
      nop.i 999
}
{ .mfi
      nop.m 999
      fadd.s1 A_lo = Tbl_lo, w_lo            // A_lo = Tbl_lo + w_lo
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fmpy.s0 Q_1 =  Q_1, Q_1                // Dummy operation to raise inexact
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fmpy.s1 poly = wsq, poly               // poly = wsq * poly
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fmpy.s1 poly = w_hi, poly              // poly = w_hi * poly
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fadd.s1 A_lo = A_lo, poly              // A_lo = A_lo + poly
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fadd.s1 A_lo = A_lo, w_hi              // A_lo = A_lo + w_hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 Res_lo = sigma, A_lo, P_lo      // Res_lo = P_lo + sigma * A_lo
      nop.i 999
}
;;

//
//     Result  =  Res_hi + Res_lo * s_Y  (User Supplied Rounding Mode)
//
{ .mfb
      nop.m 999
      fma.s0 Result = Res_lo, s_Y, Res_hi
      br.ret.sptk   b0                        // Exit table path 2^-3 <= V/U < 1
}
;;


ATANL_POLY: 
// Here if 0 < V/U < 2^-3
//
// ***********************************************
// ******************** STEP4 ********************
// ***********************************************

//
//     Following:
//     Iterate 3 times E = E + E*(1.0 - E*U)
//     Also load P_8, P_7, P_6, P_5, P_4
//
{ .mfi
      ldfe P_8 = [table_ptr1], -16            // Load P_8
      fnma.s1 z_lo = A_temp, U, V             // z_lo = V - A_temp * U
      nop.i 999
}
{ .mfi
      nop.m 999
      fnma.s1 E_hold = E, U, f1               // E_hold = 1.0 - E*U (2)
      nop.i 999
}
;;

{ .mmi
      ldfe P_7 = [table_ptr1], -16            // Load P_7
;;
      ldfe P_6 = [table_ptr1], -16            // Load P_6
      nop.i 999
}
;;

{ .mfi
      ldfe P_5 = [table_ptr1], -16            // Load P_5
      fma.s1 E = E, E_hold, E                 // E = E + E_hold*E (2)
      nop.i 999
}
;;

{ .mmi
      ldfe P_4 = [table_ptr1], -16            // Load P_4
;;
      ldfe P_3 = [table_ptr1], -16            // Load P_3
      nop.i 999
}
;;

{ .mfi
      ldfe P_2 = [table_ptr1], -16            // Load P_2
      fnma.s1 E_hold = E, U, f1               // E_hold = 1.0 - E*U (3)
      nop.i 999
}
{ .mlx
      nop.m 999
      movl         int_temp = 0x24005         // Signexp for small neg number
}
;;

{ .mmf
      ldfe P_1 = [table_ptr1], -16            // Load P_1
      setf.exp     tmp_small = int_temp       // Form small neg number
      fma.s1 E = E, E_hold, E                 // E = E + E_hold*E (3)
}
;;

//
//
// At this point E approximates 1/U to roughly working precision
// Z = V*E approximates V/U
//
{ .mfi
      nop.m 999
      fmpy.s1 Z = V, E                         // Z = V * E
      nop.i 999
}
{ .mfi
      nop.m 999
      fmpy.s1 z_lo = z_lo, E                   // z_lo = z_lo * E
      nop.i 999
}
;;

//
//     Now what we want to do is
//     poly1 = P_4 + zsq*(P_5 + zsq*(P_6 + zsq*(P_7 + zsq*P_8)))
//     poly2 = zsq*(P_1 + zsq*(P_2 + zsq*P_3))
//
//
//     Fixup added to force inexact later -
//     A_hi = A_temp + z_lo
//     z_lo = (A_temp - A_hi) + z_lo
//
{ .mfi
      nop.m 999
      fmpy.s1 zsq = Z, Z                        // zsq = Z * Z
      nop.i 999
}
{ .mfi
      nop.m 999
      fadd.s1 A_hi = A_temp, z_lo               // A_hi = A_temp + z_lo
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 poly1 = zsq, P_8, P_7              // poly1 = P_7 + zsq * P_8
      nop.i 999
}
{ .mfi
      nop.m 999
      fma.s1 poly2 = zsq, P_3, P_2              // poly2 = P_2 + zsq * P_3
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fmpy.s1 z4 = zsq, zsq                     // z4 = zsq * zsq
      nop.i 999
}
{ .mfi
      nop.m 999
      fsub.s1 A_temp = A_temp, A_hi             // A_temp = A_temp - A_hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fmerge.s     tmp = A_hi, A_hi             // Copy tmp = A_hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 poly1 = zsq, poly1, P_6            // poly1 = P_6 + zsq * poly1
      nop.i 999
}
{ .mfi
      nop.m 999
      fma.s1 poly2 = zsq, poly2, P_1            // poly2 = P_2 + zsq * poly2
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fmpy.s1 z8 = z4, z4                       // z8 = z4 * z4
      nop.i 999
}
{ .mfi
      nop.m 999
      fadd.s1 z_lo = A_temp, z_lo               // z_lo = (A_temp - A_hi) + z_lo
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 poly1 = zsq, poly1, P_5            // poly1 = P_5 + zsq * poly1
      nop.i 999
}
{ .mfi
      nop.m 999
      fmpy.s1 poly2 = poly2, zsq                // poly2 = zsq * poly2
      nop.i 999
}
;;

//     Create small GR double in case need to raise underflow
{ .mfi
      nop.m 999
      fma.s1 poly1 = zsq, poly1, P_4            // poly1 = P_4 + zsq * poly1
      dep GR_temp = -1,r0,0,53
}
;;

//     Create small double in case need to raise underflow
{ .mfi
      setf.d FR_temp = GR_temp	
      fma.s1 poly = z8, poly1, poly2            // poly = poly2 + z8 * poly1
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 A_lo = Z, poly, z_lo               // A_lo = z_lo + Z * poly
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fadd.s1      A_hi = tmp, A_lo             // A_hi = tmp + A_lo
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fsub.s1      tmp = tmp, A_hi              // tmp = tmp - A_hi
      nop.i 999
}
{ .mfi
      nop.m 999
      fmpy.s1 A_hi = s_Y, A_hi                  // A_hi = s_Y * A_hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fadd.s1      A_lo = tmp, A_lo             // A_lo = tmp + A_lo
      nop.i 999
}
{ .mfi
      nop.m 999
      fma.s1 Res_hi = sigma, A_hi, P_hi         // Res_hi = P_hi + sigma * A_hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fsub.s1 tmp =  P_hi, Res_hi               // tmp = P_hi - Res_hi
      nop.i 999
}
;;

//
//     Test if A_lo is zero
//
{ .mfi
      nop.m 999
      fclass.m p6,p0 = A_lo, 0x007              // Test A_lo = 0
      nop.i 999
}
;;

{ .mfi
      nop.m 999
(p6)  mov          A_lo = tmp_small             // If A_lo zero, make very small
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 tmp = A_hi, sigma, tmp             // tmp = sigma * A_hi  + tmp
      nop.i 999
}
{ .mfi
      nop.m 999
      fma.s1 sigma =  A_lo, sigma, P_lo         // sigma = A_lo * sigma  + P_lo
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fma.s1 Res_lo = s_Y, sigma, tmp           // Res_lo = s_Y * sigma + tmp
      nop.i 999
}
;;

//
//     Test if Res_lo is denormal
//
{ .mfi
      nop.m 999
      fclass.m p14, p15 = Res_lo, 0x0b
      nop.i 999
}
;;

//
//     Compute Result = Res_lo + Res_hi.  Use s3 if Res_lo is denormal.
//
{ .mfi
      nop.m 999
(p14) fadd.s3 Result = Res_lo, Res_hi     // Result for Res_lo denormal
      nop.i 999
}
{ .mfi
      nop.m 999
(p15) fadd.s0 Result = Res_lo, Res_hi     // Result for Res_lo normal
      nop.i 999
}
;;

//	
//     If Res_lo is denormal test if Result equals zero
//	
{ .mfi
      nop.m 999
(p14) fclass.m.unc p14, p0 = Result, 0x07
      nop.i 999
}
;;

//
//     If Res_lo is denormal and Result equals zero, raise inexact, underflow
//     by squaring small double
//
{ .mfb
      nop.m 999
(p14) fmpy.d.s0 FR_temp = FR_temp, FR_temp
      br.ret.sptk   b0                     // Exit POLY path, 0 < Q < 2^-3
}
;;


ATANL_UNSUPPORTED: 
{ .mfb
      nop.m 999
      fmpy.s0 Result = ArgX,ArgY 
      br.ret.sptk   b0
}
;;

// Here if y natval, nan, inf, zero
ATANL_Y_SPECIAL:
// Here if x natval, nan, inf, zero
ATANL_X_SPECIAL:
{ .mfi
      nop.m 999
      fclass.m p13,p12 = ArgY_orig, 0x0c3  // Test y nan
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fclass.m p15,p14 = ArgY_orig, 0x103  // Test y natval
      nop.i 999
}
;;

{ .mfi
      nop.m 999
(p12) fclass.m p13,p0 = ArgX_orig, 0x0c3  // Test x nan
      nop.i 999
}
;;

{ .mfi
      nop.m 999
(p14) fclass.m p15,p0 = ArgX_orig, 0x103  // Test x natval
      nop.i 999
}
;;

{ .mfb
      nop.m 999
(p13) fmpy.s0 Result = ArgX_orig, ArgY_orig // Result nan if x or y nan
(p13) br.ret.spnt b0                      // Exit if x or y nan
}
;;

{ .mfb
      nop.m 999
(p15) fmpy.s0 Result = ArgX_orig, ArgY_orig // Result natval if x or y natval
(p15) br.ret.spnt b0                      // Exit if x or y natval
}
;;


// Here if x or y inf or zero
ATANL_SPECIAL_HANDLING: 
{ .mfi
      nop.m 999
      fclass.m p6, p7 = ArgY_orig, 0x007        // Test y zero
      mov special = 992                         // Offset to table
}
;;

{ .mfb
      add table_ptr1 = table_base, special      // Point to 3pi/4
      fcmp.eq.s0 p0, p9 = ArgX_orig, ArgY_orig  // Dummy to set denormal flag
(p7)  br.cond.spnt ATANL_ArgY_Not_ZERO          // Branch if y not zero
}
;;

// Here if y zero
{ .mmf
      ldfd  Result = [table_ptr1], 8            // Get pi high
      nop.m 999
      fclass.m p14, p0 = ArgX, 0x035            // Test for x>=+0
}
;;

{ .mmf
      nop.m 999
      ldfd  Result_lo = [table_ptr1], -8        // Get pi lo
      fclass.m p15, p0 = ArgX, 0x036            // Test for x<=-0
}
;;

//
//     Return sign_Y * 0 when  ArgX > +0
//
{ .mfi
      nop.m 999
(p14) fmerge.s Result = ArgY, f0               // If x>=+0, y=0, hi sgn(y)*0
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fclass.m p13, p0 = ArgX, 0x007           // Test for x=0
      nop.i 999
}
;;

{ .mfi
      nop.m 999
(p14) fmerge.s Result_lo = ArgY, f0            // If x>=+0, y=0, lo sgn(y)*0
      nop.i 999
}
;;

{ .mfi
(p13) mov GR_Parameter_TAG = 36                // Error tag for x=0, y=0
      nop.f 999
      nop.i 999
}
;;

//
//     Return sign_Y * pi when  ArgX < -0
//
{ .mfi
      nop.m 999
(p15) fmerge.s Result = ArgY, Result           // If x<0, y=0, hi=sgn(y)*pi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
(p15) fmerge.s Result_lo = ArgY, Result_lo     // If x<0, y=0, lo=sgn(y)*pi
      nop.i 999
}
;;

//
//     Call error support function for atan(0,0)
//
{ .mfb
      nop.m 999
      fadd.s0 Result = Result, Result_lo
(p13) br.cond.spnt __libm_error_region         // Branch if atan(0,0)
}
;;

{ .mib
      nop.m 999
      nop.i 999
      br.ret.sptk   b0                         // Exit for y=0, x not 0
}
;;

// Here if y not zero
ATANL_ArgY_Not_ZERO: 
{ .mfi
      nop.m 999
      fclass.m p0, p10 = ArgY, 0x023           // Test y inf
      nop.i 999
}
;;

{ .mfb
      nop.m 999
      fclass.m p6, p0 = ArgX, 0x017            // Test for 0 <= |x| < inf
(p10) br.cond.spnt  ATANL_ArgY_Not_INF         // Branch if 0 < |y| < inf
}
;;

// Here if y=inf
//
//     Return +PI/2 when ArgY = +Inf and ArgX = +/-0 or normal
//     Return -PI/2 when ArgY = -Inf and ArgX = +/-0 or normal
//     Return +PI/4 when ArgY = +Inf and ArgX = +Inf
//     Return -PI/4 when ArgY = -Inf and ArgX = +Inf
//     Return +3PI/4 when ArgY = +Inf and ArgX = -Inf
//     Return -3PI/4 when ArgY = -Inf and ArgX = -Inf
//
{ .mfi
      nop.m 999
      fclass.m p7, p0 = ArgX, 0x021            // Test for x=+inf
      nop.i 999
}
;;

{ .mfi
(p6)  add table_ptr1 =  16, table_ptr1         // Point to pi/2, if x finite 
      fclass.m p8, p0 = ArgX, 0x022            // Test for x=-inf
      nop.i 999
}
;;

{ .mmi
(p7)  add table_ptr1 =  32, table_ptr1         // Point to pi/4 if x=+inf
;;
(p8)  add table_ptr1 =  48, table_ptr1         // Point to 3pi/4 if x=-inf

      nop.i 999
}
;;

{ .mmi
      ldfd Result = [table_ptr1], 8            // Load pi/2, pi/4, or 3pi/4 hi
;;
      ldfd Result_lo = [table_ptr1], -8        // Load pi/2, pi/4, or 3pi/4 lo
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fmerge.s Result = ArgY, Result           // Merge sgn(y) in hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fmerge.s Result_lo = ArgY, Result_lo     // Merge sgn(y) in lo
      nop.i 999
}
;;

{ .mfb
      nop.m 999
      fadd.s0 Result = Result, Result_lo       // Compute complete result
      br.ret.sptk   b0                         // Exit for y=inf
}
;;

// Here if y not INF, and x=0 or INF
ATANL_ArgY_Not_INF: 
//
//     Return +PI/2 when ArgY NOT Inf, ArgY > 0 and ArgX = +/-0
//     Return -PI/2 when ArgY NOT Inf, ArgY < 0 and ArgX = +/-0
//     Return +0    when ArgY NOT Inf, ArgY > 0 and ArgX = +Inf
//     Return -0    when ArgY NOT Inf, ArgY > 0 and ArgX = +Inf
//     Return +PI   when ArgY NOT Inf, ArgY > 0 and ArgX = -Inf
//     Return -PI   when ArgY NOT Inf, ArgY > 0 and ArgX = -Inf
//
{ .mfi
      nop.m 999
      fclass.m p7, p9 = ArgX, 0x021            // Test for x=+inf
      nop.i 999
}
;;

{ .mfi
      nop.m 999
      fclass.m p6, p0 = ArgX, 0x007            // Test for x=0
      nop.i 999
}
;;

{ .mfi
(p6)  add table_ptr1 = 16, table_ptr1          // Point to pi/2
      fclass.m p8, p0 = ArgX, 0x022            // Test for x=-inf
      nop.i 999
}
;;

.pred.rel "mutex",p7,p9
{ .mfi
(p9)  ldfd Result = [table_ptr1], 8           // Load pi or pi/2 hi
(p7)  fmerge.s Result = ArgY, f0              // If y not inf, x=+inf, sgn(y)*0
      nop.i 999
}
;;

{ .mfi
(p9)  ldfd Result_lo = [table_ptr1], -8       // Load pi or pi/2 lo
(p7)  fnorm.s0 Result = Result                // If y not inf, x=+inf normalize
      nop.i 999
}
;;

{ .mfi
      nop.m 999
(p9)  fmerge.s Result = ArgY, Result          // Merge sgn(y) in hi
      nop.i 999
}
;;

{ .mfi
      nop.m 999
(p9)  fmerge.s Result_lo = ArgY, Result_lo    // Merge sgn(y) in lo
      nop.i 999
}
;;

{ .mfb
      nop.m 999
(p9)  fadd.s0 Result = Result, Result_lo      // Compute complete result
      br.ret.spnt   b0                        // Exit for y not inf, x=0,inf
}
;;

GLOBAL_IEEE754_END(atan2l)
 
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
        stfe [GR_Parameter_Y] = FR_Y,16         // Save 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
        stfe [GR_Parameter_X] = FR_X            // Store Parameter 1 on stack
        add   GR_Parameter_RESULT = 0,GR_Parameter_Y
        nop.b 0                                 // Parameter 3 address
}
{ .mib
        stfe [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
        ldfe  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#