This file is indexed.

/usr/share/pocl/include/_kernel.h is in libpocl2-common 1.1-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
/* pocl/_kernel.h - OpenCL types and runtime library
   functions declarations. This should be included only from OpenCL C files.

   Copyright (c) 2011 Universidad Rey Juan Carlos
   Copyright (c) 2011-2017 Pekka Jääskeläinen / TUT
   Copyright (c) 2011-2013 Erik Schnetter <eschnetter@perimeterinstitute.ca>
                           Perimeter Institute for Theoretical Physics
   
   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:
   
   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.
   
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.
*/

/* If the -cl-std build option is not specified, the highest OpenCL C 1.x
 * language version supported by each device is used as the version of
 * OpenCL C when compiling the program for each device.
 */
#ifndef __OPENCL_C_VERSION__
#define __OPENCL_C_VERSION__ 120
#endif

#if (__OPENCL_C_VERSION__ > 99)
#define CL_VERSION_1_0 100
#endif

#if (__OPENCL_C_VERSION__ > 109)
#define CL_VERSION_1_1 110
#endif

#if (__OPENCL_C_VERSION__ > 119)
#define CL_VERSION_1_2 120
#endif

#if (__OPENCL_C_VERSION__ > 199)
#define CL_VERSION_2_0 200
#endif

#include "_enable_all_exts.h"

/* Enable double precision. This should really only be done when
   building the run-time library; when building application code, we
   should instead check a macro to see whether the application has
   enabled this. At the moment, always enable this seems fine, since
   all our target devices will support double precision anyway.

   FIX: this is not really true. TCE target is 32-bit scalars
   only. Seems the pragma does not add the macro, so we have the target
   define the macro and the pragma is conditionally enabled.
*/

/* Define some feature test macros to help write generic code */
#ifdef cl_khr_int64
#  define __IF_INT64(x) x
#else
#  define __IF_INT64(x)
#endif
#ifdef cl_khr_fp16
#  define __IF_FP16(x) x
#else
#  define __IF_FP16(x)
#endif
#ifdef cl_khr_fp64
#  define __IF_FP64(x) x
#else
#  define __IF_FP64(x)
#endif

#ifdef cl_khr_int64_base_atomics
#define __IF_BA64(x) x
#else
#define __IF_BA64(x)
#endif

#ifdef cl_khr_int64_extended_atomics
#define __IF_EA64(x) x
#else
#define __IF_EA64(x)
#endif

#include "_builtin_renames.h"

/* 3.9 needs access qualifier */
#if ((__clang_major__ < 4) && (__clang_minor__ < 9))

#undef CLANG_HAS_IMAGE_AS
#define IMG_WO_AQ
#define IMG_RO_AQ
#define IMG_RW_AQ

#else

#define CLANG_HAS_IMAGE_AS
#define IMG_RO_AQ __read_only
#define IMG_WO_AQ __write_only

#if (__OPENCL_C_VERSION__ > 199)
#define CLANG_HAS_RW_IMAGES
#define IMG_RW_AQ __read_write
#else
#undef CLANG_HAS_RW_IMAGES
#define IMG_RW_AQ __RW_IMAGES_UNSUPPORTED_BEFORE_CL_20
#endif

#endif

/* Image types (implementation).
 * Note: there is a duplicate definition in
 * lib/CL/devices/dev_image.h - keep in sync?
 */
typedef int dev_sampler_t;

typedef struct dev_image_t {
  void* _data;
  int _width;
  int _height;
  int _depth;
  int _image_array_size;
  int _row_pitch;
  int _slice_pitch;
  int _num_mip_levels; /* maybe not needed */
  int _num_samples; /* maybe not needed */
  int _order;
  int _data_type;
  int _num_channels;
  int _elem_size;
} dev_image_t;

#include "_builtin_renames.h"

/* A static assert statement to catch inconsistencies at build time */
#if __has_extension(__c_static_assert__)
#  define _CL_STATIC_ASSERT(_t, _x) _Static_assert(_x, #_t)
#else
#  define _CL_STATIC_ASSERT(_t, _x) typedef int __cl_ai##_t[(x) ? 1 : -1];
#endif

#if (__clang_major__ >= 4)

#ifndef _OPENCL_H_
/* Use the declarations shipped with Clang. */
/* Check for _OPENCL_H already here because the kernel compiler loads the
   header beforehand, but cannot find the file due to include paths not
   set up. */
#include <opencl-c.h>

#define __ovld __attribute__((overloadable))
#define __conv __attribute__((convergent))

// Optimizations
#define __purefn __attribute__((pure))
#define __cnfn __attribute__((const))

/* Missing declarations from opencl-c.h. Some of the geometric builtins are
   defined only up to 4 vectors, but we implement them all: */
#ifdef cl_khr_fp16
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
half __ovld __cnfn length(half8 p);
half __ovld __cnfn length(half16 p);

half __ovld __cnfn fast_length(half8 p);
half __ovld __cnfn fast_length(half16 p);

half8 __ovld __cnfn normalize(half8 p);
half16 __ovld __cnfn normalize(half16 p);

half8 __ovld __cnfn fast_normalize(half8 p);
half16 __ovld __cnfn fast_normalize(half16 p);

half __ovld __cnfn dot(half8 p0, half8 p1);
half __ovld __cnfn dot(half16 p0, half16 p1);
#endif

float __ovld __cnfn length(float8 p);
float __ovld __cnfn length(float16 p);

float __ovld __cnfn fast_length(float8 p);
float __ovld __cnfn fast_length(float16 p);

float8 __ovld __cnfn normalize(float8 p);
float16 __ovld __cnfn normalize(float16 p);

float8 __ovld __cnfn fast_normalize(float8 p);
float16 __ovld __cnfn fast_normalize(float16 p);

float __ovld __cnfn dot(float8 p0, float8 p1);
float __ovld __cnfn dot(float16 p0, float16 p1);

#ifdef cl_khr_fp64
#pragma OPENCL EXTENSION cl_khr_fp64 : enable

double __ovld __cnfn length(double8 p);
double __ovld __cnfn length(double16 p);

double __ovld __cnfn fast_length(double p);
double __ovld __cnfn fast_length(double2 p);
double __ovld __cnfn fast_length(double3 p);
double __ovld __cnfn fast_length(double4 p);
double __ovld __cnfn fast_length(double8 p);
double __ovld __cnfn fast_length(double16 p);

double8 __ovld __cnfn normalize(double8 p);
double16 __ovld __cnfn normalize(double16 p);

double8 __ovld __cnfn fast_normalize(double8 p);
double16 __ovld __cnfn fast_normalize(double16 p);

double __ovld __cnfn dot(double8 p0, double8 p1);
double __ovld __cnfn dot(double16 p0, double16 p1);

#endif

#undef __ovld
#undef __conv
#undef __purefn
#undef __cnfn

#include "_enable_all_exts.h"

#endif

/* GNU's libm seems to use INT_MIN here while the Clang's header uses
   INT_MAX. Both are allowed by the OpenCL specs. */
#undef FP_ILOGBNAN
#undef FP_ILOGB0
#define FP_ILOGBNAN INT_MIN
#define FP_ILOGB0 INT_MIN


/* Function/type attributes supported by Clang/SPIR */
#if __has_attribute(__always_inline__)
#  define _CL_ALWAYSINLINE __attribute__((__always_inline__))
#else
#  define _CL_ALWAYSINLINE
#endif
#if __has_attribute(__noinline__)
#  define _CL_NOINLINE __attribute__((__noinline__))
#else
#  define _CL_NOINLINE
#endif
#if __has_attribute(__overloadable__)
#  define _CL_OVERLOADABLE __attribute__((__overloadable__))
#else
#  define _CL_OVERLOADABLE
#endif
#if __has_attribute(__pure__)
#  define _CL_READONLY __attribute__((__pure__))
#else
#  define _CL_READONLY
#endif
#if __has_attribute(__const__)
#  define _CL_READNONE __attribute__((__const__))
#else
#  define _CL_READNONE
#endif

#else

/* Language feature detection */
/* must come after _enable_all_exts.h b/c of pocl_types.h*/
#include "_kernel_c.h"

/* required to be defined by the OpenCL standard, see:
   https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/preprocessorDirectives.html */
#define __kernel_exec(X, typen)                                               \
  __kernel __attribute__ ((work_group_size_hint (X, 1, 1)))                   \
      __attribute__ ((vec_type_hint (typen)))

/* Ensure the data types have the right sizes */
_CL_STATIC_ASSERT(char  , sizeof(char  ) == 1);
_CL_STATIC_ASSERT(char2 , sizeof(char2 ) == 2 *sizeof(char));
_CL_STATIC_ASSERT(char3 , sizeof(char3 ) == 4 *sizeof(char));
_CL_STATIC_ASSERT(char4 , sizeof(char4 ) == 4 *sizeof(char));
_CL_STATIC_ASSERT(char8 , sizeof(char8 ) == 8 *sizeof(char));
_CL_STATIC_ASSERT(char16, sizeof(char16) == 16*sizeof(char));

_CL_STATIC_ASSERT(uchar , sizeof(uchar ) == 1);
_CL_STATIC_ASSERT(uchar2 , sizeof(uchar2 ) == 2 *sizeof(uchar));
_CL_STATIC_ASSERT(uchar3 , sizeof(uchar3 ) == 4 *sizeof(uchar));
_CL_STATIC_ASSERT(uchar4 , sizeof(uchar4 ) == 4 *sizeof(uchar));
_CL_STATIC_ASSERT(uchar8 , sizeof(uchar8 ) == 8 *sizeof(uchar));
_CL_STATIC_ASSERT(uchar16, sizeof(uchar16) == 16*sizeof(uchar));

_CL_STATIC_ASSERT(short , sizeof(short ) == 2);
_CL_STATIC_ASSERT(short2 , sizeof(short2 ) == 2 *sizeof(short));
_CL_STATIC_ASSERT(short3 , sizeof(short3 ) == 4 *sizeof(short));
_CL_STATIC_ASSERT(short4 , sizeof(short4 ) == 4 *sizeof(short));
_CL_STATIC_ASSERT(short8 , sizeof(short8 ) == 8 *sizeof(short));
_CL_STATIC_ASSERT(short16, sizeof(short16) == 16*sizeof(short));

_CL_STATIC_ASSERT(ushort, sizeof(ushort) == 2);
_CL_STATIC_ASSERT(ushort2 , sizeof(ushort2 ) == 2 *sizeof(ushort));
_CL_STATIC_ASSERT(ushort3 , sizeof(ushort3 ) == 4 *sizeof(ushort));
_CL_STATIC_ASSERT(ushort4 , sizeof(ushort4 ) == 4 *sizeof(ushort));
_CL_STATIC_ASSERT(ushort8 , sizeof(ushort8 ) == 8 *sizeof(ushort));
_CL_STATIC_ASSERT(ushort16, sizeof(ushort16) == 16*sizeof(ushort));

_CL_STATIC_ASSERT(int   , sizeof(int   ) == 4);
_CL_STATIC_ASSERT(int2 , sizeof(int2 ) == 2 *sizeof(int));
_CL_STATIC_ASSERT(int3 , sizeof(int3 ) == 4 *sizeof(int));
_CL_STATIC_ASSERT(int4 , sizeof(int4 ) == 4 *sizeof(int));
_CL_STATIC_ASSERT(int8 , sizeof(int8 ) == 8 *sizeof(int));
_CL_STATIC_ASSERT(int16, sizeof(int16) == 16*sizeof(int));

_CL_STATIC_ASSERT(uint  , sizeof(uint  ) == 4);
_CL_STATIC_ASSERT(uint2 , sizeof(uint2 ) == 2 *sizeof(uint));
_CL_STATIC_ASSERT(uint3 , sizeof(uint3 ) == 4 *sizeof(uint));
_CL_STATIC_ASSERT(uint4 , sizeof(uint4 ) == 4 *sizeof(uint));
_CL_STATIC_ASSERT(uint8 , sizeof(uint8 ) == 8 *sizeof(uint));
_CL_STATIC_ASSERT(uint16, sizeof(uint16) == 16*sizeof(uint));

#ifdef cl_khr_int64 
_CL_STATIC_ASSERT(long  , sizeof(long  ) == 8);
_CL_STATIC_ASSERT(long2 , sizeof(long2 ) == 2 *sizeof(long));
_CL_STATIC_ASSERT(long3 , sizeof(long3 ) == 4 *sizeof(long));
_CL_STATIC_ASSERT(long4 , sizeof(long4 ) == 4 *sizeof(long));
_CL_STATIC_ASSERT(long8 , sizeof(long8 ) == 8 *sizeof(long));
_CL_STATIC_ASSERT(long16, sizeof(long16) == 16*sizeof(long));

_CL_STATIC_ASSERT(ulong  , sizeof(ulong  ) == 8);
_CL_STATIC_ASSERT(ulong2 , sizeof(ulong2 ) == 2 *sizeof(ulong));
_CL_STATIC_ASSERT(ulong3 , sizeof(ulong3 ) == 4 *sizeof(ulong));
_CL_STATIC_ASSERT(ulong4 , sizeof(ulong4 ) == 4 *sizeof(ulong));
_CL_STATIC_ASSERT(ulong8 , sizeof(ulong8 ) == 8 *sizeof(ulong));
_CL_STATIC_ASSERT(ulong16, sizeof(ulong16) == 16*sizeof(ulong));
#endif

#ifdef cl_khr_fp16
_CL_STATIC_ASSERT(half, sizeof(half) == 2);
_CL_STATIC_ASSERT(half2 , sizeof(half2 ) == 2 *sizeof(half));
_CL_STATIC_ASSERT(half3 , sizeof(half3 ) == 4 *sizeof(half));
_CL_STATIC_ASSERT(half4 , sizeof(half4 ) == 4 *sizeof(half));
_CL_STATIC_ASSERT(half8 , sizeof(half8 ) == 8 *sizeof(half));
_CL_STATIC_ASSERT(half16, sizeof(half16) == 16*sizeof(half));
#endif

_CL_STATIC_ASSERT(float , sizeof(float ) == 4);
_CL_STATIC_ASSERT(float2 , sizeof(float2 ) == 2 *sizeof(float));
_CL_STATIC_ASSERT(float3 , sizeof(float3 ) == 4 *sizeof(float));
_CL_STATIC_ASSERT(float4 , sizeof(float4 ) == 4 *sizeof(float));
_CL_STATIC_ASSERT(float8 , sizeof(float8 ) == 8 *sizeof(float));
_CL_STATIC_ASSERT(float16, sizeof(float16) == 16*sizeof(float));

#ifdef cl_khr_fp64
_CL_STATIC_ASSERT(double, sizeof(double) == 8);
_CL_STATIC_ASSERT(double2 , sizeof(double2 ) == 2 *sizeof(double));
_CL_STATIC_ASSERT(double3 , sizeof(double3 ) == 4 *sizeof(double));
_CL_STATIC_ASSERT(double4 , sizeof(double4 ) == 4 *sizeof(double));
_CL_STATIC_ASSERT(double8 , sizeof(double8 ) == 8 *sizeof(double));
_CL_STATIC_ASSERT(double16, sizeof(double16) == 16*sizeof(double));
#endif

_CL_STATIC_ASSERT(size_t, sizeof(size_t) == sizeof(void*));
_CL_STATIC_ASSERT(ptrdiff_t, sizeof(ptrdiff_t) == sizeof(void*));
_CL_STATIC_ASSERT(intptr_t, sizeof(intptr_t) == sizeof(void*));
_CL_STATIC_ASSERT(uintptr_t, sizeof(uintptr_t) == sizeof(void*));


/* Conversion functions */

#define _CL_DECLARE_AS_TYPE(SRC, DST)           \
  DST _CL_OVERLOADABLE as_##DST(SRC a);

/* 1 byte */
#define _CL_DECLARE_AS_TYPE_1(SRC)              \
  _CL_DECLARE_AS_TYPE(SRC, char)                \
  _CL_DECLARE_AS_TYPE(SRC, uchar)
_CL_DECLARE_AS_TYPE_1(char)
_CL_DECLARE_AS_TYPE_1(uchar)

/* 2 bytes */
#define _CL_DECLARE_AS_TYPE_2(SRC)              \
  _CL_DECLARE_AS_TYPE(SRC, char2)               \
  _CL_DECLARE_AS_TYPE(SRC, uchar2)              \
  _CL_DECLARE_AS_TYPE(SRC, short)               \
  _CL_DECLARE_AS_TYPE(SRC, ushort)              \
  __IF_FP16(_CL_DECLARE_AS_TYPE(SRC, half))
_CL_DECLARE_AS_TYPE_2(char2)
_CL_DECLARE_AS_TYPE_2(uchar2)
_CL_DECLARE_AS_TYPE_2(short)
_CL_DECLARE_AS_TYPE_2(ushort)
__IF_FP16(_CL_DECLARE_AS_TYPE_2(half))

/* 4 bytes */
#define _CL_DECLARE_AS_TYPE_4(SRC)                      \
  _CL_DECLARE_AS_TYPE(SRC, char4)                       \
  _CL_DECLARE_AS_TYPE(SRC, uchar4)                      \
  _CL_DECLARE_AS_TYPE(SRC, char3)                       \
  _CL_DECLARE_AS_TYPE(SRC, uchar3)                      \
  _CL_DECLARE_AS_TYPE(SRC, short2)                      \
  _CL_DECLARE_AS_TYPE(SRC, ushort2)                     \
  __IF_FP16(_CL_DECLARE_AS_TYPE(SRC, half2))            \
  _CL_DECLARE_AS_TYPE(SRC, int)                         \
  _CL_DECLARE_AS_TYPE(SRC, uint)                        \
  _CL_DECLARE_AS_TYPE(SRC, float)
_CL_DECLARE_AS_TYPE_4(char4)
_CL_DECLARE_AS_TYPE_4(uchar4)
_CL_DECLARE_AS_TYPE_4(char3)
_CL_DECLARE_AS_TYPE_4(uchar3)
_CL_DECLARE_AS_TYPE_4(short2)
_CL_DECLARE_AS_TYPE_4(ushort2)
__IF_FP16(_CL_DECLARE_AS_TYPE_4(half2))
_CL_DECLARE_AS_TYPE_4(int)
_CL_DECLARE_AS_TYPE_4(uint)
_CL_DECLARE_AS_TYPE_4(float)

/* 8 bytes */
#define _CL_DECLARE_AS_TYPE_8(SRC)                      \
  _CL_DECLARE_AS_TYPE(SRC, char8)                       \
  _CL_DECLARE_AS_TYPE(SRC, uchar8)                      \
  _CL_DECLARE_AS_TYPE(SRC, short4)                      \
  _CL_DECLARE_AS_TYPE(SRC, ushort4)                     \
  __IF_FP16(_CL_DECLARE_AS_TYPE(SRC, half4))            \
  _CL_DECLARE_AS_TYPE(SRC, short3)                      \
  _CL_DECLARE_AS_TYPE(SRC, ushort3)                     \
  __IF_FP16(_CL_DECLARE_AS_TYPE(SRC, half3))            \
  _CL_DECLARE_AS_TYPE(SRC, int2)                        \
  _CL_DECLARE_AS_TYPE(SRC, uint2)                       \
  __IF_INT64(_CL_DECLARE_AS_TYPE(SRC, long))            \
  __IF_INT64(_CL_DECLARE_AS_TYPE(SRC, ulong))           \
  _CL_DECLARE_AS_TYPE(SRC, float2)                      \
  __IF_FP64(_CL_DECLARE_AS_TYPE(SRC, double))
_CL_DECLARE_AS_TYPE_8(char8)
_CL_DECLARE_AS_TYPE_8(uchar8)
_CL_DECLARE_AS_TYPE_8(short4)
_CL_DECLARE_AS_TYPE_8(ushort4)
__IF_FP16(_CL_DECLARE_AS_TYPE_8(half4))
_CL_DECLARE_AS_TYPE_8(short3)
_CL_DECLARE_AS_TYPE_8(ushort3)
__IF_FP16(_CL_DECLARE_AS_TYPE_8(half3))
_CL_DECLARE_AS_TYPE_8(int2)
_CL_DECLARE_AS_TYPE_8(uint2)
__IF_INT64(_CL_DECLARE_AS_TYPE_8(long))
__IF_INT64(_CL_DECLARE_AS_TYPE_8(ulong))
_CL_DECLARE_AS_TYPE_8(float2)
__IF_FP64(_CL_DECLARE_AS_TYPE_8(double))

/* 16 bytes */
#define _CL_DECLARE_AS_TYPE_16(SRC)                     \
  _CL_DECLARE_AS_TYPE(SRC, char16)                      \
  _CL_DECLARE_AS_TYPE(SRC, uchar16)                     \
  _CL_DECLARE_AS_TYPE(SRC, short8)                      \
  _CL_DECLARE_AS_TYPE(SRC, ushort8)                     \
  __IF_FP16(_CL_DECLARE_AS_TYPE(SRC, half8))            \
  _CL_DECLARE_AS_TYPE(SRC, int4)                        \
  _CL_DECLARE_AS_TYPE(SRC, uint4)                       \
  _CL_DECLARE_AS_TYPE(SRC, int3)                        \
  _CL_DECLARE_AS_TYPE(SRC, uint3)                       \
  __IF_INT64(_CL_DECLARE_AS_TYPE(SRC, long2))           \
  __IF_INT64(_CL_DECLARE_AS_TYPE(SRC, ulong2))          \
  _CL_DECLARE_AS_TYPE(SRC, float4)                      \
  _CL_DECLARE_AS_TYPE(SRC, float3)                      \
  __IF_FP64(_CL_DECLARE_AS_TYPE(SRC, double2))
_CL_DECLARE_AS_TYPE_16(char16)
_CL_DECLARE_AS_TYPE_16(uchar16)
_CL_DECLARE_AS_TYPE_16(short8)
_CL_DECLARE_AS_TYPE_16(ushort8)
__IF_FP16(_CL_DECLARE_AS_TYPE_16(half8))
_CL_DECLARE_AS_TYPE_16(int4)
_CL_DECLARE_AS_TYPE_16(uint4)
_CL_DECLARE_AS_TYPE_16(int3)
_CL_DECLARE_AS_TYPE_16(uint3)
__IF_INT64(_CL_DECLARE_AS_TYPE_16(long2))
__IF_INT64(_CL_DECLARE_AS_TYPE_16(ulong2))
_CL_DECLARE_AS_TYPE_16(float4)
_CL_DECLARE_AS_TYPE_16(float3)
__IF_FP64(_CL_DECLARE_AS_TYPE_16(double2))

