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
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
|
{{+bindTo:partials.standard_nacl_article}}
<section id="contents-of-pnacl-bitcode-files">
<h1 id="contents-of-pnacl-bitcode-files">Contents Of PNaCl Bitcode Files</h1>
<div class="contents local" id="contents" style="display: none">
<ul class="small-gap">
<li><a class="reference internal" href="#introduction" id="id6">Introduction</a></li>
<li><a class="reference internal" href="#data-model" id="id7">Data Model</a></li>
<li><a class="reference internal" href="#pnacl-blocks" id="id8">PNaCl Blocks</a></li>
<li><a class="reference internal" href="#pnacl-records" id="id9">PNaCl Records</a></li>
<li><a class="reference internal" href="#default-abbreviations" id="id10">Default Abbreviations</a></li>
<li><a class="reference internal" href="#pnacl-identifiers" id="id11">PNaCl Identifiers</a></li>
<li><a class="reference internal" href="#conventions-for-describing-records" id="id12">Conventions For Describing Records</a></li>
<li><a class="reference internal" href="#factorial-example" id="id13">Factorial Example</a></li>
<li><a class="reference internal" href="#road-map" id="id14">Road Map</a></li>
<li><p class="first"><a class="reference internal" href="#global-state" id="id15">Global State</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#typing-functions" id="id16">Typing Functions</a></li>
<li><a class="reference internal" href="#link-to-id-counters" id="id17">ID Counters</a></li>
<li><a class="reference internal" href="#size-variables" id="id18">Size Variables</a></li>
<li><a class="reference internal" href="#other-variables" id="id19">Other Variables</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#global-records" id="id20">Global Records</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#header-record" id="id21">Header Record</a></li>
<li><a class="reference internal" href="#enter-block-record" id="id22">Enter Block Record</a></li>
<li><a class="reference internal" href="#exit-block-record" id="id23">Exit Block Record</a></li>
<li><a class="reference internal" href="#abbreviation-record" id="id24">Abbreviation Record</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#types-block" id="id25">Types Block</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#count-record" id="id26">Count Record</a></li>
<li><a class="reference internal" href="#void-type" id="id27">Void Type</a></li>
<li><a class="reference internal" href="#integer-types" id="id28">Integer Types</a></li>
<li><a class="reference internal" href="#bit-floating-point-type" id="id29">32-Bit Floating Point Type</a></li>
<li><a class="reference internal" href="#id1" id="id30">64-bit Floating Point Type</a></li>
<li><a class="reference internal" href="#vector-types" id="id31">Vector Types</a></li>
<li><a class="reference internal" href="#function-type" id="id32">Function Type</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#globals-block" id="id33">Globals Block</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#link-for-globals-count-record" id="id34">Count Record</a></li>
<li><a class="reference internal" href="#global-variable-addresses" id="id35">Global Variable Addresses</a></li>
<li><a class="reference internal" href="#global-constant-addresses" id="id36">Global Constant Addresses</a></li>
<li><a class="reference internal" href="#zerofill-initializer" id="id37">Zerofill Initializer</a></li>
<li><a class="reference internal" href="#data-initializer" id="id38">Data Initializer</a></li>
<li><a class="reference internal" href="#relocation-initializer" id="id39">Relocation Initializer</a></li>
<li><a class="reference internal" href="#subfield-relocation-initializer" id="id40">Subfield Relocation Initializer</a></li>
<li><a class="reference internal" href="#compound-initializer" id="id41">Compound Initializer</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#valuesymtab-block" id="id42">Valuesymtab Block</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#entry-record" id="id43">Entry Record</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#module-block" id="id44">Module Block</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#version-record" id="id45">Version Record</a></li>
<li><a class="reference internal" href="#function-address" id="id46">Function Address</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#constants-blocks" id="id47">Constants Blocks</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#set-type-record" id="id48">Set Type Record</a></li>
<li><a class="reference internal" href="#undefined-literal" id="id49">Undefined Literal</a></li>
<li><a class="reference internal" href="#integer-literal" id="id50">Integer Literal</a></li>
<li><a class="reference internal" href="#floating-point-literal" id="id51">Floating Point Literal</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#function-blocks" id="id52">Function Blocks</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#function-enter" id="id53">Function Enter</a></li>
<li><a class="reference internal" href="#link-for-basic-blocks-count" id="id54">Count Record</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#terminator-instructions" id="id55">Terminator Instructions</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#return-void-instruction" id="id56">Return Void Instruction</a></li>
<li><a class="reference internal" href="#return-value-instruction" id="id57">Return Value Instruction</a></li>
<li><a class="reference internal" href="#unconditional-branch-instruction" id="id58">Unconditional Branch Instruction</a></li>
<li><a class="reference internal" href="#conditional-branch-instruction" id="id59">Conditional Branch Instruction</a></li>
<li><a class="reference internal" href="#unreachable" id="id60">Unreachable</a></li>
<li><a class="reference internal" href="#switch-instruction" id="id61">Switch Instruction</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#integer-binary-instructions" id="id62">Integer Binary Instructions</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#integer-add" id="id63">Integer Add</a></li>
<li><a class="reference internal" href="#integer-subtract" id="id64">Integer Subtract</a></li>
<li><a class="reference internal" href="#integer-multiply" id="id65">Integer Multiply</a></li>
<li><a class="reference internal" href="#signed-integer-divide" id="id66">Signed Integer Divide</a></li>
<li><a class="reference internal" href="#unsigned-integer-divide" id="id67">Unsigned Integer Divide</a></li>
<li><a class="reference internal" href="#signed-integer-remainder" id="id68">Signed Integer Remainder</a></li>
<li><a class="reference internal" href="#unsigned-integer-remainder-instruction" id="id69">Unsigned Integer Remainder Instruction</a></li>
<li><a class="reference internal" href="#shift-left" id="id70">Shift Left</a></li>
<li><a class="reference internal" href="#logical-shift-right" id="id71">Logical Shift Right</a></li>
<li><a class="reference internal" href="#arithmetic-shift-right" id="id72">Arithmetic Shift Right</a></li>
<li><a class="reference internal" href="#logical-and" id="id73">Logical And</a></li>
<li><a class="reference internal" href="#logical-or" id="id74">Logical Or</a></li>
<li><a class="reference internal" href="#logical-xor" id="id75">Logical Xor</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#floating-point-binary-instructions" id="id76">Floating Point Binary Instructions</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#floating-point-add" id="id77">Floating Point Add</a></li>
<li><a class="reference internal" href="#floating-point-subtract" id="id78">Floating Point Subtract</a></li>
<li><a class="reference internal" href="#floating-point-multiply" id="id79">Floating Point Multiply</a></li>
<li><a class="reference internal" href="#floating-point-divide" id="id80">Floating Point Divide</a></li>
<li><a class="reference internal" href="#floating-point-remainder" id="id81">Floating Point Remainder</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#memory-creation-and-access-instructions" id="id82">Memory Creation and Access Instructions</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#alloca-instruction" id="id83">Alloca Instruction</a></li>
<li><a class="reference internal" href="#load-instruction" id="id84">Load Instruction</a></li>
<li><a class="reference internal" href="#store-instruction" id="id85">Store Instruction</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#conversion-instructions" id="id86">Conversion Instructions</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#integer-truncating-instruction" id="id87">Integer Truncating Instruction</a></li>
<li><a class="reference internal" href="#floating-point-truncating-instruction" id="id88">Floating Point Truncating Instruction</a></li>
<li><a class="reference internal" href="#zero-extending-instruction" id="id89">Zero Extending Instruction</a></li>
<li><a class="reference internal" href="#sign-extending-instruction" id="id90">Sign Extending Instruction</a></li>
<li><a class="reference internal" href="#floating-point-extending-instruction" id="id91">Floating Point Extending Instruction</a></li>
<li><a class="reference internal" href="#floating-point-to-unsigned-integer-instruction" id="id92">Floating Point to Unsigned Integer Instruction</a></li>
<li><a class="reference internal" href="#floating-point-to-signed-integer-instruction" id="id93">Floating Point to Signed Integer Instruction</a></li>
<li><a class="reference internal" href="#unsigned-integer-to-floating-point-instruction" id="id94">Unsigned Integer to Floating Point Instruction</a></li>
<li><a class="reference internal" href="#signed-integer-to-floating-point-instruction" id="id95">Signed Integer to Floating Point Instruction</a></li>
<li><a class="reference internal" href="#bitcast-instruction" id="id96">Bitcast Instruction</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#comparison-instructions" id="id97">Comparison Instructions</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#integer-comparison-instructions" id="id98">Integer Comparison Instructions</a></li>
<li><a class="reference internal" href="#floating-point-comparison-instructions" id="id99">Floating Point Comparison Instructions</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#vector-instructions" id="id100">Vector Instructions</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#insert-element-instruction" id="id101">Insert Element Instruction</a></li>
<li><a class="reference internal" href="#extract-element-instruction" id="id102">Extract Element Instruction</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#other-instructions" id="id103">Other Instructions</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#forward-type-declaration" id="id104">Forward Type Declaration</a></li>
<li><a class="reference internal" href="#phi-instruction" id="id105">Phi Instruction</a></li>
<li><a class="reference internal" href="#select-instruction" id="id106">Select Instruction</a></li>
<li><p class="first"><a class="reference internal" href="#call-instructions" id="id107">Call Instructions</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#direct-procedure-call" id="id108">Direct Procedure Call</a></li>
<li><a class="reference internal" href="#direct-function-call" id="id109">Direct Function Call</a></li>
<li><a class="reference internal" href="#indirect-procedure-call" id="id110">Indirect Procedure Call</a></li>
<li><a class="reference internal" href="#indirect-function-call" id="id111">Indirect Function Call</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#memory-blocks-and-alignment" id="id112">Memory Blocks and Alignment</a></li>
<li><a class="reference internal" href="#intrinsic-functions" id="id113">Intrinsic Functions</a></li>
<li><p class="first"><a class="reference internal" href="#support-functions" id="id114">Support Functions</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#signrotate" id="id115">SignRotate</a></li>
<li><a class="reference internal" href="#absoluteindex" id="id116">AbsoluteIndex</a></li>
<li><a class="reference internal" href="#relativeindex" id="id117">RelativeIndex</a></li>
<li><a class="reference internal" href="#abbrevindex" id="id118">AbbrevIndex</a></li>
<li><a class="reference internal" href="#log2" id="id119">Log2</a></li>
<li><a class="reference internal" href="#bitsizeof" id="id120">BitSizeOf</a></li>
<li><a class="reference internal" href="#underlyingtype" id="id121">UnderlyingType</a></li>
<li><a class="reference internal" href="#underlyingcount" id="id122">UnderlyingCount</a></li>
<li><a class="reference internal" href="#isinteger" id="id123">IsInteger</a></li>
<li><a class="reference internal" href="#isfloat" id="id124">IsFloat</a></li>
<li><a class="reference internal" href="#isvector" id="id125">IsVector</a></li>
<li><a class="reference internal" href="#isprimitive" id="id126">IsPrimitive</a></li>
<li><a class="reference internal" href="#isfcnargtype" id="id127">IsFcnArgType</a></li>
</ul>
</li>
<li><p class="first"><a class="reference internal" href="#abbreviations" id="id128">Abbreviations</a></p>
<ul class="small-gap">
<li><a class="reference internal" href="#abbreviations-block" id="id129">Abbreviations Block</a></li>
<li><a class="reference internal" href="#todo" id="id130">TODO</a></li>
</ul>
</li>
</ul>
</div><h2 id="introduction">Introduction</h2>
<p>This document is a reference manual for the contents of PNaCl bitcode files. We
define bitcode files via three layers. The first layer is presented using
assembly language <em>PNaClAsm</em>, and defines the textual form of the bitcode
file. The textual form is then lowered to a sequence of <a class="reference internal" href="#link-for-pnacl-records"><em>PNaCl
records</em></a>. The final layer applies abbreviations that
convert each PNaCl record into a corresponding sequence of bits.</p>
<img alt="/native-client/images/PNaClBitcodeFlow.png" src="/native-client/images/PNaClBitcodeFlow.png" />
<p>PNaClAsm uses a <em>static single assignment</em> (SSA) based representation that
requires generated results to have a single (assignment) source.</p>
<p>PNaClAsm focuses on the semantic content of the file, not the bit-encoding of
that content. However, it does provide annotations that allow one to specify how
the <a class="reference internal" href="#link-for-abbreviations-section"><em>abbreviations</em></a> are used to convert
PNaCl records into the sequence of bits.</p>
<p>Each construct in PNaClAsm defines a corresponding <a class="reference internal" href="#link-for-pnacl-records"><em>PNaCl
record</em></a>. A PNaCl bitcode file is simply a sequence of
PNaCl records. The goal of PNaClAsm is to make records easier to read, and not
to define a high-level user programming language.</p>
<p>PNaCl records are an abstract encoding of structured data, similar to XML. Like
XML, A PNaCl record has a notion of a tag (i.e. the first element in a record,
called a <em>code</em>). PNaCl records can be nested. Nesting is defined by a
corresponding <a class="reference internal" href="#link-for-enter-block-record-section"><em>enter</em></a> and
<a class="reference internal" href="#link-for-exit-block-record-section"><em>exit</em></a> block record.</p>
<p>These block records must be used like balanced parentheses to define the block
structure that is imposed on top of records. Each exit record must be preceded
by a corresponding enter record. Blocks can be nested by nesting enter/exit
records appropriately.</p>
<p>The <em>PNaCl bitcode writer</em> takes the sequence of records, defined by a PNaClAsm
program, and converts each record into a (variable-length) sequence of bits. The
output of each bit sequence is appended together. The resulting generated
sequence of bits is the contents of the PNaCl bitcode file.</p>
<p>For every kind of record, there is a method for converting records into bit
sequences. These methods correspond to a notion of
<a class="reference internal" href="#link-for-abbreviations-section"><em>abbreviations</em></a>. Each abbreviation defines
a specific bit sequence conversion to be applied.</p>
<p>Abbreviations can be user-defined, but there are also predefined defaults. All
user-specified abbreviations are included in the generated bitcode
file. Predefined defaults are not.</p>
<p>Each abbreviation defines how a record is converted to a bit sequence. The
<a class="reference internal" href="/native-client/overview.html#link-for-pnacl-translator"><em>PNaCl translator</em></a> uses these abbreviations
to convert the bit sequence back to the corresponding sequence of PNaCl records.
As a result, all records have an abbreviation (user or default) associated with
them.</p>
<p>Conceptually, abbreviations are used to define how to pack the contents of
records into bit sequences. The main reason for defining abbreviations is to
save space. The default abbreviations are simplistic and are intended to handle
all possible records. The default abbreviations do not really worry about being
efficient, in terms of the number of bits generated.</p>
<p>By separating the concepts of PNaCl records and abbreviations, the notion of
data compression is cleanly separated from semantic content. This allows
different use cases to decide how much effort should be spent on compressing
records.</p>
<p>For a JIT compiler that produces bitcode, little (if any) compression should be
applied. In fact, the API to the JIT may just be the records themselves. The
goal of a JIT is to perform the final translation to machine code as quickly as
possible.</p>
<p>On the other hand, when delivering across the web, one may want to compress the
sequence of bits considerably, to reduce costs in delivering web pages. Note
that <a class="reference internal" href="/native-client/devguide/devcycle/building.html#pnacl-compress"><em>pnacl-compress</em></a> is provided as part of the SDK to do
this job.</p>
<h2 id="data-model">Data Model</h2>
<p>The data model for PNaCl bitcode is fixed at little-endian ILP32: pointers are
32 bits in size. 64-bit integer types are also supported natively via the i64
type (for example, a front-end can generate these from the C/C++ type <code>long
long</code>).</p>
<p>Integers are assumed to be modeled using two’s complement. Floating point
support is fixed at <a class="reference internal" href="/native-client/reference/pnacl-c-cpp-language-support.html#c-cpp-floating-point"><em>IEEE 754</em></a> 32-bit and 64-bit
values (float and double, respectively).</p>
<h2 id="pnacl-blocks">PNaCl Blocks</h2>
<p>Blocks are used to organize records in the bitcode file. The kinds of blocks
defined in PNaClAsm are:</p>
<dl class="docutils">
<dt>Module block</dt>
<dd>A top-level block defining the program. The <a class="reference internal" href="#link-for-module-block"><em>module
block</em></a> defines global information used by the program,
followed by function blocks defining the implementation of functions within
the program. All other blocks (listed below) must appear within a module
block.</dd>
<dt>Types block</dt>
<dd>The <a class="reference internal" href="#link-for-types-block-section"><em>types block</em></a> defines the set of types
used by the program. All types used in the program must be defined in the
types block. These types consist of primitive types as well as high level
constructs such as vectors and function signatures.</dd>
<dt>Globals block</dt>
<dd>The <a class="reference internal" href="#link-for-globals-block-section"><em>globals block</em></a> defines the set of
addresses of global variables and constants used by the program. It also
defines how each global (associated with the global address) is initialized.</dd>
<dt>Valuesymtab block</dt>
<dd>The <a class="reference internal" href="#link-for-valuesymtab-block-section"><em>valuesymtab block</em></a> defines
textual names for external function addresses.</dd>
<dt>Function block</dt>
<dd>Each function (implemented) in a program has its own <a class="reference internal" href="#link-for-function-blocks-section"><em>function
block</em></a> that defines the implementation of
the corresponding function.</dd>
<dt>Constants block</dt>
<dd>Each implemented function that uses constants in its instructions defines a
<a class="reference internal" href="#link-for-constants-block-section"><em>constants block</em></a>. Constants blocks
appear within the corresponding function block of the implemented function.</dd>
<dt>Abbreviations block</dt>
<dd>Defines global abbreviations that are used to compress PNaCl records. The
<a class="reference internal" href="#link-for-abbreviations-block-section"><em>abbreviations block</em></a> is segmented
into multiple sections, one section for each kind of block. This block appears
at the beginning of the module block.</dd>
</dl>
<p>This section is only intended as a high-level discussion of blocks. Later
sections will dive more deeply into the constraints on how blocks must be laid
out. This section only presents the overall concepts of what kinds of data are
stored in each of the blocks.</p>
<p>A PNaCl program consists of a <a class="reference internal" href="#link-for-header-record-section"><em>header
record</em></a> and a <a class="reference internal" href="#link-for-module-block"><em>module
block</em></a>. The header record defines a sequence of bytes
uniquely identifying the file as a bitcode file. The module block defines the
program to run.</p>
<p>Each block, within a bitcode file, defines values. These values are associated
with IDs. Each type of block defines different kinds of IDs. The
<a class="reference internal" href="#link-for-module-block"><em>module</em></a>,
<a class="reference internal" href="#link-for-types-block-section"><em>types</em></a>,
<a class="reference internal" href="#link-for-globals-block-section"><em>globals</em></a>, and
<a class="reference internal" href="#link-for-abbreviations-block-section"><em>abbreviations</em></a> blocks define global
identifiers, and only a single instance can appear. The
<a class="reference internal" href="#link-for-function-blocks-section"><em>function</em></a> and
<a class="reference internal" href="#link-for-constants-block-section"><em>constant</em></a> blocks define local
identifiers, and can have multiple instances (one for each implemented
function).</p>
<p>The only records in the module block that define values, are <a class="reference internal" href="#link-for-function-address-section"><em>function
address</em></a> records. Each function address
record defines a different function address, and the <a class="reference internal" href="#link-for-function-type"><em>type
signature</em></a> associated with that function address.</p>
<p>Each <a class="reference internal" href="#link-for-function-blocks-section"><em>function block</em></a> defines the
implementation of a single function. Each function block defines the
intermediate representation of the function, consisting of basic blocks and
instructions. If constants are used within instructions, they are defined in a
<a class="reference internal" href="#link-for-constants-block-section"><em>constants block</em></a>, nested within the
corresponding function block.</p>
<p>All function blocks are associated with a corresponding function address. This
association is positional rather than explicit. That is, the Nth function block
in a module block corresponds to the Nth
<a class="reference internal" href="#link-for-function-address-section"><em>defining</em></a> (rather than declared)
function address record in the module block.</p>
<p>Hence, within a function block, there is no explicit reference to the function
address the block defines. For readability, PNaClAsm uses the corresponding
function signature, associated with the corresponding function address record,
even though that data does not appear in the corresponding records.</p>
<h2 id="pnacl-records"><span id="link-for-pnacl-records"></span>PNaCl Records</h2>
<p>A PNaCl record is a non-empty sequence of unsigned, 64-bit, integers. A record
is identified by the record <em>code</em>, which is the first element in the
sequence. Record codes are unique within a specific kind of block, but are not
necessarily unique across different kinds of blocks. The record code acts as the
variant discriminator (i.e. tag) within a block, to identify what kind of record
it is.</p>
<p>Record codes that are local to a specific kind of block are small values
(starting from zero). In an ideal world, they would be a consecutive sequence of
integers, starting at zero. However, the reality is that PNaCl records evolved
over time (and actually started as <a class="reference external" href="http://llvm.org/docs/BitCodeFormat.html">LLVM records</a>). For backward compatibility,
obsolete numbers have not been reused, leaving gaps in the actual record code
values used.</p>
<p>Global record codes are record codes that have the same meaning in multiple
kinds of blocks. To separate global record codes from local record codes, large
values are used. Currently there are four <a class="reference internal" href="#link-for-global-record-codes"><em>global record
codes</em></a>. To make these cases clear, and to leave
ample room for future growth in PNaClAsm, these special records have record
codes close to the value 2<sup>16</sup>. Note: Well-formed PNaCl bitcode files
do not have record codes >= 2<sup>16</sup>.</p>
<p>A PNaCl record is denoted as follows:</p>
<pre class="prettyprint">
a: <v0, v1, ... , vN>
</pre>
<p>The value <code>v0</code> is the record code. The remaining values, <code>v1</code> through
<code>vN</code>, are parameters that fill in additional information needed by the
construct it represents. All records must have a record code. Hence, empty PNaCl
records are not allowed. <code>a</code> is the index to the abbreviation used to convert
the record to a bit sequence.</p>
<p>While most records (for a given record code) have the same length, it is not
true of all record codes. Some record codes can have arbitrary length. In
particular, function type signatures, call instructions, phi instructions,
switch instructions, and global variable initialization records all have
variable length. The expected length is predefined and part of the PNaClAsm
language. See the corresponding construct (associated with the record) to
determine the expected length.</p>
<p>The <em>PNaCl bitstream writer</em>, which converts records to bit sequences, does
this by writing out the abbreviation index used to encode the record, followed
by the contents of the record. The details of this are left to the section on
<a class="reference internal" href="#link-for-abbreviations-section"><em>abbreviations</em></a>. However, at the record
level, one important aspect of this appears in <a class="reference internal" href="#link-for-enter-block-record-section"><em>block
enter</em></a> records. These records must define
how many bits are required to hold abbreviation indices associated with records
of that block.</p>
<h2 id="default-abbreviations"><span id="link-for-default-abbreviations"></span>Default Abbreviations</h2>
<p>There are 4 predefined (default) abbreviation indices, used as the default
abbreviations for PNaCl records. They are:</p>
<dl class="docutils">
<dt>0</dt>
<dd>Abbreviation index for the abbreviation used to bit-encode an exit block
record.</dd>
<dt>1</dt>
<dd>Abbreviation index for the abbreviation used to bit-encode an enter block
record.</dd>
<dt>2</dt>
<dd>Abbreviation index for the abbreviation used to bit-encode a user-defined
abbreviation. Note: User-defined abbreviations are also encoded as records,
and hence need an abbreviation index to bit-encode them.</dd>
<dt>3</dt>
<dd>Abbreviation index for the default abbreviation to bit-encode all other
records in the bitcode file.</dd>
</dl>
<p>A block may, in addition, define a list of block specific, user-defined,
abbreviations (of length <code>U</code>). The number of bits <code>B</code> specified for an enter
record must be sufficiently large such that:</p>
<pre class="prettyprint">
2**B >= U + 4
</pre>
<p>In addition, the upper limit for <code>B</code> is <code>16</code>.</p>
<p>PNaClAsm requires specifying the number of bits needed to read abbreviations as
part of the enter block record. This allows the PNaCl bitcode reader/writer to
use the specified number of bits to encode abbreviation indices.</p>
<h2 id="pnacl-identifiers">PNaCl Identifiers</h2>
<p>A program is defined by a <a class="reference internal" href="#link-for-module-block"><em>module block</em></a>. Blocks can
be nested within other blocks, including the module block. Each block defines a
sequence of records.</p>
<p>Most of the records, within a block, also define unique values. Each unique
value is given a corresponding unique identifier (i.e. <em>ID</em>). In PNaClAsm, each
kind of block defines its own kind of identifiers. The names of these
identifiers are defined by concatenating a prefix character (<code>'@'</code> or
<code>'%'</code>), the kind of block (a single character), and a suffix index. The suffix
index is defined by the positional location of the defined value within the
records of the corresponding block. The indices are all zero based, meaning that
the first defined value (within a block) is defined using index 0.</p>
<p>Identifiers are categorized into two types, <em>local</em> and <em>global</em>. Local
identifiers are identifiers that are associated with the implementation of a
single function. In that sense, they are local to the block they appear in.</p>
<p>All other identifiers are global, and can appear in multiple blocks. This split
is intentional. Global identifiers are used by multiple functions, and therefore
must be known in all function implementations. Local identifiers only apply to a
single function, and can be reused between functions. The <a class="reference internal" href="/native-client/overview.html#link-for-pnacl-translator"><em>PNaCl
translator</em></a> uses this separation to parallelize the
compilation of functions.</p>
<p>Note that local abbreviation identifiers are unique to the block they appear
in. Global abbreviation identifiers are only unique to the block type they are
defined for. Different block types can reuse global abbreviation identifiers.</p>
<p>Global identifiers use the prefix character <code>'@'</code> while local identifiers use
the prefix character <code>'%'</code>.</p>
<p>Note that by using positional location to define identifiers (within a block),
the values defined in PNaCl bitcode files need not be explicitly included in the
bitcode file. Rather, they are inferred by the (ordered) position of the record
in the block. This is also intentional. It is used to reduce the amount of data
that must be (explicitly) passed to the <a class="reference internal" href="/native-client/overview.html#link-for-pnacl-translator"><em>PNaCl
translator</em></a>, when downloaded into Chrome.</p>
<p>In general, most of the records within blocks are assumed to be topologically
sorted, putting value definitions before their uses. This implies that records
do not need to encode data if they can deduce the corresponding information from
their uses.</p>
<p>The most common use of this is that many instructions use the type of their
operands to determine the type of the instruction. Again, this is
intentional. It allows less information to be stored.</p>
<p>However, for function blocks (which define instructions), a topological sort may
not exist. Loop carried value dependencies simply do not allow topologically
sorting. To deal with this, function blocks have a notion of (instruction value)
<a class="reference internal" href="#link-for-forward-type-declaration-section"><em>forward type
declarations</em></a>. These declarations
must appear before any of the uses of that value, if the (instruction) value is
defined later in the function than its first use.</p>
<p>The kinds of identifiers used in PNaClAsm are:</p>
<dl class="docutils">
<dt>@a</dt>
<dd>Global abbreviation identifier.</dd>
<dt>%a</dt>
<dd>Local abbreviation identifier.</dd>
<dt>%b</dt>
<dd>Function basic block identifier.</dd>
<dt>%c</dt>
<dd>Function constant identifier.</dd>
<dt>@f</dt>
<dd>Global function address identifier.</dd>
<dt>@g</dt>
<dd>Global variable/constant address identifier.</dd>
<dt>%p</dt>
<dd>Function parameter identifier.</dd>
<dt>@t</dt>
<dd>Global type identifier.</dd>
<dt>%v</dt>
<dd>Value generated by an instruction in a function block.</dd>
</dl>
<h2 id="conventions-for-describing-records">Conventions For Describing Records</h2>
<p>PNaClAsm is the textual representation of <a class="reference internal" href="#link-for-pnacl-records"><em>PNaCl
records</em></a>. Each PNaCl record is described by a
corresponding PNaClAsm construct. These constructs are described using syntax
rules, and semantics on how they are converted to records. Along with the rules,
is a notion of <a class="reference internal" href="#link-for-global-state-section"><em>global state</em></a>. The global
state is updated by syntax rules. The purpose of the global state is to track
positional dependencies between records.</p>
<p>For each PNaCl construct, we define multiple sections. The <strong>Syntax</strong>
section defines a syntax rule for the construct. The <strong>Record</strong> section
defines the corresponding record associated with the syntax rule. The
<strong>Semantics</strong> section describes the semantics associated with the record, in
terms of data within the global state and the corresponding syntax. It also
includes other high-level semantics, when appropriate.</p>
<p>The <strong>Constraints</strong> section (if present) defines any constraints associated
with the construct, including the global state. The <strong>Updates</strong> section (if
present) defines how the global state is updated when the construct is
processed. The <strong>Examples</strong> section gives one or more examples of using the
corresponding PNaClAsm construct.</p>
<p>Some semantics sections use functions to compute values. The meaning of
functions can be found in <a class="reference internal" href="#link-for-support-functions-section"><em>support
functions</em></a>.</p>
<p>The syntax rule may include the
<a class="reference internal" href="#link-for-abbreviations-section"><em>abbreviation</em></a> to use, when converting to a
bit-sequence. These abbreviations, if allowed, are at the end of the construct,
and enclosed in <code><</code> and <code>></code> brackets. These abbreviations are optional in
the syntax, and can be omitted. If they are used, the abbreviation brackets are
part of the actual syntax of the construct. If the abbreviation is omitted, the
default abbreviation index is used. To make it clear that abbreviations are
optional, syntax rules separate abbreviations using plenty of whitespace.</p>
<p>Within a syntax rule, lower case characters are literal values. Sequences of
upper case alphanumeric characters are named values. If we mix lower and upper
case letters within a name appearing in a syntax rule, the lower case letters
are literal while the upper case sequence of alphanumeric characters denote rule
specific values. The valid values for each of these names will be defined in
the corresponding semantics and constraints subsections.</p>
<p>For example, consider the following syntax rule:</p>
<pre class="prettyprint">
%vN = add T O1, O2; <A>
</pre>
<p>This rule defines a PNaClAsm add instruction. This construct defines an
instruction that adds two values (<code>O1</code> and <code>O2</code>) to generate instruction
value <code>%vN</code>. The types of the arguments, and the result, are all of type
<code>T</code>. If abbreviation ID <code>A</code> is present, the record is encoded using that
abbreviation. Otherwise the corresponding <a class="reference internal" href="#link-for-default-abbreviations"><em>default abbreviation
index</em></a> is used.</p>
<p>To be concrete, the syntactic rule above defines the structure of the following
PNaClAsm examples:</p>
<pre class="prettyprint">
%v10 = add i32 %v1, %v2; <@a5>
%v11 = add i32 %v10, %v3;
</pre>
<p>In addition to specifying the syntax, each syntax rule can also also specify the
contents of the corresponding record in the corresponding record subsection. In
simple cases, the elements of the corresponding record are predefined (literal)
constants. Otherwise the record element is an identifier from another subsection
associated with the construct.</p>
<h2 id="factorial-example">Factorial Example</h2>
<p>This section provides a simple example of a PNaCl bitcode file. Its contents
describe a bitcode file that only defines a function to compute the factorial
value of a number.</p>
<p>In C, the factorial function can be defined as:</p>
<pre class="prettyprint">
int fact(int n) {
if (n == 1) return 1;
return n * fact(n-1);
}
</pre>
<p>Compiling this into a PNaCl bitcode file, and dumping out its contents with
utility <a class="reference internal" href="/native-client/devguide/devcycle/building.html#pnacl-bcdis"><em>pnacl-bcdis</em></a>, the corresponding output is:</p>
<pre class="prettyprint">
0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, 88, 69)
| 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2
| 0> |
16:0|1: <65535, 8, 2> |module { // BlockID = 8
24:0| 3: <1, 1> | version 1;
26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0
36:0| 0: <65534> | }
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <2> | @t1 = void;
55:4| 3: <21, 0, 0, 0> | @t2 = i32 (i32);
59:4| 3: <7, 1> | @t3 = i1;
62:0| 0: <65534> | }
64:0| 3: <8, 2, 0, 0, 0> | define external i32 @f0(i32);
68:6| 1: <65535, 19, 2> | globals { // BlockID = 19
76:0| 3: <5, 0> | count 0;
78:4| 0: <65534> | }
80:0| 1: <65535, 14, 2> | valuesymtab { // BlockID = 14
88:0| 3: <1, 0, 102, 97, 99, | @f0 : "fact";
| 116> |
96:4| 0: <65534> | }
100:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0) {
| | // BlockID = 12
108:0| 3: <1, 3> | blocks 3;
110:4| 1: <65535, 11, 2> | constants { // BlockID = 11
120:0| 3: <1, 0> | i32:
122:4| 3: <4, 2> | %c0 = i32 1;
125:0| 0: <65534> | }
| | %b0:
128:0| 3: <28, 2, 1, 32> | %v0 = icmp eq i32 %p0, %c0;
132:6| 3: <11, 1, 2, 1> | br i1 %v0, label %b1, label %b2;
| | %b1:
136:6| 3: <10, 2> | ret i32 %c0;
| | %b2:
139:2| 3: <2, 3, 2, 1> | %v1 = sub i32 %p0, %c0;
143:2| 3: <34, 0, 5, 1> | %v2 = call i32 @f0(i32 %v1);
148:0| 3: <2, 5, 1, 2> | %v3 = mul i32 %p0, %v2;
152:0| 3: <10, 1> | ret i32 %v3;
154:4| 0: <65534> | }
156:0|0: <65534> |}
</pre>
<p>Note that there are three columns in this output. The first column contains the
bit positions of the records within the bitcode file. The second column contains
the sequence of records within the bitcode file. The third column contains the
corresponding PNaClAsm program.</p>
<p>Bit positions are defined by a pair <code>B:N</code>. <code>B</code> is the number of bytes, while
<code>N</code> is the bit offset within the <code>B</code>-th byte. Hence, the bit position (in
bits) is:</p>
<pre class="prettyprint">
B*8 + N
</pre>
<p>Hence, the first record is at bit offset <code>0</code> (<code>0*8+0</code>). The second record is
at bit offset <code>128</code> (<code>16*8+0</code>). The third record is at bit offset <code>192</code>
(<code>24*8+0</code>). The fourth record is at bit offset <code>212</code> (<code>26*8+4</code>).</p>
<p>The <a class="reference internal" href="#link-for-header-record-section"><em>header record</em></a> is a sequence of 16
bytes, defining the contents of the first 16 bytes of the bitcode file. These
bytes never change, and are expected for all version 2, PNaCl bitcode files. The
first four bytes define the magic number of the file, i.e. ‘PEXE’. All PEXE
bitcode files begin with these four bytes.</p>
<p>All but the header record has an abbreviation index associated with it. Since no
user-defined abbreviations are provided, all records were converted to
bit sequences using default abbreviations.</p>
<p>The types block (starting at bit address <code>40:0</code>), defines 4 types: <code>i1</code>,
<code>i32</code>, <code>void</code>, and function signature <code>i32 (i32)</code>.</p>
<p>Bit address <code>64:0</code> declares the factorial function address <code>@f0</code>, and its
corresponding type signature. Bit address <code>88:0</code> associates the name <code>fact</code>
with function address <code>@f0</code>.</p>
<p>Bit address <code>100:0</code> defines the function block that implements function
<code>fact</code>. The entry point is <code>%b0</code> (at bit address <code>128:0</code>). It uses the
32-bit integer constant <code>1</code> (defined at bit addresses <code>122:4</code>). Bit address
<code>128:0</code> defines an equality comparison of the argument <code>%p0</code> with <code>1</code>
(constant <code>%c0</code>). Bit address <code>132:6</code> defines a conditional branch. If the
result of the previous comparison (<code>%v0</code>) is true, the program will branch to
block <code>%b1</code>. Otherwise it will branch to block <code>%b2</code>.</p>
<p>Bit address <code>136:6</code> returns constant <code>1</code> (<code>%c0</code>) when the input parameter
is 1. Instructions between bit address <code>139:2</code> and <code>154:4</code> compute and
return <code>n * fact(n-1)</code>.</p>
<h2 id="road-map">Road Map</h2>
<p>At this point, this document transitions from basic concepts to the details
of how records should be formatted. This section defines the road map to
the remaining sections in this document.</p>
<p>Many records have implicit information associated with them, and must be
maintained across records. <a class="reference internal" href="#link-for-global-state-section"><em>Global state</em></a>
describes how this implicit information is modeled. In addition, there are
various <a class="reference internal" href="#link-for-support-functions-section"><em>support functions</em></a> that are
used to define the semantics of records, and how they update the global state.</p>
<p>There are just a handful of global records (records that either don’t appear in
any block, or can appear in all blocks). <a class="reference internal" href="#link-for-global-record-codes"><em>Global
records</em></a> describes these records. This includes
the block delimiter records <a class="reference internal" href="#link-for-enter-block-record-section"><em>enter</em></a>
and <a class="reference internal" href="#link-for-exit-block-record-section"><em>exit</em></a> that define block
boundaries.</p>
<p>PNaClAsm is a strongly typed language, and most block values are typed.
<a class="reference internal" href="#link-for-types-block-section"><em>types</em></a> describes the set of legal types, and
how to define types.</p>
<p>Global variables and their initializers are presented in the <a class="reference internal" href="#link-for-globals-block-section"><em>globals
block</em></a>. <a class="reference internal" href="#link-for-function-address-section"><em>Function
addresses</em></a> are part of the <a class="reference internal" href="#link-for-module-block"><em>module
block</em></a>, but must be defined before any global variables.</p>
<p>Names to be associated with global variables and function addresses, are defined
in the <a class="reference internal" href="#link-for-valuesymtab-block-section"><em>valuesymtab block</em></a>, and must
appear after the <a class="reference internal" href="#link-for-globals-block-section"><em>globals block</em></a>, but
before any <a class="reference internal" href="#link-for-function-blocks-section"><em>function definition</em></a>.</p>
<p>The <a class="reference internal" href="#link-for-module-block"><em>module block</em></a> is the top-most block, and all
other blocks must appear within the module block. The module block defines the
executable in the bitcode file.</p>
<p>Constants used within a <a class="reference internal" href="#link-for-function-blocks-section"><em>function
definition</em></a> must be defined using a
<a class="reference internal" href="#link-for-constants-block-section"><em>constants block</em></a>. Each function
definition is defined by a <a class="reference internal" href="#link-for-function-blocks-section"><em>function
block</em></a> and constant blocks can only appear
within function blocks. Constants defined within a constant block can only be
used in the enclosing function block.</p>
<p>Function definitions are defined by a sequence of instructions. There are
several types of instructions.</p>
<p>A <a class="reference internal" href="#link-for-terminator-instruction-section"><em>terminator instruction</em></a> is the
last instruction in a <a class="reference internal" href="#link-for-function-blocks-section"><em>basic block</em></a>, and
is a branch, return, or unreachable instruction.</p>
<p>There are <a class="reference internal" href="#link-for-integer-binary-instructions"><em>integer</em></a> and
<a class="reference internal" href="#link-for-floating-point-binary-instructions"><em>floating point</em></a> binary
operations. Integer binary instructions include both arithmetic and logical
operations. Floating point instructions define arithmetic operations.</p>
<p>There are also <a class="reference internal" href="#link-for-memory-creation-and-access-instructions"><em>memory
access</em></a> instructions that
allow one to load and store values. That section also includes how to define
local variables using the <a class="reference internal" href="#link-for-alloca-instruction"><em>alloca
instruction</em></a>.</p>
<p>One can also convert integer and floating point values using <a class="reference internal" href="#link-for-conversion-instructions"><em>conversion
instructions</em></a>.</p>
<p><a class="reference internal" href="#link-for-compare-instructions"><em>Comparison instructions</em></a>
allow you to compare values.</p>
<p><a class="reference internal" href="#link-for-vector-instructions"><em>Vector instructions</em></a> allow you to build and
update vectors. Corresponding <a class="reference internal" href="#link-for-intrinsic-functions-section"><em>intrinsic
functions</em></a>, as well as
<a class="reference internal" href="#link-for-integer-binary-instructions"><em>integer</em></a> and <a class="reference internal" href="#link-for-floating-point-binary-instructions"><em>floating
point</em></a> binary instructions allow
you to apply operations to vectors.</p>
<p>In addition, <a class="reference internal" href="#link-for-other-pnaclasm-instructions"><em>other instructions</em></a> are
available. This includes function and procedure calls.</p>
<p>There are also <a class="reference internal" href="#link-for-memory-blocks-and-alignment-section"><em>memory
alignment</em></a> issues that should be
considered for global and local variables, as well as load and store
instructions.</p>
<p>Finally, how to pack records is described in the
<a class="reference internal" href="#link-for-abbreviations-section"><em>abbreviations</em></a> section.</p>
<h2 id="global-state"><span id="link-for-global-state-section"></span>Global State</h2>
<p>This section describes the global state associated with PNaClAsm. It is used to
define contextual data that is carried between records.</p>
<p>In particular, PNaClAsm is a strongly typed language, and hence, we must track
the type associated with values. Subsection <a class="reference internal" href="#link-to-typing-functions"><em>Typing Functions</em></a>
describes the functions used to maintain typing information associated with
values.</p>
<p>Values are implicitly ordered within a block, and the indices associated with
the values do not appear in records. Rather, ID counters are used to figure out
what corresponding ID name is associated with a value generating record.
Subsection <a class="reference internal" href="#link-to-id-counters"><em>ID Counters</em></a> defines counters maintained in the global
state.</p>
<p>In several blocks, one of the first records in the block defines how many values
are defined in in the block. The main purpose of these counts is to communicate
to the <a class="reference internal" href="/native-client/overview.html#link-for-pnacl-translator"><em>PNaCl translator</em></a> space requirements, or
a limit so that it can detect bad references to values. Subsection
<a class="reference internal" href="#link-for-size-variables"><em>Size Variables</em></a> defines variables that hold size definitions in
the corresponding records.</p>
<p>Finally, the function and constants block contain implicit context between
records in those blocks. Subsection <a class="reference internal" href="#link-to-other-variables"><em>Other Variables</em></a> defines the
variables that contain this implicit context.</p>
<h3 id="typing-functions"><span id="link-to-typing-functions"></span>Typing Functions</h3>
<p>Associated with most identifiers is a type. This type defines what type the
corresponding value has. It is defined by the (initially empty) map:</p>
<pre class="prettyprint">
TypeOf: ID -> Type
</pre>
<p>For each type in the <a class="reference internal" href="#link-for-types-block-section"><em>types block</em></a>, a
corresponding inverse map:</p>
<pre class="prettyprint">
TypeID: Type -> ID
</pre>
<p>is maintained to convert syntactic types to the corresponding type ID.</p>
<p>Note: This document assumes that map <code>TypeID</code> is automatically maintained
during updates to map <code>TypeOf</code> (when given a type <code>ID</code>). Hence, <em>Updates</em>
subsections will not contain assignments to this map.</p>
<p>Associated with each function identifier is its <a class="reference internal" href="#link-for-function-type"><em>type
signature</em></a>. This is different than the type of the
function identifier, since function identifiers represent the function address
which is a pointer (and pointers are always implemented as a 32-bit integer
following the ILP32 data model).</p>
<p>Function type signatures are maintained using:</p>
<pre class="prettyprint">
TypeOfFcn: ID -> Type
</pre>
<p>In addition, if a function address has an implementing block, there is a
corresponding implementation associated with the function address. To indicate
which function addresses have implementations, we use the set:</p>
<pre class="prettyprint">
DefiningFcnIDs: set(ID)
</pre>
<h3 id="link-to-id-counters"><span id="id-counters"></span>ID Counters</h3>
<p>Each block defines one or more kinds of values. Value indices are generated
sequentially, starting at zero. To capture this, the following counters are
defined:</p>
<dl class="docutils">
<dt>NumTypes</dt>
<dd>The number of types defined so far (in the <a class="reference internal" href="#link-for-types-block-section"><em>types
block</em></a>).</dd>
<dt>NumFuncAddresses</dt>
<dd>The number of function addresses defined so far (in the <a class="reference internal" href="#link-for-module-block"><em>module
block</em></a>).</dd>
<dt>NumGlobalAddresses</dt>
<dd>The number of global variable/constant addresses defined so far (in the
<a class="reference internal" href="#link-for-globals-block-section"><em>globals block</em></a>).</dd>
<dt>NumParams</dt>
<dd>The number of parameters defined for a function. Note: Unlike other counters,
this value is set once, at the beginning of the corresponding <a class="reference internal" href="#link-for-function-blocks-section"><em>function
block</em></a>, based on the type signature
associated with the function.</dd>
<dt>NumFcnConsts</dt>
<dd>The number of constants defined in a function so far (in the corresponding
nested <a class="reference internal" href="#link-for-constants-block-section"><em>constants block</em></a>).</dd>
<dt>NumBasicBlocks</dt>
<dd>The number of basic blocks defined so far (within a <a class="reference internal" href="#link-for-function-blocks-section"><em>function
block</em></a>).</dd>
<dt>NumValuedInsts</dt>
<dd>The number of instructions, generating values, defined so far (within a
<a class="reference internal" href="#link-for-function-blocks-section"><em>function block</em></a>).</dd>
</dl>
<h3 id="size-variables"><span id="link-for-size-variables"></span>Size Variables</h3>
<p>A number of blocks define expected sizes of constructs. These sizes are recorded
in the following size variables:</p>
<dl class="docutils">
<dt>ExpectedBasicBlocks</dt>
<dd>The expected <a class="reference internal" href="#link-for-basic-blocks-count"><em>number of basic blocks</em></a> within
a function implementation.</dd>
<dt>ExpectedTypes</dt>
<dd>The expected <a class="reference internal" href="#link-for-types-count-record"><em>number of types</em></a> defined in
the types block.</dd>
<dt>ExpectedGlobals</dt>
<dd>The expected <a class="reference internal" href="#link-for-globals-count-record"><em>number of global variable/constant
addresses</em></a> in the globals block.</dd>
<dt>ExpectedInitializers</dt>
<dd>The expected <a class="reference internal" href="#link-for-compound-initializer"><em>number of initializers</em></a> for
a global variable/constant address in the globals block.</dd>
</dl>
<p>It is assumed that the corresponding <a class="reference internal" href="#link-to-id-counters"><em>ID counters</em></a> are
always smaller than the corresponding size variables (except
ExpectedInitializers). That is:</p>
<pre class="prettyprint">
NumBasicBlocks < ExpectedBasicBlocks
NumTypes < ExpectedTypes
NumGlobalAddresses < ExpectedGlobals
</pre>
<h3 id="other-variables"><span id="link-to-other-variables"></span>Other Variables</h3>
<dl class="docutils">
<dt>EnclosingFcnID</dt>
<dd>The function ID of the function block being processed.</dd>
<dt>ConstantsSetType</dt>
<dd>Holds the type associated with the last <a class="reference internal" href="#link-for-constants-set-type-record"><em>set type
record</em></a> in the constants block. Note: at
the beginning of each constants block, this variable is set to type void.</dd>
</dl>
<h2 id="global-records"><span id="link-for-global-record-codes"></span>Global Records</h2>
<p>Global records are records that can appear in any block. These records have
the same meaning in multiple kinds of blocks.</p>
<p>There are four global PNaCl records, each having its own record code. These
global records are:</p>
<dl class="docutils">
<dt>Header</dt>
<dd>The <a class="reference internal" href="#link-for-header-record-section"><em>header record</em></a> is the first record
of a PNaCl bitcode file, and identifies the file’s magic number, as well as
the bitcode version it uses. The record defines the sequence of bytes that
make up the header and uniquely identifies the file as a PNaCl bitcode file.</dd>
<dt>Enter</dt>
<dd>An <a class="reference internal" href="#link-for-enter-block-record-section"><em>enter record</em></a> defines the
beginning of a block. Since blocks can be nested, one can appear inside other
blocks, as well as at the top level.</dd>
<dt>Exit</dt>
<dd>An <a class="reference internal" href="#link-for-exit-block-record-section"><em>exit record</em></a> defines the end of a
block. Hence, it must appear in every block, to end the block.</dd>
<dt>Abbreviation</dt>
<dd>An <a class="reference internal" href="#link-for-abbreviation-record"><em>abbreviation record</em></a> defines a
user-defined abbreviation to be applied to records within blocks.
Abbreviation records appearing in the abbreviations block define global
abbreviations. All other abbreviations are local to the block they appear in,
and can only be used in that block.</dd>
</dl>
<p>All global records can’t have user-defined abbreviations associated with
them. The <a class="reference internal" href="#link-for-default-abbreviations"><em>default abbreviation</em></a> is always
used.</p>
<h3 id="header-record"><span id="link-for-header-record-section"></span>Header Record</h3>
<p>The header record must be the first record in the file. It is the only record in
the bitcode file that doesn’t have a corresponding construct in PNaClAsm. In
addition, no abbreviation index is associated with it.</p>
<p><strong>Syntax</strong>:</p>
<p>There is no syntax for header records in PNaClAsm.</p>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
<65532, 80, 69, 88, 69, 1, 0, 8, 0, 17, 0, 4, 0, 2, 0, 0, 0>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The header record defines the initial sequence of bytes that must appear at the
beginning of all (PNaCl bitcode version 2) files. That sequence is the list of
bytes inside the record (excluding the record code). As such, it uniquely
identifies all PNaCl bitcode files.</p>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, 88, 69)
| 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2
| 0> |
</pre>
<h3 id="enter-block-record"><span id="link-for-enter-block-record-section"></span>Enter Block Record</h3>
<p>Block records can be top-level, as well as nested in other blocks. Blocks must
begin with an <em>enter</em> record, and end with an
<a class="reference internal" href="#link-for-exit-block-record-section"><em>exit</em></a> record.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
N { <B>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
1: <65535, ID, B>
</pre>
<p><strong>Semantics</strong>:</p>
<p>Enter block records define the beginning of a block. <code>B</code>, if present, is the
number of bits needed to represent all possible abbreviation indices used within
the block. If omitted, <code>B=2</code> is assumed.</p>
<p>The block <code>ID</code> value is dependent on the name <code>N</code>. Valid names and
corresponding <code>BlockID</code> values are defined as follows:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">N</th>
<th class="head">Block ID</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>abbreviations</td>
<td>0</td>
</tr>
<tr class="row-odd"><td>constants</td>
<td>11</td>
</tr>
<tr class="row-even"><td>function</td>
<td>12</td>
</tr>
<tr class="row-odd"><td>globals</td>
<td>19</td>
</tr>
<tr class="row-even"><td>module</td>
<td>8</td>
</tr>
<tr class="row-odd"><td>types</td>
<td>17</td>
</tr>
<tr class="row-even"><td>valuesymtab</td>
<td>14</td>
</tr>
</tbody>
</table>
<p>Note: For readability, PNaClAsm defines a more readable form of a function block
enter record. See <a class="reference internal" href="#link-for-function-blocks-section"><em>function blocks</em></a> for
more details.</p>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
16:0|1: <65535, 8, 2> |module { // BlockID = 8
24:0| 3: <1, 1> | version 1;
26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0
36:0| 0: <65534> | }
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 2> | count 2;
50:4| 3: <2> | @t0 = void;
52:2| 3: <21, 0, 0> | @t1 = void ();
55:4| 0: <65534> | }
56:0| 3: <8, 1, 0, 1, 0> | declare external void @f0();
60:6| 1: <65535, 19, 2> | globals { // BlockID = 19
68:0| 3: <5, 0> | count 0;
70:4| 0: <65534> | }
72:0|0: <65534> |}
</pre>
<h3 id="exit-block-record"><span id="link-for-exit-block-record-section"></span>Exit Block Record</h3>
<p>Block records can be top-level, as well as nested, records. Blocks must begin
with an <a class="reference internal" href="#link-for-enter-block-record-section"><em>enter</em></a> record, and end with
an <em>exit</em> record.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
}
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
0: <65534>
</pre>
<p><strong>Semantics</strong>:</p>
<p>All exit records are identical, no matter what block they are ending. An exit
record defines the end of the block.</p>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
16:0|1: <65535, 8, 2> |module { // BlockID = 8
24:0| 3: <1, 1> | version 1;
26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0
36:0| 0: <65534> | }
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 2> | count 2;
50:4| 3: <2> | @t0 = void;
52:2| 3: <21, 0, 0> | @t1 = void ();
55:4| 0: <65534> | }
56:0| 3: <8, 1, 0, 1, 0> | declare external void @f0();
60:6| 1: <65535, 19, 2> | globals { // BlockID = 19
68:0| 3: <5, 0> | count 0;
70:4| 0: <65534> | }
72:0|0: <65534> |}
</pre>
<h3 id="abbreviation-record"><span id="link-for-abbreviation-record"></span>Abbreviation Record</h3>
<p>Abbreviation records define abbreviations. See
<a class="reference internal" href="#link-for-abbreviations-section"><em>abbreviations</em></a> for details on how
abbreviations should be written. This section only presents the mechanical
details for converting an abbreviation into a PNaCl record.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
A = abbrev <E1, ... , EM>;
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
2: <65533, M, EE1, ... , EEM>
</pre>
<p><strong>Semantics</strong>:</p>
<p>Defines an abbreviation <code>A</code> as the sequence of encodings <code>E1</code> through
<code>EM</code>. If the abbreviation appears within the <a class="reference internal" href="#link-for-abbreviations-block-section"><em>abbreviations
block</em></a>, <code>A</code> must be a global
abbreviation. Otherwise, <code>A</code> must be a local abbreviation.</p>
<p>Abbreviations within a block (or a section within the abbreviations block), must
be enumerated in order, starting at index <code>0</code>.</p>
<p>Valid encodings <code>Ei</code>, and the corresponding sequence of (unsigned) integers
<code>EEi</code>, ( for <code>1 <= i <= M</code>) are defined by the following table:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Ei</th>
<th class="head">EEi</th>
<th class="head">Form</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>C</td>
<td>1, C</td>
<td>Literal C in corresponding position in record.</td>
</tr>
<tr class="row-odd"><td>fixed(N)</td>
<td>0, 1, N</td>
<td>Encode value as a fixed sequence of N bits.</td>
</tr>
<tr class="row-even"><td>vbr(N)</td>
<td>0, 2, N</td>
<td>Encode value using a variable bit rate of N.</td>
</tr>
<tr class="row-odd"><td>char6</td>
<td>0, 4</td>
<td>Encode value as 6-bit char containing
characters [a-zA-Z0-9._].</td>
</tr>
<tr class="row-even"><td>array</td>
<td>0, 3</td>
<td>Allow zero or more of the succeeding abbreviation.</td>
</tr>
</tbody>
</table>
<p>Note that ‘array’ can only appear as the second to last element in the
abbreviation. Notationally, <code>array(EM)</code> is used in place of <code>array</code> and
<code>EM</code>, the last two entries in an abbreviation.</p>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, 88, 69)
| 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2
| 0> |
16:0|1: <65535, 8, 2> |module { // BlockID = 8
24:0| 3: <1, 1> | version 1;
26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0
36:0| 1: <1, 14> | valuesymtab:
38:4| 2: <65533, 4, 0, 1, 3, 0,| @a0 = abbrev <fixed(3), vbr(8),
| 2, 8, 0, 3, 0, 1, 8> | array(fixed(8))>;
43:2| 2: <65533, 4, 1, 1, 0, 2,| @a1 = abbrev <1, vbr(8),
| 8, 0, 3, 0, 1, 7> | array(fixed(7))>;
48:0| 2: <65533, 4, 1, 1, 0, 2,| @a2 = abbrev <1, vbr(8),
| 8, 0, 3, 0, 4> | array(char6)>;
52:1| 2: <65533, 4, 1, 2, 0, 2,| @a3 = abbrev <2, vbr(8),
| 8, 0, 3, 0, 4> | array(char6)>;
56:2| 1: <1, 11> | constants:
58:6| 2: <65533, 2, 1, 1, 0, 1,| @a0 = abbrev <1, fixed(2)>;
| 2> |
61:7| 2: <65533, 2, 1, 4, 0, 2,| @a1 = abbrev <4, vbr(8)>;
| 8> |
65:0| 2: <65533, 2, 1, 4, 1, 0>| @a2 = abbrev <4, 0>;
68:1| 2: <65533, 2, 1, 6, 0, 2,| @a3 = abbrev <6, vbr(8)>;
| 8> |
71:2| 1: <1, 12> | function:
73:6| 2: <65533, 4, 1, 20, 0, | @a0 = abbrev <20, vbr(6), vbr(4),
| 2, 6, 0, 2, 4, 0, 2, | vbr(4)>;
| 4> |
79:1| 2: <65533, 4, 1, 2, 0, 2,| @a1 = abbrev <2, vbr(6), vbr(6),
| 6, 0, 2, 6, 0, 1, 4> | fixed(4)>;
84:4| 2: <65533, 4, 1, 3, 0, 2,| @a2 = abbrev <3, vbr(6),
| 6, 0, 1, 2, 0, 1, 4> | fixed(2), fixed(4)>;
89:7| 2: <65533, 1, 1, 10> | @a3 = abbrev <10>;
91:7| 2: <65533, 2, 1, 10, 0, | @a4 = abbrev <10, vbr(6)>;
| 2, 6> |
95:0| 2: <65533, 1, 1, 15> | @a5 = abbrev <15>;
97:0| 2: <65533, 3, 1, 43, 0, | @a6 = abbrev <43, vbr(6),
| 2, 6, 0, 1, 2> | fixed(2)>;
101:2| 2: <65533, 4, 1, 24, 0, | @a7 = abbrev <24, vbr(6), vbr(6),
| 2, 6, 0, 2, 6, 0, 2, | vbr(4)>;
| 4> |
106:5| 1: <1, 19> | globals:
109:1| 2: <65533, 3, 1, 0, 0, 2,| @a0 = abbrev <0, vbr(6),
| 6, 0, 1, 1> | fixed(1)>;
113:3| 2: <65533, 2, 1, 1, 0, 2,| @a1 = abbrev <1, vbr(8)>;
| 8> |
116:4| 2: <65533, 2, 1, 2, 0, 2,| @a2 = abbrev <2, vbr(8)>;
| 8> |
119:5| 2: <65533, 3, 1, 3, 0, 3,| @a3 = abbrev <3, array(fixed(8))>
| 0, 1, 8> | ;
123:2| 2: <65533, 2, 1, 4, 0, 2,| @a4 = abbrev <4, vbr(6)>;
| 6> |
126:3| 2: <65533, 3, 1, 4, 0, 2,| @a5 = abbrev <4, vbr(6), vbr(6)>;
| 6, 0, 2, 6> |
130:5| 0: <65534> | }
132:0| 1: <65535, 17, 3> | types { // BlockID = 17
140:0| 2: <65533, 4, 1, 21, 0, | %a0 = abbrev <21, fixed(1),
| 1, 1, 0, 3, 0, 1, 2> | array(fixed(2))>;
144:7| 3: <1, 3> | count 3;
147:4| 3: <7, 32> | @t0 = i32;
150:7| 4: <21, 0, 0, 0, 0> | @t1 = i32 (i32, i32); <%a0>
152:7| 3: <2> | @t2 = void;
154:6| 0: <65534> | }
156:0| 3: <8, 1, 0, 0, 0> | define external i32 @f0(i32, i32);
160:6| 1: <65535, 19, 4> | globals { // BlockID = 19
168:0| 3: <5, 0> | count 0;
170:6| 0: <65534> | }
172:0| 1: <65535, 14, 3> | valuesymtab { // BlockID = 14
180:0| 6: <1, 0, 102> | @f0 : "f"; <@a2>
182:7| 0: <65534> | }
184:0| 1: <65535, 12, 4> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
192:0| 3: <1, 1> | blocks 1;
| | %b0:
194:6| 5: <2, 2, 1, 0> | %v0 = add i32 %p0, %p1; <@a1>
197:2| 5: <2, 3, 1, 0> | %v1 = add i32 %p0, %v0; <@a1>
199:6| 8: <10, 1> | ret i32 %v1; <@a4>
201:0| 0: <65534> | }
204:0|0: <65534> |}
</pre>
<p>Note that the example above shows the standard abbreviations used by
<em>pnacl-finalize</em>.</p>
<h2 id="types-block"><span id="link-for-types-block-section"></span>Types Block</h2>
<p>The types block defines all types used in a program. It must appear in the
<a class="reference internal" href="#link-for-module-block"><em>module block</em></a>, before any <a class="reference internal" href="#link-for-function-address-section"><em>function
address</em></a> records, the <a class="reference internal" href="#link-for-globals-block-section"><em>globals
block</em></a>, the <a class="reference internal" href="#link-for-valuesymtab-block-section"><em>valuesymtab
block</em></a>, and any <a class="reference internal" href="#link-for-function-blocks-section"><em>function
blocks</em></a>.</p>
<p>All types used in a program must be defined in the types block. Many PNaClAsm
constructs allow one to use explicit type names, rather than the type
identifiers defined by this block. However, they are internally converted to the
corresponding type identifier in the types block. Hence, the requirement that
the types block must appear early in the module block.</p>
<p>Each record in the types block defines a type used by the program. Types can be
broken into the following groups:</p>
<dl class="docutils">
<dt>Primitive value types</dt>
<dd>Defines the set of base types for values. This includes various sizes of
integer and floating point types.</dd>
<dt>Void type</dt>
<dd>A primitive type that doesn’t represent any value and has no size.</dd>
<dt>Function types</dt>
<dd>The type signatures of functions.</dd>
<dt>Vector type</dt>
<dd>Defines vectors of primitive types.</dd>
</dl>
<p>In addition, any type that is not defined using another type is a primitive
type. All other types (i.e. function and vector) are composite types.</p>
<p>Types must be defined in a topological order, causing primitive types to appear
before the composite types that use them. Each type must be unique. There are no
additional restrictions on the order that types can be defined in a types block.</p>
<p>The following subsections introduce each valid PNaClAsm type, and the
corresponding PNaClAsm construct that defines the type. Types not defined in the
types block, can’t be used in a PNaCl program.</p>
<p>The first record of a types block must be a <a class="reference internal" href="#link-for-types-count-record"><em>count
record</em></a>, defining how many types are defined by the
types block. All remaining records defines a type. The following subsections
defines valid records within a types block. The order of type records is
important. The position of each defining record implicitly defines the type ID
that will be used to denote that type, within other PNaCl records of the bitcode
file.</p>
<p>To make this more concrete, consider the following example types block:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <3> | @t1 = float;
55:4| 3: <2> | @t2 = void;
57:2| 3: <21, 0, 2, 0, 1> | @t3 = void (i32, float);
62:0| 0: <65534> | }
</pre>
<p>This example defines a types block that defines four type IDs:</p>
<dl class="docutils">
<dt>@t0</dt>
<dd>A 32-bit integer type.</dd>
<dt>@t1</dt>
<dd>A 32-bit floating point type.</dd>
<dt>@t2</dt>
<dd>The void type.</dd>
<dt>@t3</dt>
<dd>A function, taking 32-bit integer and float point arguments that returns
void.</dd>
</dl>
<h3 id="count-record"><span id="link-for-types-count-record"></span>Count Record</h3>
<p>The <em>count record</em> defines how many types are defined in the types
block. Following the types count record are records that define types used by
the PNaCl program.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
count N; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <1, N>
</pre>
<p><strong>Semantics</strong>:</p>
<p>This construct defines the number of types used by the PNaCl program. <code>N</code> is
the number of types defined in the types block. It is an error to define more
(or fewer) types than value <code>N</code>, within the enclosing types block.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
0 == NumTypes
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
ExpectedTypes = N;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <3> | @t1 = float;
55:4| 3: <2> | @t2 = void;
57:2| 3: <21, 0, 2, 0, 1> | @t3 = void (i32, float);
62:0| 0: <65534> | }
</pre>
<h3 id="void-type">Void Type</h3>
<p>The <em>void</em> type record defines the void type, which corresponds to the type that
doesn’t define any value, and has no size.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
@tN = void; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The void type record defines the type that has no values and has no size.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
N == NumTypes
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumTypes;
TypeOf(@tN) = void;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <3> | @t1 = float;
55:4| 3: <2> | @t2 = void;
62:0| 0: <65534> | }
</pre>
<h3 id="integer-types">Integer Types</h3>
<p>PNaClAsm allows integer types for various bit sizes. Valid bit sizes are 1, 8,
16, 32, and 64. Integers can be signed or unsigned, but the signed component of
an integer is not specified by the type. Rather, individual instructions
determine whether the value is assumed to be signed or unsigned.</p>
<p>It should be noted that in PNaClAsm, all pointers are implemented as 32-bit
(unsigned) integers. There isn’t a separate type for pointers. The only way to
tell that a 32-bit integer is a pointer, is when it is used in an instruction
that requires a pointer (such as load and store instructions).</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
@tN = iB; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <7, B>
</pre>
<p><strong>Semantics</strong>:</p>
<p>An integer type record defines an integer type. <code>B</code> defines the number of bits
of the integer type.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
N == NumTypes &
B in {1, 8, 16, 32, 64}
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumTypes;
TypeOf(@tN) = iB;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 7> | count 7;
50:4| 3: <7, 64> | @t0 = i64;
53:6| 3: <7, 1> | @t1 = i1;
56:2| 3: <7, 8> | @t2 = i8;
58:6| 3: <7, 16> | @t3 = i16;
61:2| 3: <7, 32> | @t4 = i32;
64:4| 3: <21, 0, 0, 1> | @t5 = i64 (i1);
68:4| 3: <2> | @t6 = void;
70:2| 0: <65534> | }
</pre>
<h3 id="bit-floating-point-type">32-Bit Floating Point Type</h3>
<p>PNaClAsm allows computation on 32-bit floating point values. A floating point
type record defines the 32-bit floating point type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
@tN = float; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <3>
</pre>
<p><strong>Semantics</strong>:</p>
<p>A floating point type record defines the 32-bit floating point type.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
N == NumTypes
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumTypes;
TypeOf(@tN) = float;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <4> | @t0 = double;
52:2| 3: <3> | @t1 = float;
54:0| 3: <21, 0, 0, 1> | @t2 = double (float);
58:0| 3: <2> | @t3 = void;
59:6| 0: <65534> | }
</pre>
<h3 id="id1">64-bit Floating Point Type</h3>
<p>PNaClAsm allows computation on 64-bit floating point values. A 64-bit floating
type record defines the 64-bit floating point type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
@tN = double; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <4>
</pre>
<p><strong>Semantics</strong>:</p>
<p>A double type record defines the 64-bit floating point type.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
N == NumTypes
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumTypes;
TypeOf(@tN) = double;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <4> | @t0 = double;
52:2| 3: <3> | @t1 = float;
54:0| 3: <21, 0, 0, 1> | @t2 = double (float);
58:0| 3: <2> | @t3 = void;
59:6| 0: <65534> | }
</pre>
<h3 id="vector-types">Vector Types</h3>
<p>A vector type is a derived type that represents a vector of elements. Vector
types are used when multiple primitive data values are operated in parallel
using a single (SIMD) <a class="reference internal" href="#link-for-vector-instructions"><em>vector instruction</em></a>. A
vector type requires a size (number of elements) and an underlying primitive
data type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
@tN = < E x T > <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <12, E, TT>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The vector type defines a vector of elements. <code>T</code> is the type of each
element. <code>E</code> is the number of elements in the vector.</p>
<p>Vector types can only be defined on <code>i1</code>, <code>i8</code>, <code>i16</code>, <code>i32</code>, and
<code>float</code>. All vector types, except those on <code>i1</code>, must contain exactly 128
bits. The valid element sizes are restricted as follows:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Type</th>
<th class="head">Valid element sizes</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>i1</td>
<td>4, 8, 16</td>
</tr>
<tr class="row-odd"><td>i8</td>
<td>16</td>
</tr>
<tr class="row-even"><td>i16</td>
<td>8</td>
</tr>
<tr class="row-odd"><td>i32</td>
<td>4</td>
</tr>
<tr class="row-even"><td>float</td>
<td>4</td>
</tr>
</tbody>
</table>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
TT == AbsoluteIndex(TypeID(T)) &
N == NumTypes
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumTypes
TypeOf(@tN) = <E x T>
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 14> | count 14;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <7, 1> | @t1 = i1;
56:2| 3: <2> | @t2 = void;
58:0| 3: <12, 4, 1> | @t3 = <4 x i1>;
61:2| 3: <12, 8, 1> | @t4 = <8 x i1>;
64:4| 3: <12, 16, 1> | @t5 = <16 x i1>;
67:6| 3: <7, 8> | @t6 = i8;
70:2| 3: <12, 16, 6> | @t7 = <16 x i8>;
73:4| 3: <7, 16> | @t8 = i16;
76:0| 3: <12, 8, 8> | @t9 = <8 x i16>;
79:2| 3: <12, 4, 0> | @t10 = <4 x i32>;
82:4| 3: <3> | @t11 = float;
84:2| 3: <12, 4, 11> | @t12 = <4 x float>;
87:4| 3: <21, 0, 2> | @t13 = void ();
90:6| 0: <65534> | }
</pre>
<h3 id="function-type"><span id="link-for-function-type"></span>Function Type</h3>
<p>The <em>function</em> type can be thought of as a function signature. It consists of a
return type, and a (possibly empty) list of formal parameter types.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%tN = RT (T1, ... , TM) <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <21, 0, IRT, IT1, ... , ITM>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The function type defines the signature of a function. <code>RT</code> is the return type
of the function, while types <code>T1</code> through <code>TM</code> are the types of the
arguments. Indices to the corresponding type identifiers are stored in the
corresponding record.</p>
<p>The return value must either be a primitive type, type <code>void</code>, or a vector
type. Parameter types can be a primitive or vector type.</p>
<p>For ordinary functions, the only valid integer types that can be used for a
return or parameter type are <code>i32</code> and <code>i64</code>. All other integer types are
not allowed.</p>
<p>For <a class="reference internal" href="#link-for-intrinsic-functions-section"><em>intrinsic functions</em></a>, all
integer types are allowed for both return and parameter types.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
M >= 0 &
IRT == AbsoluteIndex(TypeID(RT)) &
IT1 == AbsoluteIndex(TypeID(T1)) &
...
ITM == AbsoluteIndex(TypeID(TM)) &
N == NumTypes
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumTypes
TypeOf(@tN) = RT (T1, ... , TM)
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 7> | count 7;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <3> | @t1 = float;
55:4| 3: <4> | @t2 = double;
57:2| 3: <21, 0, 2, 1> | @t3 = double (float);
61:2| 3: <2> | @t4 = void;
63:0| 3: <21, 0, 4> | @t5 = void ();
66:2| 3: <21, 0, 0, 0, 1, 0, 2>| @t6 =
| | i32 (i32, float, i32, double);
72:4| 0: <65534> | }
</pre>
<h2 id="globals-block"><span id="link-for-globals-block-section"></span>Globals Block</h2>
<p>The globals block defines global addresses of variables and constants, used by
the PNaCl program. It also defines the memory associated with the global
addresses, and how to initialize each global variable/constant. It must appear
in the <a class="reference internal" href="#link-for-module-block"><em>module block</em></a>. It must appear after the
<a class="reference internal" href="#link-for-types-block-section"><em>types block</em></a>, as well as after all
<a class="reference internal" href="#link-for-function-address-section"><em>function address</em></a> records. But, it must
also appear before the <a class="reference internal" href="#link-for-valuesymtab-block-section"><em>valuesymtab
block</em></a>, and any
<a class="reference internal" href="#link-for-function-blocks-section"><em>function blocks</em></a>.</p>
<p>The globals block begins with a <a class="reference internal" href="#link-for-globals-count-record"><em>count
record</em></a>, defining how many global addresses are
defined by the PNaCl program. It is then followed by a sequence of records that
defines each global address, and how each global address is initialized.</p>
<p>The standard sequence, for defining global addresses, begins with a global
address record. It is then followed by a sequence of records defining how the
global address is initialized. If the initializer is simple, a single record is
used. Otherwise, the initializer is preceded with a <a class="reference internal" href="#link-for-compound-initializer"><em>compound
record</em></a>, specifying a number <em>N</em>, followed by
sequence of <em>N</em> simple initializer records.</p>
<p>The size of the memory referenced by each global address is defined by its
initializer records. All simple initializer records define a sequence of
bytes. A compound initializer defines the sequence of bytes by concatenating the
corresponding sequence of bytes for each of its simple initializer records.</p>
<p>For notational convenience, PNaClAsm begins a compound record with a “{”, and
inserts a “}” after the last initializer record associated with the compound
record. This latter “}” does not correspond to any record. It is implicitly
assumed by the size specified in the compound record, and is added only to
improve readability.</p>
<p>Explicit alignment is specified for global addresses, and must be a power of
2. See <a class="reference internal" href="#link-for-memory-blocks-and-alignment-section"><em>memory blocks and
alignment</em></a> for a more detailed
discussion on how to define alignment.</p>
<p>For example, consider the following pnacl-bcdis output snippet:</p>
<pre class="prettyprint">
52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
60:0| 3: <5, 2> | count 2;
62:4| 3: <0, 1, 1> | const @g0, align 1,
65:6| 3: <2, 8> | zerofill 8;
68:2| 3: <0, 1, 0> | var @g1, align 1,
71:4| 3: <1, 2> | initializers 2 {
74:0| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4}
78:6| 3: <2, 2> | zerofill 2;
| | }
81:2| 0: <65534> | }
</pre>
<p>This snippet defines the global constant <code>@g0</code>, and the global variable
<code>@g1</code>. <code>@g0</code> is 8 bytes long, and initialized to zero. <code>@g1</code> is
initialized with 6 bytes: <code>1 2 3 4 0 0</code>.</p>
<h3 id="link-for-globals-count-record"><span id="id2"></span>Count Record</h3>
<p>The count record defines the number of global addresses used by the PNaCl
program.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
count N; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <5, N>
</pre>
<p><strong>Semantics</strong>:</p>
<p>This record must appear first in the globals block. The count record defines
the number of global addresses used by the program.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A)
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
ExpectedGlobals = N;
ExpectedInitializers = 0;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
60:0| 3: <5, 2> | count 2;
62:4| 3: <0, 1, 1> | const @g0, align 1,
65:6| 3: <2, 8> | zerofill 8;
68:2| 3: <0, 1, 0> | var @g1, align 1,
71:4| 3: <1, 2> | initializers 2 {
74:0| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4}
78:6| 3: <2, 2> | zerofill 2;
| | }
81:2| 0: <65534> | }
</pre>
<h3 id="global-variable-addresses"><span id="link-for-global-variable-address"></span>Global Variable Addresses</h3>
<p>A global variable address record defines a global address to global data. The
global variable address record must be immediately followed by initializer
record(s) that define how the corresponding global variable is initialized.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
var @gN, align V, <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <0, VV, 0>
</pre>
<p><strong>Semantics</strong>:</p>
<p>A global variable address record defines a global address for a global variable.
<code>V</code> is the <a class="reference internal" href="#link-for-memory-blocks-and-alignment-section"><em>memory
alignment</em></a> for the global variable
address, and is a power of 2.</p>
<p>It is assumed that the memory, referenced by the global variable address, can be
both read and written to.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
N == NumGlobalAddresses &
ExpectedInitializers == 0 &
VV == Log2(V+1)
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumGlobalAddresses;
ExpectedInitializers = 1;
TypeOf(@gN) = i32;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
60:0| 3: <5, 2> | count 2;
62:4| 3: <0, 3, 0> | var @g0, align 4,
65:6| 3: <2, 8> | zerofill 8;
68:2| 3: <0, 1, 0> | var @g1, align 1,
71:4| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4}
76:2| 0: <65534> | }
80:0|0: <65534> |}
</pre>
<h3 id="global-constant-addresses"><span id="link-for-global-constant-address"></span>Global Constant Addresses</h3>
<p>A global constant address record defines an address corresponding to a global
constant that can’t be modified by the program. The global constant address
record must be immediately followed by initializer record(s) that define how
the corresponding global constant is initialized.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
const @gN, align V, <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <0, VV, 1>
</pre>
<p><strong>Semantics</strong>:</p>
<p>A global constant address record defines a global address for a global constant.
<code>V</code> is the <a class="reference internal" href="#link-for-memory-blocks-and-alignment-section"><em>memory
alignment</em></a> for the global constant
address, and is a power of 2.</p>
<p>It is assumed that the memory, referenced by the global constant address, is
only read, and can’t be written to.</p>
<p>Note that the only difference between a global variable address and a global
constant address record is the third element of the record. If the value is
zero, it defines a global variable address. If the value is one, it defines a
global constant address.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
N == NumGlobalAddresses &
ExpectedInitializers == 0 &
VV == Log2(V+1)
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumGlobalAddresses;
ExpectedInitializers = 1;
TypeOf(@gN) = i32;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
60:0| 3: <5, 2> | count 2;
62:4| 3: <0, 3, 1> | const @g0, align 4,
65:6| 3: <2, 8> | zerofill 8;
68:2| 3: <0, 1, 1> | const @g1, align 1,
71:4| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4}
76:2| 0: <65534> | }
</pre>
<h3 id="zerofill-initializer">Zerofill Initializer</h3>
<p>The zerofill initializer record initializes a sequence of bytes, associated with
a global address, with zeros.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
zerofill N; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, N>
</pre>
<p><strong>Semantics</strong>:</p>
<p>A zerofill initializer record initializes a sequence of bytes, associated with a
global address, with zeros. The number of bytes initialized to zero is <code>N</code>.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
ExpectedInitializers > 0
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
--ExpectedInitializers;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
60:0| 3: <5, 2> | count 2;
62:4| 3: <0, 3, 1> | const @g0, align 4,
65:6| 3: <2, 8> | zerofill 8;
68:2| 3: <0, 1, 0> | var @g1, align 1,
71:4| 3: <2, 4> | zerofill 4;
74:0| 0: <65534> | }
</pre>
<h3 id="data-initializer">Data Initializer</h3>
<p>Data records define a sequence of bytes. These bytes define the initial value of
the contents of the corresponding memory.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
{ B1 , .... , BN } <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <3, B1, ..., BN>
</pre>
<p><strong>Semantics</strong>:</p>
<p>A data record defines a sequence of (unsigned) bytes <code>B1</code> through <code>BN</code>, that
initialize <code>N</code> bytes of memory.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
ExpectedInitializers > 0
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
--ExpectedInitializers;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
56:0| 3: <8, 1, 0, 1, 0> | declare external void @f0();
60:6| 1: <65535, 19, 2> | globals { // BlockID = 19
68:0| 3: <5, 2> | count 2;
70:4| 3: <0, 1, 1> | const @g0, align 1,
73:6| 3: <3, 1, 2, 97, 36, 44, | { 1, 2, 97, 36, 44, 88,
| 88, 44, 50> | 44, 50}
86:0| 3: <0, 1, 1> | const @g1, align 1,
89:2| 3: <1, 3> | initializers 3 {
91:6| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4}
96:4| 3: <4, 0> | reloc @f0;
99:0| 3: <3, 99, 66, 22, 12> | { 99, 66, 22, 12}
| | }
105:2| 0: <65534> | }
</pre>
<h3 id="relocation-initializer">Relocation Initializer</h3>
<p>A relocation initializer record allows one to define the initial value of a
global address with the value of another global address (i.e. either
<a class="reference internal" href="#link-for-function-address-section"><em>function</em></a>,
<a class="reference internal" href="#link-for-global-variable-address"><em>variable</em></a>, or
<a class="reference internal" href="#link-for-global-constant-address"><em>constant</em></a>). Since addresses are
pointers, a relocation initializer record defines 4 bytes of memory.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
reloc V; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <4, VV>
</pre>
<p><strong>Semantics</strong>:</p>
<p>A relocation initializer record defines a 4-byte value containing the specified
global address <code>V</code>.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV == AbsoluteIndex(V) &
VV >= NumFuncAddresses &
VV < NumFuncAddresses + ExpectedGlobals &
ExpectedInitializers > 0
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
--ExpectedInitializers;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 2> | count 2;
50:4| 3: <2> | @t0 = void;
52:2| 3: <21, 0, 0> | @t1 = void ();
55:4| 0: <65534> | }
56:0| 3: <8, 1, 0, 1, 0> | declare external void @f0();
60:6| 1: <65535, 19, 2> | globals { // BlockID = 19
68:0| 3: <5, 2> | count 2;
70:4| 3: <0, 1, 0> | var @g0, align 1,
73:6| 3: <1, 3> | initializers 3 {
76:2| 3: <4, 0> | reloc @f0;
78:6| 3: <4, 1> | reloc @g0;
81:2| 3: <4, 2> | reloc @g1;
| | }
83:6| 3: <0, 3, 0> | var @g1, align 4,
87:0| 3: <2, 4> | zerofill 4;
89:4| 0: <65534> | }
</pre>
<p>This example defines global address <code>@g0</code> and <code>@g1</code>. <code>@g0</code> defines 12
bytes of memory, and is initialized with three addresses <code>@f1</code>, <code>@g0</code>, and
<code>@g1</code>. Note that all global addresses can be used in a relocation
initialization record, even if it isn’t defined yet.</p>
<h3 id="subfield-relocation-initializer">Subfield Relocation Initializer</h3>
<p>A subfield relocation initializer record allows one to define the initial value
of a global address with the value of another (non-function) global address
(i.e. either <a class="reference internal" href="#link-for-global-variable-address"><em>variable</em></a> or
<a class="reference internal" href="#link-for-global-constant-address"><em>constant</em></a> address), plus a
constant. Since addresses are pointers, a relocation initializer record defines
4 bytes of memory.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
reloc V + X; <A>
reloc V - X; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <4, VV, XXX>
</pre>
<p><strong>Semantics</strong>:</p>
<p>A subfield relocation initializer record defines a 4-byte value containing the
specified global (non-function) address <code>V</code>, modified by the unsigned offset
<code>X</code>. <code>XX</code> is the corresponding signed offset. In the first form, <code>XX ==
X</code>. In the second form, <code>XX == -X</code>.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A)
VV == AbsoluteIndex(V)
VV >= NumFuncAddresses
VV < NumFuncAddresses + ExpectedGlobals
ExpectedInitializers > 0
XXX == SignRotate(XX)
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
--ExpectedInitializers;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 0> | count 0;
50:4| 0: <65534> | }
52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
60:0| 3: <5, 3> | count 3;
62:4| 3: <0, 1, 0> | var @g0, align 1,
65:6| 3: <1, 3> | initializers 3 {
68:2| 3: <4, 0, 1> | reloc @g0 + 1;
71:4| 3: <4, 1, 4294967295> | reloc @g1 - 1;
79:2| 3: <4, 2, 4> | reloc @g2 + 4;
| | }
82:4| 3: <0, 3, 0> | var @g1, align 4,
85:6| 3: <2, 4> | zerofill 4;
88:2| 3: <0, 3, 0> | var @g2, align 4,
91:4| 3: <2, 8> | zerofill 8;
94:0| 0: <65534> | }
</pre>
<h3 id="compound-initializer"><span id="link-for-compound-initializer"></span>Compound Initializer</h3>
<p>The compound initializer record must immediately follow a global
<a class="reference internal" href="#link-for-global-variable-address"><em>variable</em></a> or
<a class="reference internal" href="#link-for-global-constant-address"><em>constant</em></a> address record. It defines how
many simple initializer records are used to define the initializer. The size of
the corresponding memory is the sum of the bytes needed for each of the
succeeding initializers.</p>
<p>Note that a compound initializer can’t be used as a simple initializer of
another compound initializer (i.e. nested compound initializers are not
allowed).</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
initializers N { <A>
...
}
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <1, N>
</pre>
<p><strong>Semantics</strong>:</p>
<p>Defines that the next <cite>N</cite> initializers should be associated with the global
address of the previous record.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
ExpectedInitializers == 1
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
ExpectedInitializers = N;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 0> | count 0;
50:4| 0: <65534> | }
52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
60:0| 3: <5, 2> | count 2;
62:4| 3: <0, 0, 1> | const @g0, align 0,
65:6| 3: <1, 2> | initializers 2 {
68:2| 3: <2, 8> | zerofill 8;
70:6| 3: <3, 3, 2, 1, 0> | { 3, 2, 1, 0}
| | }
75:4| 3: <0, 0, 0> | var @g1, align 0,
78:6| 3: <1, 2> | initializers 2 {
81:2| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4}
86:0| 3: <2, 2> | zerofill 2;
| | }
88:4| 0: <65534> | }
</pre>
<h2 id="valuesymtab-block"><span id="link-for-valuesymtab-block-section"></span>Valuesymtab Block</h2>
<p>The valuesymtab block does not define any values. Its only goal is to associate
text names with external <a class="reference internal" href="#link-for-function-address-section"><em>function
addresses</em></a>. Each association is defined by a
record in the valuesymtab block. Currently, only
<a class="reference internal" href="#link-for-intrinsic-functions-section"><em>intrinsic</em></a> function addresses and
the (external) start function (<code>_start</code>) can be named. All named function
addresses must be external. Each record in the valuesymtab block is a <em>entry</em>
record, defining a single name association.</p>
<h3 id="entry-record">Entry Record</h3>
<p>The <em>entry</em> record defines a name for a function address.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
V : "NAME"; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <1, B1, ... , BN>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The <em>entry</em> record defines a name <code>NAME</code> for function address <code>V</code>. <code>NAME</code>
is a sequence of ASCII characters <code>B1</code> through <code>BN</code>.</p>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
72:0| 3: <8, 4, 0, 1, 0> | declare external
| | void @f0(i32, i32, i32, i32, i1);
76:6| 3: <8, 4, 0, 1, 0> | declare external
| | void @f1(i32, i32, i32, i32, i1);
81:4| 3: <8, 5, 0, 0, 0> | define external void @f2(i32);
86:2| 1: <65535, 19, 2> | globals { // BlockID = 19
92:0| 3: <5, 0> | count 0;
94:4| 0: <65534> | }
96:0| 1: <65535, 14, 2> | valuesymtab { // BlockID = 14
104:0| 3: <1, 1, 108, 108, 118, | @f1 : "llvm.memmove.p0i8.p0i8.i32";
| 109, 46, 109, 101, |
| 109, 109, 111, 118, |
| 101, 46, 112, 48, |
| 105, 56, 46, 112, 48,|
| 105, 56, 46, 105, 51,|
| 50> |
145:4| 3: <1, 2, 95, 115, 116, | @f2 : "_start";
| 97, 114, 116> |
157:0| 3: <1, 0, 108, 108, 118, | @f0 : "llvm.memcpy.p0i8.p0i8.i32";
| 109, 46, 109, 101, |
| 109, 99, 112, 121, |
| 46, 112, 48, 105, 56,|
| 46, 112, 48, 105, 56,|
| 46, 105, 51, 50> |
197:0| 0: <65534> | }
</pre>
<h2 id="module-block"><span id="link-for-module-block"></span>Module Block</h2>
<p>The module block, like all blocks, is enclosed in a pair of
<a class="reference internal" href="#link-for-enter-block-record-section"><em>enter</em></a> /
<a class="reference internal" href="#link-for-exit-block-record-section"><em>exit</em></a> records, using block ID 8. A
well-formed module block consists of the following records (in order):</p>
<dl class="docutils">
<dt>A version record</dt>
<dd>The <a class="reference internal" href="#link-for-version-record"><em>version record</em></a> communicates which version
of the PNaCl bitcode reader/writer should be used. Note that this is
different than the PNaCl bitcode (ABI) version. The PNaCl bitcode (ABI)
version defines what is expected in records, and is defined in the header
record of the bitcode file. The version record defines the version of the
PNaCl bitcode reader/writer to use to convert records into bit sequences.</dd>
<dt>Optional local abbreviations</dt>
<dd>Defines a list of local <a class="reference internal" href="#link-for-abbreviations-section"><em>abbreviations</em></a>
to use for records within the module block.</dd>
<dt>An abbreviations block</dt>
<dd>The <a class="reference internal" href="#link-for-abbreviations-block-section"><em>abbreviations block</em></a> defines
user-defined, global abbreviations that are used to convert PNaCl records to
bit sequences in blocks following the abbreviations block.</dd>
<dt>A types block</dt>
<dd>The <a class="reference internal" href="#link-for-types-block-section"><em>types block</em></a> defines the set of all
types used in the program.</dd>
<dt>A non-empty sequence of function address records</dt>
<dd>Each record defines a <a class="reference internal" href="#link-for-function-address-section"><em>function
address</em></a> used by the program. Function
addresses must either be external, or defined internally by the program. If
they are defined by the program, there must be a <a class="reference internal" href="#link-for-function-blocks-section"><em>function
block</em></a> (appearing later in the module) that
defines the sequence of instructions for each defined function.</dd>
<dt>A globals block defining the global variables.</dt>
<dd>This <a class="reference internal" href="#link-for-globals-block-section"><em>block</em></a> defines the set of
global <a class="reference internal" href="#link-for-global-variable-address"><em>variable</em></a> and
<a class="reference internal" href="#link-for-global-constant-address"><em>constant</em></a> addresses used by the
program. In addition to the addresses, each global variable also defines how
the corresponding global variable is initialized.</dd>
<dt>An optional value symbol table block.</dt>
<dd>This <a class="reference internal" href="#link-for-valuesymtab-block-section"><em>block</em></a>, if defined, provides
textual names for <a class="reference internal" href="#link-for-function-address-section"><em>function
addresses</em></a> (previously defined in the
module). Note that only names for intrinsic functions and the start function
are specified.</dd>
<dt>A sequence of function blocks.</dt>
<dd>Each <a class="reference internal" href="#link-for-function-blocks-section"><em>function block</em></a> defines the
corresponding intermediate representation for each defined function. The
order of function blocks is used to associate them with <a class="reference internal" href="#link-for-function-address-section"><em>function
addresses</em></a>. The order of the defined
function blocks must follow the same order as the corresponding function
addresses defined in the module block.</dd>
</dl>
<p>Descriptions of the <a class="reference internal" href="#link-for-abbreviations-section"><em>abbreviations</em></a>,
<a class="reference internal" href="#link-for-types-block-section"><em>types</em></a>,
<a class="reference internal" href="#link-for-globals-block-section"><em>globals</em></a>, <a class="reference internal" href="#link-for-valuesymtab-block-section"><em>value symbol
table</em></a>, and
<a class="reference internal" href="#link-for-function-blocks-section"><em>function</em></a> blocks are not provided
here. See the appropriate reference for more details. The following subsections
describe each of the records that can appear in a module block.</p>
<h3 id="version-record"><span id="link-for-version-record"></span>Version Record</h3>
<p>The version record defines the implementation of the PNaCl bitstream
reader/writer to use. That is, the implementation that converts PNaCl records to
bit sequences, and converts them back to PNaCl records. Note that this is
different than the PNaCl version of the bitcode file (encoded in the header
record of the bitcode file). The PNaCl version defines the valid forms of PNaCl
records. The version record is specific to the PNaCl version, and may have
different values for different PNaCl versions.</p>
<p>Note that currently, only PNaCl bitcode version 2, and version record value 1 is
defined.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
version N; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <1, N>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The version record defines which PNaCl reader/writer rules should be
followed. <code>N</code> is the version number. Currently <code>N</code> must be 1. Future
versions of PNaCl may define additional legal values.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A)
</pre>
<p><em>Examples</em>:</p>
<pre class="prettyprint">
16:0|1: <65535, 8, 2> |module { // BlockID = 8
24:0| 3: <1, 1> | version 1;
26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0
36:0| 0: <65534> | }
</pre>
<h3 id="function-address"><span id="link-for-function-address-section"></span>Function Address</h3>
<p>A function address record describes a function address. <em>Defined</em> function
addresses define <a class="reference internal" href="#link-for-function-blocks-section"><em>implementations</em></a> while
<em>declared</em> function addresses do not.</p>
<p>Since a PNaCl program is assumed to be a complete (statically linked)
executable, All functions should be <em>defined</em> and <em>internal</em>. The exception to
this are <a class="reference internal" href="#link-for-intrinsic-functions-section"><em>intrinsic functions</em></a>, which
should only be <em>declared</em> and <em>external</em>, since intrinsic functions will be
automatically converted to appropriate code by the <a class="reference internal" href="/native-client/overview.html#link-for-pnacl-translator"><em>PNaCl
translator</em></a>.</p>
<p>The implementation of a <em>defined</em> function address is provided by a
corresponding function block, appearing later in the module block. The
association of a <em>defined</em> function address with the corresponding function
block is based on position. The <em>Nth</em> defined function address record, in the
module block, has its implementation in the <em>Nth</em> function block of that module
block.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
PN LN T0 @fN ( T1 , ... , TM ); <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <8, T, C, P, L>
</pre>
<p><strong>Semantics</strong>:</p>
<p>Describes the function address <code>@fN</code>. <code>PN</code> is the name that specifies the
prototype value <code>P</code> associated with the function. A function address is
<em>defined</em> only if <code>P == 0</code>. Otherwise, it is only <em>declared</em>. The type of the
function is <a class="reference internal" href="#link-for-function-type"><em>function type</em></a> <code>@tT</code>. <code>L</code> is the
linkage specification corresponding to name <code>LN</code>. <code>C</code> is the calling
convention used by the function.</p>
<p>Note that function signature must be defined by a function type in the types
block. Hence, the return value must either be a primitive type, type <code>void</code>,
or a vector type.</p>
<p>For ordinary functions, integer parameter and types can only be <code>i32</code> and
<code>i64</code>. All other integer types are not allowed. For intrinsic functions, all
integer types are allowed.</p>
<p>Valid prototype names <code>PN</code>, and corresponding <code>P</code> values, are:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">P</th>
<th class="head">PN</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>1</td>
<td>declare</td>
</tr>
<tr class="row-odd"><td>0</td>
<td>define</td>
</tr>
</tbody>
</table>
<p>Valid linkage names <code>LN</code>, and corresponding <code>L</code> values, are:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">L</th>
<th class="head">LN</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>3</td>
<td>internal</td>
</tr>
<tr class="row-odd"><td>0</td>
<td>external</td>
</tr>
</tbody>
</table>
<p>Currently, only one calling convention <code>C</code> is supported:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">C</th>
<th class="head">Calling Convention</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>0</td>
<td>C calling convention</td>
</tr>
</tbody>
</table>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA = AbbrevIndex(A) &
T = TypeID(TypeOf(T0 ( T1 , ... , TN ))) &
N = NumFuncAddresses
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumFuncAddresses;
TypeOf(@fN) = TypeOf(TypeID(i32));
TypeOfFcn(@fN) = TypeOf(@tT);
if PN == 0:
DefiningFcnIDs += @FN;
++NumDefinedFunctionAddresses;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 7> | count 7;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <3> | @t1 = float;
55:4| 3: <4> | @t2 = double;
57:2| 3: <2> | @t3 = void;
59:0| 3: <21, 0, 2, 1> | @t4 = double (float);
63:0| 3: <21, 0, 0, 0, 1, 0, 2>| @t5 =
| | i32 (i32, float, i32, double);
69:2| 3: <21, 0, 3> | @t6 = void ();
72:4| 0: <65534> | }
76:0| 3: <8, 4, 0, 1, 0> | declare external double @f0(float);
80:6| 3: <8, 5, 0, 1, 0> | declare external
| | i32 @f1(i32, float, i32, double);
85:4| 3: <8, 6, 0, 0, 0> | define external void @f2();
</pre>
<h2 id="constants-blocks"><span id="link-for-constants-block-section"></span>Constants Blocks</h2>
<p>Constants blocks define literal constants used within each function. Its intent
is to define them once, before instructions. A constants block can only appear
in a <a class="reference internal" href="#link-for-function-blocks-section"><em>function block</em></a>, and must appear
before any instructions in the function block.</p>
<p>Currently, only integer literals, floating point literals, and undefined vector
constants can be defined.</p>
<p>To minimize type information put in a constants block, the type information is
separated from the constants. This allows a sequence of constants to be given
the same type. This is done by defining a <a class="reference internal" href="#link-for-constants-set-type-record"><em>set type
record</em></a>, followed by a sequence of literal
constants. These literal constants all get converted to the type of the
preceding set type record.</p>
<p>Note that constants that are used for switch case selectors should not be added
to the constants block, since the switch instruction contains the constants used
for case selectors. All other constants in the function block must be put into a
constants block, so that instructions can use them.</p>
<p>To make this more concrete, consider the following example constants block:</p>
<pre class="prettyprint">
106:4| 1: <65535, 11, 2> | constants { // BlockID = 11
116:0| 3: <1, 0> | i32:
118:4| 3: <4, 2> | %c0 = i32 1;
121:0| 3: <4, 4> | %c1 = i32 2;
123:4| 3: <1, 2> | i8:
126:0| 3: <4, 8> | %c2 = i8 4;
128:4| 3: <4, 6> | %c3 = i8 3;
131:0| 3: <1, 1> | float:
133:4| 3: <6, 1065353216> | %c4 = float 1;
139:6| 0: <65534> | }
</pre>
<h3 id="set-type-record"><span id="link-for-constants-set-type-record"></span>Set Type Record</h3>
<p>The <em>set type</em> record defines the type to use for the (immediately) succeeding
literals.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
T: <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <1, TT>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The <em>set type</em> record defines type <code>T</code> to be used to type the (immediately)
succeeding literals. <code>T</code> must be a non-void primitive value type or a vector
type.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
TT == TypeID(T)
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
ConstantsSetType = T;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
106:4| 1: <65535, 11, 2> | constants { // BlockID = 11
116:0| 3: <1, 0> | i32:
118:4| 3: <4, 2> | %c0 = i32 1;
121:0| 3: <4, 4> | %c1 = i32 2;
123:4| 3: <1, 2> | i8:
126:0| 3: <4, 8> | %c2 = i8 4;
128:4| 3: <4, 6> | %c3 = i8 3;
131:0| 3: <1, 1> | float:
133:4| 3: <6, 1065353216> | %c4 = float 1;
139:6| 0: <65534> | }
</pre>
<h3 id="undefined-literal"><span id="link-for-undefined-literal"></span>Undefined Literal</h3>
<p>The <em>undefined</em> literal record creates an undefined literal for the type <em>T</em>
defined by the preceding <em>set type</em> record.</p>
<p>Note: See <a class="reference internal" href="#link-for-insert-element-instruction-section"><em>insert element
instruction</em></a> for an example of how
you would use the undefined literal with vector types.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%cN = T undef; <50>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <3>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The <em>undefined</em> literal record creates an undefined literal constant <code>%cN</code> for
type <code>T</code>. <code>T</code> must be the type defined by the preceding <em>set type</em> record,
and be a primitive value type or a vector type.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
N == NumFcnConsts &
T == ConstantsSetType &
IsPrimitive(T) or IsVector(T)
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumFcnConsts;
TypeOf(%cN) = T;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 5> | count 5;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <3> | @t1 = float;
55:4| 3: <2> | @t2 = void;
57:2| 3: <12, 4, 0> | @t3 = <4 x i32>;
60:4| 3: <21, 0, 2> | @t4 = void ();
63:6| 0: <65534> | }
...
106:4| 1: <65535, 11, 2> | constants { // BlockID = 11
116:0| 3: <1, 0> | i32:
118:4| 3: <3> | %c0 = i32 undef;
120:2| 3: <4, 2> | %c1 = i32 1;
122:6| 3: <1, 3> | <4 x i32>:
125:2| 3: <3> | %c2 = <4 x i32> undef;
127:0| 3: <1, 1> | float:
129:4| 3: <3> | %c3 = float undef;
131:2| 0: <65534> | }
</pre>
<h3 id="integer-literal"><span id="link-for-integer-literal"></span>Integer Literal</h3>
<p>The <em>integer literal</em> record creates an integer literal for the integer type <em>T</em>
defined by the preceding <em>set type</em> record.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%cN = T V; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <4, VV>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The <em>integer literal</em> record creates an integer literal constant <code>%cN</code> for
type <code>T</code>. <code>T</code> must be the type defined by the preceding <em>set type</em> record,
and an integer type. The literal <code>V</code> can be signed, but must be definable by
type <code>T</code>.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
N == NumFcnConsts &
T == ConstantsSetType &
VV == SignRotate(V) &
IsInteger(T)
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
TypeOf(%cN) = T;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 7> | count 7;
50:4| 3: <7, 8> | @t0 = i8;
53:0| 3: <7, 16> | @t1 = i16;
55:4| 3: <7, 32> | @t2 = i32;
58:6| 3: <7, 64> | @t3 = i64;
62:0| 3: <7, 1> | @t4 = i1;
64:4| 3: <2> | @t5 = void;
66:2| 3: <21, 0, 5> | @t6 = void ();
69:4| 0: <65534> | }
...
114:4| 1: <65535, 11, 2> | constants { // BlockID = 11
124:0| 3: <1, 0> | i8:
126:4| 3: <4, 2> | %c0 = i8 1;
129:0| 3: <4, 4> | %c1 = i8 2;
131:4| 3: <1, 1> | i16:
134:0| 3: <4, 6> | %c2 = i16 3;
136:4| 3: <4, 8> | %c3 = i16 4;
139:0| 3: <1, 2> | i32:
141:4| 3: <4, 10> | %c4 = i32 5;
144:0| 3: <4, 12> | %c5 = i32 6;
146:4| 3: <1, 3> | i64:
149:0| 3: <4, 3> | %c6 = i64 -1;
151:4| 3: <4, 5> | %c7 = i64 -2;
154:0| 3: <1, 4> | i1:
156:4| 3: <4, 3> | %c8 = i1 1;
159:0| 3: <4, 0> | %c9 = i1 0;
161:4| 0: <65534> | }
</pre>
<h3 id="floating-point-literal">Floating Point Literal</h3>
<p>The <em>floating point literal</em> record creates a floating point literal for the
floating point type <em>T</em> defined by the preceding <em>set type</em> record.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%cN = T V; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <6, VV>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The <em>floating point literal</em> record creates a floating point literal constant
<code>%cN</code> for type <code>T</code>. <code>T</code> must the type type defined by the preceding <em>set
type</em> record, and be a floating point type. The literal <code>V</code> is the floating
value to be defined. The value <code>VV</code> if the corresponding IEEE unsigned integer
that defines value <code>V</code>. That is, the literal <code>VV</code> must be a valid IEEE 754
32-bit (unsigned integer) value if <code>T</code> is <code>float</code>, and a valid IEEE 754
64-bit (unsigned integer) value if <code>T</code> is <code>double</code>.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
N == NumFcnConsts
T == ConstantsSetType
IsFloat(T)
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
TypeOf(%cN) = T;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <3> | @t0 = float;
52:2| 3: <4> | @t1 = double;
54:0| 3: <2> | @t2 = void;
55:6| 3: <21, 0, 2> | @t3 = void ();
59:0| 0: <65534> | }
...
102:4| 1: <65535, 11, 2> | constants { // BlockID = 11
112:0| 3: <1, 0> | float:
114:4| 3: <6, 0> | %c0 = float 0;
117:0| 3: <6, 1065353216> | %c1 = float 1;
123:2| 3: <6, 1088421888> | %c2 = float 7;
130:2| 3: <6, 1090519040> | %c3 = float 8;
137:2| 3: <3> | %c4 = float undef;
139:0| 3: <6, 2143289344> | %c5 = float nan;
146:0| 3: <6, 2139095040> | %c6 = float inf;
153:0| 3: <6, 4286578688> | %c7 = float -inf;
160:0| 3: <1, 1> | double:
162:4| 3: <6, | %c8 = double 1;
| 4607182418800017408> |
174:0| 3: <6, 0> | %c9 = double 0;
176:4| 3: <6, | %c10 = double 5;
| 4617315517961601024> |
188:0| 3: <6, | %c11 = double 6;
| 4618441417868443648> |
199:4| 3: <6, | %c12 = double nan;
| 9221120237041090560> |
211:0| 3: <6, | %c13 = double inf;
| 9218868437227405312> |
222:4| 3: <6, | %c14 = double -inf;
| 18442240474082181120>|
234:0| 0: <65534> | }
</pre>
<h2 id="function-blocks"><span id="link-for-function-blocks-section"></span>Function Blocks</h2>
<p>A function block defines the implementation of a defined <a class="reference internal" href="#link-for-function-address-section"><em>function
address</em></a>. The function address it defines is
based on the position of the corresponding defined function address. The Nth
defined function address always corresponds to the Nth function block in the
module block.</p>
<p>A function implementation contains a list of basic blocks, forming the control
flow graph. Each <em>basic block</em> contains a list of instructions, and ends with a
<a class="reference internal" href="#link-for-terminator-instruction-section"><em>terminator instruction</em></a>
(e.g. branch).</p>
<p>Basic blocks are not represented by records. Rather, context is implicit. The
first basic block begins with the first instruction record in the function
block. Block boundaries are determined by terminator instructions. The
instruction that follows a terminator instruction begins a new basic block.</p>
<p>The first basic block in a function is special in two ways: it is immediately
executed on entrance to the function, and it is not allowed to have predecessor
basic blocks (i.e. there can’t be any branches to the entry block of a
function). Because the entry block has no predecessors, it also can’t have any
<a class="reference internal" href="#link-for-phi-instruction-section"><em>phi</em></a> instructions.</p>
<p>The parameters are implied by the type of the corresponding function
address. One parameter is defined for each argument of the function <a class="reference internal" href="#link-for-function-type"><em>type
signature</em></a> of the corresponding <a class="reference internal" href="#link-for-function-address-section"><em>function
address</em></a>.</p>
<p>The number of basic blocks is defined by the <a class="reference internal" href="#link-for-basic-blocks-count"><em>count
record</em></a>. Each <a class="reference internal" href="#link-for-terminator-instruction-section"><em>terminator
instruction</em></a> ends the current basic
block, and the next instruction begins a new basic block. Basic blocks are
numbered by the order they appear (starting with index 0). Basic block IDs have
the form <code>%bN</code>, where <code>N</code> corresponds to the position of the basic block
within the function block.</p>
<p>Each instruction, within a function block, corresponds to a corresponding PNaCl
record. The layout of a function block is the (basic block) count record,
followed by a sequence of instruction records.</p>
<p>For readability, PNaClAsm introduces basic block IDs. These basic block IDs do
not correspond to PNaCl records, since basic block boundaries are defined
implicitly, after terminator instructions. They appear only for readability.</p>
<p>Operands of instructions are defined using an <a class="reference internal" href="#link-for-absolute-index-section"><em>absolute
index</em></a>. This absolute index implicitly encodes
function addresses, global addresses, parameters, constants, and instructions
that generate values. The encoding takes advantage of the implied ordering of
these values in the bitcode file, defining a contiguous sequence of indices for
each kind of identifier. That is, indices are ordered by putting function
address identifiers first, followed by global address identifiers, followed by
parameter identifiers, followed by constant identifiers, and lastly instruction
value identifiers.</p>
<p>To save space in the encoded bitcode file, most operands are encoded using a
<a class="reference internal" href="#link-for-relative-index"><em>relative index</em></a> value, rather than
<a class="reference internal" href="#link-for-absolute-index-section"><em>absolute</em></a>. This
is done because most instruction operands refer to values defined earlier in the
(same) basic block. As a result, the relative distance (back) from the next
value defining instruction is frequently a small number. Small numbers tend to
require fewer bits when they are converted to bit sequences.</p>
<p>Note that instructions that can appear in a function block are defined in
sections <a class="reference internal" href="#link-for-terminator-instruction-section"><em>Terminator Instructions</em></a>,
<a class="reference internal" href="#link-for-integer-binary-instructions"><em>Integer Binary Instructions</em></a>,
<a class="reference internal" href="#link-for-floating-point-binary-instructions"><em>Floating Point Binary Instructions</em></a>,
<a class="reference internal" href="#link-for-memory-creation-and-access-instructions"><em>Memory Creation and Access Instructions</em></a>,
<a class="reference internal" href="#link-for-conversion-instructions"><em>Conversion Instructions</em></a>, <a class="reference internal" href="#link-for-compare-instructions"><em>Comparison Instructions</em></a>,
<a class="reference internal" href="#link-for-vector-instructions"><em>Vector Instructions</em></a>, and
<a class="reference internal" href="#link-for-other-pnaclasm-instructions"><em>Other Instructions</em></a>.</p>
<p>The following subsections define the remaining records that can appear in a
function block.</p>
<h3 id="function-enter">Function Enter</h3>
<p>PNaClAsm defines a function enter block construct. The corresponding record is
simply an <a class="reference internal" href="#link-for-enter-block-record-section"><em>enter block</em></a> record, with
BlockID value <code>12</code>. All context about the defining address is implicit by the
position of the function block, and the corresponding defining <a class="reference internal" href="#link-for-function-address-section"><em>function
address</em></a>. To improve readability, PNaClAsm
includes the function signature into the syntax rule.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
function TR @fN ( T0 %p0, ... , TM %pM ) { <B>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
1: <65535, 12, B>
</pre>
<p><strong>Semantics</strong>:</p>
<p><code>B</code> is the number of bits reserved for abbreviations in the block. If it is
omitted, 2 is assumed. See <a class="reference internal" href="#link-for-enter-block-record-section"><em>enter</em></a>
block records for more details.</p>
<p>The value of <code>N</code> corresponds to the positional index of the corresponding
defining function address this block is associated with. <code>M</code> is the number of
defined parameters (minus one) in the function heading.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
N == NumFcnImpls &
@fN in DefiningFcnIDs &
TypeOfFcn(@fN) == TypeOf(TypeID(TR (T0, ... , TM)))
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumFcnImpls;
EnclosingFcnID = @fN;
NumBasicBlocks = 0;
ExpectedBlocks = 0;
NumParams = M;
for I in [0..M]:
TypeOf(%pI) = TypeOf(TypeID(TI));
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <2> | @t1 = void;
55:4| 3: <21, 0, 1> | @t2 = void ();
58:6| 3: <21, 0, 0, 0> | @t3 = i32 (i32);
62:6| 0: <65534> | }
...
104:0| 1: <65535, 12, 2> | function void @f0() {
| | // BlockID = 12
112:0| 3: <1, 1> | blocks 1;
| | %b0:
114:4| 3: <10> | ret void;
116:2| 0: <65534> | }
120:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) {
| | // BlockID = 12
128:0| 3: <1, 1> | blocks 1;
| | %b0:
130:4| 3: <10, 1> | ret i32 %p0;
133:0| 0: <65534> | }
</pre>
<h3 id="link-for-basic-blocks-count"><span id="id3"></span>Count Record</h3>
<p>The count record, within a function block, defines the number of basic blocks
used to define the function implementation. It must be the first record in the
function block.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
blocks: N; <A>
%b0:
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <1, N>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The count record defines the number <code>N</code> of basic blocks in the implemented
function.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
ExpectedBasicBlocks == N &
NumBasicBlocks == 0
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
104:0| 1: <65535, 12, 2> | function void @f0() {
| | // BlockID = 12
112:0| 3: <1, 1> | blocks 1;
| | %b0:
114:4| 3: <10> | ret void;
116:2| 0: <65534> | }
120:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) {
| | // BlockID = 12
128:0| 3: <1, 1> | blocks 1;
| | %b0:
130:4| 3: <10, 1> | ret i32 %p0;
133:0| 0: <65534> | }
</pre>
<h2 id="terminator-instructions"><span id="link-for-terminator-instruction-section"></span>Terminator Instructions</h2>
<p>Terminator instructions are instructions that appear in a <a class="reference internal" href="#link-for-function-blocks-section"><em>function
block</em></a>, and define the end of the current
basic block. A terminator instruction indicates which block should be executed
after the current block is finished. The function block is well formed only if
the number of terminator instructions, in the function block, corresponds to the
value defined by the corresponding function basic block <a class="reference internal" href="#link-for-basic-blocks-count"><em>count
record</em></a>.</p>
<p>Note that any branch instruction to label <code>%bN</code>, where <code>N >=
ExpectedBasicBlocks</code>, is illegal. For ease of readability, this constraint
hasn’t been put on branch instructions. Rather it is only implied.</p>
<p>In addition, it must be the case that <code>NumBasicBlocks < ExpectedBasicBlocks</code>,
and will not be listed as a constraint. Further, if <code>B = NumBasicBlocks + 1</code>
is the number associated with the next basic block. Label <cite>%bB:</cite> only appears
if:</p>
<pre class="prettyprint">
B < ExpectedBasicBlocks
</pre>
<p>That is, the label is omitted only if this terminator instruction is the last
instruction in the function block.</p>
<h3 id="return-void-instruction">Return Void Instruction</h3>
<p>The return void instruction is used to return control from a function back to
the caller, without returning any value.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
ret void; <A>
%bB:
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <10>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The return void instruction returns control to the calling function.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
B == NumBasicBlocks + 1 &
ReturnType(TypeOf(EnclosingFcnID)) == void
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumBasicBlocks;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
104:0| 1: <65535, 12, 2> | function void @f0() {
| | // BlockID = 12
112:0| 3: <1, 1> | blocks 1;
| | %b0:
114:4| 3: <10> | ret void;
116:2| 0: <65534> | }
</pre>
<h3 id="return-value-instruction">Return Value Instruction</h3>
<p>The return value instruction is used to return control from a function back to
the caller, including a value. The value must correspond to the return type of
the enclosing function.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
ret T V; <A>
%bB:
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <10, VV>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The return value instruction returns control to the calling function, returning
the provided value.</p>
<p><code>V</code> is the value to return. Type <code>T</code> must be of the type returned by the
function. It must also be the type associated with value <code>V</code>.</p>
<p>The return type <code>T</code> must either be a (non-void) primitive type, or a vector
type. If the function block is implementing an ordinary function, and the return
type is an integer type, it must be either <code>i32</code> or <code>i64</code>.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV == RelativeIndex(V) &
B == NumBasicBlocks + 1 &
T == TypeOf(V) == ReturnType(TypeOf(EnclosingFcnID))
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumBasicBlocks;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
120:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) {
| | // BlockID = 12
128:0| 3: <1, 1> | blocks 1;
| | %b0:
130:4| 3: <10, 1> | ret i32 %p0;
</pre>
<h3 id="unconditional-branch-instruction">Unconditional Branch Instruction</h3>
<p>The unconditional branch instruction is used to cause control flow to transfer
to a different basic block of the function.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
br %bN; <A>
%bB:
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <11, N>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The unconditional branch instruction causes control flow to transfer to basic
block <code>N</code>.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
B == NumBasicBlocks + 1 &
0 < N &
N < ExpectedBasicBlocks
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumBasicBlocks;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
88:0| 1: <65535, 12, 2> | function void @f0() {
| | // BlockID = 12
96:0| 3: <1, 5> | blocks 5;
| | %b0:
98:4| 3: <11, 3> | br label %b3;
| | %b1:
101:0| 3: <11, 4> | br label %b4;
| | %b2:
103:4| 3: <11, 1> | br label %b1;
| | %b3:
106:0| 3: <11, 2> | br label %b2;
| | %b4:
108:4| 3: <10> | ret void;
110:2| 0: <65534> | }
</pre>
<h3 id="conditional-branch-instruction">Conditional Branch Instruction</h3>
<p>The conditional branch instruction is used to cause control flow to transfer to
a different basic block of the function, based on a boolean test condition.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
br i1 C, %bT, %bBF; <A>
%bB:
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <11, T, F, CC>
</pre>
<p><strong>Semantics</strong>:</p>
<p>Upon execution of a conditional branch instruction, the <em>i1</em> (boolean) argument
<code>C</code> is evaluated. If the value is <code>true</code>, control flows to basic block
<code>%bT</code>. Otherwise control flows to basic block <code>%bF</code>.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
CC == RelativeIndex(C) &
B == NumBasicBlocks + 1 &
0 < T &
B1 < ExpectedBasicBlocks &
0 < F &
B2 < ExpectedBasicBlocks &
TypeOf(C) == i1
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumBasicBlocks;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
92:0| 1: <65535, 12, 2> | function void @f0() {
| | // BlockID = 12
100:0| 3: <1, 5> | blocks 5;
102:4| 1: <65535, 11, 2> | constants { // BlockID = 11
112:0| 3: <1, 1> | i1:
114:4| 3: <4, 3> | %c0 = i1 1;
117:0| 3: <4, 0> | %c1 = i1 0;
119:4| 0: <65534> | }
| | %b0:
120:0| 3: <11, 3> | br label %b3;
| | %b1:
122:4| 3: <11, 2, 4, 2> | br i1 %c0, label %b2, label %b4;
| | %b2:
126:4| 3: <11, 3> | br label %b3;
| | %b3:
129:0| 3: <10> | ret void;
| | %b4:
130:6| 3: <11, 2, 3, 1> | br i1 %c1, label %b2, label %b3;
134:6| 0: <65534> | }
</pre>
<h3 id="unreachable">Unreachable</h3>
<p>The unreachable instruction has no defined semantics. The instruction is used to
inform the <a class="reference internal" href="/native-client/overview.html#link-for-pnacl-translator"><em>PNaCl translator</em></a> that control
can’t reach this instruction.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
unreachable; <A>
%bB:
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <15>
</pre>
<p><strong>Semantics</strong>:</p>
<p>Directive to the <a class="reference internal" href="/native-client/overview.html#link-for-pnacl-translator"><em>PNaCl translator</em></a> that
this instruction is unreachable.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A)
B == NumBasicBlocks + 1 &
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumBasicBlocks;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
108:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
| | // BlockID = 12
116:0| 3: <1, 5> | blocks 5;
118:4| 1: <65535, 11, 2> | constants { // BlockID = 11
128:0| 3: <1, 2> | i1:
130:4| 3: <4, 3> | %c0 = i1 1;
133:0| 3: <4, 0> | %c1 = i1 0;
135:4| 0: <65534> | }
| | %b0:
136:0| 3: <11, 1, 2, 2> | br i1 %c0, label %b1, label %b2;
| | %b1:
140:0| 3: <11, 3, 4, 1> | br i1 %c1, label %b3, label %b4;
| | %b2:
144:0| 3: <15> | unreachable;
| | %b3:
145:6| 3: <15> | unreachable;
| | %b4:
147:4| 3: <10> | ret void;
149:2| 0: <65534> | }
</pre>
<h3 id="switch-instruction">Switch Instruction</h3>
<p>The <em>switch</em> instruction transfers control flow to one of several different
places, based on a selector value. It is a generalization of the conditional
branch instruction.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
switch T V0 {
default: br label %bB0;
T V1: br label %bB1;
...
T VN: br label %bBN;
} <A>
%bB:
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <12, TT, B0, N, (1, 1, VVI, BI | 1 <= i <= N)>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The switch instruction transfers control to a basic block in <code>B0</code> through
<code>BN</code>. Value <code>V</code> is used to conditionally select which block to branch
to. <code>T</code> is the type of <code>V</code> and <code>V1</code> through <code>VN</code>, and must be an integer
type. Value <code>V1</code> through <code>VN</code> are integers to compare against <code>V</code>. If
selector <code>V</code> matches <code>VI</code> (for some <code>I</code>, <code>1 <= I <= N</code>), then the
instruction branches to block <code>BI</code>. If <code>V</code> is not in <code>V1</code> through <code>VN</code>,
the instruction branches to block <code>B0</code>.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
B == NumBasicBlocks + 1 &
TT == TypeID(T) &
VI == SignRotate(VI) for all I, 1 <= I <= N &
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumBasicBlocks;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
116:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
| | // BlockID = 12
124:0| 3: <1, 6> | blocks 6;
| | %b0:
126:4| 3: <12, 1, 1, 2, 4, 1, 1,| switch i32 %p0 {
| 2, 3, 1, 1, 4, 3, 1, | default: br label %b2;
| 1, 8, 4, 1, 1, 10, 4>| i32 1: br label %b3;
| | i32 2: br label %b3;
| | i32 4: br label %b4;
| | i32 5: br label %b4;
| | }
| | %b1:
143:2| 3: <11, 5> | br label %b5;
| | %b2:
145:6| 3: <11, 5> | br label %b5;
| | %b3:
148:2| 3: <11, 5> | br label %b5;
| | %b4:
150:6| 3: <11, 5> | br label %b5;
| | %b5:
153:2| 3: <10> | ret void;
155:0| 0: <65534> | }
156:0| 1: <65535, 12, 2> | function void @f1(i64 %p0) {
| | // BlockID = 12
164:0| 3: <1, 6> | blocks 6;
| | %b0:
166:4| 3: <12, 2, 1, 2, 4, 1, 1,| switch i64 %p0 {
| 2, 3, 1, 1, 4, 3, 1, | default: br label %b2;
| 1, 8, 4, 1, 1, | i64 1: br label %b3;
| 39777555332, 4> | i64 2: br label %b3;
| | i64 4: br label %b4;
| | i64 19888777666: br label %b4;
| | }
| | %b1:
188:4| 3: <11, 5> | br label %b5;
| | %b2:
191:0| 3: <11, 5> | br label %b5;
| | %b3:
193:4| 3: <11, 5> | br label %b5;
| | %b4:
196:0| 3: <11, 5> | br label %b5;
| | %b5:
198:4| 3: <10> | ret void;
200:2| 0: <65534> | }
</pre>
<h2 id="integer-binary-instructions"><span id="link-for-integer-binary-instructions"></span>Integer Binary Instructions</h2>
<p>Binary instructions are used to do most of the computation in a program. This
section focuses on binary instructions that operator on integer values, or
vectors of integer values.</p>
<p>All binary operations require two operands of the same type, execute an
operation on them, and produce a value. The value may represent multiple values
if the type is a vector type. The result value always has the same type as its
operands.</p>
<p>Some integer binary operations can be applied to both signed and unsigned
integers. Others, the sign is significant. In general, if the sign plays a role
in the instruction, the sign information is encoded into the name of the
instruction.</p>
<p>For most binary operations (except some of the logical operations), integer
type i1 is disallowed.</p>
<h3 id="integer-add">Integer Add</h3>
<p>The integer add instruction returns the sum of its two arguments. Both arguments
and the result must be of the same type. That type must be integer, or an
integer vector type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = add T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 0>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The integer add instruction returns the sum of its two arguments. Arguments
<code>V1</code> and <code>V2</code>, and the result <code>%vN</code>, must be of type <code>T</code>. <code>T</code> must be
an integer type, or an integer vector type. <code>N</code> is defined by the record
position, defining the corresponding value generated by the instruction.</p>
<p>The result returned is the mathematical result modulo 2<sup>n</sup>, where <code>n</code>
is the bit width of the integer result.</p>
<p>Because integers are assumed to use a two’s complement representation,
this instruction is appropriate for both signed and unsigned integers.</p>
<p>In the add instruction, integer type <code>i1</code> (and a vector of integer type
<code>i1</code>) is disallowed.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsInteger(UnderlyingType(T)) &
UnderlyingType(T) != i1 &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <2, 2, 1, 0> | %v0 = add i32 %p0, %p1;
110:4| 3: <2, 3, 1, 0> | %v1 = add i32 %p0, %v0;
114:4| 3: <10, 1> | ret i32 %v1;
117:0| 0: <65534> | }
</pre>
<h3 id="integer-subtract">Integer Subtract</h3>
<p>The integer subtract instruction returns the difference of its two arguments.
Both arguments and the result must be of the same type. That type must be
integer, or an integer vector type.</p>
<p>Note: Since there isn’t a negate instruction, subtraction from constant zero
should be used to negate values.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = sub T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 1>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The integer subtract returns the difference of its two arguments. Arguments
<code>V1</code> and <code>V2</code>, and the result <code>%vN</code> must be of type <code>T</code>. <code>T</code> must be
an integer type, or an integer vector type. <code>N</code> is defined by the record
position, defining the corresponding value generated by the instruction.</p>
<p>The result returned is the mathematical result modulo 2<sup>n</sup>, where <code>n</code>
is the bit width of the integer result.</p>
<p>Because integers are assumed to use a two’s complement representation,
this instruction is appropriate for both signed and unsigned integers.</p>
<p>In the subtract instruction, integer type <code>i1</code> (and a vector of integer type
<code>i1</code>) is disallowed.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsInteger(UnderlyingType(T)) &
UnderlyingType(T) != i1 &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <2, 2, 1, 1> | %v0 = sub i32 %p0, %p1;
110:4| 3: <2, 3, 1, 1> | %v1 = sub i32 %p0, %v0;
114:4| 3: <10, 1> | ret i32 %v1;
117:0| 0: <65534> | }
</pre>
<h3 id="integer-multiply">Integer Multiply</h3>
<p>The integer multiply instruction returns the product of its two arguments. Both
arguments and the result must be of the same type. That type must be integer,
or an integer based vector type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
&vN = mul T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 2>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The integer multiply instruction returns the product of its two
arguments. Arguments <code>V1</code> and <code>V2</code>, and the result <code>%vN</code>, must be of type
<code>T</code>. <code>T</code> must be an integer type, or an integer vector type. <code>N</code> is
defined by the record position, defining the corresponding value generated by
the instruction.</p>
<p>The result returned is the mathematical result modulo 2<sup>n</sup>, where <code>n</code>
is the bit width of the integer result.</p>
<p>Because integers are assumed to use a two’s complement representation,
this instruction is appropriate for both signed and unsigned integers.</p>
<p>In the subtract instruction, integer type <code>i1</code> (or a vector on integer type
<code>i1</code>) is disallowed.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsInteger(UnderlyingType(T)) &
UnderlyingType(T) != i1 &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <2, 2, 1, 2> | %v0 = mul i32 %p0, %p1;
110:4| 3: <2, 1, 3, 2> | %v1 = mul i32 %v0, %p0;
114:4| 3: <10, 1> | ret i32 %v1;
117:0| 0: <65534> | }
</pre>
<h3 id="signed-integer-divide">Signed Integer Divide</h3>
<p>The signed integer divide instruction returns the quotient of its two arguments.
Both arguments and the result must be of the same type. That type must be
integer, or an integer vector type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = sdiv T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 4>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The signed integer divide instruction returns the quotient of its two
arguments. Arguments <code>V1</code> and <code>V2</code>, and the result <code>%vN</code>, must be of type
<code>T</code>. <code>T</code> must be a integer type, or an integer vector type. <code>N</code> is defined
by the record position, defining the corresponding value generated by the
instruction.</p>
<p>Signed values are assumed. Note that signed and unsigned integer division are
distinct operations. For unsigned integer division use the unsigned integer
divide instruction (udiv).</p>
<p>In the signed integer divide instruction, integer type <code>i1</code> (and a vector of
integer type <code>i1</code>) is disallowed. Integer division by zero is guaranteed to
trap.</p>
<p>Note that overflow can happen with this instruction when dividing the maximum
negative integer by <code>-1</code>. The behavior for this case is currently undefined.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsInteger(UnderlyingType(T)) &
UnderlyingType(T) != i1 &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <2, 2, 1, 4> | %v0 = sdiv i32 %p0, %p1;
110:4| 3: <2, 1, 2, 4> | %v1 = sdiv i32 %v0, %p1;
114:4| 3: <10, 1> | ret i32 %v1;
117:0| 0: <65534> | }
</pre>
<h3 id="unsigned-integer-divide">Unsigned Integer Divide</h3>
<p>The unsigned integer divide instruction returns the quotient of its two
arguments. Both the arguments and the result must be of the same type. That type
must be integer, or an integer vector type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = udiv T V1, V2; <a>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, A1, A2, 3>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The unsigned integer divide instruction returns the quotient of its two
arguments. Arguments <code>V1</code> and <code>V2</code>, and the result <code>%vN</code>, must be of type
<code>T</code>. <code>T</code> must be an integer type, or an integer vector type. <code>N</code> is
defined by the record position, defining the corresponding value generated by
the instruction.</p>
<p>Unsigned integer values are assumed. Note that signed and unsigned integer
division are distinct operations. For signed integer division use the signed
integer divide instruction (sdiv).</p>
<p>In the unsigned integer divide instruction, integer type <code>i1</code> (and a vector of
integer type <code>i1</code>) is disallowed. Division by zero is guaranteed to trap.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsInteger(UnderlyingType(T)) &
UnderlyingType(T) != i1 &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <2, 2, 1, 3> | %v0 = udiv i32 %p0, %p1;
110:4| 3: <2, 1, 2, 3> | %v1 = udiv i32 %v0, %p1;
114:4| 3: <10, 1> | ret i32 %v1;
117:0| 0: <65534> | }
</pre>
<h3 id="signed-integer-remainder">Signed Integer Remainder</h3>
<p>The signed integer remainder instruction returns the remainder of the quotient
of its two arguments. Both arguments and the result must be of the same
type. That type must be integer, or an integer based vector type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = srem T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 6>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The signed integer remainder instruction returns the remainder of the quotient
of its two arguments. Arguments <code>V1</code> and <code>V2</code>, and the result <code>%vN</code>, must
be of type <code>T</code>. <code>T</code> must be a integer type, or an integer vector type. <code>N</code>
is defined by the record position, defining the corresponding value generated by
the instruction.</p>
<p>Signed values are assumed. Note that signed and unsigned integer division are
distinct operations. For unsigned integer division use the unsigned integer
remainder instruction (urem).</p>
<p>In the signed integer remainder instruction, integer type <code>i1</code> (and a vector
of integer type <code>i1</code>) is disallowed. Division by zero is guaranteed to trap.</p>
<p>Note that overflow can happen with this instruction when dividing the maximum
negative integer by <code>-1</code>. The behavior for this case is currently undefined.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsInteger(UnderlyingType(T)) &
UnderlyingType(T) != i1 &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <2, 2, 1, 6> | %v0 = srem i32 %p0, %p1;
110:4| 3: <2, 1, 2, 6> | %v1 = srem i32 %v0, %p1;
114:4| 3: <10, 1> | ret i32 %v1;
117:0| 0: <65534> | }
</pre>
<h3 id="unsigned-integer-remainder-instruction">Unsigned Integer Remainder Instruction</h3>
<p>The unsigned integer remainder instruction returns the remainder of the quotient
of its two arguments. Both the arguments and the result must be of the same
type. The type must be integer, or an integer vector type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = urem T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, A1, A2, 5>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The unsigned integer remainder instruction returns the remainder of the quotient
of its two arguments. Arguments <code>V1</code> and <code>V2</code>, and the result <code>%vN</code>, must
be of type <code>T</code>. <code>T</code> must be an integer type, or an integer vector type.
<code>N</code> is defined by the record position, defining the corresponding value
generated by the instruction.</p>
<p>Unsigned values are assumed. Note that signed and unsigned integer division are
distinct operations. For signed integer division use the remainder instruction
(srem).</p>
<p>In the unsigned integer remainder instruction, integer type <code>i1</code> (and a vector
of integer type <code>i1</code>) is disallowed. Division by zero is guaranteed to trap.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsInteger(UnderlyingType(T)) &
UnderlyingType(T) != i1 &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <2, 2, 1, 5> | %v0 = urem i32 %p0, %p1;
110:4| 3: <2, 1, 2, 5> | %v1 = urem i32 %v0, %p1;
114:4| 3: <10, 1> | ret i32 %v1;
117:0| 0: <65534> | }
</pre>
<h3 id="shift-left">Shift Left</h3>
<p>The (integer) shift left instruction returns the first operand, shifted to the
left a specified number of bits with zero fill. The shifted value must be
integer, or an integer vector type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = shl T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 7>
</pre>
<p><strong>Semantics</strong>:</p>
<p>This instruction performs a shift left operation. Arguments <code>V1</code> and <code>V2</code>
and the result <code>%vN</code> must be of type <code>T</code>. <code>T</code> must be an integer, or a
vector of integers. <code>N</code> is defined by the record position, defining the
corresponding value generated by the instruction.</p>
<p><code>V2</code> is assumed to be unsigned. The least significant bits of the result will
be filled with zero bits after the shift. If <code>V2</code> is (statically or
dynamically) negative or equal to or larger than the number of bits in
<code>V1</code>, the result is undefined. If the arguments are vectors, each vector
element of <code>V1</code> is shifted by the corresponding shift amount in <code>V2</code>.</p>
<p>In the shift left instruction, integer type <code>i1</code> (and a vector of integer type
<code>i1</code>) is disallowed.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsInteger(UnderlyingType(T)) &
UnderlyingType(T) != i1 &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <2, 2, 1, 7> | %v0 = shl i32 %p0, %p1;
110:4| 3: <2, 1, 2, 7> | %v1 = shl i32 %v0, %p1;
114:4| 3: <10, 1> | ret i32 %v1;
117:0| 0: <65534> | }
</pre>
<h3 id="logical-shift-right">Logical Shift Right</h3>
<p>The logical shift right instruction returns the first operand, shifted to the
right a specified number of bits with zero fill.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = lshr T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 8>
</pre>
<p><strong>Semantics</strong>:</p>
<p>This instruction performs a logical shift right operation. Arguments <code>V1</code> and
<code>V2</code> and the result <code>%vN</code> must be of type <code>T</code>. <code>T</code> must be an integer,
or a vector of integers. <code>N</code> is defined by the record position, defining the
corresponding value generated by the instruction.</p>
<p><code>V2</code> is assumed to be unsigned. The most significant bits of the result will
be filled with zero bits after the shift. If <code>V2</code> is (statically or
dynamically) negative or equal to or larger than the number of bits in <code>V1</code>,
the result is undefined. If the arguments are vectors, each vector element of
<code>V1</code> is shifted by the corresponding shift amount in <code>V2</code>.</p>
<p>In the logical shift right instruction, integer type <code>i1</code> (and a vector of
integer type <code>i1</code>) is disallowed.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsInteger(UnderlyingType(T)) &
UnderlyingType(T) != i1 &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <2, 2, 1, 8> | %v0 = lshr i32 %p0, %p1;
110:4| 3: <2, 1, 2, 8> | %v1 = lshr i32 %v0, %p1;
114:4| 3: <10, 1> | ret i32 %v1;
117:0| 0: <65534> | }
</pre>
<h3 id="arithmetic-shift-right">Arithmetic Shift Right</h3>
<p>The arithmetic shift right instruction returns the first operand, shifted to the
right a specified number of bits with sign extension.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = ashr T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VVA2, 9>
</pre>
<p><strong>Semantics</strong>:</p>
<p>This instruction performs an arithmetic shift right operation. Arguments <code>V1</code>
and <code>V2</code> and and the result <code>%vN</code> must be of type <code>T</code>. <code>T</code> must be an
integer, or a vector of integers. <code>N</code> is defined by the record position,
defining the corresponding value generated by the instruction.</p>
<p><code>V2</code> is assumed to be unsigned. The most significant bits of the result will
be filled with the sign bit of <code>V1</code>. If <code>V2</code> is (statically or dynamically)
negative or equal to or larger than the number of bits in <code>V1</code>, the result is
undefined. If the arguments are vectors, each vector element of <code>V1</code> is
shifted by the corresponding shift amount in <code>V2</code>.</p>
<p>In the arithmetic shift right instruction, integer type <code>i1</code> (and a vector of
integral type <code>i1</code>) is disallowed.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsInteger(UnderlyingType(T)) &
UnderlyingType(T) != i1 &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <2, 2, 1, 9> | %v0 = ashr i32 %p0, %p1;
110:4| 3: <2, 1, 2, 9> | %v1 = ashr i32 %v0, %p1;
114:4| 3: <10, 1> | ret i32 %v1;
117:0| 0: <65534> | }
</pre>
<h3 id="logical-and">Logical And</h3>
<p>The <em>and</em> instruction returns the bitwise logical and of its two operands.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = and T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 10>
</pre>
<p><strong>Semantics</strong>:</p>
<p>This instruction performs a bitwise logical and of its arguments. Arguments
<code>V1</code> and <code>V2</code>, and the result <code>%vN</code> must be of type <code>T</code>. <code>T</code> must be
an integer, or a vector of integers. <code>N</code> is defined by the record position,
defining the corresponding value generated by the instruction. <code>A</code> is the
(optional) abbreviation associated with the corresponding record.</p>
<p>The truth table used for the <em>and</em> instruction is:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Arg 1</th>
<th class="head">Arg 2</th>
<th class="head">Result</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr class="row-odd"><td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr class="row-even"><td>1</td>
<td>0</td>
<td>0</td>
</tr>
<tr class="row-odd"><td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsInteger(UnderlyingType(T))) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <2, 2, 1, 10> | %v0 = and i32 %p0, %p1;
110:4| 3: <2, 1, 2, 10> | %v1 = and i32 %v0, %p1;
114:4| 3: <10, 1> | ret i32 %v1;
117:0| 0: <65534> | }
</pre>
<h3 id="logical-or">Logical Or</h3>
<p>The <em>or</em> instruction returns the bitwise logical inclusive or of its
two operands.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = or T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 11>
</pre>
<p><strong>Semantics</strong>:</p>
<p>This instruction performs a bitwise logical inclusive or of its arguments.
Arguments <code>V1</code> and <code>V2</code>, and the result <code>%vN</code> must be of type <code>T</code>. <code>T</code>
must be an integer, or a vector of integers. <code>N</code> is defined by the record
position, defining the corresponding value generated by the instruction.</p>
<p>The truth table used for the <em>or</em> instruction is:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Arg 1</th>
<th class="head">Arg 2</th>
<th class="head">Result</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr class="row-odd"><td>0</td>
<td>1</td>
<td>1</td>
</tr>
<tr class="row-even"><td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr class="row-odd"><td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsInteger(UnderlyingType(T))) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <2, 2, 1, 11> | %v0 = or i32 %p0, %p1;
110:4| 3: <2, 1, 2, 11> | %v1 = or i32 %v0, %p1;
114:4| 3: <10, 1> | ret i32 %v1;
117:0| 0: <65534> | }
</pre>
<h3 id="logical-xor">Logical Xor</h3>
<p>The <em>xor</em> instruction returns the bitwise logical exclusive or of its
two operands.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = xor T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 12>
</pre>
<p><strong>Semantics</strong>:</p>
<p>This instruction performs a bitwise logical exclusive or of its arguments.
Arguments <code>V1</code> and <code>V2</code>, and the result <code>%vN</code> must be of type <code>T</code>. <code>T</code>
must be an integer, or a vector of integers. <code>N</code> is defined by the record
position, defining the corresponding value generated by the instruction.</p>
<p>The truth table used for the <em>xor</em> instruction is:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Arg 1</th>
<th class="head">Arg 2</th>
<th class="head">Result</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr class="row-odd"><td>0</td>
<td>1</td>
<td>1</td>
</tr>
<tr class="row-even"><td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr class="row-odd"><td>1</td>
<td>1</td>
<td>0</td>
</tr>
</tbody>
</table>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
A1 == RelativeIndex(V1) &
A2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsInteger(UnderlyingType(T))) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <2, 2, 1, 12> | %v0 = xor i32 %p0, %p1;
110:4| 3: <2, 1, 2, 12> | %v1 = xor i32 %v0, %p1;
114:4| 3: <10, 1> | ret i32 %v1;
117:0| 0: <65534> | }
</pre>
<h2 id="floating-point-binary-instructions"><span id="link-for-floating-point-binary-instructions"></span>Floating Point Binary Instructions</h2>
<p>Floating point binary instructions require two operands of the same type,
execute an operation on them, and produce a value. The value may represent
multiple values if the type is a vector type. The result value always has the
same type as its operands.</p>
<h3 id="floating-point-add">Floating Point Add</h3>
<p>The floating point add instruction returns the sum of its two arguments. Both
arguments and the result must be of the same type. That type must be a floating
point type, or a vector of a floating point type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = fadd T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 0>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The floating point add instruction returns the sum of its two arguments.
Arguments <code>V1</code> and <code>V2</code> and the result <code>%vN</code> must be of type <code>T</code>. <code>T</code>
must be a floating point type, or a vector of a floating point type. <code>N</code> is
defined by the record position, defining the corresponding value generated by
the instruction.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsFloat(UnderlyingType(T)) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
92:0| 1: <65535, 12, 2> | function
| | float @f0(float %p0, float %p1) {
| | // BlockID = 12
100:0| 3: <1, 1> | blocks 1;
| | %b0:
102:4| 3: <2, 2, 1, 0> | %v0 = fadd float %p0, %p1;
106:4| 3: <2, 3, 1, 0> | %v1 = fadd float %p0, %v0;
110:4| 3: <10, 1> | ret float %v1;
113:0| 0: <65534> | }
</pre>
<h3 id="floating-point-subtract">Floating Point Subtract</h3>
<p>The floating point subtract instruction returns the difference of its two
arguments. Both arguments and the result must be of the same type. That type
must be a floating point type, or a vector of a floating point type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = fsub T V1, V2; <a>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 1>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The floating point subtract instruction returns the difference of its two
arguments. Arguments <code>V1</code> and <code>V2</code>, and the result <code>%vN</code> must be of type
<code>T</code>. <code>T</code> must be a floating point type, or a vector of a floating point
type. <code>N</code> is defined by the record position, defining the corresponding value
generated by the instruction.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsFloat(UnderlyingType(T)) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
92:0| 1: <65535, 12, 2> | function
| | float @f0(float %p0, float %p1) {
| | // BlockID = 12
100:0| 3: <1, 1> | blocks 1;
| | %b0:
102:4| 3: <2, 2, 1, 1> | %v0 = fsub float %p0, %p1;
106:4| 3: <2, 3, 1, 1> | %v1 = fsub float %p0, %v0;
110:4| 3: <10, 1> | ret float %v1;
113:0| 0: <65534> | }
</pre>
<h3 id="floating-point-multiply">Floating Point Multiply</h3>
<p>The floating point multiply instruction returns the product of its two
arguments. Both arguments and the result must be of the same type. That type
must be a floating point type, or a vector of a floating point type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
&vN = fmul T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 2>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The floating point multiply instruction returns the product of its two
arguments. Arguments <code>V1</code> and <code>V2</code>, and the result <code>%vN</code> must be of type
<code>T</code>. <code>T</code> must be a floating point type, or a vector of a floating point
type. <code>N</code> is defined by the record position, defining the corresponding value
generated by the instruction.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsFloat(UnderlyingType(T)) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
92:0| 1: <65535, 12, 2> | function
| | float @f0(float %p0, float %p1) {
| | // BlockID = 12
100:0| 3: <1, 1> | blocks 1;
| | %b0:
102:4| 3: <2, 2, 1, 2> | %v0 = fmul float %p0, %p1;
106:4| 3: <2, 3, 1, 2> | %v1 = fmul float %p0, %v0;
110:4| 3: <10, 1> | ret float %v1;
113:0| 0: <65534> | }
</pre>
<h3 id="floating-point-divide">Floating Point Divide</h3>
<p>The floating point divide instruction returns the quotient of its two
arguments. Both arguments and the result must be of the same type. That type
must be a floating point type, or a vector of a floating point type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = fdiv T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, V1, V2, 4>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The floating point divide instruction returns the quotient of its two
arguments. Arguments <code>V1</code> and <code>V2</code>, and the result <code>%vN</code> must be of type
<code>T</code>. <code>T</code> must be a floating point type, or a vector of a floating point
type. <code>N</code> is defined by the record position, defining the corresponding value
generated by the instruction.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV22 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsFloat(UnderlyingType(T)) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
92:0| 1: <65535, 12, 2> | function
| | double
| | @f0(double %p0, double %p1) {
| | // BlockID = 12
100:0| 3: <1, 1> | blocks 1;
| | %b0:
102:4| 3: <2, 2, 1, 4> | %v0 = fdiv double %p0, %p1;
106:4| 3: <2, 3, 1, 4> | %v1 = fdiv double %p0, %v0;
110:4| 3: <10, 1> | ret double %v1;
113:0| 0: <65534> | }
</pre>
<h3 id="floating-point-remainder">Floating Point Remainder</h3>
<p>The floating point remainder instruction returns the remainder of the quotient
of its two arguments. Both arguments and the result must be of the same
type. That type must be a floating point type, or a vector of a floating point
type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = frem T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <2, VV1, VV2, 6>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The floating point remainder instruction returns the remainder of the quotient
of its two arguments. Arguments <code>V1</code> and <code>V2</code>, and the result <code>%vN</code> must
be of type <code>T</code>. <code>T</code> must be a floating point type, or a vector of a floating
point type. <code>N</code> is defined by the record position, defining the corresponding
value generated by the instruction.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
IsFloat(UnderlyingType(T)) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
92:0| 1: <65535, 12, 2> | function
| | double
| | @f0(double %p0, double %p1) {
| | // BlockID = 12
100:0| 3: <1, 1> | blocks 1;
| | %b0:
102:4| 3: <2, 2, 1, 6> | %v0 = frem double %p0, %p1;
106:4| 3: <2, 3, 1, 6> | %v1 = frem double %p0, %v0;
110:4| 3: <10, 1> | ret double %v1;
113:0| 0: <65534> | }
</pre>
<h2 id="memory-creation-and-access-instructions"><span id="link-for-memory-creation-and-access-instructions"></span>Memory Creation and Access Instructions</h2>
<p>A key design point of SSA-based representation is how it represents
memory. In PNaCl bitcode files, no memory locations are in SSA
form. This makes things very simple.</p>
<h3 id="alloca-instruction"><span id="link-for-alloca-instruction"></span>Alloca Instruction</h3>
<p>The <em>alloca</em> instruction allocates memory on the stack frame of the
currently executing function. This memory is automatically released
when the function returns to its caller.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = alloca i8, i32 S, align V; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <19, SS, VV>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The <em>alloca</em> instruction allocates memory on the stack frame of the currently
executing function. The resulting value is a pointer to the allocated memory
(i.e. of type i32). <code>S</code> is the number of bytes that are allocated on the
stack. <code>S</code> must be of integer type i32. <code>V</code> is the alignment of the
generated stack address.</p>
<p>Alignment must be a power of 2. See <a class="reference internal" href="#link-for-memory-blocks-and-alignment-section"><em>memory blocks and
alignment</em></a> for a more detailed
discussion on how to define alignment.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
VV == Log2(V+1) &
SS == RelativeIndex(S) &
i32 == TypeOf(S) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = i32;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
112:0| 1: <65535, 12, 2> | function void @f1() {
| | // BlockID = 12
120:0| 3: <1, 1> | blocks 1;
122:4| 1: <65535, 11, 2> | constants { // BlockID = 11
132:0| 3: <1, 0> | i32:
134:4| 3: <4, 4> | %c0 = i32 2;
137:0| 3: <4, 8> | %c1 = i32 4;
139:4| 3: <4, 16> | %c2 = i32 8;
142:0| 0: <65534> | }
| | %b0:
144:0| 3: <19, 3, 1> | %v0 = alloca i8, i32 %c0, align 1;
147:2| 3: <19, 3, 3> | %v1 = alloca i8, i32 %c1, align 4;
150:4| 3: <19, 3, 4> | %v2 = alloca i8, i32 %c2, align 8;
153:6| 3: <10> | ret void;
155:4| 0: <65534> | }
</pre>
<h3 id="load-instruction">Load Instruction</h3>
<p>The <em>load</em> instruction is used to read from memory.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = load T* P, align V; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <20, PP, VV, TT>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The load instruction is used to read from memory. <code>P</code> is the identifier of the
memory address to read. The type of <code>P</code> must be an <code>i32</code>. <code>T</code> is the type
of value to read. <code>V</code> is the alignment of the memory address.</p>
<p>Type <code>T</code> must be a vector, integer, or floating point type. Both <code>float</code> and
<code>double</code> types are allowed for floating point types. All integer types except
i1 are allowed.</p>
<p>Alignment must be a power of 2. See <a class="reference internal" href="#link-for-memory-blocks-and-alignment-section"><em>memory blocks and
alignment</em></a> for a more detailed
discussion on how to define alignment.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
i32 == TypeOf(P) &
PP == RelativeIndex(P) &
VV == Log2(V+1) &
%tTT == TypeID(T) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <2> | @t1 = void;
55:4| 3: <4> | @t2 = double;
57:2| 3: <21, 0, 1, 0> | @t3 = void (i32);
61:2| 0: <65534> | }
...
96:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <20, 1, 1, 0> | %v0 = load i32* %p0, align 1;
110:4| 3: <20, 1, 4, 2> | %v1 = load double* %v0, align 8;
114:4| 3: <10> | ret void;
116:2| 0: <65534> | }
</pre>
<h3 id="store-instruction">Store Instruction</h3>
<p>The <em>store</em> instruction is used to write to memory.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
store T S, T* P, align V; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <24, PP, SS, VV>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The store instruction is used to write to memory. <code>P</code> is the identifier of the
memory address to write to. The type of <code>P</code> must be an i32 integer. <code>T</code> is
the type of value to store. <code>S</code> is the value to store, and must be of type
<code>T</code>. <code>V</code> is the alignment of the memory address. <code>A</code> is the (optional)
abbreviation index associated with the record.</p>
<p>Type <code>T</code> must be an integer or floating point type. Both <code>float</code> and
<code>double</code> types are allowed for floating point types. All integer types except
i1 are allowed.</p>
<p>Alignment must be a power of 2. See <a class="reference internal" href="#link-for-memory-blocks-and-alignment-section"><em>memory blocks and
alignment</em></a> for a more detailed
discussion on how to define alignment.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
i32 == TypeOf(P) &
PP == RelativeIndex(P) &
VV == Log2(V+1)
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <2> | @t1 = void;
55:4| 3: <4> | @t2 = double;
57:2| 3: <21, 0, 1, 0, 0, 0, 2>| @t3 = void (i32, i32, i32, double);
63:4| 0: <65534> | }
...
96:0| 1: <65535, 12, 2> | function
| | void
| | @f0(i32 %p0, i32 %p1, i32 %p2,
| | double %p3) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
| | %b0:
106:4| 3: <24, 4, 3, 1> | store i32 %p1, i32* %p0, align 1;
110:4| 3: <24, 2, 1, 4> | store double %p3, double* %p2,
| | align 8;
114:4| 3: <10> | ret void;
116:2| 0: <65534> | }
</pre>
<h2 id="conversion-instructions"><span id="link-for-conversion-instructions"></span>Conversion Instructions</h2>
<p>Conversion instructions all take a single operand and a type. The value is
converted to the corresponding type.</p>
<h3 id="integer-truncating-instruction">Integer Truncating Instruction</h3>
<p>The integer truncating instruction takes a value to truncate, and a type
defining the truncated type. Both types must be integer types, or integer
vectors with the same number of elements. The bit size of the value must be
larger than the bit size of the destination type. Equal sized types are not
allowed.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = trunc T1 V to T2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <3, VV, TT2, 0>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The integer truncating instruction takes a value <code>V</code>, and truncates to type
<code>T2</code>. Both <code>T1</code> and <code>T2</code> must be integer types, or integer vectors with
the same number of elements. <code>T1</code> has to be wider than <code>T2</code>. If the value
doesn’t fit in in <code>T2</code>, then the higher order bits are dropped.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
TypeOf(V) == T1 &
VV == RelativeIndex(V) &
%tTT2 == TypeID(T2) &
BitSizeOf(UnderlyingType(T1)) > BitSizeOf(UnderlyingType(T2)) &
UnderlyingCount(T1) == UnderlyingCount(T2) &
IsInteger(UnderlyingType(T1)) &
IsInteger(UnderlyingType(T2)) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T2;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 5> | count 5;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <2> | @t1 = void;
55:4| 3: <7, 16> | @t2 = i16;
58:0| 3: <21, 0, 1, 0> | @t3 = void (i32);
62:0| 3: <7, 8> | @t4 = i8;
64:4| 0: <65534> | }
...
100:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
| | // BlockID = 12
108:0| 3: <1, 1> | blocks 1;
| | %b0:
110:4| 3: <3, 1, 2, 0> | %v0 = trunc i32 %p0 to i16;
114:4| 3: <3, 1, 4, 0> | %v1 = trunc i16 %v0 to i8;
118:4| 3: <10> | ret void;
120:2| 0: <65534> | }
</pre>
<h3 id="floating-point-truncating-instruction">Floating Point Truncating Instruction</h3>
<p>The floating point truncating instruction takes a value to truncate, and a type
defining the truncated type. Both types must be floating point types, or
floating point vectors with the same number of elements. The source must be
<code>double</code> while the destination is <code>float</code>. If the source is a vector, the
destination must also be vector with the same size as the source.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = fptrunc T1 V to T2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <3, VV, TT2, 7>
</pre>
<p><strong>Semantics</strong></p>
<p>The floating point truncating instruction takes a value <code>V</code>, and truncates to
type <code>T2</code>. Both <code>T1</code> and <code>T2</code> must be floating point types, or floating
point vectors with the same number of elements. <code>T1</code> must be defined on
<code>double</code> while <code>T2</code> is defined on <code>float</code>. If the value can’t fit within
the destination type <code>T2</code>, the results are undefined.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
TypeOf(V) == T1 &
double == UnderlyingType(T1) &
float == UnderlyingType(T2) &
VV == RelativeIndex(V) &
%tTT2 == TypeID(T2) &
BitSizeOf(UnderlyingType(T1)) > BitSizeOf(UnderlyingType(T2)) &
UnderlyingCount(T1) == UnderlyingCount(T2) &
IsFloat(UnderlyingType(T1)) &
IsFloat(UnderlyingType(T2)) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T2;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <3> | @t0 = float;
52:2| 3: <4> | @t1 = double;
54:0| 3: <21, 0, 0, 1> | @t2 = float (double);
58:0| 3: <2> | @t3 = void;
59:6| 0: <65534> | }
...
92:0| 1: <65535, 12, 2> | function float @f0(double %p0) {
| | // BlockID = 12
100:0| 3: <1, 1> | blocks 1;
| | %b0:
102:4| 3: <3, 1, 0, 7> | %v0 = fptrunc double %p0 to float;
106:4| 3: <10, 1> | ret float %v0;
109:0| 0: <65534> | }
</pre>
<h3 id="zero-extending-instruction">Zero Extending Instruction</h3>
<p>The zero extending instruction takes a value to extend, and a type to extend it
to. Both types must be integer types, or integer vectors with the same number
of elements. The bit size of the source type must be smaller than the bit size
of the destination type. Equal sized types are not allowed.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = zext T1 V to T2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <3, VV, TT2, 1>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The zero extending instruction takes a value <code>V</code>, and expands it to type
<code>T2</code>. Both <code>T1</code> and <code>T2</code> must be integer types, or integer vectors with
the same number of elements. <code>T2</code> must be wider than <code>T1</code>.</p>
<p>The instruction fills the high order bits of the value with zero bits until it
reaches the size of the destination type. When zero extending from i1, the
result will always be either 0 or 1.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
TypeOf(V) == T1 &
VV == RelativeIndex(V) &
%tTT2 == TypeID(T2) &
BitSizeOf(UnderlyingType(T1)) < BitSizeOf(UnderlyingType(T2)) &
UnderlyingCount(T1) == UnderlyingCount(T2) &
IsInteger(UnderlyingType(T1)) &
IsInteger(UnderlyingType(T2)) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T2;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 5> | count 5;
50:4| 3: <7, 64> | @t0 = i64;
53:6| 3: <7, 32> | @t1 = i32;
57:0| 3: <21, 0, 0> | @t2 = i64 ();
60:2| 3: <7, 8> | @t3 = i8;
62:6| 3: <2> | @t4 = void;
64:4| 0: <65534> | }
...
100:0| 1: <65535, 12, 2> | function i64 @f0() { // BlockID = 12
108:0| 3: <1, 1> | blocks 1;
110:4| 1: <65535, 11, 2> | constants { // BlockID = 11
120:0| 3: <1, 3> | i8:
122:4| 3: <4, 2> | %c0 = i8 1;
125:0| 0: <65534> | }
| | %b0:
128:0| 3: <3, 1, 1, 1> | %v0 = zext i8 %c0 to i32;
132:0| 3: <3, 1, 0, 1> | %v1 = zext i32 %v0 to i64;
136:0| 3: <10, 1> | ret i64 %v1;
138:4| 0: <65534> | }
</pre>
<h3 id="sign-extending-instruction">Sign Extending Instruction</h3>
<p>The sign extending instruction takes a value to cast, and a type to extend it
to. Both types must be integer types, or integral vectors with the same number
of elements. The bit size of the source type must be smaller than the bit size
of the destination type. Equal sized types are not allowed.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = sext T1 V to T2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <3, VV, TT2, 2>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The sign extending instruction takes a value <code>V</code>, and expands it to type
<code>T2</code>. Both <code>T1</code> and <code>T2</code> must be integer types, or integer vectors with
the same number of integers. <code>T2</code> has to be wider than <code>T1</code>.</p>
<p>When sign extending, the instruction fills the high order bits of the value with
the (current) high order bit of the value. When sign extending from i1, the
extension always results in -1 or 0.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
TypeOf(V) == T1 &
VV == RelativeIndex(V) &
%tTT2 == TypeID(T2) &
BitSizeOf(UnderlyingType(T1)) < BitSizeOf(UnderlyingType(T2)) &
UnderlyingCount(T1) == UnderlyingCount(T2) &
IsInteger(UnderlyingType(T1)) &
IsInteger(UnderlyingType(T2)) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T2;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 5> | count 5;
50:4| 3: <7, 64> | @t0 = i64;
53:6| 3: <7, 32> | @t1 = i32;
57:0| 3: <21, 0, 0> | @t2 = i64 ();
60:2| 3: <7, 8> | @t3 = i8;
62:6| 3: <2> | @t4 = void;
64:4| 0: <65534> | }
...
100:0| 1: <65535, 12, 2> | function i64 @f0() { // BlockID = 12
108:0| 3: <1, 1> | blocks 1;
110:4| 1: <65535, 11, 2> | constants { // BlockID = 11
120:0| 3: <1, 3> | i8:
122:4| 3: <4, 3> | %c0 = i8 -1;
125:0| 0: <65534> | }
| | %b0:
128:0| 3: <3, 1, 1, 2> | %v0 = sext i8 %c0 to i32;
132:0| 3: <3, 1, 0, 2> | %v1 = sext i32 %v0 to i64;
136:0| 3: <10, 1> | ret i64 %v1;
138:4| 0: <65534> | }
</pre>
<h3 id="floating-point-extending-instruction">Floating Point Extending Instruction</h3>
<p>The floating point extending instruction takes a value to extend, and a type to
extend it to. Both types must either be floating point types, or vectors of
floating point types with the same number of elements. The source value must be
<code>float</code> while the destination is <code>double</code>. If the source is a vector, the
destination must also be vector with the same size as the source.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = fpext T1 V to T2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <3, VV, TT2, 8>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The floating point extending instruction converts floating point values.
<code>V</code> is the value to extend, and <code>T2</code> is the type to extend it
to. Both <code>T1</code> and <code>T2</code> must be floating point types, or floating point
vector types with the same number of floating point values. <code>T1</code> contains
<code>float</code> while <code>T2</code> contains <code>double</code>.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
TypeOf(V) == T1 &
VV == RelativeIndex(V) &
%tTT2 == TypeID(T2) &
BitSizeOf(UnderlyingType(T1)) < BitSizeOf(UnderlyingType(T2)) &
UnderlyingCount(T1) == UnderlyingCount(T2) &
IsFloat(UnderlyingType(T1)) &
IsFloat(UnderlyingType(T2)) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T2;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <4> | @t0 = double;
52:2| 3: <3> | @t1 = float;
54:0| 3: <21, 0, 0, 1> | @t2 = double (float);
58:0| 3: <2> | @t3 = void;
59:6| 0: <65534> | }
...
92:0| 1: <65535, 12, 2> | function double @f0(float %p0) {
| | // BlockID = 12
100:0| 3: <1, 1> | blocks 1;
| | %b0:
102:4| 3: <3, 1, 0, 8> | %v0 = fpext float %p0 to double;
106:4| 3: <10, 1> | ret double %v0;
109:0| 0: <65534> | }
</pre>
<h3 id="floating-point-to-unsigned-integer-instruction">Floating Point to Unsigned Integer Instruction</h3>
<p>The floating point to unsigned integer instruction converts floating point
values to unsigned integers.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = fptoui T1 V to T2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <3, VV, TT2, 3>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The floating point to unsigned integer instruction converts floating point
value(s) in <code>V</code> to its unsigned integer equivalent of type <code>T2</code>. <code>T1</code> must
be a floating point type, or a floating point vector type. <code>T2</code> must be an
integer type, or an integer vector type. If either type is a vector type, they
both must have the same number of elements.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
TypeOf(V) == T1 &
VV == RelativeIndex(V) &
%tTT2 == TypeID(T2) &
UnderlyingCount(T1) == UnderlyingCount(T2) &
IsFloat(UnderlyingType(T1)) &
IsInteger(UnderlyingType(T2)) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T2;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 6> | count 6;
50:4| 3: <3> | @t0 = float;
52:2| 3: <4> | @t1 = double;
54:0| 3: <2> | @t2 = void;
55:6| 3: <21, 0, 2, 0, 1> | @t3 = void (float, double);
60:4| 3: <7, 32> | @t4 = i32;
63:6| 3: <7, 16> | @t5 = i16;
66:2| 0: <65534> | }
...
100:0| 1: <65535, 12, 2> | function
| | void @f0(float %p0, double %p1) {
| | // BlockID = 12
108:0| 3: <1, 1> | blocks 1;
| | %b0:
110:4| 3: <3, 2, 4, 3> | %v0 = fptoui float %p0 to i32;
114:4| 3: <3, 2, 5, 3> | %v1 = fptoui double %p1 to i16;
118:4| 3: <10> | ret void;
120:2| 0: <65534> | }
</pre>
<h3 id="floating-point-to-signed-integer-instruction">Floating Point to Signed Integer Instruction</h3>
<p>The floating point to signed integer instruction converts floating point
values to signed integers.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = fptosi T1 V to T2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <3, VV, TT2, 4>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The floating point to signed integer instruction converts floating point
value(s) in <code>V</code> to its signed integer equivalent of type <code>T2</code>. <code>T1</code> must
be a floating point type, or a floating point vector type. <code>T2</code> must be an
integer type, or an integer vector type. If either type is a vector type, they
both must have the same number of elements.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
TypeOf(V) == T1 &
VV == RelativeIndex(V) &
%tTT2 = TypeID(T2) &
UnderlyingCount(T1) = UnderlyingCount(T2) &
IsFloat(UnderlyingType(T1)) &
IsInteger(UnderlyingType(T2)) &
N = NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T2;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 6> | count 6;
50:4| 3: <3> | @t0 = float;
52:2| 3: <4> | @t1 = double;
54:0| 3: <2> | @t2 = void;
55:6| 3: <21, 0, 2, 0, 1> | @t3 = void (float, double);
60:4| 3: <7, 8> | @t4 = i8;
63:0| 3: <7, 16> | @t5 = i16;
65:4| 0: <65534> | }
...
100:0| 1: <65535, 12, 2> | function
| | void @f0(float %p0, double %p1) {
| | // BlockID = 12
108:0| 3: <1, 1> | blocks 1;
| | %b0:
110:4| 3: <3, 2, 4, 4> | %v0 = fptosi float %p0 to i8;
114:4| 3: <3, 2, 5, 4> | %v1 = fptosi double %p1 to i16;
118:4| 3: <10> | ret void;
120:2| 0: <65534> | }
</pre>
<h3 id="unsigned-integer-to-floating-point-instruction">Unsigned Integer to Floating Point Instruction</h3>
<p>The unsigned integer to floating point instruction converts unsigned integers to
floating point values.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = uitofp T1 V to T2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <3, VV, TT2, 5>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The unsigned integer to floating point instruction converts unsigned integer(s)
to its floating point equivalent of type <code>T2</code>. <code>T1</code> must be an integer type,
or a integer vector type. <code>T2</code> must be a floating point type, or a floating
point vector type. If either type is a vector type, they both must have the same
number of elements.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
TypeOf(V) == T1 &
VV == RelativeIndex(V) &
%tTT2 = TypeID(T2) &
UnderlyingCount(T1) == UnderlyingCount(T2) &
IsInteger(UnderlyingType(T1)) &
IsFloat(UnderlyingType(T2)) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) == T2;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 7> | count 7;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <7, 64> | @t1 = i64;
57:0| 3: <2> | @t2 = void;
58:6| 3: <3> | @t3 = float;
60:4| 3: <21, 0, 2, 0, 1> | @t4 = void (i32, i64);
65:2| 3: <7, 1> | @t5 = i1;
67:6| 3: <4> | @t6 = double;
69:4| 0: <65534> | }
...
104:0| 1: <65535, 12, 2> | function void @f0(i32 %p0, i64 %p1) {
| | // BlockID = 12
112:0| 3: <1, 1> | blocks 1;
114:4| 1: <65535, 11, 2> | constants { // BlockID = 11
124:0| 3: <1, 5> | i1:
126:4| 3: <4, 3> | %c0 = i1 1;
129:0| 0: <65534> | }
| | %b0:
132:0| 3: <3, 1, 6, 5> | %v0 = uitofp i1 %c0 to double;
136:0| 3: <3, 4, 3, 5> | %v1 = uitofp i32 %p0 to float;
140:0| 3: <3, 4, 3, 5> | %v2 = uitofp i64 %p1 to float;
144:0| 3: <10> | ret void;
145:6| 0: <65534> | }
</pre>
<h3 id="signed-integer-to-floating-point-instruction">Signed Integer to Floating Point Instruction</h3>
<p>The signed integer to floating point instruction converts signed integers to
floating point values.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = sitofp T1 V to T2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <3, VV, TT2, 6>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The signed integer to floating point instruction converts signed integer(s) to
its floating point equivalent of type <code>T2</code>. <code>T1</code> must be an integer type, or
a integer vector type. <code>T2</code> must be a floating point type, or a floating point
vector type. If either type is a vector type, they both must have the same
number of elements.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
TypeOf(V) == T1 &
VV == RelativeIndex(V) &
%tTT2 = TypeID(T2) &
UnderlyingCount(T1) == UnderlyingCount(T2) &
IsInteger(UnderlyingType(T1)) &
IsFloat(UnderlyingType(T2)) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T2;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 7> | count 7;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <7, 64> | @t1 = i64;
57:0| 3: <2> | @t2 = void;
58:6| 3: <3> | @t3 = float;
60:4| 3: <21, 0, 2, 0, 1> | @t4 = void (i32, i64);
65:2| 3: <7, 8> | @t5 = i8;
67:6| 3: <4> | @t6 = double;
69:4| 0: <65534> | }
...
104:0| 1: <65535, 12, 2> | function void @f0(i32 %p0, i64 %p1) {
| | // BlockID = 12
112:0| 3: <1, 1> | blocks 1;
114:4| 1: <65535, 11, 2> | constants { // BlockID = 11
124:0| 3: <1, 5> | i8:
126:4| 3: <4, 3> | %c0 = i8 -1;
129:0| 0: <65534> | }
| | %b0:
132:0| 3: <3, 1, 6, 6> | %v0 = sitofp i8 %c0 to double;
136:0| 3: <3, 4, 3, 6> | %v1 = sitofp i32 %p0 to float;
140:0| 3: <3, 4, 3, 6> | %v2 = sitofp i64 %p1 to float;
144:0| 3: <10> | ret void;
145:6| 0: <65534> | }
</pre>
<h3 id="bitcast-instruction">Bitcast Instruction</h3>
<p>The bitcast instruction converts the type of the value without changing the bit
contents of the value. The bit size of the type of the value must be the same as
the bit size of the cast type.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = bitcast T1 V to T2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <3, VV, TT2, 11>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The bitcast instruction converts the type of value <code>V</code> to type <code>T2</code>. <code>T1</code>
and <code>T2</code> must be primitive types or vectors, and define the same number of
bits.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
TypeOf(V) == T1 &
VV = RelativeIndex(V) &
%tTT2 = TypeID(T2) &
BitSizeOf(T1) == BitSizeOf(T2) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T2;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 6> | count 6;
50:4| 3: <3> | @t0 = float;
52:2| 3: <7, 64> | @t1 = i64;
55:4| 3: <2> | @t2 = void;
57:2| 3: <21, 0, 2, 0, 1> | @t3 = void (float, i64);
62:0| 3: <7, 32> | @t4 = i32;
65:2| 3: <4> | @t5 = double;
67:0| 0: <65534> | }
...
100:0| 1: <65535, 12, 2> | function void @f0(float %p0, i64 %p1)
| | { // BlockID = 12
108:0| 3: <1, 1> | blocks 1;
| | %b0:
110:4| 3: <3, 2, 4, 11> | %v0 = bitcast float %p0 to i32;
114:4| 3: <3, 2, 5, 11> | %v1 = bitcast i64 %p1 to double;
118:4| 3: <10> | ret void;
120:2| 0: <65534> | }
</pre>
<h2 id="comparison-instructions"><span id="link-for-compare-instructions"></span>Comparison Instructions</h2>
<p>The comparison instructions compare values and generates a boolean (i1) result
for each pair of compared values. There are different comparison operations for
integer and floating point values.</p>
<h3 id="integer-comparison-instructions">Integer Comparison Instructions</h3>
<p>The integer comparison instruction compares integer values and returns a
boolean (i1) result for each pair of compared values.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = icmp C T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <9, VV1, VV2, CC>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The integer comparison instruction compares integer values and returns a boolean
(i1) result for each pair of compared values in <code>V1</code> and <code>V2</code>. <code>V1</code> and
<code>V2</code> must be of type <code>T</code>. <code>T</code> must be an integer type, or an integer
vector type. Condition code <code>C</code> is the condition applied to all elements in
<code>V1</code> and <code>V2</code>. Each comparison always yields an i1. If <code>T</code> is a primitive
type, the resulting type is i1. If <code>T</code> is a vector, then the resulting type is
a vector of i1 with the same size as <code>T</code>.</p>
<p>Legal test conditions are:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">C</th>
<th class="head">CC</th>
<th class="head">Operator</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>eq</td>
<td>32</td>
<td>equal</td>
</tr>
<tr class="row-odd"><td>ne</td>
<td>33</td>
<td>not equal</td>
</tr>
<tr class="row-even"><td>ugt</td>
<td>34</td>
<td>unsigned greater than</td>
</tr>
<tr class="row-odd"><td>uge</td>
<td>35</td>
<td>unsigned greater than or equal</td>
</tr>
<tr class="row-even"><td>ult</td>
<td>36</td>
<td>unsigned less than</td>
</tr>
<tr class="row-odd"><td>ule</td>
<td>37</td>
<td>unsigned less than or equal</td>
</tr>
<tr class="row-even"><td>sgt</td>
<td>38</td>
<td>signed greater than</td>
</tr>
<tr class="row-odd"><td>sge</td>
<td>39</td>
<td>signed greater than or equal</td>
</tr>
<tr class="row-even"><td>slt</td>
<td>40</td>
<td>signed less than</td>
</tr>
<tr class="row-odd"><td>sle</td>
<td>41</td>
<td>signed less than or equal</td>
</tr>
</tbody>
</table>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
IsInteger(UnderlyingType(T) &
T == TypeOf(V1) == TypeOf(V2) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
if IsVector(T) then
TypeOf(%vN) = <UnderlyingCount(T), i1>
else
TypeOf(%vN) = i1
endif
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <7, 1> | @t1 = i1;
56:2| 3: <2> | @t2 = void;
58:0| 3: <21, 0, 2> | @t3 = void ();
61:2| 0: <65534> | }
...
108:0| 1: <65535, 12, 2> | function void @f0() {
| | // BlockID = 12
116:0| 3: <1, 1> | blocks 1;
118:4| 1: <65535, 11, 2> | constants { // BlockID = 11
128:0| 3: <1, 0> | i32:
130:4| 3: <4, 0> | %c0 = i32 0;
133:0| 3: <4, 2> | %c1 = i32 1;
135:4| 0: <65534> | }
| | %b0:
136:0| 3: <28, 2, 1, 32> | %v0 = icmp eq i32 %c0, %c1;
140:6| 3: <28, 3, 2, 33> | %v1 = icmp ne i32 %c0, %c1;
145:4| 3: <28, 4, 3, 34> | %v2 = icmp ugt i32 %c0, %c1;
150:2| 3: <28, 5, 4, 36> | %v3 = icmp ult i32 %c0, %c1;
155:0| 3: <28, 6, 5, 37> | %v4 = icmp ule i32 %c0, %c1;
159:6| 3: <28, 7, 6, 38> | %v5 = icmp sgt i32 %c0, %c1;
164:4| 3: <28, 8, 7, 38> | %v6 = icmp sgt i32 %c0, %c1;
169:2| 3: <28, 9, 8, 39> | %v7 = icmp sge i32 %c0, %c1;
174:0| 3: <28, 10, 9, 40> | %v8 = icmp slt i32 %c0, %c1;
178:6| 3: <28, 11, 10, 41> | %v9 = icmp sle i32 %c0, %c1;
183:4| 3: <10> | ret void;
185:2| 0: <65534> | }
</pre>
<h3 id="floating-point-comparison-instructions">Floating Point Comparison Instructions</h3>
<p>The floating point comparison instruction compares floating point values and
returns a boolean (i1) result for each pair of compared values.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = fcmp C T V1, V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <9, VV1, VV2, CC>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The floating point comparison instruction compares floating point values and
returns a boolean (i1) result for each pair of compared values in <code>V1</code> and
<code>V2</code>. <code>V1</code> and <code>V2</code> must be of type <code>T</code>. <code>T</code> must be a floating point
type, or a floating point vector type. Condition code <code>C</code> is the condition
applied to all elements in <code>V1</code> and <code>V2</code>. Each comparison always yields an
i1. If <code>T</code> is a primitive type, the resulting type is i1. If <code>T</code> is a
vector, then the resulting type is a vector of i1 with the same size as <code>T</code>.</p>
<p>Legal test conditions are:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">C</th>
<th class="head">CC</th>
<th class="head">Operator</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>false</td>
<td>0</td>
<td>Always false</td>
</tr>
<tr class="row-odd"><td>oeq</td>
<td>1</td>
<td>Ordered and equal</td>
</tr>
<tr class="row-even"><td>ogt</td>
<td>2</td>
<td>Ordered and greater than</td>
</tr>
<tr class="row-odd"><td>oge</td>
<td>3</td>
<td>Ordered and greater than or equal</td>
</tr>
<tr class="row-even"><td>olt</td>
<td>4</td>
<td>Ordered and less than</td>
</tr>
<tr class="row-odd"><td>ole</td>
<td>5</td>
<td>Ordered and less than or equal</td>
</tr>
<tr class="row-even"><td>one</td>
<td>6</td>
<td>Ordered and not equal</td>
</tr>
<tr class="row-odd"><td>ord</td>
<td>7</td>
<td>Ordered (no NaNs)</td>
</tr>
<tr class="row-even"><td>uno</td>
<td>8</td>
<td>Unordered (either NaNs)</td>
</tr>
<tr class="row-odd"><td>ueq</td>
<td>9</td>
<td>Unordered or equal</td>
</tr>
<tr class="row-even"><td>ugt</td>
<td>10</td>
<td>Unordered or greater than</td>
</tr>
<tr class="row-odd"><td>uge</td>
<td>11</td>
<td>Unordered or greater than or equal</td>
</tr>
<tr class="row-even"><td>ult</td>
<td>12</td>
<td>Unordered or less than</td>
</tr>
<tr class="row-odd"><td>ule</td>
<td>13</td>
<td>Unordered or less than or equal</td>
</tr>
<tr class="row-even"><td>une</td>
<td>14</td>
<td>Unordered or not equal</td>
</tr>
<tr class="row-odd"><td>true</td>
<td>15</td>
<td>Always true</td>
</tr>
</tbody>
</table>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
IsFloat(UnderlyingType(T) &
T == TypeOf(V1) == TypeOf(V2) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
if IsVector(T) then
TypeOf(%vN) = <UnderlyingCount(T), i1>
else
TypeOf(%vN) = i1
endif
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <3> | @t0 = float;
52:2| 3: <7, 1> | @t1 = i1;
54:6| 3: <2> | @t2 = void;
56:4| 3: <21, 0, 2> | @t3 = void ();
59:6| 0: <65534> | }
...
108:0| 1: <65535, 12, 2> | function void @f0() {
| | // BlockID = 12
116:0| 3: <1, 1> | blocks 1;
118:4| 1: <65535, 11, 2> | constants { // BlockID = 11
128:0| 3: <1, 0> | float:
130:4| 3: <6, 0> | %c0 = float 0;
133:0| 3: <6, 1065353216> | %c1 = float 1;
139:2| 0: <65534> | }
| | %b0:
140:0| 3: <28, 2, 1, 0> | %v0 = fcmp false float %c0, %c1;
144:0| 3: <28, 3, 2, 1> | %v1 = fcmp oeq float %c0, %c1;
148:0| 3: <28, 4, 3, 2> | %v2 = fcmp ogt float %c0, %c1;
152:0| 3: <28, 5, 4, 3> | %v3 = fcmp oge float %c0, %c1;
156:0| 3: <28, 6, 5, 4> | %v4 = fcmp olt float %c0, %c1;
160:0| 3: <28, 7, 6, 5> | %v5 = fcmp ole float %c0, %c1;
164:0| 3: <28, 8, 7, 6> | %v6 = fcmp one float %c0, %c1;
168:0| 3: <28, 9, 8, 7> | %v7 = fcmp ord float %c0, %c1;
172:0| 3: <28, 10, 9, 9> | %v8 = fcmp ueq float %c0, %c1;
176:0| 3: <28, 11, 10, 10> | %v9 = fcmp ugt float %c0, %c1;
180:0| 3: <28, 12, 11, 11> | %v10 = fcmp uge float %c0, %c1;
184:0| 3: <28, 13, 12, 12> | %v11 = fcmp ult float %c0, %c1;
188:0| 3: <28, 14, 13, 13> | %v12 = fcmp ule float %c0, %c1;
192:0| 3: <28, 15, 14, 14> | %v13 = fcmp une float %c0, %c1;
196:0| 3: <28, 16, 15, 8> | %v14 = fcmp uno float %c0, %c1;
200:0| 3: <28, 17, 16, 15> | %v15 = fcmp true float %c0, %c1;
204:0| 3: <10> | ret void;
205:6| 0: <65534> | }
208:0|0: <65534> |}
</pre>
<h2 id="vector-instructions"><span id="link-for-vector-instructions"></span>Vector Instructions</h2>
<p>PNaClAsm supports several instructions that process vectors. This includes the
<a class="reference internal" href="#link-for-integer-binary-instructions"><em>integer</em></a> and <a class="reference internal" href="#link-for-floating-point-binary-instructions"><em>floating
point</em></a> binary instructions as well
as <a class="reference internal" href="#link-for-compare-instructions"><em>compare</em></a> instructions. These
instructions work with vectors and generate resulting (new) vectors. This
section introduces the instructions to construct vectors and extract results.</p>
<h3 id="insert-element-instruction"><span id="link-for-insert-element-instruction-section"></span>Insert Element Instruction</h3>
<p>The <em>insert element</em> instruction inserts a scalar value into a vector at a
specified index. The <em>insert element</em> instruction takes an existing vector and
puts a scalar value in one of the elements of the vector.</p>
<p>The <em>insert element</em> instruction can be used to construct a vector, one element
at a time. At first glance, it may appear that one can’t construct a vector,
since the <em>insert element</em> instruction needs a vector to insert elements into.</p>
<p>The key to understanding vector construction is understand that one can create
an <a class="reference internal" href="#link-for-undefined-literal"><em>undefined</em></a> vector literal. Using that
constant as a starting point, one can built up the wanted vector by a sequence
of <em>insert element</em> instructions.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = insertelement TV V, TE E, i32 I; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <7, VV, EE, II>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The <em>insert element</em> instruction inserts scalar value <code>E</code> into index <code>I</code> of
vector <code>V</code>. <code>%vN</code> holds the updated vector. Type <code>TV</code> is the type of
vector. It is also the type of updated vector <code>%vN</code>. Type <code>TE</code> is the type
of scalar value <code>E</code> and must be the element type of vector <code>V</code>. <code>I</code> must
be an <a class="reference internal" href="#link-for-integer-literal"><em>i32 literal</em></a>.</p>
<p>If <code>I</code> exceeds the length of <code>V</code>, the result is undefined.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
IsVector(TV) &
TypeOf(V) == TV &
UnderlyingType(TV) == TE &
TypeOf(I) == i32 &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = TV;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 5> | count 5;
50:4| 3: <7, 1> | @t0 = i1;
53:0| 3: <12, 4, 0> | @t1 = <4 x i1>;
56:2| 3: <7, 32> | @t2 = i32;
59:4| 3: <2> | @t3 = void;
61:2| 3: <21, 0, 3> | @t4 = void ();
64:4| 0: <65534> | }
...
116:0| 1: <65535, 12, 2> | function void @f0() {
| | // BlockID = 12
124:0| 3: <1, 1> | blocks 1;
126:4| 1: <65535, 11, 2> | constants { // BlockID = 11
136:0| 3: <1, 0> | i1:
138:4| 3: <4, 0> | %c0 = i1 0;
141:0| 3: <4, 3> | %c1 = i1 1;
143:4| 3: <1, 1> | <4 x i1>:
146:0| 3: <3> | %c2 = <4 x i1> undef;
147:6| 3: <1, 2> | i32:
150:2| 3: <4, 0> | %c3 = i32 0;
152:6| 3: <4, 2> | %c4 = i32 1;
155:2| 3: <4, 4> | %c5 = i32 2;
157:6| 3: <4, 6> | %c6 = i32 3;
160:2| 0: <65534> | }
| | %b0:
164:0| 3: <7, 5, 7, 4> | %v0 = insertelement <4 x i1> %c2,
| | i1 %c0, i32 %c3;
168:0| 3: <7, 1, 7, 4> | %v1 = insertelement <4 x i1> %v0,
| | i1 %c1, i32 %c4;
172:0| 3: <7, 1, 9, 4> | %v2 = insertelement <4 x i1> %v1,
| | i1 %c0, i32 %c5;
176:0| 3: <7, 1, 9, 4> | %v3 = insertelement <4 x i1> %v2,
| | i1 %c1, i32 %c6;
180:0| 3: <10> | ret void;
181:6| 0: <65534> | }
</pre>
<h3 id="extract-element-instruction">Extract Element Instruction</h3>
<p>The <em>extract element</em> instruction extracts a single scalar value from a vector
at a specified index.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = extractelement TV V, i32 I; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <6, VV, II>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The <em>extract element</em> instruction extracts the scalar value at index <code>I</code> from
vector <code>V</code>. The extracted value is assigned to <code>%vN</code>. Type <code>TV</code> is the
type of vector <code>V</code>. <code>I</code> must be an <a class="reference internal" href="#link-for-integer-literal"><em>i32
literal</em></a>. The type of <code>vN</code> must be the element type
of vector <code>V</code>.</p>
<p>If <code>I</code> exceeds the length of <code>V</code>, the result is undefined.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
IsVector(TV) &
TypeOf(V) == TV &
TypeOf(I) == i32 &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = UnderlyingType(TV);
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function void @f0(<4 x i32> %p0) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
106:4| 1: <65535, 11, 2> | constants { // BlockID = 11
116:0| 3: <1, 0> | i32:
118:4| 3: <4, 0> | %c0 = i32 0;
121:0| 0: <65534> | }
| | %b0:
124:0| 3: <6, 2, 1> | %v0 =
| | extractelement <4 x i32> %p0,
| | i32 %c0;
127:2| 3: <10> | ret void;
129:0| 0: <65534> | }
</pre>
<h2 id="other-instructions"><span id="link-for-other-pnaclasm-instructions"></span>Other Instructions</h2>
<p>This section defines miscellaneous instructions which defy better
classification.</p>
<h3 id="forward-type-declaration"><span id="link-for-forward-type-declaration-section"></span>Forward Type Declaration</h3>
<p>The forward type declaration exists to deal with the fact that all instruction
values must have a type associated with them before they are used. For some
simple functions one can easily topologically sort instructions so that
instruction values are defined before they are used. However, if the
implementation contains loops, the loop induced values can’t be defined before
they are used.</p>
<p>The solution is to forward declare the type of an instruction value. One could
forward declare the types of all instructions at the beginning of the function
block. However, this would make the corresponding file size considerably
larger. Rather, one should only generate these forward type declarations
sparingly and only when needed.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
declare T %vN; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <43, N, TT>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The forward declare type declaration defines the type to be associated with a
(not yet defined) instruction value <code>%vN</code>. <code>T</code> is the type of the value
generated by the <code>Nth</code> value generating instruction in the function block.</p>
<p>Note: It is an error to define the type of <code>%vN</code> with a different type than
will be generated by the <code>Nth</code> value generating instruction in the function
block.</p>
<p>Also note that this construct is a declaration and not considered an
instruction, even though it appears in the list of instruction records. Hence,
they may appear before and between <a class="reference internal" href="#link-for-phi-instruction-section"><em>phi</em></a>
instructions in a basic block.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA = AbbrevIndex(A) &
TT = TypeID(T)
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
TypeOf(%vN) = T;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <2> | @t1 = void;
55:4| 3: <7, 1> | @t2 = i1;
58:0| 3: <21, 0, 1, 0> | @t3 = void (i32);
62:0| 0: <65534> | }
...
108:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
| | // BlockID = 12
116:0| 3: <1, 7> | blocks 7;
118:4| 1: <65535, 11, 2> | constants { // BlockID = 11
128:0| 3: <1, 2> | i1:
130:4| 3: <4, 3> | %c0 = i1 1;
133:0| 0: <65534> | }
| | %b0:
136:0| 3: <11, 4> | br label %b4;
| | %b1:
138:4| 3: <43, 6, 0> | declare i32 %v3;
142:4| 3: <2, 2, 4294967293, 0> | %v0 = add i32 %p0, %v3;
151:0| 3: <11, 6> | br label %b6;
| | %b2:
153:4| 3: <43, 7, 0> | declare i32 %v4;
157:4| 3: <2, 3, 4294967293, 0> | %v1 = add i32 %p0, %v4;
166:0| 3: <11, 6> | br label %b6;
| | %b3:
168:4| 3: <2, 4, 4294967295, 0> | %v2 = add i32 %p0, %v3;
177:0| 3: <11, 6> | br label %b6;
| | %b4:
179:4| 3: <2, 5, 5, 0> | %v3 = add i32 %p0, %p0;
183:4| 3: <11, 1, 5, 5> | br i1 %c0, label %b1, label %b5;
| | %b5:
187:4| 3: <2, 1, 6, 0> | %v4 = add i32 %v3, %p0;
191:4| 3: <11, 2, 3, 6> | br i1 %c0, label %b2, label %b3;
| | %b6:
195:4| 3: <10> | ret void;
197:2| 0: <65534> | }
</pre>
<h3 id="phi-instruction"><span id="link-for-phi-instruction-section"></span>Phi Instruction</h3>
<p>The <em>phi</em> instruction is used to implement phi nodes in the SSA graph
representing the function. Phi instructions can only appear at the beginning of
a basic block. There must be no non-phi instructions (other than forward type
declarations) between the start of the basic block and the <em>phi</em> instruction.</p>
<p>To clarify the origin of each incoming value, the incoming value is associated
with the incoming edge from the corresponding predecessor block that the
incoming value comes from.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = phi T [V1, %bB1], ... , [VM, %bBM]; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <16, TT, VV1, B1, ..., VVM, BM>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The phi instruction is used to implement phi nodes in the SSA graph representing
the function. <code>%vN</code> is the resulting value of the corresponding phi
node. <code>T</code> is the type of the phi node. Values <code>V1</code> through <code>VM</code> are the
reaching definitions for the phi node while <code>%bB1</code> through <code>%bBM</code> are the
corresponding predecessor blocks. Each <code>VI</code> reaches via the incoming
predecessor edge from block <code>%bBI</code> (for 1 <= I <= M). Type <code>T</code> must be the
type associated with each <code>VI</code>.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
M > 1 &
TT == TypeID(T) &
T = TypeOf(VI) for all I, 1 <= I <= M &
BI < ExpectedBasicBlocks for all I, 1 <= I <= M &
VVI = SignRotate(RelativeIndex(VI)) for all I, 1 <= I <= M &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 4> | count 4;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <2> | @t1 = void;
55:4| 3: <21, 0, 1> | @t2 = void ();
58:6| 3: <7, 1> | @t3 = i1;
61:2| 0: <65534> | }
...
112:0| 1: <65535, 12, 2> | function void @f0() {
| | // BlockID = 12
120:0| 3: <1, 4> | blocks 4;
122:4| 1: <65535, 11, 2> | constants { // BlockID = 11
132:0| 3: <1, 0> | i32:
134:4| 3: <4, 2> | %c0 = i32 1;
137:0| 3: <1, 3> | i1:
139:4| 3: <4, 0> | %c1 = i1 0;
142:0| 0: <65534> | }
| | %b0:
144:0| 3: <11, 1, 2, 1> | br i1 %c1, label %b1, label %b2;
| | %b1:
148:0| 3: <2, 2, 2, 0> | %v0 = add i32 %c0, %c0;
152:0| 3: <2, 3, 3, 1> | %v1 = sub i32 %c0, %c0;
156:0| 3: <11, 3> | br label %b3;
| | %b2:
158:4| 3: <2, 4, 4, 2> | %v2 = mul i32 %c0, %c0;
162:4| 3: <2, 5, 5, 3> | %v3 = udiv i32 %c0, %c0;
166:4| 3: <11, 3> | br label %b3;
| | %b3:
169:0| 3: <16, 0, 8, 1, 4, 2> | %v4 = phi i32 [%v0, %b1],
| | [%v2, %b2];
174:4| 3: <16, 0, 8, 1, 4, 2> | %v5 = phi i32 [%v1, %b1],
| | [%v3, %b2];
180:0| 3: <10> | ret void;
181:6| 0: <65534> | }
</pre>
<h3 id="select-instruction">Select Instruction</h3>
<p>The <em>select</em> instruction is used to choose between pairs of values, based on a
condition, without PNaClAsm-level branching.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = select CT C, T V1, T V2; <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <29, VV1, VV2, CC>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The <em>select</em> instruction chooses pairs of values <code>V1</code> and <code>V2</code>, based on
condition value <code>C</code>. The type <code>CT</code> of value <code>C</code> must either be an i1, or
a vector of type i1. The type of values <code>V1</code> and <code>V2</code> must be of type
<code>T</code>. Type <code>T</code> must either be a primitive type, or a vector of a primitive
type.</p>
<p>Both <code>CT</code> and <code>T</code> must be primitive types, or both must be vector types of
the same size. When the contents of <code>C</code> is 1, the corresponding value from
<code>V1</code> will be chosen. Otherwise the corresponding value from <code>V2</code> will be
chosen.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
CC == RelativeIndex(C) &
VV1 == RelativeIndex(V1) &
VV2 == RelativeIndex(V2) &
T == TypeOf(V1) == TypeOf(V2) &
UnderlyingType(CT) == i1 &
IsInteger(UnderlyingType(T)) or IsFloat(UnderlyingType(T)) &
UnderlyingCount(C) == UnderlyingCount(T) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = T;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
| | // BlockID = 12
104:0| 3: <1, 1> | blocks 1;
106:4| 1: <65535, 11, 2> | constants { // BlockID = 11
116:0| 3: <1, 2> | i1:
118:4| 3: <4, 3> | %c0 = i1 1;
121:0| 0: <65534> | }
| | %b0:
124:0| 3: <29, 3, 2, 1> | %v0 = select i1 %c0, i32 %p0,
| | i32 %p1;
128:0| 3: <10, 1> | ret i32 %v0;
130:4| 0: <65534> | }
</pre>
<h3 id="call-instructions">Call Instructions</h3>
<p>The <em>call</em> instruction does a function call. The call instruction is used to
cause control flow to transfer to a specified routine, with its incoming
arguments bound to the specified values. When a return instruction in the called
function is reached, control flow continues with the instruction after the
function call. If the call is to a function, the returned value is the value
generated by the call instruction. Otherwise no result is defined by the call.</p>
<p>If the <em>tail</em> flag is associated with the call instruction, then the <a class="reference internal" href="/native-client/overview.html#link-for-pnacl-translator"><em>PNaCl
translator</em></a> is free to perform tail call
optimization. That is, the <em>tail</em> flag is a hint that may be ignored by the
PNaCl translator.</p>
<p>There are two kinds of calls: <em>direct</em> and <em>indirect</em>. A <em>direct</em> call calls a
defined <a class="reference internal" href="#link-for-function-address-section"><em>function address</em></a> (i.e. a
reference to a bitcode ID of the form <code>%fF</code>). All other calls are <em>indirect</em>.</p>
<h4 id="direct-procedure-call">Direct Procedure Call</h4>
<p>The direct procedure call calls a defined <a class="reference internal" href="#link-for-function-address-section"><em>function
address</em></a> whose <a class="reference internal" href="#link-for-function-type"><em>type
signature</em></a> returns type void.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
TAIL call void @fF (T1 A1, ... , TN AN); <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <34, CC, F, AA1, ... , AAN>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The direct procedure call calls a define function address <code>%fF</code> whose type
signature return type is void. The arguments <code>A1</code> through <code>AN</code> are passed in
the order specified. The type of argument <code>AI</code> must be type <code>TI</code> (for all I,
1 <=I <= N). Flag <code>TAIL</code> is optional. If it is included, it must be the
literal <code>tail</code>.</p>
<p>The types of the arguments must match the corresponding types of the function
signature associated with <code>%fF</code>. The return type of <code>%f</code> must be void.</p>
<p>TAIL is encoded into calling convention value <code>CC</code> as follows:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">TAIL</th>
<th class="head">CC</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>“”</td>
<td>0</td>
</tr>
<tr class="row-odd"><td>“tail”</td>
<td>1</td>
</tr>
</tbody>
</table>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
N >= 0 &
TypeOfFcn(%fF) == void (T1, ... , TN) &
TypeOf(AI) == TI for all I, 1 <= I <= N
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
72:0| 3: <8, 3, 0, 1, 0> | declare external
| | void @f0(i32, i64, i32);
...
116:0| 1: <65535, 12, 2> | function void @f1(i32 %p0) {
| | // BlockID = 12
124:0| 3: <1, 1> | blocks 1;
126:4| 1: <65535, 11, 2> | constants { // BlockID = 11
136:0| 3: <1, 2> | i64:
138:4| 3: <4, 2> | %c0 = i64 1;
141:0| 0: <65534> | }
| | %b0:
144:0| 3: <34, 0, 4, 2, 1, 2> | call void
| | @f0(i32 %p0, i64 %c0, i32 %p0);
150:2| 3: <10> | ret void;
152:0| 0: <65534> | }
</pre>
<h4 id="direct-function-call">Direct Function Call</h4>
<p>The direct function call calls a defined function address whose type signature
returns a value.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = TAIL call RT %fF (T1 A1, ... , TM AM); <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <34, CC, F, AA1, ... , AAM>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The direct function call calls a defined function address <code>%fF</code> whose type
signature returned is not type void. The arguments <code>A1</code> through <code>AM</code> are
passed in the order specified. The type of argument <code>AI</code> must be type <code>TI</code>
(for all I, 1 <= I <= N). Flag <code>TAIL</code> is optional. If it is included, it must
be the literal <code>tail</code>.</p>
<p>The types of the arguments must match the corresponding types of the function
signature associated with <code>%fF</code>. The return type must match <code>RT</code>.</p>
<p>Each parameter type <code>TI</code>, and return type <code>RT</code>, must either be a primitive
type, or a vector type. If the parameter type is an integer type, it must
either be i32 or i64.</p>
<p>TAIL is encoded into calling convention value <code>CC</code> as follows:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">TAIL</th>
<th class="head">CC</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>“”</td>
<td>0</td>
</tr>
<tr class="row-odd"><td>“tail”</td>
<td>1</td>
</tr>
</tbody>
</table>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
N >= 0 &
TypeOfFcn(%fF) == RT (T1, ... , TN) &
TypeOf(AI) == TI for all I, 1 <= I <= M &
IsFcnArgType(TI) for all I, 1 <= I <= M &
IsFcnArgType(RT) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = RT;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
72:0| 3: <8, 2, 0, 1, 0> | declare external
| | i32 @f0(i32, i64, i32);
...
116:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) {
| | // BlockID = 12
124:0| 3: <1, 1> | blocks 1;
126:4| 1: <65535, 11, 2> | constants { // BlockID = 11
136:0| 3: <1, 1> | i64:
138:4| 3: <4, 2> | %c0 = i64 1;
141:0| 0: <65534> | }
| | %b0:
144:0| 3: <34, 0, 4, 2, 1, 2> | %v0 = call i32
| | @f0(i32 %p0, i64 %c0, i32 %p0);
150:2| 3: <34, 1, 4, 1> | %v1 = tail call i32 @f1(i32 %v0);
155:0| 3: <10, 2> | ret i32 %v0;
157:4| 0: <65534> | }
</pre>
<h4 id="indirect-procedure-call">Indirect Procedure Call</h4>
<p>The indirect procedure call calls a function using an indirect function address,
and whose type signature is assumed to return type void. It is different from
the direct procedure call because we can’t use the type signature of the
corresponding direct function address to type check the construct.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
TAIL call void V (T1 A1, ... , TN AN); <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <44, CC, TV, VV, AA1, ... , AAN>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The indirect call procedure calls a function using value <code>V</code> that is an
indirect function address, and whose type signature is assumed to return type
void. The arguments <code>A1</code> through <code>AN</code> are passed in the order
specified. The type of argument <code>AI</code> must be type <code>TI</code> (for all I, 1 <= I <=
N). Flag <code>TAIL</code> is optional. If it is included, it must be the literal
<code>tail</code>.</p>
<p>Each parameter type <code>TI</code> (1 <= I <= N) must either be a primitive type, or a
vector type. If the parameter type is an integer type, it must either be i32
or i64.</p>
<p>TAIL is encoded into calling convention value <code>CC</code> as follows:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">TAIL</th>
<th class="head">CC</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>“”</td>
<td>0</td>
</tr>
<tr class="row-odd"><td>“tail”</td>
<td>1</td>
</tr>
</tbody>
</table>
<p>The type signature of the called procedure is assumed to be:</p>
<pre class="prettyprint">
void (T1, ... , TN)
</pre>
<p>It isn’t necessary to define this type in the <a class="reference internal" href="#link-for-types-block-section"><em>types
block</em></a>, since the type is inferred rather than
used.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
N >= 0 &
TV = TypeID(void) &
AbsoluteIndex(V) >= NumFuncAddresses &
TypeOf(AI) == TI for all I, 1 <= I <= N &
IsFcnArgType(TI) for all I, 1 <= I <= N
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 3> | count 3;
50:4| 3: <2> | @t0 = void;
52:2| 3: <7, 32> | @t1 = i32;
55:4| 3: <21, 0, 0, 1> | @t2 = void (i32);
59:4| 0: <65534> | }
...
92:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
| | // BlockID = 12
100:0| 3: <1, 1> | blocks 1;
102:4| 1: <65535, 11, 2> | constants { // BlockID = 11
112:0| 3: <1, 1> | i32:
114:4| 3: <4, 2> | %c0 = i32 1;
117:0| 0: <65534> | }
| | %b0:
120:0| 3: <44, 0, 2, 0, 1> | call void %p0(i32 %c0);
125:4| 3: <10> | ret void;
127:2| 0: <65534> | }
</pre>
<h4 id="indirect-function-call">Indirect Function Call</h4>
<p>The indirect function call calls a function using a value that is an indirect
function address. It is different from the direct function call because we can’t
use the type signature of the corresponding literal function address to type
check the construct.</p>
<p><strong>Syntax</strong>:</p>
<pre class="prettyprint">
%vN = TAIL call RT V (T1 A1, ... , TM AM); <A>
</pre>
<p><strong>Record</strong>:</p>
<pre class="prettyprint">
AA: <34, CC, RRT, VV, AA1, ... , AAM>
</pre>
<p><strong>Semantics</strong>:</p>
<p>The indirect function call calls a function using a value <code>V</code> that is an
indirect function address, and is assumed to return type <code>RT</code>. The arguments
<code>A1</code> through <code>AM</code> are passed in the order specified. The type of argument
<code>AI</code> must be type <code>TI</code> (for all I, 1 <= I <= N). Flag <code>TAIL</code> is
optional. If it is included, it must be the literal <code>tail</code>.</p>
<p>Each parameter type <code>TI</code> (1 <= I <= M), and return type <code>RT</code>, must either be
a primitive type, or a vector type. If the parameter type is an integer type,
it must either be i32 or i64.</p>
<p>TAIL is encoded into calling convention value <code>CC</code> as follows:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">TAIL</th>
<th class="head">CC</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>‘’</td>
<td>0</td>
</tr>
<tr class="row-odd"><td>‘tail’</td>
<td>1</td>
</tr>
</tbody>
</table>
<p>The type signature of the called function is assumed to be:</p>
<pre class="prettyprint">
RT (T1, ... , TN)
</pre>
<p>It isn’t necessary to define this type in the <a class="reference internal" href="#link-for-types-block-section"><em>types
block</em></a>, since the type is inferred rather than
used.</p>
<p><strong>Constraints</strong>:</p>
<pre class="prettyprint">
AA == AbbrevIndex(A) &
RRT = TypeID(RT) &
VV = RelativeIndex(V) &
M >= 0 &
AbsoluteIndex(V) >= NumFcnAddresses &
TypeOf(AI) == TI for all I, 1 <= I <= M &
IsFcnArgType(TI) for all I, 1 <= I <= M &
IsFcnArgType(RT) &
N == NumValuedInsts
</pre>
<p><strong>Updates</strong>:</p>
<pre class="prettyprint">
++NumValuedInsts;
TypeOf(%vN) = RT;
</pre>
<p><strong>Examples</strong>:</p>
<pre class="prettyprint">
40:0| 1: <65535, 17, 2> | types { // BlockID = 17
48:0| 3: <1, 6> | count 6;
50:4| 3: <7, 32> | @t0 = i32;
53:6| 3: <3> | @t1 = float;
55:4| 3: <4> | @t2 = double;
57:2| 3: <21, 0, 0, 0, 1, 2> | @t3 = i32 (i32, float, double);
62:6| 3: <21, 0, 0, 1, 2> | @t4 = i32 (float, double);
67:4| 3: <2> | @t5 = void;
69:2| 0: <65534> | }
...
104:0| 1: <65535, 12, 2> | function
| | i32
| | @f0(i32 %p0, float %p1,
| | double %p2) {
| | // BlockID = 12
112:0| 3: <1, 1> | blocks 1;
| | %b0:
114:4| 3: <44, 0, 3, 0, 2, 1> | %v0 = call i32
| | %p0(float %p1, double %p2);
120:6| 3: <10, 1> | ret i32 %v0;
123:2| 0: <65534> | }
</pre>
<h2 id="memory-blocks-and-alignment"><span id="link-for-memory-blocks-and-alignment-section"></span>Memory Blocks and Alignment</h2>
<p>In general, variable and heap allocated data are represented as byte addressable
memory blocks. Alignment is always a power of 2, and defines an expectation on
the memory address. That is, an alignment is met if the memory address is
(evenly) divisible by the alignment. Note that alignment of 0 is never allowed.</p>
<blockquote>
<div>Alignment plays a role at two points:</div></blockquote>
<ul class="small-gap">
<li>When you create a local/global variable</li>
<li>When you load/store data using a pointer.</li>
</ul>
<p>PNaClAsm allows most types to be placed at any address, and therefore can
have alignment of 1. However, many architectures can load more efficiently
if the data has an alignment that is larger than 1. As such, choosing a larger
alignment can make load/stores more efficient.</p>
<p>On loads and stores, the alignment in the instruction is used to communicate
what assumptions the <a class="reference internal" href="/native-client/overview.html#link-for-pnacl-translator"><em>PNaCl translator</em></a> can
make when choosing the appropriate machine instructions. If the alignment is 1,
it can’t assume anything about the memory address used by the instruction. When
the alignment is greater than one, it can use that information to potentially
chose a more efficient sequence of instructions to do the load/store.</p>
<p>When laying out data within a variable, one also considers alignment. The reason
for this is that if you want an address to be aligned, within the bytes defining
the variable, you must choose an alignment for the variable that guarantees that
alignment.</p>
<p>In PNaClAsm, the valid load/store alignments are:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Type</th>
<th class="head">Alignment</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>i1</td>
<td>1</td>
</tr>
<tr class="row-odd"><td>i8</td>
<td>1</td>
</tr>
<tr class="row-even"><td>i16</td>
<td>1</td>
</tr>
<tr class="row-odd"><td>i32</td>
<td>1</td>
</tr>
<tr class="row-even"><td>i64</td>
<td>1</td>
</tr>
<tr class="row-odd"><td>Float</td>
<td>1, 4</td>
</tr>
<tr class="row-even"><td>Double</td>
<td>1, 8</td>
</tr>
<tr class="row-odd"><td><4 x i1></td>
<td>not applicable</td>
</tr>
<tr class="row-even"><td><8 x i1></td>
<td>not applicable</td>
</tr>
<tr class="row-odd"><td><16 x i1></td>
<td>not applicable</td>
</tr>
<tr class="row-even"><td><16 x i8></td>
<td>1</td>
</tr>
<tr class="row-odd"><td><8 x i16></td>
<td>2</td>
</tr>
<tr class="row-even"><td><4 x i32></td>
<td>4</td>
</tr>
<tr class="row-odd"><td><4 x float></td>
<td>4</td>
</tr>
</tbody>
</table>
<p>Note that only vectors do not have an alignment value of 1. Hence, they can’t be
placed at an arbitrary memory address. Also, since vectors on <code>i1</code> can’t be
loaded/stored, the alignment is not applicable for these types.</p>
<h2 id="intrinsic-functions"><span id="link-for-intrinsic-functions-section"></span>Intrinsic Functions</h2>
<p>Intrinsic functions are special in PNaClAsm. They are implemented as specially
named (external) function calls. The purpose of these intrinsic functions is to
extend the PNaClAsm instruction set with additional functionality that is
architecture specific. Hence, they either can’t be implemented within PNaClAsm,
or a non-architecture specific implementation may be too slow on some
architectures. In such cases, the <a class="reference internal" href="/native-client/overview.html#link-for-pnacl-translator"><em>PNaCl
translator</em></a> must fill in the corresponding
implementation, since only it knows the architecture it is compiling down to.</p>
<p>Examples of intrinsic function calls are for concurrent operations, atomic
operations, bulk memory moves, thread pointer operations, and long jumps.</p>
<p>It should be noted that calls to intrinsic functions do not have the same
calling type constraints as ordinary functions. That is, an intrinsic can use
any integer type for arguments/results, unlike ordinary functions (which
restrict integer types to <code>i32</code> and <code>i64</code>).</p>
<p>See the <a class="reference internal" href="/native-client/reference/pnacl-bitcode-abi.html"><em>PNaCl bitcode reference manual</em></a> for the full
set of intrinsic functions allowed. Note that in PNaClAsm, all pointer types to
an (LLVM) intrinsic function is converted to type i32.</p>
<h2 id="support-functions"><span id="link-for-support-functions-section"></span>Support Functions</h2>
<p>Defines functions used to convert syntactic representation to values in the
corresponding record.</p>
<h3 id="signrotate">SignRotate</h3>
<p>The SignRotate function encodes a signed integer in an easily compressible
form. This is done by rotating the sign bit to the rightmost bit, rather than
the leftmost bit. By doing this rotation, both small positive and negative
integers are small (unsigned) integers. Therefore, all small integers can be
encoded as a small (unsigned) integers.</p>
<p>The definition of SignRotate(N) is:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Argument</th>
<th class="head">Value</th>
<th class="head">Condition</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>N</td>
<td>abs(N)<<1</td>
<td>N >= 0</td>
</tr>
<tr class="row-odd"><td>N</td>
<td>abs(N)<<1 + 1</td>
<td>N < 0</td>
</tr>
</tbody>
</table>
<h3 id="absoluteindex"><span id="link-for-absolute-index-section"></span>AbsoluteIndex</h3>
<p>Bitcode IDs of the forms <code>@fN</code>, <code>@gN</code>, <code>%pN</code>, <code>%cN</code>, and <code>%vN</code>, are
combined into a single index space. This can be done because of the ordering
imposed by PNaClAsm. All function address bitcode IDs must be defined before any
of the other forms of bitcode IDs. All global address bitcode IDs must be
defined before any local bitcode IDs. Within a function block, the parameter
bitcode IDs must be defined before constant IDs, and constant IDs must be
defined before instruction value IDs.</p>
<p>Hence, within a function block, it is safe to refer to all of these
bitcode IDs using a single <em>absolute</em> index. The absolute index for
each kind of bitcode ID is computed as follows:</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Bitcode ID</th>
<th class="head">AbsoluteIndex</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>@tN</td>
<td>N</td>
</tr>
<tr class="row-odd"><td>@fN</td>
<td>N</td>
</tr>
<tr class="row-even"><td>@gN</td>
<td>N + NumFcnAddresses</td>
</tr>
<tr class="row-odd"><td>@pN</td>
<td>N + NumFcnAddresses + NumGlobalAddresses</td>
</tr>
<tr class="row-even"><td>@cN</td>
<td>N + NumFcnAddresses + NumGlobalAddresses + NumParams</td>
</tr>
<tr class="row-odd"><td>@vN</td>
<td>N + NumFcnAddresses + NumGlobalAddresses + NumParams + NumFcnConsts</td>
</tr>
</tbody>
</table>
<h3 id="relativeindex"><span id="link-for-relative-index"></span>RelativeIndex</h3>
<p>Relative indices are used to refer to values within instructions of a function.
The relative index of an ID is always defined in terms of the index associated
with the next value generating instruction. It is defined as follows:</p>
<pre class="prettyprint">
RelativeIndex(J) = AbsoluteIndex(%vN) - AbsoluteIndex(J)
</pre>
<p>where:</p>
<pre class="prettyprint">
N = NumValuedInsts
</pre>
<h3 id="abbrevindex">AbbrevIndex</h3>
<p>This function converts user-defined abbreviation indices to the corresponding
internal abbreviation index saved in the bitcode file. It adds 4 to its
argument, since there are 4 predefined internal abbreviation indices (0, 1, 2,
and 3).</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">N</th>
<th class="head">AbbrevIndex(N)</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>undefined</td>
<td>3</td>
</tr>
<tr class="row-odd"><td>%aA</td>
<td>A + 4</td>
</tr>
<tr class="row-even"><td>@aA</td>
<td>A + 4</td>
</tr>
</tbody>
</table>
<h3 id="log2">Log2</h3>
<p>This is the 32-bit log2 value of its argument.</p>
<h3 id="bitsizeof">BitSizeOf</h3>
<p>Returns the number of bits needed to represent its argument (a type).</p>
<table border="1" class="docutils">
<colgroup>
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">T</th>
<th class="head">BitSizeOf</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>i1</td>
<td>1</td>
</tr>
<tr class="row-odd"><td>i8</td>
<td>8</td>
</tr>
<tr class="row-even"><td>i16</td>
<td>16</td>
</tr>
<tr class="row-odd"><td>i32</td>
<td>32</td>
</tr>
<tr class="row-even"><td>i64</td>
<td>64</td>
</tr>
<tr class="row-odd"><td>float</td>
<td>32</td>
</tr>
<tr class="row-even"><td>double</td>
<td>64</td>
</tr>
<tr class="row-odd"><td><N X T></td>
<td>N * BitSizeOf(T)</td>
</tr>
</tbody>
</table>
<h3 id="underlyingtype">UnderlyingType</h3>
<p>Returns the primitive type of the type construct. For primitive types, the
<em>UnderlyingType</em> is itself. For vector types, the base type of the vector is the
underlying type.</p>
<h3 id="underlyingcount">UnderlyingCount</h3>
<p>Returns the size of the vector if given a vector, and 0 for primitive types.
Note that this function is used to check if two vectors are of the same size.
It is also used to test if two types are either primitive (i.e. UnderlyingCount
returns 0 for both types) or are vectors of the same size (i.e. UnderlyingCount
returns the same non-zero value).</p>
<h3 id="isinteger">IsInteger</h3>
<p>Returns true if the argument is in {i1, i8, i16, i32, i64}.</p>
<h3 id="isfloat">IsFloat</h3>
<p>Returns true if the argument is in {<code>float</code>, <code>double</code>}.</p>
<h3 id="isvector">IsVector</h3>
<p>Returns true if the argument is a vector type.</p>
<h3 id="isprimitive">IsPrimitive</h3>
<p>Returns true if the argument is a primitive type. That is:</p>
<pre class="prettyprint">
IsPrimitive(T) == IsInteger(T) or IsFloat(T)
</pre>
<h3 id="isfcnargtype">IsFcnArgType</h3>
<p>Returns true if the argument is a primitive type or a vector type. Further,
if it is an integer type, it must be i32 or i64. That is:</p>
<pre class="prettyprint">
IsFcnArgType(T) = (IsInteger(T) and (i32 = BitSizeOf(T)
or i64 == BitSizeOf(T)))
or IsFloat(T) or IsVector(T)
</pre>
<h2 id="abbreviations"><span id="link-for-abbreviations-section"></span>Abbreviations</h2>
<p>Abbreviations are used to convert PNaCl records to a sequence of bits. PNaCl
uses the same strategy as <a class="reference external" href="http://llvm.org/docs/BitCodeFormat.html">LLVM’s bitcode file format</a>. See that document for more
details.</p>
<p>It should be noted that we replace LLVM’s header (called the <em>Bitcode Wrapper
Format</em>) with the bytes of the <a class="reference internal" href="#link-for-header-record-section"><em>PNaCl record
header</em></a>. In addition, PNaCl bitcode files do
not allow <em>blob</em> abbreviation.</p>
<h3 id="abbreviations-block"><span id="link-for-abbreviations-block-section"></span>Abbreviations Block</h3>
<p>The abbreviations block is the first block in the module build. The
block is divided into sections. Each section is a sequence of records. Each
record in the sequence defines a user-defined abbreviation. Each section
defines abbreviations that can be applied to all (succeeding) blocks of a
particular kind. These abbreviations are denoted by the (global) ID of the form
<em>@aN</em>.</p>
<p>In terms of <a class="reference external" href="http://llvm.org/docs/BitCodeFormat.html">LLVM’s bitcode file format</a>, the abbreviations block is called a
<em>BLOCKINFO</em> block. Records <em>SETBID</em> and <em>DEFINE_ABBREV</em> are the only records
allowed in PNaCl’s abbreviation block (i.e. it doesn’t allow <em>BLOCKNAME</em> and
<em>SETRECORDNAME</em> records).</p>
<h3 id="todo">TODO</h3>
<p>Extend this document to describe PNaCl’s bitcode bit sequencer
without requiring the reader to refer to <a class="reference external" href="http://llvm.org/docs/BitCodeFormat.html">LLVM’s bitcode file
format</a>.</p>
</section>
{{/partials.standard_nacl_article}}
|