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
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
|
// Copyright 2020 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !(linux && (amd64 || arm64 || loong64))
//go.generate echo package libc > ccgo.go
//go:generate go fmt ./...
// Package libc provides run time support for ccgo generated programs and
// implements selected parts of the C standard library.
package libc // import "modernc.org/libc"
//TODO use O_RDONLY etc. from fcntl header
//TODO use t.Alloc/Free where appropriate
import (
"bufio"
crand "crypto/rand"
"fmt"
"math"
mbits "math/bits"
"math/rand"
"os"
"runtime"
"runtime/debug"
"sort"
"strings"
"sync"
"sync/atomic"
gotime "time"
"unsafe"
"github.com/mattn/go-isatty"
"modernc.org/libc/errno"
"modernc.org/libc/stdio"
"modernc.org/libc/sys/types"
"modernc.org/libc/time"
"modernc.org/libc/unistd"
"modernc.org/mathutil"
)
const (
ENOENT = errno.ENOENT
)
type (
// RawMem64 represents the biggest uint64 array the runtime can handle.
RawMem64 [unsafe.Sizeof(RawMem{}) / unsafe.Sizeof(uint64(0))]uint64
)
var (
allocMu sync.Mutex
environInitialized bool
isWindows bool
ungetcMu sync.Mutex
ungetc = map[uintptr]byte{}
)
// Keep these outside of the var block otherwise go generate will miss them.
var Xenviron uintptr
var Xstdin = newFile(nil, unistd.STDIN_FILENO)
var Xstdout = newFile(nil, unistd.STDOUT_FILENO)
var Xstderr = newFile(nil, unistd.STDERR_FILENO)
func setEnviron() {
SetEnviron(nil, os.Environ())
}
func Environ() uintptr {
if !environInitialized {
SetEnviron(nil, os.Environ())
}
return Xenviron
}
func EnvironP() uintptr {
if !environInitialized {
SetEnviron(nil, os.Environ())
}
return uintptr(unsafe.Pointer(&Xenviron))
}
func X___errno_location(t *TLS) uintptr {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
return X__errno_location(t)
}
// int * __errno_location(void);
func X__errno_location(t *TLS) uintptr {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
return t.errnop
}
func Start(main func(*TLS, int32, uintptr) int32) {
if dmesgs {
wd, err := os.Getwd()
dmesg("%v: %v, wd %v, %v", origin(1), os.Args, wd, err)
defer func() {
if err := recover(); err != nil {
dmesg("%v: CRASH: %v\n%s", origin(1), err, debug.Stack())
}
}()
}
runtime.LockOSThread()
t := &TLS{errnop: uintptr(unsafe.Pointer(&errno0))}
argv := Xcalloc(t, 1, types.Size_t((len(os.Args)+1)*int(uintptrSize)))
if argv == 0 {
panic("OOM")
}
p := argv
for _, v := range os.Args {
s := Xcalloc(t, 1, types.Size_t(len(v)+1))
if s == 0 {
panic("OOM")
}
copy((*RawMem)(unsafe.Pointer(s))[:len(v):len(v)], v)
*(*uintptr)(unsafe.Pointer(p)) = s
p += uintptrSize
}
SetEnviron(t, os.Environ())
audit := false
if memgrind {
if s := os.Getenv("LIBC_MEMGRIND_START"); s != "0" {
MemAuditStart()
audit = true
}
}
t = NewTLS()
rc := main(t, int32(len(os.Args)), argv)
exit(t, rc, audit)
}
func Xexit(t *TLS, status int32) {
if __ccgo_strace {
trc("t=%v status=%v, (%v:)", t, status, origin(2))
}
exit(t, status, false)
}
func exit(t *TLS, status int32, audit bool) {
if len(Covered) != 0 {
buf := bufio.NewWriter(os.Stdout)
CoverReport(buf)
buf.Flush()
}
if len(CoveredC) != 0 {
buf := bufio.NewWriter(os.Stdout)
CoverCReport(buf)
buf.Flush()
}
for _, v := range atExit {
v()
}
if audit {
t.Close()
if tlsBalance != 0 {
fmt.Fprintf(os.Stderr, "non zero TLS balance: %d\n", tlsBalance)
status = 1
}
}
X_exit(nil, status)
}
// void _exit(int status);
func X_exit(_ *TLS, status int32) {
if dmesgs {
dmesg("%v: EXIT %v", origin(1), status)
}
os.Exit(int(status))
}
func SetEnviron(t *TLS, env []string) {
if environInitialized {
return
}
environInitialized = true
p := Xcalloc(t, 1, types.Size_t((len(env)+1)*(int(uintptrSize))))
if p == 0 {
panic("OOM")
}
Xenviron = p
for _, v := range env {
s := Xcalloc(t, 1, types.Size_t(len(v)+1))
if s == 0 {
panic("OOM")
}
copy((*(*RawMem)(unsafe.Pointer(s)))[:len(v):len(v)], v)
*(*uintptr)(unsafe.Pointer(p)) = s
p += uintptrSize
}
}
// void setbuf(FILE *stream, char *buf);
func Xsetbuf(t *TLS, stream, buf uintptr) {
if __ccgo_strace {
trc("t=%v buf=%v, (%v:)", t, buf, origin(2))
}
//TODO panic(todo(""))
}
// size_t confstr(int name, char *buf, size_t len);
func Xconfstr(t *TLS, name int32, buf uintptr, len types.Size_t) types.Size_t {
if __ccgo_strace {
trc("t=%v name=%v buf=%v len=%v, (%v:)", t, name, buf, len, origin(2))
}
panic(todo(""))
}
// int puts(const char *s);
func Xputs(t *TLS, s uintptr) int32 {
if __ccgo_strace {
trc("t=%v s=%v, (%v:)", t, s, origin(2))
}
n, err := fmt.Printf("%s\n", GoString(s))
if err != nil {
return stdio.EOF
}
return int32(n)
}
var (
randomMu sync.Mutex
randomGen = rand.New(rand.NewSource(42))
)
// long int random(void);
func Xrandom(t *TLS) long {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
randomMu.Lock()
r := randomGen.Int63n(math.MaxInt32 + 1)
randomMu.Unlock()
return long(r)
}
func write(b []byte) (int, error) {
// if dmesgs {
// dmesg("%v: %s", origin(1), b)
// }
if _, err := os.Stdout.Write(b); err != nil {
return -1, err
}
return len(b), nil
}
func X__builtin_bzero(t *TLS, s uintptr, n types.Size_t) {
if __ccgo_strace {
trc("t=%v s=%v n=%v, (%v:)", t, s, n, origin(2))
}
Xbzero(t, s, n)
}
func X__builtin_abort(t *TLS) {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
Xabort(t)
}
func X__builtin_abs(t *TLS, j int32) int32 {
if __ccgo_strace {
trc("t=%v j=%v, (%v:)", t, j, origin(2))
}
return Xabs(t, j)
}
func X__builtin_clz(t *TLS, n uint32) int32 {
if __ccgo_strace {
trc("t=%v n=%v, (%v:)", t, n, origin(2))
}
return int32(mbits.LeadingZeros32(n))
}
func X__builtin_clzl(t *TLS, n ulong) int32 {
if __ccgo_strace {
trc("t=%v n=%v, (%v:)", t, n, origin(2))
}
return int32(mbits.LeadingZeros64(uint64(n)))
}
func X__builtin_clzll(t *TLS, n uint64) int32 {
if __ccgo_strace {
trc("t=%v n=%v, (%v:)", t, n, origin(2))
}
return int32(mbits.LeadingZeros64(n))
}
func X__builtin_constant_p_impl() { panic(todo("internal error: should never be called")) }
func X__builtin_copysign(t *TLS, x, y float64) float64 {
if __ccgo_strace {
trc("t=%v y=%v, (%v:)", t, y, origin(2))
}
return Xcopysign(t, x, y)
}
func X__builtin_copysignf(t *TLS, x, y float32) float32 {
if __ccgo_strace {
trc("t=%v y=%v, (%v:)", t, y, origin(2))
}
return Xcopysignf(t, x, y)
}
func X__builtin_copysignl(t *TLS, x, y float64) float64 {
if __ccgo_strace {
trc("t=%v y=%v, (%v:)", t, y, origin(2))
}
return Xcopysign(t, x, y)
}
func X__builtin_exit(t *TLS, status int32) {
if __ccgo_strace {
trc("t=%v status=%v, (%v:)", t, status, origin(2))
}
Xexit(t, status)
}
func X__builtin_expect(t *TLS, exp, c long) long {
if __ccgo_strace {
trc("t=%v c=%v, (%v:)", t, c, origin(2))
}
return exp
}
func X__builtin_fabs(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return Xfabs(t, x)
}
func X__builtin_fabsf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return Xfabsf(t, x)
}
func X__builtin_fabsl(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return Xfabsl(t, x)
}
func X__builtin_free(t *TLS, ptr uintptr) {
if __ccgo_strace {
trc("t=%v ptr=%v, (%v:)", t, ptr, origin(2))
}
Xfree(t, ptr)
}
func X__builtin_getentropy(t *TLS, buf uintptr, n types.Size_t) int32 {
if __ccgo_strace {
trc("t=%v buf=%v n=%v, (%v:)", t, buf, n, origin(2))
}
return Xgetentropy(t, buf, n)
}
func X__builtin_huge_val(t *TLS) float64 {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
return math.Inf(1)
}
func X__builtin_huge_valf(t *TLS) float32 {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
return float32(math.Inf(1))
}
func X__builtin_inf(t *TLS) float64 {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
return math.Inf(1)
}
func X__builtin_inff(t *TLS) float32 {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
return float32(math.Inf(1))
}
func X__builtin_infl(t *TLS) float64 {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
return math.Inf(1)
}
func X__builtin_malloc(t *TLS, size types.Size_t) uintptr {
if __ccgo_strace {
trc("t=%v size=%v, (%v:)", t, size, origin(2))
}
return Xmalloc(t, size)
}
func X__builtin_memcmp(t *TLS, s1, s2 uintptr, n types.Size_t) int32 {
if __ccgo_strace {
trc("t=%v s2=%v n=%v, (%v:)", t, s2, n, origin(2))
}
return Xmemcmp(t, s1, s2, n)
}
func X__builtin_nan(t *TLS, s uintptr) float64 {
if __ccgo_strace {
trc("t=%v s=%v, (%v:)", t, s, origin(2))
}
return math.NaN()
}
func X__builtin_nanf(t *TLS, s uintptr) float32 {
if __ccgo_strace {
trc("t=%v s=%v, (%v:)", t, s, origin(2))
}
return float32(math.NaN())
}
func X__builtin_nanl(t *TLS, s uintptr) float64 {
if __ccgo_strace {
trc("t=%v s=%v, (%v:)", t, s, origin(2))
}
return math.NaN()
}
func X__builtin_prefetch(t *TLS, addr, args uintptr) {
if __ccgo_strace {
trc("t=%v args=%v, (%v:)", t, args, origin(2))
}
}
func X__builtin_printf(t *TLS, s, args uintptr) int32 {
if __ccgo_strace {
trc("t=%v args=%v, (%v:)", t, args, origin(2))
}
return Xprintf(t, s, args)
}
func X__builtin_strchr(t *TLS, s uintptr, c int32) uintptr {
if __ccgo_strace {
trc("t=%v s=%v c=%v, (%v:)", t, s, c, origin(2))
}
return Xstrchr(t, s, c)
}
func X__builtin_strcmp(t *TLS, s1, s2 uintptr) int32 {
if __ccgo_strace {
trc("t=%v s2=%v, (%v:)", t, s2, origin(2))
}
return Xstrcmp(t, s1, s2)
}
func X__builtin_strcpy(t *TLS, dest, src uintptr) uintptr {
if __ccgo_strace {
trc("t=%v src=%v, (%v:)", t, src, origin(2))
}
return Xstrcpy(t, dest, src)
}
func X__builtin_strlen(t *TLS, s uintptr) types.Size_t {
if __ccgo_strace {
trc("t=%v s=%v, (%v:)", t, s, origin(2))
}
return Xstrlen(t, s)
}
func X__builtin_trap(t *TLS) {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
Xabort(t)
}
func X__isnan(t *TLS, arg float64) int32 {
if __ccgo_strace {
trc("t=%v arg=%v, (%v:)", t, arg, origin(2))
}
return X__builtin_isnan(t, arg)
}
func X__isnanf(t *TLS, arg float32) int32 {
if __ccgo_strace {
trc("t=%v arg=%v, (%v:)", t, arg, origin(2))
}
return Xisnanf(t, arg)
}
func X__isnanl(t *TLS, arg float64) int32 {
if __ccgo_strace {
trc("t=%v arg=%v, (%v:)", t, arg, origin(2))
}
return Xisnanl(t, arg)
}
func Xvfprintf(t *TLS, stream, format, ap uintptr) int32 {
if __ccgo_strace {
trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
}
return Xfprintf(t, stream, format, ap)
}
// int __builtin_popcount (unsigned int x)
func X__builtin_popcount(t *TLS, x uint32) int32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return int32(mbits.OnesCount32(x))
}
// int __builtin_popcountl (unsigned long x)
func X__builtin_popcountl(t *TLS, x ulong) int32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return int32(mbits.OnesCount64(uint64(x)))
}
// char * __builtin___strcpy_chk (char *dest, const char *src, size_t os);
func X__builtin___strcpy_chk(t *TLS, dest, src uintptr, os types.Size_t) uintptr {
if __ccgo_strace {
trc("t=%v src=%v os=%v, (%v:)", t, src, os, origin(2))
}
return Xstrcpy(t, dest, src)
}
func X__builtin_mmap(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
if __ccgo_strace {
trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
}
return Xmmap(t, addr, length, prot, flags, fd, offset)
}
// uint16_t __builtin_bswap16 (uint32_t x)
func X__builtin_bswap16(t *TLS, x uint16) uint16 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return x<<8 |
x>>8
}
// uint32_t __builtin_bswap32 (uint32_t x)
func X__builtin_bswap32(t *TLS, x uint32) uint32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return x<<24 |
x&0xff00<<8 |
x&0xff0000>>8 |
x>>24
}
// uint64_t __builtin_bswap64 (uint64_t x)
func X__builtin_bswap64(t *TLS, x uint64) uint64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return x<<56 |
x&0xff00<<40 |
x&0xff0000<<24 |
x&0xff000000<<8 |
x&0xff00000000>>8 |
x&0xff0000000000>>24 |
x&0xff000000000000>>40 |
x>>56
}
// bool __builtin_add_overflow (type1 a, type2 b, type3 *res)
func X__builtin_add_overflowInt64(t *TLS, a, b int64, res uintptr) int32 {
if __ccgo_strace {
trc("t=%v b=%v res=%v, (%v:)", t, b, res, origin(2))
}
r, ovf := mathutil.AddOverflowInt64(a, b)
*(*int64)(unsafe.Pointer(res)) = r
return Bool32(ovf)
}
// bool __builtin_add_overflow (type1 a, type2 b, type3 *res)
func X__builtin_add_overflowUint32(t *TLS, a, b uint32, res uintptr) int32 {
if __ccgo_strace {
trc("t=%v b=%v res=%v, (%v:)", t, b, res, origin(2))
}
r := a + b
*(*uint32)(unsafe.Pointer(res)) = r
return Bool32(r < a)
}
// bool __builtin_add_overflow (type1 a, type2 b, type3 *res)
func X__builtin_add_overflowUint64(t *TLS, a, b uint64, res uintptr) int32 {
if __ccgo_strace {
trc("t=%v b=%v res=%v, (%v:)", t, b, res, origin(2))
}
r := a + b
*(*uint64)(unsafe.Pointer(res)) = r
return Bool32(r < a)
}
// bool __builtin_sub_overflow (type1 a, type2 b, type3 *res)
func X__builtin_sub_overflowInt64(t *TLS, a, b int64, res uintptr) int32 {
if __ccgo_strace {
trc("t=%v b=%v res=%v, (%v:)", t, b, res, origin(2))
}
r, ovf := mathutil.SubOverflowInt64(a, b)
*(*int64)(unsafe.Pointer(res)) = r
return Bool32(ovf)
}
// bool __builtin_mul_overflow (type1 a, type2 b, type3 *res)
func X__builtin_mul_overflowInt64(t *TLS, a, b int64, res uintptr) int32 {
if __ccgo_strace {
trc("t=%v b=%v res=%v, (%v:)", t, b, res, origin(2))
}
r, ovf := mathutil.MulOverflowInt64(a, b)
*(*int64)(unsafe.Pointer(res)) = r
return Bool32(ovf)
}
// bool __builtin_mul_overflow (type1 a, type2 b, type3 *res)
func X__builtin_mul_overflowUint64(t *TLS, a, b uint64, res uintptr) int32 {
if __ccgo_strace {
trc("t=%v b=%v res=%v, (%v:)", t, b, res, origin(2))
}
hi, lo := mbits.Mul64(a, b)
*(*uint64)(unsafe.Pointer(res)) = lo
return Bool32(hi != 0)
}
// bool __builtin_mul_overflow (type1 a, type2 b, type3 *res)
func X__builtin_mul_overflowUint128(t *TLS, a, b Uint128, res uintptr) int32 {
if __ccgo_strace {
trc("t=%v b=%v res=%v, (%v:)", t, b, res, origin(2))
}
r, ovf := a.mulOvf(b)
*(*Uint128)(unsafe.Pointer(res)) = r
return Bool32(ovf)
}
func X__builtin_unreachable(t *TLS) {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
fmt.Fprintf(os.Stderr, "unrechable\n")
os.Stderr.Sync()
Xexit(t, 1)
}
func X__builtin_snprintf(t *TLS, str uintptr, size types.Size_t, format, args uintptr) int32 {
if __ccgo_strace {
trc("t=%v str=%v size=%v args=%v, (%v:)", t, str, size, args, origin(2))
}
return Xsnprintf(t, str, size, format, args)
}
func X__builtin_sprintf(t *TLS, str, format, args uintptr) (r int32) {
if __ccgo_strace {
trc("t=%v args=%v, (%v:)", t, args, origin(2))
defer func() { trc("-> %v", r) }()
}
return Xsprintf(t, str, format, args)
}
func X__builtin_memcpy(t *TLS, dest, src uintptr, n types.Size_t) (r uintptr) {
if __ccgo_strace {
trc("t=%v src=%v n=%v, (%v:)", t, src, n, origin(2))
defer func() { trc("-> %v", r) }()
}
return Xmemcpy(t, dest, src, n)
}
// void * __builtin___memcpy_chk (void *dest, const void *src, size_t n, size_t os);
func X__builtin___memcpy_chk(t *TLS, dest, src uintptr, n, os types.Size_t) (r uintptr) {
if __ccgo_strace {
trc("t=%v src=%v os=%v, (%v:)", t, src, os, origin(2))
defer func() { trc("-> %v", r) }()
}
if os != ^types.Size_t(0) && n < os {
Xabort(t)
}
return Xmemcpy(t, dest, src, n)
}
func X__builtin_memset(t *TLS, s uintptr, c int32, n types.Size_t) uintptr {
if __ccgo_strace {
trc("t=%v s=%v c=%v n=%v, (%v:)", t, s, c, n, origin(2))
}
return Xmemset(t, s, c, n)
}
// void * __builtin___memset_chk (void *s, int c, size_t n, size_t os);
func X__builtin___memset_chk(t *TLS, s uintptr, c int32, n, os types.Size_t) uintptr {
if __ccgo_strace {
trc("t=%v s=%v c=%v os=%v, (%v:)", t, s, c, os, origin(2))
}
if os < n {
Xabort(t)
}
return Xmemset(t, s, c, n)
}
// size_t __builtin_object_size (const void * ptr, int type)
func X__builtin_object_size(t *TLS, p uintptr, typ int32) types.Size_t {
if __ccgo_strace {
trc("t=%v p=%v typ=%v, (%v:)", t, p, typ, origin(2))
}
return ^types.Size_t(0) //TODO frontend magic
}
var atomicLoadStore16 sync.Mutex
func AtomicStoreNUint8(ptr uintptr, val uint8, memorder int32) {
a_store_8(ptr, val)
}
func AtomicStoreNUint16(ptr uintptr, val uint16, memorder int32) {
a_store_16(ptr, val)
}
// int sprintf(char *str, const char *format, ...);
func Xsprintf(t *TLS, str, format, args uintptr) (r int32) {
if __ccgo_strace {
trc("t=%v args=%v, (%v:)", t, args, origin(2))
defer func() { trc("-> %v", r) }()
}
b := printf(format, args)
r = int32(len(b))
copy((*RawMem)(unsafe.Pointer(str))[:r:r], b)
*(*byte)(unsafe.Pointer(str + uintptr(r))) = 0
return int32(len(b))
}
// int __builtin___sprintf_chk (char *s, int flag, size_t os, const char *fmt, ...);
func X__builtin___sprintf_chk(t *TLS, s uintptr, flag int32, os types.Size_t, format, args uintptr) (r int32) {
if __ccgo_strace {
trc("t=%v s=%v flag=%v os=%v args=%v, (%v:)", t, s, flag, os, args, origin(2))
defer func() { trc("-> %v", r) }()
}
return Xsprintf(t, s, format, args)
}
// void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
func Xqsort(t *TLS, base uintptr, nmemb, size types.Size_t, compar uintptr) {
if __ccgo_strace {
trc("t=%v base=%v size=%v compar=%v, (%v:)", t, base, size, compar, origin(2))
}
sort.Sort(&sorter{
len: int(nmemb),
base: base,
sz: uintptr(size),
f: (*struct {
f func(*TLS, uintptr, uintptr) int32
})(unsafe.Pointer(&struct{ uintptr }{compar})).f,
t: t,
})
}
// void __assert_fail(const char * assertion, const char * file, unsigned int line, const char * function);
func X__assert_fail(t *TLS, assertion, file uintptr, line uint32, function uintptr) {
if __ccgo_strace {
trc("t=%v file=%v line=%v function=%v, (%v:)", t, file, line, function, origin(2))
}
fmt.Fprintf(os.Stderr, "assertion failure: %s:%d.%s: %s\n", GoString(file), line, GoString(function), GoString(assertion))
if memgrind {
fmt.Fprintf(os.Stderr, "%s\n", debug.Stack())
}
os.Stderr.Sync()
Xexit(t, 1)
}
// int vprintf(const char *format, va_list ap);
func Xvprintf(t *TLS, s, ap uintptr) int32 {
if __ccgo_strace {
trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
}
return Xprintf(t, s, ap)
}
// int vsprintf(char *str, const char *format, va_list ap);
func Xvsprintf(t *TLS, str, format, va uintptr) int32 {
if __ccgo_strace {
trc("t=%v va=%v, (%v:)", t, va, origin(2))
}
return Xsprintf(t, str, format, va)
}
// int vsnprintf(char *str, size_t size, const char *format, va_list ap);
func Xvsnprintf(t *TLS, str uintptr, size types.Size_t, format, va uintptr) int32 {
if __ccgo_strace {
trc("t=%v str=%v size=%v va=%v, (%v:)", t, str, size, va, origin(2))
}
return Xsnprintf(t, str, size, format, va)
}
func X__builtin_vsnprintf(t *TLS, str uintptr, size types.Size_t, format, va uintptr) int32 {
if __ccgo_strace {
trc("t=%v str=%v size=%v va=%v, (%v:)", t, str, size, va, origin(2))
}
return Xvsnprintf(t, str, size, format, va)
}
// int obstack_vprintf (struct obstack *obstack, const char *template, va_list ap)
func Xobstack_vprintf(t *TLS, obstack, template, va uintptr) int32 {
if __ccgo_strace {
trc("t=%v va=%v, (%v:)", t, va, origin(2))
}
panic(todo(""))
}
// extern void _obstack_newchunk(struct obstack *, int);
func X_obstack_newchunk(t *TLS, obstack uintptr, length int32) int32 {
if __ccgo_strace {
trc("t=%v obstack=%v length=%v, (%v:)", t, obstack, length, origin(2))
}
panic(todo(""))
}
// int _obstack_begin (struct obstack *h, _OBSTACK_SIZE_T size, _OBSTACK_SIZE_T alignment, void *(*chunkfun) (size_t), void (*freefun) (void *))
func X_obstack_begin(t *TLS, obstack uintptr, size, alignment int32, chunkfun, freefun uintptr) int32 {
if __ccgo_strace {
trc("t=%v obstack=%v alignment=%v freefun=%v, (%v:)", t, obstack, alignment, freefun, origin(2))
}
panic(todo(""))
}
// void obstack_free (struct obstack *h, void *obj)
func Xobstack_free(t *TLS, obstack, obj uintptr) {
if __ccgo_strace {
trc("t=%v obj=%v, (%v:)", t, obj, origin(2))
}
panic(todo(""))
}
// unsigned int sleep(unsigned int seconds);
func Xsleep(t *TLS, seconds uint32) uint32 {
if __ccgo_strace {
trc("t=%v seconds=%v, (%v:)", t, seconds, origin(2))
}
gotime.Sleep(gotime.Second * gotime.Duration(seconds))
return 0
}
// size_t strcspn(const char *s, const char *reject);
func Xstrcspn(t *TLS, s, reject uintptr) (r types.Size_t) {
if __ccgo_strace {
trc("t=%v reject=%v, (%v:)", t, reject, origin(2))
defer func() { trc("-> %v", r) }()
}
bits := newBits(256)
for {
c := *(*byte)(unsafe.Pointer(reject))
if c == 0 {
break
}
reject++
bits.set(int(c))
}
for {
c := *(*byte)(unsafe.Pointer(s))
if c == 0 || bits.has(int(c)) {
return r
}
s++
r++
}
}
// int printf(const char *format, ...);
func Xprintf(t *TLS, format, args uintptr) int32 {
if __ccgo_strace {
trc("t=%v args=%v, (%v:)", t, args, origin(2))
}
n, _ := write(printf(format, args))
return int32(n)
}
// int snprintf(char *str, size_t size, const char *format, ...);
func Xsnprintf(t *TLS, str uintptr, size types.Size_t, format, args uintptr) (r int32) {
if __ccgo_strace {
trc("t=%v str=%v size=%v args=%v, (%v:)", t, str, size, args, origin(2))
defer func() { trc("-> %v", r) }()
}
if format == 0 {
return 0
}
b := printf(format, args)
r = int32(len(b))
if size == 0 {
return r
}
if len(b)+1 > int(size) {
b = b[:size-1]
}
n := len(b)
copy((*RawMem)(unsafe.Pointer(str))[:n:n], b)
*(*byte)(unsafe.Pointer(str + uintptr(n))) = 0
return r
}
// int __builtin___snprintf_chk(char * str, size_t maxlen, int flag, size_t os, const char * format, ...);
func X__builtin___snprintf_chk(t *TLS, str uintptr, maxlen types.Size_t, flag int32, os types.Size_t, format, args uintptr) (r int32) {
if __ccgo_strace {
trc("t=%v str=%v maxlen=%v flag=%v os=%v args=%v, (%v:)", t, str, maxlen, flag, os, args, origin(2))
defer func() { trc("-> %v", r) }()
}
if os != ^types.Size_t(0) && maxlen > os {
Xabort(t)
}
return Xsnprintf(t, str, maxlen, format, args)
}
// int __builtin___vsnprintf_chk (char *s, size_t maxlen, int flag, size_t os, const char *fmt, va_list ap);
func X__builtin___vsnprintf_chk(t *TLS, str uintptr, maxlen types.Size_t, flag int32, os types.Size_t, format, args uintptr) (r int32) {
if __ccgo_strace {
trc("t=%v str=%v maxlen=%v flag=%v os=%v args=%v, (%v:)", t, str, maxlen, flag, os, args, origin(2))
defer func() { trc("-> %v", r) }()
}
if os != ^types.Size_t(0) && maxlen > os {
Xabort(t)
}
return Xsnprintf(t, str, maxlen, format, args)
}
// int abs(int j);
func Xabs(t *TLS, j int32) int32 {
if __ccgo_strace {
trc("t=%v j=%v, (%v:)", t, j, origin(2))
}
if j >= 0 {
return j
}
return -j
}
// long abs(long j);
func Xlabs(t *TLS, j long) long {
if __ccgo_strace {
trc("t=%v j=%v, (%v:)", t, j, origin(2))
}
if j >= 0 {
return j
}
return -j
}
func Xllabs(tls *TLS, a int64) int64 {
if __ccgo_strace {
trc("tls=%v a=%v, (%v:)", tls, a, origin(2))
}
if a >= int64(0) {
return a
}
return -a
}
func X__builtin_isnan(t *TLS, x float64) int32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return Bool32(math.IsNaN(x))
}
func X__builtin_llabs(tls *TLS, a int64) int64 {
if __ccgo_strace {
trc("tls=%v a=%v, (%v:)", tls, a, origin(2))
}
return Xllabs(tls, a)
}
func Xacos(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Acos(x)
}
func Xacosf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Acos(float64(x)))
}
func Xacosh(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Acosh(x)
}
func Xacoshf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Acosh(float64(x)))
}
func Xasin(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Asin(x)
}
func Xasinf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Asin(float64(x)))
}
func Xasinh(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Asinh(x)
}
func Xasinhf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Asinh(float64(x)))
}
func Xatan(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Atan(x)
}
func Xatanf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Atan(float64(x)))
}
func Xatan2(t *TLS, x, y float64) float64 {
if __ccgo_strace {
trc("t=%v y=%v, (%v:)", t, y, origin(2))
}
return math.Atan2(x, y)
}
func Xatan2f(t *TLS, x, y float32) float32 {
if __ccgo_strace {
trc("t=%v y=%v, (%v:)", t, y, origin(2))
}
return float32(math.Atan2(float64(x), float64(y)))
}
func Xatanh(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Atanh(x)
}
func Xatanhf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Atanh(float64(x)))
}
func Xceil(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Ceil(x)
}
func Xceilf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Ceil(float64(x)))
}
func Xcopysign(t *TLS, x, y float64) float64 {
if __ccgo_strace {
trc("t=%v y=%v, (%v:)", t, y, origin(2))
}
return math.Copysign(x, y)
}
func Xcopysignf(t *TLS, x, y float32) float32 {
if __ccgo_strace {
trc("t=%v y=%v, (%v:)", t, y, origin(2))
}
return float32(math.Copysign(float64(x), float64(y)))
}
func Xcos(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Cos(x)
}
func Xcosf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Cos(float64(x)))
}
func Xcosh(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Cosh(x)
}
func Xcoshf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Cosh(float64(x)))
}
func Xexp(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Exp(x)
}
func Xexpf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Exp(float64(x)))
}
func Xfabs(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Abs(x)
}
func Xfabsf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Abs(float64(x)))
}
func Xfloor(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Floor(x)
}
func Xfloorf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Floor(float64(x)))
}
func Xfmod(t *TLS, x, y float64) float64 {
if __ccgo_strace {
trc("t=%v y=%v, (%v:)", t, y, origin(2))
}
return math.Mod(x, y)
}
func Xfmodf(t *TLS, x, y float32) float32 {
if __ccgo_strace {
trc("t=%v y=%v, (%v:)", t, y, origin(2))
}
return float32(math.Mod(float64(x), float64(y)))
}
func X__builtin_hypot(t *TLS, x float64, y float64) (r float64) {
return Xhypot(t, x, y)
}
func Xhypot(t *TLS, x, y float64) float64 {
if __ccgo_strace {
trc("t=%v y=%v, (%v:)", t, y, origin(2))
}
return math.Hypot(x, y)
}
func Xhypotf(t *TLS, x, y float32) float32 {
if __ccgo_strace {
trc("t=%v y=%v, (%v:)", t, y, origin(2))
}
return float32(math.Hypot(float64(x), float64(y)))
}
func Xisnan(t *TLS, x float64) int32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return X__builtin_isnan(t, x)
}
func Xisnanf(t *TLS, x float32) int32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return Bool32(math.IsNaN(float64(x)))
}
func Xisnanl(t *TLS, x float64) int32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return Bool32(math.IsNaN(x))
} // ccgo has to handle long double as double as Go does not support long double.
func Xldexp(t *TLS, x float64, exp int32) float64 {
if __ccgo_strace {
trc("t=%v x=%v exp=%v, (%v:)", t, x, exp, origin(2))
}
return math.Ldexp(x, int(exp))
}
func Xlog(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Log(x)
}
func Xlogf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Log(float64(x)))
}
func Xlog10(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Log10(x)
}
func Xlog10f(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Log10(float64(x)))
}
func X__builtin_log2(t *TLS, x float64) float64 {
return Xlog2(t, x)
}
func Xlog2(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Log2(x)
}
func Xlog2f(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Log2(float64(x)))
}
func Xround(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Round(x)
}
func Xroundf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Round(float64(x)))
}
func X__builtin_round(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Round(x)
}
func X__builtin_roundf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Round(float64(x)))
}
func Xsin(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Sin(x)
}
func Xsinf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Sin(float64(x)))
}
func Xsinh(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Sinh(x)
}
func Xsinhf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Sinh(float64(x)))
}
func Xsqrt(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Sqrt(x)
}
func Xsqrtf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Sqrt(float64(x)))
}
func Xtan(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Tan(x)
}
func Xtanf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Tan(float64(x)))
}
func Xtanh(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Tanh(x)
}
func Xtanhf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Tanh(float64(x)))
}
func Xtrunc(t *TLS, x float64) float64 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return math.Trunc(x)
}
func Xtruncf(t *TLS, x float32) float32 {
if __ccgo_strace {
trc("t=%v x=%v, (%v:)", t, x, origin(2))
}
return float32(math.Trunc(float64(x)))
}
var nextRand = uint64(1)
// int rand(void);
func Xrand(t *TLS) int32 {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
nextRand = nextRand*1103515245 + 12345
return int32(uint32(nextRand / (math.MaxUint32 + 1) % math.MaxInt32))
}
func Xpow(t *TLS, x, y float64) float64 {
if __ccgo_strace {
trc("t=%v y=%v, (%v:)", t, y, origin(2))
}
r := math.Pow(x, y)
if x > 0 && r == 1 && y >= -1.0000000000000000715e-18 && y < -1e-30 {
r = 0.9999999999999999
}
return r
}
func Xpowf(t *TLS, x, y float32) float32 {
if __ccgo_strace {
trc("t=%v y=%v, (%v:)", t, y, origin(2))
}
return float32(math.Pow(float64(x), float64(y)))
}
func Xfrexp(t *TLS, x float64, exp uintptr) float64 {
if __ccgo_strace {
trc("t=%v x=%v exp=%v, (%v:)", t, x, exp, origin(2))
}
f, e := math.Frexp(x)
*(*int32)(unsafe.Pointer(exp)) = int32(e)
return f
}
func Xfrexpf(t *TLS, x float32, exp uintptr) float32 {
if __ccgo_strace {
trc("t=%v x=%v exp=%v, (%v:)", t, x, exp, origin(2))
}
f, e := math.Frexp(float64(x))
*(*int32)(unsafe.Pointer(exp)) = int32(e)
return float32(f)
}
func Xmodf(t *TLS, x float64, iptr uintptr) float64 {
if __ccgo_strace {
trc("t=%v x=%v iptr=%v, (%v:)", t, x, iptr, origin(2))
}
i, f := math.Modf(x)
*(*float64)(unsafe.Pointer(iptr)) = i
return f
}
func Xmodff(t *TLS, x float32, iptr uintptr) float32 {
if __ccgo_strace {
trc("t=%v x=%v iptr=%v, (%v:)", t, x, iptr, origin(2))
}
i, f := math.Modf(float64(x))
*(*float32)(unsafe.Pointer(iptr)) = float32(i)
return float32(f)
}
// char *strncpy(char *dest, const char *src, size_t n)
func Xstrncpy(t *TLS, dest, src uintptr, n types.Size_t) (r uintptr) {
if __ccgo_strace {
trc("t=%v src=%v n=%v, (%v:)", t, src, n, origin(2))
defer func() { trc("-> %v", r) }()
}
r = dest
for c := *(*int8)(unsafe.Pointer(src)); c != 0 && n > 0; n-- {
*(*int8)(unsafe.Pointer(dest)) = c
dest++
src++
c = *(*int8)(unsafe.Pointer(src))
}
for ; uintptr(n) > 0; n-- {
*(*int8)(unsafe.Pointer(dest)) = 0
dest++
}
return r
}
// char * __builtin___strncpy_chk (char *dest, const char *src, size_t n, size_t os);
func X__builtin___strncpy_chk(t *TLS, dest, src uintptr, n, os types.Size_t) (r uintptr) {
if __ccgo_strace {
trc("t=%v src=%v os=%v, (%v:)", t, src, os, origin(2))
defer func() { trc("-> %v", r) }()
}
if n != ^types.Size_t(0) && os < n {
Xabort(t)
}
return Xstrncpy(t, dest, src, n)
}
// int strcmp(const char *s1, const char *s2)
func Xstrcmp(t *TLS, s1, s2 uintptr) int32 {
if __ccgo_strace {
trc("t=%v s2=%v, (%v:)", t, s2, origin(2))
}
for {
ch1 := *(*byte)(unsafe.Pointer(s1))
s1++
ch2 := *(*byte)(unsafe.Pointer(s2))
s2++
if ch1 != ch2 || ch1 == 0 || ch2 == 0 {
return int32(ch1) - int32(ch2)
}
}
}
// size_t strlen(const char *s)
func Xstrlen(t *TLS, s uintptr) (r types.Size_t) {
if __ccgo_strace {
trc("t=%v s=%v, (%v:)", t, s, origin(2))
defer func() { trc("-> %v", r) }()
}
if s == 0 {
return 0
}
for ; *(*int8)(unsafe.Pointer(s)) != 0; s++ {
r++
}
return r
}
// char *strcat(char *dest, const char *src)
func Xstrcat(t *TLS, dest, src uintptr) (r uintptr) {
if __ccgo_strace {
trc("t=%v src=%v, (%v:)", t, src, origin(2))
defer func() { trc("-> %v", r) }()
}
r = dest
for *(*int8)(unsafe.Pointer(dest)) != 0 {
dest++
}
for {
c := *(*int8)(unsafe.Pointer(src))
src++
*(*int8)(unsafe.Pointer(dest)) = c
dest++
if c == 0 {
return r
}
}
}
// char * __builtin___strcat_chk (char *dest, const char *src, size_t os);
func X__builtin___strcat_chk(t *TLS, dest, src uintptr, os types.Size_t) (r uintptr) {
if __ccgo_strace {
trc("t=%v src=%v os=%v, (%v:)", t, src, os, origin(2))
defer func() { trc("-> %v", r) }()
}
return Xstrcat(t, dest, src)
}
// int strncmp(const char *s1, const char *s2, size_t n)
func Xstrncmp(t *TLS, s1, s2 uintptr, n types.Size_t) int32 {
if __ccgo_strace {
trc("t=%v s2=%v n=%v, (%v:)", t, s2, n, origin(2))
}
var ch1, ch2 byte
for ; n != 0; n-- {
ch1 = *(*byte)(unsafe.Pointer(s1))
s1++
ch2 = *(*byte)(unsafe.Pointer(s2))
s2++
if ch1 != ch2 {
return int32(ch1) - int32(ch2)
}
if ch1 == 0 {
return 0
}
}
return 0
}
// char *strcpy(char *dest, const char *src)
func Xstrcpy(t *TLS, dest, src uintptr) (r uintptr) {
if __ccgo_strace {
trc("t=%v src=%v, (%v:)", t, src, origin(2))
defer func() { trc("-> %v", r) }()
}
r = dest
// src0 := src
for ; ; dest++ {
c := *(*int8)(unsafe.Pointer(src))
src++
*(*int8)(unsafe.Pointer(dest)) = c
if c == 0 {
return r
}
}
}
// char *strchr(const char *s, int c)
func Xstrchr(t *TLS, s uintptr, c int32) uintptr {
if __ccgo_strace {
trc("t=%v s=%v c=%v, (%v:)", t, s, c, origin(2))
}
for {
ch2 := *(*byte)(unsafe.Pointer(s))
if ch2 == byte(c) {
return s
}
if ch2 == 0 {
return 0
}
s++
}
}
// char *strrchr(const char *s, int c)
func Xstrrchr(t *TLS, s uintptr, c int32) (r uintptr) {
if __ccgo_strace {
trc("t=%v s=%v c=%v, (%v:)", t, s, c, origin(2))
defer func() { trc("-> %v", r) }()
}
for {
ch2 := *(*byte)(unsafe.Pointer(s))
if ch2 == 0 {
return r
}
if ch2 == byte(c) {
r = s
}
s++
}
}
// void *memset(void *s, int c, size_t n)
func Xmemset(t *TLS, dest uintptr, c int32, n types.Size_t) uintptr {
if __ccgo_strace {
trc("t=%v s=%v c=%v n=%v, (%v:)", t, dest, c, n, origin(2))
}
var c8 uint8
var c32 uint32
var c64 uint64
var k types.Size_t
var s uintptr
s = dest
/* Fill head and tail with minimal branching. Each
* conditional ensures that all the subsequently used
* offsets are well-defined and in the dest region. */
if n == 0 {
return dest
}
c8 = uint8(c)
*(*uint8)(unsafe.Pointer(s)) = c8
*(*uint8)(unsafe.Pointer(s + uintptr(n-1))) = c8
if n <= types.Size_t(2) {
return dest
}
*(*uint8)(unsafe.Pointer(s + 1)) = c8
*(*uint8)(unsafe.Pointer(s + 2)) = c8
*(*uint8)(unsafe.Pointer(s + uintptr(n-2))) = c8
*(*uint8)(unsafe.Pointer(s + uintptr(n-3))) = c8
if n <= types.Size_t(6) {
return dest
}
*(*uint8)(unsafe.Pointer(s + 3)) = c8
*(*uint8)(unsafe.Pointer(s + uintptr(n-4))) = c8
if n <= types.Size_t(8) {
return dest
}
/* Advance pointer to align it at a 4-byte boundary,
* and truncate n to a multiple of 4. The previous code
* already took care of any head/tail that get cut off
* by the alignment. */
k = -types.Size_t(s) & types.Size_t(3)
s += uintptr(k)
n -= k
n &= types.Size_t(-Int32FromInt32(4))
c32 = uint32(0x01010101) * uint32(c8)
/* In preparation to copy 32 bytes at a time, aligned on
* an 8-byte bounary, fill head/tail up to 28 bytes each.
* As in the initial byte-based head/tail fill, each
* conditional below ensures that the subsequent offsets
* are valid (e.g. !(n<=24) implies n>=28). */
*(*uint32)(unsafe.Pointer(s + uintptr(0))) = c32
*(*uint32)(unsafe.Pointer(s + uintptr(n-4))) = c32
if n <= types.Size_t(8) {
return dest
}
c64 = uint64(c32) | (uint64(c32) << 32)
*(*uint64)(unsafe.Pointer(s + uintptr(4))) = c64
*(*uint64)(unsafe.Pointer(s + uintptr(n-12))) = c64
if n <= types.Size_t(24) {
return dest
}
*(*uint64)(unsafe.Pointer(s + uintptr(12))) = c64
*(*uint64)(unsafe.Pointer(s + uintptr(20))) = c64
*(*uint64)(unsafe.Pointer(s + uintptr(n-28))) = c64
*(*uint64)(unsafe.Pointer(s + uintptr(n-20))) = c64
/* Align to a multiple of 8 so we can fill 64 bits at a time,
* and avoid writing the same bytes twice as much as is
* practical without introducing additional branching. */
k = types.Size_t(24) + types.Size_t(s)&types.Size_t(4)
s += uintptr(k)
n -= k
/* If this loop is reached, 28 tail bytes have already been
* filled, so any remainder when n drops below 32 can be
* safely ignored. */
for {
if !(n >= types.Size_t(32)) {
break
}
*(*uint64)(unsafe.Pointer(s + uintptr(0))) = c64
*(*uint64)(unsafe.Pointer(s + uintptr(8))) = c64
*(*uint64)(unsafe.Pointer(s + uintptr(16))) = c64
*(*uint64)(unsafe.Pointer(s + uintptr(24))) = c64
n -= types.Size_t(32)
s += uintptr(32)
}
return dest
}
// void *memcpy(void *dest, const void *src, size_t n);
func Xmemcpy(t *TLS, dest, src uintptr, n types.Size_t) (r uintptr) {
if __ccgo_strace {
trc("t=%v src=%v n=%v, (%v:)", t, src, n, origin(2))
defer func() { trc("-> %v", r) }()
}
if n != 0 {
copy((*RawMem)(unsafe.Pointer(dest))[:n:n], (*RawMem)(unsafe.Pointer(src))[:n:n])
}
return dest
}
// int memcmp(const void *s1, const void *s2, size_t n);
func Xmemcmp(t *TLS, s1, s2 uintptr, n types.Size_t) int32 {
if __ccgo_strace {
trc("t=%v s2=%v n=%v, (%v:)", t, s2, n, origin(2))
}
for ; n != 0; n-- {
c1 := *(*byte)(unsafe.Pointer(s1))
s1++
c2 := *(*byte)(unsafe.Pointer(s2))
s2++
if c1 < c2 {
return -1
}
if c1 > c2 {
return 1
}
}
return 0
}
// void *memchr(const void *s, int c, size_t n);
func Xmemchr(t *TLS, s uintptr, c int32, n types.Size_t) uintptr {
if __ccgo_strace {
trc("t=%v s=%v c=%v n=%v, (%v:)", t, s, c, n, origin(2))
}
for ; n != 0; n-- {
if *(*byte)(unsafe.Pointer(s)) == byte(c) {
return s
}
s++
}
return 0
}
// void *memmove(void *dest, const void *src, size_t n);
func Xmemmove(t *TLS, dest, src uintptr, n types.Size_t) uintptr {
if __ccgo_strace {
trc("t=%v src=%v n=%v, (%v:)", t, src, n, origin(2))
}
if n == 0 {
return dest
}
copy((*RawMem)(unsafe.Pointer(uintptr(dest)))[:n:n], (*RawMem)(unsafe.Pointer(uintptr(src)))[:n:n])
return dest
}
// void * __builtin___memmove_chk (void *dest, const void *src, size_t n, size_t os);
func X__builtin___memmove_chk(t *TLS, dest, src uintptr, n, os types.Size_t) uintptr {
if __ccgo_strace {
trc("t=%v src=%v os=%v, (%v:)", t, src, os, origin(2))
}
if os != ^types.Size_t(0) && os < n {
Xabort(t)
}
return Xmemmove(t, dest, src, n)
}
// char *getenv(const char *name);
func Xgetenv(t *TLS, name uintptr) uintptr {
if __ccgo_strace {
trc("t=%v name=%v, (%v:)", t, name, origin(2))
}
return getenv(Environ(), GoString(name))
}
func getenv(p uintptr, nm string) uintptr {
for ; ; p += uintptrSize {
q := *(*uintptr)(unsafe.Pointer(p))
if q == 0 {
return 0
}
s := GoString(q)
a := strings.SplitN(s, "=", 2)
if len(a) != 2 {
panic(todo("%q %q %q", nm, s, a))
}
if a[0] == nm {
return q + uintptr(len(nm)) + 1
}
}
}
// char *strstr(const char *haystack, const char *needle);
func Xstrstr(t *TLS, haystack, needle uintptr) uintptr {
if __ccgo_strace {
trc("t=%v needle=%v, (%v:)", t, needle, origin(2))
}
hs := GoString(haystack)
nd := GoString(needle)
if i := strings.Index(hs, nd); i >= 0 {
r := haystack + uintptr(i)
return r
}
return 0
}
// int putc(int c, FILE *stream);
func Xputc(t *TLS, c int32, fp uintptr) int32 {
if __ccgo_strace {
trc("t=%v c=%v fp=%v, (%v:)", t, c, fp, origin(2))
}
return Xfputc(t, c, fp)
}
// int atoi(const char *nptr);
func Xatoi(t *TLS, nptr uintptr) int32 {
if __ccgo_strace {
trc("t=%v nptr=%v, (%v:)", t, nptr, origin(2))
}
_, neg, _, n, _ := strToUint64(t, nptr, 10)
switch {
case neg:
return int32(-n)
default:
return int32(n)
}
}
// double atof(const char *nptr);
func Xatof(t *TLS, nptr uintptr) float64 {
if __ccgo_strace {
trc("t=%v nptr=%v, (%v:)", t, nptr, origin(2))
}
n, _ := strToFloatt64(t, nptr, 64)
// if dmesgs {
// dmesg("%v: %q: %v", origin(1), GoString(nptr), n)
// }
return n
}
// int tolower(int c);
func Xtolower(t *TLS, c int32) int32 {
if __ccgo_strace {
trc("t=%v c=%v, (%v:)", t, c, origin(2))
}
if c >= 'A' && c <= 'Z' {
return c + ('a' - 'A')
}
return c
}
// int toupper(int c);
func Xtoupper(t *TLS, c int32) int32 {
if __ccgo_strace {
trc("t=%v c=%v, (%v:)", t, c, origin(2))
}
if c >= 'a' && c <= 'z' {
return c - ('a' - 'A')
}
return c
}
// int isatty(int fd);
func Xisatty(t *TLS, fd int32) int32 {
if __ccgo_strace {
trc("t=%v fd=%v, (%v:)", t, fd, origin(2))
}
return Bool32(isatty.IsTerminal(uintptr(fd)))
}
// long atol(const char *nptr);
func Xatol(t *TLS, nptr uintptr) long {
if __ccgo_strace {
trc("t=%v nptr=%v, (%v:)", t, nptr, origin(2))
}
_, neg, _, n, _ := strToUint64(t, nptr, 10)
switch {
case neg:
return long(-n)
default:
return long(n)
}
}
func getLocalLocation() (loc *gotime.Location) {
loc = gotime.Local
if r := getenv(Environ(), "TZ"); r != 0 {
zname := GoString(r)
zone, off := parseZone(zname)
loc = gotime.FixedZone(zone, -off)
loc2, _ := gotime.LoadLocation(zname)
if loc2 != nil {
loc = loc2
}
}
return loc
}
// time_t mktime(struct tm *tm);
func Xmktime(t *TLS, ptm uintptr) time.Time_t {
if __ccgo_strace {
trc("t=%v ptm=%v, (%v:)", t, ptm, origin(2))
}
loc := getLocalLocation()
tt := gotime.Date(
int((*time.Tm)(unsafe.Pointer(ptm)).Ftm_year+1900),
gotime.Month((*time.Tm)(unsafe.Pointer(ptm)).Ftm_mon+1),
int((*time.Tm)(unsafe.Pointer(ptm)).Ftm_mday),
int((*time.Tm)(unsafe.Pointer(ptm)).Ftm_hour),
int((*time.Tm)(unsafe.Pointer(ptm)).Ftm_min),
int((*time.Tm)(unsafe.Pointer(ptm)).Ftm_sec),
0,
loc,
)
(*time.Tm)(unsafe.Pointer(ptm)).Ftm_wday = int32(tt.Weekday())
(*time.Tm)(unsafe.Pointer(ptm)).Ftm_yday = int32(tt.YearDay() - 1)
return time.Time_t(tt.Unix())
}
// char *strpbrk(const char *s, const char *accept);
func Xstrpbrk(t *TLS, s, accept uintptr) uintptr {
if __ccgo_strace {
trc("t=%v accept=%v, (%v:)", t, accept, origin(2))
}
bits := newBits(256)
for {
b := *(*byte)(unsafe.Pointer(accept))
if b == 0 {
break
}
bits.set(int(b))
accept++
}
for {
b := *(*byte)(unsafe.Pointer(s))
if b == 0 {
return 0
}
if bits.has(int(b)) {
return s
}
s++
}
}
// int strcasecmp(const char *s1, const char *s2);
func Xstrcasecmp(t *TLS, s1, s2 uintptr) int32 {
if __ccgo_strace {
trc("t=%v s2=%v, (%v:)", t, s2, origin(2))
}
for {
ch1 := *(*byte)(unsafe.Pointer(s1))
if ch1 >= 'a' && ch1 <= 'z' {
ch1 = ch1 - ('a' - 'A')
}
s1++
ch2 := *(*byte)(unsafe.Pointer(s2))
if ch2 >= 'a' && ch2 <= 'z' {
ch2 = ch2 - ('a' - 'A')
}
s2++
if ch1 != ch2 || ch1 == 0 || ch2 == 0 {
r := int32(ch1) - int32(ch2)
return r
}
}
}
func Xntohs(t *TLS, netshort uint16) uint16 {
if __ccgo_strace {
trc("t=%v netshort=%v, (%v:)", t, netshort, origin(2))
}
return uint16((*[2]byte)(unsafe.Pointer(&netshort))[0])<<8 | uint16((*[2]byte)(unsafe.Pointer(&netshort))[1])
}
// uint16_t htons(uint16_t hostshort);
func Xhtons(t *TLS, hostshort uint16) uint16 {
if __ccgo_strace {
trc("t=%v hostshort=%v, (%v:)", t, hostshort, origin(2))
}
var a [2]byte
a[0] = byte(hostshort >> 8)
a[1] = byte(hostshort)
return *(*uint16)(unsafe.Pointer(&a))
}
// uint32_t htonl(uint32_t hostlong);
func Xhtonl(t *TLS, hostlong uint32) uint32 {
if __ccgo_strace {
trc("t=%v hostlong=%v, (%v:)", t, hostlong, origin(2))
}
var a [4]byte
a[0] = byte(hostlong >> 24)
a[1] = byte(hostlong >> 16)
a[2] = byte(hostlong >> 8)
a[3] = byte(hostlong)
return *(*uint32)(unsafe.Pointer(&a))
}
// FILE *fopen(const char *pathname, const char *mode);
func Xfopen(t *TLS, pathname, mode uintptr) uintptr {
if __ccgo_strace {
trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
}
return Xfopen64(t, pathname, mode) //TODO 32 bit
}
func Dmesg(s string, args ...interface{}) {
if dmesgs {
dmesg(s, args...)
}
}
// void sqlite3_log(int iErrCode, const char *zFormat, ...);
func X__ccgo_sqlite3_log(t *TLS, iErrCode int32, zFormat uintptr, args uintptr) {
if __ccgo_strace {
trc("t=%v iErrCode=%v zFormat=%v args=%v, (%v:)", t, iErrCode, zFormat, args, origin(2))
}
// if dmesgs {
// dmesg("%v: iErrCode: %v, msg: %s\n%s", origin(1), iErrCode, printf(zFormat, args), debug.Stack())
// }
}
// int _IO_putc(int __c, _IO_FILE *__fp);
func X_IO_putc(t *TLS, c int32, fp uintptr) int32 {
if __ccgo_strace {
trc("t=%v c=%v fp=%v, (%v:)", t, c, fp, origin(2))
}
return Xputc(t, c, fp)
}
// int atexit(void (*function)(void));
func Xatexit(t *TLS, function uintptr) int32 {
if __ccgo_strace {
trc("t=%v function=%v, (%v:)", t, function, origin(2))
}
AtExit(func() {
(*struct{ f func(*TLS) })(unsafe.Pointer(&struct{ uintptr }{function})).f(t)
})
return 0
}
// int vasprintf(char **strp, const char *fmt, va_list ap);
func Xvasprintf(t *TLS, strp, fmt, ap uintptr) int32 {
if __ccgo_strace {
trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
}
panic(todo(""))
}
func AtomicLoadInt32(addr *int32) (val int32) { return atomic.LoadInt32(addr) }
func AtomicLoadInt64(addr *int64) (val int64) { return atomic.LoadInt64(addr) }
func AtomicLoadUint32(addr *uint32) (val uint32) { return atomic.LoadUint32(addr) }
func AtomicLoadUint64(addr *uint64) (val uint64) { return atomic.LoadUint64(addr) }
func AtomicLoadUintptr(addr *uintptr) (val uintptr) { return atomic.LoadUintptr(addr) }
func AtomicLoadFloat32(addr *float32) (val float32) {
return math.Float32frombits(atomic.LoadUint32((*uint32)(unsafe.Pointer(addr))))
}
func AtomicLoadFloat64(addr *float64) (val float64) {
return math.Float64frombits(atomic.LoadUint64((*uint64)(unsafe.Pointer(addr))))
}
func AtomicLoadPInt32(addr uintptr) (val int32) {
return atomic.LoadInt32((*int32)(unsafe.Pointer(addr)))
}
func AtomicLoadPInt64(addr uintptr) (val int64) {
return atomic.LoadInt64((*int64)(unsafe.Pointer(addr)))
}
func AtomicLoadPUint32(addr uintptr) (val uint32) {
return atomic.LoadUint32((*uint32)(unsafe.Pointer(addr)))
}
func AtomicLoadPUint64(addr uintptr) (val uint64) {
return atomic.LoadUint64((*uint64)(unsafe.Pointer(addr)))
}
func AtomicLoadPUintptr(addr uintptr) (val uintptr) {
return atomic.LoadUintptr((*uintptr)(unsafe.Pointer(addr)))
}
func AtomicLoadPFloat32(addr uintptr) (val float32) {
return math.Float32frombits(atomic.LoadUint32((*uint32)(unsafe.Pointer(addr))))
}
func AtomicLoadPFloat64(addr uintptr) (val float64) {
return math.Float64frombits(atomic.LoadUint64((*uint64)(unsafe.Pointer(addr))))
}
func AtomicStoreInt32(addr *int32, val int32) { atomic.StoreInt32(addr, val) }
func AtomicStoreInt64(addr *int64, val int64) { atomic.StoreInt64(addr, val) }
func AtomicStoreUint32(addr *uint32, val uint32) { atomic.StoreUint32(addr, val) }
func AtomicStoreUint64(addr *uint64, val uint64) { atomic.StoreUint64(addr, val) }
func AtomicStoreUintptr(addr *uintptr, val uintptr) { atomic.StoreUintptr(addr, val) }
func AtomicStoreFloat32(addr *float32, val float32) {
atomic.StoreUint32((*uint32)(unsafe.Pointer(addr)), math.Float32bits(val))
}
func AtomicStoreFloat64(addr *float64, val float64) {
atomic.StoreUint64((*uint64)(unsafe.Pointer(addr)), math.Float64bits(val))
}
func AtomicStorePInt32(addr uintptr, val int32) {
atomic.StoreInt32((*int32)(unsafe.Pointer(addr)), val)
}
func AtomicStorePInt64(addr uintptr, val int64) {
atomic.StoreInt64((*int64)(unsafe.Pointer(addr)), val)
}
func AtomicStorePUint32(addr uintptr, val uint32) {
atomic.StoreUint32((*uint32)(unsafe.Pointer(addr)), val)
}
func AtomicStorePUint64(addr uintptr, val uint64) {
atomic.StoreUint64((*uint64)(unsafe.Pointer(addr)), val)
}
func AtomicStorePUintptr(addr uintptr, val uintptr) {
atomic.StoreUintptr((*uintptr)(unsafe.Pointer(addr)), val)
}
func AtomicStorePFloat32(addr uintptr, val float32) {
atomic.StoreUint32((*uint32)(unsafe.Pointer(addr)), math.Float32bits(val))
}
func AtomicStorePFloat64(addr uintptr, val float64) {
atomic.StoreUint64((*uint64)(unsafe.Pointer(addr)), math.Float64bits(val))
}
func AtomicAddInt32(addr *int32, delta int32) (new int32) { return atomic.AddInt32(addr, delta) }
func AtomicAddInt64(addr *int64, delta int64) (new int64) { return atomic.AddInt64(addr, delta) }
func AtomicAddUint32(addr *uint32, delta uint32) (new uint32) { return atomic.AddUint32(addr, delta) }
func AtomicAddUint64(addr *uint64, delta uint64) (new uint64) { return atomic.AddUint64(addr, delta) }
func AtomicAddUintptr(addr *uintptr, delta uintptr) (new uintptr) {
return atomic.AddUintptr(addr, delta)
}
func AtomicAddFloat32(addr *float32, delta float32) (new float32) {
v := AtomicLoadFloat32(addr) + delta
AtomicStoreFloat32(addr, v)
return v
}
func AtomicAddFloat64(addr *float64, delta float64) (new float64) {
v := AtomicLoadFloat64(addr) + delta
AtomicStoreFloat64(addr, v)
return v
}
// size_t mbstowcs(wchar_t *dest, const char *src, size_t n);
func Xmbstowcs(t *TLS, dest, src uintptr, n types.Size_t) types.Size_t {
if __ccgo_strace {
trc("t=%v src=%v n=%v, (%v:)", t, src, n, origin(2))
}
panic(todo(""))
}
// int mbtowc(wchar_t *pwc, const char *s, size_t n);
func Xmbtowc(t *TLS, pwc, s uintptr, n types.Size_t) int32 {
if __ccgo_strace {
trc("t=%v s=%v n=%v, (%v:)", t, s, n, origin(2))
}
panic(todo(""))
}
// size_t __ctype_get_mb_cur_max(void);
func X__ctype_get_mb_cur_max(t *TLS) types.Size_t {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
panic(todo(""))
}
// int wctomb(char *s, wchar_t wc);
func Xwctomb(t *TLS, s uintptr, wc wchar_t) int32 {
if __ccgo_strace {
trc("t=%v s=%v wc=%v, (%v:)", t, s, wc, origin(2))
}
panic(todo(""))
}
// int mblen(const char *s, size_t n);
func Xmblen(t *TLS, s uintptr, n types.Size_t) int32 {
if __ccgo_strace {
trc("t=%v s=%v n=%v, (%v:)", t, s, n, origin(2))
}
panic(todo(""))
}
// ssize_t readv(int fd, const struct iovec *iov, int iovcnt);
func Xreadv(t *TLS, fd int32, iov uintptr, iovcnt int32) types.Ssize_t {
if __ccgo_strace {
trc("t=%v fd=%v iov=%v iovcnt=%v, (%v:)", t, fd, iov, iovcnt, origin(2))
}
panic(todo(""))
}
// int openpty(int *amaster, int *aslave, char *name,
//
// const struct termios *termp,
// const struct winsize *winp);
func Xopenpty(t *TLS, amaster, aslave, name, termp, winp uintptr) int32 {
if __ccgo_strace {
trc("t=%v winp=%v, (%v:)", t, winp, origin(2))
}
panic(todo(""))
}
// pid_t setsid(void);
func Xsetsid(t *TLS) types.Pid_t {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
panic(todo(""))
}
// int pselect(int nfds, fd_set *readfds, fd_set *writefds,
//
// fd_set *exceptfds, const struct timespec *timeout,
// const sigset_t *sigmask);
func Xpselect(t *TLS, nfds int32, readfds, writefds, exceptfds, timeout, sigmask uintptr) int32 {
if __ccgo_strace {
trc("t=%v nfds=%v sigmask=%v, (%v:)", t, nfds, sigmask, origin(2))
}
panic(todo(""))
}
// int kill(pid_t pid, int sig);
func Xkill(t *TLS, pid types.Pid_t, sig int32) int32 {
if __ccgo_strace {
trc("t=%v pid=%v sig=%v, (%v:)", t, pid, sig, origin(2))
}
panic(todo(""))
}
// int tcsendbreak(int fd, int duration);
func Xtcsendbreak(t *TLS, fd, duration int32) int32 {
if __ccgo_strace {
trc("t=%v duration=%v, (%v:)", t, duration, origin(2))
}
panic(todo(""))
}
// int wcwidth(wchar_t c);
func Xwcwidth(t *TLS, c wchar_t) int32 {
if __ccgo_strace {
trc("t=%v c=%v, (%v:)", t, c, origin(2))
}
panic(todo(""))
}
// int clock_gettime(clockid_t clk_id, struct timespec *tp);
func Xclock_gettime(t *TLS, clk_id int32, tp uintptr) int32 {
if __ccgo_strace {
trc("t=%v clk_id=%v tp=%v, (%v:)", t, clk_id, tp, origin(2))
}
panic(todo(""))
}
// AtExit will attempt to run f at process exit. The execution cannot be
// guaranteed, neither its ordering with respect to any other handlers
// registered by AtExit.
func AtExit(f func()) {
atExitMu.Lock()
atExit = append(atExit, f)
atExitMu.Unlock()
}
func X__ccgo_dmesg(t *TLS, fmt uintptr, va uintptr) {
if __ccgo_strace {
trc("t=%v fmt=%v va=%v, (%v:)", t, fmt, va, origin(2))
}
if dmesgs {
dmesg("%s", printf(fmt, va))
}
}
// int getentropy(void *buffer, size_t length);
//
// The getentropy() function writes length bytes of high-quality random data
// to the buffer starting at the location pointed to by buffer. The maximum
// permitted value for the length argument is 256.
func Xgetentropy(t *TLS, buffer uintptr, length size_t) int32 {
if __ccgo_strace {
trc("t=%v buffer=%v length=%v, (%v:)", t, buffer, length, origin(2))
}
const max = 256
switch {
case length == 0:
return 0
case buffer == 0:
t.setErrno(errno.EFAULT)
return -1
case length > max:
t.setErrno(errno.EIO)
return -1
}
if _, err := crand.Read((*RawMem)(unsafe.Pointer(buffer))[:length]); err != nil {
t.setErrno(errno.EIO)
return -1
}
return 0
}
// void * reallocarray(void *ptr, size_t nmemb, size_t size);
func Xreallocarray(t *TLS, ptr uintptr, nmemb, size size_t) uintptr {
if __ccgo_strace {
trc("t=%v ptr=%v size=%v, (%v:)", t, ptr, size, origin(2))
}
hi, lo := mathutil.MulUint128_64(uint64(nmemb), uint64(size))
if hi != 0 || lo > uint64(unsafe.Sizeof(RawMem{})) {
t.setErrno(errno.ENOMEM)
return 0
}
return Xrealloc(t, ptr, size_t(lo))
}
// int setjmp(jmp_buf env);
func Xsetjmp(t *TLS, env uintptr) int32 {
if __ccgo_strace {
trc("t=%v env=%v, (%v:)", t, env, origin(2))
}
return 0 //TODO
}
// void longjmp(jmp_buf env, int val);
func Xlongjmp(t *TLS, env uintptr, val int32) {
if __ccgo_strace {
trc("t=%v env=%v val=%v, (%v:)", t, env, val, origin(2))
}
panic(todo(""))
}
// https://linux.die.net/man/3/_setjmp
//
// The _longjmp() and _setjmp() functions shall be equivalent to longjmp() and
// setjmp(), respectively, with the additional restriction that _longjmp() and
// _setjmp() shall not manipulate the signal mask.
// int _setjmp(jmp_buf env);
func X_setjmp(t *TLS, env uintptr) int32 {
if __ccgo_strace {
trc("t=%v env=%v, (%v:)", t, env, origin(2))
}
return 0 //TODO
}
// void _longjmp(jmp_buf env, int val);
func X_longjmp(t *TLS, env uintptr, val int32) {
if __ccgo_strace {
trc("t=%v env=%v val=%v, (%v:)", t, env, val, origin(2))
}
panic(todo(""))
}
// unsigned __sync_add_and_fetch_uint32(*unsigned, unsigned)
func X__sync_add_and_fetch_uint32(t *TLS, p uintptr, v uint32) uint32 {
if __ccgo_strace {
trc("t=%v p=%v v=%v, (%v:)", t, p, v, origin(2))
}
return atomic.AddUint32((*uint32)(unsafe.Pointer(p)), v)
}
// unsigned __sync_sub_and_fetch_uint32(*unsigned, unsigned)
func X__sync_sub_and_fetch_uint32(t *TLS, p uintptr, v uint32) uint32 {
if __ccgo_strace {
trc("t=%v p=%v v=%v, (%v:)", t, p, v, origin(2))
}
return atomic.AddUint32((*uint32)(unsafe.Pointer(p)), -v)
}
// int sched_yield(void);
func Xsched_yield(t *TLS) {
if __ccgo_strace {
trc("t=%v, (%v:)", t, origin(2))
}
runtime.Gosched()
}
// int getc(FILE *stream);
func Xgetc(t *TLS, stream uintptr) int32 {
if __ccgo_strace {
trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
}
return Xfgetc(t, stream)
}
// char *fgets(char *s, int size, FILE *stream);
func Xfgets(t *TLS, s uintptr, size int32, stream uintptr) uintptr {
if __ccgo_strace {
trc("t=%v s=%v size=%v stream=%v, (%v:)", t, s, size, stream, origin(2))
}
var b []byte
out:
for ; size > 0; size-- {
switch c := Xfgetc(t, stream); c {
case '\n':
b = append(b, byte(c))
break out
case stdio.EOF:
break out
default:
b = append(b, byte(c))
}
}
if len(b) == 0 {
return 0
}
b = append(b, 0)
copy((*RawMem)(unsafe.Pointer(s))[:len(b):len(b)], b)
return s
}
// void bzero(void *s, size_t n);
func Xbzero(t *TLS, s uintptr, n types.Size_t) {
if __ccgo_strace {
trc("t=%v s=%v n=%v, (%v:)", t, s, n, origin(2))
}
b := (*RawMem)(unsafe.Pointer(s))[:n]
for i := range b {
b[i] = 0
}
}
// char *rindex(const char *s, int c);
func Xrindex(t *TLS, s uintptr, c int32) uintptr {
if __ccgo_strace {
trc("t=%v s=%v c=%v, (%v:)", t, s, c, origin(2))
}
if s == 0 {
return 0
}
var r uintptr
for {
c2 := int32(*(*byte)(unsafe.Pointer(s)))
if c2 == c {
r = s
}
if c2 == 0 {
return r
}
s++
}
}
// int isascii(int c);
func Xisascii(t *TLS, c int32) int32 {
if __ccgo_strace {
trc("t=%v c=%v, (%v:)", t, c, origin(2))
}
return Bool32(c >= 0 && c <= 0x7f)
}
func X__builtin_isunordered(t *TLS, a, b float64) int32 {
if __ccgo_strace {
trc("t=%v b=%v, (%v:)", t, b, origin(2))
}
return Bool32(math.IsNaN(a) || math.IsNaN(b))
}
func AtomicLoadNUint16(ptr uintptr, memorder int32) uint16 {
atomicLoadStore16.Lock()
r := *(*uint16)(unsafe.Pointer(ptr))
atomicLoadStore16.Unlock()
return r
}
func PreIncAtomicInt32P(p uintptr, d int32) int32 {
return atomic.AddInt32((*int32)(unsafe.Pointer(p)), d)
}
func PreIncAtomicInt64P(p uintptr, d int64) int64 {
return atomic.AddInt64((*int64)(unsafe.Pointer(p)), d)
}
func PreIncAtomicUint32P(p uintptr, d uint32) uint32 {
return atomic.AddUint32((*uint32)(unsafe.Pointer(p)), d)
}
func PreIncAtomicUint64P(p uintptr, d uint64) uint64 {
return atomic.AddUint64((*uint64)(unsafe.Pointer(p)), d)
}
func PreInrAtomicUintptrP(p uintptr, d uintptr) uintptr {
return atomic.AddUintptr((*uintptr)(unsafe.Pointer(p)), d)
}
func X__builtin_ffs(tls *TLS, i int32) (r int32) {
if __ccgo_strace {
trc("tls=%v i=%v, (%v:)", tls, i, origin(2))
defer func() { trc("-> %v", r) }()
}
return Xffs(tls, i)
}
func Xffs(tls *TLS, i int32) (r int32) {
if __ccgo_strace {
trc("tls=%v i=%v, (%v:)", tls, i, origin(2))
defer func() { trc("-> %v", r) }()
}
if i == 0 {
return 0
}
return int32(mbits.TrailingZeros32(uint32(i))) + 1
}
var _toint5 = Float32FromInt32(1) / Float32FromFloat32(1.1920928955078125e-07)
func X__builtin_rintf(tls *TLS, x float32) (r float32) {
return Xrintf(tls, x)
}
func Xrintf(tls *TLS, x float32) (r float32) {
if __ccgo_strace {
trc("tls=%v x=%v, (%v:)", tls, x, origin(2))
defer func() { trc("-> %v", r) }()
}
bp := tls.Alloc(16)
defer tls.Free(16)
var e, s int32
var y float32
var v1 float32
var _ /* u at bp+0 */ struct {
Fi [0]uint32
Ff float32
}
_, _, _, _ = e, s, y, v1
*(*struct {
Fi [0]uint32
Ff float32
})(unsafe.Pointer(bp)) = struct {
Fi [0]uint32
Ff float32
}{}
*(*float32)(unsafe.Pointer(bp)) = x
e = int32(*(*uint32)(unsafe.Pointer(bp)) >> int32(23) & uint32(0xff))
s = int32(*(*uint32)(unsafe.Pointer(bp)) >> int32(31))
if e >= Int32FromInt32(0x7f)+Int32FromInt32(23) {
return x
}
if s != 0 {
y = x - _toint5 + _toint5
} else {
y = x + _toint5 - _toint5
}
if y == Float32FromInt32(0) {
if s != 0 {
v1 = -Float32FromFloat32(0)
} else {
v1 = Float32FromFloat32(0)
}
return v1
}
return y
}
func X__builtin_lrintf(tls *TLS, x float32) (r long) {
return Xlrintf(tls, x)
}
func Xlrintf(tls *TLS, x float32) (r long) {
if __ccgo_strace {
trc("tls=%v x=%v, (%v:)", tls, x, origin(2))
defer func() { trc("-> %v", r) }()
}
return long(Xrintf(tls, x))
}
func X__builtin_lrint(tls *TLS, x float64) (r long) {
return Xlrint(tls, x)
}
func Xlrint(tls *TLS, x float64) (r long) {
if __ccgo_strace {
trc("tls=%v x=%v, (%v:)", tls, x, origin(2))
defer func() { trc("-> %v", r) }()
}
return long(Xrint(tls, x))
}
|