/* 32 bytes */
#define _CL_DECLARE_AS_TYPE_32(SRC)                     \
  _CL_DECLARE_AS_TYPE(SRC, short16)                     \
  _CL_DECLARE_AS_TYPE(SRC, ushort16)                    \
  __IF_FP16(_CL_DECLARE_AS_TYPE(SRC, half16))           \
  _CL_DECLARE_AS_TYPE(SRC, int8)                        \
  _CL_DECLARE_AS_TYPE(SRC, uint8)                       \
  __IF_INT64(_CL_DECLARE_AS_TYPE(SRC, long4))           \
  __IF_INT64(_CL_DECLARE_AS_TYPE(SRC, ulong4))          \
  __IF_INT64(_CL_DECLARE_AS_TYPE(SRC, long3))           \
  __IF_INT64(_CL_DECLARE_AS_TYPE(SRC, ulong3))          \
  _CL_DECLARE_AS_TYPE(SRC, float8)                      \
  __IF_FP64(_CL_DECLARE_AS_TYPE(SRC, double4))          \
  __IF_FP64(_CL_DECLARE_AS_TYPE(SRC, double3))
_CL_DECLARE_AS_TYPE_32(short16)
_CL_DECLARE_AS_TYPE_32(ushort16)
__IF_FP16(_CL_DECLARE_AS_TYPE_32(half16))
_CL_DECLARE_AS_TYPE_32(int8)
_CL_DECLARE_AS_TYPE_32(uint8)
__IF_INT64(_CL_DECLARE_AS_TYPE_32(long4))
__IF_INT64(_CL_DECLARE_AS_TYPE_32(ulong4))
__IF_INT64(_CL_DECLARE_AS_TYPE_32(long3))
__IF_INT64(_CL_DECLARE_AS_TYPE_32(ulong3))
_CL_DECLARE_AS_TYPE_32(float8)
__IF_FP64(_CL_DECLARE_AS_TYPE_32(double4))
__IF_FP64(_CL_DECLARE_AS_TYPE_32(double3))

/* 64 bytes */
#define _CL_DECLARE_AS_TYPE_64(SRC)             \
  _CL_DECLARE_AS_TYPE(SRC, int16)               \
  _CL_DECLARE_AS_TYPE(SRC, uint16)              \
  __IF_INT64(_CL_DECLARE_AS_TYPE(SRC, long8))   \
  __IF_INT64(_CL_DECLARE_AS_TYPE(SRC, ulong8))  \
  _CL_DECLARE_AS_TYPE(SRC, float16)             \
  __IF_FP64(_CL_DECLARE_AS_TYPE(SRC, double8))
_CL_DECLARE_AS_TYPE_64(int16)
_CL_DECLARE_AS_TYPE_64(uint16)
__IF_INT64(_CL_DECLARE_AS_TYPE_64(long8))
__IF_INT64(_CL_DECLARE_AS_TYPE_64(ulong8))
_CL_DECLARE_AS_TYPE_64(float16)
__IF_FP64(_CL_DECLARE_AS_TYPE_64(double8))

/* 128 bytes */
#define _CL_DECLARE_AS_TYPE_128(SRC)            \
  __IF_INT64(_CL_DECLARE_AS_TYPE(SRC, long16))  \
  __IF_INT64(_CL_DECLARE_AS_TYPE(SRC, ulong16)) \
  __IF_FP64(_CL_DECLARE_AS_TYPE(SRC, double16))
__IF_INT64(_CL_DECLARE_AS_TYPE_128(long16))
__IF_INT64(_CL_DECLARE_AS_TYPE_128(ulong16))
__IF_FP64(_CL_DECLARE_AS_TYPE_128(double16))

/* Conversions between builtin types.
 * 
 * Even though the OpenCL specification isn't entirely clear on this
 * matter, we implement all rounding mode combinations even for
 * integer-to-integer conversions. The rounding mode is essentially
 * redundant and thus ignored.
 *
 * Other OpenCL implementations seem to allow this in user code, and some
 * of the test suites/benchmarks out in the wild expect these functions
 * are available.
 *
 * Saturating conversions are only allowed when the destination type
 * is an integer.
 */

#define _CL_DECLARE_CONVERT_TYPE(SRC, DST, SIZE, INTSUFFIX, FLOATSUFFIX) \
  DST##SIZE _CL_OVERLOADABLE                                             \
  convert_##DST##SIZE##INTSUFFIX##FLOATSUFFIX(SRC##SIZE a);

#define _CL_DECLARE_CONVERT_TYPE_DST(SRC, SIZE, FLOATSUFFIX)            \
  _CL_DECLARE_CONVERT_TYPE(SRC, char  , SIZE,     , FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, char  , SIZE, _sat, FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, uchar , SIZE,     , FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, uchar , SIZE, _sat, FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, short , SIZE,     , FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, short , SIZE, _sat, FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, ushort, SIZE,     , FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, ushort, SIZE, _sat, FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, int   , SIZE,     , FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, int   , SIZE, _sat, FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, uint  , SIZE,     , FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, uint  , SIZE, _sat, FLOATSUFFIX)        \
  __IF_INT64(                                                           \
  _CL_DECLARE_CONVERT_TYPE(SRC, long  , SIZE,     , FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, long  , SIZE, _sat, FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, ulong , SIZE,     , FLOATSUFFIX)        \
  _CL_DECLARE_CONVERT_TYPE(SRC, ulong , SIZE, _sat, FLOATSUFFIX))       \
  __IF_FP16(                                                            \
  _CL_DECLARE_CONVERT_TYPE(SRC, half  , SIZE,     , FLOATSUFFIX))       \
  _CL_DECLARE_CONVERT_TYPE(SRC, float , SIZE,     , FLOATSUFFIX)        \
  __IF_FP64(                                                            \
  _CL_DECLARE_CONVERT_TYPE(SRC, double, SIZE,     , FLOATSUFFIX))

#define _CL_DECLARE_CONVERT_TYPE_SRC_DST(SIZE, FLOATSUFFIX) \
  _CL_DECLARE_CONVERT_TYPE_DST(char  , SIZE, FLOATSUFFIX)   \
  _CL_DECLARE_CONVERT_TYPE_DST(uchar , SIZE, FLOATSUFFIX)   \
  _CL_DECLARE_CONVERT_TYPE_DST(short , SIZE, FLOATSUFFIX)   \
  _CL_DECLARE_CONVERT_TYPE_DST(ushort, SIZE, FLOATSUFFIX)   \
  _CL_DECLARE_CONVERT_TYPE_DST(int   , SIZE, FLOATSUFFIX)   \
  _CL_DECLARE_CONVERT_TYPE_DST(uint  , SIZE, FLOATSUFFIX)   \
  __IF_INT64(                                               \
  _CL_DECLARE_CONVERT_TYPE_DST(long  , SIZE, FLOATSUFFIX)   \
  _CL_DECLARE_CONVERT_TYPE_DST(ulong , SIZE, FLOATSUFFIX))  \
  __IF_FP16(                                                \
  _CL_DECLARE_CONVERT_TYPE_DST(half  , SIZE, FLOATSUFFIX))  \
  _CL_DECLARE_CONVERT_TYPE_DST(float , SIZE, FLOATSUFFIX)   \
  __IF_FP64(                                                \
  _CL_DECLARE_CONVERT_TYPE_DST(double, SIZE, FLOATSUFFIX))

#define _CL_DECLARE_CONVERT_TYPE_SRC_DST_SIZE(FLOATSUFFIX) \
  _CL_DECLARE_CONVERT_TYPE_SRC_DST(  , FLOATSUFFIX)   \
  _CL_DECLARE_CONVERT_TYPE_SRC_DST( 2, FLOATSUFFIX)   \
  _CL_DECLARE_CONVERT_TYPE_SRC_DST( 3, FLOATSUFFIX)   \
  _CL_DECLARE_CONVERT_TYPE_SRC_DST( 4, FLOATSUFFIX)   \
  _CL_DECLARE_CONVERT_TYPE_SRC_DST( 8, FLOATSUFFIX)   \
  _CL_DECLARE_CONVERT_TYPE_SRC_DST(16, FLOATSUFFIX)

_CL_DECLARE_CONVERT_TYPE_SRC_DST_SIZE(    )
_CL_DECLARE_CONVERT_TYPE_SRC_DST_SIZE(_rtz)
_CL_DECLARE_CONVERT_TYPE_SRC_DST_SIZE(_rte)
_CL_DECLARE_CONVERT_TYPE_SRC_DST_SIZE(_rtp)
_CL_DECLARE_CONVERT_TYPE_SRC_DST_SIZE(_rtn)


/* Work-Item Functions */

uint _CL_OVERLOADABLE get_work_dim(void);
size_t _CL_OVERLOADABLE get_global_size(uint);
size_t _CL_OVERLOADABLE get_global_id(uint);
size_t _CL_OVERLOADABLE get_local_size(uint);
size_t _CL_OVERLOADABLE get_local_id(uint);
size_t _CL_OVERLOADABLE get_num_groups(uint);
size_t _CL_OVERLOADABLE get_group_id(uint);
size_t _CL_OVERLOADABLE get_global_offset(uint);

#if (__OPENCL_C_VERSION__ < 121)
void _CL_OVERLOADABLE read_mem_fence (cl_mem_fence_flags flags);
void _CL_OVERLOADABLE write_mem_fence (cl_mem_fence_flags flags);
void _CL_OVERLOADABLE mem_fence (cl_mem_fence_flags flags);
#endif

#if __has_attribute(__noduplicate__)
void _CL_OVERLOADABLE __attribute__ ((__noduplicate__))
barrier (cl_mem_fence_flags flags);
#else
void _CL_OVERLOADABLE barrier (cl_mem_fence_flags flags);
#endif

/* clang's header defines these */
#ifndef _OPENCL_H_

/* Math Constants */

/* half */

#ifdef cl_khr_fp16
#define HALF_DIG         3
#define HALF_MANT_DIG    11
#define HALF_MAX_10_EXP  +4
#define HALF_MAX_EXP     +16
#define HALF_MIN_10_EXP  -4
#define HALF_MIN_EXP     -13
#define HALF_RADIX       2
// #define HALF_MAX         0x1.ffcp15h
// #define HALF_MIN         0x1.0p-14h
// #define HALF_EPSILON     0x1.0p-10h
#define HALF_MAX         ((half)0x1.ffcp15f)
#define HALF_MIN         ((half)0x1.0p-14f)
#define HALF_EPSILON     ((half)0x1.0p-10f)

// #define M_E_H        2.71828182845904523536028747135h
// #define M_LOG2E_H    1.44269504088896340735992468100h
// #define M_LOG10E_H   0.434294481903251827651128918917h
// #define M_LN2_H      0.693147180559945309417232121458h
// #define M_LN10_H     2.30258509299404568401799145468h
// #define M_PI_H       3.14159265358979323846264338328h
// #define M_PI_2_H     1.57079632679489661923132169164h
// #define M_PI_4_H     0.785398163397448309615660845820h
// #define M_1_PI_H     0.318309886183790671537767526745h
// #define M_2_PI_H     0.636619772367581343075535053490h
// #define M_2_SQRTPI_H 1.12837916709551257389615890312h
// #define M_SQRT2_H    1.41421356237309504880168872421h
// #define M_SQRT1_2_H  0.707106781186547524400844362105h

#define M_E_H        ((half)2.71828182845904523536028747135f)
#define M_LOG2E_H    ((half)1.44269504088896340735992468100f)
#define M_LOG10E_H   ((half)0.434294481903251827651128918917f)
#define M_LN2_H      ((half)0.693147180559945309417232121458f)
#define M_LN10_H     ((half)2.30258509299404568401799145468f)
#define M_PI_H       ((half)3.14159265358979323846264338328f)
#define M_PI_2_H     ((half)1.57079632679489661923132169164f)
#define M_PI_4_H     ((half)0.785398163397448309615660845820f)
#define M_1_PI_H     ((half)0.318309886183790671537767526745f)
#define M_2_PI_H     ((half)0.636619772367581343075535053490f)
#define M_2_SQRTPI_H ((half)1.12837916709551257389615890312f)
#define M_SQRT2_H    ((half)1.41421356237309504880168872421f)
#define M_SQRT1_2_H  ((half)0.707106781186547524400844362105f)
#endif

/* float */

#define MAXFLOAT  FLT_MAX
#define HUGE_VALF __builtin_huge_valf()
#define INFINITY  __builtin_inff()
#define NAN       (0.0f/0.0f)

#define FLT_DIG        6
#define FLT_MANT_DIG   24
#define FLT_MAX_10_EXP +38
#define FLT_MAX_EXP    +128
#define FLT_MIN_10_EXP -37
#define FLT_MIN_EXP    -125
#define FLT_RADIX      2
#define FLT_MAX        0x1.fffffep127f
#define FLT_MIN        0x1.0p-126f
#define FLT_EPSILON    0x1.0p-23f
#define FLT_RADIX 2

#define FP_ILOGB0   INT_MIN
#define FP_ILOGBNAN INT_MIN

#define M_E_F        2.71828182845904523536028747135f
#define M_LOG2E_F    1.44269504088896340735992468100f
#define M_LOG10E_F   0.434294481903251827651128918917f
#define M_LN2_F      0.693147180559945309417232121458f
#define M_LN10_F     2.30258509299404568401799145468f
#define M_PI_F       3.14159265358979323846264338328f
#define M_PI_2_F     1.57079632679489661923132169164f
#define M_PI_4_F     0.785398163397448309615660845820f
#define M_1_PI_F     0.318309886183790671537767526745f
#define M_2_PI_F     0.636619772367581343075535053490f
#define M_2_SQRTPI_F 1.12837916709551257389615890312f
#define M_SQRT2_F    1.41421356237309504880168872421f
#define M_SQRT1_2_F  0.707106781186547524400844362105f

/* double */

#ifdef cl_khr_fp64
#define HUGE_VAL __builtin_huge_val()

#define DBL_DIG        15
#define DBL_MANT_DIG   53
#define DBL_MAX_10_EXP +308
#define DBL_MAX_EXP    +1024
#define DBL_MIN_10_EXP -307
#define DBL_MIN_EXP    -1021
#define DBL_MAX        0x1.fffffffffffffp1023
#define DBL_MIN        0x1.0p-1022
#define DBL_EPSILON    0x1.0p-52
#define DBL_RADIX 2

#define M_E        2.71828182845904523536028747135
#define M_LOG2E    1.44269504088896340735992468100
#define M_LOG10E   0.434294481903251827651128918917
#define M_LN2      0.693147180559945309417232121458
#define M_LN10     2.30258509299404568401799145468
#define M_PI       3.14159265358979323846264338328
#define M_PI_2     1.57079632679489661923132169164
#define M_PI_4     0.785398163397448309615660845820
#define M_1_PI     0.318309886183790671537767526745
#define M_2_PI     0.636619772367581343075535053490
#define M_2_SQRTPI 1.12837916709551257389615890312
#define M_SQRT2    1.41421356237309504880168872421
#define M_SQRT1_2  0.707106781186547524400844362105
#endif

#endif /* _OPENCL_H_ */

/* Math Functions */

/* Naming scheme:
 *    [NAME]_[R]_[A]*
 * where [R] is the return type, and [A] are the argument types:
 *    I: int
 *    J: vector of int
 *    U: vector of uint or ulong
 *    S: scalar (float or double)
 *    F: vector of float
 *    V: vector of float or double
 *    G: generic, any of the above
 */

#define _CL_DECLARE_FUNC_V_V(NAME)              \
  __IF_FP16(                                    \
  half     _CL_OVERLOADABLE NAME(half    );     \
  half2    _CL_OVERLOADABLE NAME(half2   );     \
  half3    _CL_OVERLOADABLE NAME(half3   );     \
  half4    _CL_OVERLOADABLE NAME(half4   );     \
  half8    _CL_OVERLOADABLE NAME(half8   );     \
  half16   _CL_OVERLOADABLE NAME(half16  );)    \
  float    _CL_OVERLOADABLE NAME(float   );     \
  float2   _CL_OVERLOADABLE NAME(float2  );     \
  float3   _CL_OVERLOADABLE NAME(float3  );     \
  float4   _CL_OVERLOADABLE NAME(float4  );     \
  float8   _CL_OVERLOADABLE NAME(float8  );     \
  float16  _CL_OVERLOADABLE NAME(float16 );     \
  __IF_FP64(                                    \
  double   _CL_OVERLOADABLE NAME(double  );     \
  double2  _CL_OVERLOADABLE NAME(double2 );     \
  double3  _CL_OVERLOADABLE NAME(double3 );     \
  double4  _CL_OVERLOADABLE NAME(double4 );     \
  double8  _CL_OVERLOADABLE NAME(double8 );     \
  double16 _CL_OVERLOADABLE NAME(double16);)

#define _CL_DECLARE_FUNC_V_VV(NAME)                     \
  __IF_FP16(                                            \
  half     _CL_OVERLOADABLE NAME(half    , half    );   \
  half2    _CL_OVERLOADABLE NAME(half2   , half2   );   \
  half3    _CL_OVERLOADABLE NAME(half3   , half3   );   \
  half4    _CL_OVERLOADABLE NAME(half4   , half4   );   \
  half8    _CL_OVERLOADABLE NAME(half8   , half8   );   \
  half16   _CL_OVERLOADABLE NAME(half16  , half16  );)  \
  float    _CL_OVERLOADABLE NAME(float   , float   );   \
  float2   _CL_OVERLOADABLE NAME(float2  , float2  );   \
  float3   _CL_OVERLOADABLE NAME(float3  , float3  );   \
  float4   _CL_OVERLOADABLE NAME(float4  , float4  );   \
  float8   _CL_OVERLOADABLE NAME(float8  , float8  );   \
  float16  _CL_OVERLOADABLE NAME(float16 , float16 );   \
  __IF_FP64(                                            \
  double   _CL_OVERLOADABLE NAME(double  , double  );   \
  double2  _CL_OVERLOADABLE NAME(double2 , double2 );   \
  double3  _CL_OVERLOADABLE NAME(double3 , double3 );   \
  double4  _CL_OVERLOADABLE NAME(double4 , double4 );   \
  double8  _CL_OVERLOADABLE NAME(double8 , double8 );   \
  double16 _CL_OVERLOADABLE NAME(double16, double16);)
#define _CL_DECLARE_FUNC_V_VVV(NAME)                                    \
  __IF_FP16(                                                            \
  half     _CL_OVERLOADABLE NAME(half    , half    , half  );           \
  half2    _CL_OVERLOADABLE NAME(half2   , half2   , half2 );           \
  half3    _CL_OVERLOADABLE NAME(half3   , half3   , half3 );           \
  half4    _CL_OVERLOADABLE NAME(half4   , half4   , half4 );           \
  half8    _CL_OVERLOADABLE NAME(half8   , half8   , half8 );           \
  half16   _CL_OVERLOADABLE NAME(half16  , half16  , half16);)          \
  float    _CL_OVERLOADABLE NAME(float   , float   , float   );         \
  float2   _CL_OVERLOADABLE NAME(float2  , float2  , float2  );         \
  float3   _CL_OVERLOADABLE NAME(float3  , float3  , float3  );         \
  float4   _CL_OVERLOADABLE NAME(float4  , float4  , float4  );         \
  float8   _CL_OVERLOADABLE NAME(float8  , float8  , float8  );         \
  float16  _CL_OVERLOADABLE NAME(float16 , float16 , float16 );         \
  __IF_FP64(                                                            \
  double   _CL_OVERLOADABLE NAME(double  , double  , double  );         \
  double2  _CL_OVERLOADABLE NAME(double2 , double2 , double2 );         \
  double3  _CL_OVERLOADABLE NAME(double3 , double3 , double3 );         \
  double4  _CL_OVERLOADABLE NAME(double4 , double4 , double4 );         \
  double8  _CL_OVERLOADABLE NAME(double8 , double8 , double8 );         \
  double16 _CL_OVERLOADABLE NAME(double16, double16, double16);)
#define _CL_DECLARE_FUNC_V_VVS(NAME)                            \
  __IF_FP16(                                                    \
  half2    _CL_OVERLOADABLE NAME(half2   , half2   , half  );   \
  half3    _CL_OVERLOADABLE NAME(half3   , half3   , half  );   \
  half4    _CL_OVERLOADABLE NAME(half4   , half4   , half  );   \
  half8    _CL_OVERLOADABLE NAME(half8   , half8   , half  );   \
  half16   _CL_OVERLOADABLE NAME(half16  , half16  , half  );)  \
  float2   _CL_OVERLOADABLE NAME(float2  , float2  , float );   \
  float3   _CL_OVERLOADABLE NAME(float3  , float3  , float );   \
  float4   _CL_OVERLOADABLE NAME(float4  , float4  , float );   \
  float8   _CL_OVERLOADABLE NAME(float8  , float8  , float );   \
  float16  _CL_OVERLOADABLE NAME(float16 , float16 , float );   \
  __IF_FP64(                                                    \
  double2  _CL_OVERLOADABLE NAME(double2 , double2 , double);   \
  double3  _CL_OVERLOADABLE NAME(double3 , double3 , double);   \
  double4  _CL_OVERLOADABLE NAME(double4 , double4 , double);   \
  double8  _CL_OVERLOADABLE NAME(double8 , double8 , double);   \
  double16 _CL_OVERLOADABLE NAME(double16, double16, double);)
