Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: native_client_sdk/src/doc/reference/pnacl-bitcode-manual.rst

Issue 364463002: Initial draft of PNaCl bitcode files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Next round of cleanups. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 ===================================
2 Pnacl Bitcode File Reference Manual
jvoung (off chromium) 2014/07/28 19:20:35 PNaCl
Karl 2014/11/14 22:35:34 Done.
3 ===================================
4
5 .. contents::
6 :local:
7 :backlinks: none
8 :depth: 3
9
10
11 Introduction
JF 2014/07/28 20:58:11 The intro is pretty long. I think having a figure
Karl 2014/11/14 22:35:29 Done.
12 ============
13
14 This document is a reference manual for the contents of PNaCl bitcode files. We
15 define bitcode files via three layers. The first layer is presented using
16 assembly language *PNaClAsm*, and defines the textual form of the bitcode
17 file. The textual form is then lowered to a sequence of *PNaCl records*. The
18 final layer applies abbreviations that convert each PNaCl record into a
19 corresponding sequence of bits.
20
21 PNaClAsm uses a *static single assignment* (SSA) based representation that
22 requires generated results to have a single (assignment) source.
23
24 PNaClAsm focuses on the semantic content of the file, not the bit-encoding of
25 that content. However, it does provide annotations that allow one to specify how
26 the the abbreviations are used to convert PNaCl records into the sequence of bit s.
Sam Clegg 2014/07/28 18:28:31 Wrap at 80 here and a few lines down.
Jim Stichnoth 2014/07/28 22:52:08 the the
Karl 2014/11/14 22:35:27 Done.
Karl 2014/11/14 22:35:29 Done.
27
28 Each construct in PNaClAsm defines a corresponding :ref:`PNaCl
29 record<link_for_pnacl_records>`. A PNaCl bitcode file is simply a sequence of P NaCl
30 records. The goal of PNaClAsm is to make records easier to read, and not to
31 define a high-level user programming language.
32
33 PNaCl records are an abstract encoding of structured data, similar to XML. Like
34 XML, PNaCl records have a notion of tags (i.e. the first element in a record,
Jim Stichnoth 2014/07/28 22:52:03 Instead of "tags", can you say "a tag", to keep si
Karl 2014/11/14 22:35:31 Rewrote to fix agreement.
35 called a *code*), and nested structures. The nested structures are defined by
36 corresponding *enter* and *exit* block records.
37
38 These block records must be used like balanced parentheses to define the block
39 structure that is imposed on top of records. Each exit record must be preceded
40 by a corresponding enter record. Blocks can be nested by nesting enter/exit
41 records appropriately.
42
43 The *PNaCl bitcode writer* takes the sequence of records, defined by a PNaClAsm
44 program, and converts each record into a (variable) sequence of bits. The output
Jim Stichnoth 2014/07/28 22:52:04 "variable" - do you mean "variable-length"?
Karl 2014/11/14 22:35:34 Done.
45 of each bit sequence is appended together. The resulting generated sequence of
46 bits is the contents of the PNaCl bitcode file.
47
48 For every kind of record, there is a default method for converting records into
jvoung (off chromium) 2014/07/28 19:20:36 nit: is "default" important for this first sentenc
Karl 2014/11/14 22:35:35 Done.
49 bit sequences. These methods correspond to a notion of
50 :ref:`abbreviations<link_for_abbreviations_section>`. Each abbreviation defines
51 a specific bit sequence conversion to be applied. The default conversion methods
52 are simply predefined abbreviations.
53
54 The default abbreviations can be overridden with user-specified abbreviations.
55 All user-specified abbreviations are included in the generated bitcode
56 file. Each abbreviation defines how a record is converted to a bit sequence. The
57 PNaCl translator uses these abbreviations to convert the bit sequence back to
58 the corresponding sequence of PNaCl records. As a result, all records have an
59 abbreviation (user or default) associated with them.
60
61 Conceptually, abbreviations are used to define how to pack the contents of
62 records into bit sequences. The main reason for defining abbreviations is to
63 save space. The default abbreviations are simplistic and are intended to handle
64 all possible records. The default abbreviations do not really worry about being
65 efficient, in terms of the number of bits generated.
66
67 By separating the concepts of PNaCl records and abbreviations, the notion of
68 data compression is cleanly separated from semantic content. This allows
69 different use cases to decide how much effort should be spent on compressing
70 records.
JF 2014/07/28 20:58:12 Mention pnacl-bccompress here?
Karl 2014/11/14 22:35:32 Done.
71
72 For a JIT compiler that produces bitcode, little (if any) compression should be
73 applied. In fact, the API to the JIT may just be the records themselves. The
74 goal of a JIT is to perform the final translation to machine code as quickly as
75 possible. On the other hand, when delivering across the web, one may want to
76 compress the sequence of bits considerably, to reduce costs in delivering web
77 pages.
78
79 Data Model
80 ==========
81
82 The data model for PNaCl bitcode is fixed at little-endian ILP32: pointers are
83 32 bits in size. 64-bit integer types are also supported natively via the i64
84 type (for example, a front-end can generate these from the C/C++ type *long
85 long*).
JF 2014/07/28 20:58:12 Code should be in backticks: ``long long``
Karl 2014/11/14 22:35:28 Done.
86
87 Integers are assumed to be modeled using two's complement. Floating point
88 support is fixed at IEEE 754 32-bit and 64-bit values (float and double,
89 respectively).
JF 2014/07/28 20:58:11 The file reference/pnacl-c-cpp-language-support.rs
Karl 2014/11/14 22:35:31 Done.
90
91 PNaCl Blocks
92 ============
93
94 Blocks are used to organize records in the bitcode file. The kinds of blocks
95 defined in PNaClAsm are:
96
97 Module block
98 A top-level block defining the program. This block defines global information
99 used by the program, followed by function blocks defining the implementation
100 of functions within the program.
jvoung (off chromium) 2014/07/28 19:20:35 Would it make sense to talk about any subblocks ne
Karl 2014/11/14 22:35:32 Done.
101
102 Types block
103 Defines the set of types used by the program. All types used in the program
104 must be defined in this block. These types consist of primitive types as well
105 as high level constructs such as vectors and function signatures.
106
107 Globals block
108 Defines the set of global addresses of global variables and constants used by
109 the program. It also defines how each global (associated with the global
110 address) is initialized.
111
112 Valuesymtab block
113 Defines textual names for external function addresses.
114
115 Function block
116 Each function (implemented) in a program has its own block that defines the
117 implementation of the corresponding function.
118
119 Constants block
120 Each implemented function, that uses constants in its instructions, defines a
Jim Stichnoth 2014/07/28 22:52:04 I would remove both commas.
Karl 2014/11/14 22:35:35 Done.
121 constant block. Constants blocks appear within the corresponding function
Jim Stichnoth 2014/07/28 22:52:03 "constants block", right?
Karl 2014/11/14 22:35:33 Correct, and fixed.
122 block of the implemented function.
123
124 Abbreviations block
125 Defines global abbreviations that are used to compress PNaCl records. This
126 block is segmented into multiple sections, one section for each kind of
127 block. This block appears at the beginning of the module block.
JF 2014/07/28 20:58:11 Could you make all of the above links to the secti
Karl 2014/11/14 22:35:27 Done.
128
129 This section is only intended as a high-level discussion of blocks. Later
130 subsections will dive more deeply into the constraints on how blocks must be
Jim Stichnoth 2014/07/28 22:52:04 Use "sections" instead of "subsections"?
Karl 2014/11/14 22:35:35 Done.
131 laid out. This section only presents the overall concepts of what kinds of data
Jim Stichnoth 2014/07/28 22:52:06 Either "what kinds of data are stored" or "what ki
Karl 2014/11/14 22:35:30 Done.
132 is stored in each of the blocks.
133
134 A PNaCl program consists of a header record and a module block. The header
135 defines a sequence of bytes uniquely identifying the file as a bitcode file. The
136 module block defines the program to run.
137
138 Each block, within a bitcode file, defines values. These values are associated
139 with IDs. Each type of block defines different kinds of IDs. The module, types,
140 globals, and abbreviations blocks define global identifiers, and only a single
141 instance can appear. The function and constant blocks define local identifiers,
Jim Stichnoth 2014/07/28 22:52:04 only a single instance of each global identifier?
Karl 2014/11/14 22:35:31 Yes. Each global is represented by a "global varia
142 and can have multiple instances (one for each implemented function).
143
144 Each :ref:`function block<link_for_function_blocks_section>` defines the
145 implementation of a single function. Each function block defines the
146 intermediate representation of the function, consisting of basic blocks and
147 instructions. If constants are used within instructions, they are defined in a
148 *constants block*, nested within the corresponding function block.
149
150 All function blocks are associated with a corresponding function address. This
151 association is (again) positional rather than explicit. That is, the Nth
jvoung (off chromium) 2014/07/28 19:20:35 After the reordering suggested in the previous rev
Karl 2014/11/14 22:35:35 Done.
152 function block in a module block corresponds to the Nth defining (rather than
153 declared) function address record in the module block.
jvoung (off chromium) 2014/07/28 19:20:35 I'm not sure it's clear that there are "function a
Karl 2014/11/14 22:35:32 Added a short paragraph before the paragraph on fu
154
155 Hence, within a function block, there is no explicit reference to the
156 function address the block defines. For readability, PNaClAsm uses the
157 corresponding function heading, associated with the corresponding
158 function address record, even though that data does not appear in the
159 corresponding records.
160
161 .. _link_for_pnacl_records:
162
163 PNaCl Records
164 =============
165
166 A PNaCl record is a non-empty sequence of unsigned, 64-bit, integers. A record
167 is identified by the record *code*, which is the first element in the
168 sequence. Record codes are unique within a specific kind of block, but are not
169 necessarily unique across different kinds of blocks. The record code acts as the
170 variant discriminator (i.e. tag) within a block, to identify what kind of record
171 it is.
172
173 Record codes that are local to a specific kind of block are small values
174 (starting from zero). In an ideal world, they would be a consecutive sequence of
175 integers, starting at zero. However, the reality is that PNaCl records evolved
176 over time (and actually started as `LLVM records
177 <http://llvm.org/docs/BitCodeFormat.html>`_). For backwards
Jim Stichnoth 2014/07/28 22:52:08 backward?
Karl 2014/11/14 22:35:33 Done.
178 compatibility, old numbers have not been reused, leaving gaps in the actual
179 record code values used.
180
181 Global record codes are record codes that have the same meaning in multiple
182 kinds of block. To separate global record codes from local record codes, large
Jim Stichnoth 2014/07/28 22:52:03 blocks
Karl 2014/11/14 22:35:29 Done.
183 values are used. Currently there are four global record codes. To make these
jvoung (off chromium) 2014/07/28 19:20:36 Maybe add a link to the later deep dive?
Karl 2014/11/14 22:35:34 Done.
184 cases clear, and to leave room for lots of future growth in PNaClAsm, these
Jim Stichnoth 2014/07/28 22:52:03 I would remove "lots of", maybe say "to leave ampl
Karl 2014/11/14 22:35:35 Done.
185 special records have record codes close to the value 2**16. Note: Well-formed
186 PNaCl bitcode files do not have record codes >= 2**16.
JF 2014/07/28 20:58:11 You can do superscripts with: 2\ :sup:`16`\ . (no
Karl 2014/11/14 22:35:32 Done.
187
188 A PNaCl record is denoted as follows:
189
190 .. naclcode::
191
192 a: <v0, v1, ... , vN>
193
194 The value *v0* is the record code. The remaining values, *v1* through *vN*, are
JF 2014/07/28 20:58:12 You should use ``code quotes`` here, to be consist
Karl 2014/11/14 22:35:27 Done.
195 parameters that fill in additional information needed by the construct it
196 represents. All records must have a record code. Hence, empty PNaCl records are
197 not allowed. *a* is the index to the abbreviation used to convert the record to
JF 2014/07/28 20:58:11 Same for ``a``
Karl 2014/11/14 22:35:29 Done.
198 a bit sequence.
199
200 While most records (for a given record code) are of the same length, it is not
Jim Stichnoth 2014/07/28 22:52:08 are of --> have ?
Karl 2014/11/14 22:35:35 Done.
201 true of all record codes. Some record codes can have arbitrary length. In
202 particular, function type signatures, call instructions, phi nodes, switch
203 instructions, and global variable initialization records all have variable
204 length. The expected length is predefined and part of the PNaClAsm language. See
205 the corresponding contruct (associated with the record) to determine the
Jim Stichnoth 2014/07/28 22:52:06 construct
Karl 2014/11/14 22:35:34 Done.
206 expected length.
207
208 The PNaCl bitstream writer, which converts records to bit sequences, does this
209 by writing out the abbreviation index used to encode the record, followed by the
210 contents of the record. The details of this are left to the section on
211 :ref:`abbreviations<link_for_abbreviations_section>`. However, at the record
212 level, one important aspect of this appears in block enter records. These
213 records must define how many bits are required to hold abbreviation indices
214 associated with records of that block.
215
216 There are 4 predefined (default) abbreviation indices, used as the default
217 abbreviations for PNaCl records. They are:
218
219 0
220 Abbreviation index for the abbreviation used to bit-encode an exit block
221 record.
222
223 1
224 Abbreviation index for the abbreviation used to bit-encode an enter block
225 record.
226
227 2
228 Abbreviation index for the abbreviation used to bit-encode a user-defined
229 abbreviation. Note: User defined abbreviations are also encoded as records,
230 and hence need an abbreviation index to bit-encode them.
231
232 3
233 Abbreviation index for the default abbreviation to bit-encode all other
234 records in the bitcode file.
235
236 A block may (in addition), define a list of block specific, user-defined,
Jim Stichnoth 2014/07/28 22:52:03 may (in addition), --> may, in addition, ?
Karl 2014/11/14 22:35:30 Done.
237 abbreviations (of length *U*). The number of bits *B* specified for an enter
238 record must be sufficiently large such that
239
240 .. naclcode::
241
242 2**B >= U + 4
243
244 In addition, the upper limit for B is 32.
245
246 PNaClAsm requires that you specify the number of bits needed to read
Jim Stichnoth 2014/07/28 22:52:08 that you specify --> specifying
Karl 2014/11/14 22:35:32 Done.
247 abbreviations as part of the enter block record. This allows the PNaCl bitcode
248 reader/writer to use the specified number of bits to encode abbreviation
249 indices.
250
251 PNaCl Identifiers
252 =================
253
254 A program is defined as a sequence of top-level *blocks*. Blocks can be nested
255 within other blocks. Each block defines a sequence of records.
256
257 Most of the records, within a block, also define unique values. Each unique
258 value is given a corresponding unique identifier (i.e. *ID*). In PNaClAsm. each
Jim Stichnoth 2014/07/28 22:52:07 PNaClAsm. --> PNaClAsm, (period to comma)
Karl 2014/11/14 22:35:30 Done.
259 kind of block defines its own kind of identifiers. The names of these
260 identifiers are defined by concatenating a prefix character ('@' or '%'), the
261 kind of block (a single character), and a suffix index. The suffix index is
262 defined by the positional location of the defined value within the records of
263 the corresponding block. The indices are all zero based, meaning that the first
264 defined value (within a block) is defined using index 0.
265
266 Identifiers are categorized into two types, *local* and *global*. Local
267 identifiers are identifiers that are associated with the implementation of a
268 single function. In that sense, they are local to the block they appear in.
269
270 All other identifiers are global. This split is intentional. Global identifiers
271 are used by multiple functions, and therefore must be known in all function
272 implementations. Local identifiers only apply to a single function, and can be
273 reused between functions. The *PNaCl translator* uses this separation to
274 parallelize the compilation of functions.
275
276 In general, global identifiers are tied to a specific type of block. Local
jvoung (off chromium) 2014/07/28 19:20:35 There's some redundancy between this paragraph and
Karl 2014/11/14 22:35:29 Done.
277 identifiers are unique to the function block they appear in.
278
279 Note that local abbreviation identifiers are unique to the block they appear
280 in. Global abbreviation identifiers are only unique to the block type they are
281 defined for. Different block types can reuse global abbreviation identifiers.
282
283 Global identifiers use the prefix character *'@'* while local identifiers use
284 the prefix character *'%'*.
JF 2014/07/28 20:58:12 I'd just use ``code quotes`` here too. Also 5 para
Karl 2014/11/14 22:35:27 Done.
285
286 Note that by using positional location to define identifiers (within a block),
287 the values defined in PNaCl bitcode files need not be explicitly included in the
288 bitcode file. Rather, they are inferred by the (ordered) position of the record
289 in the block. This is also intentional. It is used to reduce the amount of data
290 that must be (explicitly) passed to the PNaCl translator, and downloaded though
Jim Stichnoth 2014/07/28 22:52:05 though --> through (or "over" or "via")
Karl 2014/11/14 22:35:28 Done.
291 the internet.
Jim Stichnoth 2014/07/28 18:21:07 Internet?
Karl 2014/11/14 22:35:29 Changed to 'cloud'.
292
293 In general, most of the records within blocks are assumed to be topologically
294 sorted, putting value definitions before their uses. This implies that records
295 do not need to encode data if they can deduce the corresponding information from
296 their uses.
297
298 The most common use of this is that many instructions use the type of their
299 operands to determine the type of the instruction. Again, this is
300 intentional. It allows less information to be stored.
301
302 However, for function blocks (which define instructions), no topological sort
303 exists. Loop carried value dependencies simply do not allow topologically
304 sorting. To deal with this, function blocks have a notion of a forward
305 (instruction value) declaration. These declarations must appear before any of
306 the uses of that value, if the (instruction) value is defined later in the
307 function than its first use (see :ref:`forward type
308 declarations<link_for_forward_type_declaration_section>`).
309
310 The kinds of identifiers used in PNaClAsm are:
311
312 @a
313 Global abbreviation identifier.
314
315 %a
316 Block local abbreviation identifier.
317
318 %b
319 Function local basic block identifier.
320
321 %c
322 Function local constant identifier.
323
324 @f
325 Global function address identifier.
326
327 @g
328 Global variable/constant address identifier.
329
330 %p
331 Function local parameter identifier.
332
333 @t
334 Global type identifier.
335
336 %v
337 Function local instruction generated value identifier.
338
339 Conventions For Describing Records
340 ==================================
341
342 PNaClAsm is the textual representation of PNaCl records. Each PNaCl record is
343 described by a corresponding PNaClAsm construct. These constructs are described
344 using syntax rules, and semantics on how they are converted to records. Along
345 with the rules, is a notion of :ref:`link_for_global_state_section`. The global
jvoung (off chromium) 2014/07/28 19:20:35 For "notion of ... link_for_global_state_section"
Karl 2014/11/14 22:35:29 Good point. Fixing.
346 state is updated by syntax rules. The purpose of the global state is to track
347 positional dependencies between records.
348
349 For each PNaCl construct, we define multiple subsections. The **Syntax**
350 subsection defines a syntax rule for the construct. The **Record** subsection
351 defines the corresponding record associated with the syntax rule. The
352 **Semantics** subsection describes the semantics associated with the record, in
353 terms of data within the globa state and the corresponding syntax. It also
Jim Stichnoth 2014/07/28 18:21:08 global
Karl 2014/11/14 22:35:30 Done.
354 includes other high-level semantics, when appropriate.
355
356 The **Constraints** subsection (if present) defines any constraints associated
357 with the construct, including the global state. The **Updates** subsection (if
358 present) defines how the global state is updated when the construct is
359 processed. The **Examples** subsection gives one (or more) examples of using
Jim Stichnoth 2014/07/28 22:52:09 remove parentheses?
Karl 2014/11/14 22:35:28 Done.
360 the corresponding PNaClAsm construct.
361
362 Some semantics subsections use functions to compute values. The meaning of
363 functions can be found in :ref:`link_for_support_functions_section`.
jvoung (off chromium) 2014/07/28 19:20:35 similar, does this "found in :ref:..." end up show
Karl 2014/11/14 22:35:32 Just checked. If you don't specify text with a ref
364
365 The syntax rule may include the abbreviation to use, when converting to a
366 bit-sequence. These abbreviations, if allowed, are at the end of the construct,
367 and enclosed in *<* and *>* brackets. These abbreviation are optional in the
Jim Stichnoth 2014/07/28 22:52:09 abbreviations
Karl 2014/11/14 22:35:29 Done.
368 syntax, and can be omitted. If they are used, the abbreviation brackets are part
369 of the actual syntax of the construct. If the abbreviation is omitted, the
370 default abbreviation index is used. To make it clear that abbreviations are
371 optional, syntax rules separate abbreviations using plenty of whitespace.
372
373 Within a syntax rule, lower case characters are literal values. Sequences of
374 upper case alphanumeric characters are named values. if we mix lower and upper
jvoung (off chromium) 2014/07/28 19:20:34 "if" -> "If"
Karl 2014/11/14 22:35:31 Done.
375 case letters within a name appearing in a syntax rule, the lower case letters
376 are literal while the upper case sequence of alphanumeric charaters denote rule
Jim Stichnoth 2014/07/28 18:21:08 characters
Karl 2014/11/14 22:35:31 Done.
377 specific values. The valid values for each of these names will be defined in
378 the corresponding semantics and constraints subsections.
379
380 For example, consider the following syntax rule:
381
382 .. naclcode::
383
384 %vN = add T O1, O2; <A>
385
386 This rule defines a PNaClAsm add instruction. This construct defines an
387 instruction that adds two values (*O1* and *O2*) to generate instruction value
388 *%vN*. The types of the arguments, and the result, are all of type *T*. If
389 abbreviation ID *A* is present, the record is encoded using that
390 abbreviation. Otherwise the corresponding default abbreviation (3) is used.
391
392 To be concrete, the syntactic rule above defines the structure of the following
393 PNaClAsm examples.
394
395 .. naclcode::
396
397 %v10 = add i32 %v1, %v2; <@a5>
398 %v11 = add i32 %v10, %v3;
399
400 In addition to specifying the syntax, each syntax rule can also also specify the
401 contents of the corresponding record in the corresponding record subsection. In
402 simple cases, the elements of the corresponding record are predefined (literal)
403 constants. Otherwise the record element is a name that is defined by the other
jvoung (off chromium) 2014/07/28 19:20:34 At least to me, this sentence is a bit hard to und
Karl 2014/11/14 22:35:28 Tried cleaning this up (including using identifier
404 subsections associated with the construct.
405
406 Factorial Example
407 =================
408
409 This section provides a simple example of a PNaCl bitcode file. Its contents
410 describe a bitcode file that only defines a function to compute the factorial
411 value of a number.
412
413 In C, the factorial function can be defined as:
414
415 .. naclcode::
416
417 int fact(int n) {
418 if (n == 1) return 1;
419 return n * fact(n-1);
420 }
421
422 Compiling this into a PNaCl bitcode file, and dumping out its contents with
423 utility *pnacl-bcdis*, the corresponding output is:
424
425 .. naclcode::
426
427 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, 88, 69)
428 | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2
429 | 0> |
430 16:0|1: <65535, 8, 2> |module { // BlockID = 8
431 24:0| 3: <1, 1> | version 1;
432 26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0
433 36:0| 0: <65534> | }
434 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
435 48:0| 3: <1, 4> | count 4;
436 50:4| 3: <7, 32> | @t0 = i32;
437 53:6| 3: <2> | @t1 = void;
438 55:4| 3: <21, 0, 0, 0> | @t2 = i32 (i32);
439 59:4| 3: <7, 1> | @t3 = i1;
440 62:0| 0: <65534> | }
441 64:0| 3: <8, 2, 0, 0, 0> | define external i32 @f0(i32);
442 68:6| 1: <65535, 19, 2> | globals { // BlockID = 19
443 76:0| 3: <5, 0> | count 0;
444 78:4| 0: <65534> | }
445 80:0| 1: <65535, 14, 2> | valuesymtab { // BlockID = 14
446 88:0| 3: <1, 0, 102, 97, 99, | @f0 : "fact";
447 | 116> |
448 96:4| 0: <65534> | }
449 100:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0) {
450 | | // BlockID = 12
451 108:0| 3: <1, 3> | blocks 3;
452 110:4| 1: <65535, 11, 2> | constants { // BlockID = 11
453 120:0| 3: <1, 0> | i32:
454 122:4| 3: <4, 2> | %c0 = i32 1;
455 125:0| 0: <65534> | }
456 | | %b0:
457 128:0| 3: <28, 2, 1, 32> | %v0 = icmp eq i32 %p0, %c0;
458 132:6| 3: <11, 1, 2, 1> | br i1 %v0, label %b1, label %b2;
459 | | %b1:
460 136:6| 3: <10, 2> | ret i32 %c0;
461 | | %b2:
462 139:2| 3: <2, 3, 2, 1> | %v1 = sub i32 %p0, %c0;
463 143:2| 3: <34, 0, 5, 1> | %v2 = call i32 @f0(i32 %v1);
464 148:0| 3: <2, 5, 1, 2> | %v3 = mul i32 %p0, %v2;
465 152:0| 3: <10, 1> | ret i32 %v3;
466 154:4| 0: <65534> | }
467 156:0|0: <65534> |}
468
469 Note that there are three columns in this output. The first column contains the
470 bit positions of the records within the bitcode file. The second column contains
471 the sequence of records within the bitcode file. The third column contains the
472 corresponding PNaClAsm program.
473
474 Bit positions are defined by a pair *B:N*. *B* is the number of bytes, while *N*
475 is the bit offset within the *Bth* byte. Hence, the bit position (in bits) is:
476
477 .. naclcode::
478
479 B*8 + N
480
481 Hence, the first *header* record is at bit offset 0 (0*8+0). The second record
482 is at bit offset 128 (16*8+0). The third record is at bit offset 192 (24*8+0).
483 The fourth record is at bit offset 212 (26*8+4).
484
485 The header record is a sequence of 16 bytes, defining the contents of the first
486 16 bytes of the bitcode file. These bytes never change, and are expected for all
487 version 2, PNaClBitcode files. The first four bytes define the magic number of
jvoung (off chromium) 2014/07/28 19:20:34 "PNaClBitcode" is that meant to have a space betwe
Karl 2014/11/14 22:35:32 Done.
488 the file, i.e. 'PEXE'. All PEXE bitcode files begin with these four bytes.
489
490 All but the header record has an abbreviation index associated with it. Since no
491 user-defined abbreviations are provided, all records were converted to
492 bitsequences using default abbreviations.
Jim Stichnoth 2014/07/28 18:21:05 bit sequences
Karl 2014/11/14 22:35:27 Done.
493
494 The types block (starting at bit address 40:0), defines 4 types: *i1*, *i32*,
495 *void*, and function signature *i32 (i32)*.
496
497 Bit address 64:0 declares the factorial function address @f0, and its
498 corresponding type signature. Bit address 88:0 associates the name "fact" with
499 function address @f0.
500
501 Bit address 100:0 defines the function block that implements function
502 "fact". The entry point is %b0 (at bit address 128:0). It uses the 32-bit
503 integer constant 1 (defined at bit addresses 122:4). Bit address 128:0 defines
504 an equality comparison of the argument %p0 with 1 (constant %c0). Bit address
505 132:6 defines a conditional branch. If the result of the previous comparison
506 (%v0) is true, the program will branch to block %b1. Otherwise it will branch to
507 block %b2.
508
509 Bit address 136:6 returns constant 1 (%c0) when the input parameter is 1.
510 Instructions between bit address 139:2 and 154:4 compute and return "n *
511 fact(n-1)".
512
513 .. _link_for_memory_blocks_and_alignment_section:
jvoung (off chromium) 2014/07/28 19:20:35 This isn't linked to till later, so can it be move
Karl 2014/11/14 22:35:30 I didn't see a better place to put this, but I wil
514
515 Memory Blocks and Alignment
516 ===========================
517
518 In general, variable and heap allocated data are represented as byte addressable
519 memory blocks. Alignment is address placement of these memory blocks. Alignment
jvoung (off chromium) 2014/07/28 19:20:34 Is there some word missing in the sentence "Alignm
Karl 2014/11/14 22:35:32 Removing the sentence.
520 is always a power of 2, and defines an expectation on the memory address. That
521 is, an alignment is met if the memory address is (evenly) divisible by the
522 alignment. Note that alignment of 0 is never allowed.
523
524 Alignment plays a role at two points:
525
526 * When you create a local/global variable
527
528 * When you load/store data using a pointer.
529
530 PNaClAsm allows most types to be placed at any address, and therefore can
531 have alignment of 1. However, many architectures can load more efficiently
532 if the data has an alignment that is larger than 1. As such, chosing a larger
jvoung (off chromium) 2014/07/28 19:20:35 "chosing" -> "choosing"
Karl 2014/11/14 22:35:34 Done.
533 alignment can make load/stores more efficient.
534
535 On loads and stores, the aligment in the instruction is used to communicate what
Jim Stichnoth 2014/07/28 18:21:05 alignment
Karl 2014/11/14 22:35:35 Done.
536 assumptions the PNaCl translator can make when choosing the appropriate machine
537 instructions. If the alignment is 1, it can't assume anything about the memory
538 address used by the instruction. When the alignment is greater than one, it can
539 use that information to potentially chose a more efficent sequence of
Jim Stichnoth 2014/07/28 18:21:05 efficient
Karl 2014/11/14 22:35:32 Done.
540 instructions to do the load/store.
541
542 When laying out data within a variable, one also considers alignment. The reason
543 for this is that if you want an address to be aligned, within the bytes defining
544 the variable, you must choose an alignment for the variable that guarantees that
545 alignment.
546
547 In PNaClAsm, the valid load/store alignments are:
Jim Stichnoth 2014/07/28 22:52:07 Do we say anything about <16 x i1> alignment?
Karl 2014/11/14 22:35:34 Added not applicable entries since they can be loa
548
549 =========== =========
550 Type Alignment
551 =========== =========
552 i1 1
553 i8 1
554 i16 1
555 i32 1
556 i64 1
557 Float 1, 4
558 Double 1, 8
559 <16 x i8> 1
560 <8 x i16> 2
561 <4 x i32> 4
562 <4 x float> 4
563 =========== =========
564
565 Note that only vectors do not have an alignment value of 1. Hence, they can't be
566 placed at any memory address.
jvoung (off chromium) 2014/07/28 19:20:36 they can't be placed at "an arbitrary" memory addr
Karl 2014/11/14 22:35:31 Done.
567
568 .. _link_for_intrinsic_functions_section:
569
570 Intrinsic functions
Jim Stichnoth 2014/07/28 22:52:03 Functions (capitalized for consistency)
Karl 2014/11/14 22:35:29 Done.
571 ===================
572
573 Intrinsic functions are special in PNaClAsm. They are implemented as specially
574 named (external) function calls. The purpose of these intrinsic functions is to
575 extend the PNaClAsm instruction set with additional functionality that is
576 architecture specific. Hence, they either can't be implemented within PNaClAsm,
577 or a non-architecture specific implementation may be too slow on some
578 architectures. In such cases, the PNaCl translator must fill in the
579 corresponding implementation, since only it knows the architecture it is
580 compiling down to.
581
582 Examples of intrinsic function calls are for concurrent operations, atomic
583 operations, bulk memory moves, thread pointer operations, and long jumps.
584
585 It should be noted that calls to intrinsic functions do not have the same
586 calling type constraints as ordinary functions. That is, an instrisic can use
Jim Stichnoth 2014/07/28 18:21:08 intrinsic
Karl 2014/11/14 22:35:28 Done.
587 any integral type for arguments/results, unlike ordinary functions (which
Jim Stichnoth 2014/07/28 22:52:06 The document has mixed use of "integer type" and "
Karl 2014/11/14 22:35:29 Done.
Karl 2014/11/14 22:35:32 Done.
588 restrict integral types to i32 and i64).
jvoung (off chromium) 2014/07/28 19:20:34 The i32 and i64 parameter/return type restriction
Karl 2014/11/14 22:35:32 Again, moved to appear after sections on instructi
589
590 See the :doc:`PNaCl bitcode reference manual<pnacl-bitcode-abi>` for the full
591 set of intrinsic functions allowed.
592
593 .. _link_for_global_state_section:
594
jvoung (off chromium) 2014/07/28 19:20:35 Can you add something to help w/ transitions betwe
Karl 2014/11/14 22:35:33 Added a "road map" section to describe the remaini
595 Global State
596 ============
597
598 This section describes the global state associated with PNaClAsm. It is used to
599 define contextual data that is carried between records. The following
600 subsections describe each element of the global state.
601
602 Typing
603 ------
604
605 Associated with most identifiers is a type. This type defines what type the
606 corresponding value has. It is defined by the (initially empty) map
607
608 .. naclcode::
609
610 TypeOf: ID -> Type
611
612 For each type in the :ref:`types block<link_for_types_block_section>`, a
613 corresponding inverse map
614
615 .. naclcode::
616
617 TypeID: Type -> ID
618
619 is maintained to convert syntactic types to the corresponding type ID.
620
621 Note: This document assumes that map *TypeID* is automatically maintained during
622 updates to map *TypeOf* (when given a type ID). Hence, *updates* subsections
jvoung (off chromium) 2014/07/28 19:20:35 capitalize "Updates" for consistency
Karl 2014/11/14 22:35:28 Done.
623 will not contain assignments to this map.
624
625 Associated with each function identifier is its type signature. This is
626 different than the type of the function identifier, since function identifiers
627 represent the function addrress which is a pointer (and pointers are alwyas
Jim Stichnoth 2014/07/28 18:21:05 address
Jim Stichnoth 2014/07/28 18:21:06 always
Karl 2014/11/14 22:35:33 Done.
Karl 2014/11/14 22:35:34 Done.
628 implemented as a 32-bit integer following the ILP32 data model).
629
630 Function type signatures are maintained using:
631
632 .. naclcode::
633
634 TypeOfFcn: ID -> Type
635
636 In addition, if a function address has an implementing block, there is a
637 corresponding implementation associated with the function address. To capture
638 this association, we use the set:
jvoung (off chromium) 2014/07/28 19:20:35 nit: Just a set of IDs doesn't seem sufficient to
Karl 2014/11/14 22:35:30 Changed to say: "To indicate which functions have
639
640 .. naclcode::
641
642 DefiningFcnIDs: set(ID)
643
644 ID Counters
645 -----------
646
647 Each block defines one (or more) kinds of values. Value indices are generated
Jim Stichnoth 2014/07/28 22:52:08 remove parentheses
Karl 2014/11/14 22:35:29 Done.
648 sequentially, starting at zero. To capture this, the following counters are
649 defined:
650
651 NumTypes
652 The number of types defined so far (in the types block)
Jim Stichnoth 2014/07/28 22:52:04 period at the end for consistency
Karl 2014/11/14 22:35:33 Done.
653
654 NumFuncAddresses
655 The number of function addresses defined so far (in the module block).
656
657 NumGlobalAddresses
658 The number of global variable/constant addresses defined so far (in the
659 globals block).
660
661 NumParams
662 The number of parameters defined for a function.
jvoung (off chromium) 2014/07/28 19:20:34 So this is the only one that's not "so far".
Karl 2014/11/14 22:35:33 Yes. Mainly because we introduce them all at once,
663
664 NumFcnConsts
665 The number of constants defined in a function so far.
666
667 NumBasicBlocks
668 The number of basic blocks defined so far (within a function block).
669
670 NumValuedInsts
671 The number of instructions, generating values, defined so far (within a
672 function block) so far.
jvoung (off chromium) 2014/07/28 19:20:34 "so far" appears twice here
Karl 2014/11/14 22:35:31 Done.
673
674 Size Variables
675 --------------
676
677 A number of blocks define expected sizes of constructs. These sizes are recorded
678 in the following size variables:
679
680 ExpectedBasicBlocks
681 The expected number of basic blocks within a function implementation.
682
683 ExpectedTypes
684 The expected number of types defined in the types block.
685
686 ExpectedGlobals
687 The expected number of global variable/constant addresses in the globals
688 block.
689
690 ExpectedInitializers
691 The expected number of initializers for a global variable/constant address in
692 the globals block.
693
694 Other Variables
695 ---------------
696
697 EnclosingFcnID
698 The function ID of the function block being processed.
699
700 ConstantsSetType
701 Holds the type associated with the last *set type* record in the
702 constants block. Note: at the beginning of each constants block, this
703 variable is set to type void.
704
705 Global records
Jim Stichnoth 2014/07/28 22:52:04 capitalize Records
Karl 2014/11/14 22:35:34 Done.
706 ==============
707
708 There are four global PNaCl records, each having its own record code. These
709 global records are:
710
711 Header
712 The header record is the first record of a PNaCl bitcode file, and identifies
713 the file's magic number, as well as the bitcode version it uses. The record
714 defines the sequence of bytes that make up the header and uniquely identifies
715 the file as a PNaCl bitcode file.
716
717 Enter
718 An enter record defines the beginning of a block. Since blocks can be nested,
719 one can appear inside other blocks, as well as at the top level.
720
721 Exit
722 An exit record defines the end of a block. Hence, it must appear in every
723 block, to end the block.
724
725 Abbreviation
726 An abbreviation record defines a user-defined abbreviation to be applied to
727 records within blocks. Abbreviation records appearing in the abbreviations
728 block define global abbreviations. All other abbreviations are local to the
729 block they appear in, and can only be used in that block.
730
731 All special records can't have user-defined abbreviations associated with
jvoung (off chromium) 2014/07/28 19:20:35 Are "special records" the same as "global records"
Karl 2014/11/14 22:35:34 Good point. Missed this when I changed from "speci
732 them. The default abbreviation is always used.
733
734 Header Record
735 -------------
736
737 The header record must be the first record in the file. It is the only record in
738 the bitcode file that doesn't have a corresponding construct in PNaClAsm. In
739 addition, no abbreviation index is associated with it.
740
741 **Syntax**
Sam Clegg 2014/07/28 18:28:31 Would it be better use a third level of section he
Karl 2014/11/14 22:35:35 I don't really want to distinguish these. The reas
742
743 There is no syntax for header records in PNaClAsm.
744
745 **Record**
746
747 .. naclcode::
748
749 <65532, 80, 69, 88, 69, 1, 0, 8, 0, 17, 0, 4, 0, 2, 0, 0, 0>
750
751 **Semantics**
752
753 The header record defines the initial sequence of bytes that must appear at the
754 beginning of all (PNaCl bitcode version 2) files. That sequence is the list of
755 bytes inside the record (excluding the record code). As such, it uniquely
756 identifies all PNaCl bitcode files.
757
758 **Examples**
759
760 There are no examples for the header record, since it is not part of PNaClAsm.
jvoung (off chromium) 2014/07/28 19:20:34 Instead of "since it is not part of", how about "s
Karl 2014/11/14 22:35:30 Done.
761
762 .. _link_for_enter_block_record_section:
763
764 Enter Block Record
765 ------------------
766
767 Block records can be top-level, as well as nested in other blocks. Blocks must
768 begin with an *enter* record, and end with an *exit* record.
769
770 **Syntax**
771
772 .. naclcode::
773
774 N { <B>
775
776 **Record**
777
778 .. naclcode::
Sam Clegg 2014/07/28 18:28:31 If you just want to fixed width font than I prefer
Karl 2014/11/14 22:35:28 Ok. I did not see that in the available documentat
779
780 1: <65535, ID, B>
781
782 **Semantics**
783
784 Enter block records define the beginning of a block. *B*, if present, is the
785 number of bits needed to represent all possible abbreviation indices used within
786 the block. If omitted, B=2 is assumed.
787
788 The block *ID* value is dependent on the name *N*. Valid names and corresponding
789 *BlockID* values are defined as follows:
790
791 ============= ========
792 N Block ID
793 ============= ========
794 abbreviations 0
795 constants 11
796 function 12
797 globals 19
798 module 8
799 types 17
800 valuesymtab 14
801 ============= ========
802
803 Note: For readability, PNaClAsm defines a more readable form of a function block
804 enter record. See :ref:`function blocks<link_for_function_blocks_section>` for
805 more details.
806
807 **Examples**
808
809 .. naclcode::
810
811 16:0|1: <65535, 8, 2> |module { // BlockID = 8
812 24:0| 3: <1, 1> | version 1;
813 26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0
814 36:0| 0: <65534> | }
815 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
816 48:0| 3: <1, 2> | count 2;
817 50:4| 3: <2> | @t0 = void;
818 52:2| 3: <21, 0, 0> | @t1 = void ();
819 55:4| 0: <65534> | }
820 56:0| 3: <8, 1, 0, 1, 0> | declare external void @f0();
821 60:6| 1: <65535, 19, 2> | globals { // BlockID = 19
822 68:0| 3: <5, 0> | count 0;
823 70:4| 0: <65534> | }
824 72:0|0: <65534> |}
825
826 Exit Block Record
827 -----------------
828
829 Block records can be top-level, as well as nested, records. Blocks must begin
830 with an *enter* record, and end with an *exit* record.
831
832 **Syntax**
833
834 .. naclcode::
835
836 }
837
838 **Record**
839
840 .. naclcode::
841
842 0: <65534>
843
844 **Semantics**
845
846 All exit records are identical, no matter what block they are ending. An exit
847 record defines the end of the block.
848
849 **Examples**
850
851 .. naclcode::
852
853 16:0|1: <65535, 8, 2> |module { // BlockID = 8
854 24:0| 3: <1, 1> | version 1;
855 26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0
856 36:0| 0: <65534> | }
857 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
858 48:0| 3: <1, 2> | count 2;
859 50:4| 3: <2> | @t0 = void;
860 52:2| 3: <21, 0, 0> | @t1 = void ();
861 55:4| 0: <65534> | }
862 56:0| 3: <8, 1, 0, 1, 0> | declare external void @f0();
863 60:6| 1: <65535, 19, 2> | globals { // BlockID = 19
864 68:0| 3: <5, 0> | count 0;
865 70:4| 0: <65534> | }
866 72:0|0: <65534> |}
867
868 Abbreviation Record
869 -------------------
870
871 Abbreviation records define abbreviations. See
872 :ref:`link_for_abbreviations_section` for details on how abbreviations should be
873 written. This section only presents the mechanical details for converting
874 an abbreviation into a PNaCl record.
875
876 **Syntax**
877
878 .. naclcode::
879
880 A = abbrev <E1, ... , EM>;
881
882 **Record**
883
884 .. naclcode::
885
886 <65533, M, EE1, ... , EEM>
887
888 **Semantics**
889
890 Defines an abbreviation *A* as the sequence of encodings *E1* through *EM*. If
891 the abbreviation appears within the abbreviations block, *A* must be a global
892 abbreviation. Otherwise, *A* must be a local abbreviation.
893
894 Abbreviations within a block (or a section within the abbreviations block), must
895 be enumerated in order, starting at index 0.
896
897 Valid encodings *Ei*, and the corresponding sequence of (unsigned) integers
898 *EEi*, ( for 1 <= i <= M) are defined by the following table:
899
900 ======== ======= ===============================================================
901 Ei EEi Form
902 ======== ======= ===============================================================
903 C 1, C Literal C in corresponding position in record.
904 Fixed(N) 0, 1, N Encode value as a fixed sequence of N bit.
jvoung (off chromium) 2014/07/28 19:20:35 "N bit" -> "N bits"
Karl 2014/11/14 22:35:32 Done.
905 Vbr(N) 0, 2, N Encode value using a variable bit rate of N
jvoung (off chromium) 2014/07/28 19:20:35 end with period (for consistency w/ the rest of th
Karl 2014/11/14 22:35:32 Done.
906 Char6 0, 4 Encode value as 6-bit char containing characters [a-zA-Z0-9._].
907 Array 0, 3 Allow zero or more of the enclosed encoding
jvoung (off chromium) 2014/07/28 19:20:36 Clarify what is the "enclosed encoding"? It's the
Karl 2014/11/14 22:35:32 I tried to clean this up, but I'm still not sure i
908 ======== ======= ===============================================================
909
910 Notationally, Array encloses the encoding that immediately follows it, and must
911 appear at the end of the abbreviation.
912
913 **Examples**
914
915 The following example shows the standard abbreviations used by *pnacl-finalize*.
916
917 .. naclcode::
918
919 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, 88, 69)
920 | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2
921 | 0> |
922 16:0|1: <65535, 8, 2> |module { // BlockID = 8
923 24:0| 3: <1, 1> | version 1;
924 26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0
925 36:0| 1: <1, 14> | valuesymtab:
926 38:4| 2: <65533, 4, 0, 1, 3, 0,| @a0 = abbrev <fixed(3), vbr(8),
927 | 2, 8, 0, 3, 0, 1, 8> | array(fixed(8))>;
928 43:2| 2: <65533, 4, 1, 1, 0, 2,| @a1 = abbrev <1, vbr(8),
929 | 8, 0, 3, 0, 1, 7> | array(fixed(7))>;
930 48:0| 2: <65533, 4, 1, 1, 0, 2,| @a2 = abbrev <1, vbr(8),
931 | 8, 0, 3, 0, 4> | array(char6)>;
932 52:1| 2: <65533, 4, 1, 2, 0, 2,| @a3 = abbrev <2, vbr(8),
933 | 8, 0, 3, 0, 4> | array(char6)>;
934 56:2| 1: <1, 11> | constants:
935 58:6| 2: <65533, 2, 1, 1, 0, 1,| @a0 = abbrev <1, fixed(2)>;
936 | 2> |
937 61:7| 2: <65533, 2, 1, 4, 0, 2,| @a1 = abbrev <4, vbr(8)>;
938 | 8> |
939 65:0| 2: <65533, 2, 1, 4, 1, 0>| @a2 = abbrev <4, 0>;
940 68:1| 2: <65533, 2, 1, 6, 0, 2,| @a3 = abbrev <6, vbr(8)>;
941 | 8> |
942 71:2| 1: <1, 12> | function:
943 73:6| 2: <65533, 4, 1, 20, 0, | @a0 = abbrev <20, vbr(6), vbr(4),
944 | 2, 6, 0, 2, 4, 0, 2, | vbr(4)>;
945 | 4> |
946 79:1| 2: <65533, 4, 1, 2, 0, 2,| @a1 = abbrev <2, vbr(6), vbr(6),
947 | 6, 0, 2, 6, 0, 1, 4> | fixed(4)>;
948 84:4| 2: <65533, 4, 1, 3, 0, 2,| @a2 = abbrev <3, vbr(6),
949 | 6, 0, 1, 2, 0, 1, 4> | fixed(2), fixed(4)>;
950 89:7| 2: <65533, 1, 1, 10> | @a3 = abbrev <10>;
951 91:7| 2: <65533, 2, 1, 10, 0, | @a4 = abbrev <10, vbr(6)>;
952 | 2, 6> |
953 95:0| 2: <65533, 1, 1, 15> | @a5 = abbrev <15>;
954 97:0| 2: <65533, 3, 1, 43, 0, | @a6 = abbrev <43, vbr(6),
955 | 2, 6, 0, 1, 2> | fixed(2)>;
956 101:2| 2: <65533, 4, 1, 24, 0, | @a7 = abbrev <24, vbr(6), vbr(6),
957 | 2, 6, 0, 2, 6, 0, 2, | vbr(4)>;
958 | 4> |
959 106:5| 1: <1, 19> | globals:
960 109:1| 2: <65533, 3, 1, 0, 0, 2,| @a0 = abbrev <0, vbr(6),
961 | 6, 0, 1, 1> | fixed(1)>;
962 113:3| 2: <65533, 2, 1, 1, 0, 2,| @a1 = abbrev <1, vbr(8)>;
963 | 8> |
964 116:4| 2: <65533, 2, 1, 2, 0, 2,| @a2 = abbrev <2, vbr(8)>;
965 | 8> |
966 119:5| 2: <65533, 3, 1, 3, 0, 3,| @a3 = abbrev <3, array(fixed(8))>
967 | 0, 1, 8> | ;
968 123:2| 2: <65533, 2, 1, 4, 0, 2,| @a4 = abbrev <4, vbr(6)>;
969 | 6> |
970 126:3| 2: <65533, 3, 1, 4, 0, 2,| @a5 = abbrev <4, vbr(6), vbr(6)>;
971 | 6, 0, 2, 6> |
972 130:5| 0: <65534> | }
973 132:0| 1: <65535, 17, 3> | types { // BlockID = 17
974 140:0| 2: <65533, 4, 1, 21, 0, | %a0 = abbrev <21, fixed(1),
975 | 1, 1, 0, 3, 0, 1, 2> | array(fixed(2))>;
976 144:7| 3: <1, 3> | count 3;
977 147:4| 3: <7, 32> | @t0 = i32;
978 150:7| 4: <21, 0, 0, 0, 0> | @t1 = i32 (i32, i32); <%a0>
979 152:7| 3: <2> | @t2 = void;
980 154:6| 0: <65534> | }
981 156:0| 3: <8, 1, 0, 0, 0> | define external i32 @f0(i32, i32);
982 160:6| 1: <65535, 19, 4> | globals { // BlockID = 19
983 168:0| 3: <5, 0> | count 0;
984 170:6| 0: <65534> | }
985 172:0| 1: <65535, 14, 3> | valuesymtab { // BlockID = 14
986 180:0| 6: <1, 0, 102> | @f0 : "f"; <@a2>
987 182:7| 0: <65534> | }
988 184:0| 1: <65535, 12, 4> | function i32 @f0(i32 %p0, i32 %p1) {
989 | | // BlockID = 12
990 192:0| 3: <1, 1> | blocks 1;
991 | | %b0:
992 194:6| 5: <2, 2, 1, 0> | %v0 = add i32 %p0, %p1; <@a1>
993 197:2| 5: <2, 3, 1, 0> | %v1 = add i32 %p0, %v0; <@a1>
994 199:6| 8: <10, 1> | ret i32 %v1; <@a4>
995 201:0| 0: <65534> | }
996 204:0|0: <65534> |}
997
998 .. _link_for_types_block_section:
999
1000 Types Block
1001 ===========
1002
1003 The types block defines all types used in a program. It must appear in the
1004 module block, before any function address records, the globals block, the
1005 valuesymtab block, and any function blocks.
1006
1007 All types used in a program must be defined in the types block. Many PNaClAsm
1008 constructs allow one to use explicit type names, rather than the type
1009 identifiers defined by this block. However, they are internally converted to the
1010 corresponding type identifer in the types block. Hence, the requirement that the
Jim Stichnoth 2014/07/28 18:21:07 identifier
Karl 2014/11/14 22:35:27 Done.
1011 types block must appear early in the module block.
1012
1013 Each record in the types block defines a type used by the program. Types can be
1014 broken into the following groups:
1015
1016 Primitive value types
1017 Defines the set of base types for values. This includes various sizes of
1018 integral and floating types.
Jim Stichnoth 2014/07/28 22:52:07 There are a lot of uses of "floating type", and a
Karl 2014/11/14 22:35:34 Changed to use "floating point" everywhere.
1019
1020 Void type
1021 A primitive type that doesn't represent any value and has no size.
1022
1023 Function types
1024 The type signatures of functions.
1025
1026 Vector type
1027 Defines vectors of primitive types.
1028
1029 In addition, any type that is not defined using another type is a primitive
1030 type. All other types (i.e. function and vector) are composite types.
1031
1032 Types must be defined in a topological order, causing primitive types to appear
1033 before the composite types that use them. Each type must be unique. There are no
1034 additional restrictions on the order that types can be defined in a types block.
1035
1036 The following subsections introduce each valid PNaClAsm type, and the
1037 corresponding PNaClAsm construct that defines the type. Types not defined in the
1038 types block, can't be used in a PNaCl program.
1039
1040 The first record of a types block must be a *count* record, defining how many
1041 types are defined by the types block. All remaining records defines a type. The
Jim Stichnoth 2014/07/28 22:52:04 defines --> define
Karl 2014/11/14 22:35:31 Done.
1042 following subsections define valid records within a types block. The order of
1043 type records is important. The position of each defining record implicitly
1044 defines the type ID that will be used to denote that type, within other PNaCl
1045 records of the bitcode file.
1046
1047 To make this more concrete, consider the following example types block:
1048
1049 .. naclcode::
1050
1051 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
1052 48:0| 3: <1, 4> | count 4;
1053 50:4| 3: <7, 32> | @t0 = i32;
1054 53:6| 3: <3> | @t1 = float;
1055 55:4| 3: <2> | @t2 = void;
1056 57:2| 3: <21, 0, 2, 0, 1> | @t3 = void (i32, float);
1057 62:0| 0: <65534> | }
1058
1059 This example defines a types block that defines four type IDs:
1060
1061 @t0
1062 A 32-bit integer type.
1063 @t1
1064 A 32-bit floating type.
1065 @t2
1066 The void type.
1067 @t3
1068 A function, taking 32-bit integer and float arguments that returns void.
1069
1070 Count Record
1071 ------------
1072
1073 The *count record* defines how many types are defined in the types
1074 block. Following the types count record are records that define types used by
1075 the PNaCl program.
1076
1077 **Syntax**
1078
1079 .. naclcode::
1080
1081 count: N; <A>
1082
1083 **Record**
1084
1085 .. naclcode::
1086
1087 AA: <1, N>
1088
1089 **Semantics**
1090
1091 This construct defines the number of types used by the PNaCl program. *N* is
1092 the number of types defined in the types block. It is an error to define more
1093 (or fewer) types than value *N*, within the enclosing types block.
1094
1095 **Constraints**
1096
1097 .. naclcode::
1098
1099 AA == AbbrevIndex(A)
1100 0 == NumTypes
1101
1102 **Updates**
1103
1104 .. naclcode::
1105
1106 ExpectedTypes = N;
1107
1108 **Examples**
1109
1110 .. naclcode::
1111
1112 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
1113 48:0| 3: <1, 4> | count 4;
1114 50:4| 3: <7, 32> | @t0 = i32;
1115 53:6| 3: <3> | @t1 = float;
1116 55:4| 3: <2> | @t2 = void;
1117 57:2| 3: <21, 0, 2, 0, 1> | @t3 = void (i32, float);
1118 62:0| 0: <65534> | }
1119
1120 Void Type
1121 ---------
1122
1123 The *void* type record defines the void type, which corresponds to the type that
1124 doesn't define any value, and has no size.
1125
1126 **Syntax**
1127
1128 .. naclcode::
1129
1130 @tN = void; <A>
1131
1132 **Record**
1133
1134 .. naclcode::
1135
1136 AA: <2>
1137
1138 **Semantics**
1139
1140 The void type record defines the type that has no values and has no size.
1141
1142 **Constraints**
1143
1144 .. naclcode::
1145
1146 AA == AbbrevIndex(A)
1147 N == NumTypes
1148 NumTypes < ExpectedTypes
1149
1150 **Updates**
1151
1152 .. naclcode::
1153
1154 ++NumTypes;
1155 TypeOf(@tN) = void;
1156
1157 **Examples**
1158
1159 .. naclcode::
1160
1161 @t0 = void;
1162
1163 defines the record
jvoung (off chromium) 2014/07/28 19:20:34 I wanted to check if this was meant to be a comple
Karl 2014/11/14 22:35:29 Simplified to a single case. Also removed partial
1164
1165 .. naclcode::
1166
1167 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
1168 48:0| 3: <1, 4> | count 4;
1169 50:4| 3: <7, 32> | @t0 = i32;
1170 53:6| 3: <3> | @t1 = float;
1171 55:4| 3: <2> | @t2 = void;
1172 57:2| 3: <21, 0, 2, 0, 1> | @t3 = void (i32, float);
1173 62:0| 0: <65534> | }
1174
1175 Integer Types
1176 -------------
1177
1178 PNaClAsm allows integral types for various bit sizes. Valid bit sizes are 1, 8,
1179 16, 32, and 64. Integers can be signed or unsigned, but the signed component of
1180 an integer is not specified by the type. Rather, individual instructions
1181 determine whether the value is assumed to be signed or unsigned.
1182
1183 It should be noted that in PNaClAsm, all pointers are implemented as 32-bit
1184 (unsigned) integers. There isn't a separate type for pointers. The only way to
1185 tell that a 32-bit integer is a pointer, is when it is used in an instruction
1186 that requires a pointer (such as load and store instructions).
1187
1188 **Syntax**
1189
1190 .. naclcode::
1191
1192 @tN = iB; <A>
1193
1194 **Record**
1195
1196 .. naclcode::
1197
1198 AA: <7, B>
1199
1200 **Semantics**
1201
1202 An integer type record defines an integral type. *B* defines the number of bits
1203 of the integral type.
1204
1205 **Constraints**
1206
1207 .. naclcode::
1208
1209 AA == AbbrevIndex(A)
1210 N == NumTypes
1211 NumTypes < ExpectedTypes
1212 B in {1, 8, 16, 32, 64}
1213
1214 **Updates**
1215
1216 .. naclcode::
1217
1218 ++NumTypes;
1219 TypeOf(@tN) = iB;
1220
1221 **Examples**
1222
1223 .. naclcode::
1224
1225 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
1226 48:0| 3: <1, 7> | count 7;
1227 50:4| 3: <7, 64> | @t0 = i64;
1228 53:6| 3: <7, 1> | @t1 = i1;
1229 56:2| 3: <7, 8> | @t2 = i8;
1230 58:6| 3: <7, 16> | @t3 = i16;
1231 61:2| 3: <7, 32> | @t4 = i32;
1232 64:4| 3: <21, 0, 0, 1> | @t5 = i64 (i1);
1233 68:4| 3: <2> | @t6 = void;
1234 70:2| 0: <65534> | }
1235
1236 32-Bit Floating Point Type
1237 --------------------------
1238
1239 PNaClAsm allows computation on 32-bit floating point values. A float type record
1240 defines the 32-bit floating point type.
1241
1242 **Syntax**
1243
1244 .. naclcode::
1245
1246 @tN = float; <A>
1247
1248 **Record**
1249
1250 .. naclcode::
1251
1252 AA: <3>
1253
1254 **Semantics**
1255
1256 A floating type record defines the 32-bit floating point type.
1257
1258 **Constraints**
1259
1260 .. naclcode::
1261
1262 AA == AbbrevIndex(A).
1263 N == NumTypes
1264 NumTypes < ExpectedTypes
1265
1266 **Updates**
1267
1268 .. naclcode::
1269
1270 ++NumTypes;
1271 TypeOf(@tN) = float;
1272
1273 **Examples**
1274
1275 .. naclcode::
1276
1277 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
1278 48:0| 3: <1, 4> | count 4;
1279 50:4| 3: <4> | @t0 = double;
1280 52:2| 3: <3> | @t1 = float;
1281 54:0| 3: <21, 0, 0, 1> | @t2 = double (float);
1282 58:0| 3: <2> | @t3 = void;
1283 59:6| 0: <65534> | }
1284
1285 64-bit Floating Point Type
1286 --------------------------
1287
1288 PNaClAsm allows computation on 64-bit floating point values. A double type
1289 record defines the 64-bit floating point type.
1290
1291 **Syntax**
1292
1293 .. naclcode::
1294
1295 @tN = double; <A>
1296
1297 **Record**
1298
1299 .. naclcode::
1300
1301 AA: <4>
1302
1303 **Semantics**
1304
1305 A double type record defines the 64-bit floating point type.
1306
1307 **Constraints**
1308
1309 .. naclcode::
1310
1311 AA == AbbrevIndex(A)
1312 N == NumTypes
1313 NumTypes < ExpectedTypes
1314
1315 **Updates**
1316
1317 .. naclcode::
1318
1319 ++NumTypes;
1320 TypeOf(@tN) = double;
1321
1322 **Examples**
1323
1324 .. naclcode::
1325
1326 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
1327 48:0| 3: <1, 4> | count 4;
1328 50:4| 3: <4> | @t0 = double;
1329 52:2| 3: <3> | @t1 = float;
1330 54:0| 3: <21, 0, 0, 1> | @t2 = double (float);
1331 58:0| 3: <2> | @t3 = void;
1332 59:6| 0: <65534> | }
1333
1334 Vector Types
1335 ------------
1336
1337 A vector type is a derived type that represents a vector of elements. Vector
1338 types are used when multiple primitve data are operated in parallel using a
Jim Stichnoth 2014/07/28 18:21:08 primitive
Karl 2014/11/14 22:35:34 Done.
1339 single instruction (SIMD). A vector type requires a size (number of elements)
1340 and an uderlying primitive data type.
Jim Stichnoth 2014/07/28 22:52:04 underlying
Karl 2014/11/14 22:35:34 Done.
1341
1342 **Syntax**
1343
1344 .. naclcode::
1345
1346 @tN = < E x T > <A>
1347
1348 **Record**
1349
1350 .. naclcode::
1351
1352 AA: <12, E, TT>
1353
1354 **Semantics**
1355
1356 The vector type defines a vector of elements. *T* is the type of each
1357 element. *E* is the number of elements in the vector.
1358
1359 Vector types can only be defined on i1, i8, i16, i32, and float.
1360 All vector types, except those on i1, must contain exactly 128 bits.
1361 The valid element sizes are restricted as follows:
1362
1363 ====== ===================
1364 Type Valid element sizes
1365 ====== ===================
1366 i1 4, 8, 16
1367 i8 16
1368 i16 8
1369 i32 4
1370 float 4
1371 ====== ===================
1372
1373 **Constraints**
1374
1375 .. naclcode::
1376
1377 AA == AbbrevIndex(A)
1378 TT == AbsoluteIndex(TypeID(T))
1379 N == NumTypes
1380 NumTypes < ExpectedTypes
1381
1382 *Updates*
jvoung (off chromium) 2014/07/28 19:20:36 double star the Updates for consistency?
Karl 2014/11/14 22:35:33 Done.
1383
1384 .. naclcode::
1385
1386 ++NumTypes
1387 TypeOf(@tN) = <E x T>
1388
1389 **Examples**
1390
1391 The following types block defines all valid vector types:
1392
1393 .. naclcode::
1394
1395 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
1396 48:0| 3: <1, 14> | count 14;
1397 50:4| 3: <7, 32> | @t0 = i32;
1398 53:6| 3: <7, 1> | @t1 = i1;
1399 56:2| 3: <2> | @t2 = void;
1400 58:0| 3: <12, 4, 1> | @t3 = <4 x i1>;
1401 61:2| 3: <12, 8, 1> | @t4 = <8 x i1>;
1402 64:4| 3: <12, 16, 1> | @t5 = <16 x i1>;
1403 67:6| 3: <7, 8> | @t6 = i8;
1404 70:2| 3: <12, 16, 6> | @t7 = <16 x i8>;
1405 73:4| 3: <7, 16> | @t8 = i16;
1406 76:0| 3: <12, 8, 8> | @t9 = <8 x i16>;
1407 79:2| 3: <12, 4, 0> | @t10 = <4 x i32>;
1408 82:4| 3: <3> | @t11 = float;
1409 84:2| 3: <12, 4, 11> | @t12 = <4 x float>;
1410 87:4| 3: <21, 0, 2> | @t13 = void ();
1411 90:6| 0: <65534> | }
1412
1413 Function Type
1414 -------------
1415
1416 The *function* type can be thought of as a function signature. It consists of a
1417 return type, and a (possibly empty) list of formal parameter types.
1418
1419 **Syntax**
1420
1421 .. naclcode::
1422
1423 %tN = RT (T1, ... , TM) <A>
1424
1425 **Record**
1426
1427 .. naclcode::
1428
1429 AA: <21, 0, IRT, IT1, ... , ITM>
1430
1431 **Semantics**
1432
1433 The function type defines the signature of a function. *RT* is the return type
1434 of the function, while types *T1* through *TM* are the types of the
1435 arguments. Indices to the corresponding type identifiers are stored in the
1436 corresponding record.
1437
1438 The return value must either be a primitive type, type *void*, or a vector type.
1439 Parameter types can be a primitive or vector type.
1440
1441 For ordinary functions, the only valid integral types that can be used for a
1442 return or parameter type are i32 and i64. All other integral types are not
1443 allowed. For intrisic functions, all integral types are allowed for both return and
Jim Stichnoth 2014/07/28 18:21:06 intrinsic
Jim Stichnoth 2014/07/28 22:52:07 80-char
Karl 2014/11/14 22:35:28 Done.
Karl 2014/11/14 22:35:34 Done.
1444 parameter types.
1445
1446 **Constraints**
1447
1448 .. naclcode::
1449
1450 AA == AbbrevIndex(A)
1451 M >= 0
1452 IRT == AbsoluteIndex(TypeID(RT))
1453 IT1 == AbsoluteIndex(TypeID(T1))
1454 ...
1455 ITM == AbsoluteIndex(TypeID(TM))
1456 N == NumTypes
1457 NumTypes < ExpectedTypes
1458
1459 **Updates**
1460
1461 .. naclcode::
1462
1463 ++NumTypes
1464 TypeOf(@tN) = RT (T1, ... , TM)
1465
1466 **Examples**
1467
1468 .. naclcode::
1469
1470 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
1471 48:0| 3: <1, 7> | count 7;
1472 50:4| 3: <7, 32> | @t0 = i32;
1473 53:6| 3: <3> | @t1 = float;
1474 55:4| 3: <4> | @t2 = double;
1475 57:2| 3: <21, 0, 2, 1> | @t3 = double (float);
1476 61:2| 3: <2> | @t4 = void;
1477 63:0| 3: <21, 0, 4> | @t5 = void ();
1478 66:2| 3: <21, 0, 0, 0, 1, 0, 2>| @t6 =
1479 | | i32 (i32, float, i32, double);
1480 72:4| 0: <65534> | }
1481
1482 .. _link_for_globals_block_section:
1483
1484 Globals block
Jim Stichnoth 2014/07/28 22:52:09 capitalize Block
Karl 2014/11/14 22:35:27 Done.
1485 =============
1486
1487 The globals block defines global addresses of variables and constants, used by
1488 the PNaCl program. It also defines the memory associated with the global
1489 addresses, and how to initialize each global variable/constant. It must appear
1490 in the module block. It must appear after the types block, as well as after all
1491 function address records. But, it must also appear before the valuesymtab block,
1492 and any function blocks.
1493
1494 The globals block begins with a count record, defining how many global addresses
1495 are defined by the PNaCl program. It is then followed by a sequence of records
1496 that defines each global address, and how each global address is initialized.
1497
1498 The standard sequence, for defining global addresses, begins with a global
1499 address record. It is then followed by a sequence of records defining how the
1500 global address is initialized. If the initializer is simple, a single record is
1501 used. Otherwise, the initializer is preceded with a compound record, specifying
1502 a number *N*, followed by sequence of *N* simple initializer records.
1503
1504 The size of the memory referenced by each global address is defined by its
1505 initializer records. All simple initializer records define a sequence of
1506 bytes. A compound initializer defines the sequence of bytes by concatenating the
1507 corresponding sequence of bytes for each of its simple initializer records.
1508
1509 For notational convenience, PNaClAsm begins a compound record with a "{", and
1510 inserts a "}" after the last initializer record associated compound record. This
Jim Stichnoth 2014/07/28 22:52:07 associated *with the* compound record ?
Karl 2014/11/14 22:35:34 Done.
1511 latter "}" does not correspond to any record. It is implicitly assumed by the
1512 size specified in the compound record, and is added only to improve readability.
1513
1514 Explicit alignment is specified for global addresses, and must be a power of
1515 2. See :ref:`link_for_memory_blocks_and_alignment_section` for a more detailed
1516 discussion on how to define alignment.
1517
1518 For example, consider the following pnacl-bcdis output snippet:
1519
1520 .. naclcode::
1521
1522 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
1523 60:0| 3: <5, 2> | count 2;
1524 62:4| 3: <0, 1, 1> | const @g0, align 1,
1525 65:6| 3: <2, 8> | zerofill 8;
1526 68:2| 3: <0, 1, 0> | var @g1, align 1,
1527 71:4| 3: <1, 2> | initializers 2 {
1528 74:0| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4}
1529 78:6| 3: <2, 2> | zerofill 2;
1530 | | }
1531 81:2| 0: <65534> | }
1532
1533 This snippet defines the global constant *@g0*, and the global variable
1534 *@g1*. @g0 is 8 bytes long, and initialized to zero. @g1 is with 6 bytes: "1 2 3
Jim Stichnoth 2014/07/28 22:52:06 g1 is initialized with ?
Karl 2014/11/14 22:35:28 Done.
1535 4 0 0".
1536
1537 Count Record
1538 ------------
1539
1540 The count record defines the number of global addresses used by the PNaCl
1541 program.
1542
1543 **Syntax**
1544
1545 .. naclcode::
1546
1547 count: N; <A>
1548
1549 **Record**
1550
1551 .. naclcode::
1552
1553 AA: <5, N>
1554
1555 **Semantics**
1556
1557 This record must appear first in the globals block. The count record defines
1558 the number of global addresses used by the program.
1559
1560 **Constraints**
1561
1562 .. naclcode::
1563
1564 AA == AbbrevIndex(A)
1565
1566 **Updates**
1567
1568 .. naclcode::
1569
1570 ExpectedGlobals = N;
1571 ExpectedInitializers = 0;
1572
1573 **Examples**
1574
1575 .. naclcode::
1576
1577 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
1578 60:0| 3: <5, 2> | count 2;
1579 62:4| 3: <0, 1, 1> | const @g0, align 1,
1580 65:6| 3: <2, 8> | zerofill 8;
1581 68:2| 3: <0, 1, 0> | var @g1, align 1,
1582 71:4| 3: <1, 2> | initializers 2 {
1583 74:0| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4}
1584 78:6| 3: <2, 2> | zerofill 2;
1585 | | }
1586 81:2| 0: <65534> | }
1587
1588 Global Variable Addressses
Jim Stichnoth 2014/07/28 18:21:06 Addresses
Karl 2014/11/14 22:35:35 Done.
1589 --------------------------
1590
1591 A global variable address record defines a global address to global data. The
1592 global variable address record must be immediately followed by initializer
1593 record(s) that define how the corresponding global variable is initialized.
1594
1595 **Syntax**
1596
1597 .. naclcode::
1598
1599 var @gN, align V, <A>
1600
1601 **Record**
1602
1603 .. naclcode::
1604
1605 AA: <0, VV, 0>
1606
1607 **Semantics**
1608
1609 A global variable address record defines a global address for a global variable.
1610 *V* is the memory alignment for the global variable address, and is a power
1611 of 2.
1612
1613 It is assumed that the memory, referenced by the global variable address, can be
1614 both read and written to.
1615
1616 **Constraints**
1617
1618 .. naclcode::
1619
1620 AA == AbbrevIndex(A)
1621 N == NumGlobalAddresses
1622 NumGlobalAddresses < ExpectedGlobals
1623 ExpectedInitializers == 0
1624 VV == Log2(V+1)
1625
1626 **Updates**
1627
1628 .. naclcode::
1629
1630 ++NumGlobalAddresses;
1631 ExpectedInitializers = 1;
1632 TypeOf(@gN) = i32;
1633
1634 **Examples**
1635
1636 .. naclcode::
1637
1638 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
1639 60:0| 3: <5, 2> | count 2;
1640 62:4| 3: <0, 3, 0> | var @g0, align 4,
1641 65:6| 3: <2, 8> | zerofill 8;
1642 68:2| 3: <0, 1, 0> | var @g1, align 1,
1643 71:4| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4}
1644 76:2| 0: <65534> | }
1645 80:0|0: <65534> |}
1646
1647 Global Constant Addresses
1648 -------------------------
1649
1650 A global constant address record defines an address corresponding to a global
1651 constant that can't be modified by the program. The global constant address
1652 record must be immediately followed by initializer record(s) that define how
1653 the corresponding global constant is initialized.
1654
1655 **Syntax**
1656
1657 .. naclcode::
1658
1659 const @gN, align V, <A>
1660
1661 **Record**
1662
1663 .. naclcode::
1664
1665 AA: <0, VV, 1>
1666
1667 **Semantics**
1668
1669 A global constant address record defines a global address for a global constant.
1670 *V* is the memory alignment for the global constant address, and is a power
1671 of 2.
1672
1673 It is assumed that the memory, referenced by the global constant address, is
1674 only read, and can't be written to.
1675
1676 Note that the only difference between a global variable address and a global
1677 constant address record is the third element of the record. If the value is
1678 zero, it defines a global variable address. If the value is one, it defines a
1679 global constant address.
1680
1681 **Constraints**
1682
1683 .. naclcode::
1684
1685 AA == AbbrevIndex(A)
1686 N == NumGlobalAddresses
1687 NumGlobalAddresses < ExpectedGlobals
1688 ExpectedInitializers == 0
1689 VV == Log2(V+1)
1690
1691 **Updates**
1692
1693 .. naclcode::
1694
1695 ++NumGlobalAddresses;
1696 ExpectedInitializers = 1;
1697 TypeOf(@gN) = i32;
1698
1699 **Examples**
1700
1701 .. naclcode::
1702
1703 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
1704 60:0| 3: <5, 2> | count 2;
1705 62:4| 3: <0, 3, 1> | const @g0, align 4,
1706 65:6| 3: <2, 8> | zerofill 8;
1707 68:2| 3: <0, 1, 1> | const @g1, align 1,
1708 71:4| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4}
1709 76:2| 0: <65534> | }
1710
1711 Zerofill Initializer
1712 --------------------
1713
1714 The zerofill initializer record initializes a sequence of bytes, associated with
1715 a global address, with zeros.
1716
1717 **Syntax**
1718
1719 .. naclcode::
1720
1721 zerofill N; <A>
1722
1723 **Record**
1724
1725 .. naclcode::
1726
1727 AA: <2, N>
1728
1729 **Semantics**
1730
1731 A zerofill initializer record intializes a sequence of bytes, associated with a
Jim Stichnoth 2014/07/28 18:21:06 initializes
Karl 2014/11/14 22:35:33 Done.
1732 global address, with zeros. The number of bytes initialized to zero is *N*.
1733
1734 **Constraints**
1735
1736 .. naclcode::
1737
1738 AA == AbbrevIndex(A)
1739 ExpectedInitializers > 0;
1740
1741 **Updates**
1742
1743 .. naclcode::
1744
1745 --ExpectedInitializers;
1746
1747 **Examples**
1748
1749 .. naclcode::
1750
1751 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
1752 60:0| 3: <5, 2> | count 2;
1753 62:4| 3: <0, 3, 1> | const @g0, align 4,
1754 65:6| 3: <2, 8> | zerofill 8;
1755 68:2| 3: <0, 1, 0> | var @g1, align 1,
1756 71:4| 3: <2, 4> | zerofill 4;
1757 74:0| 0: <65534> | }
1758
1759 Data Initializer
1760 ----------------
1761
1762 Data records define a sequence of bytes. These bytes define the initial value of
1763 the contents of the corresponding memory.
1764
1765 **Syntax**
1766
1767 .. naclcode::
1768
1769 { B1 , .... , BN } <A>
1770
1771 **Record**
1772
1773 .. naclcode::
1774
1775 AA: <3, B1, ..., BN>
1776
1777 **Semantics**
1778
1779 A data record defines a sequence of bytes *B1* through *BN*, that initialize *N*
1780 bytes of memory.
1781
1782 **Constraints**
1783
1784 .. naclcode::
1785
1786 AA == AbbrevIndex(A)
1787 ExpectedInitializers > 0
1788
1789 **Updates**
1790
1791 .. naclcode::
1792
1793 --ExpectedInitializers;
1794
1795 **Examples**
1796
1797 .. naclcode::
1798
1799 56:0| 3: <8, 1, 0, 1, 0> | declare external void @f0();
1800 60:6| 1: <65535, 19, 2> | globals { // BlockID = 19
1801 68:0| 3: <5, 2> | count 2;
1802 70:4| 3: <0, 1, 1> | const @g0, align 1,
1803 73:6| 3: <3, 1, 2, 97, 36, 44, | { 1, 2, 97, 36, 44, 88,
1804 | 88, 44, 50> | 44, 50}
1805 86:0| 3: <0, 1, 1> | const @g1, align 1,
1806 89:2| 3: <1, 3> | initializers 3 {
1807 91:6| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4}
1808 96:4| 3: <4, 0> | reloc @f0;
1809 99:0| 3: <3, 99, 66, 22, 12> | { 99, 66, 22, 12}
1810 | | }
1811 105:2| 0: <65534> | }
1812
1813 Relocation Initializer
1814 ----------------------
1815
1816 A relocation initializer record allows one to define the initial value of a
1817 global address with the value of another global address (i.e. either function,
1818 variable, or constant). Since addresses are pointers, a relocation initializer
1819 record defines 4 bytes of memory.
1820
1821 **Syntax**
1822
1823 .. naclcode::
1824
1825 reloc V; <A>
1826
1827 **Record**
1828
1829 .. naclcode::
1830
1831 AA: <4, VV>
1832
1833 **Semantics**
1834
1835 A relocation initializer record defines a 4-byte value containing the specified
1836 global address *V*.
1837
1838 **Constraints**
1839
1840 .. naclcode::
1841
1842 AA == AbbrevIndex(A)
1843 VV == AbsoluteIndex(V);
1844 VV >= NumFuncAddresses
1845 VV < NumFuncAddresses + ExpectedGlobals
1846 ExpectedInitializers > 0
1847
1848 **Updates**
1849
1850 .. naclcode::
1851
1852 --ExpectedInitializers;
1853
1854 **Examples**
1855
1856 .. naclcode::
1857
1858 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
1859 48:0| 3: <1, 2> | count 2;
1860 50:4| 3: <2> | @t0 = void;
1861 52:2| 3: <21, 0, 0> | @t1 = void ();
1862 55:4| 0: <65534> | }
1863 56:0| 3: <8, 1, 0, 1, 0> | declare external void @f0();
1864 60:6| 1: <65535, 19, 2> | globals { // BlockID = 19
1865 68:0| 3: <5, 2> | count 2;
1866 70:4| 3: <0, 1, 0> | var @g0, align 1,
1867 73:6| 3: <1, 3> | initializers 3 {
1868 76:2| 3: <4, 0> | reloc @f0;
1869 78:6| 3: <4, 1> | reloc @g0;
1870 81:2| 3: <4, 2> | reloc @g1;
1871 | | }
1872 83:6| 3: <0, 3, 0> | var @g1, align 4,
1873 87:0| 3: <2, 4> | zerofill 4;
1874 89:4| 0: <65534> | }
1875
1876 This example defines global address *@g0* and *g1*. *g0* defines 12 bytes of
1877 memory, and is initialized with three addresses *@f1*, *@g0*, and *@g1*. Note
1878 that all global addresses can be used in a relocation initialization record,
1879 even if it isn't defined yet.
1880
1881 Subfield Relocation Initializer
1882 -------------------------------
1883
1884 A subfield relocation initializer record allows one to define the initial value
1885 of a global address with the value of another (non-function) global address
1886 (i.e. either variable or constant), plus a constant. Since addresses are
1887 pointers, a relocation initializer record defines 4 bytes of memory.
1888
1889 **Syntax**
1890
1891 .. naclcode::
1892
1893 reloc V + O; <A>
Jim Stichnoth 2014/07/28 22:52:06 I don't have a constructive suggestion here, but "
Karl 2014/11/14 22:35:31 Changed to use "X".
1894 reloc V - O; <A>
1895
1896 **Record**
1897
1898 .. naclcode::
1899
1900 AA: <4, VV, OOO>
1901
1902 **Semantics**
1903
1904 A relocation initializer record defines a 4-byte value containing the specified
1905 global (non-function) address *V*, modified by the unsigned offset *O*. *OO* is
1906 the corresponding signed offset. In the first form, *OO == O*. In the second
1907 form, *OO == - O*.
1908
1909 **Constraints**
1910
1911 .. naclcode::
1912
1913 AA == AbbrevIndex(A)
1914 VV == AbsoluteIndex(V)
1915 VV >= NumFuncAddresses
1916 VV < NumFuncAddresses + ExpectedGlobals
1917 ExpectedInitializers > 0
1918 OOO == SignRotate(OO)
1919
1920 **Updates**
1921
1922 .. naclcode::
1923
1924 --ExpectedInitializers;
1925
1926 **Examples**
1927
1928 .. naclcode::
1929
1930 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
1931 48:0| 3: <1, 0> | count 0;
1932 50:4| 0: <65534> | }
1933 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
1934 60:0| 3: <5, 3> | count 3;
1935 62:4| 3: <0, 1, 0> | var @g0, align 1,
1936 65:6| 3: <1, 3> | initializers 3 {
1937 68:2| 3: <4, 0, 1> | reloc @g0 + 1;
1938 71:4| 3: <4, 1, 4294967295> | reloc @g1 - 1;
1939 79:2| 3: <4, 2, 4> | reloc @g2 + 4;
1940 | | }
1941 82:4| 3: <0, 3, 0> | var @g1, align 4,
1942 85:6| 3: <2, 4> | zerofill 4;
1943 88:2| 3: <0, 3, 0> | var @g2, align 4,
1944 91:4| 3: <2, 8> | zerofill 8;
1945 94:0| 0: <65534> | }
1946
1947
1948 Compound Initializer
1949 --------------------
1950
1951 The compound initializer record must immediately follow a global
1952 variable/constant address record. It defines how many simple initializer records
1953 are used to define the initializer. The size of the corresponding memory is the
1954 sum of the bytes needed for each of the succeeding initializers.
1955
1956 Note that a compound initializer can't be used as a simple initializer of
1957 another compound initializer (i.e. nested compound initializers are not
1958 allowed).
1959
1960 **Syntax**
1961
1962 .. naclcode::
1963
1964 initializers N { <A>
1965 ...
1966 }
1967
1968 **Record**
1969
1970 .. naclcode::
1971
1972 AA: <1, N>
1973
1974 **Semantics**
1975
1976 Defines that the next *N* initializers should be associated with the global
1977 address of the previous record.
1978
1979 **Constraints**
1980
1981 .. naclcode::
1982
1983 AA == AbbrevIndex(A)
1984 ExpectedInitializers == 1
1985
1986 **Updates**
1987
1988 .. naclcode::
1989
1990 ExpectedInitializers = N;
1991
1992 **Examples**
1993
1994 .. naclcode::
1995
1996 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
1997 48:0| 3: <1, 0> | count 0;
1998 50:4| 0: <65534> | }
1999 52:0| 1: <65535, 19, 2> | globals { // BlockID = 19
2000 60:0| 3: <5, 2> | count 2;
2001 62:4| 3: <0, 0, 1> | const @g0, align 0,
2002 65:6| 3: <1, 2> | initializers 2 {
2003 68:2| 3: <2, 8> | zerofill 8;
2004 70:6| 3: <3, 3, 2, 1, 0> | { 3, 2, 1, 0}
2005 | | }
2006 75:4| 3: <0, 0, 0> | var @g1, align 0,
2007 78:6| 3: <1, 2> | initializers 2 {
2008 81:2| 3: <3, 1, 2, 3, 4> | { 1, 2, 3, 4}
2009 86:0| 3: <2, 2> | zerofill 2;
2010 | | }
2011 88:4| 0: <65534> | }
2012
2013 .. _link_for_valuesymtab_block_section:
2014
2015 Valuesymtab Block
2016 =================
2017
2018 The valuesymtab block ref does not define any values. Its only goal is to
Jim Stichnoth 2014/07/28 22:52:04 Is "ref" supposed to be here?
Karl 2014/11/14 22:35:33 Removed.
2019 associate text names with external function addresses. Each association is
2020 defined by a record in the valuesymtab block. Currently, only
2021 :ref:`intrinsic<link_for_intrinsic_functions_section>` function addresses and
2022 the (external) start function (*_start*) can be named. All named function
2023 addresses must be external (see the module block's
2024 :ref:`link_for_function_address_section` record). Each record in the
2025 valuesymtab block is a *entry* record, defining a single name association.
2026
2027 Entry Record
2028 ------------
2029
2030 The *entry* record defines a name for a function address.
2031
2032 **Syntax**
2033
2034 .. naclcode::
2035
2036 V : "NAME"; <A>
2037
2038 **Record**
2039
2040 .. naclcode::
2041
2042 AA: <1, B1, ... , BN>
2043
2044 **Semnatics**
Jim Stichnoth 2014/07/28 18:21:08 Semantics
Karl 2014/11/14 22:35:30 Done.
2045
2046 The *entry* record defines a name *NAME* for function address *V*. *NAME* is a
2047 sequence of anscii characters *B1* through *BN*.
Jim Stichnoth 2014/07/28 18:21:06 ascii or ASCII
Karl 2014/11/14 22:35:32 Done.
2048
2049 **Examples**
2050
2051 .. naclcode::
2052
2053 72:0| 3: <8, 4, 0, 1, 0> | declare external
2054 | | void @f0(i32, i32, i32, i32, i1);
2055 76:6| 3: <8, 4, 0, 1, 0> | declare external
2056 | | void @f1(i32, i32, i32, i32, i1);
2057 81:4| 3: <8, 5, 0, 0, 0> | define external void @f2(i32);
2058 86:2| 1: <65535, 19, 2> | globals { // BlockID = 19
2059 92:0| 3: <5, 0> | count 0;
2060 94:4| 0: <65534> | }
2061 96:0| 1: <65535, 14, 2> | valuesymtab { // BlockID = 14
2062 104:0| 3: <1, 1, 108, 108, 118, | @f1 : "llvm.memmove.p0i8.p0i8.i32";
2063 | 109, 46, 109, 101, |
2064 | 109, 109, 111, 118, |
2065 | 101, 46, 112, 48, |
2066 | 105, 56, 46, 112, 48,|
2067 | 105, 56, 46, 105, 51,|
2068 | 50> |
2069 145:4| 3: <1, 2, 95, 115, 116, | @f2 : "_start";
2070 | 97, 114, 116> |
2071 157:0| 3: <1, 0, 108, 108, 118, | @f0 : "llvm.memcpy.p0i8.p0i8.i32";
2072 | 109, 46, 109, 101, |
2073 | 109, 99, 112, 121, |
2074 | 46, 112, 48, 105, 56,|
2075 | 46, 112, 48, 105, 56,|
2076 | 46, 105, 51, 50> |
2077 197:0| 0: <65534> | }
2078
2079 Module Block
2080 ============
2081
2082 The module block, like all blocks, is enclosed in a pair of enter/exit records,
2083 using block ID 8. A well-formed module block consists of the following records
2084 (in order):
2085
2086 A version record
2087 The version record communicates which version of the PNaCl bitcode
2088 reader/writer should be used. Note that this is different than the PNaCl
2089 bitcode (ABI) version. The PNaCl bitcode (ABI) version defines what is
2090 expected in records, and is defined in the header record of the bitcode
2091 file. The version record defines the version of the PNaCl bitcode
2092 reader/writer to use to convert records into bit sequences.
2093
2094 Optional local abbreviations
2095 Defines a list of local abbreviations to use for records within the module
2096 block.
2097
2098 An abbreviations block
2099 The abbreviations block defines user-defined, global abbreviations that are
2100 used to convert PNaCl records to bit sequences in blocks following the
2101 abbreviations block.
2102
2103 A types block
2104 The types block defines the set of all types used in the program.
2105
2106 A non-empty sequence of function address records
2107 Each record defines a function address used by the program. Function
2108 addresses must either be external, or defined internally by the program. If
2109 they are defined by the program, there must be a function block (appearing
2110 later in the module) that defines the sequence of instructions for each
2111 defined function.
2112
2113 A globals block defining the global variables.
2114 This block defines the set of global variable (addresses) used by the
2115 program. In addition to the addresses, each global variable also defines how
2116 the corresponding global variable is initialized.
2117
2118 An optional value symbol table block.
2119 This block, if defined, provides textual names for function and global
2120 variable addresses (previously defined in the module). Note that only names
2121 for intrinsic functions and the start function are specified.
2122
2123 A sequence of function blocks.
2124 Each function block defines the corresponding control flow graph for each
Jim Stichnoth 2014/07/28 22:52:07 control flow graph --> intermediate representation
Karl 2014/11/14 22:35:35 Done.
2125 defined function. The order of function blocks is used to associate them with
2126 function addresses. The order of the defined function blocks must follow the
2127 same order as the corresponding function addresses defined in the module
2128 block.
2129
2130 Descriptions of the :ref:`abbreviations<link_for_abbreviations_section>`,
2131 :ref:`types<link_for_types_block_section>`,
2132 :ref:`globals<link_for_globals_block_section>`, :ref:`value symbol
2133 table<link_for_valuesymtab_block_section>`, and
2134 :ref:`function<link_for_function_blocks_section>` blocks are not provided
2135 here. See the appropriate reference for more details. The following subsections
2136 describe each of the records that can appear in a module block.
2137
2138 Version
2139 -------
2140
2141 The version record defines the implementation of the PNaCl bitstream
2142 reader/writer to use. That is, the implementation that converts PNaCl records to
2143 bit sequences, and converts them back to PNaCl records. Note that this is
2144 different than the PNaCl version of the bitcode file (encoded in the header
2145 record of the bitcode file). The PNaCl version defines the valid forms of PNaCl
2146 records. The version record is specific to the PNaCl version, and may have
2147 different values for different PNaCl versions.
2148
2149 Note that currently, only PNaCl bitcode version 2, and version record value 1 is
2150 defined.
2151
2152 **Syntax**
2153
2154 .. naclcode::
2155
2156 version N; <A>
2157
2158 **Record**
2159
2160 .. naclcode::
2161
2162 AA: <1, N>
2163
2164 **Semantics**
2165
2166 The version record defines which PNaCl reader/writer rules should be
2167 followed. *N* is the version number. Currently *N* must be 1. Future versions of
2168 PNaCl may define additional legal values.
2169
2170 **Constraints**
2171
2172 .. naclcode::
2173
2174 AA == AbbrevIndex(A)
2175
2176 *Examples*
2177
2178 .. naclcode::
2179
2180 16:0|1: <65535, 8, 2> |module { // BlockID = 8
2181 24:0| 3: <1, 1> | version 1;
2182 26:4| 1: <65535, 0, 2> | abbreviations { // BlockID = 0
2183 36:0| 0: <65534> | }
2184
2185 .. _link_for_function_address_section:
2186
2187 Function Address
2188 ----------------
2189
2190 A function address record describes a function address. *Defined* function
2191 addresses define implementations while *declared* function addresses do not.
2192
2193 Since a PNaCl program is assumed to be a complete (statically linked)
2194 executable, All functions should be *defined* and *internal*. The exception to
Jim Stichnoth 2014/07/28 22:52:04 "exception ... is" or "exceptions ... are"
Jim Stichnoth 2014/07/28 22:52:05 All --> all
2195 this are *intrinsic* functions, which should only be *declared* and *external*,
2196 since intrinsic functions will automatically converted to appropriate code by
Jim Stichnoth 2014/07/28 22:52:04 will be automatically
Karl 2014/11/14 22:35:33 Done.
2197 the PNaCl translator.
2198
2199 The implementation of a *defined* function address is provided by a
2200 corresponding function block, appearing later in the module block. The
2201 association of a *defined* function address with the corresponding function
2202 block is based on position. The *Nth* defined function address record, in the
2203 module block, has its implementation in the *Nth* function block of that module
2204 block.
2205
2206 **Syntax**
2207
2208 .. naclcode::
2209
2210 PN LN T0 @fN ( T1 , ... , TM ); <A>
2211
2212 **Record**
2213
2214 .. naclcode::
2215
2216 AA: <8, T, C, P, L>
2217
2218 **Semantics**
2219
2220 Decribes the function address *@fN*. *PN* is the name that specifies the
Jim Stichnoth 2014/07/28 18:21:06 Describes
2221 prototype value *P* associated with the function. A function address is
2222 *defined* only if *P==0*. Otherwise, it is only *declared*. The type of the
2223 function is function type *@tT*. *L* is the linkage specification corresponding
2224 to name *LN*. *C* is the calling convention used by the function.
2225
2226 Note that function signature must be defined by a function type in the types
2227 block. Hence, the return value must either be a primitive type, type *void*, or
2228 a vector type.
2229
2230 For ordinary functions, integral parameter and types can only be i32 and i64.
2231 All other integer types are not allowed.
2232
2233 Valid prototype names *PN*, and corresponding *P* values, are:
2234
2235 = =======
2236 P PN
2237 = =======
2238 1 declare
2239 0 define
2240 = =======
2241
2242 Valid linkage names *LN*, and corresponding *L* values, are:
2243
2244 = ========
2245 L LN
2246 = ========
2247 3 internal
2248 0 external
2249 = ========
2250
2251 Currently, only one calling convention *C* is supported:
2252
2253 = ====================
2254 C Calling Convention
2255 = ====================
2256 0 C calling convention
2257 = ====================
2258
2259 **Constraint**
2260
2261 .. naclcode::
2262
2263 AA = AbbrevIndex(A)
2264 T = TypeID(TypeOf(T0 ( T1 , ... , TN )))
2265 N = NumFuncAddresses
2266
2267 **Updates**
2268
2269 .. naclcode::
2270
2271 ++NumFuncAddresses;
2272 TypeOf(@fN) = TypeOf(TypeID(i32));
2273 TypeOfFcn(@fN) = TypeOf(@tT);
2274
2275 if PN == 0:
2276 DefiningFcnIDs += @FN;
2277 ++NumDefinedFunctionAddresses;
2278
2279 **Examples**
2280
2281 .. naclcode::
2282
2283 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
2284 48:0| 3: <1, 7> | count 7;
2285 50:4| 3: <7, 32> | @t0 = i32;
2286 53:6| 3: <3> | @t1 = float;
2287 55:4| 3: <4> | @t2 = double;
2288 57:2| 3: <2> | @t3 = void;
2289 59:0| 3: <21, 0, 2, 1> | @t4 = double (float);
2290 63:0| 3: <21, 0, 0, 0, 1, 0, 2>| @t5 =
2291 | | i32 (i32, float, i32, double);
2292 69:2| 3: <21, 0, 3> | @t6 = void ();
2293 72:4| 0: <65534> | }
2294 76:0| 3: <8, 4, 0, 1, 0> | declare external double @f0(float);
2295 80:6| 3: <8, 5, 0, 1, 0> | declare external
2296 | | i32 @f1(i32, float, i32, double);
2297 85:4| 3: <8, 6, 0, 0, 0> | define external void @f2();
2298
2299 Constants Blocks
2300 ================
2301
2302 Constants blocks define literal constants used within each function. It's intent
Jim Stichnoth 2014/07/28 22:52:07 It's --> Its
Karl 2014/11/14 22:35:28 Done.
2303 it to define them once, before instructions. A constants block can only appear
2304 in a function block, and must appear before any instructions in the function
2305 block.
2306
2307 Currently, only literal integrals, floating point literals, and undefined vector
2308 constants can be defined.
2309
2310 To minimize type information put in a constants block, the type information is
2311 separated from the constants. This allows a sequence of constants to be given
2312 the same type. This is done by defining a *set type* record, followed by a
2313 sequence of literal constants. These literal constants all get converted to the
2314 type of the preceding *set type* record.
2315
2316 Note that constants that are used for switch case selectors should not be added
2317 to the constants block, since the switch instruction contains the constants used
2318 for case selectors. All other constants in the function block must be put into a
2319 constants block, so that instructions can use them.
2320
2321 To make this more concrete, consider the following example constants block:
2322
2323 .. naclcode::
2324
2325 types {
2326 @t0 = i1;
2327 ...
2328 }
2329 ...
2330 constants {
2331 i1:
2332 %c0 = i1 1;
2333 %c2 = i1 2;
2334 }
2335
2336 The corresponding records for the constants block are:
2337
2338 .. naclcode::
2339
2340 <65535, 11, 2>
2341 <1, 0>
2342 <4, 0>
2343 <4, 2>
2344 <65534>
2345
2346 TODO(kschimpf) Generate pnacl-bcdis output for above.
2347
2348 Set Type
2349 --------
2350
2351 The *set type* record defines the type to use for the (immediately) succeeding
2352 literals.
2353
2354 **Syntax**
2355
2356 .. naclcode::
2357
2358 T: <A>
2359
2360 **Record**
2361
2362 .. naclcode::
2363
2364 AA: <1, TT>
2365
2366 **Semantics**
2367
2368 The *set type* record deifnes type *T* to be used to type the (immediately)
Jim Stichnoth 2014/07/28 18:21:05 defines
Karl 2014/11/14 22:35:28 Done.
2369 succeeding literals. *T* must be a non-void primitive value type or a vector
2370 type.
2371
2372 **Constraints**
2373
2374 .. naclcode::
2375
2376 TT == TypeID(T)
2377
2378 **Updates**
2379
2380 .. naclcode::
2381
2382 ConstantsSetType = T;
2383
2384 **Examples**
2385
2386 .. naclcode::
2387
2388 106:4| 1: <65535, 11, 2> | constants { // BlockID = 11
2389 116:0| 3: <1, 0> | i32:
2390 118:4| 3: <4, 2> | %c0 = i32 1;
2391 121:0| 3: <4, 4> | %c1 = i32 2;
2392 123:4| 3: <1, 2> | i8:
2393 126:0| 3: <4, 8> | %c2 = i8 4;
2394 128:4| 3: <4, 6> | %c3 = i8 3;
2395 131:0| 3: <1, 1> | float:
2396 133:4| 3: <6, 1065353216> | %c4 = float 1;
2397 139:6| 0: <65534> | }
2398
2399 Undefined Literal
2400 -----------------
2401
2402 The *undefined* literal record creates an undefined literal for the type *T*
2403 defined by the preceding *set type* record.
2404
2405 Note: See :ref:`link_for_insert_element_instruction_section` for an example of
2406 how you would use the undefined literal with vector types.
2407
2408 **Syntax**
2409
2410 .. naclcode::
2411
2412 %cN = T undef; <50>
2413
2414 **Record**
2415
2416 .. naclcode::
2417
2418 AA: <3>
2419
2420 **Semantics**
2421
2422 The *undefined* lieral record creates an undefined literal constant *%cN* for
Jim Stichnoth 2014/07/28 18:21:05 literal
Karl 2014/11/14 22:35:29 Done.
2423 type *T*. *T* must be the type defined by the preceding *set type* record, and
2424 be a primitive value type or a vector type.
2425
2426 **Constraints**
2427
2428 .. naclcode::
2429
2430 N == NumFcnConsts
2431 T == ConstantsSetType
2432 IsPrimitive(T) or IsVector(T)
2433
2434 **Updates**
2435
2436 .. naclcode::
2437
2438 ++NumFcnConsts;
2439 TypeOf(%cN) = T;
2440
2441 **Examples**
2442
2443 .. naclcode::
2444
2445 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
2446 48:0| 3: <1, 5> | count 5;
2447 50:4| 3: <7, 32> | @t0 = i32;
2448 53:6| 3: <3> | @t1 = float;
2449 55:4| 3: <2> | @t2 = void;
2450 57:2| 3: <12, 4, 0> | @t3 = <4 x i32>;
2451 60:4| 3: <21, 0, 2> | @t4 = void ();
2452 63:6| 0: <65534> | }
2453 ...
2454 106:4| 1: <65535, 11, 2> | constants { // BlockID = 11
2455 116:0| 3: <1, 0> | i32:
2456 118:4| 3: <3> | %c0 = i32 undef;
2457 120:2| 3: <4, 2> | %c1 = i32 1;
2458 122:6| 3: <1, 3> | <4 x i32>:
2459 125:2| 3: <3> | %c2 = <4 x i32> undef;
2460 127:0| 3: <1, 1> | float:
2461 129:4| 3: <3> | %c3 = float undef;
2462 131:2| 0: <65534> | }
2463
2464
2465 Integer Literal
2466 ---------------
2467
2468 The *integer literal* record creates an integer literal for the integral type *T *
Jim Stichnoth 2014/07/28 22:52:05 80-col
Karl 2014/11/14 22:35:30 Done.
2469 defined by the preceding *set type* record.
2470
2471 **Syntax**
2472
2473 .. naclcode::
2474
2475 %cN = T V; <A>
2476
2477 **Record**
2478
2479 .. naclcode::
2480
2481 AA: <4, VV>
2482
2483 **Semantics**
2484
2485 The *integer literal* record creates an integer literal constant *%cN* for type
2486 *T*. *T* must be the type defined by the preceding *set type* record, and an
2487 integral type. The literal *V* can be signed, but must be definable by type *T*.
2488
2489 **Constraints**
2490
2491 .. naclcode::
2492
2493 N == NumFcnConsts
2494 T == ConsgtantsSetType
Jim Stichnoth 2014/07/28 18:21:06 ConstantsSetType?
Karl 2014/11/14 22:35:27 Done.
2495 VV == SignRotate(V)
2496 IsInteger(T)
2497
2498 **Updates**
2499
2500 TypeOf(%cN) = T;
2501
2502 **Examples**
2503
2504 .. naclcode::
2505
2506 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
2507 48:0| 3: <1, 7> | count 7;
2508 50:4| 3: <7, 8> | @t0 = i8;
2509 53:0| 3: <7, 16> | @t1 = i16;
2510 55:4| 3: <7, 32> | @t2 = i32;
2511 58:6| 3: <7, 64> | @t3 = i64;
2512 62:0| 3: <7, 1> | @t4 = i1;
2513 64:4| 3: <2> | @t5 = void;
2514 66:2| 3: <21, 0, 5> | @t6 = void ();
2515 69:4| 0: <65534> | }
2516 ...
2517 114:4| 1: <65535, 11, 2> | constants { // BlockID = 11
2518 124:0| 3: <1, 0> | i8:
2519 126:4| 3: <4, 2> | %c0 = i8 1;
2520 129:0| 3: <4, 4> | %c1 = i8 2;
2521 131:4| 3: <1, 1> | i16:
2522 134:0| 3: <4, 6> | %c2 = i16 3;
2523 136:4| 3: <4, 8> | %c3 = i16 4;
2524 139:0| 3: <1, 2> | i32:
2525 141:4| 3: <4, 10> | %c4 = i32 5;
2526 144:0| 3: <4, 12> | %c5 = i32 6;
2527 146:4| 3: <1, 3> | i64:
2528 149:0| 3: <4, 3> | %c6 = i64 -1;
2529 151:4| 3: <4, 5> | %c7 = i64 -2;
2530 154:0| 3: <1, 4> | i1:
2531 156:4| 3: <4, 3> | %c8 = i1 1;
2532 159:0| 3: <4, 0> | %c9 = i1 0;
2533 161:4| 0: <65534> | }
2534
2535 Floating point literal
Jim Stichnoth 2014/07/28 22:52:07 Floating Point Literal
2536 ----------------------
2537
2538 The *floating point literal* record creates a floating point literal for the
2539 floating type *T* defined by the preceding *set type* record.
2540
2541 **Syntax**
2542
2543 .. naclcode::
2544
2545 %cN = T V; <A>
2546
2547 **Record**
2548
2549 .. naclcode::
2550
2551 AA: <6, V>
2552
2553 **Semantics**
2554
2555 The *floating point literal* record creates a floating point literal constant
2556 *%cN* for type *T*. *T* must the type type defined by the preceding *set type*
2557 record, and be a floating point type. The literal *V* must be a valid IEE 754
2558 32-bit (unsigned integer) value if *T* is float, and a IEEE 754 64-bit (unsigned
2559 integer) value if *T* is double.
2560
2561 **Constraints**
2562
2563 .. naclcode::
2564
2565 N == NumFcnConsts
2566 T == ConstantsSetType
2567 IsFloat(T)
2568
2569 **Updates**
2570
2571 .. naclcode::
2572
2573 TypeOf(%cN) = T;
2574
2575 ** Examples **
2576
2577 .. naclcode::
2578
2579 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
2580 48:0| 3: <1, 4> | count 4;
2581 50:4| 3: <3> | @t0 = float;
2582 52:2| 3: <4> | @t1 = double;
2583 54:0| 3: <2> | @t2 = void;
2584 55:6| 3: <21, 0, 2> | @t3 = void ();
2585 59:0| 0: <65534> | }
2586 ...
2587 102:4| 1: <65535, 11, 2> | constants { // BlockID = 11
2588 112:0| 3: <1, 0> | float:
2589 114:4| 3: <6, 0> | %c0 = float 0;
2590 117:0| 3: <6, 1065353216> | %c1 = float 1;
2591 123:2| 3: <6, 1088421888> | %c2 = float 7;
2592 130:2| 3: <6, 1090519040> | %c3 = float 8;
2593 137:2| 3: <3> | %c4 = float undef;
2594 139:0| 3: <6, 2143289344> | %c5 = float nan;
2595 146:0| 3: <6, 2139095040> | %c6 = float inf;
2596 153:0| 3: <6, 4286578688> | %c7 = float -inf;
2597 160:0| 3: <1, 1> | double:
2598 162:4| 3: <6, | %c8 = double 1;
2599 | 4607182418800017408> |
2600 174:0| 3: <6, 0> | %c9 = double 0;
2601 176:4| 3: <6, | %c10 = double 5;
2602 | 4617315517961601024> |
2603 188:0| 3: <6, | %c11 = double 6;
2604 | 4618441417868443648> |
2605 199:4| 3: <6, | %c12 = double nan;
2606 | 9221120237041090560> |
2607 211:0| 3: <6, | %c13 = double inf;
2608 | 9218868437227405312> |
2609 222:4| 3: <6, | %c14 = double -inf;
2610 | 18442240474082181120>|
2611 234:0| 0: <65534> | }
2612
2613 .. _link_for_function_blocks_section:
2614
2615 Function Blocks
2616 ===============
2617
2618 A function block defines the implementation of a *defined* function address. The
2619 function address it defines is based on the position of the corresponding
2620 *defined* function address. The Nth *defined* function address always
2621 corresponds to the Nth function block in the module block.
2622
2623 A function implementation contains a list of basic blocks, forming the CFG
Jim Stichnoth 2014/07/28 22:52:05 I don't think you need to use the CFG abbreviation
Karl 2014/11/14 22:35:30 Done.
2624 (control flow graph). Each basic block contains a list of instructions, and ends
2625 with a :ref:`terminator<link_for_terminator_instruction_section>` (e.g. branch)
2626 instruction.
2627
2628 Basic blocks are not represented by records. Rather, context is implicit. The
2629 first basic block begins with the first instruction record in the function
2630 block. Blocks boundaries are determined by *terminator* instructions. The
Jim Stichnoth 2014/07/28 22:52:08 Block boundaries
Karl 2014/11/14 22:35:27 Done.
2631 instruction that follows a terminator instruction begins a new basic block.
2632
2633 The first basic block in a function is special in two ways: it is immediately
2634 executed on entrance to the function, and it is not allowed to have predecessor
2635 basic blocks (i.e. there can't be any branches to the entry block of a
2636 function). Because the entry block has no predecessors, it also can't have any
2637 :ref:`phi<link_for_phi_instruction_section>` instructions.
2638
2639 The parameters are implied by the type of the corresponding function
2640 address. One parameter is defined for each argument of the function type
2641 signature.
2642
2643 The number of basic blocks is defined by the count record. Each terminator
2644 instruction ends the current basic block, and the next instruction begins a new
2645 basic block. Basic blocks are numbered by the order they appear (starting with
2646 index 0). Basic block IDs have the form *%bN*, where *N* corresponds to the
2647 position of the basic block within the function block.
2648
2649 Each instruction, within a function block, corresponds to a corresponding PNaCl
2650 record. The layout of a function block is the (basic block) count record,
2651 followed by a sequence of instruction records.
2652
2653 For readability, PNaClAsm introduces basic block IDs. These basic block IDs do
2654 not correspond to PNaCl records, since basic block boundaries are defined
2655 implicitly, after terminator instructions. They appear only for readability.
2656
2657 Operands of instructions are defined using an :ref:`absolute
2658 index<link_for_absolute_index_section>`. This absolute index implicitly encodes
2659 function addresses, global addresses, parameters, constants, and instructions
2660 that generate values. The encoding takes advantage of the implied ordering of
2661 these values in the bitcode file, defining a contiguous sequence of indices for
2662 each kind of identifier. That is, indices are ordered by putting function
2663 address identifiers first, followed by global address identifiers, followed by
2664 parameter identifiers, followed by constant identifiers, and lastly instruction
2665 value identifiers.
2666
2667 To save space in the encoded bitcode file, most operands are encoded using a
2668 relative index value, rather than absolute. This is done because most
2669 instruction operands refer to values defined earlier in the (same) basic block.
2670 As a result, the relative distance (back) from the next value defining
2671 instruction is frequently a small number. Small numbers tend to require fewer
2672 bits when they are converted to bit sequences.
2673
2674 The following subsections define records that can appear in a function block.
2675
2676 Function enter
Jim Stichnoth 2014/07/28 22:52:08 Function Enter
Karl 2014/11/14 22:35:34 Done.
2677 --------------
2678
2679 PNaClAsm defines a function enter block construct. The corresponding record is
2680 simply an enter block record, with BlockID value 12. All context about the
2681 defining address is implicit by the position of the function block, and the
2682 corresponding defining function address. To improve readability, PNaClAsm
2683 includes the function signature into the syntax rule.
2684
2685 **Syntax**
2686
2687 .. naclcode::
2688
2689 function TR @fN ( T0 %p0, ... , TM %pM ) { <B>
2690
2691 **Record**
2692
2693 1: <65535, 12, B>
2694
2695 **Semantics**
2696
2697 *B* is the number of bits reserved for abbreviations in the block. If it is
2698 omitted, 2 is assumed. See :ref:`enter<link_for_enter_block_record_section>`
2699 block records for more details.
2700
2701 The value of *N* corresponds to the positional index of the corresponding
2702 defining function address this block is associated with. *M* is the number of
2703 defined parameters (minus one) in the function heading.
2704
2705 **Constraints**
2706
2707 .. naclcode::
2708
2709 N == NumFcnImpls
2710 @fN in DefiningFcnIDs
2711 TypeOfFcn(@fN) == TypeOf(TypeID(TR (T0, ... , TM)))
2712
2713 **Updates**
2714
2715 .. naclcode::
2716
2717 ++NumFcnImpls;
2718 EnclosingFcnID = @fN;
2719 NumBasicBlocks = 0;
2720 ExpectedBlocks = 0;
2721 NumParams = M;
2722 for I in [0..M]:
2723 TypeOf(%pI) = TypeOf(TypeID(TI));
2724
2725 **Examples**
2726
2727 .. naclcode::
2728
2729 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
2730 48:0| 3: <1, 4> | count 4;
2731 50:4| 3: <7, 32> | @t0 = i32;
2732 53:6| 3: <2> | @t1 = void;
2733 55:4| 3: <21, 0, 1> | @t2 = void ();
2734 58:6| 3: <21, 0, 0, 0> | @t3 = i32 (i32);
2735 62:6| 0: <65534> | }
2736 ...
2737 104:0| 1: <65535, 12, 2> | function void @f0() {
2738 | | // BlockID = 12
2739 112:0| 3: <1, 1> | blocks 1;
2740 | | %b0:
2741 114:4| 3: <10> | ret void;
2742 116:2| 0: <65534> | }
2743 120:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) {
2744 | | // BlockID = 12
2745 128:0| 3: <1, 1> | blocks 1;
2746 | | %b0:
2747 130:4| 3: <10, 1> | ret i32 %p0;
2748 133:0| 0: <65534> | }
2749
2750 Count Record
2751 ------------
2752
2753 The count record, within a function block, defines the number of basic blocks
2754 used to define the function implementation. It must be the first record in the
2755 function block.
2756
2757 **Syntax**
2758
2759 .. naclcode::
2760
2761 blocks: N; <A>
2762 %b0:
2763
2764 **Record**
2765
2766 .. naclcode::
2767
2768 AA: <1, N>
2769
2770 **Semantics**
2771
2772 The count record defines the number *N* of basic blocks in the implemented
2773 function.
2774
2775 **Constraints**
2776
2777 .. naclcode::
2778
2779 AA == AbbrevIndex(A)
2780 ExpectedBasicBlocks == N
2781 NumBasicBlocks = 0
2782
2783 **Updates**
2784
2785 .. naclcode::
2786
2787 104:0| 1: <65535, 12, 2> | function void @f0() {
2788 | | // BlockID = 12
2789 112:0| 3: <1, 1> | blocks 1;
2790 | | %b0:
2791 114:4| 3: <10> | ret void;
2792 116:2| 0: <65534> | }
2793 120:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) {
2794 | | // BlockID = 12
2795 128:0| 3: <1, 1> | blocks 1;
2796 | | %b0:
2797 130:4| 3: <10, 1> | ret i32 %p0;
2798 133:0| 0: <65534> | }
2799
2800 .. _link_for_terminator_instruction_section:
2801
2802 Terminator Instructions
2803 -----------------------
2804
2805 Terminator instructions are instructions that appear in a function block, and
2806 define the end of the current basic block. A terminator instruction indicates
2807 which block should be executed after the current block is finished. The function
2808 block is well formed only if the number of terminator instructions, in the
2809 function block, corresponds to the value defined by the corresponding count
2810 block.
2811
2812 Return Void Instruction
2813 ^^^^^^^^^^^^^^^^^^^^^^^
2814
2815 The return void instruction is used to return control from a function back to
2816 the caller, without returning any value.
2817
2818 **Syntax**
2819
2820 .. naclcode::
2821
2822 ret void; <A>
2823 %bB:
2824
2825 **Record**
2826
2827 .. naclcode::
2828
2829 AA: <10>
2830
2831 **Semantics**
2832
2833 The return instruction returns control to the calling function.
Jim Stichnoth 2014/07/28 22:52:08 Do you want "return instruction" or "return void i
Karl 2014/11/14 22:35:29 Added void.
2834
2835 *B* is the number associated with the next basic block. Label *%bB:* only
2836 appears if *B < ExpectedBasicBlocks*. That is, the label is omitted only if this
2837 terminator instruction is the last instruction in the function block.
2838
2839 **Constraints**
2840
2841 .. naclcode::
2842
2843 AA == AbbrevIndex(A)
2844 B == NumBasicBlocks + 1
2845 NumBasicBlocks < ExpectedBasicBLocks
2846 ReturnType(TypeOf(EnclosingFcnID)) == void
2847
2848 **Updates**
2849
2850 .. naclcode::
2851
2852 ++NumBasicBlocks;
2853
2854 **Examples**
2855
2856 .. naclcode::
2857
2858 104:0| 1: <65535, 12, 2> | function void @f0() {
2859 | | // BlockID = 12
2860 112:0| 3: <1, 1> | blocks 1;
2861 | | %b0:
2862 114:4| 3: <10> | ret void;
2863 116:2| 0: <65534> | }
2864
2865 Return Value Instruction
2866 ^^^^^^^^^^^^^^^^^^^^^^^^
2867
2868 The return value instruction is used to return control from a function back to
2869 the caller, including a value. The value must correspond to the return type of
2870 the enclosing function.
2871
2872 **Syntax**
2873
2874 .. naclcode::
2875
2876 ret T V; <A>
2877 %bB:
2878
2879 **Record**
2880
2881 .. naclcode::
2882
2883 AA: <10, VV>
2884
2885 **Semantics**
2886
2887 The return value instruction returns control to the calling function, returning
2888 the provided value.
2889
2890 *V* is the value to return. Type *T* must be of the type returned by the
2891 function. It must also be the type associated with value *V*.
2892
2893 *B* is the number associated with the next basic block. Label *%bB:* only
2894 appears if *B < ExpectedBasicBlocks*. That is, the label is omitted only if this
2895 terminator instruction is the last instruction in the function block.
2896
2897 The return type *T* must either be a (non-void) primitive type, or a vector
2898 type. If the function block is implementing an ordinary function, and the return
2899 type is an integral type, it must be either i32 or i64.
2900
2901 **Constraints**
2902
2903 .. naclcode::
2904
2905 AA == AbbrevIndex(A)
2906 VV == RelativeIndex(V)
2907 B == NumBasicBlocks + 1
2908 NumBasicBlocks < ExpectedBasicBlocks
2909 T == TypeOf(V) == ReturnType(TypeOf(EnclosingFcnID))
2910
2911 **Updates**
2912
2913 .. naclcode::
2914
2915 ++NumBasicBlocks;
2916
2917 **Examples**
2918
2919 .. naclcode::
2920
2921 120:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) {
2922 | | // BlockID = 12
2923 128:0| 3: <1, 1> | blocks 1;
2924 | | %b0:
2925 130:4| 3: <10, 1> | ret i32 %p0;
2926
2927 Unconditional Branch Instruction
2928 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2929
2930 The unconditional branch instruction is used to cause control flow to transfer
2931 to a different basic block of the function.
2932
2933 **Syntax**
2934
2935 .. naclcode::
2936
2937 br %bN; <A>
2938 %bB:
2939
2940 **Record**
2941
2942 .. naclcode::
2943
2944 AA: <11, N>
2945
2946 **Semantics**
2947
2948 The unconditional branch instruction causes control flow to transfer to basic
2949 block *N*.
2950
2951 *B* is the number associated with the next basic block. Label *%bB:* only
2952 appears if *B < ExpectedBasicBlocks*. That is, the label is omitted only if this
2953 terminator instruction is the last instruction in the function block.
2954
2955 **Constraints**
2956
2957 .. naclcode::
2958
2959 AA == AbbrevIndex(A)
2960 0 < N
2961 N < ExpectedBasicBlocks
2962 B == NumBasicBlocks + 1
2963 NumBasicBlocks < ExpectedBasicBlocks
2964
2965 **Updates**
2966
2967 .. naclcode::
2968
2969 ++NumBasicBlocks;
2970
2971 **Examples**
2972
2973 .. naclcode::
2974
2975 88:0| 1: <65535, 12, 2> | function void @f0() {
2976 | | // BlockID = 12
2977 96:0| 3: <1, 5> | blocks 5;
2978 | | %b0:
2979 98:4| 3: <11, 3> | br label %b3;
2980 | | %b1:
2981 101:0| 3: <11, 4> | br label %b4;
2982 | | %b2:
2983 103:4| 3: <11, 1> | br label %b1;
2984 | | %b3:
2985 106:0| 3: <11, 2> | br label %b2;
2986 | | %b4:
2987 108:4| 3: <10> | ret void;
2988 110:2| 0: <65534> | }
2989
2990 Conditional Branch Instruction
2991 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2992
2993 The conditional branch instruction is used to cause control flow to transfer to
2994 a different basic block of the function, based on a boolean test condition.
2995
2996 **Syntax**
2997
2998 .. naclcode::
2999
3000 br i1 C, %bT, %bBF; <A>
3001 %bB:
3002
3003 **Record**
3004
3005 .. naclcode::
3006
3007 AA: <11, T, F, CC>
3008
3009 **Semantics**
3010
3011 Upon execution of a conditional branch instruction, the *i1* (boolean) argument
3012 *C* is evaluated. If the value is *true*, control flows to basic block
3013 *%bT*. Otherwise control flows to basic block *%bF*.
3014
3015 *B* is the number associated with the next basic block. Label *%bB:* only
3016 appears if *B < ExpectedBasicBlocks*. That is, the label is omitted only if this
3017 terminator instruction is the last instruction in the function block.
3018
3019 **Constraints**
3020
3021 .. naclcode::
3022
3023 AA == AbbrevIndex(A)
3024 CC == RelativeIndex(C)
3025 0 < T
3026 B1 < ExpectedBasicBlocks
3027 0 < F
3028 B2 < ExpectedBasicBlocks
3029 B == NumBasicBlocks + 1
3030 NumBasicBlocks < ExpectedBasicBlocks
3031 TypeOf(C) == i1
3032
3033 **Updates**
3034
3035 .. naclcode::
3036
3037 ++NumBasicBlocks;
3038
3039 **Examples**
3040
3041 .. naclcode::
3042
3043 92:0| 1: <65535, 12, 2> | function void @f0() {
3044 | | // BlockID = 12
3045 100:0| 3: <1, 5> | blocks 5;
3046 102:4| 1: <65535, 11, 2> | constants { // BlockID = 11
3047 112:0| 3: <1, 1> | i1:
3048 114:4| 3: <4, 3> | %c0 = i1 1;
3049 117:0| 3: <4, 0> | %c1 = i1 0;
3050 119:4| 0: <65534> | }
3051 | | %b0:
3052 120:0| 3: <11, 3> | br label %b3;
3053 | | %b1:
3054 122:4| 3: <11, 2, 4, 2> | br i1 %c0, label %b2, label %b4;
3055 | | %b2:
3056 126:4| 3: <11, 3> | br label %b3;
3057 | | %b3:
3058 129:0| 3: <10> | ret void;
3059 | | %b4:
3060 130:6| 3: <11, 2, 3, 1> | br i1 %c1, label %b2, label %b3;
3061 134:6| 0: <65534> | }
3062
3063 Unreachable
3064 ^^^^^^^^^^^
3065
3066 The unreachable instruction has no defined semantics. The instruction is used to
3067 inform the *PNaCl translator* that control can't reach this instruction.
3068
3069 **Syntax**
3070
3071 .. naclcode::
3072
3073 unreachable; <A>
3074 %bB:
3075
3076 **Record**
3077
3078 .. naclcode::
3079
3080 AA: <15>
3081
3082 **Semantics**
3083
3084 Directive to the *PNaCl translator* that this instruction is unreachable. *B*
3085 is the number associated with the next basic block. Label *%bB:* only appears if
3086 *B < ExpectedBasicBlocks*. That is, the label is omitted only if this terminator
3087 instruction is the last instruction in the function block.
3088
3089 **Constraints**
3090
3091 .. naclcode::
3092
3093 AA == AbbrevIndex(A)
3094 B == NumBasicBlocks + 1
3095 NumBasicBlocks < ExpectedBasicBlocks
3096
3097 **Updates**
3098
3099 .. naclcode::
3100
3101 ++NumBasicBlocks;
3102
3103 **Examples**
3104
3105 .. naclcode::
3106
3107 108:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
3108 | | // BlockID = 12
3109 116:0| 3: <1, 5> | blocks 5;
3110 118:4| 1: <65535, 11, 2> | constants { // BlockID = 11
3111 128:0| 3: <1, 2> | i1:
3112 130:4| 3: <4, 3> | %c0 = i1 1;
3113 133:0| 3: <4, 0> | %c1 = i1 0;
3114 135:4| 0: <65534> | }
3115 | | %b0:
3116 136:0| 3: <11, 1, 2, 2> | br i1 %c0, label %b1, label %b2;
3117 | | %b1:
3118 140:0| 3: <11, 3, 4, 1> | br i1 %c1, label %b3, label %b4;
3119 | | %b2:
3120 144:0| 3: <15> | unreachable;
3121 | | %b3:
3122 145:6| 3: <15> | unreachable;
3123 | | %b4:
3124 147:4| 3: <10> | ret void;
3125 149:2| 0: <65534> | }
3126
3127 Switch Instruction
3128 ^^^^^^^^^^^^^^^^^^
3129
3130 The *switch* instruction transfers control flow to one of several different
3131 places, based on a selector value. It is a generaliation of the conditional
Jim Stichnoth 2014/07/28 18:21:05 generalization
Karl 2014/11/14 22:35:32 Done.
3132 branch instruction.
3133
3134 **Syntax**
3135
3136 .. naclcode::
3137
3138 switch T V0 {
3139 default: br label %bB0;
3140 T V1: br label %bB1;
3141 ...
3142 T VN: br label %bBN;
3143 } <A>
3144 %bB:
3145
3146 **Record**
3147
3148 .. naclcode::
3149
3150 AA: <12, TT, B0, N, (1, 1, VVI, BI | 1 <= i <= N)>
3151
3152 **Sematics**
Jim Stichnoth 2014/07/28 18:21:05 Semantics
Karl 2014/11/14 22:35:29 Done.
3153
3154 The switch instruction transfer control to a basic block in B0 through BN.
Jim Stichnoth 2014/07/28 22:52:06 transfers
Karl 2014/11/14 22:35:35 Done.
3155 Value *V* is used to conditionally select which block to branch to. *T* is the
3156 type of *V* and *V1* through *VN*, and must be an integral type. Value *V1*
3157 through *VN* are integers to compare against *V*. If selector *V* matches *VI*
3158 (for some I, 1 <= I <= N), then the instruction branches to block *BI*. If *V*
3159 is not in *V1* through *VN*, the instruction branches to block *B0*.
3160
3161 **Constraints**
3162
3163 .. naclcode::
3164
3165 AA == AbbrevIndex(A)
3166 TT == TypeID(T)
3167 VI == SignRotate(VI) for all I, 1 <= I <= N
3168 B == NumBasicBlocks + 1
3169 NumBasicBlocks < ExpectedBasicBlocks
3170
3171 **Updates**
3172
3173 .. naclcode:
3174
3175 ++NumBasicBlocks;
3176
3177 **Examples**
3178
3179 .. naclcode::
3180
3181 116:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
3182 | | // BlockID = 12
3183 124:0| 3: <1, 6> | blocks 6;
3184 | | %b0:
3185 126:4| 3: <12, 1, 1, 2, 4, 1, 1,| switch i32 %p0 {
3186 | 2, 3, 1, 1, 4, 3, 1, | default: br label %b2;
3187 | 1, 8, 4, 1, 1, 10, 4>| i32 1: br label %b3;
3188 | | i32 2: br label %b3;
3189 | | i32 4: br label %b4;
3190 | | i32 5: br label %b4;
3191 | | }
3192 | | %b1:
3193 143:2| 3: <11, 5> | br label %b5;
3194 | | %b2:
3195 145:6| 3: <11, 5> | br label %b5;
3196 | | %b3:
3197 148:2| 3: <11, 5> | br label %b5;
3198 | | %b4:
3199 150:6| 3: <11, 5> | br label %b5;
3200 | | %b5:
3201 153:2| 3: <10> | ret void;
3202 155:0| 0: <65534> | }
3203 156:0| 1: <65535, 12, 2> | function void @f1(i64 %p0) {
3204 | | // BlockID = 12
3205 164:0| 3: <1, 6> | blocks 6;
3206 | | %b0:
3207 166:4| 3: <12, 2, 1, 2, 4, 1, 1,| switch i64 %p0 {
3208 | 2, 3, 1, 1, 4, 3, 1, | default: br label %b2;
3209 | 1, 8, 4, 1, 1, | i64 1: br label %b3;
3210 | 39777555332, 4> | i64 2: br label %b3;
3211 | | i64 4: br label %b4;
3212 | | i64 19888777666: br label %b4;
3213 | | }
3214 | | %b1:
3215 188:4| 3: <11, 5> | br label %b5;
3216 | | %b2:
3217 191:0| 3: <11, 5> | br label %b5;
3218 | | %b3:
3219 193:4| 3: <11, 5> | br label %b5;
3220 | | %b4:
3221 196:0| 3: <11, 5> | br label %b5;
3222 | | %b5:
3223 198:4| 3: <10> | ret void;
3224 200:2| 0: <65534> | }
3225
3226
3227 Integer Binary Instructions
3228 -----------------------------
3229
3230 Binary instructions are used to do most of the computation in a program. This
3231 section focuses on binary instructions that operator on integral values, or
3232 vectors of integral values.
3233
3234 All binary operations require two operands of the same type, execute an
3235 operation on them, and produce a value. The value may represent multiple values
3236 if the type is a vector type. The result value always has the same type as its
3237 operands.
3238
3239 Some integer binary operations can be applied to both signed and unsigned
3240 integers. Others, the sign is significant. In general, if the sign plays a role
3241 in the instruction, the sign information is encoded into the name of the
3242 instruction.
3243
3244 For most binary operations (except some of the logical operations), integral
3245 type i1 is disallowed.
3246
3247 Integer Add
3248 ^^^^^^^^^^^
3249
3250 The integer add instruction returns the sum of its two arguments. Both arguments
3251 and the result must be of the same type. That type must be integral, or an
3252 integral vector type.
3253
3254 **Syntax**
3255
3256 .. naclcode::
3257
3258 %vN = add T V1, V2; <A>
3259
3260 **Record**
3261
3262 .. naclcode::
3263
3264 AA: <2, VV1, VV2, 0>
3265
3266 **Semantics**
3267
3268 The integer add instruction returns the sum of its two arguments. Arguments *V1*
3269 and *V2*, and the result *%vN*, must be of type *T*. *T* must be an integral
3270 type, or an integral vector type. *N* is defined by the record position,
3271 defining the corresponding value generated by the instruction.
3272
3273 The result returned is the mathematical result modulo *exp(2,n)*, where *n* is
Jim Stichnoth 2014/07/28 22:52:04 Here (and 2 other places) you use exp(2,n), but in
Karl 2014/11/14 22:35:31 Done.
3274 the bitwidth of the integer result.
3275
3276 Because integers are assumed to use a two's complement representation,
3277 this instruction is appropriate for both signed and unsigned integers.
3278
3279 In the add instruction, integral type i1 (and a vector on integral type i1) is
3280 disallowed.
3281
3282 **Constraints**
3283
3284 .. naclcode::
3285
3286 AA == AbbrevIndex(A)
3287 VV1 == RelativeIndex(V1)
3288 VV2 == RelativeIndex(V2)
3289 T == TypeOf(V1) == TypeOf(V2)
3290 IsInteger(UnderlyingType(T))
3291 UnderlyingType(T) != i1
3292 N == NumValuedInsts
3293 NumBasicBlocks < ExpectedBasicBlocks
jvoung (off chromium) 2014/07/28 19:20:34 Do we need to have the NumBasicBlocks < ExpectedBa
Karl 2014/11/14 22:35:27 Yes. It states that you can't branch to an unknown
3294
3295 **Updates**
3296
3297 .. naclcode::
3298
3299 ++NumValuedInsts;
3300 TypeOf(%vN) = T
3301
3302 **Examples**
3303
3304 .. naclcode::
3305
3306 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3307 | | // BlockID = 12
3308 104:0| 3: <1, 1> | blocks 1;
3309 | | %b0:
3310 106:4| 3: <2, 2, 1, 0> | %v0 = add i32 %p0, %p1;
3311 110:4| 3: <2, 3, 1, 0> | %v1 = add i32 %p0, %v0;
3312 114:4| 3: <10, 1> | ret i32 %v1;
3313 117:0| 0: <65534> | }
3314
3315 Integer Subtract
3316 ^^^^^^^^^^^^^^^^
3317
3318 The integer subtract instruction returns the difference of its two arguments.
3319 Both arguments and the result must be of the same type. That type must be
3320 integral, or an integral vector type.
3321
3322 Note: Since there isn't a negate instruction, subtraction from constant zero
3323 should be used to negate values.
3324
3325 **Syntax**
3326
3327 .. naclcode::
3328
3329 %vN = sub T V1, V2; <A>
3330
3331 **Record**
3332
3333 .. naclcode::
3334
3335 AA: <2, VV1, VV2, 1>
3336
3337 **Semantics**
3338
3339 The integer subtract returns the difference of its two arguments. Arguments *V1*
3340 and *V2*, and the result *%vN* must be of type *T*. *T* must be an integral
3341 type, or an integral vector type. *N* is defined by the record position,
3342 defining the corresponding value generated by the instruction.
3343
3344 The result returned is the mathematical result modulo *exp(2, n)*, where *n* is
3345 the integer bitwidth of the result.
3346
3347 Because integers are assumed to use a two's complement representation,
3348 this instruction is appropriate for both signed and unsigned integers.
3349
3350 In the subtract instruction, integral type i1 (and a vector on integral type i1)
3351 is disallowed.
3352
3353 **Constraints**
3354
3355 .. naclcode::
3356
3357 AA == AbbrevIndex(A)
3358 VV1 == RelativeIndex(V1)
3359 VV2 == RelativeIndex(V2)
3360 T == TypeOf(V1) == TypeOf(V2)
3361 IsInteger(UnderlyingType(T))
3362 UnderlyingType(T) != i1
3363 N == NumValuedInsts
3364 NumBasicBlocks < ExpectedBasicBlocks
3365
3366 **Updates**
3367
3368 .. naclcode::
3369
3370 ++NumValuedInsts;
3371 TypeOf(%vN) = T
3372
3373 **Examples**
3374
3375 .. naclcode::
3376
3377 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3378 | | // BlockID = 12
3379 104:0| 3: <1, 1> | blocks 1;
3380 | | %b0:
3381 106:4| 3: <2, 2, 1, 1> | %v0 = sub i32 %p0, %p1;
3382 110:4| 3: <2, 3, 1, 1> | %v1 = sub i32 %p0, %v0;
3383 114:4| 3: <10, 1> | ret i32 %v1;
3384 117:0| 0: <65534> | }
3385
3386 Integer Multiply
3387 ^^^^^^^^^^^^^^^^
3388
3389 The integer multiply instruction returns the product of its two arguments. Both
3390 arguments and the result must be of the same type. That type must be integral,
3391 or an integral based vector type.
3392
3393 **Syntax**
3394
3395 .. naclcode::
3396
3397 &vN = mul T V1, V2; <A>
3398
3399 **Record**
3400
3401 .. naclcode::
3402
3403 AA: <2, VV1, VV2, 2>
3404
3405 **Semantics**
3406
3407 The integer multiply instruction returns the product of its two
3408 arguments. Arguments *V1* and *V2*, and the result *%vN*, must be of type *T*.
3409 *T* must be an integral type, or an integral vector type. *N* is defined by the
3410 record position, defining the corresponding value generated by the instruction.
3411
3412 The result returned is the mathematical result modulo *exp(2, n)*, where *n* is
3413 the bitwidth of the result.
3414
3415 Because integers are assumed to use a two's complement representation,
3416 this instruction is appropriate for both signed and unsigned integers.
3417
3418 In the subtract instruction, integral type i1 (or a vector on integrap type i1)
Jim Stichnoth 2014/07/28 18:21:05 integral
Jim Stichnoth 2014/07/28 22:52:07 multiply instruction
Karl 2014/11/14 22:35:35 Done.
3419 is disallowed.
3420
3421 **Constraints**
3422
3423 .. naclcode::
3424
3425 AA == AbbrevIndex(A)
3426 VV1 == RelativeIndex(V1)
3427 VV2 == RelativeIndex(V2)
3428 T == TypeOf(V1) == TypeOf(V2)
3429 IsInteger(UnderlyingType(T))
3430 UnderlyingType(T) != i1
3431 N == NumValuedInsts
3432 NumBasicBlocks < ExpectedBasicBlocks
3433
3434 **Updates**
3435
3436 .. naclcode::
3437
3438 ++NumValuedInsts;
3439 TypeOf(%vN) = T
3440
3441 **Examples**
3442
3443 .. naclcode::
3444
3445 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3446 | | // BlockID = 12
3447 104:0| 3: <1, 1> | blocks 1;
3448 | | %b0:
3449 106:4| 3: <2, 2, 1, 2> | %v0 = mul i32 %p0, %p1;
3450 110:4| 3: <2, 1, 3, 2> | %v1 = mul i32 %v0, %p0;
3451 114:4| 3: <10, 1> | ret i32 %v1;
3452 117:0| 0: <65534> | }
3453
3454 Signed Integer Divide
3455 ^^^^^^^^^^^^^^^^^^^^^
3456
3457 The signed integer divide instruction returns the quotient of its two arguments.
3458 Both arguments and the result must be of the same type. That type must be
3459 integral, or an integral vector type.
3460
3461 **Syntax**
3462
3463 .. naclcode::
3464
3465 %vN = sdiv T V1, V2; <A>
3466
3467 **Record**
3468
3469 .. naclcode::
3470
3471 AA: <2, VV1, VV2, 4>
3472
3473 **Semantics**
3474
3475 The signed integer divide instruction returns the quotient of its two
3476 arguments. Arguments *V1* and *V2*, and the result *%vN*, must be of type
3477 *T*. *T* must be a integral type, or an integral vector type. *N* is defined by
3478 the record position, defining the corresponding value generated by the
3479 instruction.
3480
3481 Signed values are assumed. Note that signed and unsigned integer division are
3482 distinct operations. For unsigned integer division use the unsigned integer
3483 divide instruction (udiv).
3484
3485 In the signed integer divide instruction, integral type i1 (and a vector on
3486 integral type i1) is disallowed. Integer division by zero is guaranteed to trap.
3487
3488 Note that overflow can happen with this instruction when dividing the maximum
3489 negative integer by -1. The behaviour for this case is undefined.
Jim Stichnoth 2014/07/28 18:21:08 behavior :)
Jim Stichnoth 2014/07/28 22:52:05 Maybe say behavior is "currently" undefined? Sinc
Karl 2014/11/14 22:35:29 Done.
Karl 2014/11/14 22:35:29 Done.
3490
3491 **Constraints**
3492
3493 .. naclcode::
3494
3495 AA == AbbrevIndex(A)
3496 VV1 == RelativeIndex(V1)
3497 VV2 == RelativeIndex(V2)
3498 T == TypeOf(V1) == TypeOf(V2)
3499 IsInteger(UnderlyingType(T))
3500 UnderlyingType(T) != i1
3501 N == NumValuedInsts
3502 NumBasicBlocks < ExpectedBasicBlocks
3503
3504 **Updates**
3505
3506 .. naclcode::
3507
3508 ++NumValuedInsts;
3509 TypeOf(%vN) = T
3510
3511 **Examples**
3512
3513 .. naclcode::
3514
3515 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3516 | | // BlockID = 12
3517 104:0| 3: <1, 1> | blocks 1;
3518 | | %b0:
3519 106:4| 3: <2, 2, 1, 4> | %v0 = sdiv i32 %p0, %p1;
3520 110:4| 3: <2, 1, 2, 4> | %v1 = sdiv i32 %v0, %p1;
3521 114:4| 3: <10, 1> | ret i32 %v1;
3522 117:0| 0: <65534> | }
3523
3524 Unsigned Integer Divide
3525 ^^^^^^^^^^^^^^^^^^^^^^^
3526
3527 The unsigned integer divide instruction returns the quotient of its two
3528 arguments. Both the arguments and the result must be of the same type. That type
3529 must be integral, or an integral vector type.
3530
3531 **Syntax**
3532
3533 .. naclcode::
3534
3535 %vN = udiv T V1, V2; <a>
3536
3537 **Record**
3538
3539 .. naclcode::
3540
3541 AA: <2, A1, A2, 3>
3542
3543 **Semantics**
3544
3545 The unsigned integer divide instruction returns the quotient of its two
3546 arguments. Arguments *V1* and *V2*, and the result *%vN*, must be of type
3547 *T*. *T* must be an integral type, or an integral vector type. *N* is defined
3548 by the record position, defining the corresponding value generated by the
3549 instruction.
3550
3551 Unsigned integral values are assumed. Note that signed and unsigned integer
3552 division are distinct operations. For signed integer division use the signed
3553 integer divide instruction (sdiv).
3554
3555 In the unsigned integer divide instruction, integral type i1 (and a vector on
3556 integral type i1) is disallowed. Division by zero is guaranteed to trap.
3557
3558 **Constraints**
3559
3560 .. naclcode::
3561
3562 AA == AbbrevIndex(A)
3563 VV1 == RelativeIndex(V1)
3564 VV2 == RelativeIndex(V2)
3565 T == TypeOf(V1) == TypeOf(V2)
3566 IsInteger(UnderlyingType(T))
3567 UnderlyingType(T) != i1
3568 N == NumValuedInsts
3569 NumBasicBlocks < ExpectedBasicBlocks
3570
3571 **Updates**
3572
3573 .. naclcode::
3574
3575 ++NumValuedInsts;
3576 TypeOf(%vN) = T
3577
3578 **Examples**
3579
3580 .. naclcode::
3581
3582 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3583 | | // BlockID = 12
3584 104:0| 3: <1, 1> | blocks 1;
3585 | | %b0:
3586 106:4| 3: <2, 2, 1, 3> | %v0 = udiv i32 %p0, %p1;
3587 110:4| 3: <2, 1, 2, 3> | %v1 = udiv i32 %v0, %p1;
3588 114:4| 3: <10, 1> | ret i32 %v1;
3589 117:0| 0: <65534> | }
3590
3591 Signed Integer Remainder
3592 ^^^^^^^^^^^^^^^^^^^^^^^^
3593
3594 The signed integer remainder instruction returns the remainder of the quotient
3595 of its two arguments. Both arguments and the result must be of the same
3596 type. That type must be integral, or an integral based vector type.
3597
3598 **Syntax**
3599
3600 .. naclcode::
3601
3602 %vN = srem T V1, V2; <A>
3603
3604 **Record**
3605
3606 .. naclcode::
3607
3608 AA: <2, VV1, VV2, 6>
3609
3610 **Semantics**
3611
3612 The signed integer remainder instruction returns the remainder of the quotient
3613 of its two arguments. Arguments *V1* and *V2*, and the result *%vN*, must be of
3614 type *T*. *T* must be a integral type, or an integral vector type. *N* is
3615 defined by the record position, defining the corresponding value generated by
3616 the instruction.
3617
3618 Signed values are assumed. Note that signed and unsigned integer division are
3619 distinct operations. For unsigned integer division use the unsigned integer
3620 remainder instruction (urem).
3621
3622 In the signed integer remainder instruction, integral type i1 (and a vector on
3623 integral type i1) is disallowed. Division by zero is guaranteed to trap.
Jim Stichnoth 2014/07/28 22:52:09 You need the same comment as sdiv about undefined
Karl 2014/11/14 22:35:32 Done.
3624
3625 **Constraints**
3626
3627 .. naclcode::
3628
3629 AA == AbbrevIndex(A)
3630 VV1 == RelativeIndex(V1)
3631 VV2 == RelativeIndex(V2)
3632 T == TypeOf(V1) == TypeOf(V2)
3633 IsInteger(UnderlyingType(T))
3634 UnderlyingType(T) != i1
3635 N == NumValuedInsts
3636 NumBasicBlocks < ExpectedBasicBlocks
3637
3638 **Updates**
3639
3640 .. naclcode::
3641
3642 ++NumValuedInsts;
3643 TypeOf(%vN) = T
3644
3645 **Examples**
3646
3647 .. naclcode::
3648
3649 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3650 | | // BlockID = 12
3651 104:0| 3: <1, 1> | blocks 1;
3652 | | %b0:
3653 106:4| 3: <2, 2, 1, 6> | %v0 = srem i32 %p0, %p1;
3654 110:4| 3: <2, 1, 2, 6> | %v1 = srem i32 %v0, %p1;
3655 114:4| 3: <10, 1> | ret i32 %v1;
3656 117:0| 0: <65534> | }
3657
3658 Unsigned Integer Remainder Instruction
3659 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3660
3661 The unsigned integer remainder instruction returns the remainder of the quotient
3662 of its two arguments. Both the arguments and the result must be of the same
3663 type. The type must be integral, or an integral vector type.
3664
3665 **Syntax**
3666
3667 .. naclcode::
3668
3669 %vN = urem T V1, V2; <A>
3670
3671 **Record**
3672
3673 .. naclcode::
3674
3675 AA: <2, A1, A2, 5>
3676
3677 **Semantics**
3678
3679 The unsigned integer remainder instruction returns the remainder of the quotient
3680 of its two arguments. Arguments *V1* and *V2*, and the result *%vN*, must be of
3681 type *T*. *T* must be an integral type, or an integral vector type. *N* is
3682 defined by the record position, defining the corresponding value generated by
3683 the instruction.
3684
3685 Unsigned values are assumed. Note that signed and unsigned integer division are
3686 distinct operations. For signed integer division use the remainder instruction
3687 (srem).
3688
3689 In the unsigned integer remainder instruction, integral type i1 (and a vector on
3690 integral type i1) is disallowed. Division by zero is guaranteed to trap.
3691
3692 **Constraints**
3693
3694 .. naclcode::
3695
3696 AA == AbbrevIndex(A)
3697 VV1 == RelativeIndex(V1)
3698 VV2 == RelativeIndex(V2)
3699 T == TypeOf(V1) == TypeOf(V2)
3700 IsInteger(UnderlyingType(T))
3701 UnderlyingType(T) != i1
3702 N == NumValuedInsts
3703 NumBasicBlocks < ExpectedBasicBlocks
3704
3705 **Updates**
3706
3707 .. naclcode::
3708
3709 ++NumValuedInsts;
3710 TypeOf(%vN) = T
3711
3712 **Examples**
3713
3714 .. naclcode::
3715
3716 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3717 | | // BlockID = 12
3718 104:0| 3: <1, 1> | blocks 1;
3719 | | %b0:
3720 106:4| 3: <2, 2, 1, 5> | %v0 = urem i32 %p0, %p1;
3721 110:4| 3: <2, 1, 2, 5> | %v1 = urem i32 %v0, %p1;
3722 114:4| 3: <10, 1> | ret i32 %v1;
3723 117:0| 0: <65534> | }
3724
3725 Shift Left
3726 ^^^^^^^^^^
3727
3728 The (integer) shift left instruction returns the first operand, shifted to the
3729 left a specified number of bits with zero fill. The shifted value must be
3730 integral, or an integral vector type.
3731
3732 **Syntax**
3733
3734 .. naclcode::
3735
3736 %vN = shl T V1, V2; <A>
3737
3738 **Record**
3739
3740 .. naclcode::
3741
3742 AA: <2, VV1, VV2, 7>
3743
3744 **Semantics**
3745
3746 This instruction performs a shift left operation. Arguments *V1* and *V2* and
3747 the result *%vN* must be of type *T*. *T* nust be an integral, or a vector of
Jim Stichnoth 2014/07/28 18:21:07 must
Karl 2014/11/14 22:35:34 Done.
3748 integrals. *N* is defined by the record position, defining the corresponding
3749 value generated by the instruction.
3750
3751 *V2* is assumed to be unsigned. The least significant bits of the
3752 result will be filled with zero bits after the shift. If *V2* is
3753 (statically or dynamically) is negative or equal to or larger than the
Jim Stichnoth 2014/07/28 22:52:08 remove "is"
Karl 2014/11/14 22:35:31 Done.
3754 number of bits in *V1*, the result is undefined. If the arguments are
3755 vectors, each vector element of *V1* is shifted by the corresponding
3756 shift amount in *V2*.
3757
3758 In the shift left instruction, integral type i1 (and a vector on integral type
3759 i1) is disallowed.
3760
3761 **Constraints**
3762
3763 .. naclcode::
3764
3765 AA == AbbrevIndex(A)
3766 VV1 == RelativeIndex(V1)
3767 VV2 == RelativeIndex(V2)
3768 T == TypeOf(V1) == TypeOf(V2)
3769 IsInteger(UnderlyingType(T))
3770 UnderlyingType(T) != i1
3771 N == NumValuedInsts
3772 NumBasicBlocks < ExpectedBasicBlocks
3773
3774 **Updates**
3775
3776 .. naclcode::
3777
3778 ++NumValuedInsts;
3779 TypeOf(%vN) = T
3780
3781 **Examples**
3782
3783 .. naclcode::
3784
3785 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3786 | | // BlockID = 12
3787 104:0| 3: <1, 1> | blocks 1;
3788 | | %b0:
3789 106:4| 3: <2, 2, 1, 7> | %v0 = shl i32 %p0, %p1;
3790 110:4| 3: <2, 1, 2, 7> | %v1 = shl i32 %v0, %p1;
3791 114:4| 3: <10, 1> | ret i32 %v1;
3792 117:0| 0: <65534> | }
3793
3794 Logical Shift Right
3795 ^^^^^^^^^^^^^^^^^^^
3796
3797 The logical shift right instruction returns the first operand, shifted to the
3798 right a specified number of bits with zero fill.
3799
3800 **Syntax**
3801
3802 .. naclcode::
3803
3804 %vN = lshr T V1, V2; <A>
3805
3806 **Record**
3807
3808 .. naclcode::
3809
3810 AA: <2, VV1, VV2, 8>
3811
3812 **Semantics**
3813
3814 This instruction performs a logical shift right operation. Arguments *V1* and
3815 *V2* and the result *%vN* must be of type *T*. *T* nust be an integral, or a
Jim Stichnoth 2014/07/28 18:21:04 must
Karl 2014/11/14 22:35:34 Done.
3816 vector of integrals. *N* is defined by the record position, defining the
3817 corresponding value generated by the instruction.
3818
3819 *V2* is assumed to be unsigned. The most significant bits of the result will be
3820 filled with zero bits after the shift. If *V2* is (statically or dynamically)
3821 negative or equal to or larger than the number of bits in *V1*, the result is
3822 undefined. If the arguments are vectors, each vector element of *V1* is shifted
3823 by the corresponding shift amount in *V2*.
3824
3825 In the logical shift right instruction, integral type i1 (and a vector on
3826 integral type i1) is disallowed.
3827
3828 **Constraints**
3829
3830 .. naclcode::
3831
3832 AA == AbbrevIndex(A)
3833 VV1 == RelativeIndex(V1)
3834 VV2 == RelativeIndex(V2)
3835 T == TypeOf(V1) == TypeOf(V2)
3836 IsInteger(UnderlyingType(T))
3837 UnderlyingType(T) != i1
3838 N == NumValuedInsts
3839 NumBasicBlocks < ExpectedBasicBlocks
3840
3841 **Updates**
3842
3843 .. naclcode::
3844
3845 ++NumValuedInsts;
3846 TypeOf(%vN) = T
3847
3848 **Examples**
3849
3850 .. naclcode::
3851
3852 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3853 | | // BlockID = 12
3854 104:0| 3: <1, 1> | blocks 1;
3855 | | %b0:
3856 106:4| 3: <2, 2, 1, 8> | %v0 = lshr i32 %p0, %p1;
3857 110:4| 3: <2, 1, 2, 8> | %v1 = lshr i32 %v0, %p1;
3858 114:4| 3: <10, 1> | ret i32 %v1;
3859 117:0| 0: <65534> | }
3860
3861 Arithmetic Shift Right
3862 ^^^^^^^^^^^^^^^^^^^^^^
3863
3864 The arithmetic shift right instruction returns the first operand, shifted to the
3865 right a specified number of bits with sign extension.
3866
3867 **Syntax**
3868
3869 .. naclcode::
3870
3871 %vN = ashr T V1, V2; <A>
3872
3873 **Record**
3874
3875 .. naclcode::
3876
3877 AA: <2, VV1, VVA2, 9>
3878
3879 **Semantics**
3880
3881 This instruction performs an arithmetic shift right operation. Arguments *V1*
3882 and *V2* and and the result *%vN* must be of type *T*. *T* nust be an integral,
Jim Stichnoth 2014/07/28 18:21:09 must
Karl 2014/11/14 22:35:35 Done.
3883 or a vector of integrals. *N* is defined by the record position, defining the
3884 corresponding value generated by the instruction.
3885
3886 *V2* is assumed to be unsigned. The most significant bits of the result will be
3887 filled with the sign bit of *V1*. If *V2* is (statically or dynamically)
3888 negative or equal to or larger than the number of bits in *V1*, the result is
3889 undefined. If the arguments are vectors, each vector element of *V1* is shifted
3890 by the corresponding shift amount in *V2*.
3891
3892 In the arithmetic shift right instruction, integral type i1 (and a vector on
3893 integrl type i1) is disallowed.
Jim Stichnoth 2014/07/28 18:21:07 integral
Karl 2014/11/14 22:35:29 Done.
3894
3895 **Constraints**
3896
3897 .. naclcode::
3898
3899 AA == AbbrevIndex(A)
3900 VV1 == RelativeIndex(V1)
3901 VV2 == RelativeIndex(V2)
3902 T == TypeOf(V1) == TypeOf(V2)
3903 IsInteger(UnderlyingType(T))
3904 UnderlyingType(T) != i1
3905 N == NumValuedInsts
3906 NumBasicBlocks < ExpectedBasicBlocks
3907
3908 **Updates**
3909
3910 .. naclcode::
3911
3912 ++NumValuedInsts;
3913 TypeOf(%vN) = T
3914
3915 **Examples**
3916
3917 .. naclcode::
3918
3919 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3920 | | // BlockID = 12
3921 104:0| 3: <1, 1> | blocks 1;
3922 | | %b0:
3923 106:4| 3: <2, 2, 1, 9> | %v0 = ashr i32 %p0, %p1;
3924 110:4| 3: <2, 1, 2, 9> | %v1 = ashr i32 %v0, %p1;
3925 114:4| 3: <10, 1> | ret i32 %v1;
3926 117:0| 0: <65534> | }
3927
3928 Logical And
3929 ^^^^^^^^^^^
3930
3931 The *and* instruction returns the bitwise logical and of its two operands.
3932
3933 **Syntax**
3934
3935 .. naclcode::
3936
3937 %vN = and T V1, V2; <A>
3938
3939 **Record**
3940
3941 .. naclcode::
3942
3943 AA: <2, VV1, VV2, 10>
3944
3945 **Semantics**
3946
3947 This instruction performs a bitwise logical and of its arguments. Arguments
3948 *V1* and *V2*, and the result *%vN* must be of type *T*. *T* nust be an
Jim Stichnoth 2014/07/28 18:21:07 must
Karl 2014/11/14 22:35:31 Done.
3949 integral, or a vector of integrals. *N* is defined by the record position,
3950 defining the corresponding value generated by the instruction. *A* is the
3951 (optional) abbreviation associated with the corresponding record.
3952
3953 The truth table used for the *and* instruction is:
3954
3955 ===== ===== ======
3956 Arg 1 Arg 2 Result
3957 ===== ===== ======
3958 0 0 0
3959 0 1 0
3960 1 0 0
3961 1 1 1
3962 ===== ===== ======
3963
3964 **Constraints**
3965
3966 .. naclcode::
3967
3968 AA == AbbrevIndex(A)
3969 VV1 == RelativeIndex(V1)
3970 VV2 == RelativeIndex(V2)
3971 T == TypeOf(V1) == TypeOf(V2)
3972 IsInteger(UnderlyingType(T)))
3973 N == NumValuedInsts
3974 NumBasicBlocks < ExpectedBasicBlocks
3975
3976 **Updates**
3977
3978 .. naclcode::
3979
3980 ++NumValuedInsts;
3981 TypeOf(%vN) = T
3982
3983 **Examples**
3984
3985 .. naclcode::
3986
3987 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
3988 | | // BlockID = 12
3989 104:0| 3: <1, 1> | blocks 1;
3990 | | %b0:
3991 106:4| 3: <2, 2, 1, 10> | %v0 = and i32 %p0, %p1;
3992 110:4| 3: <2, 1, 2, 10> | %v1 = and i32 %v0, %p1;
3993 114:4| 3: <10, 1> | ret i32 %v1;
3994 117:0| 0: <65534> | }
3995
3996 Logical Or
3997 ^^^^^^^^^^
3998
3999 The *or* instruction returns the bitwise logical inclusive or of its
4000 two operands.
4001
4002 **Syntax**
4003
4004 .. naclcode::
4005
4006 %vN = or T V1, V2; <A>
4007
4008 **Record**
4009
4010 .. naclcode::
4011
4012 AA: <2, VV1, VV2, 11>
4013
4014 **Semantics**
4015
4016 This instruction performs a bitwise logical inclusive or of its arguments.
4017 Arguments *V1* and *V2*, and the result *%vN* must be of type *T*. *T* nust be
Jim Stichnoth 2014/07/28 18:21:05 must
Karl 2014/11/14 22:35:35 Done.
4018 an integral, or a vector of integrals. *N* is defined by the record position,
4019 defining the corresponding value generated by the instruction.
4020
4021 The truth table used for the *or* instruction is:
4022
4023 ===== ===== ======
4024 Arg 1 Arg 2 Result
4025 ===== ===== ======
4026 0 0 0
4027 0 1 1
4028 1 0 1
4029 1 1 1
4030 ===== ===== ======
4031
4032 **Constraints**
4033
4034 .. naclcode::
4035
4036 AA == AbbrevIndex(A)
4037 VV1 == RelativeIndex(V1)
4038 VV2 == RelativeIndex(V2)
4039 T == TypeOf(V1) == TypeOf(V2)
4040 IsInteger(UnderlyingType(T)))
4041 N == NumValuedInsts
4042 NumBasicBlocks < ExpectedBasicBlocks
4043
4044 **Updates**
4045
4046 .. naclcode::
4047
4048 ++NumValuedInsts;
4049 TypeOf(%vN) = T
4050
4051 **Examples**
4052
4053 .. naclcode::
4054
4055 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
4056 | | // BlockID = 12
4057 104:0| 3: <1, 1> | blocks 1;
4058 | | %b0:
4059 106:4| 3: <2, 2, 1, 11> | %v0 = or i32 %p0, %p1;
4060 110:4| 3: <2, 1, 2, 11> | %v1 = or i32 %v0, %p1;
4061 114:4| 3: <10, 1> | ret i32 %v1;
4062 117:0| 0: <65534> | }
4063
4064 Logical Xor
4065 ^^^^^^^^^^^
4066
4067 The *xor* instruction returns the bitwise logical exclusive or of its
4068 two operands.
4069
4070 **Syntax**
4071
4072 .. naclcode::
4073
4074 %vN = xor T V1, V2; <A>
4075
4076 **Record**
4077
4078 .. naclcode::
4079
4080 AA: <2, VV1, VV2, 12>
4081
4082 **Semantics**
4083
4084 This instruction performs a bitwise logical exclusive or of its
4085 arguments. Arguments *V1* and *V2*, and the result *%vN* must be of
4086 type *T*. *T* nust be an integral, or a vector of integrals. *N* is
Jim Stichnoth 2014/07/28 18:21:07 must
Karl 2014/11/14 22:35:33 Done.
4087 defined by the record position, defining the corresponding value
4088 generated by the instruction.
4089
4090 The truth table used for the *or* instruction is:
4091
4092 ===== ===== ======
4093 Arg 1 Arg 2 Result
4094 ===== ===== ======
4095 0 0 0
4096 0 1 1
4097 1 0 1
4098 1 1 0
4099 ===== ===== ======
4100
4101 **Constraints**
4102
4103 .. naclcode::
4104
4105 AA == AbbrevIndex(A)
4106 A1 == RelativeIndex(V1)
4107 A2 == RelativeIndex(V2)
4108 T == TypeOf(V1) == TypeOf(V2)
4109 IsInteger(UnderlyingType(T)))
4110 N == NumValuedInsts
4111 NumBasicBlocks < ExpectedBasicBlocks
4112
4113 **Updates**
4114
4115 .. naclcode::
4116
4117 ++NumValuedInsts;
4118 TypeOf(%vN) = T
4119
4120 **Examples**
4121
4122 .. naclcode::
4123
4124 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
4125 | | // BlockID = 12
4126 104:0| 3: <1, 1> | blocks 1;
4127 | | %b0:
4128 106:4| 3: <2, 2, 1, 12> | %v0 = xor i32 %p0, %p1;
4129 110:4| 3: <2, 1, 2, 12> | %v1 = xor i32 %v0, %p1;
4130 114:4| 3: <10, 1> | ret i32 %v1;
4131 117:0| 0: <65534> | }
4132
4133 Floating Point Binary Instructions
4134 ----------------------------------
4135
4136 Floating point binary instructions require two operands of the same type,
4137 execute an operation on them, and produce a value. The value may represent
4138 multiple values if the type is a vector type. The result value always has the
4139 same type as its operands.
4140
4141 Floating Point Add
4142 ^^^^^^^^^^^^^^^^^^
4143
4144 The floating point add instruction returns the sum of its two arguments. Both
4145 arguments and the result must be of the same type. That type must be a floating
4146 point type, or a vector of a floating point type.
4147
4148 **Syntax**
4149
4150 .. naclcode::
4151
4152 %vN = fadd T V1, V2; <A>
4153
4154 **Record**
4155
4156 .. naclcode::
4157
4158 AA: <2, VV1, VV2, 0>
4159
4160 **Semantics**
4161
4162 The floating point add instruction returns the sum of its two arguments.
4163 Arguments *V1* and *V2* and the result *%vN* must be of type *T*. *T* must be a
4164 floating point type, or a vector of a floating point type. *N* is defined by the
4165 record position, defining the corresponding value generated by the instruction.
4166
4167 **Constraints**
4168
4169 .. naclcode::
4170
4171 AA == AbbrevIndex(A)
4172 VV1 == RelativeIndex(V1)
4173 VV2 == RelativeIndex(V2)
4174 T == TypeOf(V1) == TypeOf(V2)
4175 IsFloat(UnderlyingType(T))
4176 N == NumValuedInsts
4177 NumBasicBlocks < ExpectedBasicBlocks
4178
4179 **Updates**
4180
4181 .. naclcode::
4182
4183 ++NumValuedInsts;
4184 TypeOf(%vN) = T
4185
4186 **Examples**
4187
4188 .. naclcode::
4189
4190 92:0| 1: <65535, 12, 2> | function
4191 | | float @f0(float %p0, float %p1) {
4192 | | // BlockID = 12
4193 100:0| 3: <1, 1> | blocks 1;
4194 | | %b0:
4195 102:4| 3: <2, 2, 1, 0> | %v0 = fadd float %p0, %p1;
4196 106:4| 3: <2, 3, 1, 0> | %v1 = fadd float %p0, %v0;
4197 110:4| 3: <10, 1> | ret float %v1;
4198 113:0| 0: <65534> | }
4199
4200 Floating Point Subtract
4201 ^^^^^^^^^^^^^^^^^^^^^^^
4202
4203 The floating point subtract instruction returns the difference of its two
4204 arguments. Both arguments and the result must be of the same type. That type
4205 must be a floating point type, or a vector of a floating point type.
4206
4207 **Syntax**
4208
4209 .. naclcode::
4210
4211 %vN = fsub T V1, V2; <a>
4212
4213 **Record**
4214
4215 .. naclcode::
4216
4217 AA: <2, VV1, VV2, 1>
4218
4219 **Semantics**
4220
4221 The floating point subtract instruction returns the difference of its two
4222 arguments. Arguments *V1* and *V2*, and the result *%vN* must be of type
4223 *T*. *T* must be a floating point type, or a vector of a floating point
4224 type. *N* is defined by the record position, defining the corresponding value
4225 generated by the instruction.
4226
4227 **Constraints**
4228
4229 .. naclcode::
4230
4231 AA == AbbrevIndex(A)
4232 VV1 == RelativeIndex(V1)
4233 VV2 == RelativeIndex(V2)
4234 T == TypeOf(V1) == TypeOf(V2)
4235 IsFloat(UnderlyingType(T))
4236 N == NumValuedInsts
4237 NumBasicBlocks < ExpectedBasicBlocks
4238
4239 **Updates**
4240
4241 .. naclcode::
4242
4243 ++NumValuedInsts;
4244 TypeOf(%vN) = T
4245
4246 **Examples**
4247
4248 .. naclcode::
4249
4250 92:0| 1: <65535, 12, 2> | function
4251 | | float @f0(float %p0, float %p1) {
4252 | | // BlockID = 12
4253 100:0| 3: <1, 1> | blocks 1;
4254 | | %b0:
4255 102:4| 3: <2, 2, 1, 1> | %v0 = fsub float %p0, %p1;
4256 106:4| 3: <2, 3, 1, 1> | %v1 = fsub float %p0, %v0;
4257 110:4| 3: <10, 1> | ret float %v1;
4258 113:0| 0: <65534> | }
4259
4260 Floating Point Multiply
4261 ^^^^^^^^^^^^^^^^^^^^^^^
4262
4263 The floating point multiply instruction returns the product of its two
4264 arguments. Both arguments and the result must be of the same type. That type
4265 must be a floating point type, or a vector of a floating point type.
4266
4267 **Syntax**
4268
4269 .. naclcode::
4270
4271 &vN = fmul T V1, V2; <A>
4272
4273 **Record**
4274
4275 .. naclcode::
4276
4277 AA: <2, VV1, VV2, 2>
4278
4279 **Semantics**
4280
4281 The floating point multiply instruction returns the product of its two
4282 arguments. Arguments *V1* and *V2*, and the result *%vN* must be of type *T*.
4283 *T* must be a floating point type, or a vector of a floating point type. *N* is
4284 defined by the record position, defining the corresponding value generated by
4285 the instruction.
4286
4287 **Constraints**
4288
4289 .. naclcode::
4290
4291 AA == AbbrevIndex(A)
4292 VV1 == RelativeIndex(V1)
4293 VV2 == RelativeIndex(V2)
4294 T == TypeOf(V1) == TypeOf(V2)
4295 IsFloat(UnderlyingType(T))
4296 N == NumValuedInsts
4297 NumBasicBlocks < ExpectedBasicBlocks
4298
4299 **Updates**
4300
4301 .. naclcode::
4302
4303 ++NumValuedInsts;
4304 TypeOf(%vN) = T
4305
4306 **Examples**
4307
4308 .. naclcode::
4309
4310 92:0| 1: <65535, 12, 2> | function
4311 | | float @f0(float %p0, float %p1) {
4312 | | // BlockID = 12
4313 100:0| 3: <1, 1> | blocks 1;
4314 | | %b0:
4315 102:4| 3: <2, 2, 1, 2> | %v0 = fmul float %p0, %p1;
4316 106:4| 3: <2, 3, 1, 2> | %v1 = fmul float %p0, %v0;
4317 110:4| 3: <10, 1> | ret float %v1;
4318 113:0| 0: <65534> | }
4319
4320 Floating Point Divide
4321 ^^^^^^^^^^^^^^^^^^^^^
4322
4323 The floating point divide instruction returns the quotient of its two
4324 arguments. Both arguments and the result must be of the same type. That type
4325 must be a floating point type, or a vector of a floating point type.
4326
4327 **Syntax**
4328
4329 .. naclcode::
4330
4331 %vN = fdiv T V1, V2; <A>
4332
4333 **Record**
4334
4335 .. naclcode::
4336
4337 AA: <2, V1, V2, 4>
4338
4339 **Semantics**
4340
4341 The float divide instruction returns the quotient of its two
Jim Stichnoth 2014/07/28 22:52:06 floating point divide instruction
Karl 2014/11/14 22:35:35 Done.
4342 arguments. Arguments *V1* and *V2*, and the result *%vN* must be of type
4343 *T*. *T* must be a floating type, or a vector of a floating point type. *N* is
Jim Stichnoth 2014/07/28 22:52:06 floating type --> floating point type
Karl 2014/11/14 22:35:27 Done.
4344 defined by the record position, defining the corresponding value generated by
4345 the instruction.
4346
4347 **Constraints**
4348
4349 .. naclcode::
4350
4351 AA == AbbrevIndex(A)
4352 VV1 == RelativeIndex(V1)
4353 VV22 == RelativeIndex(V2)
4354 T == TypeOf(V1) == TypeOf(V2)
4355 IsFloat(UnderlyingType(T))
4356 N == NumValuedInsts
4357 NumBasicBlocks < ExpectedBasicBlocks
4358
4359 **Updates**
4360
4361 .. naclcode::
4362
4363 ++NumValuedInsts;
4364 TypeOf(%vN) = T
4365
4366 **Examples**
4367
4368 .. naclcode::
4369
4370 92:0| 1: <65535, 12, 2> | function
4371 | | double
4372 | | @f0(double %p0, double %p1) {
4373 | | // BlockID = 12
4374 100:0| 3: <1, 1> | blocks 1;
4375 | | %b0:
4376 102:4| 3: <2, 2, 1, 4> | %v0 = fdiv double %p0, %p1;
4377 106:4| 3: <2, 3, 1, 4> | %v1 = fdiv double %p0, %v0;
4378 110:4| 3: <10, 1> | ret double %v1;
4379 113:0| 0: <65534> | }
4380
4381 Floating Point Remainder
4382 ^^^^^^^^^^^^^^^^^^^^^^^^
4383
4384 The floatint point remainder instruction returns the remainder of the quotient
Jim Stichnoth 2014/07/28 18:21:07 floating
Karl 2014/11/14 22:35:31 Done.
4385 of its two arguments. Both arguments and the result must be of the same
4386 type. That type must be a floating point type, or a vector of a floating point
4387 type.
4388
4389 **Syntax**
4390
4391 .. naclcode::
4392
4393 %vN = frem T V1, V2; <A>
4394
4395 **Record**
4396
4397 .. naclcode::
4398
4399 AA: <2, VV1, VV2, 6>
4400
4401 **Semantics**
4402
4403 The floating point remainder instruction returns the remainder of the quotient
4404 of its two arguments. Arguments *V1* and *V2*, and the result *%vN* must be of
4405 type *T*. *T* must be a floating point type, or a vector of a floating point
4406 type. *N* is defined by the record position, defining the corresponding value
4407 generated by the instruction.
4408
4409 **Constraints**
4410
4411 .. naclcode::
4412
4413 AA == AbbrevIndex(A)
4414 VV1 == RelativeIndex(V1)
4415 VV2 == RelativeIndex(V2)
4416 T == TypeOf(V1) == TypeOf(V2)
4417 IsFloat(UnderlyingType(T))
4418 N == NumValuedInsts
4419 NumBasicBlocks < ExpectedBasicBlocks
4420
4421 **Updates**
4422
4423 .. naclcode::
4424
4425 ++NumValuedInsts;
4426 TypeOf(%vN) = T
4427
4428 **Examples**
4429
4430 .. naclcode::
4431
4432 92:0| 1: <65535, 12, 2> | function
4433 | | double
4434 | | @f0(double %p0, double %p1) {
4435 | | // BlockID = 12
4436 100:0| 3: <1, 1> | blocks 1;
4437 | | %b0:
4438 102:4| 3: <2, 2, 1, 6> | %v0 = frem double %p0, %p1;
4439 106:4| 3: <2, 3, 1, 6> | %v1 = frem double %p0, %v0;
4440 110:4| 3: <10, 1> | ret double %v1;
4441 113:0| 0: <65534> | }
4442
4443 Memory Creation And Access Instructions
Jim Stichnoth 2014/07/28 22:52:09 don't capitalize "and"
Karl 2014/11/14 22:35:31 Done.
4444 ---------------------------------------
4445
4446 A key design point of SSA-based representation is how it represents
4447 memory. In PNaCl bitcode files, no memory locations are in SSA
4448 form. This makes things very simple.
4449
4450 Alloca Instruction
4451 ^^^^^^^^^^^^^^^^^^
4452
4453 The *alloca* instruction allocates memory on the stack frame of the
4454 currently executing function. This memory is automatically released
4455 when the function returns to its caller.
4456
4457 **Syntax**
4458
4459 .. naclcode::
4460
4461 %vN = alloca i8, i32 S, align V; <A>
4462
4463 **Record**
4464
4465 .. naclcode::
4466
4467 AA: <19, SS, VV>
4468
4469 **Semantics**
4470
4471 The *alloca* instruction allocates memory on the stack frame of the currently
4472 executing function. The resulting value is a pointer to the allocated memory
4473 (i.e. of type i32). *S* is the number of bytes that are allocated on the
4474 stack. *S* must be of integral type i32. *V* is the alignment of the generated
4475 stack address.
4476
4477 Alignment must be a power of 2. See :ref:`memory blocks and
4478 alignment<link_for_memory_blocks_and_alignment_section>` for a more detailed
4479 discussion on how to define alignment.
4480
4481 **Constraints**
4482
4483 .. naclcode::
4484
4485 AA == AbbrevIndex(A)
4486 VV == Log2(V+1)
4487 SS == RelativeIndex(S)
4488 i32 == TypeOf(S)
4489 N == NumValuedInsts
4490 NumBasicBlocks < ExpectedBasicBlocks
4491
4492 **Updates**
4493
4494 .. naclcode::
4495
4496 ++NumValuedInsts;
4497 TypeOf(%vN) = i32;
4498
4499 **Examples**
4500
4501 .. naclcode::
4502
4503 112:0| 1: <65535, 12, 2> | function void @f1() {
4504 | | // BlockID = 12
4505 120:0| 3: <1, 1> | blocks 1;
4506 122:4| 1: <65535, 11, 2> | constants { // BlockID = 11
4507 132:0| 3: <1, 0> | i32:
4508 134:4| 3: <4, 4> | %c0 = i32 2;
4509 137:0| 3: <4, 8> | %c1 = i32 4;
4510 139:4| 3: <4, 16> | %c2 = i32 8;
4511 142:0| 0: <65534> | }
4512 | | %b0:
4513 144:0| 3: <19, 3, 1> | %v0 = alloca i8, i32 %c0, align 1;
4514 147:2| 3: <19, 3, 3> | %v1 = alloca i8, i32 %c1, align 4;
4515 150:4| 3: <19, 3, 4> | %v2 = alloca i8, i32 %c2, align 8;
4516 153:6| 3: <10> | ret void;
4517 155:4| 0: <65534> | }
4518
4519 Load Instruction
4520 ^^^^^^^^^^^^^^^^
4521
4522 The *load* instruction is used to read from memory.
4523
4524 **Syntax**
4525
4526 .. naclcode::
4527
4528 %vN = load T* P, align V; <A>
4529
4530 **Record**
4531
4532 .. naclcode::
4533
4534 AA: <20, PP, VV, TT>
4535
4536 **Semantics**
4537
4538 The load instruction is used to read from memory. *P* is the identifier of the
4539 memory address to read. The type of *P* must be an i32 integer. *T* is the type
4540 of value to read. *V* is the alignment of the memory address. *A* is the
4541 (optional) abbreviation associated with the record.
4542
4543 Type *T* must be a vector, integral, or floating point type. Both float and
4544 double types are allowed for floating point types. All integral types except i1
4545 are allowed.
4546
4547 Alignment must be a power of 2. See :ref:`memory blocks and
4548 alignment<link_for_memory_blocks_and_alignment_section>` for a more detailed
4549 discussion on how to define alignment.
4550
4551 **Constraints**
4552
4553 AA == AbbrevIndex(A)
4554 i32 == TypeOf(P)
4555 PP == RelativeIndex(P)
4556 VV == Log2(V+1)
4557 %tTT == TypeID(T)
4558 N == NumValuedInsts
4559 NumBasicBlocks < ExpectedBasicBlocks
4560
4561 **Updates**
4562
4563 .. naclcode::
4564
4565 ++NumValuedInsts;
4566 TypeOf(%vN) = T;
4567
4568 **Examples**
4569
4570 .. naclcode::
4571
4572 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
4573 48:0| 3: <1, 4> | count 4;
4574 50:4| 3: <7, 32> | @t0 = i32;
4575 53:6| 3: <2> | @t1 = void;
4576 55:4| 3: <4> | @t2 = double;
4577 57:2| 3: <21, 0, 1, 0> | @t3 = void (i32);
4578 61:2| 0: <65534> | }
4579 ...
4580 96:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
4581 | | // BlockID = 12
4582 104:0| 3: <1, 1> | blocks 1;
4583 | | %b0:
4584 106:4| 3: <20, 1, 1, 0> | %v0 = load i32* %p0, align 1;
4585 110:4| 3: <20, 1, 4, 2> | %v1 = load double* %v0, align 8;
4586 114:4| 3: <10> | ret void;
4587 116:2| 0: <65534> | }
4588
4589 Store Instruction
4590 ^^^^^^^^^^^^^^^^^
4591
4592 The *store* instruction is used to write to memory.
4593
4594 **Syntax**
4595
4596 .. naclcode::
4597
4598 store T S, T* P, align V; <A>
4599
4600 **Record**
4601
4602 .. naclcode::
4603
4604 AA: <24, PP, SS, VV>
4605
4606 **Semantics**
4607
4608 The store instruction is used to write to memory. *P* is the identifier of the
4609 memory address to write to. The type of *P* must be an i32 integer. *T* is the
4610 type of value to store. *S* is the value to store, and must be of type *T*. *V*
4611 is the alignment of the memory address. *A* is the (optional) abbreviation
4612 index associated with the record.
4613
4614 Type *T* must be an integral or floating point type. Both float and double types
4615 are allowed for floating point types. All integral types except i1 are allowed.
4616
4617 Alignment must be a power of 2. See :ref:`memory blocks and
4618 alignment<link_for_memory_Blocks_and_alignment_section>` for a more detailed
4619 discussion on how to define alignment.
4620
4621 **Constraints**
4622
4623 .. naclcode::
4624
4625 AA == AbbrevIndex(A)
4626 i32 == TypeOf(P)
4627 PP == RelativeIndex(P)
4628 VV == Log2(V+1)
4629 NumBasicBlocks < ExpectedBasicBlocks
4630
4631 **Examples**
4632
4633 The following instructions store an i32 integer and a 32-bit floating
4634 value.
4635
4636 .. naclcode::
4637
4638 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
4639 48:0| 3: <1, 4> | count 4;
4640 50:4| 3: <7, 32> | @t0 = i32;
4641 53:6| 3: <2> | @t1 = void;
4642 55:4| 3: <4> | @t2 = double;
4643 57:2| 3: <21, 0, 1, 0, 0, 0, 2>| @t3 = void (i32, i32, i32, double);
4644 63:4| 0: <65534> | }
4645 ...
4646 96:0| 1: <65535, 12, 2> | function
4647 | | void
4648 | | @f0(i32 %p0, i32 %p1, i32 %p2,
4649 | | double %p3) {
4650 | | // BlockID = 12
4651 104:0| 3: <1, 1> | blocks 1;
4652 | | %b0:
4653 106:4| 3: <24, 4, 3, 1> | store i32 %p1, i32* %p0, align 1;
4654 110:4| 3: <24, 2, 1, 4> | store double %p3, double* %p2,
4655 | | align 8;
4656 114:4| 3: <10> | ret void;
4657 116:2| 0: <65534> | }
4658
4659 Conversion Instructions
4660 -----------------------
4661
4662 Conversion instructions all take a single operand and a type. The value is
4663 converted to the corresponding type.
4664
4665 Integer Truncating Instruction
4666 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4667
4668 The integer truncating instruction takes a value to truncate, and a type
4669 defining the truncated type. Both types must be integer types, or integral
4670 vectors with the same number of elements. The bit size of the value must be
4671 larger than the bit size of the destination type. Equal sized types are not
4672 allowed.
4673
4674 **Syntax**
4675
4676 .. naclcode::
4677
4678 %vN = trunc T1 V to T2; <A>
4679
4680 **Record**
4681
4682 .. naclcode::
4683
4684 AA: <3, VV, TT2, 0>
4685
4686 **Semantics**
4687
4688 The integer truncating instruction takes a value *V*, and truncates to type
4689 *T2*. Both *T1* and *T2* must be integer types, or integral vectors with the
4690 same number of elements. *T1* has to be wider than *T2*. If the value doesn't
4691 fit in in *T2*, then the higer order bits are dropped.
Jim Stichnoth 2014/07/28 18:21:06 higher
Karl 2014/11/14 22:35:28 Done.
4692
4693 **Constraints**
4694
4695 .. naclcode::
4696
4697 AA == AbbrevIndex(A)
4698 TypeOf(V) == T1
4699 *VV* == RelativeIndex(*V*)
4700 %tTT2 == TypeID(T2)
4701 BitSizeOf(UnderlyingType(T1)) > BitSizeOf(UnderlyingType(T2))
4702 UnderlyingCount(T1) == UnderlyingCount(T2)
4703 IsInteger(UnderlyingType(T1))
4704 IsInteger(UnderlyingType(T2))
4705 N == NumValuedInsts
4706 NumBasicBlocks < ExpectedBasicBlocks
4707
4708 **Updates**
4709
4710 .. naclcode::
4711
4712 ++NumValuedInsts;
4713 TypeOf(%vN) = T2;
4714
4715 **Examples**
4716
4717 .. naclcode::
4718
4719 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
4720 48:0| 3: <1, 5> | count 5;
4721 50:4| 3: <7, 32> | @t0 = i32;
4722 53:6| 3: <2> | @t1 = void;
4723 55:4| 3: <7, 16> | @t2 = i16;
4724 58:0| 3: <21, 0, 1, 0> | @t3 = void (i32);
4725 62:0| 3: <7, 8> | @t4 = i8;
4726 64:4| 0: <65534> | }
4727 ...
4728 100:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
4729 | | // BlockID = 12
4730 108:0| 3: <1, 1> | blocks 1;
4731 | | %b0:
4732 110:4| 3: <3, 1, 2, 0> | %v0 = trunc i32 %p0 to i16;
4733 114:4| 3: <3, 1, 4, 0> | %v1 = trunc i16 %v0 to i8;
4734 118:4| 3: <10> | ret void;
4735 120:2| 0: <65534> | }
4736
4737 Floating Point Truncating Instruction
4738 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4739
4740 The floating point truncating instruction takes a value to truncate, and a type
4741 defining the truncated type. Both types must be floating point types, or
Jim Stichnoth 2014/07/28 22:52:06 Can we just say T1 must be double and T2 must be f
Karl 2014/11/14 22:35:34 Done.
4742 floating point vectors with the same number of elements. The bit size of the
4743 source type must be larger than the bit size of the destination type. Equal
4744 sized types are not allowed.
4745
4746 **Syntax**
4747
4748 .. naclcode::
4749
4750 %vN = fptrunc T1 V to T2; <A>
4751
4752 **Record**
4753
4754 .. naclcode::
4755
4756 AA: <3, VV, TT2, 7>
4757
4758 **Semantics**
4759
4760 The floating truncating instruction takes a value *V*, and truncates to type
4761 *T2*. Both *T1* and *T2* must be floating point types, or floating point vectors
4762 with the same number of elements. *T1* has to be wider than *T2*. If the value
4763 can't fit within the destination type *T2*, the results are undefined.
4764
4765 **Constraints**
4766
4767 .. naclcode::
4768
4769 TypeOf(V) == T1
4770 double == UnderlyingType(T1)
4771 float == UnderlyingType(T2)
4772 *VV* == RelativeIndex(*V*)
4773 %tTT2 == TypeID(T2)
4774 BitSizeOf(UnderlyingType(T1)) > BitSizeOf(UnderlyingType(T2))
4775 UnderlyingCount(T1) == UnderlyingCount(T2)
4776 IsFloat(UnderlyingType(T1))
4777 IsFloat(UnderlyingType(T2))
4778 N == NumValuedInsts
4779 NumBasicBlocks < ExpectedBasicBlocks
4780
4781 **Updates**
4782
4783 .. naclcode::
4784
4785 ++NumValuedInsts;
4786 TypeOf(%vN) = T2;
4787
4788 **Examples**
4789
4790 .. naclcode::
4791
4792 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
4793 48:0| 3: <1, 4> | count 4;
4794 50:4| 3: <3> | @t0 = float;
4795 52:2| 3: <4> | @t1 = double;
4796 54:0| 3: <21, 0, 0, 1> | @t2 = float (double);
4797 58:0| 3: <2> | @t3 = void;
4798 59:6| 0: <65534> | }
4799 ...
4800 92:0| 1: <65535, 12, 2> | function float @f0(double %p0) {
4801 | | // BlockID = 12
4802 100:0| 3: <1, 1> | blocks 1;
4803 | | %b0:
4804 102:4| 3: <3, 1, 0, 7> | %v0 = fptrunc double %p0 to float;
4805 106:4| 3: <10, 1> | ret float %v0;
4806 109:0| 0: <65534> | }
4807
4808
4809 Zero Extending Instruction
4810 ^^^^^^^^^^^^^^^^^^^^^^^^^^
4811
4812 The zero extending instruction takes a value to extend, and a type to extend it
4813 to. Both types must be integer types, or integral vectors with the same number
4814 of elements. The bit size of the source type must be smaller than the bit size
4815 of the destination type. Equal sized types are not allowed.
4816
4817 **Syntax**
4818
4819 .. naclcode::
4820
4821 %vN = zext T1 V to T2; <A>
4822
4823 **Record**
4824
4825 .. naclcode::
4826
4827 AA: <3, VV, TT2, 1>
4828
4829
4830 **Semantics**
4831
4832 The zero extending instruction takes a value *V*, and expands it to type
4833 *T2*. Both *T1* and *T2* must be integral types, or integral vectors with the
4834 same number of elements. *T2* must be wider than *T1*.
4835
4836 The instruction fills the high order bits of the value with zero bits until it
4837 reaches the size of the destination type. When zero extending from i1, the
4838 result will always be either 0 or 1.
4839
4840 **Constraints**
4841
4842 .. naclcode::
4843
4844 AA == AbbrevIndex(A)
4845 TypeOf(V) == T1
4846 *VV* == RelativeIndex(*V*)
4847 %tTT2 == TypeID(T2)
4848 BitSizeOf(UnderlyingType(T1)) < BitSizeOf(UnderlyingType(T2))
4849 UnderlyingCount(T1) == UnderlyingCount(T2)
4850 IsInteger(UnderlyingType(T1))
4851 IsInteger(UnderlyingType(T2))
4852 N == NumValuedInsts
4853 NumBasicBlocks < ExpectedBasicBlocks
4854
4855 **Updates**
4856
4857 .. naclcode::
4858
4859 ++NumValuedInsts;
4860 TypeOf(%vN) = T2;
4861
4862 **Examples**
4863
4864 .. naclcode::
4865
4866 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
4867 48:0| 3: <1, 5> | count 5;
4868 50:4| 3: <7, 64> | @t0 = i64;
4869 53:6| 3: <7, 32> | @t1 = i32;
4870 57:0| 3: <21, 0, 0> | @t2 = i64 ();
4871 60:2| 3: <7, 8> | @t3 = i8;
4872 62:6| 3: <2> | @t4 = void;
4873 64:4| 0: <65534> | }
4874 ...
4875 100:0| 1: <65535, 12, 2> | function i64 @f0() { // BlockID = 12
4876 108:0| 3: <1, 1> | blocks 1;
4877 110:4| 1: <65535, 11, 2> | constants { // BlockID = 11
4878 120:0| 3: <1, 3> | i8:
4879 122:4| 3: <4, 2> | %c0 = i8 1;
4880 125:0| 0: <65534> | }
4881 | | %b0:
4882 128:0| 3: <3, 1, 1, 1> | %v0 = zext i8 %c0 to i32;
4883 132:0| 3: <3, 1, 0, 1> | %v1 = zext i32 %v0 to i64;
4884 136:0| 3: <10, 1> | ret i64 %v1;
4885 138:4| 0: <65534> | }
4886
4887 Sign Extending Instruction
4888 ^^^^^^^^^^^^^^^^^^^^^^^^^^
4889
4890 The sign extending instruction takes a value to cast, and a type to extend it
4891 to. Both types must be integral types, or integarl vectors with the same number
Jim Stichnoth 2014/07/28 18:21:09 integral
Karl 2014/11/14 22:35:33 Done.
4892 of Elements. The bit size of the source type must be smaller than the bit size
Jim Stichnoth 2014/07/28 22:52:03 Elements --> elements
Karl 2014/11/14 22:35:34 Done.
4893 of the destination type. Equal sized types are not allowed.
4894
4895 **Syntax**
4896
4897 .. naclcode::
4898
4899 %vN = sext T1 V to T2; <A>
4900
4901 **Record**
4902
4903 .. naclcode::
4904
4905 AA: <3, VV, TT2, 2>
4906
4907 **Semantics**
4908
4909 The sign extending instruction takes a value *V*, and expands it to type
4910 *T2*. Both *T1* and *T2* must be integral types, or integral vectors with the
4911 same number of integers. *T2* has to be wider than *T1*.
4912
4913 When sign extending, the instruction fills the high order bits of the value with
4914 the (current) high order bit of the value. When sign extending from i1, the
4915 extension always results in -1 or 0.
4916
4917 **Constraints**
4918
4919 .. naclcode::
4920
4921 AA == AbbrevIndex(A)
4922 TypeOf(V) == T1
4923 *VV* == RelativeIndex(*V*)
4924 %tTT2 == TypeID(T2)
4925 BitSizeOf(UnderlyingType(T1)) < BitSizeOf(UnderlyingType(T2))
4926 UnderlyingCount(T1) == UnderlyingCount(T2)
4927 IsInteger(UnderlyingType(T1))
4928 IsInteger(UnderlyingType(T2))
4929 N == NumValuedInsts
4930 NumBasicBlocks < ExpectedBasicBlocks
4931
4932 **Updates**
4933
4934 .. naclcode::
4935
4936 ++NumValuedInsts;
4937 TypeOf(%vN) = T2;
4938
4939 **Examples**
4940
4941 .. naclcode::
4942
4943 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
4944 48:0| 3: <1, 5> | count 5;
4945 50:4| 3: <7, 64> | @t0 = i64;
4946 53:6| 3: <7, 32> | @t1 = i32;
4947 57:0| 3: <21, 0, 0> | @t2 = i64 ();
4948 60:2| 3: <7, 8> | @t3 = i8;
4949 62:6| 3: <2> | @t4 = void;
4950 64:4| 0: <65534> | }
4951 ...
4952 100:0| 1: <65535, 12, 2> | function i64 @f0() { // BlockID = 12
4953 108:0| 3: <1, 1> | blocks 1;
4954 110:4| 1: <65535, 11, 2> | constants { // BlockID = 11
4955 120:0| 3: <1, 3> | i8:
4956 122:4| 3: <4, 3> | %c0 = i8 -1;
4957 125:0| 0: <65534> | }
4958 | | %b0:
4959 128:0| 3: <3, 1, 1, 2> | %v0 = sext i8 %c0 to i32;
4960 132:0| 3: <3, 1, 0, 2> | %v1 = sext i32 %v0 to i64;
4961 136:0| 3: <10, 1> | ret i64 %v1;
4962 138:4| 0: <65534> | }
4963
4964 Floating point Extending Instruction
Jim Stichnoth 2014/07/28 22:52:06 point --> Point
Karl 2014/11/14 22:35:33 Done.
4965 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4966
4967 The floating point extending instruction takes a value to extend, and a type to
4968 extend it to. Both types must be floating types, or vectors of floating a
Jim Stichnoth 2014/07/28 22:52:04 Like above, can we just say T1 must be float and T
Karl 2014/11/14 22:35:30 Done.
4969 floating type with the same number of elements. The source value must be of
4970 float type, or a vector of float type. The extended value must be a double type,
4971 or a vector of double type. If the source is a vector, the destination must
4972 also be vector with the same size as the source.
4973
4974 **Syntax**
4975
4976 .. naclcode::
4977
4978 %vN = fpext T1 V to T2; <A>
4979
4980 **Record**
4981
4982 .. naclcode::
4983
4984 AA: <3, VV, TT2, 8>
4985
4986 **Semantics**
4987
4988 The floating point extending instruction converts float values to double. *V*
4989 is the value to extend, and *T2* is the type to extend it to. Both *T1* and *T2*
4990 must be floating point types, or floating point vector types with the same
4991 number of floating values. *T2* has to be wider than *T1*.
4992
4993 **Constraints**
4994
4995 .. naclcode::
4996
4997 AA == AbbrevIndex(A)
4998 TypeOf(V) == T1
4999 VV == RelativeIndex(V)
5000 %tTT2 == TypeID(T2)
5001 BitSizeOf(UnderlyingType(T1)) < BitSizeOf(UnderlyingType(T2))
5002 UnderlyingCount(T1) == UnderlyingCount(T2)
5003 IsFloat(UnderlyingType(T1))
5004 IsFloat(UnderlyingType(T2))
5005 N == NumValuedInsts
5006 NumBasicBlocks < ExpectedBasicBlocks
5007
5008 **Updates**
5009
5010 .. naclcode::
5011
5012 ++NumValuedInsts;
5013 TypeOf(%vN) = T2;
5014
5015 **Examples**
5016
5017 .. naclcode::
5018
5019 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
5020 48:0| 3: <1, 4> | count 4;
5021 50:4| 3: <4> | @t0 = double;
5022 52:2| 3: <3> | @t1 = float;
5023 54:0| 3: <21, 0, 0, 1> | @t2 = double (float);
5024 58:0| 3: <2> | @t3 = void;
5025 59:6| 0: <65534> | }
5026 ...
5027 92:0| 1: <65535, 12, 2> | function double @f0(float %p0) {
5028 | | // BlockID = 12
5029 100:0| 3: <1, 1> | blocks 1;
5030 | | %b0:
5031 102:4| 3: <3, 1, 0, 8> | %v0 = fpext float %p0 to double;
5032 106:4| 3: <10, 1> | ret double %v0;
5033 109:0| 0: <65534> | }
5034
5035 Floating Point To Unsigned Integer Instruction
Jim Stichnoth 2014/07/28 22:52:05 To --> to ?
Karl 2014/11/14 22:35:28 Done.
5036 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5037
5038 The floating point to unsigned integer instruction converts floating point
5039 values to an unsigned integers.
Jim Stichnoth 2014/07/28 22:52:05 remobe "an"
Karl 2014/11/14 22:35:29 Done.
5040
5041 **Syntax**
5042
5043 .. naclcode::
5044
5045 %vN = fptoui T1 V to T2; <A>
5046
5047 **Record**
5048
5049 .. naclcode::
5050
5051 AA: <3, VV, TT2, 3>
5052
5053 **Semantics**
5054
5055 The floating point to unsigned integer instruction coverts floating point values
Jim Stichnoth 2014/07/28 18:21:06 converts
Jim Stichnoth 2014/07/28 22:52:05 converts a floating point value
Karl 2014/11/14 22:35:34 Done.
5056 in *V* to its unsigned integer equivalent of type *T2*. *T1* must be a floating
5057 point type, or a floating point vector type. *T2* must be an integral type, or a
5058 integral vector type. If either type is a vector type, they both must be and
Jim Stichnoth 2014/07/28 22:52:06 remove "be and"
Karl 2014/11/14 22:35:35 Done.
5059 have the same number of elements.
5060
5061 **Constraints**
5062
5063 .. naclcode::
5064
5065 AA == AbbrevIndex(A)
5066 TypeOf(V) == T1
5067 VV == RelativeIndex(V)
5068 %tTT2 == TypeID(T2)
5069 UnderlyingCount(T1) == UnderlyingCount(T2)
5070 IsFloat(UnderlyingType(T1))
5071 IsInteger(UnderlyingType(T2))
5072 N == NumValuedInsts
5073 NumBasicBlocks < ExpectedBasicBlocks
5074
5075 **Updates**
5076
5077 .. naclcode::
5078
5079 ++NumValuedInsts;
5080 TypeOf(%vN) = T2;
5081
5082 **Examples**
5083
5084 .. naclcode::
5085
5086 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
5087 48:0| 3: <1, 6> | count 6;
5088 50:4| 3: <3> | @t0 = float;
5089 52:2| 3: <4> | @t1 = double;
5090 54:0| 3: <2> | @t2 = void;
5091 55:6| 3: <21, 0, 2, 0, 1> | @t3 = void (float, double);
5092 60:4| 3: <7, 32> | @t4 = i32;
5093 63:6| 3: <7, 16> | @t5 = i16;
5094 66:2| 0: <65534> | }
5095 ...
5096 100:0| 1: <65535, 12, 2> | function
5097 | | void @f0(float %p0, double %p1) {
5098 | | // BlockID = 12
5099 108:0| 3: <1, 1> | blocks 1;
5100 | | %b0:
5101 110:4| 3: <3, 2, 4, 3> | %v0 = fptoui float %p0 to i32;
5102 114:4| 3: <3, 2, 5, 3> | %v1 = fptoui double %p1 to i16;
5103 118:4| 3: <10> | ret void;
5104 120:2| 0: <65534> | }
5105
5106 Floating Point To Signed Integer Instruction
Jim Stichnoth 2014/07/28 22:52:05 To --> to ?
Karl 2014/11/14 22:35:34 Done.
5107 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5108
5109 The floating point to signed integer instruction converts floating point
5110 values to signed integers.
5111
5112 **Syntax**
5113
5114 .. naclcode::
5115
5116 %vN = fptosi T1 V to T2; <A>
5117
5118 **Record**
5119
5120
5121 .. naclcode::
5122
5123 AA: <3, VV, TT2, 4>
5124
5125 **Semantics**
5126
5127 The floating point to signed integer instruction coverts floating point values
Jim Stichnoth 2014/07/28 18:21:05 converts
Jim Stichnoth 2014/07/28 22:52:08 converts a floating point value
5128 in *V* to its signed integer equivalent of type *T2*. *T1* must be a floating
5129 point type, or a floating point vector type. *T2* must be an integral type, or a
5130 integral vector type. If either type is a vector type, they both must be and
Jim Stichnoth 2014/07/28 22:52:03 Remove "be and"
Karl 2014/11/14 22:35:28 Done.
5131 have the same number of elements.
5132
5133 **Constraints**
5134
5135 .. naclcode::
5136
5137 AA == AbbrevIndex(A)
5138 TypeOf(V) == T1
5139 VV == RelativeIndex(V)
5140 %tTT2 = TypeID(T2)
5141 UnderlyingCount(T1) = UnderlyingCount(T2)
5142 IsFloat(UnderlyingType(T1))
5143 IsInteger(UnderlyingType(T2))
5144 N = NumValuedInsts
5145 NumBasicBlocks < ExpectedBasicBlocks
5146
5147 **Updates**
5148
jvoung (off chromium) 2014/07/28 19:20:36 naclcode ?
Karl 2014/11/14 22:35:31 Done.
5149 ++NumValuedInsts;
5150 TypeOf(%vN) = T2;
5151
5152 **Examples**
5153
5154 .. naclcode::
5155
5156 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
5157 48:0| 3: <1, 6> | count 6;
5158 50:4| 3: <3> | @t0 = float;
5159 52:2| 3: <4> | @t1 = double;
5160 54:0| 3: <2> | @t2 = void;
5161 55:6| 3: <21, 0, 2, 0, 1> | @t3 = void (float, double);
5162 60:4| 3: <7, 8> | @t4 = i8;
5163 63:0| 3: <7, 16> | @t5 = i16;
5164 65:4| 0: <65534> | }
5165 ...
5166 100:0| 1: <65535, 12, 2> | function
5167 | | void @f0(float %p0, double %p1) {
5168 | | // BlockID = 12
5169 108:0| 3: <1, 1> | blocks 1;
5170 | | %b0:
5171 110:4| 3: <3, 2, 4, 4> | %v0 = fptosi float %p0 to i8;
5172 114:4| 3: <3, 2, 5, 4> | %v1 = fptosi double %p1 to i16;
5173 118:4| 3: <10> | ret void;
5174 120:2| 0: <65534> | }
5175
5176
5177 Unsigned Integer To Floating Point Instruction
Jim Stichnoth 2014/07/28 22:52:08 To --> to ?
Karl 2014/11/14 22:35:30 Done.
5178 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5179
5180 The unsigned integer to floating point instruction converts unsigned integers to
5181 floating point values.
5182
5183 **Syntax**
5184
5185 .. naclcode::
5186
5187 %vN = uitofp T1 V to T2; <A>
5188
5189 **Record**
5190
5191 .. naclcode::
5192
5193 AA: <3, VV, TT2, 5>
5194
5195 **Semantics**
5196
5197 The unsigned integer to floating point instruction converts unsigned integers to
Jim Stichnoth 2014/07/28 22:52:03 converts an unsigned integer
Karl 2014/11/14 22:35:33 Done.
5198 its floating point equivalent of type *T2*. *T1* must be an integral type, or a
5199 integral vector type. *T2* must be a floating point type, or a floating point
5200 vector type. If either type is a vector type, they both must be and have the
Jim Stichnoth 2014/07/28 22:52:05 remove "be and"
Karl 2014/11/14 22:35:34 Done.
5201 same number of elements.
5202
5203 **Constraints**
5204
5205 .. naclcode::
5206
5207 AA == AbbrevIndex(A)
5208 TypeOf(V) == T1
5209 VV == RelativeIndex(V)
5210 %tTT2 = TypeID(T2)
5211 UnderlyingCount(T1) == UnderlyingCount(T2)
5212 IsInteger(UnderlyingType(T1))
5213 IsFloat(UnderlyingType(T2))
5214 N == NumValuedInsts
5215 NumBasicBlocks < ExpectedBasicBlocks
5216
5217 **Updates**
5218
5219 .. naclcode::
5220
5221 ++NumValuedInsts;
5222 TypeOf(%vN) == T2;
5223
5224 **Examples**
5225
5226 .. naclcode::
5227
5228 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
5229 48:0| 3: <1, 7> | count 7;
5230 50:4| 3: <7, 32> | @t0 = i32;
5231 53:6| 3: <7, 64> | @t1 = i64;
5232 57:0| 3: <2> | @t2 = void;
5233 58:6| 3: <3> | @t3 = float;
5234 60:4| 3: <21, 0, 2, 0, 1> | @t4 = void (i32, i64);
5235 65:2| 3: <7, 1> | @t5 = i1;
5236 67:6| 3: <4> | @t6 = double;
5237 69:4| 0: <65534> | }
5238 ...
5239 104:0| 1: <65535, 12, 2> | function void @f0(i32 %p0, i64 %p1) {
5240 | | // BlockID = 12
5241 112:0| 3: <1, 1> | blocks 1;
5242 114:4| 1: <65535, 11, 2> | constants { // BlockID = 11
5243 124:0| 3: <1, 5> | i1:
5244 126:4| 3: <4, 3> | %c0 = i1 1;
5245 129:0| 0: <65534> | }
5246 | | %b0:
5247 132:0| 3: <3, 1, 6, 5> | %v0 = uitofp i1 %c0 to double;
5248 136:0| 3: <3, 4, 3, 5> | %v1 = uitofp i32 %p0 to float;
5249 140:0| 3: <3, 4, 3, 5> | %v2 = uitofp i64 %p1 to float;
5250 144:0| 3: <10> | ret void;
5251 145:6| 0: <65534> | }
5252
5253 Signed Integer To Floating Point Instruction
Jim Stichnoth 2014/07/28 22:52:05 To --> to ?
Karl 2014/11/14 22:35:29 Done.
5254 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5255
5256 The signed integer to floating point instruction converts signed integers to
5257 floating point values.
5258
5259 **Syntax**
5260
5261 .. naclcode::
5262
5263 %vN = sitofp T1 V to T2; <A>
5264
5265 **Record**
5266
5267 .. naclcode::
5268
5269 AA: <3, VV, TT2, 6>
5270
5271 **Semantics**
5272
5273 The signed integer to floating point instruction converts signed integers to its
Jim Stichnoth 2014/07/28 22:52:07 converts a signed integer
Karl 2014/11/14 22:35:34 Done.
5274 floating point equivalent of type *T2*. *T1* must be an integral type, or a
5275 integral vector type. *T2* must be a floating point type, or a floating point
5276 vector type. If either type is a vector type, they both must be and have the
Jim Stichnoth 2014/07/28 22:52:07 remove "be and"
Karl 2014/11/14 22:35:28 Done.
5277 same number of elements.
5278
5279 **Constraints**
5280
5281 .. naclcode::
5282
5283 AA == AbbrevIndex(A)
5284 TypeOf(V) == T1
5285 VV == RelativeIndex(V)
5286 %tTT2 = TypeID(T2)
5287 UnderlyingCount(T1) == UnderlyingCount(T2)
5288 IsInteger(UnderlyingType(T1))
5289 IsFloat(UnderlyingType(T2))
5290 N == NumValuedInsts
5291 NumBasicBlocks < ExpectedBasicBlocks
5292
5293 **Updates**
5294
5295 .. naclcode::
5296
5297 ++NumValuedInsts;
5298 TypeOf(%vN) = T2;
5299
5300 **Examples**
5301
5302 .. naclcode::
5303
5304 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
5305 48:0| 3: <1, 7> | count 7;
5306 50:4| 3: <7, 32> | @t0 = i32;
5307 53:6| 3: <7, 64> | @t1 = i64;
5308 57:0| 3: <2> | @t2 = void;
5309 58:6| 3: <3> | @t3 = float;
5310 60:4| 3: <21, 0, 2, 0, 1> | @t4 = void (i32, i64);
5311 65:2| 3: <7, 8> | @t5 = i8;
5312 67:6| 3: <4> | @t6 = double;
5313 69:4| 0: <65534> | }
5314 ...
5315 104:0| 1: <65535, 12, 2> | function void @f0(i32 %p0, i64 %p1) {
5316 | | // BlockID = 12
5317 112:0| 3: <1, 1> | blocks 1;
5318 114:4| 1: <65535, 11, 2> | constants { // BlockID = 11
5319 124:0| 3: <1, 5> | i8:
5320 126:4| 3: <4, 3> | %c0 = i8 -1;
5321 129:0| 0: <65534> | }
5322 | | %b0:
5323 132:0| 3: <3, 1, 6, 6> | %v0 = sitofp i8 %c0 to double;
5324 136:0| 3: <3, 4, 3, 6> | %v1 = sitofp i32 %p0 to float;
5325 140:0| 3: <3, 4, 3, 6> | %v2 = sitofp i64 %p1 to float;
5326 144:0| 3: <10> | ret void;
5327 145:6| 0: <65534> | }
5328
5329 Bitcast Instruction
5330 ^^^^^^^^^^^^^^^^^^^
5331
5332 The bitcast instruction converts the type of the value without changing the bit
5333 contents of the value. The bitsize of the type of the value must be the same as
Jim Stichnoth 2014/07/28 18:21:08 bit size
Karl 2014/11/14 22:35:28 Done.
5334 the bitsize of the type it is casted to.
Jim Stichnoth 2014/07/28 18:21:05 bit size
Jim Stichnoth 2014/07/28 18:21:08 casted or cast?
Karl 2014/11/14 22:35:32 Done.
5335
5336 **Sytax**
Jim Stichnoth 2014/07/28 22:52:08 Syntax
Karl 2014/11/14 22:35:33 Done.
5337
5338 .. naclcode::
5339
5340 %vN = bitcast T1 V to T2; <A>
5341
5342 **Record**
5343
5344 .. naclcode::
5345
5346 AA: <3, VV, TT2, 11>
5347
5348 **Semantics**
5349
5350 The bitcast instruction converts the type of value *V* to type *T2*. *T1* and
5351 *T2* must be primitive types or vectors, and define the same number of bits.
5352
5353 **Constraints**
5354
5355 .. naclcode::
5356
5357 AA == AbbrevIndex(A)
5358 TypeOf(V) == T1
5359 VV = RelativeIndex(V)
5360 %tTT2 = TypeID(T2)
5361 BitSizeOf(T1) == BitSizeOf(T2)
5362 N == NumValuedInsts
5363 NumBasicBlocks < ExpectedBasicBlocks
5364
5365 **Updates**
5366
5367 .. naclcode::
5368
5369 ++NumValuedInsts;
5370 TypeOf(%vN) = T2;
5371
5372 **Examples**
5373
5374 .. naclcode::
5375
5376 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
5377 48:0| 3: <1, 6> | count 6;
5378 50:4| 3: <3> | @t0 = float;
5379 52:2| 3: <7, 64> | @t1 = i64;
5380 55:4| 3: <2> | @t2 = void;
5381 57:2| 3: <21, 0, 2, 0, 1> | @t3 = void (float, i64);
5382 62:0| 3: <7, 32> | @t4 = i32;
5383 65:2| 3: <4> | @t5 = double;
5384 67:0| 0: <65534> | }
5385 ...
5386 100:0| 1: <65535, 12, 2> | function void @f0(float %p0, i64 %p1)
5387 | | { // BlockID = 12
5388 108:0| 3: <1, 1> | blocks 1;
5389 | | %b0:
5390 110:4| 3: <3, 2, 4, 11> | %v0 = bitcast float %p0 to i32;
5391 114:4| 3: <3, 2, 5, 11> | %v1 = bitcast i64 %p1 to double;
5392 118:4| 3: <10> | ret void;
5393 120:2| 0: <65534> | }
5394
5395 Integer Comparison Instructions
5396 -------------------------------
5397
5398 The integer comparison instruction compares integral values and returns a
5399 boolean (i1) result for each pair of compared values.
5400
5401 **Syntax**
5402
5403 .. naclcode::
5404
5405 %vN = icmp C T V1, V2; <A>
5406
5407 **Record**
5408
5409 .. naclcode::
5410
5411 AA: <9, VV1, VV2, CC>
5412
5413 **Semantics**
5414
5415 The integer comparison instruction compares integral values and returns a
5416 boolean (i1) result for each pair of compared values in *V1* and *V2*. *V1* and
5417 *V2* must be of type *T*. *T* must be an integral type, or an integral vector
5418 type. Condition code *C* is the condition applied to all elements in *V1* and
5419 *V2*. Each comparison always yields an i1. If *T* is a primitive type, the
5420 resulting type is i1. If *T* is a vector, then the resulting type is a vector of
5421 i1 with the same size as *T*.
5422
5423 Legal test conditions are:
5424
5425 === == ==============================
5426 C CC Operator
5427 === == ==============================
5428 eq 32 equal
5429 ne 33 not equal
5430 ugt 34 unsigned greater than
5431 uge 35 unsigned greater than or equal
5432 ult 36 unsigned less then
5433 ule 37 unsigned less than or equal
5434 sgt 38 signed greater than
5435 sge 39 signed greater than or equal
5436 slt 40 signed less than
5437 sle 41 signed less than or equal
5438 === == ==============================
5439
5440 **Constraints**
5441
5442 .. naclcode::
5443
5444 AA == AbbrevIndex(A)
5445 IsInteger(UnderlyingType(T)
5446 T == TypeOf(V1) == TypeOf(V2)
5447 N == NumValuedInsts
5448 NumBasicBlocks < ExpectedBasicBlocks
5449
5450 **Updates**
5451
5452 .. naclcode::
5453
5454 ++NumValuedInsts;
5455 if IsVector(T) then
5456 TypeOf(%vN) = <UnderlyingCount(T), i1>
5457 else
5458 TypeOf(%vN) = i1
5459 endif
5460
5461 **Examples**
5462
5463 .. naclcode::
5464
5465 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
5466 48:0| 3: <1, 4> | count 4;
5467 50:4| 3: <7, 32> | @t0 = i32;
5468 53:6| 3: <7, 1> | @t1 = i1;
5469 56:2| 3: <2> | @t2 = void;
5470 58:0| 3: <21, 0, 2> | @t3 = void ();
5471 61:2| 0: <65534> | }
5472 ...
5473 108:0| 1: <65535, 12, 2> | function void @f0() {
5474 | | // BlockID = 12
5475 116:0| 3: <1, 1> | blocks 1;
5476 118:4| 1: <65535, 11, 2> | constants { // BlockID = 11
5477 128:0| 3: <1, 0> | i32:
5478 130:4| 3: <4, 0> | %c0 = i32 0;
5479 133:0| 3: <4, 2> | %c1 = i32 1;
5480 135:4| 0: <65534> | }
5481 | | %b0:
5482 136:0| 3: <28, 2, 1, 32> | %v0 = icmp eq i32 %c0, %c1;
5483 140:6| 3: <28, 3, 2, 33> | %v1 = icmp ne i32 %c0, %c1;
5484 145:4| 3: <28, 4, 3, 34> | %v2 = icmp ugt i32 %c0, %c1;
5485 150:2| 3: <28, 5, 4, 36> | %v3 = icmp ult i32 %c0, %c1;
5486 155:0| 3: <28, 6, 5, 37> | %v4 = icmp ule i32 %c0, %c1;
5487 159:6| 3: <28, 7, 6, 38> | %v5 = icmp sgt i32 %c0, %c1;
5488 164:4| 3: <28, 8, 7, 38> | %v6 = icmp sgt i32 %c0, %c1;
5489 169:2| 3: <28, 9, 8, 39> | %v7 = icmp sge i32 %c0, %c1;
5490 174:0| 3: <28, 10, 9, 40> | %v8 = icmp slt i32 %c0, %c1;
5491 178:6| 3: <28, 11, 10, 41> | %v9 = icmp sle i32 %c0, %c1;
5492 183:4| 3: <10> | ret void;
5493 185:2| 0: <65534> | }
5494
5495 Floating Point Comparison Instructions
5496 --------------------------------------
5497
5498 The floating point comparison instruction compares floating point values and
5499 returns a boolean (i1) result for each pair of compared values.
5500
5501 **Syntax**
5502
5503 .. naclcode::
5504
5505 %vN = fcmp C T V1, V2; <A>
5506
5507 **Record**
5508
5509 .. naclcode::
5510
5511 AA: <9, VV1, VV2, CC>
5512
5513 **Semantics**
5514
5515 The floating point comparison instruciton compares floating point values and
Jim Stichnoth 2014/07/28 18:21:06 instruction
Karl 2014/11/14 22:35:27 Done.
5516 returns a boolean (i1) result for each pair of compared values in *V1* and
5517 *V2*. *V1* and *V2* must be of type *T*. *T* must be a floating point type, or a
5518 floating point vector type. Condition code *C* is the condition applied to all
5519 elements in *V1* and *V2*. Each comparison always yeilds an i1. If *T* is a
Jim Stichnoth 2014/07/28 18:21:06 yields
Karl 2014/11/14 22:35:28 Done.
5520 primitive type, the resulting type is i1. If *T* is a vector, then the resulting
5521 type is a vector of i1 with the same size as *T*.
5522
5523 Legal test conditions are:
5524
5525 ===== == ==================================
5526 C CC Operator
5527 ===== == ==================================
5528 false 0 Always false
5529 oeq 1 Ordered and equal
5530 ogt 2 Ordered and greater than
5531 oge 3 Ordered and greater than or equal
5532 olt 4 Ordered and less than
5533 ole 5 Ordered and less than or equal
5534 one 6 Ordered and not equal
5535 ord 7 Ordered (no nans)
5536 uno 8 Unordered (either nans)
5537 ueq 9 Unordered or equal
5538 ugt 10 Unordered or greater than
5539 uge 11 Unordered or greater than or equal
5540 ult 12 Unordered or less than
5541 ule 13 Unordered or less than or equal
5542 une 14 Unordered or not equal
5543 true 15 Alwyas true
Jim Stichnoth 2014/07/28 18:21:08 Always
Karl 2014/11/14 22:35:30 Done.
5544 ===== == ==================================
5545
5546 **Constraints**
5547
5548 .. naclcode::
5549
5550 AA == AbbrevIndex(A)
5551 IsFloat(UnderlyingType(T)
5552 T == TypeOf(V1) == TypeOf(V2)
5553 N == NumValuedInsts
5554 NumBasicBlocks < ExpectedBasicBlocks
5555
5556 **Updates**
5557
5558 .. naclcode::
5559
5560 ++NumValuedInsts;
5561 if IsVector(T) then
5562 TypeOf(%vN) = <UnderlyingCount(T), i1>
5563 else
5564 TypeOf(%vN) = i1
5565 endif
5566
5567 **Examples**
5568
5569 .. naclcode::
5570
5571 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
5572 48:0| 3: <1, 4> | count 4;
5573 50:4| 3: <3> | @t0 = float;
5574 52:2| 3: <7, 1> | @t1 = i1;
5575 54:6| 3: <2> | @t2 = void;
5576 56:4| 3: <21, 0, 2> | @t3 = void ();
5577 59:6| 0: <65534> | }
5578 ...
5579 108:0| 1: <65535, 12, 2> | function void @f0() {
5580 | | // BlockID = 12
5581 116:0| 3: <1, 1> | blocks 1;
5582 118:4| 1: <65535, 11, 2> | constants { // BlockID = 11
5583 128:0| 3: <1, 0> | float:
5584 130:4| 3: <6, 0> | %c0 = float 0;
5585 133:0| 3: <6, 1065353216> | %c1 = float 1;
5586 139:2| 0: <65534> | }
5587 | | %b0:
5588 140:0| 3: <28, 2, 1, 0> | %v0 = fcmp false float %c0, %c1;
5589 144:0| 3: <28, 3, 2, 1> | %v1 = fcmp oeq float %c0, %c1;
5590 148:0| 3: <28, 4, 3, 2> | %v2 = fcmp ogt float %c0, %c1;
5591 152:0| 3: <28, 5, 4, 3> | %v3 = fcmp oge float %c0, %c1;
5592 156:0| 3: <28, 6, 5, 4> | %v4 = fcmp olt float %c0, %c1;
5593 160:0| 3: <28, 7, 6, 5> | %v5 = fcmp ole float %c0, %c1;
5594 164:0| 3: <28, 8, 7, 6> | %v6 = fcmp one float %c0, %c1;
5595 168:0| 3: <28, 9, 8, 7> | %v7 = fcmp ord float %c0, %c1;
5596 172:0| 3: <28, 10, 9, 9> | %v8 = fcmp ueq float %c0, %c1;
5597 176:0| 3: <28, 11, 10, 10> | %v9 = fcmp ugt float %c0, %c1;
5598 180:0| 3: <28, 12, 11, 11> | %v10 = fcmp uge float %c0, %c1;
5599 184:0| 3: <28, 13, 12, 12> | %v11 = fcmp ult float %c0, %c1;
5600 188:0| 3: <28, 14, 13, 13> | %v12 = fcmp ule float %c0, %c1;
5601 192:0| 3: <28, 15, 14, 14> | %v13 = fcmp une float %c0, %c1;
5602 196:0| 3: <28, 16, 15, 8> | %v14 = fcmp uno float %c0, %c1;
5603 200:0| 3: <28, 17, 16, 15> | %v15 = fcmp true float %c0, %c1;
5604 204:0| 3: <10> | ret void;
5605 205:6| 0: <65534> | }
5606 208:0|0: <65534> |}
5607
5608 Vector Instructions
5609 -------------------
5610
5611 PNaClAsm supports several instructions that process vectors. This includes
5612 binary instructions and compare instructions. These instructions work with
5613 existing vectors and generate resulting (new) vectors. This section instroduces
Jim Stichnoth 2014/07/28 18:21:07 introduces
Karl 2014/11/14 22:35:27 Done.
5614 the instructions to construct vectors and extract results.
5615
5616 .. _link_for_insert_element_instruction_section:
5617
5618 Insert Element Instruction
5619 ^^^^^^^^^^^^^^^^^^^^^^^^^^
5620
5621 The *insert element* instruction inserts a scalar value into a vector at a
5622 specified index. The *insert element* instruction takes an existing vector and
5623 puts a scalar value in one of the elements of the vector.
5624
5625 The *insert element* instruction can be used to construct a vector, one element
5626 at a time. At first glance, it may appear that one can't construct a vector,
5627 since the *insert element* instruction needs a vector to insert elements into.
5628
5629 The key to understanding vector construction is understand that one can create
5630 an undefined vector literal. Using that constant as a starting point, one can
5631 built up the wanted vector by a sequence of *insert element* instructions.
5632
5633 **Syntax**
5634
5635 .. naclcode::
5636
5637 %vN = insertelement TV V, TE E, i32 I; <A>
5638
5639 **Record**
5640
5641 .. naclcode::
5642
5643 AA: <7, VV, EE, II>
5644
5645 **Semantics**
5646
5647 The *insert element* instruction inserts scalar value *E* into index *I* of
5648 vector *V*. *%vN* holds the updated vector. Type *TV* is the type of vector. It
5649 is also the type of updated vector *%vN*. Type *TE* is the type of scalar value
5650 *E* and must be the element type of vector *V*. *I* must be an i32 value.
5651
5652 If *I* exceeds the length of *V*, the results is undefined.
Jim Stichnoth 2014/07/28 22:52:03 result
Karl 2014/11/14 22:35:27 Done.
5653
5654 **Constrants**
Jim Stichnoth 2014/07/28 18:21:07 Constraints
Karl 2014/11/14 22:35:28 Done.
5655
5656 .. naclcode::
5657
5658 AA == AbbrevIndex(A)
5659 IsVector(TV)
5660 TypeOf(V) == TV
5661 UnderlyingType(TV) == TE
5662 TypeOf(I) == i32
5663 N == NumValuedInsts
5664 NumBasicBlocks < ExpectedBasicBlocks
5665
5666 **Updates**
5667
5668 .. naclcode::
5669
5670 ++NumValuedInsts;
5671 TypeOf(%vN) = TV;
5672
5673 **Examples**
5674
5675 .. naclcode::
5676
5677 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
5678 48:0| 3: <1, 5> | count 5;
5679 50:4| 3: <7, 1> | @t0 = i1;
5680 53:0| 3: <12, 4, 0> | @t1 = <4 x i1>;
5681 56:2| 3: <7, 32> | @t2 = i32;
5682 59:4| 3: <2> | @t3 = void;
5683 61:2| 3: <21, 0, 3> | @t4 = void ();
5684 64:4| 0: <65534> | }
5685 ...
5686 116:0| 1: <65535, 12, 2> | function void @f0() {
5687 | | // BlockID = 12
5688 124:0| 3: <1, 1> | blocks 1;
5689 126:4| 1: <65535, 11, 2> | constants { // BlockID = 11
5690 136:0| 3: <1, 0> | i1:
5691 138:4| 3: <4, 0> | %c0 = i1 0;
5692 141:0| 3: <4, 3> | %c1 = i1 1;
5693 143:4| 3: <1, 1> | <4 x i1>:
5694 146:0| 3: <3> | %c2 = <4 x i1> undef;
5695 147:6| 3: <1, 2> | i32:
5696 150:2| 3: <4, 0> | %c3 = i32 0;
5697 152:6| 3: <4, 2> | %c4 = i32 1;
5698 155:2| 3: <4, 4> | %c5 = i32 2;
5699 157:6| 3: <4, 6> | %c6 = i32 3;
5700 160:2| 0: <65534> | }
5701 | | %b0:
5702 164:0| 3: <7, 5, 7, 4> | %v0 = insertelement <4 x i1> %c2,
5703 | | i1 %c0, i32 %c3;
5704 168:0| 3: <7, 1, 7, 4> | %v1 = insertelement <4 x i1> %v0,
5705 | | i1 %c1, i32 %c4;
5706 172:0| 3: <7, 1, 9, 4> | %v2 = insertelement <4 x i1> %v1,
5707 | | i1 %c0, i32 %c5;
5708 176:0| 3: <7, 1, 9, 4> | %v3 = insertelement <4 x i1> %v2,
5709 | | i1 %c1, i32 %c6;
5710 180:0| 3: <10> | ret void;
5711 181:6| 0: <65534> | }
5712
5713 Extract Element Instruction
5714 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
5715
5716 The *extract element* instruction extracts a single scalar value from a vector
5717 at a specified index.
5718
5719 **Syntax**
5720
5721 .. naclcode::
5722
5723 %vN = extractelement TV V, i32 I; <A>
5724
5725 **Record**
5726
5727 .. naclcode::
5728
5729 AA: <6, VV, II>
5730
5731 **Semantics**
5732
5733 The *extract element* instruction extracts the scalar value at index *I* from
5734 vector *V*. The extracted value is assigned to *%vN*. Type *TV* is the type of
5735 vector *V*. *I* must be an i32 value. The type of *vN* must be the element type
5736 of vector *V*.
5737
5738 If *I* exceeds the length of *V*, the results is undefined.
Jim Stichnoth 2014/07/28 22:52:08 result
Karl 2014/11/14 22:35:33 Done.
5739
5740 **Constraints**
5741
5742 .. naclcode::
5743
5744 AA == AbbrevIndex(A)
5745 IsVector(TV)
5746 TypeOf(V) == TV
5747 TypeOf(I) == i32
5748 N == NumValuedInsts
5749 NumBasicBlocks < ExpectedBasicBlocks
5750
5751 **Updates**
5752
5753 .. naclcode::
5754
5755 ++NumValuedInsts;
5756 TypeOf(%vN) = UnderlyingType(TV);
5757
5758 **Examples**
5759
5760 .. naclcode::
5761
5762 96:0| 1: <65535, 12, 2> | function void @f0(<4 x i32> %p0) {
5763 | | // BlockID = 12
5764 104:0| 3: <1, 1> | blocks 1;
5765 106:4| 1: <65535, 11, 2> | constants { // BlockID = 11
5766 116:0| 3: <1, 0> | i32:
5767 118:4| 3: <4, 0> | %c0 = i32 0;
5768 121:0| 0: <65534> | }
5769 | | %b0:
5770 124:0| 3: <6, 2, 1> | %v0 =
5771 | | extractelement <4 x i32> %p0,
5772 | | i32 %c0;
5773 127:2| 3: <10> | ret void;
5774 129:0| 0: <65534> | }
5775
5776 Other Instructions
5777 ------------------
5778
5779 This section defines miscellaneous instructions which defy better
5780 classification.
5781
5782 .. _link_for_forward_type_declaration_section:
5783
5784 Forward type declaration
Jim Stichnoth 2014/07/28 22:52:05 Forward Type Declaration
Karl 2014/11/14 22:35:32 Done.
5785 ^^^^^^^^^^^^^^^^^^^^^^^^
5786
5787 The forward type declaration exists to deal with the fact that all instruction
5788 values must have a type associated with them before they are used. For some
5789 simple functions one can easily topologically sort instructions so that
5790 instruction values are defined before they are used. However, if the
5791 implementation contains loops, the loop induced values can't be defined before
5792 they are used.
5793
5794 The solution is to forward declare the type of an instruction value. One could
5795 forward declare the types of all instructions at the beginning of the function
5796 block. However, this would make the corresponding file size considerably
5797 larger. Rather, one should only generate these forward type declarations
5798 sparingly and only when needed.
5799
5800 **Syntax**
5801
5802 .. naclcode::
5803
5804 declare T %vN; <A>
5805
5806 **Record**
5807
5808 .. naclcode::
5809
5810 AA: <43, N, TT>
5811
5812 **Semantics**
5813
5814 The forward declare type declaration defines the type to be associated with a
5815 (not yet defined) instruction value *%vN*. *T* is the type of the value
5816 generated by the *Nth* value generating instruction in the function block.
5817
5818 Note: It is an error to define the type of *%vN* with a different type than will
5819 be generated by the *Nth* value generating instruction in the function block.
5820
5821 Also note that this construct is a declaration and not considered an
5822 instruction, even though it appears in the list of instruction records. Hence,
5823 they may appear before and between :ref:`phi<link_for_phi_instruction_section>`
5824 instructions in a basic block.
5825
5826 **Constraints**
5827
5828 .. naclcode::
5829
5830 AA = AbbrevIndex(A)
5831 TT = TypeID(T)
5832 NumBasicBlocks < ExpectedBasicBlocks
5833
5834 **Updates**
5835
5836 .. naclcode::
5837
5838 TypeOf(%vN) = T;
5839
5840 **Examples**
5841
5842 .. naclcode::
5843
5844 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
5845 48:0| 3: <1, 4> | count 4;
5846 50:4| 3: <7, 32> | @t0 = i32;
5847 53:6| 3: <2> | @t1 = void;
5848 55:4| 3: <7, 1> | @t2 = i1;
5849 58:0| 3: <21, 0, 1, 0> | @t3 = void (i32);
5850 62:0| 0: <65534> | }
5851 ...
5852 108:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
5853 | | // BlockID = 12
5854 116:0| 3: <1, 7> | blocks 7;
5855 118:4| 1: <65535, 11, 2> | constants { // BlockID = 11
5856 128:0| 3: <1, 2> | i1:
5857 130:4| 3: <4, 3> | %c0 = i1 1;
5858 133:0| 0: <65534> | }
5859 | | %b0:
5860 136:0| 3: <11, 4> | br label %b4;
5861 | | %b1:
5862 138:4| 3: <43, 6, 0> | declare i32 %v3;
5863 142:4| 3: <2, 2, 4294967293, 0> | %v0 = add i32 %p0, %v3;
5864 151:0| 3: <11, 6> | br label %b6;
5865 | | %b2:
5866 153:4| 3: <43, 7, 0> | declare i32 %v4;
5867 157:4| 3: <2, 3, 4294967293, 0> | %v1 = add i32 %p0, %v4;
5868 166:0| 3: <11, 6> | br label %b6;
5869 | | %b3:
5870 168:4| 3: <2, 4, 4294967295, 0> | %v2 = add i32 %p0, %v3;
5871 177:0| 3: <11, 6> | br label %b6;
5872 | | %b4:
5873 179:4| 3: <2, 5, 5, 0> | %v3 = add i32 %p0, %p0;
5874 183:4| 3: <11, 1, 5, 5> | br i1 %c0, label %b1, label %b5;
5875 | | %b5:
5876 187:4| 3: <2, 1, 6, 0> | %v4 = add i32 %v3, %p0;
5877 191:4| 3: <11, 2, 3, 6> | br i1 %c0, label %b2, label %b3;
5878 | | %b6:
5879 195:4| 3: <10> | ret void;
5880 197:2| 0: <65534> | }
5881
5882 .. _link_for_phi_instruction_section:
5883
5884 Phi Instruction
5885 ^^^^^^^^^^^^^^^
5886
5887 The *phi* instruction is used to implement phi nodes in the SSA graph
5888 representing the function. Phi instructions can only appear at the beginning of
5889 a basic block. There must be no non-phi instructions (other than forward type
5890 declarations) between the start of the basic block and the *phi* instruction.
5891
5892 To clarify the origin of each incoming value, the incoming value is associated
5893 with the incoming edge from the corresponding predicessor block for which the
Jim Stichnoth 2014/07/28 18:21:05 predecessor
Jim Stichnoth 2014/07/28 22:52:05 for which --> that ?
Karl 2014/11/14 22:35:30 Done.
Karl 2014/11/14 22:35:32 Done.
5894 incoming value comes from.
5895
5896 **Syntax**
5897
5898 .. naclcode::
5899
5900 %vN = phi T [V1, %bB1], ... , [VM, %bBM]; <A>
5901
5902 **Record**
5903
5904 .. naclcode::
5905
5906 AA: <16, TT, VV1, B1, ..., VVM, BM>
5907
5908 **Semantics**
5909
5910 The phi instruction is used to implement phi nodes in the SSA graph representing
5911 the function. *%vN* is the resulting value of the corresponding phi node. *T* is
5912 the type of the phi node. Values *V1* through *VM* are the reaching definitions
5913 for the phi node while *%bB1* through *%bBM* are the corresponding predicessor
Jim Stichnoth 2014/07/28 18:21:08 predecessor
Karl 2014/11/14 22:35:30 Done.
5914 blocks. Each *VI* reaches via the incoming predicessor edge from block *%bBI*
Jim Stichnoth 2014/07/28 18:21:06 predecessor
Karl 2014/11/14 22:35:31 Done.
5915 (for 1 <= I <= M). Type *T* must be the type associated with each *VI*.
5916
5917 **Constraints**
5918
5919 .. naclcode::
5920
5921 AA == AbbrevIndex(A)
5922 M > 1
5923 TT == TypeID(T)
5924 T = TypeOf(VI) for all I, 1 <= I <= M
5925 BI < ExpectedBasicBlocks for all I, 1 <= I <= M
5926 VVI = SignRotate(RelativeIndex(VI)) for all I, 1 <= I <= M
5927 N == NumValuedInsts
5928
5929 **Updates**
5930
5931 .. naclcode::
5932
5933 ++NumValuedInsts;
5934 TypeOf(%vN) = T;
5935
5936 **Examples**
5937
5938 .. naclcode::
5939
5940 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
5941 48:0| 3: <1, 4> | count 4;
5942 50:4| 3: <7, 32> | @t0 = i32;
5943 53:6| 3: <2> | @t1 = void;
5944 55:4| 3: <21, 0, 1> | @t2 = void ();
5945 58:6| 3: <7, 1> | @t3 = i1;
5946 61:2| 0: <65534> | }
5947 ...
5948 112:0| 1: <65535, 12, 2> | function void @f0() {
5949 | | // BlockID = 12
5950 120:0| 3: <1, 4> | blocks 4;
5951 122:4| 1: <65535, 11, 2> | constants { // BlockID = 11
5952 132:0| 3: <1, 0> | i32:
5953 134:4| 3: <4, 2> | %c0 = i32 1;
5954 137:0| 3: <1, 3> | i1:
5955 139:4| 3: <4, 0> | %c1 = i1 0;
5956 142:0| 0: <65534> | }
5957 | | %b0:
5958 144:0| 3: <11, 1, 2, 1> | br i1 %c1, label %b1, label %b2;
5959 | | %b1:
5960 148:0| 3: <2, 2, 2, 0> | %v0 = add i32 %c0, %c0;
5961 152:0| 3: <2, 3, 3, 1> | %v1 = sub i32 %c0, %c0;
5962 156:0| 3: <11, 3> | br label %b3;
5963 | | %b2:
5964 158:4| 3: <2, 4, 4, 2> | %v2 = mul i32 %c0, %c0;
5965 162:4| 3: <2, 5, 5, 3> | %v3 = udiv i32 %c0, %c0;
5966 166:4| 3: <11, 3> | br label %b3;
5967 | | %b3:
5968 169:0| 3: <16, 0, 8, 1, 4, 2> | %v4 = phi i32 [%v0, %b1],
5969 | | [%v2, %b2];
5970 174:4| 3: <16, 0, 8, 1, 4, 2> | %v5 = phi i32 [%v1, %b1],
5971 | | [%v3, %b2];
5972 180:0| 3: <10> | ret void;
5973 181:6| 0: <65534> | }
5974
5975 Select Instruction
5976 ^^^^^^^^^^^^^^^^^^
5977
5978 The *select* instruction is used to choose between pairs of values, based on a
5979 condition, without PNaClAsm-level branching.
5980
5981 **Syntax**
5982
5983 .. naclcode::
5984
5985 %vN = select CT C, T V1, T V2; <A>
5986
5987 **Record**
5988
5989 .. naclcode::
5990
5991 AA: <29, VV1, VV2, CC>
5992
5993 **Semantics**
5994
5995 The *select* instruction choses pairs of values *V1* and *V2*, based on
Jim Stichnoth 2014/07/28 18:21:08 chooses
Karl 2014/11/14 22:35:28 Done.
5996 condition values *C*. The type *CT* of value *C* must either be an i1, or a
5997 vector of type i1. The type of values *V1* and *V2* must be of type *T*. Type
5998 *T* must either be a primitive type, or a vector of a primitive type.
5999
6000 Both *CT* and *T* must be primitive types, or both must be vector types of the
6001 same size. When the contents of *C* is 1, the corresponding value from *V1* will
6002 be chosen. Otherwise the conrresponding value from *V2* will be chosen.
Jim Stichnoth 2014/07/28 22:52:06 corresponding
Karl 2014/11/14 22:35:35 Done.
6003
6004 **Constraints**
6005
6006 .. naclcode::
6007
6008 AA == AbbrevIndex(A)
6009 CC == RelativeIndex(C)
6010 VV1 == RelativeIndex(V1)
6011 VV2 == RelativeIndex(V2)
6012 T == TypeOf(V1) == TypeOf(V2)
6013 UnderlyingType(CT) == i1
6014 IsInteger(UnderlyingType(T)) or IsFloat(UnderlyingType(T))
6015 UnderlyingCount(C) == UnderlyingCount(T)
6016 N == NumValuedInsts
6017
6018 **Updates**
6019
6020 .. naclcode::
6021
6022 ++NumValuedInsts;
6023 TypeOf(%vN) = T;
6024
6025 **Examples**
6026
6027 .. naclcode::
6028
6029 96:0| 1: <65535, 12, 2> | function i32 @f0(i32 %p0, i32 %p1) {
6030 | | // BlockID = 12
6031 104:0| 3: <1, 1> | blocks 1;
6032 106:4| 1: <65535, 11, 2> | constants { // BlockID = 11
6033 116:0| 3: <1, 2> | i1:
6034 118:4| 3: <4, 3> | %c0 = i1 1;
6035 121:0| 0: <65534> | }
6036 | | %b0:
6037 124:0| 3: <29, 3, 2, 1> | %v0 = select i1 %c0, i32 %p0,
6038 | | i32 %p1;
6039 128:0| 3: <10, 1> | ret i32 %v0;
6040 130:4| 0: <65534> | }
6041
6042
6043 Call Instructions
6044 ^^^^^^^^^^^^^^^^^
6045
6046 The *call* instruction does a function call. The call instruction is used to
6047 cause control flow to transfer to a specified routine, with its incoming
6048 arguments bound to the specified values. When a *ret* instruction, in the called
6049 function, is reached control flow continues with instruction after the function
Jim Stichnoth 2014/07/28 22:52:03 Commas more like this? When a *ret* instruction i
Jim Stichnoth 2014/07/28 22:52:08 with --> with the
Karl 2014/11/14 22:35:33 Done.
Karl 2014/11/14 22:35:33 Done.
6050 call. If the call is to a function, the returned value is the value generated by
6051 the call instruction. Otherwise no result is defined by the call.
6052
6053 If the *tail* flag is associated with the call instruction, then optimizers in
Jim Stichnoth 2014/07/28 22:52:09 Remove "optimizers in", I think.
Karl 2014/11/14 22:35:30 Done.
6054 the PNaCl translator is free to perform tail call optimiziation. That is, the
Jim Stichnoth 2014/07/28 18:21:06 optimization
Karl 2014/11/14 22:35:31 Done.
6055 *tail* flag is a hint that may be ignored by the PNaCl translator.
6056
6057 There are two kinds of calls: *direct* and *indirect*. A *direct* call calls a
6058 defined function address (i.e. a reference to a bitcode ID of the form
6059 *%fF*). All other calls are *indirect*.
6060
6061 Direct Procedure Call
6062 ---------------------
6063
6064 The direct procedure call calls a defined function address whose type signature
6065 returns type void.
6066
6067 **Syntax**
6068
6069 .. naclcode::
6070
6071 TAIL call void @fF (T1 A1, ... , TN AN); <A>
6072
6073 **Record**
6074
6075 .. naclcode::
6076
6077 AA: <34, CC, F, AA1, ... , AAN>
6078
6079 **Semantics**
6080
6081 The direct procedure call calls a define function address *%fF* whose type
6082 signature return type is void. The arguments *A1* through *AN* are passed
6083 in the order specified. The type of arugment *AI* must be type *TI* (for all I,
Jim Stichnoth 2014/07/28 18:21:07 argument
Karl 2014/11/14 22:35:31 Done.
6084 1 <=I <= N). Flag *TAIL* is optional. If it is included, it must the the
Jim Stichnoth 2014/07/28 22:52:06 the the --> be the
Karl 2014/11/14 22:35:32 Done.
6085 literal *tail*.
6086
6087 The types of the arugments must match the corresponding types of the function
Jim Stichnoth 2014/07/28 18:21:07 arguments
Karl 2014/11/14 22:35:35 Done.
6088 signature associated with *%fF*. The return type of *%f* must be void.
6089
6090 TAIL is encoded into calling convention value *CC* as follows:
6091
6092 ====== ==
6093 TAIL CC
6094 ====== ==
6095 '' 0
6096 'tail' 1
6097 ====== ==
6098
6099 **Constraints**
6100
6101 .. naclcode::
6102
6103 AA == AbbrevIndex(A)
6104 N >= 0
6105 TypeOfFcn(%fF) == void (T1, ... , TN)
6106 TypeOf(AI) == TI for all I, 1 <= I <= N
6107
6108 **Updates**
6109
6110 .. naclcode::
6111
6112 ++NumValuedInsts;
6113
6114 **Examples**
6115
6116 .. naclcode::
6117
6118 72:0| 3: <8, 3, 0, 1, 0> | declare external
6119 | | void @f0(i32, i64, i32);
6120 ...
6121 116:0| 1: <65535, 12, 2> | function void @f1(i32 %p0) {
6122 | | // BlockID = 12
6123 124:0| 3: <1, 1> | blocks 1;
6124 126:4| 1: <65535, 11, 2> | constants { // BlockID = 11
6125 136:0| 3: <1, 2> | i64:
6126 138:4| 3: <4, 2> | %c0 = i64 1;
6127 141:0| 0: <65534> | }
6128 | | %b0:
6129 144:0| 3: <34, 0, 4, 2, 1, 2> | call void
6130 | | @f0(i32 %p0, i64 %c0, i32 %p0);
6131 150:2| 3: <10> | ret void;
6132 152:0| 0: <65534> | }
6133
6134 Direct Function Call
6135 --------------------
6136
6137 The direct function call calls a defined function address whose type signature
6138 returns a value.
6139
6140 **Syntax**
6141
6142 .. naclcode::
6143
6144 %vN = TAIL call RT %fF (T1 A1, ... , TM AM); <A>
6145
6146
6147 **Record**
6148
6149 .. naclcode::
6150
6151 AA: <34, CC, F, AA1, ... , AAM>
6152
6153 **Semantics**
6154
6155 The direct function call calls a defined function address *%fF* whose type
6156 signature returns is not type void. The arguments *A1* through *AM* are passed
Jim Stichnoth 2014/07/28 22:52:04 returns --> returned
Karl 2014/11/14 22:35:33 Done.
6157 in the order specified. The type of arugment *AI* must be type *TI* (for all I,
Jim Stichnoth 2014/07/28 18:21:07 argument
Karl 2014/11/14 22:35:31 Done.
6158 1 <= I <= N). Flag *TAIL* is optional. If it is included, it must the the
Jim Stichnoth 2014/07/28 22:52:07 the the --> be the
Karl 2014/11/14 22:35:29 Done.
6159 literal *tail*.
6160
6161 The types of the arugments must match the corresponding types of the function
Jim Stichnoth 2014/07/28 18:21:08 arguments
Karl 2014/11/14 22:35:30 Done.
6162 signature associated with *%fF*. The return type must match *RT*.
6163
6164 Each parameter type *TI*, and return type *RT*, must either be a primitive type,
6165 or a vector type. If the parameter type is an integral type, it must either be
6166 i32 or i64.
6167
6168 TAIL is encoded into calling convention value *CC* as follows:
6169
6170 ====== ==
6171 TAIL CC
6172 ====== ==
6173 '' 0
6174 'tail' 1
6175 ====== ==
6176
6177 **Constraints**
6178
6179 .. naclcode::
6180
6181 AA == AbbrevIndex(A)
6182 N >= 0
6183 TypeOfFcn(%fF) == RT (T1, ... , TN)
6184 TypeOf(AI) == TI for all I, 1 <= I <= M
6185 IsFcnArgType(TI) for all I, 1 <= I <= M
6186 IsFcnArgType(RT)
6187 N == NumValuedInsts
6188
6189 **Updates**
6190
6191 .. naclcode::
6192
6193 ++NumValuedInsts;
6194 TypeOf(%vN) = RT;
6195
6196 **Examples**
6197
6198 .. naclcode::
6199
6200 72:0| 3: <8, 2, 0, 1, 0> | declare external
6201 | | i32 @f0(i32, i64, i32);
6202 ...
6203 116:0| 1: <65535, 12, 2> | function i32 @f1(i32 %p0) {
6204 | | // BlockID = 12
6205 124:0| 3: <1, 1> | blocks 1;
6206 126:4| 1: <65535, 11, 2> | constants { // BlockID = 11
6207 136:0| 3: <1, 1> | i64:
6208 138:4| 3: <4, 2> | %c0 = i64 1;
6209 141:0| 0: <65534> | }
6210 | | %b0:
6211 144:0| 3: <34, 0, 4, 2, 1, 2> | %v0 = call i32
6212 | | @f0(i32 %p0, i64 %c0, i32 %p0);
6213 150:2| 3: <34, 1, 4, 1> | %v1 = tail call i32 @f1(i32 %v0);
6214 155:0| 3: <10, 2> | ret i32 %v0;
6215 157:4| 0: <65534> | }
6216
6217 Indirect Procedure Call
6218 -----------------------
6219
6220 The indirect procedure call calls a function using an indirect function address,
6221 and whose type signature is assumed to return type void. It is different from
6222 the direct procedure call because we can't use the type signature of the
6223 corresponding direct function address to type check the construct.
6224
6225 **Syntax**
6226
6227 .. naclcode::
6228
6229 TAIL call void V (T1 A1, ... , TN AN); <A>
6230
6231 **Record**
6232
6233 .. naclcode::
6234
6235 AA: <44, CC, TV, VV, AA1, ... , AAN>
6236
6237 **Semantics**
6238
6239 The indirect call procedure calls a function using value *V* that is an indirect
6240 function address, and whose type signature is assumed to return type void. The
6241 arguments *A1* through *AN* are passed in the order specified. The type of
6242 arugment *AI* must be type *TI* (for all I, 1 <= I <= N). Flag *TAIL* is
Jim Stichnoth 2014/07/28 18:21:06 argument
Karl 2014/11/14 22:35:30 Done.
6243 optional. If it is included, it must the the literal *tail*.
Jim Stichnoth 2014/07/28 22:52:05 the the --> be the
Karl 2014/11/14 22:35:30 Done.
6244
6245 Each parameter type *TI* (1 <= I <= N) must either be a primitive type, or a
6246 vector type. If the parameter type is an integral type, it must either be i32
6247 or i64.
6248
6249 TAIL is encoded into calling convention value *CC* as follows:
6250
6251 ====== ==
6252 TAIL CC
6253 ====== ==
6254 '' 0
6255 'tail' 1
6256 ====== ==
6257
6258 The type signature of the called procedure is assumed to be:
6259
6260 .. naclcode::
6261
6262 void (T1, ... , TN)
6263
6264 It isn't necessary to define this type in the types block, since the type is
6265 inferred rather than used.
6266
6267 **Constraints**
6268
6269 .. naclcode::
6270
6271 AA == AbbrevIndex(A)
6272 N >= 0
6273 TV = TypeID(void)
6274 AbsoluteIndex(V) >= NumFuncAddresses
6275 TypeOf(AI) == TI for all I, 1 <= I <= N
6276 IsFcnArgType(TI) for all I, 1 <= I <= N
6277
6278 **Updates**
6279
6280 .. naclcode::
6281
6282 ++NumValuedInsts;
6283
6284 **Examples**
6285
6286 .. naclcode::
6287
6288 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
6289 48:0| 3: <1, 3> | count 3;
6290 50:4| 3: <2> | @t0 = void;
6291 52:2| 3: <7, 32> | @t1 = i32;
6292 55:4| 3: <21, 0, 0, 1> | @t2 = void (i32);
6293 59:4| 0: <65534> | }
6294 ...
6295 92:0| 1: <65535, 12, 2> | function void @f0(i32 %p0) {
6296 | | // BlockID = 12
6297 100:0| 3: <1, 1> | blocks 1;
6298 102:4| 1: <65535, 11, 2> | constants { // BlockID = 11
6299 112:0| 3: <1, 1> | i32:
6300 114:4| 3: <4, 2> | %c0 = i32 1;
6301 117:0| 0: <65534> | }
6302 | | %b0:
6303 120:0| 3: <44, 0, 2, 0, 1> | call void %p0(i32 %c0);
6304 125:4| 3: <10> | ret void;
6305 127:2| 0: <65534> | }
6306
6307 Indirect Function Call
6308 ----------------------
6309
6310 The indirect function call calls a function using a value that is an indirect
6311 function address. It is different from the direct function call because we can't
6312 use the type signature of the corresponding literal function address to type
6313 check the construct.
6314
6315 **Syntax**
6316
6317 .. naclcode::
6318
6319 %vN = TAIL call RT V (T1 A1, ... , TM AM); <A>
6320
6321
6322 **Record**
6323
6324 .. naclcode::
6325
6326 AA: <34, CC, RRT, VV, AA1, ... , AAM>
6327
6328 **Semantics**
6329
6330 The indirect function call calls a function using a value *V* that is an
6331 indirect function address, and is assumed to return type *RT*. The arguments
6332 *A1* through *AM* are passed in the order specified. The type of arugment *AI*
Jim Stichnoth 2014/07/28 18:21:08 argument
Karl 2014/11/14 22:35:31 Done.
6333 must be type *TI* (for all I, 1 <= I <= N). Flag *TAIL* is optional. If it is
6334 included, it must the the literal *tail*.
Jim Stichnoth 2014/07/28 22:52:05 the the --> be the
Karl 2014/11/14 22:35:33 Done.
6335
6336 Each parameter type *TI* (1 <= I <= M), and return type *RT*, must either be a
6337 primitive type, or a vector type. If the parameter type is an integral type, it
6338 must either be i32 or i64.
6339
6340 TAIL is encoded into calling convention value *CC* as follows:
6341
6342 ====== ==
6343 TAIL CC
6344 ====== ==
6345 '' 0
6346 'tail' 1
6347 ====== ==
6348
6349 The type signature of the called function is assumed to be:
6350
6351 .. naclcode::
6352
6353 RT (T1, ... , TN)
6354
6355 It isn't necessary to define this type in the types block, since the type is
6356 inferred rather than used.
6357
6358 **Constraints**
6359
6360 .. naclcode::
6361
6362 AA == AbbrevIndex(A)
6363 RRT = TypeID(RT)
6364 VV = RelativeIndex(V)
6365 M >= 0
6366 AbsoluteIndex(V) >= NumFcnAddresses
6367 TypeOf(AI) == TI for all I, 1 <= I <= M
6368 IsFcnArgType(TI) for all I, 1 <= I <= M
6369 IsFcnArgType(RT)
6370 N == NumValuedInsts
6371
6372 **Updates**
6373
6374 .. naclcode::
6375
6376 ++NumValuedInsts;
6377 TypeOf(%vN) = RT;
6378
6379 **Examples**
6380
6381 .. naclcode::
6382
6383 40:0| 1: <65535, 17, 2> | types { // BlockID = 17
6384 48:0| 3: <1, 6> | count 6;
6385 50:4| 3: <7, 32> | @t0 = i32;
6386 53:6| 3: <3> | @t1 = float;
6387 55:4| 3: <4> | @t2 = double;
6388 57:2| 3: <21, 0, 0, 0, 1, 2> | @t3 = i32 (i32, float, double);
6389 62:6| 3: <21, 0, 0, 1, 2> | @t4 = i32 (float, double);
6390 67:4| 3: <2> | @t5 = void;
6391 69:2| 0: <65534> | }
6392 ...
6393 104:0| 1: <65535, 12, 2> | function
6394 | | i32
6395 | | @f0(i32 %p0, float %p1,
6396 | | double %p2) {
6397 | | // BlockID = 12
6398 112:0| 3: <1, 1> | blocks 1;
6399 | | %b0:
6400 114:4| 3: <44, 0, 3, 0, 2, 1> | %v0 = call i32
6401 | | %p0(float %p1, double %p2);
6402 120:6| 3: <10, 1> | ret i32 %v0;
6403 123:2| 0: <65534> | }
6404
6405 .. _link_for_support_functions_section:
6406
6407 Support Functions
6408 =================
6409
6410 Defines functions used to convert syntactic representation to values in the
6411 corresponding record.
6412
6413 SignRotate
6414 ----------
6415
6416 The SignRotate function encodes a signed integer in an easily compressible
6417 form. This is done by rotating the sign bit to the rightmost bit, rather than
6418 the leftmost bit. By doing this rotation, both small positive and negative
6419 integers are small (unsigned) integers. Therefore, all small integers can be
6420 encoded as a small (unsigned) integers.
6421
6422 The definition of SignRotate(N) is:
6423
6424 ======== ============= =========
6425 Argument Value Condition
6426 ======== ============= =========
6427 N abs(N)<<1 N >= 0
6428 N abs(N)<<1 + 1 N < 0
6429 ======== ============= =========
6430
6431 .. _link_for_absolute_index_section:
6432
6433 AbsoluteIndex
6434 -------------
6435
6436 Bitcode ID's of the forms *@fN*, *@gN*, *%pN*, *%cN*, and *%vN*, are combined
Jim Stichnoth 2014/07/28 22:52:07 ID's --> IDs
Karl 2014/11/14 22:35:30 Done.
6437 into a single index space. This can be done because of the ordering imposed by
6438 PNaClAsm. All function address bitcode IDs must be defined before any of the
6439 other forms of bitcode IDs. All global address bitcode IDs must be defined
6440 before any local bitcode IDs. Within a function block, the parameter bitcode IDs
6441 must be defined before constant IDs, and constant IDs must be defined before
6442 instruction value IDs.
6443
6444 Hence, within a function block, it is safe to refer to all of these
6445 bitcode IDs using a single *absolute* index. The absolute index for
6446 each kind of bitcode ID is computed as follows:
6447
6448 ========== ===================================================================== =====
6449 Bitcode ID AbsoluteIndex
6450 ========== ===================================================================== =====
6451 @fN N
6452 @gN N + NumFcnAddresses
6453 @pN N + NumFcnAddresses + NumGlobalAddresses
6454 @cN N + NumFcnAddresses + NumGlobalAddresses + NumParams
6455 @vN N + NumFcnAddresses + NumGlobalAddresses + NumParams + NumFcnConsts
6456 ========== ===================================================================== =====
Sam Clegg 2014/07/28 18:28:31 Can you shorten the ======== lines to be 80 chars
Karl 2014/11/14 22:35:33 Done.
6457
6458 RelativeIndex
6459 -------------
6460
6461 Relative indices are used to refer to values within instructions of a function.
6462 The relative index of an ID is always defined in terms of the index associated
6463 with the next value generating instruction. It is defined as follows:
6464
6465 .. naclcode::
6466
6467 RelativeIndex(J) = AbsoluteIndex(%vN) - AbsoluteIndex(J)
6468
6469 where
6470
6471 .. naclcode::
6472
6473 N = NumValuedInsts
6474
6475 AbbrevIndex
6476 -----------
6477
6478 This function converts user-defined abbreviation indices to the corresponding
6479 internal abbreviation index saved in the bitcode file. It adds 4 to its
6480 argument, since there are 4 predefined internal abbreviation indices (0, 1, 2,
6481 and 3).
6482
6483 ========= ==============
6484 N AbbrevIndex(N)
6485 ========= ==============
6486 undefined 3
6487 %aA A + 4
6488 @aA A + 4
6489 ========= ==============
6490
6491 Log2
6492 ----
6493
6494 This is the 32-bit log2 value of its argument.
6495
6496 exp
6497 ---
6498
6499 .. naclcode::
6500
6501 exp(n, m)
6502
6503 Denotes the *m* power of *n*.
6504
6505 BitSizeOf
6506 ---------
6507
6508 Returns the number of bits needed to represent its argument (a type).
6509
6510 ======= ================
6511 T BitSizeOf
6512 ======= ================
6513 i1 1
6514 i8 8
6515 i16 16
6516 i32 32
6517 i64 64
6518 float 32
6519 double 64
6520 <N X T> N * BitSizeOf(T)
6521 ======= ================
6522
6523 UnderlyingType
6524 --------------
6525
6526 Returns the primitive type of the type construct. For primitive types, the
6527 *UnderlyingType* is itself. For vector types, the base type of the vector is the
6528 underlying type.
6529
6530 UnderlyingCount
6531 ---------------
6532
6533 Returns the size of the vector if given a vector, and 0 for primitive types.
6534 Note that this function is used to check if two vectors are of the same size.
6535 It is also used to test if two types are either primitive (i.e. UnderlyingCount returns
Sam Clegg 2014/07/28 18:28:31 Wrap at 80.
Karl 2014/11/14 22:35:27 Done.
6536 0 for both types) or are vectors of the same size (i.e. UnderlyingCount returns
6537 the same non-zero value).
6538
6539 IsInteger
6540 ---------
6541
6542 Returns true if the argument is in {i1, i8, i16, i32, i64}.
6543
6544 IsFloat
6545 -------
6546
6547 Returns true if the argument is in {float, double}.
6548
6549 IsVector
6550 --------
6551
6552 Returns true if the argument is a vector type.
6553
6554 IsPrimitive
6555 -----------
6556
6557 Returns true if the argument is a primitive type. That is,
6558
6559 .. naclcode::
6560
6561 IsPrimitive(T) == IsInteger(T) or IsFloat(T)
6562
6563 IsFcnArgType
6564 ------------
6565
6566 Returns true if the argument is a primitive type or a vector type. Further,
6567 if it is an integral type, it must be i32 or i64. That is,
6568
6569 .. naclcode::
6570
6571 IsFcnArgType(T) = (IsInteger(T) and (i32 = BitSizeOf(T)
6572 or i64 == BitSizeOf(T)))
6573 or IsFloat(T) or IsVector(T)
6574
6575 .. _link_for_abbreviations_section:
6576
6577 Abbreviations
6578 -------------
6579
6580 TODO(kschimpf) Discuss the following:
6581
6582 * Blocks.
6583 * Data Records.
6584 * Abbreviations.
6585 * Abbreviation Ids.
6586
6587 Bitstream Format
6588 ^^^^^^^^^^^^^^^^
6589
6590 TODO(kschimpf)
6591
6592 * Header
6593 * Block Structure
6594 * Primitives
6595 * Abbreviations
6596 * Abbreviations block
6597
6598 Abbreviations Block
6599 ^^^^^^^^^^^^^^^^^^^
6600
6601 The abbreviations block is the first block in the module build. The
6602 block is divided into sections. Each section is a sequence of records. Each
6603 record in the sequence defines a user-defined abbreviation. Each section
6604 defines abbreviations that can be applied to all (succeeding) blocks of a
6605 particular kind. These abbreviations are denoted by the (global) ID of the form
6606 *@aN*.
6607
6608 TODO(kschimpf) Fill this in more.
6609
6610 Reference Implementation
6611 ^^^^^^^^^^^^^^^^^^^^^^^^
6612
6613 TODO(kschimpf)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698