#define _CL_DECLARE_FUNC_V_VSS(NAME)                            \
  __IF_FP16(                                                    \
  half2    _CL_OVERLOADABLE NAME(half2   , half  , half  );     \
  half3    _CL_OVERLOADABLE NAME(half3   , half  , half  );     \
  half4    _CL_OVERLOADABLE NAME(half4   , half  , half  );     \
  half8    _CL_OVERLOADABLE NAME(half8   , half  , half  );     \
  half16   _CL_OVERLOADABLE NAME(half16  , half  , half  );)    \
  float2   _CL_OVERLOADABLE NAME(float2  , float , float );     \
  float3   _CL_OVERLOADABLE NAME(float3  , float , float );     \
  float4   _CL_OVERLOADABLE NAME(float4  , float , float );     \
  float8   _CL_OVERLOADABLE NAME(float8  , float , float );     \
  float16  _CL_OVERLOADABLE NAME(float16 , float , float );     \
  __IF_FP64(                                                    \
  double2  _CL_OVERLOADABLE NAME(double2 , double, double);     \
  double3  _CL_OVERLOADABLE NAME(double3 , double, double);     \
  double4  _CL_OVERLOADABLE NAME(double4 , double, double);     \
  double8  _CL_OVERLOADABLE NAME(double8 , double, double);     \
  double16 _CL_OVERLOADABLE NAME(double16, double, double);)

#define _CL_DECLARE_FUNC_V_SSV(NAME)                            \
  __IF_FP16(                                                    \
  half2    _CL_OVERLOADABLE NAME(half  , half  , half2   );     \
  half3    _CL_OVERLOADABLE NAME(half  , half  , half3   );     \
  half4    _CL_OVERLOADABLE NAME(half  , half  , half4   );     \
  half8    _CL_OVERLOADABLE NAME(half  , half  , half8   );     \
  half16   _CL_OVERLOADABLE NAME(half  , half  , half16  );)    \
  float2   _CL_OVERLOADABLE NAME(float , float , float2  );     \
  float3   _CL_OVERLOADABLE NAME(float , float , float3  );     \
  float4   _CL_OVERLOADABLE NAME(float , float , float4  );     \
  float8   _CL_OVERLOADABLE NAME(float , float , float8  );     \
  float16  _CL_OVERLOADABLE NAME(float , float , float16 );     \
  __IF_FP64(                                                    \
  double2  _CL_OVERLOADABLE NAME(double, double, double2 );     \
  double3  _CL_OVERLOADABLE NAME(double, double, double3 );     \
  double4  _CL_OVERLOADABLE NAME(double, double, double4 );     \
  double8  _CL_OVERLOADABLE NAME(double, double, double8 );     \
  double16 _CL_OVERLOADABLE NAME(double, double, double16);)
#define _CL_DECLARE_FUNC_V_VVJ(NAME)                                    \
  __IF_FP16(                                                            \
  half     _CL_OVERLOADABLE NAME(half    , half    , short  );          \
  half2    _CL_OVERLOADABLE NAME(half2   , half2   , short2 );          \
  half3    _CL_OVERLOADABLE NAME(half3   , half3   , short3 );          \
  half4    _CL_OVERLOADABLE NAME(half4   , half4   , short4 );          \
  half8    _CL_OVERLOADABLE NAME(half8   , half8   , short8 );          \
  half16   _CL_OVERLOADABLE NAME(half16  , half16  , short16);)         \
  float    _CL_OVERLOADABLE NAME(float   , float   , int    );          \
  float2   _CL_OVERLOADABLE NAME(float2  , float2  , int2   );          \
  float3   _CL_OVERLOADABLE NAME(float3  , float3  , int3   );          \
  float4   _CL_OVERLOADABLE NAME(float4  , float4  , int4   );          \
  float8   _CL_OVERLOADABLE NAME(float8  , float8  , int8   );          \
  float16  _CL_OVERLOADABLE NAME(float16 , float16 , int16  );          \
  __IF_FP64(                                                            \
  double   _CL_OVERLOADABLE NAME(double  , double  , long   );          \
  double2  _CL_OVERLOADABLE NAME(double2 , double2 , long2  );          \
  double3  _CL_OVERLOADABLE NAME(double3 , double3 , long3  );          \
  double4  _CL_OVERLOADABLE NAME(double4 , double4 , long4  );          \
  double8  _CL_OVERLOADABLE NAME(double8 , double8 , long8  );          \
  double16 _CL_OVERLOADABLE NAME(double16, double16, long16 );)
#define _CL_DECLARE_FUNC_V_VVU(NAME)                                    \
  __IF_FP16(                                                            \
  half     _CL_OVERLOADABLE NAME(half    , half    , ushort  );         \
  half2    _CL_OVERLOADABLE NAME(half2   , half2   , ushort2 );         \
  half3    _CL_OVERLOADABLE NAME(half3   , half3   , ushort3 );         \
  half4    _CL_OVERLOADABLE NAME(half4   , half4   , ushort4 );         \
  half8    _CL_OVERLOADABLE NAME(half8   , half8   , ushort8 );         \
  half16   _CL_OVERLOADABLE NAME(half16  , half16  , ushort16);)        \
  float    _CL_OVERLOADABLE NAME(float   , float   , uint    );         \
  float2   _CL_OVERLOADABLE NAME(float2  , float2  , uint2   );         \
  float3   _CL_OVERLOADABLE NAME(float3  , float3  , uint3   );         \
  float4   _CL_OVERLOADABLE NAME(float4  , float4  , uint4   );         \
  float8   _CL_OVERLOADABLE NAME(float8  , float8  , uint8   );         \
  float16  _CL_OVERLOADABLE NAME(float16 , float16 , uint16  );         \
  __IF_FP64(                                                            \
  double   _CL_OVERLOADABLE NAME(double  , double  , ulong   );         \
  double2  _CL_OVERLOADABLE NAME(double2 , double2 , ulong2  );         \
  double3  _CL_OVERLOADABLE NAME(double3 , double3 , ulong3  );         \
  double4  _CL_OVERLOADABLE NAME(double4 , double4 , ulong4  );         \
  double8  _CL_OVERLOADABLE NAME(double8 , double8 , ulong8  );         \
  double16 _CL_OVERLOADABLE NAME(double16, double16, ulong16 );)
#define _CL_DECLARE_FUNC_V_U(NAME)              \
  __IF_FP16(                                    \
  half     _CL_OVERLOADABLE NAME(ushort  );     \
  half2    _CL_OVERLOADABLE NAME(ushort2 );     \
  half3    _CL_OVERLOADABLE NAME(ushort3 );     \
  half4    _CL_OVERLOADABLE NAME(ushort4 );     \
  half8    _CL_OVERLOADABLE NAME(ushort8 );     \
  half16   _CL_OVERLOADABLE NAME(ushort16);)    \
  float    _CL_OVERLOADABLE NAME(uint    );     \
  float2   _CL_OVERLOADABLE NAME(uint2   );     \
  float3   _CL_OVERLOADABLE NAME(uint3   );     \
  float4   _CL_OVERLOADABLE NAME(uint4   );     \
  float8   _CL_OVERLOADABLE NAME(uint8   );     \
  float16  _CL_OVERLOADABLE NAME(uint16  );     \
  __IF_FP64(                                    \
  double   _CL_OVERLOADABLE NAME(ulong   );     \
  double2  _CL_OVERLOADABLE NAME(ulong2  );     \
  double3  _CL_OVERLOADABLE NAME(ulong3  );     \
  double4  _CL_OVERLOADABLE NAME(ulong4  );     \
  double8  _CL_OVERLOADABLE NAME(ulong8  );     \
  double16 _CL_OVERLOADABLE NAME(ulong16 );)
#define _CL_DECLARE_FUNC_V_VS(NAME)                     \
  __IF_FP16(                                            \
  half2    _CL_OVERLOADABLE NAME(half2   , half  );     \
  half3    _CL_OVERLOADABLE NAME(half3   , half  );     \
  half4    _CL_OVERLOADABLE NAME(half4   , half  );     \
  half8    _CL_OVERLOADABLE NAME(half8   , half  );     \
  half16   _CL_OVERLOADABLE NAME(half16  , half  );)    \
  float2   _CL_OVERLOADABLE NAME(float2  , float );     \
  float3   _CL_OVERLOADABLE NAME(float3  , float );     \
  float4   _CL_OVERLOADABLE NAME(float4  , float );     \
  float8   _CL_OVERLOADABLE NAME(float8  , float );     \
  float16  _CL_OVERLOADABLE NAME(float16 , float );     \
  __IF_FP64(                                            \
  double2  _CL_OVERLOADABLE NAME(double2 , double);     \
  double3  _CL_OVERLOADABLE NAME(double3 , double);     \
  double4  _CL_OVERLOADABLE NAME(double4 , double);     \
  double8  _CL_OVERLOADABLE NAME(double8 , double);     \
  double16 _CL_OVERLOADABLE NAME(double16, double);)
#define _CL_DECLARE_FUNC_V_VJ(NAME)                     \
  __IF_FP16(                                            \
  half     _CL_OVERLOADABLE NAME(half    , int  );      \
  half2    _CL_OVERLOADABLE NAME(half2   , int2 );      \
  half3    _CL_OVERLOADABLE NAME(half3   , int3 );      \
  half4    _CL_OVERLOADABLE NAME(half4   , int4 );      \
  half8    _CL_OVERLOADABLE NAME(half8   , int8 );      \
  half16   _CL_OVERLOADABLE NAME(half16  , int16);)     \
  float    _CL_OVERLOADABLE NAME(float   , int  );      \
  float2   _CL_OVERLOADABLE NAME(float2  , int2 );      \
  float3   _CL_OVERLOADABLE NAME(float3  , int3 );      \
  float4   _CL_OVERLOADABLE NAME(float4  , int4 );      \
  float8   _CL_OVERLOADABLE NAME(float8  , int8 );      \
  float16  _CL_OVERLOADABLE NAME(float16 , int16);      \
  __IF_FP64(                                            \
  double   _CL_OVERLOADABLE NAME(double  , int  );      \
  double2  _CL_OVERLOADABLE NAME(double2 , int2 );      \
  double3  _CL_OVERLOADABLE NAME(double3 , int3 );      \
  double4  _CL_OVERLOADABLE NAME(double4 , int4 );      \
  double8  _CL_OVERLOADABLE NAME(double8 , int8 );      \
  double16 _CL_OVERLOADABLE NAME(double16, int16);)
#define _CL_DECLARE_FUNC_J_VV(NAME)                     \
  __IF_FP16(                                            \
  int     _CL_OVERLOADABLE NAME(half    , half    );    \
  short2  _CL_OVERLOADABLE NAME(half2   , half2   );    \
  short3  _CL_OVERLOADABLE NAME(half3   , half3   );    \
  short4  _CL_OVERLOADABLE NAME(half4   , half4   );    \
  short8  _CL_OVERLOADABLE NAME(half8   , half8   );    \
  short16 _CL_OVERLOADABLE NAME(half16  , half16  );)   \
  int     _CL_OVERLOADABLE NAME(float   , float   );    \
  int2    _CL_OVERLOADABLE NAME(float2  , float2  );    \
  int3    _CL_OVERLOADABLE NAME(float3  , float3  );    \
  int4    _CL_OVERLOADABLE NAME(float4  , float4  );    \
  int8    _CL_OVERLOADABLE NAME(float8  , float8  );    \
  int16   _CL_OVERLOADABLE NAME(float16 , float16 );    \
  __IF_FP64(                                            \
  int     _CL_OVERLOADABLE NAME(double  , double  );    \
  long2   _CL_OVERLOADABLE NAME(double2 , double2 );    \
  long3   _CL_OVERLOADABLE NAME(double3 , double3 );    \
  long4   _CL_OVERLOADABLE NAME(double4 , double4 );    \
  long8   _CL_OVERLOADABLE NAME(double8 , double8 );    \
  long16  _CL_OVERLOADABLE NAME(double16, double16);)
#define _CL_DECLARE_FUNC_V_VI(NAME)                     \
  __IF_FP16(                                            \
  half2    _CL_OVERLOADABLE NAME(half2   , int);        \
  half3    _CL_OVERLOADABLE NAME(half3   , int);        \
  half4    _CL_OVERLOADABLE NAME(half4   , int);        \
  half8    _CL_OVERLOADABLE NAME(half8   , int);        \
  half16   _CL_OVERLOADABLE NAME(half16  , int);)       \
  float2   _CL_OVERLOADABLE NAME(float2  , int);        \
  float3   _CL_OVERLOADABLE NAME(float3  , int);        \
  float4   _CL_OVERLOADABLE NAME(float4  , int);        \
  float8   _CL_OVERLOADABLE NAME(float8  , int);        \
  float16  _CL_OVERLOADABLE NAME(float16 , int);        \
  __IF_FP64(                                            \
  double2  _CL_OVERLOADABLE NAME(double2 , int);        \
  double3  _CL_OVERLOADABLE NAME(double3 , int);        \
  double4  _CL_OVERLOADABLE NAME(double4 , int);        \
  double8  _CL_OVERLOADABLE NAME(double8 , int);        \
  double16 _CL_OVERLOADABLE NAME(double16, int);)
#define _CL_DECLARE_FUNC_V_VPK(NAME)                                    \
  __IF_FP16(                                                            \
  half     _CL_OVERLOADABLE NAME(half    , __global  int     *);        \
  half2    _CL_OVERLOADABLE NAME(half2   , __global  int2    *);        \
  half3    _CL_OVERLOADABLE NAME(half3   , __global  int3    *);        \
  half4    _CL_OVERLOADABLE NAME(half4   , __global  int4    *);        \
  half8    _CL_OVERLOADABLE NAME(half8   , __global  int8    *);        \
  half16   _CL_OVERLOADABLE NAME(half16  , __global  int16   *);)       \
  float    _CL_OVERLOADABLE NAME(float   , __global  int     *);        \
  float2   _CL_OVERLOADABLE NAME(float2  , __global  int2    *);        \
  float3   _CL_OVERLOADABLE NAME(float3  , __global  int3    *);        \
  float4   _CL_OVERLOADABLE NAME(float4  , __global  int4    *);        \
  float8   _CL_OVERLOADABLE NAME(float8  , __global  int8    *);        \
  float16  _CL_OVERLOADABLE NAME(float16 , __global  int16   *);        \
  __IF_FP64(                                                            \
  double   _CL_OVERLOADABLE NAME(double  , __global  int     *);        \
  double2  _CL_OVERLOADABLE NAME(double2 , __global  int2    *);        \
  double3  _CL_OVERLOADABLE NAME(double3 , __global  int3    *);        \
  double4  _CL_OVERLOADABLE NAME(double4 , __global  int4    *);        \
  double8  _CL_OVERLOADABLE NAME(double8 , __global  int8    *);        \
  double16 _CL_OVERLOADABLE NAME(double16, __global  int16   *);)       \
  __IF_FP16(                                                            \
  half     _CL_OVERLOADABLE NAME(half    , __local   int     *);        \
  half2    _CL_OVERLOADABLE NAME(half2   , __local   int2    *);        \
  half3    _CL_OVERLOADABLE NAME(half3   , __local   int3    *);        \
  half4    _CL_OVERLOADABLE NAME(half4   , __local   int4    *);        \
  half8    _CL_OVERLOADABLE NAME(half8   , __local   int8    *);        \
  half16   _CL_OVERLOADABLE NAME(half16  , __local   int16   *);)       \
  float    _CL_OVERLOADABLE NAME(float   , __local   int     *);        \
  float2   _CL_OVERLOADABLE NAME(float2  , __local   int2    *);        \
  float3   _CL_OVERLOADABLE NAME(float3  , __local   int3    *);        \
  float4   _CL_OVERLOADABLE NAME(float4  , __local   int4    *);        \
  float8   _CL_OVERLOADABLE NAME(float8  , __local   int8    *);        \
  float16  _CL_OVERLOADABLE NAME(float16 , __local   int16   *);        \
  __IF_FP64(                                                            \
  double   _CL_OVERLOADABLE NAME(double  , __local   int     *);        \
  double2  _CL_OVERLOADABLE NAME(double2 , __local   int2    *);        \
  double3  _CL_OVERLOADABLE NAME(double3 , __local   int3    *);        \
  double4  _CL_OVERLOADABLE NAME(double4 , __local   int4    *);        \
  double8  _CL_OVERLOADABLE NAME(double8 , __local   int8    *);        \
  double16 _CL_OVERLOADABLE NAME(double16, __local   int16   *);)       \
  __IF_FP16(                                                            \
  half     _CL_OVERLOADABLE NAME(half    , __private int     *);        \
  half2    _CL_OVERLOADABLE NAME(half2   , __private int2    *);        \
  half3    _CL_OVERLOADABLE NAME(half3   , __private int3    *);        \
  half4    _CL_OVERLOADABLE NAME(half4   , __private int4    *);        \
  half8    _CL_OVERLOADABLE NAME(half8   , __private int8    *);        \
  half16   _CL_OVERLOADABLE NAME(half16  , __private int16   *);)       \
  float    _CL_OVERLOADABLE NAME(float   , __private int     *);        \
  float2   _CL_OVERLOADABLE NAME(float2  , __private int2    *);        \
  float3   _CL_OVERLOADABLE NAME(float3  , __private int3    *);        \
  float4   _CL_OVERLOADABLE NAME(float4  , __private int4    *);        \
  float8   _CL_OVERLOADABLE NAME(float8  , __private int8    *);        \
  float16  _CL_OVERLOADABLE NAME(float16 , __private int16   *);        \
  __IF_FP64(                                                            \
  double   _CL_OVERLOADABLE NAME(double  , __private int     *);        \
  double2  _CL_OVERLOADABLE NAME(double2 , __private int2    *);        \
  double3  _CL_OVERLOADABLE NAME(double3 , __private int3    *);        \
  double4  _CL_OVERLOADABLE NAME(double4 , __private int4    *);        \
  double8  _CL_OVERLOADABLE NAME(double8 , __private int8    *);        \
  double16 _CL_OVERLOADABLE NAME(double16, __private int16   *);)
#define _CL_DECLARE_FUNC_V_VVPK(NAME)                                   \
  __IF_FP16(                                                            \
  half     _CL_OVERLOADABLE NAME(half    , half    , __global  int     *);        \
  half2    _CL_OVERLOADABLE NAME(half2   , half2   , __global  int2    *);        \
  half3    _CL_OVERLOADABLE NAME(half3   , half3   , __global  int3    *);        \
  half4    _CL_OVERLOADABLE NAME(half4   , half4   , __global  int4    *);        \
  half8    _CL_OVERLOADABLE NAME(half8   , half8   , __global  int8    *);        \
  half16   _CL_OVERLOADABLE NAME(half16  , half16  , __global  int16   *);)       \
  float    _CL_OVERLOADABLE NAME(float   , float   , __global  int     *);        \
  float2   _CL_OVERLOADABLE NAME(float2  , float2  , __global  int2    *);        \
  float3   _CL_OVERLOADABLE NAME(float3  , float3  , __global  int3    *);        \
  float4   _CL_OVERLOADABLE NAME(float4  , float4  , __global  int4    *);        \
  float8   _CL_OVERLOADABLE NAME(float8  , float8  , __global  int8    *);        \
  float16  _CL_OVERLOADABLE NAME(float16 , float16 , __global  int16   *);        \
  __IF_FP64(                                                            \
  double   _CL_OVERLOADABLE NAME(double  , double  , __global  int     *);        \
  double2  _CL_OVERLOADABLE NAME(double2 , double2 , __global  int2    *);        \
  double3  _CL_OVERLOADABLE NAME(double3 , double3 , __global  int3    *);        \
  double4  _CL_OVERLOADABLE NAME(double4 , double4 , __global  int4    *);        \
  double8  _CL_OVERLOADABLE NAME(double8 , double8 , __global  int8    *);        \
  double16 _CL_OVERLOADABLE NAME(double16, double16, __global  int16   *);)       \
  __IF_FP16(                                                            \
  half     _CL_OVERLOADABLE NAME(half    , half    , __local   int     *);        \
  half2    _CL_OVERLOADABLE NAME(half2   , half2   , __local   int2    *);        \
  half3    _CL_OVERLOADABLE NAME(half3   , half3   , __local   int3    *);        \
  half4    _CL_OVERLOADABLE NAME(half4   , half4   , __local   int4    *);        \
  half8    _CL_OVERLOADABLE NAME(half8   , half8   , __local   int8    *);        \
  half16   _CL_OVERLOADABLE NAME(half16  , half16  , __local   int16   *);)       \
  float    _CL_OVERLOADABLE NAME(float   , float   , __local   int     *);        \
  float2   _CL_OVERLOADABLE NAME(float2  , float2  , __local   int2    *);        \
  float3   _CL_OVERLOADABLE NAME(float3  , float3  , __local   int3    *);        \
  float4   _CL_OVERLOADABLE NAME(float4  , float4  , __local   int4    *);        \
  float8   _CL_OVERLOADABLE NAME(float8  , float8  , __local   int8    *);        \
  float16  _CL_OVERLOADABLE NAME(float16 , float16 , __local   int16   *);        \
  __IF_FP64(                                                            \
  double   _CL_OVERLOADABLE NAME(double  , double  , __local   int     *);        \
  double2  _CL_OVERLOADABLE NAME(double2 , double2 , __local   int2    *);        \
  double3  _CL_OVERLOADABLE NAME(double3 , double3 , __local   int3    *);        \
  double4  _CL_OVERLOADABLE NAME(double4 , double4 , __local   int4    *);        \
  double8  _CL_OVERLOADABLE NAME(double8 , double8 , __local   int8    *);        \
  double16 _CL_OVERLOADABLE NAME(double16, double16, __local   int16   *);)       \
  __IF_FP16(                                                            \
  half     _CL_OVERLOADABLE NAME(half    , half    , __private int     *);        \
  half2    _CL_OVERLOADABLE NAME(half2   , half2   , __private int2    *);        \
  half3    _CL_OVERLOADABLE NAME(half3   , half3   , __private int3    *);        \
  half4    _CL_OVERLOADABLE NAME(half4   , half4   , __private int4    *);        \
  half8    _CL_OVERLOADABLE NAME(half8   , half8   , __private int8    *);        \
  half16   _CL_OVERLOADABLE NAME(half16  , half16  , __private int16   *);)       \
  float    _CL_OVERLOADABLE NAME(float   , float   , __private int     *);        \
  float2   _CL_OVERLOADABLE NAME(float2  , float2  , __private int2    *);        \
  float3   _CL_OVERLOADABLE NAME(float3  , float3  , __private int3    *);        \
  float4   _CL_OVERLOADABLE NAME(float4  , float4  , __private int4    *);        \
  float8   _CL_OVERLOADABLE NAME(float8  , float8  , __private int8    *);        \
  float16  _CL_OVERLOADABLE NAME(float16 , float16 , __private int16   *);        \
  __IF_FP64(                                                            \
  double   _CL_OVERLOADABLE NAME(double  , double  , __private int     *);        \
  double2  _CL_OVERLOADABLE NAME(double2 , double2 , __private int2    *);        \
  double3  _CL_OVERLOADABLE NAME(double3 , double3 , __private int3    *);        \
  double4  _CL_OVERLOADABLE NAME(double4 , double4 , __private int4    *);        \
  double8  _CL_OVERLOADABLE NAME(double8 , double8 , __private int8    *);        \
  double16 _CL_OVERLOADABLE NAME(double16, double16, __private int16   *);)


#define _CL_DECLARE_FUNC_V_VPV(NAME)                                    \
  __IF_FP16(                                                            \
  half     _CL_OVERLOADABLE NAME(half    , __global  half    *);        \
  half2    _CL_OVERLOADABLE NAME(half2   , __global  half2   *);        \
  half3    _CL_OVERLOADABLE NAME(half3   , __global  half3   *);        \
  half4    _CL_OVERLOADABLE NAME(half4   , __global  half4   *);        \
  half8    _CL_OVERLOADABLE NAME(half8   , __global  half8   *);        \
  half16   _CL_OVERLOADABLE NAME(half16  , __global  half16  *);)       \
  float    _CL_OVERLOADABLE NAME(float   , __global  float   *);        \
  float2   _CL_OVERLOADABLE NAME(float2  , __global  float2  *);        \
  float3   _CL_OVERLOADABLE NAME(float3  , __global  float3  *);        \
  float4   _CL_OVERLOADABLE NAME(float4  , __global  float4  *);        \
  float8   _CL_OVERLOADABLE NAME(float8  , __global  float8  *);        \
  float16  _CL_OVERLOADABLE NAME(float16 , __global  float16 *);        \
  __IF_FP64(                                                            \
  double   _CL_OVERLOADABLE NAME(double  , __global  double  *);        \
  double2  _CL_OVERLOADABLE NAME(double2 , __global  double2 *);        \
  double3  _CL_OVERLOADABLE NAME(double3 , __global  double3 *);        \
  double4  _CL_OVERLOADABLE NAME(double4 , __global  double4 *);        \
  double8  _CL_OVERLOADABLE NAME(double8 , __global  double8 *);        \
  double16 _CL_OVERLOADABLE NAME(double16, __global  double16*);)       \
  __IF_FP16(                                                            \
  half     _CL_OVERLOADABLE NAME(half    , __local   half    *);        \
  half2    _CL_OVERLOADABLE NAME(half2   , __local   half2   *);        \
  half3    _CL_OVERLOADABLE NAME(half3   , __local   half3   *);        \
  half4    _CL_OVERLOADABLE NAME(half4   , __local   half4   *);        \
  half8    _CL_OVERLOADABLE NAME(half8   , __local   half8   *);        \
  half16   _CL_OVERLOADABLE NAME(half16  , __local   half16  *);)       \
  float    _CL_OVERLOADABLE NAME(float   , __local   float   *);        \
  float2   _CL_OVERLOADABLE NAME(float2  , __local   float2  *);        \
  float3   _CL_OVERLOADABLE NAME(float3  , __local   float3  *);        \
  float4   _CL_OVERLOADABLE NAME(float4  , __local   float4  *);        \
  float8   _CL_OVERLOADABLE NAME(float8  , __local   float8  *);        \
  float16  _CL_OVERLOADABLE NAME(float16 , __local   float16 *);        \
  __IF_FP64(                                                            \
  double   _CL_OVERLOADABLE NAME(double  , __local   double  *);        \
  double2  _CL_OVERLOADABLE NAME(double2 , __local   double2 *);        \
  double3  _CL_OVERLOADABLE NAME(double3 , __local   double3 *);        \
  double4  _CL_OVERLOADABLE NAME(double4 , __local   double4 *);        \
  double8  _CL_OVERLOADABLE NAME(double8 , __local   double8 *);        \
  double16 _CL_OVERLOADABLE NAME(double16, __local   double16*);)       \
  __IF_FP16(                                                            \
  half     _CL_OVERLOADABLE NAME(half    , __private half    *);        \
  half2    _CL_OVERLOADABLE NAME(half2   , __private half2   *);        \
  half3    _CL_OVERLOADABLE NAME(half3   , __private half3   *);        \
  half4    _CL_OVERLOADABLE NAME(half4   , __private half4   *);        \
  half8    _CL_OVERLOADABLE NAME(half8   , __private half8   *);        \
  half16   _CL_OVERLOADABLE NAME(half16  , __private half16  *);)       \
  float    _CL_OVERLOADABLE NAME(float   , __private float   *);        \
  float2   _CL_OVERLOADABLE NAME(float2  , __private float2  *);        \
  float3   _CL_OVERLOADABLE NAME(float3  , __private float3  *);        \
  float4   _CL_OVERLOADABLE NAME(float4  , __private float4  *);        \
  float8   _CL_OVERLOADABLE NAME(float8  , __private float8  *);        \
  float16  _CL_OVERLOADABLE NAME(float16 , __private float16 *);        \
  __IF_FP64(                                                            \
  double   _CL_OVERLOADABLE NAME(double  , __private double  *);        \
  double2  _CL_OVERLOADABLE NAME(double2 , __private double2 *);        \
  double3  _CL_OVERLOADABLE NAME(double3 , __private double3 *);        \
  double4  _CL_OVERLOADABLE NAME(double4 , __private double4 *);        \
  double8  _CL_OVERLOADABLE NAME(double8 , __private double8 *);        \
  double16 _CL_OVERLOADABLE NAME(double16, __private double16*);)
#define _CL_DECLARE_FUNC_V_SV(NAME)                     \
  __IF_FP16(                                            \
  half2    _CL_OVERLOADABLE NAME(half  , half2   );     \
  half3    _CL_OVERLOADABLE NAME(half  , half3   );     \
  half4    _CL_OVERLOADABLE NAME(half  , half4   );     \
  half8    _CL_OVERLOADABLE NAME(half  , half8   );     \
  half16   _CL_OVERLOADABLE NAME(half  , half16  );)    \
  float2   _CL_OVERLOADABLE NAME(float , float2  );     \
  float3   _CL_OVERLOADABLE NAME(float , float3  );     \
  float4   _CL_OVERLOADABLE NAME(float , float4  );     \
  float8   _CL_OVERLOADABLE NAME(float , float8  );     \
  float16  _CL_OVERLOADABLE NAME(float , float16 );     \
  __IF_FP64(                                            \
  double2  _CL_OVERLOADABLE NAME(double, double2 );     \
  double3  _CL_OVERLOADABLE NAME(double, double3 );     \
  double4  _CL_OVERLOADABLE NAME(double, double4 );     \
  double8  _CL_OVERLOADABLE NAME(double, double8 );     \
  double16 _CL_OVERLOADABLE NAME(double, double16);)
#define _CL_DECLARE_FUNC_J_V(NAME)              \
  __IF_FP16(                                    \
  int     _CL_OVERLOADABLE NAME(half    );      \
  short2  _CL_OVERLOADABLE NAME(half2   );      \
  short3  _CL_OVERLOADABLE NAME(half3   );      \
  short4  _CL_OVERLOADABLE NAME(half4   );      \
  short8  _CL_OVERLOADABLE NAME(half8   );      \
  short16 _CL_OVERLOADABLE NAME(half16  );)     \
  int     _CL_OVERLOADABLE NAME(float   );      \
  int2    _CL_OVERLOADABLE NAME(float2  );      \
  int3    _CL_OVERLOADABLE NAME(float3  );      \
  int4    _CL_OVERLOADABLE NAME(float4  );      \
  int8    _CL_OVERLOADABLE NAME(float8  );      \
  int16   _CL_OVERLOADABLE NAME(float16 );      \
  __IF_FP64(                                    \
  int     _CL_OVERLOADABLE NAME(double  );      \
  long2   _CL_OVERLOADABLE NAME(double2 );      \
  long3   _CL_OVERLOADABLE NAME(double3 );      \
  long4   _CL_OVERLOADABLE NAME(double4 );      \
  long8   _CL_OVERLOADABLE NAME(double8 );      \
  long16  _CL_OVERLOADABLE NAME(double16);)
#define _CL_DECLARE_FUNC_K_V(NAME)              \
  __IF_FP16(                                    \
  int   _CL_OVERLOADABLE NAME(half    );        \
  int2  _CL_OVERLOADABLE NAME(half2   );        \
  int3  _CL_OVERLOADABLE NAME(half3   );        \
  int4  _CL_OVERLOADABLE NAME(half4   );        \
  int8  _CL_OVERLOADABLE NAME(half8   );        \
  int16 _CL_OVERLOADABLE NAME(half16  );)       \
  int   _CL_OVERLOADABLE NAME(float   );        \
  int2  _CL_OVERLOADABLE NAME(float2  );        \
  int3  _CL_OVERLOADABLE NAME(float3  );        \
  int4  _CL_OVERLOADABLE NAME(float4  );        \
  int8  _CL_OVERLOADABLE NAME(float8  );        \
  int16 _CL_OVERLOADABLE NAME(float16 );        \
  __IF_FP64(                                    \
  int   _CL_OVERLOADABLE NAME(double  );        \
  int2  _CL_OVERLOADABLE NAME(double2 );        \
  int3  _CL_OVERLOADABLE NAME(double3 );        \
  int4  _CL_OVERLOADABLE NAME(double4 );        \
  int8  _CL_OVERLOADABLE NAME(double8 );        \
  int16 _CL_OVERLOADABLE NAME(double16);)
#define _CL_DECLARE_FUNC_S_V(NAME)              \
  __IF_FP16(                                    \
  half   _CL_OVERLOADABLE NAME(half    );       \
  half   _CL_OVERLOADABLE NAME(half2   );       \
  half   _CL_OVERLOADABLE NAME(half3   );       \
  half   _CL_OVERLOADABLE NAME(half4   );       \
  half   _CL_OVERLOADABLE NAME(half8   );       \
  half   _CL_OVERLOADABLE NAME(half16  );)      \
  float  _CL_OVERLOADABLE NAME(float   );       \
  float  _CL_OVERLOADABLE NAME(float2  );       \
  float  _CL_OVERLOADABLE NAME(float3  );       \
  float  _CL_OVERLOADABLE NAME(float4  );       \
  float  _CL_OVERLOADABLE NAME(float8  );       \
  float  _CL_OVERLOADABLE NAME(float16 );       \
  __IF_FP64(                                    \
  double _CL_OVERLOADABLE NAME(double  );       \
  double _CL_OVERLOADABLE NAME(double2 );       \
  double _CL_OVERLOADABLE NAME(double3 );       \
  double _CL_OVERLOADABLE NAME(double4 );       \
  double _CL_OVERLOADABLE NAME(double8 );       \
  double _CL_OVERLOADABLE NAME(double16);)
#define _CL_DECLARE_FUNC_S_VV(NAME)                     \
  __IF_FP16(                                            \
  half   _CL_OVERLOADABLE NAME(half    , half    );     \
  half   _CL_OVERLOADABLE NAME(half2   , half2   );     \
  half   _CL_OVERLOADABLE NAME(half3   , half3   );     \
  half   _CL_OVERLOADABLE NAME(half4   , half4   );     \
  half   _CL_OVERLOADABLE NAME(half8   , half8   );     \
  half   _CL_OVERLOADABLE NAME(half16  , half16  );)    \
  float  _CL_OVERLOADABLE NAME(float   , float   );     \
  float  _CL_OVERLOADABLE NAME(float2  , float2  );     \
  float  _CL_OVERLOADABLE NAME(float3  , float3  );     \
  float  _CL_OVERLOADABLE NAME(float4  , float4  );     \
  float  _CL_OVERLOADABLE NAME(float8  , float8  );     \
  float  _CL_OVERLOADABLE NAME(float16 , float16 );     \
  __IF_FP64(                                            \
  double _CL_OVERLOADABLE NAME(double  , double  );     \
  double _CL_OVERLOADABLE NAME(double2 , double2 );     \
  double _CL_OVERLOADABLE NAME(double3 , double3 );     \
  double _CL_OVERLOADABLE NAME(double4 , double4 );     \
  double _CL_OVERLOADABLE NAME(double8 , double8 );     \
  double _CL_OVERLOADABLE NAME(double16, double16);)
#define _CL_DECLARE_FUNC_F_F(NAME)              \
  float    _CL_OVERLOADABLE NAME(float   );     \
  float2   _CL_OVERLOADABLE NAME(float2  );     \
  float3   _CL_OVERLOADABLE NAME(float3  );     \
  float4   _CL_OVERLOADABLE NAME(float4  );     \
  float8   _CL_OVERLOADABLE NAME(float8  );     \
  float16  _CL_OVERLOADABLE NAME(float16 );
#define _CL_DECLARE_FUNC_F_FF(NAME)                     \
  float    _CL_OVERLOADABLE NAME(float   , float   );   \
  float2   _CL_OVERLOADABLE NAME(float2  , float2  );   \
  float3   _CL_OVERLOADABLE NAME(float3  , float3  );   \
  float4   _CL_OVERLOADABLE NAME(float4  , float4  );   \
  float8   _CL_OVERLOADABLE NAME(float8  , float8  );   \
  float16  _CL_OVERLOADABLE NAME(float16 , float16 );

_CL_DECLARE_FUNC_V_V(acos)
_CL_DECLARE_FUNC_V_V(acosh)
_CL_DECLARE_FUNC_V_V(acospi)
_CL_DECLARE_FUNC_V_V(asin)
_CL_DECLARE_FUNC_V_V(asinh)
_CL_DECLARE_FUNC_V_V(asinpi)
_CL_DECLARE_FUNC_V_V(atan)
_CL_DECLARE_FUNC_V_VV(atan2)
_CL_DECLARE_FUNC_V_VV(atan2pi)
_CL_DECLARE_FUNC_V_V(atanh)
_CL_DECLARE_FUNC_V_V(atanpi)
_CL_DECLARE_FUNC_V_V(cbrt)
_CL_DECLARE_FUNC_V_V(ceil)
_CL_DECLARE_FUNC_V_VV(copysign)
_CL_DECLARE_FUNC_V_V(cos)
_CL_DECLARE_FUNC_V_V(cosh)
_CL_DECLARE_FUNC_V_V(cospi)
_CL_DECLARE_FUNC_V_V(erfc)
_CL_DECLARE_FUNC_V_V(erf)
_CL_DECLARE_FUNC_V_V(exp)
_CL_DECLARE_FUNC_V_V(exp2)
_CL_DECLARE_FUNC_V_V(exp10)
_CL_DECLARE_FUNC_V_V(expm1)
_CL_DECLARE_FUNC_V_V(fabs)
_CL_DECLARE_FUNC_V_VV(fdim)
_CL_DECLARE_FUNC_V_V(floor)
_CL_DECLARE_FUNC_V_VVV(fma)
#if __FAST__RELAXED__MATH__
#  undef fma
#  define fma mad
#endif
_CL_DECLARE_FUNC_V_VV(fmax)
_CL_DECLARE_FUNC_V_VS(fmax)
#if __FAST__RELAXED__MATH__
#  undef fmax
#  define fmax max
#endif
_CL_DECLARE_FUNC_V_VV(fmin)
_CL_DECLARE_FUNC_V_VS(fmin)
#if __FAST__RELAXED__MATH__
#  undef fmin
#  define fmin min
#endif
_CL_DECLARE_FUNC_V_VV(fmod)
_CL_DECLARE_FUNC_V_VPV(fract)
_CL_DECLARE_FUNC_V_VPK(frexp)
_CL_DECLARE_FUNC_V_VV(hypot)
_CL_DECLARE_FUNC_K_V(ilogb)
_CL_DECLARE_FUNC_V_VJ(ldexp)
_CL_DECLARE_FUNC_V_VI(ldexp)
_CL_DECLARE_FUNC_V_V(lgamma)
_CL_DECLARE_FUNC_V_VPK(lgamma_r)
_CL_DECLARE_FUNC_V_V(log)
_CL_DECLARE_FUNC_V_V(log2)
_CL_DECLARE_FUNC_V_V(log10)
_CL_DECLARE_FUNC_V_V(log1p)
_CL_DECLARE_FUNC_V_V(logb)
_CL_DECLARE_FUNC_V_VVV(mad)
_CL_DECLARE_FUNC_V_VV(maxmag)
_CL_DECLARE_FUNC_V_VV(minmag)
_CL_DECLARE_FUNC_V_VPV(modf)
_CL_DECLARE_FUNC_V_U(nan)
_CL_DECLARE_FUNC_V_VV(nextafter)
_CL_DECLARE_FUNC_V_VV(pow)
_CL_DECLARE_FUNC_V_VJ(pown)
_CL_DECLARE_FUNC_V_VI(pown)
_CL_DECLARE_FUNC_V_VV(powr)
_CL_DECLARE_FUNC_V_VV(remainder)
_CL_DECLARE_FUNC_V_VVPK(remquo)
_CL_DECLARE_FUNC_V_V(rint)
_CL_DECLARE_FUNC_V_VJ(rootn)
_CL_DECLARE_FUNC_V_VI(rootn)
_CL_DECLARE_FUNC_V_V(round)
_CL_DECLARE_FUNC_V_V(rsqrt)
_CL_DECLARE_FUNC_V_V(sin)
_CL_DECLARE_FUNC_V_VPV(sincos)
_CL_DECLARE_FUNC_V_V(sinh)
_CL_DECLARE_FUNC_V_V(sinpi)
_CL_DECLARE_FUNC_V_V(sqrt)
_CL_DECLARE_FUNC_V_V(tan)
_CL_DECLARE_FUNC_V_V(tanh)
_CL_DECLARE_FUNC_V_V(tanpi)
_CL_DECLARE_FUNC_V_V(tgamma)
_CL_DECLARE_FUNC_V_V(trunc)
_CL_DECLARE_FUNC_F_F(half_cos)
_CL_DECLARE_FUNC_F_FF(half_divide)
_CL_DECLARE_FUNC_F_F(half_exp)
_CL_DECLARE_FUNC_F_F(half_exp2)
_CL_DECLARE_FUNC_F_F(half_exp10)
_CL_DECLARE_FUNC_F_F(half_log)
_CL_DECLARE_FUNC_F_F(half_log2)
_CL_DECLARE_FUNC_F_F(half_log10)
_CL_DECLARE_FUNC_F_FF(half_powr)
_CL_DECLARE_FUNC_F_F(half_recip)
_CL_DECLARE_FUNC_F_F(half_rsqrt)
_CL_DECLARE_FUNC_F_F(half_sin)
_CL_DECLARE_FUNC_F_F(half_sqrt)
_CL_DECLARE_FUNC_F_F(half_tan)
_CL_DECLARE_FUNC_V_V(_cl_native_cos)
_CL_DECLARE_FUNC_V_VV(_cl_native_divide)
_CL_DECLARE_FUNC_V_V(_cl_native_exp)
_CL_DECLARE_FUNC_V_V(_cl_native_exp2)
_CL_DECLARE_FUNC_V_V(_cl_native_exp10)
_CL_DECLARE_FUNC_V_V(_cl_native_log)
_CL_DECLARE_FUNC_V_V(_cl_native_log2)
_CL_DECLARE_FUNC_V_V(_cl_native_log10)
_CL_DECLARE_FUNC_V_VV(_cl_native_powr)
_CL_DECLARE_FUNC_V_V(_cl_native_recip)
_CL_DECLARE_FUNC_V_V(_cl_native_rsqrt)
_CL_DECLARE_FUNC_V_V(_cl_native_sin)
_CL_DECLARE_FUNC_V_V(_cl_native_sqrt)
_CL_DECLARE_FUNC_V_V(_cl_native_tan)

/* clang's header defines these */
#ifndef _OPENCL_H_

/* Integer Constants */

#define CHAR_BIT  8
#define CHAR_MAX  SCHAR_MAX
#define CHAR_MIN  SCHAR_MIN
#define INT_MAX   2147483647
#define INT_MIN   (-2147483647 - 1)
#ifdef cl_khr_int64
#define LONG_MAX  0x7fffffffffffffffL
#define LONG_MIN  (-0x7fffffffffffffffL - 1)
#endif
#define SCHAR_MAX 127
#define SCHAR_MIN (-127 - 1)
#define SHRT_MAX  32767
#define SHRT_MIN  (-32767 - 1)
#define UCHAR_MAX 255
#define USHRT_MAX 65535
#define UINT_MAX  0xffffffff
#ifdef cl_khr_int64
#define ULONG_MAX 0xffffffffffffffffUL
#endif

#endif

/* Integer Functions */
#define _CL_DECLARE_FUNC_G_G(NAME)              \
  char     _CL_OVERLOADABLE NAME(char    );     \
  char2    _CL_OVERLOADABLE NAME(char2   );     \
  char3    _CL_OVERLOADABLE NAME(char3   );     \
  char4    _CL_OVERLOADABLE NAME(char4   );     \
  char8    _CL_OVERLOADABLE NAME(char8   );     \
  char16   _CL_OVERLOADABLE NAME(char16  );     \
  uchar    _CL_OVERLOADABLE NAME(uchar   );     \
  uchar2   _CL_OVERLOADABLE NAME(uchar2  );     \
  uchar3   _CL_OVERLOADABLE NAME(uchar3  );     \
  uchar4   _CL_OVERLOADABLE NAME(uchar4  );     \
  uchar8   _CL_OVERLOADABLE NAME(uchar8  );     \
  uchar16  _CL_OVERLOADABLE NAME(uchar16 );     \
  short    _CL_OVERLOADABLE NAME(short   );     \
  short2   _CL_OVERLOADABLE NAME(short2  );     \
  short3   _CL_OVERLOADABLE NAME(short3  );     \
  short4   _CL_OVERLOADABLE NAME(short4  );     \
  short8   _CL_OVERLOADABLE NAME(short8  );     \
  short16  _CL_OVERLOADABLE NAME(short16 );     \
  ushort   _CL_OVERLOADABLE NAME(ushort  );     \
  ushort2  _CL_OVERLOADABLE NAME(ushort2 );     \
  ushort3  _CL_OVERLOADABLE NAME(ushort3 );     \
  ushort4  _CL_OVERLOADABLE NAME(ushort4 );     \
  ushort8  _CL_OVERLOADABLE NAME(ushort8 );     \
  ushort16 _CL_OVERLOADABLE NAME(ushort16);     \
  int      _CL_OVERLOADABLE NAME(int     );     \
  int2     _CL_OVERLOADABLE NAME(int2    );     \
  int3     _CL_OVERLOADABLE NAME(int3    );     \
  int4     _CL_OVERLOADABLE NAME(int4    );     \
  int8     _CL_OVERLOADABLE NAME(int8    );     \
  int16    _CL_OVERLOADABLE NAME(int16   );     \
  uint     _CL_OVERLOADABLE NAME(uint    );     \
  uint2    _CL_OVERLOADABLE NAME(uint2   );     \
  uint3    _CL_OVERLOADABLE NAME(uint3   );     \
  uint4    _CL_OVERLOADABLE NAME(uint4   );     \
  uint8    _CL_OVERLOADABLE NAME(uint8   );     \
  uint16   _CL_OVERLOADABLE NAME(uint16  );     \
  __IF_INT64(                                   \
  long     _CL_OVERLOADABLE NAME(long    );     \
  long2    _CL_OVERLOADABLE NAME(long2   );     \
  long3    _CL_OVERLOADABLE NAME(long3   );     \
  long4    _CL_OVERLOADABLE NAME(long4   );     \
  long8    _CL_OVERLOADABLE NAME(long8   );     \
  long16   _CL_OVERLOADABLE NAME(long16  );     \
  ulong    _CL_OVERLOADABLE NAME(ulong   );     \
  ulong2   _CL_OVERLOADABLE NAME(ulong2  );     \
  ulong3   _CL_OVERLOADABLE NAME(ulong3  );     \
  ulong4   _CL_OVERLOADABLE NAME(ulong4  );     \
  ulong8   _CL_OVERLOADABLE NAME(ulong8  );     \
  ulong16  _CL_OVERLOADABLE NAME(ulong16 );)
#define _CL_DECLARE_FUNC_G_GG(NAME)                     \
  char     _CL_OVERLOADABLE NAME(char    , char    );   \
  char2    _CL_OVERLOADABLE NAME(char2   , char2   );   \
  char3    _CL_OVERLOADABLE NAME(char3   , char3   );   \
  char4    _CL_OVERLOADABLE NAME(char4   , char4   );   \
  char8    _CL_OVERLOADABLE NAME(char8   , char8   );   \
  char16   _CL_OVERLOADABLE NAME(char16  , char16  );   \
  uchar    _CL_OVERLOADABLE NAME(uchar   , uchar   );   \
  uchar2   _CL_OVERLOADABLE NAME(uchar2  , uchar2  );   \
  uchar3   _CL_OVERLOADABLE NAME(uchar3  , uchar3  );   \
  uchar4   _CL_OVERLOADABLE NAME(uchar4  , uchar4  );   \
  uchar8   _CL_OVERLOADABLE NAME(uchar8  , uchar8  );   \
  uchar16  _CL_OVERLOADABLE NAME(uchar16 , uchar16 );   \
  short    _CL_OVERLOADABLE NAME(short   , short   );   \
  short2   _CL_OVERLOADABLE NAME(short2  , short2  );   \
  short3   _CL_OVERLOADABLE NAME(short3  , short3  );   \
  short4   _CL_OVERLOADABLE NAME(short4  , short4  );   \
  short8   _CL_OVERLOADABLE NAME(short8  , short8  );   \
  short16  _CL_OVERLOADABLE NAME(short16 , short16 );   \
  ushort   _CL_OVERLOADABLE NAME(ushort  , ushort  );   \
  ushort2  _CL_OVERLOADABLE NAME(ushort2 , ushort2 );   \
  ushort3  _CL_OVERLOADABLE NAME(ushort3 , ushort3 );   \
  ushort4  _CL_OVERLOADABLE NAME(ushort4 , ushort4 );   \
  ushort8  _CL_OVERLOADABLE NAME(ushort8 , ushort8 );   \
  ushort16 _CL_OVERLOADABLE NAME(ushort16, ushort16);   \
  int      _CL_OVERLOADABLE NAME(int     , int     );   \
  int2     _CL_OVERLOADABLE NAME(int2    , int2    );   \
  int3     _CL_OVERLOADABLE NAME(int3    , int3    );   \
  int4     _CL_OVERLOADABLE NAME(int4    , int4    );   \
  int8     _CL_OVERLOADABLE NAME(int8    , int8    );   \
  int16    _CL_OVERLOADABLE NAME(int16   , int16   );   \
  uint     _CL_OVERLOADABLE NAME(uint    , uint    );   \
  uint2    _CL_OVERLOADABLE NAME(uint2   , uint2   );   \
  uint3    _CL_OVERLOADABLE NAME(uint3   , uint3   );   \
  uint4    _CL_OVERLOADABLE NAME(uint4   , uint4   );   \
  uint8    _CL_OVERLOADABLE NAME(uint8   , uint8   );   \
  uint16   _CL_OVERLOADABLE NAME(uint16  , uint16  );   \
  __IF_INT64(                                           \
  long     _CL_OVERLOADABLE NAME(long    , long    );   \
  long2    _CL_OVERLOADABLE NAME(long2   , long2   );   \
  long3    _CL_OVERLOADABLE NAME(long3   , long3   );   \
  long4    _CL_OVERLOADABLE NAME(long4   , long4   );   \
  long8    _CL_OVERLOADABLE NAME(long8   , long8   );   \
  long16   _CL_OVERLOADABLE NAME(long16  , long16  );   \
  ulong    _CL_OVERLOADABLE NAME(ulong   , ulong   );   \
  ulong2   _CL_OVERLOADABLE NAME(ulong2  , ulong2  );   \
  ulong3   _CL_OVERLOADABLE NAME(ulong3  , ulong3  );   \
  ulong4   _CL_OVERLOADABLE NAME(ulong4  , ulong4  );   \
  ulong8   _CL_OVERLOADABLE NAME(ulong8  , ulong8  );   \
  ulong16  _CL_OVERLOADABLE NAME(ulong16 , ulong16 );)
#define _CL_DECLARE_FUNC_G_GGG(NAME)                            \
  char     _CL_OVERLOADABLE NAME(char    , char    , char    ); \
  char2    _CL_OVERLOADABLE NAME(char2   , char2   , char2   ); \
  char3    _CL_OVERLOADABLE NAME(char3   , char3   , char3   ); \
  char4    _CL_OVERLOADABLE NAME(char4   , char4   , char4   ); \
  char8    _CL_OVERLOADABLE NAME(char8   , char8   , char8   ); \
  char16   _CL_OVERLOADABLE NAME(char16  , char16  , char16  ); \
  uchar    _CL_OVERLOADABLE NAME(uchar   , uchar   , uchar   ); \
  uchar2   _CL_OVERLOADABLE NAME(uchar2  , uchar2  , uchar2  ); \
  uchar3   _CL_OVERLOADABLE NAME(uchar3  , uchar3  , uchar3  ); \
  uchar4   _CL_OVERLOADABLE NAME(uchar4  , uchar4  , uchar4  ); \
  uchar8   _CL_OVERLOADABLE NAME(uchar8  , uchar8  , uchar8  ); \
  uchar16  _CL_OVERLOADABLE NAME(uchar16 , uchar16 , uchar16 ); \
  short    _CL_OVERLOADABLE NAME(short   , short   , short   ); \
  short2   _CL_OVERLOADABLE NAME(short2  , short2  , short2  ); \
  short3   _CL_OVERLOADABLE NAME(short3  , short3  , short3  ); \
  short4   _CL_OVERLOADABLE NAME(short4  , short4  , short4  ); \
  short8   _CL_OVERLOADABLE NAME(short8  , short8  , short8  ); \
  short16  _CL_OVERLOADABLE NAME(short16 , short16 , short16 ); \
  ushort   _CL_OVERLOADABLE NAME(ushort  , ushort  , ushort  ); \
  ushort2  _CL_OVERLOADABLE NAME(ushort2 , ushort2 , ushort2 ); \
  ushort3  _CL_OVERLOADABLE NAME(ushort3 , ushort3 , ushort3 ); \
  ushort4  _CL_OVERLOADABLE NAME(ushort4 , ushort4 , ushort4 ); \
  ushort8  _CL_OVERLOADABLE NAME(ushort8 , ushort8 , ushort8 ); \
  ushort16 _CL_OVERLOADABLE NAME(ushort16, ushort16, ushort16); \
  int      _CL_OVERLOADABLE NAME(int     , int     , int     ); \
  int2     _CL_OVERLOADABLE NAME(int2    , int2    , int2    ); \
  int3     _CL_OVERLOADABLE NAME(int3    , int3    , int3    ); \
  int4     _CL_OVERLOADABLE NAME(int4    , int4    , int4    ); \
  int8     _CL_OVERLOADABLE NAME(int8    , int8    , int8    ); \
  int16    _CL_OVERLOADABLE NAME(int16   , int16   , int16   ); \
  uint     _CL_OVERLOADABLE NAME(uint    , uint    , uint    ); \
  uint2    _CL_OVERLOADABLE NAME(uint2   , uint2   , uint2   ); \
  uint3    _CL_OVERLOADABLE NAME(uint3   , uint3   , uint3   ); \
  uint4    _CL_OVERLOADABLE NAME(uint4   , uint4   , uint4   ); \
  uint8    _CL_OVERLOADABLE NAME(uint8   , uint8   , uint8   ); \
  uint16   _CL_OVERLOADABLE NAME(uint16  , uint16  , uint16  ); \
  __IF_INT64(                                                   \
  long     _CL_OVERLOADABLE NAME(long    , long    , long    ); \
  long2    _CL_OVERLOADABLE NAME(long2   , long2   , long2   ); \
  long3    _CL_OVERLOADABLE NAME(long3   , long3   , long3   ); \
  long4    _CL_OVERLOADABLE NAME(long4   , long4   , long4   ); \
  long8    _CL_OVERLOADABLE NAME(long8   , long8   , long8   ); \
  long16   _CL_OVERLOADABLE NAME(long16  , long16  , long16  ); \
  ulong    _CL_OVERLOADABLE NAME(ulong   , ulong   , ulong   ); \
  ulong2   _CL_OVERLOADABLE NAME(ulong2  , ulong2  , ulong2  ); \
  ulong3   _CL_OVERLOADABLE NAME(ulong3  , ulong3  , ulong3  ); \
  ulong4   _CL_OVERLOADABLE NAME(ulong4  , ulong4  , ulong4  ); \
  ulong8   _CL_OVERLOADABLE NAME(ulong8  , ulong8  , ulong8  ); \
  ulong16  _CL_OVERLOADABLE NAME(ulong16 , ulong16 , ulong16 );)
#define _CL_DECLARE_FUNC_G_GGIG(NAME)                                   \
  char     _CL_OVERLOADABLE NAME(char    , char    , char    );         \
  char2    _CL_OVERLOADABLE NAME(char2   , char2   , char2   );         \
  char3    _CL_OVERLOADABLE NAME(char3   , char3   , char3   );         \
  char4    _CL_OVERLOADABLE NAME(char4   , char4   , char4   );         \
  char8    _CL_OVERLOADABLE NAME(char8   , char8   , char8   );         \
  char16   _CL_OVERLOADABLE NAME(char16  , char16  , char16  );         \
  uchar    _CL_OVERLOADABLE NAME(uchar   , uchar   , char    );         \
  uchar2   _CL_OVERLOADABLE NAME(uchar2  , uchar2  , char2   );         \
  uchar3   _CL_OVERLOADABLE NAME(uchar3  , uchar3  , char3   );         \
  uchar4   _CL_OVERLOADABLE NAME(uchar4  , uchar4  , char4   );         \
  uchar8   _CL_OVERLOADABLE NAME(uchar8  , uchar8  , char8   );         \
  uchar16  _CL_OVERLOADABLE NAME(uchar16 , uchar16 , char16  );         \
  short    _CL_OVERLOADABLE NAME(short   , short   , short   );         \
  short2   _CL_OVERLOADABLE NAME(short2  , short2  , short2  );         \
  short3   _CL_OVERLOADABLE NAME(short3  , short3  , short3  );         \
  short4   _CL_OVERLOADABLE NAME(short4  , short4  , short4  );         \
  short8   _CL_OVERLOADABLE NAME(short8  , short8  , short8  );         \
  short16  _CL_OVERLOADABLE NAME(short16 , short16 , short16 );         \
  ushort   _CL_OVERLOADABLE NAME(ushort  , ushort  , short   );         \
  ushort2  _CL_OVERLOADABLE NAME(ushort2 , ushort2 , short2  );         \
  ushort3  _CL_OVERLOADABLE NAME(ushort3 , ushort3 , short3  );         \
  ushort4  _CL_OVERLOADABLE NAME(ushort4 , ushort4 , short4  );         \
  ushort8  _CL_OVERLOADABLE NAME(ushort8 , ushort8 , short8  );         \
  ushort16 _CL_OVERLOADABLE NAME(ushort16, ushort16, short16 );         \
  int      _CL_OVERLOADABLE NAME(int     , int     , int     );         \
  int2     _CL_OVERLOADABLE NAME(int2    , int2    , int2    );         \
  int3     _CL_OVERLOADABLE NAME(int3    , int3    , int3    );         \
  int4     _CL_OVERLOADABLE NAME(int4    , int4    , int4    );         \
  int8     _CL_OVERLOADABLE NAME(int8    , int8    , int8    );         \
  int16    _CL_OVERLOADABLE NAME(int16   , int16   , int16   );         \
  uint     _CL_OVERLOADABLE NAME(uint    , uint    , int     );         \
  uint2    _CL_OVERLOADABLE NAME(uint2   , uint2   , int2    );         \
  uint3    _CL_OVERLOADABLE NAME(uint3   , uint3   , int3    );         \
  uint4    _CL_OVERLOADABLE NAME(uint4   , uint4   , int4    );         \
  uint8    _CL_OVERLOADABLE NAME(uint8   , uint8   , int8    );         \
  uint16   _CL_OVERLOADABLE NAME(uint16  , uint16  , int16   );         \
  __IF_INT64(                                                           \
  long     _CL_OVERLOADABLE NAME(long    , long    , long    );         \
  long2    _CL_OVERLOADABLE NAME(long2   , long2   , long2   );         \
  long3    _CL_OVERLOADABLE NAME(long3   , long3   , long3   );         \
  long4    _CL_OVERLOADABLE NAME(long4   , long4   , long4   );         \
  long8    _CL_OVERLOADABLE NAME(long8   , long8   , long8   );         \
  long16   _CL_OVERLOADABLE NAME(long16  , long16  , long16  );         \
  ulong    _CL_OVERLOADABLE NAME(ulong   , ulong   , long    );         \
  ulong2   _CL_OVERLOADABLE NAME(ulong2  , ulong2  , long2   );         \
  ulong3   _CL_OVERLOADABLE NAME(ulong3  , ulong3  , long3   );         \
  ulong4   _CL_OVERLOADABLE NAME(ulong4  , ulong4  , long4   );         \
  ulong8   _CL_OVERLOADABLE NAME(ulong8  , ulong8  , long8   );         \
  ulong16  _CL_OVERLOADABLE NAME(ulong16 , ulong16 , long16  );)
#define _CL_DECLARE_FUNC_G_GGUG(NAME)                                   \
  char     _CL_OVERLOADABLE NAME(char    , char    , uchar    );        \
  char2    _CL_OVERLOADABLE NAME(char2   , char2   , uchar2   );        \
  char3    _CL_OVERLOADABLE NAME(char3   , char3   , uchar3   );        \
  char4    _CL_OVERLOADABLE NAME(char4   , char4   , uchar4   );        \
  char8    _CL_OVERLOADABLE NAME(char8   , char8   , uchar8   );        \
  char16   _CL_OVERLOADABLE NAME(char16  , char16  , uchar16  );        \
  uchar    _CL_OVERLOADABLE NAME(uchar   , uchar   , uchar    );        \
  uchar2   _CL_OVERLOADABLE NAME(uchar2  , uchar2  , uchar2   );        \
  uchar3   _CL_OVERLOADABLE NAME(uchar3  , uchar3  , uchar3   );        \
  uchar4   _CL_OVERLOADABLE NAME(uchar4  , uchar4  , uchar4   );        \
  uchar8   _CL_OVERLOADABLE NAME(uchar8  , uchar8  , uchar8   );        \
  uchar16  _CL_OVERLOADABLE NAME(uchar16 , uchar16 , uchar16  );        \
  short    _CL_OVERLOADABLE NAME(short   , short   , ushort   );        \
  short2   _CL_OVERLOADABLE NAME(short2  , short2  , ushort2  );        \
  short3   _CL_OVERLOADABLE NAME(short3  , short3  , ushort3  );        \
  short4   _CL_OVERLOADABLE NAME(short4  , short4  , ushort4  );        \
  short8   _CL_OVERLOADABLE NAME(short8  , short8  , ushort8  );        \
  short16  _CL_OVERLOADABLE NAME(short16 , short16 , ushort16 );        \
  ushort   _CL_OVERLOADABLE NAME(ushort  , ushort  , ushort   );        \
  ushort2  _CL_OVERLOADABLE NAME(ushort2 , ushort2 , ushort2  );        \
  ushort3  _CL_OVERLOADABLE NAME(ushort3 , ushort3 , ushort3  );        \
  ushort4  _CL_OVERLOADABLE NAME(ushort4 , ushort4 , ushort4  );        \
  ushort8  _CL_OVERLOADABLE NAME(ushort8 , ushort8 , ushort8  );        \
  ushort16 _CL_OVERLOADABLE NAME(ushort16, ushort16, ushort16 );        \
  int      _CL_OVERLOADABLE NAME(int     , int     , uint     );        \
  int2     _CL_OVERLOADABLE NAME(int2    , int2    , uint2    );        \
  int3     _CL_OVERLOADABLE NAME(int3    , int3    , uint3    );        \
  int4     _CL_OVERLOADABLE NAME(int4    , int4    , uint4    );        \
  int8     _CL_OVERLOADABLE NAME(int8    , int8    , uint8    );        \
  int16    _CL_OVERLOADABLE NAME(int16   , int16   , uint16   );        \
  uint     _CL_OVERLOADABLE NAME(uint    , uint    , uint     );        \
  uint2    _CL_OVERLOADABLE NAME(uint2   , uint2   , uint2    );        \
  uint3    _CL_OVERLOADABLE NAME(uint3   , uint3   , uint3    );        \
  uint4    _CL_OVERLOADABLE NAME(uint4   , uint4   , uint4    );        \
  uint8    _CL_OVERLOADABLE NAME(uint8   , uint8   , uint8    );        \
  uint16   _CL_OVERLOADABLE NAME(uint16  , uint16  , uint16   );        \
  __IF_INT64(                                                           \
  long     _CL_OVERLOADABLE NAME(long    , long    , ulong    );        \
  long2    _CL_OVERLOADABLE NAME(long2   , long2   , ulong2   );        \
  long3    _CL_OVERLOADABLE NAME(long3   , long3   , ulong3   );        \
  long4    _CL_OVERLOADABLE NAME(long4   , long4   , ulong4   );        \
  long8    _CL_OVERLOADABLE NAME(long8   , long8   , ulong8   );        \
  long16   _CL_OVERLOADABLE NAME(long16  , long16  , ulong16  );        \
  ulong    _CL_OVERLOADABLE NAME(ulong   , ulong   , ulong    );        \
  ulong2   _CL_OVERLOADABLE NAME(ulong2  , ulong2  , ulong2   );        \
  ulong3   _CL_OVERLOADABLE NAME(ulong3  , ulong3  , ulong3   );        \
  ulong4   _CL_OVERLOADABLE NAME(ulong4  , ulong4  , ulong4   );        \
  ulong8   _CL_OVERLOADABLE NAME(ulong8  , ulong8  , ulong8   );        \
  ulong16  _CL_OVERLOADABLE NAME(ulong16 , ulong16 , ulong16  );)
#define _CL_DECLARE_FUNC_G_GS(NAME)                     \
  char2    _CL_OVERLOADABLE NAME(char2   , char  );     \
  char3    _CL_OVERLOADABLE NAME(char3   , char  );     \
  char4    _CL_OVERLOADABLE NAME(char4   , char  );     \
  char8    _CL_OVERLOADABLE NAME(char8   , char  );     \
  char16   _CL_OVERLOADABLE NAME(char16  , char  );     \
  uchar2   _CL_OVERLOADABLE NAME(uchar2  , uchar );     \
  uchar3   _CL_OVERLOADABLE NAME(uchar3  , uchar );     \
  uchar4   _CL_OVERLOADABLE NAME(uchar4  , uchar );     \
  uchar8   _CL_OVERLOADABLE NAME(uchar8  , uchar );     \
  uchar16  _CL_OVERLOADABLE NAME(uchar16 , uchar );     \
  short2   _CL_OVERLOADABLE NAME(short2  , short );     \
  short3   _CL_OVERLOADABLE NAME(short3  , short );     \
  short4   _CL_OVERLOADABLE NAME(short4  , short );     \
  short8   _CL_OVERLOADABLE NAME(short8  , short );     \
  short16  _CL_OVERLOADABLE NAME(short16 , short );     \
  ushort2  _CL_OVERLOADABLE NAME(ushort2 , ushort);     \
  ushort3  _CL_OVERLOADABLE NAME(ushort3 , ushort);     \
  ushort4  _CL_OVERLOADABLE NAME(ushort4 , ushort);     \
  ushort8  _CL_OVERLOADABLE NAME(ushort8 , ushort);     \
  ushort16 _CL_OVERLOADABLE NAME(ushort16, ushort);     \
  int2     _CL_OVERLOADABLE NAME(int2    , int   );     \
  int3     _CL_OVERLOADABLE NAME(int3    , int   );     \
  int4     _CL_OVERLOADABLE NAME(int4    , int   );     \
  int8     _CL_OVERLOADABLE NAME(int8    , int   );     \
  int16    _CL_OVERLOADABLE NAME(int16   , int   );     \
  uint2    _CL_OVERLOADABLE NAME(uint2   , uint  );     \
  uint3    _CL_OVERLOADABLE NAME(uint3   , uint  );     \
  uint4    _CL_OVERLOADABLE NAME(uint4   , uint  );     \
  uint8    _CL_OVERLOADABLE NAME(uint8   , uint  );     \
  uint16   _CL_OVERLOADABLE NAME(uint16  , uint  );     \
  __IF_INT64(                                           \
  long2    _CL_OVERLOADABLE NAME(long2   , long  );     \
  long3    _CL_OVERLOADABLE NAME(long3   , long  );     \
  long4    _CL_OVERLOADABLE NAME(long4   , long  );     \
  long8    _CL_OVERLOADABLE NAME(long8   , long  );     \
  long16   _CL_OVERLOADABLE NAME(long16  , long  );     \
  ulong2   _CL_OVERLOADABLE NAME(ulong2  , ulong );     \
  ulong3   _CL_OVERLOADABLE NAME(ulong3  , ulong );     \
  ulong4   _CL_OVERLOADABLE NAME(ulong4  , ulong );     \
  ulong8   _CL_OVERLOADABLE NAME(ulong8  , ulong );     \
  ulong16  _CL_OVERLOADABLE NAME(ulong16 , ulong );)
#define _CL_DECLARE_FUNC_UG_G(NAME)             \
  uchar    _CL_OVERLOADABLE NAME(char    );     \
  uchar2   _CL_OVERLOADABLE NAME(char2   );     \
  uchar3   _CL_OVERLOADABLE NAME(char3   );     \
  uchar4   _CL_OVERLOADABLE NAME(char4   );     \
  uchar8   _CL_OVERLOADABLE NAME(char8   );     \
  uchar16  _CL_OVERLOADABLE NAME(char16  );     \
  ushort   _CL_OVERLOADABLE NAME(short   );     \
  ushort2  _CL_OVERLOADABLE NAME(short2  );     \
  ushort3  _CL_OVERLOADABLE NAME(short3  );     \
  ushort4  _CL_OVERLOADABLE NAME(short4  );     \
  ushort8  _CL_OVERLOADABLE NAME(short8  );     \
  ushort16 _CL_OVERLOADABLE NAME(short16 );     \
  uint     _CL_OVERLOADABLE NAME(int     );     \
  uint2    _CL_OVERLOADABLE NAME(int2    );     \
  uint3    _CL_OVERLOADABLE NAME(int3    );     \
  uint4    _CL_OVERLOADABLE NAME(int4    );     \
  uint8    _CL_OVERLOADABLE NAME(int8    );     \
  uint16   _CL_OVERLOADABLE NAME(int16   );     \
  __IF_INT64(                                   \
  ulong    _CL_OVERLOADABLE NAME(long    );     \
  ulong2   _CL_OVERLOADABLE NAME(long2   );     \
  ulong3   _CL_OVERLOADABLE NAME(long3   );     \
  ulong4   _CL_OVERLOADABLE NAME(long4   );     \
  ulong8   _CL_OVERLOADABLE NAME(long8   );     \
  ulong16  _CL_OVERLOADABLE NAME(long16  );)    \
  uchar    _CL_OVERLOADABLE NAME(uchar   );     \
  uchar2   _CL_OVERLOADABLE NAME(uchar2  );     \
  uchar3   _CL_OVERLOADABLE NAME(uchar3  );     \
  uchar4   _CL_OVERLOADABLE NAME(uchar4  );     \
  uchar8   _CL_OVERLOADABLE NAME(uchar8  );     \
  uchar16  _CL_OVERLOADABLE NAME(uchar16 );     \
  ushort   _CL_OVERLOADABLE NAME(ushort  );     \
  ushort2  _CL_OVERLOADABLE NAME(ushort2 );     \
  ushort3  _CL_OVERLOADABLE NAME(ushort3 );     \
  ushort4  _CL_OVERLOADABLE NAME(ushort4 );     \
  ushort8  _CL_OVERLOADABLE NAME(ushort8 );     \
  ushort16 _CL_OVERLOADABLE NAME(ushort16);     \
  uint     _CL_OVERLOADABLE NAME(uint    );     \
  uint2    _CL_OVERLOADABLE NAME(uint2   );     \
  uint3    _CL_OVERLOADABLE NAME(uint3   );     \
  uint4    _CL_OVERLOADABLE NAME(uint4   );     \
  uint8    _CL_OVERLOADABLE NAME(uint8   );     \
  uint16   _CL_OVERLOADABLE NAME(uint16  );     \
  __IF_INT64(                                   \
  ulong    _CL_OVERLOADABLE NAME(ulong   );     \
  ulong2   _CL_OVERLOADABLE NAME(ulong2  );     \
  ulong3   _CL_OVERLOADABLE NAME(ulong3  );     \
  ulong4   _CL_OVERLOADABLE NAME(ulong4  );     \
  ulong8   _CL_OVERLOADABLE NAME(ulong8  );     \
  ulong16  _CL_OVERLOADABLE NAME(ulong16 );)
#define _CL_DECLARE_FUNC_UG_GG(NAME)                    \
  uchar    _CL_OVERLOADABLE NAME(char    , char    );   \
  uchar2   _CL_OVERLOADABLE NAME(char2   , char2   );   \
  uchar3   _CL_OVERLOADABLE NAME(char3   , char3   );   \
  uchar4   _CL_OVERLOADABLE NAME(char4   , char4   );   \
  uchar8   _CL_OVERLOADABLE NAME(char8   , char8   );   \
  uchar16  _CL_OVERLOADABLE NAME(char16  , char16  );   \
  ushort   _CL_OVERLOADABLE NAME(short   , short   );   \
  ushort2  _CL_OVERLOADABLE NAME(short2  , short2  );   \
  ushort3  _CL_OVERLOADABLE NAME(short3  , short3  );   \
  ushort4  _CL_OVERLOADABLE NAME(short4  , short4  );   \
  ushort8  _CL_OVERLOADABLE NAME(short8  , short8  );   \
  ushort16 _CL_OVERLOADABLE NAME(short16 , short16 );   \
  uint     _CL_OVERLOADABLE NAME(int     , int     );   \
  uint2    _CL_OVERLOADABLE NAME(int2    , int2    );   \
  uint3    _CL_OVERLOADABLE NAME(int3    , int3    );   \
  uint4    _CL_OVERLOADABLE NAME(int4    , int4    );   \
  uint8    _CL_OVERLOADABLE NAME(int8    , int8    );   \
  uint16   _CL_OVERLOADABLE NAME(int16   , int16   );   \
  __IF_INT64(                                           \
  ulong    _CL_OVERLOADABLE NAME(long    , long    );   \
  ulong2   _CL_OVERLOADABLE NAME(long2   , long2   );   \
  ulong3   _CL_OVERLOADABLE NAME(long3   , long3   );   \
  ulong4   _CL_OVERLOADABLE NAME(long4   , long4   );   \
  ulong8   _CL_OVERLOADABLE NAME(long8   , long8   );   \
  ulong16  _CL_OVERLOADABLE NAME(long16  , long16  );)  \
  uchar    _CL_OVERLOADABLE NAME(uchar   , uchar   );   \
  uchar2   _CL_OVERLOADABLE NAME(uchar2  , uchar2  );   \
  uchar3   _CL_OVERLOADABLE NAME(uchar3  , uchar3  );   \
  uchar4   _CL_OVERLOADABLE NAME(uchar4  , uchar4  );   \
  uchar8   _CL_OVERLOADABLE NAME(uchar8  , uchar8  );   \
  uchar16  _CL_OVERLOADABLE NAME(uchar16 , uchar16 );   \
  ushort   _CL_OVERLOADABLE NAME(ushort  , ushort  );   \
  ushort2  _CL_OVERLOADABLE NAME(ushort2 , ushort2 );   \
  ushort3  _CL_OVERLOADABLE NAME(ushort3 , ushort3 );   \
  ushort4  _CL_OVERLOADABLE NAME(ushort4 , ushort4 );   \
  ushort8  _CL_OVERLOADABLE NAME(ushort8 , ushort8 );   \
  ushort16 _CL_OVERLOADABLE NAME(ushort16, ushort16);   \
  uint     _CL_OVERLOADABLE NAME(uint    , uint    );   \
  uint2    _CL_OVERLOADABLE NAME(uint2   , uint2   );   \
  uint3    _CL_OVERLOADABLE NAME(uint3   , uint3   );   \
  uint4    _CL_OVERLOADABLE NAME(uint4   , uint4   );   \
  uint8    _CL_OVERLOADABLE NAME(uint8   , uint8   );   \
  uint16   _CL_OVERLOADABLE NAME(uint16  , uint16  );   \
  __IF_INT64(                                           \
  ulong    _CL_OVERLOADABLE NAME(ulong   , ulong   );   \
  ulong2   _CL_OVERLOADABLE NAME(ulong2  , ulong2  );   \
  ulong3   _CL_OVERLOADABLE NAME(ulong3  , ulong3  );   \
  ulong4   _CL_OVERLOADABLE NAME(ulong4  , ulong4  );   \
  ulong8   _CL_OVERLOADABLE NAME(ulong8  , ulong8  );   \
  ulong16  _CL_OVERLOADABLE NAME(ulong16 , ulong16 );)
#define _CL_DECLARE_FUNC_LG_GUG(NAME)                   \
  short    _CL_OVERLOADABLE NAME(char    , uchar   );   \
  short2   _CL_OVERLOADABLE NAME(char2   , uchar2  );   \
  short3   _CL_OVERLOADABLE NAME(char3   , uchar3  );   \
  short4   _CL_OVERLOADABLE NAME(char4   , uchar4  );   \
  short8   _CL_OVERLOADABLE NAME(char8   , uchar8  );   \
  short16  _CL_OVERLOADABLE NAME(char16  , uchar16 );   \
  ushort   _CL_OVERLOADABLE NAME(uchar   , uchar   );   \
  ushort2  _CL_OVERLOADABLE NAME(uchar2  , uchar2  );   \
  ushort3  _CL_OVERLOADABLE NAME(uchar3  , uchar3  );   \
  ushort4  _CL_OVERLOADABLE NAME(uchar4  , uchar4  );   \
  ushort8  _CL_OVERLOADABLE NAME(uchar8  , uchar8  );   \
  ushort16 _CL_OVERLOADABLE NAME(uchar16 , uchar16 );   \
  uint     _CL_OVERLOADABLE NAME(ushort  , ushort  );   \
  uint2    _CL_OVERLOADABLE NAME(ushort2 , ushort2 );   \
  uint3    _CL_OVERLOADABLE NAME(ushort3 , ushort3 );   \
  uint4    _CL_OVERLOADABLE NAME(ushort4 , ushort4 );   \
  uint8    _CL_OVERLOADABLE NAME(ushort8 , ushort8 );   \
  uint16   _CL_OVERLOADABLE NAME(ushort16, ushort16);   \
  int      _CL_OVERLOADABLE NAME(short   , ushort  );   \
  int2     _CL_OVERLOADABLE NAME(short2  , ushort2 );   \
  int3     _CL_OVERLOADABLE NAME(short3  , ushort3 );   \
  int4     _CL_OVERLOADABLE NAME(short4  , ushort4 );   \
  int8     _CL_OVERLOADABLE NAME(short8  , ushort8 );   \
  int16    _CL_OVERLOADABLE NAME(short16 , ushort16);   \
  __IF_INT64(                                           \
  long     _CL_OVERLOADABLE NAME(int     , uint    );   \
  long2    _CL_OVERLOADABLE NAME(int2    , uint2   );   \
  long3    _CL_OVERLOADABLE NAME(int3    , uint3   );   \
  long4    _CL_OVERLOADABLE NAME(int4    , uint4   );   \
  long8    _CL_OVERLOADABLE NAME(int8    , uint8   );   \
  long16   _CL_OVERLOADABLE NAME(int16   , uint16  );   \
  ulong    _CL_OVERLOADABLE NAME(uint    , uint    );   \
  ulong2   _CL_OVERLOADABLE NAME(uint2   , uint2   );   \
  ulong3   _CL_OVERLOADABLE NAME(uint3   , uint3   );   \
  ulong4   _CL_OVERLOADABLE NAME(uint4   , uint4   );   \
  ulong8   _CL_OVERLOADABLE NAME(uint8   , uint8   );   \
  ulong16  _CL_OVERLOADABLE NAME(uint16  , uint16  );)
#define _CL_DECLARE_FUNC_I_IG(NAME)             \
  int _CL_OVERLOADABLE NAME(char   );           \
  int _CL_OVERLOADABLE NAME(char2  );           \
  int _CL_OVERLOADABLE NAME(char3  );           \
  int _CL_OVERLOADABLE NAME(char4  );           \
  int _CL_OVERLOADABLE NAME(char8  );           \
  int _CL_OVERLOADABLE NAME(char16 );           \
  int _CL_OVERLOADABLE NAME(short  );           \
  int _CL_OVERLOADABLE NAME(short2 );           \
  int _CL_OVERLOADABLE NAME(short3 );           \
  int _CL_OVERLOADABLE NAME(short4 );           \
  int _CL_OVERLOADABLE NAME(short8 );           \
  int _CL_OVERLOADABLE NAME(short16);           \
  int _CL_OVERLOADABLE NAME(int    );           \
  int _CL_OVERLOADABLE NAME(int2   );           \
  int _CL_OVERLOADABLE NAME(int3   );           \
  int _CL_OVERLOADABLE NAME(int4   );           \
  int _CL_OVERLOADABLE NAME(int8   );           \
  int _CL_OVERLOADABLE NAME(int16  );           \
  __IF_INT64(                                   \
  int _CL_OVERLOADABLE NAME(long   );           \
  int _CL_OVERLOADABLE NAME(long2  );           \
  int _CL_OVERLOADABLE NAME(long3  );           \
  int _CL_OVERLOADABLE NAME(long4  );           \
  int _CL_OVERLOADABLE NAME(long8  );           \
  int _CL_OVERLOADABLE NAME(long16 );)
#define _CL_DECLARE_FUNC_J_JJ(NAME)                     \
  int      _CL_OVERLOADABLE NAME(int     , int     );   \
  int2     _CL_OVERLOADABLE NAME(int2    , int2    );   \
  int3     _CL_OVERLOADABLE NAME(int3    , int3    );   \
  int4     _CL_OVERLOADABLE NAME(int4    , int4    );   \
  int8     _CL_OVERLOADABLE NAME(int8    , int8    );   \
  int16    _CL_OVERLOADABLE NAME(int16   , int16   );   \
  uint     _CL_OVERLOADABLE NAME(uint    , uint    );   \
  uint2    _CL_OVERLOADABLE NAME(uint2   , uint2   );   \
  uint3    _CL_OVERLOADABLE NAME(uint3   , uint3   );   \
  uint4    _CL_OVERLOADABLE NAME(uint4   , uint4   );   \
  uint8    _CL_OVERLOADABLE NAME(uint8   , uint8   );   \
  uint16   _CL_OVERLOADABLE NAME(uint16  , uint16  );
#define _CL_DECLARE_FUNC_J_JJJ(NAME)                            \
  int      _CL_OVERLOADABLE NAME(int     , int     , int     ); \
  int2     _CL_OVERLOADABLE NAME(int2    , int2    , int2    ); \
  int3     _CL_OVERLOADABLE NAME(int3    , int3    , int3    ); \
  int4     _CL_OVERLOADABLE NAME(int4    , int4    , int4    ); \
  int8     _CL_OVERLOADABLE NAME(int8    , int8    , int8    ); \
  int16    _CL_OVERLOADABLE NAME(int16   , int16   , int16   ); \
  uint     _CL_OVERLOADABLE NAME(uint    , uint    , uint    ); \
  uint2    _CL_OVERLOADABLE NAME(uint2   , uint2   , uint2   ); \
  uint3    _CL_OVERLOADABLE NAME(uint3   , uint3   , uint3   ); \
  uint4    _CL_OVERLOADABLE NAME(uint4   , uint4   , uint4   ); \
  uint8    _CL_OVERLOADABLE NAME(uint8   , uint8   , uint8   ); \
  uint16   _CL_OVERLOADABLE NAME(uint16  , uint16  , uint16  );

_CL_DECLARE_FUNC_UG_G(abs)
_CL_DECLARE_FUNC_UG_GG(abs_diff)
_CL_DECLARE_FUNC_G_GG(add_sat)
_CL_DECLARE_FUNC_G_GG(hadd)
_CL_DECLARE_FUNC_G_GG(rhadd)
_CL_DECLARE_FUNC_G_GGG(clamp)
_CL_DECLARE_FUNC_G_G(clz)
_CL_DECLARE_FUNC_G_GGG(mad_hi)
_CL_DECLARE_FUNC_G_GGG(mad_sat)
_CL_DECLARE_FUNC_G_GG(max)
_CL_DECLARE_FUNC_G_GS(max)
_CL_DECLARE_FUNC_G_GG(min)
_CL_DECLARE_FUNC_G_GS(min)
_CL_DECLARE_FUNC_G_GG(mul_hi)
_CL_DECLARE_FUNC_G_GG(rotate)
_CL_DECLARE_FUNC_G_GG(sub_sat)
_CL_DECLARE_FUNC_LG_GUG(upsample)
_CL_DECLARE_FUNC_G_G(popcount)
_CL_DECLARE_FUNC_J_JJJ(mad24)
_CL_DECLARE_FUNC_J_JJ(mul24)


/* Common Functions */

_CL_DECLARE_FUNC_V_VVV(clamp)
_CL_DECLARE_FUNC_V_VSS(clamp)
_CL_DECLARE_FUNC_V_V(degrees)
_CL_DECLARE_FUNC_V_VV(max)
_CL_DECLARE_FUNC_V_VS(max)
_CL_DECLARE_FUNC_V_VV(min)
_CL_DECLARE_FUNC_V_VS(min)
_CL_DECLARE_FUNC_V_VVV(mix)
_CL_DECLARE_FUNC_V_VVS(mix)
_CL_DECLARE_FUNC_V_V(radians)
_CL_DECLARE_FUNC_V_VV(step)
_CL_DECLARE_FUNC_V_SV(step)
_CL_DECLARE_FUNC_V_VVV(smoothstep)
_CL_DECLARE_FUNC_V_SSV(smoothstep)
_CL_DECLARE_FUNC_V_V(sign)


/* Geometric Functions */

__IF_FP16(    
half4 _CL_OVERLOADABLE cross(half4, half4);
half3 _CL_OVERLOADABLE cross(half3, half3);)
float4 _CL_OVERLOADABLE cross(float4, float4);
float3 _CL_OVERLOADABLE cross(float3, float3);
__IF_FP64(
double4 _CL_OVERLOADABLE cross(double4, double4);
double3 _CL_OVERLOADABLE cross(double3, double3);)
_CL_DECLARE_FUNC_S_VV(dot)
_CL_DECLARE_FUNC_S_VV(distance)
_CL_DECLARE_FUNC_S_V(length)
_CL_DECLARE_FUNC_V_V(normalize)
// TODO: no double version of these
_CL_DECLARE_FUNC_S_VV(fast_distance)
_CL_DECLARE_FUNC_S_V(fast_length)
_CL_DECLARE_FUNC_V_V(fast_normalize)


/* Relational Functions */

_CL_DECLARE_FUNC_J_VV(isequal)
_CL_DECLARE_FUNC_J_VV(isnotequal)
_CL_DECLARE_FUNC_J_VV(isgreater)
_CL_DECLARE_FUNC_J_VV(isgreaterequal)
_CL_DECLARE_FUNC_J_VV(isless)
_CL_DECLARE_FUNC_J_VV(islessequal)
_CL_DECLARE_FUNC_J_VV(islessgreater)
_CL_DECLARE_FUNC_J_V(isfinite)
_CL_DECLARE_FUNC_J_V(isinf)
_CL_DECLARE_FUNC_J_V(isnan)
_CL_DECLARE_FUNC_J_V(isnormal)
_CL_DECLARE_FUNC_J_VV(isordered)
_CL_DECLARE_FUNC_J_VV(isunordered)
_CL_DECLARE_FUNC_J_V(signbit)
_CL_DECLARE_FUNC_I_IG(any)
_CL_DECLARE_FUNC_I_IG(all)
_CL_DECLARE_FUNC_G_GGG(bitselect)
_CL_DECLARE_FUNC_V_VVV(bitselect)
_CL_DECLARE_FUNC_G_GGIG(select)
_CL_DECLARE_FUNC_G_GGUG(select)
_CL_DECLARE_FUNC_V_VVJ(select)
_CL_DECLARE_FUNC_V_VVU(select)


/* Vector Functions */

#define _CL_DECLARE_VLOAD(TYPE, MOD)                                    \
  TYPE##2  _CL_OVERLOADABLE vload2 (size_t offset, const MOD TYPE *p);  \
  TYPE##3  _CL_OVERLOADABLE vload3 (size_t offset, const MOD TYPE *p);  \
  TYPE##4  _CL_OVERLOADABLE vload4 (size_t offset, const MOD TYPE *p);  \
  TYPE##8  _CL_OVERLOADABLE vload8 (size_t offset, const MOD TYPE *p);  \
  TYPE##16 _CL_OVERLOADABLE vload16(size_t offset, const MOD TYPE *p);

_CL_DECLARE_VLOAD(char  , __global)
_CL_DECLARE_VLOAD(uchar , __global)
_CL_DECLARE_VLOAD(short , __global)
_CL_DECLARE_VLOAD(ushort, __global)
_CL_DECLARE_VLOAD(int   , __global)
_CL_DECLARE_VLOAD(uint  , __global)
__IF_INT64(
_CL_DECLARE_VLOAD(long  , __global)
_CL_DECLARE_VLOAD(ulong , __global))
__IF_FP16(    
_CL_DECLARE_VLOAD(half  , __global))
_CL_DECLARE_VLOAD(float , __global)
__IF_FP64(
_CL_DECLARE_VLOAD(double, __global))

_CL_DECLARE_VLOAD(char  , __local)
_CL_DECLARE_VLOAD(uchar , __local)
_CL_DECLARE_VLOAD(short , __local)
_CL_DECLARE_VLOAD(ushort, __local)
_CL_DECLARE_VLOAD(int   , __local)
_CL_DECLARE_VLOAD(uint  , __local)
__IF_INT64(
_CL_DECLARE_VLOAD(long  , __local)
_CL_DECLARE_VLOAD(ulong , __local))
__IF_FP16(    
_CL_DECLARE_VLOAD(half  , __local))
_CL_DECLARE_VLOAD(float , __local)
__IF_FP64(
_CL_DECLARE_VLOAD(double, __local))

_CL_DECLARE_VLOAD(char  , __constant)
_CL_DECLARE_VLOAD(uchar , __constant)
_CL_DECLARE_VLOAD(short , __constant)
_CL_DECLARE_VLOAD(ushort, __constant)
_CL_DECLARE_VLOAD(int   , __constant)
_CL_DECLARE_VLOAD(uint  , __constant)
__IF_INT64(
_CL_DECLARE_VLOAD(long  , __constant)
_CL_DECLARE_VLOAD(ulong , __constant))
__IF_FP16(    
_CL_DECLARE_VLOAD(half  , __constant))
_CL_DECLARE_VLOAD(float , __constant)
__IF_FP64(
_CL_DECLARE_VLOAD(double, __constant))

_CL_DECLARE_VLOAD(char  , __private)
_CL_DECLARE_VLOAD(uchar , __private)
_CL_DECLARE_VLOAD(short , __private)
_CL_DECLARE_VLOAD(ushort, __private)
_CL_DECLARE_VLOAD(int   , __private)
_CL_DECLARE_VLOAD(uint  , __private)
__IF_INT64(
_CL_DECLARE_VLOAD(long  , __private)
_CL_DECLARE_VLOAD(ulong , __private))
__IF_FP16(    
_CL_DECLARE_VLOAD(half  , __private))
_CL_DECLARE_VLOAD(float , __private)
__IF_FP64(
_CL_DECLARE_VLOAD(double, __private))

#define _CL_DECLARE_VSTORE(TYPE, MOD)                                   \
  void _CL_OVERLOADABLE vstore2 (TYPE##2  data, size_t offset, MOD TYPE *p); \
  void _CL_OVERLOADABLE vstore3 (TYPE##3  data, size_t offset, MOD TYPE *p); \
  void _CL_OVERLOADABLE vstore4 (TYPE##4  data, size_t offset, MOD TYPE *p); \
  void _CL_OVERLOADABLE vstore8 (TYPE##8  data, size_t offset, MOD TYPE *p); \
  void _CL_OVERLOADABLE vstore16(TYPE##16 data, size_t offset, MOD TYPE *p);

_CL_DECLARE_VSTORE(char  , __global)
_CL_DECLARE_VSTORE(uchar , __global)
_CL_DECLARE_VSTORE(short , __global)
_CL_DECLARE_VSTORE(ushort, __global)
_CL_DECLARE_VSTORE(int   , __global)
_CL_DECLARE_VSTORE(uint  , __global)
__IF_INT64(
_CL_DECLARE_VSTORE(long  , __global)
_CL_DECLARE_VSTORE(ulong , __global))
__IF_FP16(    
_CL_DECLARE_VSTORE(half  , __global))
_CL_DECLARE_VSTORE(float , __global)
__IF_FP64(
_CL_DECLARE_VSTORE(double, __global))

_CL_DECLARE_VSTORE(char  , __local)
_CL_DECLARE_VSTORE(uchar , __local)
_CL_DECLARE_VSTORE(short , __local)
_CL_DECLARE_VSTORE(ushort, __local)
_CL_DECLARE_VSTORE(int   , __local)
_CL_DECLARE_VSTORE(uint  , __local)
__IF_INT64(
_CL_DECLARE_VSTORE(long  , __local)
_CL_DECLARE_VSTORE(ulong , __local))
__IF_FP16(    
_CL_DECLARE_VSTORE(half  , __local))
_CL_DECLARE_VSTORE(float , __local)
__IF_FP64(
_CL_DECLARE_VSTORE(double, __local))

_CL_DECLARE_VSTORE(char  , __private)
_CL_DECLARE_VSTORE(uchar , __private)
_CL_DECLARE_VSTORE(short , __private)
_CL_DECLARE_VSTORE(ushort, __private)
_CL_DECLARE_VSTORE(int   , __private)
_CL_DECLARE_VSTORE(uint  , __private)
__IF_INT64(
_CL_DECLARE_VSTORE(long  , __private)
_CL_DECLARE_VSTORE(ulong , __private))
__IF_FP16(    
_CL_DECLARE_VSTORE(half  , __private))
_CL_DECLARE_VSTORE(float , __private)
__IF_FP64(
_CL_DECLARE_VSTORE(double, __private))

#define _CL_DECLARE_VLOAD_HALF(MOD)                                     \
  float   _CL_OVERLOADABLE vload_half   (size_t offset, const MOD half *p); \
  float2  _CL_OVERLOADABLE vload_half2  (size_t offset, const MOD half *p); \
  float3  _CL_OVERLOADABLE vload_half3  (size_t offset, const MOD half *p); \
  float4  _CL_OVERLOADABLE vload_half4  (size_t offset, const MOD half *p); \
  float8  _CL_OVERLOADABLE vload_half8  (size_t offset, const MOD half *p); \
  float16 _CL_OVERLOADABLE vload_half16 (size_t offset, const MOD half *p); \
  float   _CL_OVERLOADABLE vloada_half  (size_t offset, const MOD half *p); \
  float2  _CL_OVERLOADABLE vloada_half2 (size_t offset, const MOD half *p); \
  float3  _CL_OVERLOADABLE vloada_half3 (size_t offset, const MOD half *p); \
  float4  _CL_OVERLOADABLE vloada_half4 (size_t offset, const MOD half *p); \
  float8  _CL_OVERLOADABLE vloada_half8 (size_t offset, const MOD half *p); \
  float16 _CL_OVERLOADABLE vloada_half16(size_t offset, const MOD half *p);

_CL_DECLARE_VLOAD_HALF(__global)
_CL_DECLARE_VLOAD_HALF(__local)
_CL_DECLARE_VLOAD_HALF(__constant)
_CL_DECLARE_VLOAD_HALF(__private)

/* stores to half may have a suffix: _rte _rtz _rtp _rtn */
#define _CL_DECLARE_VSTORE_HALF(MOD, SUFFIX)                            \
  void _CL_OVERLOADABLE vstore_half##SUFFIX   (float   data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstore_half2##SUFFIX  (float2  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstore_half3##SUFFIX  (float3  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstore_half4##SUFFIX  (float4  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstore_half8##SUFFIX  (float8  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstore_half16##SUFFIX (float16 data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstorea_half##SUFFIX  (float   data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstorea_half2##SUFFIX (float2  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstorea_half3##SUFFIX (float3  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstorea_half4##SUFFIX (float4  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstorea_half8##SUFFIX (float8  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstorea_half16##SUFFIX(float16 data, size_t offset, MOD half *p); \
  __IF_FP64(                                                                              \
  void _CL_OVERLOADABLE vstore_half##SUFFIX   (double   data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstore_half2##SUFFIX  (double2  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstore_half3##SUFFIX  (double3  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstore_half4##SUFFIX  (double4  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstore_half8##SUFFIX  (double8  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstore_half16##SUFFIX (double16 data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstorea_half##SUFFIX  (double   data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstorea_half2##SUFFIX (double2  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstorea_half3##SUFFIX (double3  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstorea_half4##SUFFIX (double4  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstorea_half8##SUFFIX (double8  data, size_t offset, MOD half *p); \
  void _CL_OVERLOADABLE vstorea_half16##SUFFIX(double16 data, size_t offset, MOD half *p); \
  )

_CL_DECLARE_VSTORE_HALF(__global  ,     )
_CL_DECLARE_VSTORE_HALF(__global  , _rte)
_CL_DECLARE_VSTORE_HALF(__global  , _rtz)
_CL_DECLARE_VSTORE_HALF(__global  , _rtp)
_CL_DECLARE_VSTORE_HALF(__global  , _rtn)
_CL_DECLARE_VSTORE_HALF(__local   ,     )
_CL_DECLARE_VSTORE_HALF(__local   , _rte)
_CL_DECLARE_VSTORE_HALF(__local   , _rtz)
_CL_DECLARE_VSTORE_HALF(__local   , _rtp)
_CL_DECLARE_VSTORE_HALF(__local   , _rtn)
_CL_DECLARE_VSTORE_HALF(__private ,     )
_CL_DECLARE_VSTORE_HALF(__private , _rte)
_CL_DECLARE_VSTORE_HALF(__private , _rtz)
_CL_DECLARE_VSTORE_HALF(__private , _rtp)
_CL_DECLARE_VSTORE_HALF(__private , _rtn)

/* Atomic operations */

#define _CL_DECLARE_ATOMICS(MOD, TYPE)                                  \
  _CL_OVERLOADABLE TYPE atomic_add    (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_sub    (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_xchg   (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_inc    (volatile MOD TYPE *p);           \
  _CL_OVERLOADABLE TYPE atomic_dec    (volatile MOD TYPE *p);           \
  _CL_OVERLOADABLE TYPE atomic_cmpxchg(volatile MOD TYPE *p, TYPE cmp, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_min    (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_max    (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_and    (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_or     (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_xor    (volatile MOD TYPE *p, TYPE val);

_CL_DECLARE_ATOMICS(__global, int  )
_CL_DECLARE_ATOMICS(__global, uint )
_CL_DECLARE_ATOMICS(__local , int  )
_CL_DECLARE_ATOMICS(__local , uint )
_CL_OVERLOADABLE float atomic_xchg(volatile __global float *p, float val);
_CL_OVERLOADABLE float atomic_xchg(volatile __local  float *p, float val);

#define _CL_DECLARE_ATOMICS64(MOD, TYPE)                                \
  __IF_BA64(                                                            \
  _CL_OVERLOADABLE TYPE atomic_add    (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_sub    (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_xchg   (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_inc    (volatile MOD TYPE *p);           \
  _CL_OVERLOADABLE TYPE atomic_dec    (volatile MOD TYPE *p);           \
  _CL_OVERLOADABLE TYPE atomic_cmpxchg(volatile MOD TYPE *p, TYPE cmp, TYPE val);) \
  __IF_EA64(                                                            \
  _CL_OVERLOADABLE TYPE atomic_min    (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_max    (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_and    (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_or     (volatile MOD TYPE *p, TYPE val); \
  _CL_OVERLOADABLE TYPE atomic_xor    (volatile MOD TYPE *p, TYPE val);)

_CL_DECLARE_ATOMICS64(__global, long )
_CL_DECLARE_ATOMICS64(__global, ulong)
_CL_DECLARE_ATOMICS64(__local , long )
_CL_DECLARE_ATOMICS64(__local , ulong)

/* OpenCL 2.0 Atomics */

#if ((__clang_major__ >= 4) || (__clang_major__ == 3) && (__clang_minor__ >= 7))

#if (__OPENCL_C_VERSION__ > 199) && (__OPENCL_VERSION__ > 199)

#define ATOMIC_VAR_INIT(value) (value)

typedef enum memory_order {
  memory_order_relaxed,
  memory_order_acquire,
  memory_order_release,
  memory_order_acq_rel,
  memory_order_seq_cst,
} memory_order;

typedef enum memory_scope {
  memory_scope_work_item,
  memory_scope_work_group,
  memory_scope_device,
  memory_scope_all_svm_devices,
  memory_scope_sub_group,
} memory_scope;


void atomic_work_item_fence(cl_mem_fence_flags flags,
                            memory_order order,
                            memory_scope scope);

#define _CL_DECL_ATOMICS_EXPL1(RET, NAME, MOD, A)           \
  RET _CL_OVERLOADABLE NAME(volatile MOD A *object);        \
  RET _CL_OVERLOADABLE NAME ## _explicit(volatile MOD       \
            A *object, memory_order order);                 \
  RET _CL_OVERLOADABLE NAME ## _explicit(volatile MOD       \
            A *object, memory_order order, memory_scope scope);

#define _CL_DECL_ATOMICS_EXPL2(RET, NAME, MOD, A, C) \
  RET _CL_OVERLOADABLE NAME(volatile MOD A *object, C value);           \
  RET _CL_OVERLOADABLE NAME ## _explicit (volatile MOD A *object,       \
                                          C value, memory_order order); \
  RET _CL_OVERLOADABLE NAME ## _explicit (volatile MOD A *object,       \
                                          C value, memory_order order,  \
                                          memory_scope scope);

#define _CL_DECL_ATOMICS_EXPL_CMPXCH(TYPE, MOD, A, C)                   \
  _CL_OVERLOADABLE bool atomic_compare_exchange_##TYPE(                 \
                      volatile MOD A *object, private C *expected, C desired);  \
  _CL_OVERLOADABLE bool atomic_compare_exchange_##TYPE##_explicit(      \
                      volatile MOD A *object, private C *expected, C desired,   \
                      memory_order success, memory_order failure);      \
  _CL_OVERLOADABLE bool atomic_compare_exchange_##TYPE##_explicit(      \
                      volatile MOD A *object, private C *expected, C desired,   \
                      memory_order success, memory_order failure,       \
                      memory_scope scope);

#define _CL_DECLARE_ATOMICS_DECL(MOD, A, C)                                 \
  _CL_DECL_ATOMICS_EXPL2(void, atomic_store, MOD, A, C)                     \
  _CL_OVERLOADABLE void atomic_init (volatile MOD A *object, C value);      \
  _CL_DECL_ATOMICS_EXPL1(C, atomic_load, MOD, A)                            \
  _CL_DECL_ATOMICS_EXPL2(C, atomic_exchange, MOD, A, C)                     \
  _CL_DECL_ATOMICS_EXPL_CMPXCH(strong, MOD, A, C)                           \
  _CL_DECL_ATOMICS_EXPL_CMPXCH(weak, MOD, A, C)                             \
  _CL_DECL_ATOMICS_EXPL2(C, atomic_fetch_add, MOD, A, C)                    \
  _CL_DECL_ATOMICS_EXPL2(C, atomic_fetch_sub, MOD, A, C)                    \
  _CL_DECL_ATOMICS_EXPL2(C, atomic_fetch_or, MOD, A, C)                     \
  _CL_DECL_ATOMICS_EXPL2(C, atomic_fetch_xor, MOD, A, C)                    \
  _CL_DECL_ATOMICS_EXPL2(C, atomic_fetch_and, MOD, A, C)                    \
  _CL_DECL_ATOMICS_EXPL2(C, atomic_fetch_min, MOD, A, C)                    \
  _CL_DECL_ATOMICS_EXPL2(C, atomic_fetch_max, MOD, A, C)

#define _CL_DECLARE_ATOMICS2(MOD)                                           \
  _CL_DECL_ATOMICS_EXPL1(bool, atomic_flag_test_and_set, MOD, atomic_flag)  \
  _CL_DECL_ATOMICS_EXPL1(void, atomic_flag_clear, MOD, atomic_flag)         \
  _CL_DECLARE_ATOMICS_DECL(MOD, atomic_int, int)                            \
  _CL_DECLARE_ATOMICS_DECL(MOD, atomic_uint, uint)                          \
  _CL_DECLARE_ATOMICS_DECL(MOD, atomic_float, float)                        \
  __IF_EA64(_CL_DECLARE_ATOMICS_DECL(MOD, atomic_long, long))               \
  __IF_EA64(_CL_DECLARE_ATOMICS_DECL(MOD, atomic_ulong, ulong))             \
  __IF_FP64(_CL_DECLARE_ATOMICS_DECL(MOD, atomic_double, double))           \
  _CL_DECLARE_ATOMICS_DECL(MOD, atomic_intptr_t, intptr_t)                  \
  _CL_DECLARE_ATOMICS_DECL(MOD, atomic_uintptr_t, uintptr_t)                \
  _CL_DECLARE_ATOMICS_DECL(MOD, atomic_ptrdiff_t, ptrdiff_t)                \
  _CL_DECLARE_ATOMICS_DECL(MOD, atomic_size_t, size_t)

_CL_DECLARE_ATOMICS2(global)

_CL_DECLARE_ATOMICS2(local)

#endif

#endif

/* Miscellaneous Vector Functions */


#define _CL_DECLARE_SHUFFLE(ELTYPE, MTYPE, M, N )                     \
  ELTYPE##N _CL_OVERLOADABLE shuffle(ELTYPE##M, MTYPE##N);            \
  ELTYPE##N _CL_OVERLOADABLE shuffle2(ELTYPE##M, ELTYPE##M, MTYPE##N);\

#define _CL_DECLARE_SHUFFLE_M(ELTYPE, MTYPE, M)                       \
  _CL_DECLARE_SHUFFLE(ELTYPE, MTYPE, M, 2)                            \
  _CL_DECLARE_SHUFFLE(ELTYPE, MTYPE, M, 3)                            \
  _CL_DECLARE_SHUFFLE(ELTYPE, MTYPE, M, 4)                            \
  _CL_DECLARE_SHUFFLE(ELTYPE, MTYPE, M, 8)                            \
  _CL_DECLARE_SHUFFLE(ELTYPE, MTYPE, M, 16)

#define _CL_DECLARE_SHUFFLE_MN(ELTYPE, MTYPE)                         \
  _CL_DECLARE_SHUFFLE_M(ELTYPE, MTYPE, 2)                             \
  _CL_DECLARE_SHUFFLE_M(ELTYPE, MTYPE, 3)                             \
  _CL_DECLARE_SHUFFLE_M(ELTYPE, MTYPE, 4)                             \
  _CL_DECLARE_SHUFFLE_M(ELTYPE, MTYPE, 8)                             \
  _CL_DECLARE_SHUFFLE_M(ELTYPE, MTYPE, 16)

_CL_DECLARE_SHUFFLE_MN(char  , uchar )
_CL_DECLARE_SHUFFLE_MN(uchar , uchar )
_CL_DECLARE_SHUFFLE_MN(short , ushort)
_CL_DECLARE_SHUFFLE_MN(ushort, ushort)
__IF_FP16(
_CL_DECLARE_SHUFFLE_MN(half  , ushort))
_CL_DECLARE_SHUFFLE_MN(int   , uint  )
_CL_DECLARE_SHUFFLE_MN(uint  , uint  )
_CL_DECLARE_SHUFFLE_MN(float , uint  )
__IF_INT64(
_CL_DECLARE_SHUFFLE_MN(long  , ulong )
_CL_DECLARE_SHUFFLE_MN(ulong , ulong ))
__IF_FP64(
_CL_DECLARE_SHUFFLE_MN(double, ulong ))

void _CL_OVERLOADABLE wait_group_events (int num_events, event_t *event_list);

/***************************************************************************/

/* Async Copies from Global to Local Memory, Local to
   Global Memory, and Prefetch */

#define _CL_DECLARE_ASYNC_COPY_FUNCS_SINGLE(GENTYPE)            \
  _CL_OVERLOADABLE                                              \
  event_t async_work_group_copy (__local GENTYPE *dst,          \
                                 const __global GENTYPE *src,   \
                                 size_t num_gentypes,           \
                                 event_t event);                \
                                                                \
  _CL_OVERLOADABLE                                              \
  event_t async_work_group_copy (__global GENTYPE *dst,         \
                                 const __local GENTYPE *src,    \
                                 size_t num_gentypes,           \
                                 event_t event);                \
                                                                
#define _CL_DECLARE_ASYNC_COPY_FUNCS(GENTYPE)      \
  _CL_DECLARE_ASYNC_COPY_FUNCS_SINGLE(GENTYPE)     \
  _CL_DECLARE_ASYNC_COPY_FUNCS_SINGLE(GENTYPE##2)   \
  _CL_DECLARE_ASYNC_COPY_FUNCS_SINGLE(GENTYPE##3)   \
  _CL_DECLARE_ASYNC_COPY_FUNCS_SINGLE(GENTYPE##4)   \
  _CL_DECLARE_ASYNC_COPY_FUNCS_SINGLE(GENTYPE##8)   \
  _CL_DECLARE_ASYNC_COPY_FUNCS_SINGLE(GENTYPE##16)  \

_CL_DECLARE_ASYNC_COPY_FUNCS(char);
_CL_DECLARE_ASYNC_COPY_FUNCS(uchar);
_CL_DECLARE_ASYNC_COPY_FUNCS(short);
_CL_DECLARE_ASYNC_COPY_FUNCS(ushort);
_CL_DECLARE_ASYNC_COPY_FUNCS(int);
_CL_DECLARE_ASYNC_COPY_FUNCS(uint);
__IF_INT64(_CL_DECLARE_ASYNC_COPY_FUNCS(long));
__IF_INT64(_CL_DECLARE_ASYNC_COPY_FUNCS(ulong));

__IF_FP16 (_CL_DECLARE_ASYNC_COPY_FUNCS (half));
_CL_DECLARE_ASYNC_COPY_FUNCS(float);
__IF_FP64(_CL_DECLARE_ASYNC_COPY_FUNCS(double));

/***************************************************************************/

#define _CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS_SINGLE(GENTYPE)                  \
  _CL_OVERLOADABLE                                                            \
  event_t async_work_group_strided_copy (                                     \
      __local GENTYPE *dst, const __global GENTYPE *src, size_t num_gentypes, \
      size_t src_stride, event_t event);                                      \
                                                                              \
  _CL_OVERLOADABLE                                                            \
  event_t async_work_group_strided_copy (                                     \
      __global GENTYPE *dst, const __local GENTYPE *src, size_t num_gentypes, \
      size_t dst_stride, event_t event);

#define _CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS(GENTYPE)                         \
  _CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS_SINGLE (GENTYPE)                       \
  _CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS_SINGLE (GENTYPE##2)                    \
  _CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS_SINGLE (GENTYPE##3)                    \
  _CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS_SINGLE (GENTYPE##4)                    \
  _CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS_SINGLE (GENTYPE##8)                    \
  _CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS_SINGLE (GENTYPE##16)

_CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS (char);
_CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS (uchar);
_CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS (short);
_CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS (ushort);
_CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS (int);
_CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS (uint);
__IF_INT64 (_CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS (long));
__IF_INT64 (_CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS (ulong));

__IF_FP16 (_CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS (half));
_CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS (float);
__IF_FP64 (_CL_DECLARE_ASYNC_STRIDED_COPY_FUNCS (double));

/***************************************************************************/

#define _CL_DECLARE_PREFETCH_FUNCS_SINGLE(GENTYPE) \
  _CL_OVERLOADABLE \
  void prefetch (const __global GENTYPE *p, size_t num_gentypes);

#define _CL_DECLARE_PREFETCH_FUNCS(GENTYPE)       \
  _CL_DECLARE_PREFETCH_FUNCS_SINGLE(GENTYPE)      \
  _CL_DECLARE_PREFETCH_FUNCS_SINGLE(GENTYPE##2)   \
  _CL_DECLARE_PREFETCH_FUNCS_SINGLE(GENTYPE##3)   \
  _CL_DECLARE_PREFETCH_FUNCS_SINGLE(GENTYPE##4)   \
  _CL_DECLARE_PREFETCH_FUNCS_SINGLE(GENTYPE##8)   \
  _CL_DECLARE_PREFETCH_FUNCS_SINGLE(GENTYPE##16)  \

_CL_DECLARE_PREFETCH_FUNCS(char);
_CL_DECLARE_PREFETCH_FUNCS(uchar);
_CL_DECLARE_PREFETCH_FUNCS(short);
_CL_DECLARE_PREFETCH_FUNCS(ushort);
_CL_DECLARE_PREFETCH_FUNCS(int);
_CL_DECLARE_PREFETCH_FUNCS(uint);
__IF_INT64(_CL_DECLARE_PREFETCH_FUNCS(long));
__IF_INT64(_CL_DECLARE_PREFETCH_FUNCS(ulong));
__IF_FP16(_CL_DECLARE_PREFETCH_FUNCS(half));
_CL_DECLARE_PREFETCH_FUNCS(float);
__IF_FP64(_CL_DECLARE_PREFETCH_FUNCS(double));


/***************************************************************************/

/* NO sampler */

float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image1d_t image, int coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image1d_buffer_t image,
                                     int coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image1d_array_t image, int2 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image2d_t image, int2 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image2d_array_t image, int4 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image3d_t image, int4 coord);


uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image1d_t image, int coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image1d_t image, int coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image1d_buffer_t image,
                                     int coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image1d_buffer_t image,
                                   int coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image1d_array_t image,
                                     int2 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image1d_array_t image,
                                   int2 coord);

uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image2d_t image, int2 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image2d_t image, int2 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image2d_array_t image,
                                     int4 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image2d_array_t image,
                                   int4 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image3d_t image, int4 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image3d_t image, int4 coord);

/* float4 img + float coords + sampler */

float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image1d_t image,
                                     sampler_t sampler, float coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image1d_buffer_t image,
                                     sampler_t sampler, float coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image1d_array_t image, sampler_t sampler,
                                     float2 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image2d_t image,
                                     sampler_t sampler, float2 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image2d_array_t image, sampler_t sampler,
                                     float4 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image3d_t image,
                                     sampler_t sampler, float4 coord);

/* float4 img + int coords + sampler */

float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image1d_t image,
                                     sampler_t sampler, int coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image1d_buffer_t image,
                                     sampler_t sampler, int coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image1d_array_t image,
                                     sampler_t sampler, int2 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image2d_t image,
                                     sampler_t sampler, int2 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RO_AQ image2d_array_t image,
                                     sampler_t sampler, int4 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef ( IMG_RO_AQ image3d_t image, sampler_t sampler,
                                     int4 coord);

/* int4 img + float coords + sampler */

uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image1d_t image,
                                     sampler_t sampler, float coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image1d_t image,
                                   sampler_t sampler, float coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image1d_buffer_t image,
                                     sampler_t sampler, float coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image1d_buffer_t image,
                                   sampler_t sampler, float coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image1d_array_t image,
                                     sampler_t sampler, float2 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image1d_array_t image,
                                   sampler_t sampler, float2 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image2d_t image,
                                     sampler_t sampler, float2 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image2d_t image,
                                   sampler_t sampler, float2 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image2d_array_t image,
                                     sampler_t sampler, float4 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image2d_array_t image,
                                   sampler_t sampler, float4 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image3d_t image,
                                     sampler_t sampler, float4 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image3d_t image,
                                   sampler_t sampler, float4 coord);

/* int4 img + int coords + sampler */

uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image1d_t image,
                                     sampler_t sampler, int coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image1d_t image,
                                   sampler_t sampler, int coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image1d_buffer_t image,
                                     sampler_t sampler, int coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image1d_buffer_t image,
                                   sampler_t sampler, int coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image1d_array_t image,
                                     sampler_t sampler, int2 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image1d_array_t image,
                                   sampler_t sampler, int2 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image2d_t image,
                                     sampler_t sampler, int2 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image2d_t image,
                                   sampler_t sampler, int2 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RO_AQ image2d_array_t image,
                                     sampler_t sampler, int4 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image2d_array_t image,
                                   sampler_t sampler, int4 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui ( IMG_RO_AQ image3d_t image, sampler_t sampler,
                                     int4 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RO_AQ image3d_t image,
                                   sampler_t sampler, int4 coord);

/****************************************************************************/

#ifdef CLANG_HAS_RW_IMAGES

/* NO sampler */

float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image1d_t image, int coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image1d_buffer_t image,
                                     int coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image1d_array_t image, int2 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image2d_t image, int2 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image2d_array_t image, int4 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image3d_t image, int4 coord);

uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image1d_t image, int coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image1d_t image, int coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image1d_buffer_t image,
                                     int coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image1d_buffer_t image,
                                   int coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image1d_array_t image,
                                     int2 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image1d_array_t image,
                                   int2 coord);

uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image2d_t image, int2 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image2d_t image, int2 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image2d_array_t image,
                                     int4 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image2d_array_t image,
                                   int4 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image3d_t image, int4 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image3d_t image, int4 coord);

/* float4 img + float coords + sampler */

float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image1d_t image,
                                     sampler_t sampler, float coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image1d_buffer_t image,
                                     sampler_t sampler, float coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image1d_array_t image, sampler_t sampler,
                                     float2 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image2d_t image,
                                     sampler_t sampler, float2 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image2d_array_t image, sampler_t sampler,
                                     float4 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image3d_t image,
                                     sampler_t sampler, float4 coord);

/* float4 img + int coords + sampler */

float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image1d_t image,
                                     sampler_t sampler, int coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image1d_buffer_t image,
                                     sampler_t sampler, int coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image1d_array_t image,
                                     sampler_t sampler, int2 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image2d_t image,
                                     sampler_t sampler, int2 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef (IMG_RW_AQ image2d_array_t image,
                                     sampler_t sampler, int4 coord);
float4 _CL_OVERLOADABLE _CL_READONLY read_imagef ( IMG_RW_AQ image3d_t image, sampler_t sampler,
                                     int4 coord);

/* int4 img + float coords + sampler */

uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image1d_t image,
                                     sampler_t sampler, float coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image1d_t image,
                                   sampler_t sampler, float coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image1d_buffer_t image,
                                     sampler_t sampler, float coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image1d_buffer_t image,
                                   sampler_t sampler, float coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image1d_array_t image,
                                     sampler_t sampler, float2 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image1d_array_t image,
                                   sampler_t sampler, float2 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image2d_t image,
                                     sampler_t sampler, float2 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image2d_t image,
                                   sampler_t sampler, float2 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image2d_array_t image,
                                     sampler_t sampler, float4 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image2d_array_t image,
                                   sampler_t sampler, float4 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image3d_t image,
                                     sampler_t sampler, float4 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image3d_t image,
                                   sampler_t sampler, float4 coord);

/* int4 img + int coords + sampler */

uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image1d_t image,
                                     sampler_t sampler, int coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image1d_t image,
                                   sampler_t sampler, int coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image1d_buffer_t image,
                                     sampler_t sampler, int coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image1d_buffer_t image,
                                   sampler_t sampler, int coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image1d_array_t image,
                                     sampler_t sampler, int2 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image1d_array_t image,
                                   sampler_t sampler, int2 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image2d_t image,
                                     sampler_t sampler, int2 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image2d_t image,
                                   sampler_t sampler, int2 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui (IMG_RW_AQ image2d_array_t image,
                                     sampler_t sampler, int4 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image2d_array_t image,
                                   sampler_t sampler, int4 coord);
uint4 _CL_OVERLOADABLE _CL_READONLY read_imageui ( IMG_RW_AQ image3d_t image, sampler_t sampler,
                                     int4 coord);
int4 _CL_OVERLOADABLE _CL_READONLY read_imagei (IMG_RW_AQ image3d_t image,
                                   sampler_t sampler, int4 coord);

#endif

/******************************************************************************************/

void _CL_OVERLOADABLE write_imagef (IMG_WO_AQ image1d_t image, int coord,
                                    float4 color);
void _CL_OVERLOADABLE write_imagei (IMG_WO_AQ image1d_t image, int coord,
                                    int4 color);
void _CL_OVERLOADABLE write_imageui (IMG_WO_AQ image1d_t image, int coord,
                                     uint4 color);

void _CL_OVERLOADABLE write_imagef (IMG_WO_AQ image1d_buffer_t image,
                                    int coord, float4 color);
void _CL_OVERLOADABLE write_imagei (IMG_WO_AQ image1d_buffer_t image,
                                    int coord, int4 color);
void _CL_OVERLOADABLE write_imageui (IMG_WO_AQ image1d_buffer_t image,
                                     int coord, uint4 color);

void _CL_OVERLOADABLE write_imagef (IMG_WO_AQ image1d_array_t image,
                                    int2 coord, float4 color);
void _CL_OVERLOADABLE write_imagei (IMG_WO_AQ image1d_array_t image,
                                    int2 coord, int4 color);
void _CL_OVERLOADABLE write_imageui (IMG_WO_AQ image1d_array_t image,
                                     int2 coord, uint4 color);

void _CL_OVERLOADABLE write_imagef (IMG_WO_AQ image2d_t image, int2 coord,
                                    float4 color);
void _CL_OVERLOADABLE write_imagei (IMG_WO_AQ image2d_t image, int2 coord,
                                    int4 color);
void _CL_OVERLOADABLE write_imageui (IMG_WO_AQ image2d_t image, int2 coord,
                                     uint4 color);
__IF_FP16 (void _CL_OVERLOADABLE write_imageh (IMG_WO_AQ image2d_t image,
                                               int2 coord, half4 color));

void _CL_OVERLOADABLE write_imagef (IMG_WO_AQ image2d_array_t image,
                                    int4 coord, float4 color);
void _CL_OVERLOADABLE write_imagei (IMG_WO_AQ image2d_array_t image,
                                    int4 coord, int4 color);
void _CL_OVERLOADABLE write_imageui (IMG_WO_AQ image2d_array_t image,
                                     int4 coord, uint4 color);
__IF_FP16 (void _CL_OVERLOADABLE write_imageh (IMG_WO_AQ image2d_array_t image,
                                               int4 coord, half4 color));

#ifdef cl_khr_3d_image_writes
void _CL_OVERLOADABLE write_imagef (IMG_WO_AQ image3d_t image, int4 coord,
                                    float4 color);
void _CL_OVERLOADABLE write_imagei (IMG_WO_AQ image3d_t image, int4 coord,
                                    int4 color);
void _CL_OVERLOADABLE write_imageui (IMG_WO_AQ image3d_t image, int4 coord,
                                     uint4 color);
__IF_FP16 (void _CL_OVERLOADABLE write_imageh (IMG_WO_AQ image3d_t image,
                                               int4 coord, half4 color));
#endif

/* UNIMPLEMENTED: 1d / 1d array */

#ifdef CLANG_HAS_RW_IMAGES

void _CL_OVERLOADABLE write_imagef (IMG_RW_AQ image1d_t image, int coord,
                                    float4 color);
void _CL_OVERLOADABLE write_imagei (IMG_RW_AQ image1d_t image, int coord,
                                    int4 color);
void _CL_OVERLOADABLE write_imageui (IMG_RW_AQ image1d_t image, int coord,
                                     uint4 color);

void _CL_OVERLOADABLE write_imagef (IMG_RW_AQ image1d_buffer_t image,
                                    int coord, float4 color);
void _CL_OVERLOADABLE write_imagei (IMG_RW_AQ image1d_buffer_t image,
                                    int coord, int4 color);
void _CL_OVERLOADABLE write_imageui (IMG_RW_AQ image1d_buffer_t image,
                                     int coord, uint4 color);

void _CL_OVERLOADABLE write_imagef (IMG_RW_AQ image1d_array_t image,
                                    int2 coord, float4 color);
void _CL_OVERLOADABLE write_imagei (IMG_RW_AQ image1d_array_t image,
                                    int2 coord, int4 color);
void _CL_OVERLOADABLE write_imageui (IMG_RW_AQ image1d_array_t image,
                                     int2 coord, uint4 color);

void _CL_OVERLOADABLE write_imagef (IMG_RW_AQ image2d_t image, int2 coord,
                                    float4 color);
void _CL_OVERLOADABLE write_imagei (IMG_RW_AQ image2d_t image, int2 coord,
                                    int4 color);
void _CL_OVERLOADABLE write_imageui (IMG_RW_AQ image2d_t image, int2 coord,
                                     uint4 color);
__IF_FP16 (void _CL_OVERLOADABLE write_imageh (IMG_RW_AQ image2d_t image,
                                               int2 coord, half4 color));

void _CL_OVERLOADABLE write_imagef (IMG_RW_AQ image2d_array_t image,
                                    int4 coord, float4 color);
void _CL_OVERLOADABLE write_imagei (IMG_RW_AQ image2d_array_t image,
                                    int4 coord, int4 color);
void _CL_OVERLOADABLE write_imageui (IMG_RW_AQ image2d_array_t image,
                                     int4 coord, uint4 color);
__IF_FP16 (void _CL_OVERLOADABLE write_imageh (IMG_RW_AQ image2d_array_t image,
                                               int4 coord, half4 color));

void _CL_OVERLOADABLE write_imagef (IMG_RW_AQ image3d_t image, int4 coord,
                                    float4 color);
void _CL_OVERLOADABLE write_imagei (IMG_RW_AQ image3d_t image, int4 coord,
                                    int4 color);
void _CL_OVERLOADABLE write_imageui (IMG_RW_AQ image3d_t image, int4 coord,
                                     uint4 color);
__IF_FP16 (void _CL_OVERLOADABLE write_imageh (IMG_RW_AQ image3d_t image,
                                               int4 coord, half4 color));

#endif


/******************************************************************************************/

int _CL_OVERLOADABLE get_image_channel_data_type (IMG_RO_AQ image1d_t);
int _CL_OVERLOADABLE get_image_channel_data_type (IMG_RO_AQ image1d_array_t);
int _CL_OVERLOADABLE get_image_channel_data_type (IMG_RO_AQ image2d_array_t);
int _CL_OVERLOADABLE get_image_channel_data_type (IMG_RO_AQ image2d_t);
int _CL_OVERLOADABLE get_image_channel_data_type (IMG_RO_AQ image3d_t);

int _CL_OVERLOADABLE get_image_channel_order (IMG_RO_AQ image1d_t);
int _CL_OVERLOADABLE get_image_channel_order (IMG_RO_AQ image1d_array_t);
int _CL_OVERLOADABLE get_image_channel_order (IMG_RO_AQ image2d_array_t);
int _CL_OVERLOADABLE get_image_channel_order (IMG_RO_AQ image2d_t);
int _CL_OVERLOADABLE get_image_channel_order (IMG_RO_AQ image3d_t);

int _CL_OVERLOADABLE get_image_width (IMG_RO_AQ image1d_t image);
int _CL_OVERLOADABLE get_image_width (IMG_RO_AQ image1d_array_t image);
int _CL_OVERLOADABLE get_image_width (IMG_RO_AQ image2d_t image);
int _CL_OVERLOADABLE get_image_width (IMG_RO_AQ image2d_array_t image);
int _CL_OVERLOADABLE get_image_width (IMG_RO_AQ image3d_t image);

int _CL_OVERLOADABLE get_image_height (IMG_RO_AQ image1d_t image);
int _CL_OVERLOADABLE get_image_height (IMG_RO_AQ image1d_array_t image);
int _CL_OVERLOADABLE get_image_height (IMG_RO_AQ image2d_t image);
int _CL_OVERLOADABLE get_image_height (IMG_RO_AQ image2d_array_t image);
int _CL_OVERLOADABLE get_image_height (IMG_RO_AQ image3d_t image);

int _CL_OVERLOADABLE get_image_depth (IMG_RO_AQ image3d_t image);

int2 _CL_OVERLOADABLE get_image_dim (IMG_RO_AQ image2d_t image);
int2 _CL_OVERLOADABLE get_image_dim (IMG_RO_AQ image2d_array_t image);
int4 _CL_OVERLOADABLE get_image_dim (IMG_RO_AQ image3d_t image);

size_t _CL_OVERLOADABLE get_image_array_size (IMG_RO_AQ image1d_array_t image);
size_t _CL_OVERLOADABLE get_image_array_size (IMG_RO_AQ image2d_array_t image);

#ifdef CLANG_HAS_IMAGE_AS

int _CL_OVERLOADABLE get_image_channel_order (IMG_WO_AQ image1d_t);
int _CL_OVERLOADABLE get_image_channel_order (IMG_WO_AQ image1d_array_t);
int _CL_OVERLOADABLE get_image_channel_order (IMG_WO_AQ image2d_array_t);
int _CL_OVERLOADABLE get_image_channel_order (IMG_WO_AQ image2d_t);
int _CL_OVERLOADABLE get_image_channel_order (IMG_WO_AQ image3d_t);

int _CL_OVERLOADABLE get_image_channel_data_type (IMG_WO_AQ image1d_t);
int _CL_OVERLOADABLE get_image_channel_data_type (IMG_WO_AQ image1d_array_t);
int _CL_OVERLOADABLE get_image_channel_data_type (IMG_WO_AQ image2d_array_t);
int _CL_OVERLOADABLE get_image_channel_data_type (IMG_WO_AQ image2d_t);
int _CL_OVERLOADABLE get_image_channel_data_type (IMG_WO_AQ image3d_t);

int _CL_OVERLOADABLE get_image_width (IMG_WO_AQ image1d_t image);
int _CL_OVERLOADABLE get_image_width (IMG_WO_AQ image1d_array_t image);
int _CL_OVERLOADABLE get_image_width (IMG_WO_AQ image2d_t image);
int _CL_OVERLOADABLE get_image_width (IMG_WO_AQ image2d_array_t image);
int _CL_OVERLOADABLE get_image_width (IMG_WO_AQ image3d_t image);

int _CL_OVERLOADABLE get_image_height (IMG_WO_AQ image1d_t image);
int _CL_OVERLOADABLE get_image_height (IMG_WO_AQ image1d_array_t image);
int _CL_OVERLOADABLE get_image_height (IMG_WO_AQ image2d_t image);
int _CL_OVERLOADABLE get_image_height (IMG_WO_AQ image2d_array_t image);
int _CL_OVERLOADABLE get_image_height (IMG_WO_AQ image3d_t image);

int _CL_OVERLOADABLE get_image_depth (IMG_WO_AQ image3d_t image);

int2 _CL_OVERLOADABLE get_image_dim (IMG_WO_AQ image2d_t image);
int2 _CL_OVERLOADABLE get_image_dim (IMG_WO_AQ image2d_array_t image);
int4 _CL_OVERLOADABLE get_image_dim (IMG_WO_AQ image3d_t image);

size_t _CL_OVERLOADABLE get_image_array_size (IMG_WO_AQ image1d_array_t image);
size_t _CL_OVERLOADABLE get_image_array_size (IMG_WO_AQ image2d_array_t image);

#endif

#ifdef CLANG_HAS_RW_IMAGES

int _CL_OVERLOADABLE get_image_channel_order (IMG_RW_AQ image1d_t);
int _CL_OVERLOADABLE get_image_channel_order (IMG_RW_AQ image1d_array_t);
int _CL_OVERLOADABLE get_image_channel_order (IMG_RW_AQ image2d_array_t);
int _CL_OVERLOADABLE get_image_channel_order (IMG_RW_AQ image2d_t);
int _CL_OVERLOADABLE get_image_channel_order (IMG_RW_AQ image3d_t);

int _CL_OVERLOADABLE get_image_channel_data_type (IMG_RW_AQ image1d_t);
int _CL_OVERLOADABLE get_image_channel_data_type (IMG_RW_AQ image1d_array_t);
int _CL_OVERLOADABLE get_image_channel_data_type (IMG_RW_AQ image2d_array_t);
int _CL_OVERLOADABLE get_image_channel_data_type (IMG_RW_AQ image2d_t);
int _CL_OVERLOADABLE get_image_channel_data_type (IMG_RW_AQ image3d_t);

int _CL_OVERLOADABLE get_image_width (IMG_RW_AQ image1d_t image);
int _CL_OVERLOADABLE get_image_width (IMG_RW_AQ image1d_array_t image);
int _CL_OVERLOADABLE get_image_width (IMG_RW_AQ image2d_t image);
int _CL_OVERLOADABLE get_image_width (IMG_RW_AQ image2d_array_t image);
int _CL_OVERLOADABLE get_image_width (IMG_RW_AQ image3d_t image);

int _CL_OVERLOADABLE get_image_height (IMG_RW_AQ image1d_t image);
int _CL_OVERLOADABLE get_image_height (IMG_RW_AQ image1d_array_t image);
int _CL_OVERLOADABLE get_image_height (IMG_RW_AQ image2d_t image);
int _CL_OVERLOADABLE get_image_height (IMG_RW_AQ image2d_array_t image);
int _CL_OVERLOADABLE get_image_height (IMG_RW_AQ image3d_t image);

int _CL_OVERLOADABLE get_image_depth (IMG_RW_AQ image3d_t image);

int2 _CL_OVERLOADABLE get_image_dim (IMG_RW_AQ image2d_t image);
int2 _CL_OVERLOADABLE get_image_dim (IMG_RW_AQ image2d_array_t image);
int4 _CL_OVERLOADABLE get_image_dim (IMG_RW_AQ image3d_t image);

size_t _CL_OVERLOADABLE get_image_array_size (IMG_RW_AQ image1d_array_t image);
size_t _CL_OVERLOADABLE get_image_array_size (IMG_RW_AQ image2d_array_t image);

#endif

#endif

#pragma OPENCL EXTENSION all : disable