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

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

Issue 266713003: Initial draft of PNaCl bitcode files document. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Second version of document. Created 6 years, 6 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
« no previous file with comments | « native_client_sdk/src/doc/_book.yaml ('k') | native_client_sdk/src/doc/sitemap.rst » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 ===================================
2 PNaCl Bitcode File Reference Manual
3 ===================================
4
5 .. contents::
6 :local:
7 :backlinks: none
8 :depth: 3
9
10
11 Introduction
12 ============
13
14 This document is a reference manual for the contents of PNaCl bitcode files. It
15 is presented using assembly language *PNaClAsm*. PNaClAsm uses a *static single
jvoung (off chromium) 2014/06/06 20:09:14 Perhaps mention that there are three layers up fro
Karl 2014/06/30 22:09:06 Good suggestion. Done.
16 assignment* (SSA) based representation that requires generated results to have a
17 single (assignment) source. PNaClAsm is the textual version of the bitcode file.
18
19 PNaClAsm focuses on the semantic content of the file, not the bit-encoding of
20 that content. However, it does provide annotations that allow one to specify how
21 the PNaCl bitcode writer converts the semantic content of a PNaClAsm program,
22 into a specific bit sequence.
23
24 Below PNaClAsm is the high-level form of the data stored in PNaCl bitcode
jvoung (off chromium) 2014/06/06 20:09:15 "Below PNaClAsm is the high-level..." Sounds a bi
Karl 2014/06/30 22:09:03 Decided to just call it the "textual" form.
25 files. Each construct in PNaClAsm defines a corresponding *PNaCl record* [ref].
26 A PNaCl bitcode file is simply a sequence of PNaCl records. The goal of PNaClAsm
27 is to make records easier to read, and not to define a high-level user
28 programming language.
29
30 PNaCl records are an abstract encoding of structured data, similar to XML. Like
31 XML, PNaCl records have a notion of tags (i.e. the first element in a record,
32 called a *code*), and nested structures. The nested structures are defined by
33 corresponding *enter* and *exit* block records.
34
35 These block records must be used like balanced parentheses to define the block
36 structure that is imposed on top of records. Each exit record must be preceded
37 by a corresponding enter record. Blocks can be nested by nesting enter/exit
38 records appropriately.
39
40 The *PNaCl bitcode writer* takes the sequence of records, defined by a PNaClAsm
41 program, and converts each record into a (variable) sequence of bits. The output
42 of each bit sequence is appended together. The resulting generated sequence of
43 bits is the contents of the PNaCl bitcode file.
44
45 For every kind of record, there is a default method for converting records into
46 bit sequences. These methods correspond to a notion of *abbreviations*
47 [ref]. Each abbreviation defines a specific bit sequence conversion to be
48 applied. The default conversion methods are simply predefined abbreviations.
49
50 The default abbreviations can be overridden with user-specified abbreviations.
51 All user-specified abbreviations are included in the generated bitcode
52 file. Each abbreviation defines how a record is converted to a bit sequences. Th e
Jim Stichnoth 2014/06/06 18:24:46 80-col either "to bit sequences" or "to a bit sequ
53 *PNaCl bitcode writer* uses these abbreviations to convert the corresponding
54 record sequence into a corresponding bit sequence. As a result, all records have
55 an abbreviation (user or default) associated with them.
56
57 The *PNaCl bitcode reader* then uses these abbreviations to convert the bit
58 sequences back into the corresponding records.
59
60 Conceptually, abbreviations are used to define how to pack the contents of
61 records into bit sequences. The main reason for defining abbreviations is to
62 save space. The default abbreviations are simplistic and are intended to handle
63 all possible records. The default abbreviations do not really worry about being
64 efficient, in terms of the number of bits generated.
65
66 By separating the concepts of PNaCl records and abbreviations, the notion of
67 data compression is cleanly separated from semantic content. This allows
68 different use cases to decide how much effort should be spent on compressing
69 records.
70
71 For a JIT compiler that produces bitcode, little (if any) compression should be
72 applied. In fact, the API to the JIT may just be the records themselves. The
73 goal of a JIT is to perform the final translation to machine code as quickly as
74 possible. On the other hand, when delivering across the web, one may want to
75 compress the sequence of bits considerably, to reduce costs in delivering web
76 pages.
77
78 Data Model
79 ==========
80
81 The data model for PNaCl bitcode is fixed at little-endian ILP32: pointers are
82 32 bits in size. 64-bit integer types are also supported natively via the i64
83 type (for example, a front-end can generate these from the C/C++ type *long
84 long*).
85
86 Integers are assumed to be modeled using two's complement. Floating point
87 support is fixed at IEEE 754 32-bit and 64-bit values (f32 and f64,
jvoung (off chromium) 2014/06/06 20:09:13 I think it's called "double" and "float" in the as
Karl 2014/06/30 22:09:06 Done.
88 respectively).
89
90
91 Identifiers
92 ===========
jvoung (off chromium) 2014/06/06 20:09:14 Feels a bit early to talk about identifiers. Shoul
Karl 2014/06/30 22:09:04 Good point. Moving after PNaCl blocks.
93
94 A program is defined as a sequence of top-level *blocks*. Blocks can be nested
95 within other blocks. Each block defines a sequence of records.
96
97 Most of the records, within a block, also define unique values. Each unique
98 value is given a corresponding unique identifier (i.e. *ID*). In PNaClAsm. each
99 kind of block defines its own kind of identifiers. The names of these
100 identifiers are defined by concatenating a prefix character ('@' or '%'), the
101 kind of block (a single character), and a suffix index. The suffix index is
102 defined by the positional location of the defined value within the records of
103 the corresponding block. The indices are all zero based, meaning that the first
104 defined value (within a block) is defined using index 0.
105
106 Identifiers are categorized into two types, *local* and *global*. Local
107 identifiers are identifiers that are associated with the implementation of a
108 single function. In that sense, they are local to the block they appear in.
109
110 All other identifiers are global. This split is intentional. Global identifiers
111 are used by multiple functions, and therefore must be known in all function
112 implementations. Local identifiers only apply to a single function, and can be
113 reused between functions. The *PNaCl translator* uses this separation to
114 parallelize the compilation of functions.
115
116 In general, global identifiers are tied to a specific type of block. Local ident ifiers
Jim Stichnoth 2014/06/06 18:24:50 80-col
117 are unique to the function block they appear in.
118
119 Local abbreviation identifiers are unique to the block they appear in. Global
120 abbreviation identifiers are only unique to the block type they are defined
121 for. Different block types can reuse global abbreviation identifiers.
122
123 Global identifiers use the prefix character *'@'* while local identifiers use
124 the prefix character *'%'*.
125
126 Note that by using positional location to define identifiers (within a block),
127 the values defined in PNaCl bitcode files need not be explicitly included in the
128 bitcode file. Rather, they are inferred by the (ordered) position of the record
129 in the block. This is also intentional. It is used to reduce the amount of data
130 that must be (explicitly) passed to the PNaCl translator, and downloaded though
131 the internet.
132
133 In general, most of the records within blocks are assumed to be topologically
134 sorted, putting value definitions before their uses. This implies that records
135 do not need to encode data if they can deduce the corresponding information from
136 their uses.
137
138 The most common use of this is that many instructions use the type of their
139 operands to determine the type of the instruction. Again, this is
140 intentional. It allows less information to be stored.
141
142 However, for function blocks (which define instructions), no topological sort
143 exists. Loop carried value dependencies simply do not allow topologically
144 sorting. To deal with this, function blocks have a notion of a forward
145 (instruction value) declaration. These declarations must appear before any of
146 the uses of that value, if the (instruction) value is defined later in the
147 function than its first use [ref - Forward type declarations].
148
149 The kinds of identifiers used in PNaClAsm are:
150
151 @a
152 Global abbreviation identifier.
153
154 %a
155 Block local abbreviation identifier.
156
157 %b
158 Function local basic block identifier.
159
160 %c
161 Function local constant identifier.
162
163 @f
164 Global function address identifier.
165
166 @g
167 Global variable/constant address identifier.
168
169 %p
170 Function local parameter identifier.
171
172 @t
173 Global type identifier.
174
175 %v
176 Function local instruction generated value identifier.
177
178 PNaCl Blocks
179 ============
180
181 Blocks are used to organize records in the bitcode file. The kinds of blocks
182 defined in PNaClAsm are:
183
184 Module block
185 A top-level block defining the program. This block defines global information
186 used by the program, followed by function blocks defining the implementation
187 of functions within the program.
188
189 Types block
190 Defines the set of types used by the program. All types used in the program
191 must be defined in this block. These types consist of primitive types as well
192 as high level constructs such as vectors and function signatures.
193
194 Globals block
195 Defines the set of global addresses of global variables and constants used by
196 the program. It also defines how each global (associated with the global
197 address) is initialized.
198
199 Valuesymtab block
200 Defines textual names for global and function addresses.
201
202 Function block
203 Each function (implemented) in a program has its own block that defines the
204 implementation of the corresponding function.
205
206 Constants block
207 Each implemented function, that uses constants in its instructions, defines a
208 constant block. Constants blocks appear within the corresponding function
209 block.
210
211 Abbreviations block
212 Defines global abbreviations that are used to compress PNaCl records. This
213 block is segmented into multiple sections, one section for each kind of
214 block. This block appears at the beginning of the module block.
215
216 This section is only intented as a high-level discussion of blocks. Later
Jim Stichnoth 2014/06/06 18:24:49 intended
Karl 2014/06/30 22:09:05 Done.
217 subsections will dive more deeply into the constraints on how blocks must be
218 layed out. This section only presents the overall concepts of what types of data
Jim Stichnoth 2014/06/06 18:24:49 laid
219 is stored in each of the modules.
Jim Stichnoth 2014/06/06 18:24:46 are stored
220
221 A PNaCl program consists of a header record and a module block. The header
222 defines a sequence of bytes uniquely identifying the file as a bitcode file. The
223 module block defines the program to run.
224
225 Each block, within a bitcode file, defines values. These values are associated
jvoung (off chromium) 2014/06/06 20:09:13 regarding the earlier comment about swapping the o
226 with IDs. Each type of block defines different kinds of IDs. The module, types,
227 globals, and abbreviations blocks define global identifiers, and only a single
228 instance can appear. The function and constant blocks define local identifiers,
229 and can have mlutiple instances (one for each implemented function).
Jim Stichnoth 2014/06/06 18:24:48 multiple
jvoung (off chromium) 2014/06/06 20:09:15 multiple
230
231 Each *function block* [ref] defines the implementation of a single
232 function. Each function block defines the intermediate representation of the
233 function, consisting of basic blocks and instructions. If constants are used
234 within instructions, they are defined in a *constants block*, nested within the
235 corresponding function block.
236
237 All function blocks are associated with a corresponding function address. This
238 association is (again) positional rather than explicit. That is, the Nth
239 function block in a module block corresponds to the Nth defining (rather than
240 declared) function address record in the module block.
241
242 Hence, within a function block, there is no explicit reference to the
243 function address the block defines. For readability, PNaClAsm uses the
244 corresponding function heading, associated with the corresponding
245 function address record, even though that data does not appear in the
246 corresponding records.
247
248 PNaCl Records
249 =============
250
251 A PNaCl record is a non-empty sequence of unsigned, 64-bit, integers. A record
252 is identified by the record *code*, which is the first element in the
253 sequence. Record codes are unique within a specific kind of block, but are not
254 necessarily unique across different kinds of blocks. The record code acts as the
255 variant discriminator (i.e. tag) within a block, to identify what kind of record
256 it is.
257
258 Record codes that are local to a specific kind of block are small values
259 (staring from zero). In an ideal world, they would be a consecutive sequence of
Jim Stichnoth 2014/06/06 18:24:49 starting
Karl 2014/06/30 22:09:04 Done.
260 integers, starting at zero. However, the reality is that PNaCl records evolved
261 over time (and actually started as LLVM records [ref]). For backwards
262 compatibility, old numbers have not been reused, leaving gaps in the actual
263 record code values used.
264
265 Global record codes are record codes that have the same meaning in multiple
266 kinds of block. To separate global record codes from local record codes, large
267 values are used. Currently there are four global record codes. To make these
268 cases clear, and to leave room for lots of future growth in PNaClAsm, these
269 special records have record codes close to the value 2**16. Note: Well-formed
270 PNaCl bitcode files do not have record codes >= 2**16.
271
272 A PNaCl record is denoted as follows:
273
274 .. naclcode::
275
276 a: <v0, v1, ... , vN>
277
278 The value *v0* is the record code. The remaining values, *v1* through *vN*, are
279 parameters that fill in additional information needed by the construct it
280 represents. All records must have a record code. Hence, empty PNaCl records are
281 not allowed.
282
283 While most records (for a given record code) are of the same length, it is not
284 true of all record codes. Some record codes can have arbitrary length. In
285 particular, function type signatures, call instructions, phi nodes, switch
286 instructions, and global variable initialization records all have variable
287 length.
jvoung (off chromium) 2014/06/06 20:09:14 Should this reference a section that describes how
Karl 2014/06/30 22:09:04 Added a couple of sentences trying to clarify this
288
289 Records are converted to bit sequences using an abbreviation. Let *a* the the in dex
Jim Stichnoth 2014/06/06 18:24:50 the the --> be the also, 80-col
Karl 2014/06/30 22:09:05 Removed paragraph. presented too early to be usefu
290 identifying the abbreviation that is used to convert the record to a sequence of
291 bits. If a user-defined abbreviation *%aA* (or *@aA* if global) is specified in
292 the syntax, then *a = AbbrevIndex(%aA)*.
293
294 The PNaCl bitcode writer, which converts records to bit sequences, does this by
295 writing out the abbreviation index used to encode the record, followed by the
296 contents of the record. The details of this are left to section on abbreviations
Jim Stichnoth 2014/06/06 18:24:47 to section --> to the section (though this will pr
Karl 2014/06/30 22:09:03 Done.
297 [ref]. However, at the record level, one important aspect of this appears in
298 block enter records. These records must define how many bits are required to
299 hold abbreviation indices associated with records of that block.
300
301 There are 4 predefined (default) abbreviation indices, used as the default
302 abbreviations for PNaCl records. They are:
303
304 0
305 Abbreviation index for the abbreviation used to bit-encode an exit block
306 record.
307
308 1
309 Abbreviation index for the abbreviation used to bit-encode a enter block
Jim Stichnoth 2014/06/06 18:24:47 a enter --> an enter
Karl 2014/06/30 22:09:04 Done.
310 record.
311
312 2
313 Abbreviation index for the abbreviation used to bit-encode a user-defined
jvoung (off chromium) 2014/06/06 20:09:14 I don't know if it's too redundant, or clear as is
Karl 2014/06/30 22:09:04 I agree this isn't obvious. Added a sentence to he
314 abbreviation record.
315
316 3
317 Abbreviation index for the default abbreviation to bit-encode all other
318 records in the bitcode file.
319
320 A block may (in addition), define a list of block specific, user-defined,
321 abbreviations (of length *U*). The number of bits *B* specified for an enter
322 record must be sufficiently large such that
323
324 .. naclcode::
325
326 2**B >= U + 4
327
328 In addition, the upper limit for B is 32.
329
330 PNaClAsm requires that you specify the number of bits needed to read
331 abbreviations as part of the enter block record. This allows the PNaCl bitcode
332 reader/writer to use the specified number of bits to encode abbreviation
333 indices.
334
335 Conventions for describing records
jvoung (off chromium) 2014/06/06 20:09:14 nit: consistency in capitalization of section head
336 ==================================
337
338 PNaClAsm is the textual representation of PNaCl records. Each PNaCl record is
339 described by a corresponding PNaClAsm construct. These constructs are described
340 using syntax rules, and semantics on how they are converted to records. The
jvoung (off chromium) 2014/06/06 20:09:14 This is the first time "the parser" is mentioned.
Karl 2014/06/30 22:09:04 Tried to clear up that there is "global" state tha
341 parser also has state, that is updated after the record is processed. These
Jim Stichnoth 2014/06/06 18:24:49 either "state that" or "state, which"
342 state updates are part of the semantics of the corresponding record construct.
343
344 For each PNaCl construct, we define multiple subsections. The **Syntax**
345 subsection defines a syntax rule for the construct. The **Record** subsection
346 defines the corresponding record associated with the syntax rule. The
347 **Semantics** subsection describes the semantics associated with the record, in
348 terms of data within the parse state and the corresponding syntax. It also
349 includes other high-level semantics, when appropriate.
350
351 The **Constraints** subsection (if present) defines any constraints associated
352 with the construct. The **Updates** subsection (if present) defines how the
353 parse state is updated when the construct is parsed. The **Examples**
354 subsection gives one (or more) examples of using the corresponding PNaClAsm
355 construct.
356
357 Some semantics subsections use functions to compute values. The meaning of
358 functions can be found in *Support Functions* [ref].
359
360 Within a syntax rule, there may specifications about abbreviations. These
jvoung (off chromium) 2014/06/06 20:09:14 "there may be specifications" ?
361 abbreviation specifications, if allowed, are at the end of the construct, and
362 enclosed in *<* and *>* brackets. These abbreviation specifications are optional
363 in the syntax, and can be omitted. If they are used, the abbreviation brackets
364 are part of the actual syntax of the construct. To make it clear that
365 abbreviation specifications are optional, syntax rules separate abbreviation
366 specifications using plenty of whitespace.
367
368 Abbreviation specifications consist of user-defined abbreviations, abbreviation
369 identifiers, and the number of bits required to represent abbreviations in a
370 block. These notations appear, as appropriate, in the corresponding syntax
371 rules.
372
373 The most common abbreviation syntax is the corresponding abbreviation identifier
374 to use to read/write the corresponding record. In such cases, if the specified
375 abbreviation identifier is omitted, the corresponding default abbreviation will
376 be used by the PNaCl reader/writer.
377
378 Also, within the syntax rule, all alphabetic characters are lower case unless
379 they appear within a literal value. Hence, if we mix lower and upper case
380 letters within a name appearing in a syntax rule, the lower case letters are
381 literal while the upper case sequence of letters denote (rule specific)
jvoung (off chromium) 2014/06/06 20:09:13 Earlier "all alphabetic characters are lower case
Karl 2014/06/30 22:09:04 Rewrote. Hopefully clarified.
382 values. If an upper case sequence of letters is followed by digits, the
383 corresponding embedded name includes both the upper case letters and the digits.
384 The valid values for each of these names will be defined in the corresponding
385 semantics subsection.
386
387 For example, consider the following syntax rule:
388
389 .. naclcode::
390
391 %vN = add T O1, O2; <A>
392
393 This rule defines a PNaClAsm add instruction. This construct defines an
394 instruction that adds two values (*O1* and *O2*) to generate instruction
395 value *%vN*. The types of the arguments, and the result, are all of type
396 *T*. Since abbreviation ID *A* is present, the record is encoded using that
397 abbreviation.
398
399 To be concrete, the syntactic rule above defines the structure of the following
400 PNaClAsm examples.
401
402 .. naclcode::
403
404 %v10 = add i32 %v1, %v2; <@a5>
405 %v11 = add i32 %v10, %v3;
406
407 In addition to specifying the syntax, each syntax rule also specifies the
408 contents of the corresponding record in the corresponding record subsection. In
409 simple cases, the elements of the corresponding record are predefined (literal)
410 constants. Otherwise the record element is a name that is defined by the other
411 subsections associated with the construct.
412
413 Factorial Example
414 =================
415
416 This section provides a simple example of a PNaCl bticode file. Its contents
Jim Stichnoth 2014/06/06 18:24:49 bitcode
Karl 2014/06/30 22:09:04 Done.
417 describes a bitcode file that only defines a function to compute the factorial
Jim Stichnoth 2014/06/06 18:24:47 describe
418 value of a number.
419
420 In C, the factorial function can be defined as:
421
422 .. naclcode::
423
424 int fact(int n) {
425 if (n == 0) return 1;
426 return n * fact(n-1);
427 }
428
429 Compiling this into a PEXE file, and dumping out its contents with utility
Jim Stichnoth 2014/06/06 18:24:48 Just checking - are we calling this a PEXE file in
Karl 2014/06/30 22:09:04 Good point. I should call it the bitcode file, not
430 *pnacl-bcdis*, the corresponding output is:
431
432 .. naclcode::
433
434 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, 88, 69)
435 | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2
436 | 0> |
437 16:0|1: <65535, 8, 3> |module { // BlockID = 8
438 24:0| 3: <1, 1> | version 1;
439 26:5| 1: <65535, 0, 2> | abbreviations { // BlockID = 0
440 36:0| 0: <65534> | }
441 40:0| 1: <65535, 17, 4> | types { // BlockID = 17
jvoung (off chromium) 2014/06/06 20:09:13 Abbrev index bitwidth says "4", even though no use
Karl 2014/06/30 22:09:05 Thanks for noting this. I didn't realize that we s
442 48:0| 3: <1, 4> | count 4;
443 50:6| 3: <7, 32> | @t0 = i32;
444 54:2| 3: <2> | @t1 = void;
445 56:2| 3: <21, 0, 0, 0> | @t2 = i32 (i32);
446 60:4| 3: <7, 1> | @t3 = i1;
447 63:2| 0: <65534> | }
448 64:0| 3: <8, 2, 0, 0, 0> | define external i32 @f0(i32);
449 68:7| 1: <65535, 19, 4> | globals { // BlockID = 19
450 76:0| 3: <5, 0> | count 0;
451 78:6| 0: <65534> | }
452 80:0| 1: <65535, 14, 4> | valuesymtab { // BlockID = 14
453 88:0| 3: <1, 0, 102, 97, 99, | @f0 : "fact";
454 | 116> |
455 96:6| 0: <65534> | }
456 100:0| 1: <65535, 12, 5> | function i32 @f0(i32 %p0) {
457 | | // BlockID = 12
458 108:0| 3: <1, 3> | blocks 3;
459 110:7| 1: <65535, 11, 4> | constants { // BlockID = 11
460 120:0| 3: <1, 0> | i32:
461 122:6| 3: <4, 2> | %c0 = i32 1;
462 125:4| 3: <4, 0> | %c1 = i32 0;
463 128:2| 0: <65534> | }
464 | | %b0:
465 132:0| 3: <28, 1, 2, 32> | %v0 = icmp eq i32 %c1, %c0;
466 137:1| 3: <11, 1, 2, 1> | br i1 %v0, %b1, %b2;
467 | | %b1:
468 141:4| 3: <10, 3> | ret i32 %c0;
469 | | %b2:
470 144:3| 3: <2, 4, 3, 1> | %v1 = sub i32 %p0, %c0;
471 148:6| 3: <34, 0, 6, 1> | %v2 = call i32 @f0(i32 %p0);
472 153:7| 3: <2, 6, 1, 2> | %v2 = mul i32 @f0, %v1;
473 158:2| 3: <10, 1> | ret i32 %v2;
474 161:1| 0: <65534> | }
475 164:0|0: <65534> |}
476
477
478 Note that there are three columns in this output. The first column contains the
479 bit positions of the records within the bitcode file. The second column contains
480 the sequence of records within the bitcode file. The third column contains the
481 corresponding PNaClAsm program.
482
483 Bit positions are defined by a pair *B:N*. *B* is the number of bytes, while *N*
484 is the bit offset within the *B+1* byte. Hence, the bit position (in bits) is:
485
486 .. naclcode::
487
488 B*8 + N
489
490 Hence, the first *header* record is at bit offset 0 (0*8+0). The second record
491 is at bit offset 128 (16*8+0). The third record is at bit offset 192 (24*8+0).
492 The fourth record is at bit offset 213 (26*8+5).
493
494 The header record is a sequence of 16 bytes, defining the contents of the first
495 16 bytes of the bitcode file. The first four bytes define the magic number of
496 the file. That is, 'PEXE'. All PEXE bitcode files begin with these four bytes.
Jim Stichnoth 2014/06/06 18:24:50 the file, i.e. 'PEXE'.
Karl 2014/06/30 22:09:03 Done.
497 Byte 13 defines the PNaCl bitcode version of the file. Currently, only version 2
jvoung (off chromium) 2014/06/06 20:09:13 Only byte 13, or byte 13, 14, 15, and 16?
Karl 2014/06/30 22:09:06 Simplified this to just state they shouldn't chang
498 is allowed.
jvoung (off chromium) 2014/06/06 20:09:14 What about the bytes in between (5 through 12)? Co
Karl 2014/06/30 22:09:06 Done.
499
500 All but the header record has an abbreviation index associated with it. Since no
501 user-defined abbreviations are provided, all records use the default
502 abbreviation.
503
504 The types block (starting at bit address 40:0), defines 4 types: *i1*, *i32*,
505 *void*, and function signature *i32(i32)*.
506
507 Bit address 64:0 declares the factorial function address @f0, and its
508 corresponding type signature. Bit address 88:0 associates the name "fact" with
509 function address @f0.
510
511 Bit address 100:0 defines the function block that implemnts function "fact". The
Jim Stichnoth 2014/06/06 18:24:47 implements
512 entry point is %b0 (at bit address 132:0). It uses the 32-bit integer constants
513 1 and 0 (defined at bit addresses 122:6 and 125:4). Bit address 132:0 defines an
514 equality comparison of the argument %p0 with 0 (constant %c1). Bit address 137:1
515 defines a conditional branch. If the result of the previous comparison (%v0) is true,
Jim Stichnoth 2014/06/06 18:24:46 80-col
516 the program will branch to block %b1. Otherwise it will branch to block %b2.
517
518 Bit address 141:4 returns constant 1 (%c0) when the input parameter is 0.
519 Instructions between bit address 144:3 and 158:2 compute and return "n *
520 fact(n-1)".
jvoung (off chromium) 2014/06/06 20:09:13 The second column isn't really described in this e
Karl 2014/06/30 22:09:05 yes.
521
522 Parse State
523 ===========
524
525 This section describes the parse state of the PNaClAsm assembler. It is used to
526 define contextual data that is carried between records. The following
527 subsections describe each element of the parse state.
528
529 Typing
530 ------
531
532 Associated with most identifiers is a type. This type defines what type the
533 corresponding value has. It is defined by the (initially empty) map
534
535 .. naclcode::
536
537 TypeOf: ID -> Type
538
539 For each type in the *types block* [ref], a corresponding inverse map
540
541 .. naclcode::
542
543 TypeID: Type -> ID
544
545 is maintained to convert syntactic types to the corresponding type ID.
546
547 Note: This document assumes that map *TypeID* is automatically maintained during
548 updates to map *TypeOf* (when given a type ID). Hence, *updates* subsections
549 will not contain assignments to this map.
550
551 Associated with each function identifier is its type signature. This is
552 different than the type of the function identifier, since function identifiers
jvoung (off chromium) 2014/06/06 20:09:14 would it help to say that "..., since function ide
Karl 2014/06/30 22:09:02 Done.
553 are pointers (and always implemented as a 32-bit integer).
554
555 Function type signatures are maintained using:
556
557 .. naclcode::
558
559 TypeOfFcn: ID -> Type
560
561 In addition, if a function address has an implementing block, there is a
562 corresponding implementation associated with the function address. To capture
563 this association, we use the set:
564
565 .. naclcode::
566
567 DefiningFcnIDs: set(ID)
568
569 ID Counters
570 -----------
571
572 Each block defines one (or more) kinds of values. Value indices are generated
573 sequentially, starting at zero. To capture this, the following counters are
574 defined:
575
576 NumTypes
577 The number of types defined so far (in the types block)
578
579 NumFuncAddresses
580 The number of function addresses defined so far (in the module block).
581
582 NumDefinedFcnAddresses
jvoung (off chromium) 2014/06/06 20:09:14 How is this different from NumFuncAddresses? Updat
Karl 2014/06/30 22:09:04 These are two different values. Added additional s
583 The number of defining function addresses defined so far (in the module
584 block).
585
586 NumFuncImpls
587 The number of implemented functions defined so far (in the module block).
588
589 NumGlobalAddresses
590 The number of global variable/constant addresses defined so far (in the
591 globals block).
592
593 NumParams
594 The number of parameters defined for a function.
595
596 NumFcnConsts
597 The number of constants defined in a function.
jvoung (off chromium) 2014/06/06 20:09:13 so far? Depends on how you define the update rule
Karl 2014/06/30 22:09:03 Done.
598
599 NumBasicBlocks
600 The number of basic blocks defined so far (within a function block).
601
602 NumValuedInsts
603 The number of instructions, generating values, defined so far (within a
604 function block).
605
606 Size Variables
607 --------------
608
609 A number of blocks define expected sizes of constructs. These sizes are recorded
610 in the following size variables:
611
612 ExpectedBasicBlocks
613 The expected number of basic blocks within a function implementation.
614
615 ExpectTypes
616 The expected number of types defined in the types block.
617
618 ExpectedGlobals
619 The expected number of global variable/constant addresses in the globals
620 block.
621
622 ExpectedInitializers
623 The expected number of initializers for a global variable/constant address in
624 the globals block.
625
626 Other Variables
627 ---------------
628
629 EnclosingFcnID
630 The function ID of the function block being processed.
631
632 Global records
633 ==============
634
635 There are four global PNaCl records, each having its own record code. These
636 global records are:
637
638 Header
639 The header record is the first record of a PNaCl bitcode file, and identifies
640 the file's magic number, as well as the bitcode version it uses. The record
641 defines the sequence of bytes that make up the header and uniquely identifies
642 the file as a PNaCl bitcode file.
643
644 Enter
645 An enter record defines the beginning of a block. Since blocks can be nested,
646 one can appear inside other blocks, as well as at the top level.
647
648 Exit
649 An exit record defines the end of a block. Hence, it must appear in every
650 block, to end the block.
651
652 Abbreviation
653 An abbreviation record defines a user-defined abbreviation to be applied to
654 records within blocks. Abbreviation records appearing in the abbreviations
655 block define global abbreviations. All other abbreviations are local to the
656 block they appear in, and can only be used in that block.
657
658 All special records can't have user-defined abbreviations associated with
659 them. The default abbreviation is always used.
660
661 The following subsections define valid special records, other than abbreviation
662 records. Abbreviation records are described in the Abbreviations [ref] section.
663
664 Header Record
665 -------------
666
667 The header record must be the first record in the file. It is the only record in
668 the bitcode file that doesn't have a corresponding construct in
669 PNaClAsm.
670
671 **Syntax**
672
673 There is no syntax for header records in PNaClAsm. It is automatically inserted
674 by the PNaCl bitcode writer.
675
676 **Record**
677
678 .. naclcode::
679
680 <65532, 80, 69, 88, 69, 1, 0, 8, 0, 17, 0, 4, 0, 2, 0, 0, 0>
681
682 **Semantics**
683
684 The header record defines the initial sequence of bytes that must appear at the
685 beginning of all (PNaCl bitcode version 2) files. That sequence is the list of
686 bytes inside the record (excluding the record code). As such, it uniquely
687 identifies PNaCl bitcode files.
688
689 **Examples**
690
691 There are no examples for the header record, since it is not part of PNaClAsm.
692
693 Enter Block Record
694 ------------------
695
696 Block records can be top-level, as well as nested in other blocks. Blocks must
697 begin with an *enter* record, and end with an *exit* record.
698
699 **Syntax**
700
701 .. naclcode::
702
703 N { <B>
704
705 **Record**
706
707 .. naclcode::
708
709 1: <65535, ID, B>
710
711 **Semantics**
712
713 Enter block records define the beginning of a block. *B*, if present, is the
714 number of bits needed to represent all possible abbreviation indices used within
715 the block. If omitted, B=2 is assumed.
716
717 The block *ID* value is dependent on the name *N*. Valid names and corresponding
718 *BlockID* values are defined as follows:
719
720 ============= ========
721 N Block ID
722 ============= ========
723 abbreviations 0
724 constants 11
725 function 12
726 globals 19
727 module 8
728 types 17
729 valuesymtab 14
730 ============= ========
731
732 Note: For readability, PNaClAsm allows a more readable form of a function block
733 enter record. See *function blocks* [ref] for more details.
734
735 **Examples**
736
737 .. naclcode::
738
739 module {
740 types {
741 count: 0;
742 }
743 globals {
744 count: 0;
745 }
746 }
747
748 This example defines a module, types, and globals block. Both the type and the
749 globals block appear within the module block.
750
751 The corresponding records are:
752
753 .. naclcode::
754
755 1: <65535, 8, 2>
756 1: <65535, 17, 2>
757 3: <1, 0>
758 0: <65534>
759 1: <65535, 19, 2>
760 3: <5, 0>
761 0: <65534>
762 0: <65534>
763
764 Exit Block Record
765 -----------------
766
767 Block records can be top-level, as well as nested, records. Blocks must begin
768 with an *enter* record, and end with an *exit* record.
769
770 **Syntax**
771
772 .. naclcode::
773
774 }
775
776 **Record**
777
778 .. naclcode::
779
780 0: <65534>
781
782 **Semantics**
783
784 All exit records are identical, no matter what block they are ending. An exit
785 record defines the end of the block.
786
787 **Examples**
788
789 .. naclcode::
790
791 module {
792 types {
793 count: 0;
794 }
795 globals {
796 count: 0;
797 }
798 }
799
800 This example defines a module, types, and globals block. Both the type and the
801 globals block appear within the module block.
802
803 The corresponding records are:
804
805 .. naclcode::
806
807 1: <65535, 8, 2>
808 1: <65535, 17, 2>
809 3: <1, 0>
810 0: <65534>
811 1: <65535, 19, 2>
812 3: <5, 0>
813 0: <65534>
814 0: <65534>
815
jvoung (off chromium) 2014/06/06 20:09:14 Description for the remaining global record (abbre
Karl 2014/06/30 22:09:04 This was already stated in the enclosing section.
816 Types Block
817 ===========
818
819 The types block defines all types used in a program. It must appear in the
820 module block, before any function address records, the globals block, the
821 valuesymtab block, and any function blocks.
822
823 All types used in a program must be defined in the types block. Many PNaClAsm
824 constructs allow one to use explicit type names, rather than the type
825 identifiers defined by this block. However, they are internally converted to the
826 corresponding type identifer in the types block. Hence, the requirement that the
827 types block must appear early in the module block.
828
829 Each record in the types block defines a type used by the program. Types can be
830 broken into the following groups:
831
832 Primitive Value types
833 Defines the set of base types for values. This includes various sizes of
834 integral and floating types.
835
836 Void type
837 A primitive type that doesn't represent any value and has no size.
838
839 Function types
840 The type signatures of functions.
841
842 Vector type
843 Defines vectors of primitive types.
844
845 In addition, any type that is not defined using another type is a primitive
846 type. All other types (i.e. function and vector) are composite types.
847
848 Types must be defined in a topological order, causing primitive types to appear
849 before the composite types that use them. Each type must be unique. There are no
850 additional restrictions on the order that types can be defined in a types block.
851
852 The following subsections introduce each valid PNaClAsm type, and the
853 corresponding PNaClAsm construct that defines the type. Types not defined in the
854 types block, can't be used in a PNaCl program.
855
856 The first record of a types block must be a *count* record, defining how many
857 types are defined by the types block. All remaining records defines a type. The
858 following subsections define valid records within a types block. The order of
859 type records is important. The position of each defining record implicitly
860 defines the type ID that will be used to denote that type, within other PNaCl
861 records of the bitcode file.
862
863 To make this more concrete, consider the following example types block:
864
865 .. naclcode::
866
867 types {
868 count: 4;
869 @t0 = void;
870 @t1 = i32;
871 @t2 = float;
872 @t3 = void (i32, float);
873 }
874
875 This example defines a types block that defines four type IDs:
876
877 0. The void type.
878 1. A 32-bit integer type.
879 2. A 32-bit floating type.
880 3. A function, taking 32-bit integer and float arguments that returns void.
881
882 Note that the order defines the corresponding identifier that will be used for
883 that type, and is based on the position of the type within the types
884 record. Hence, the assignment to identifier *@tN* can never appear before the
885 assignment to identifier *@tN-1*. Further, if type identifier *@tN* is assigned,
886 it must appear immediately after the assignment to identifier *@tN-1*.
887
888 Count Record
889 ------------
890
891 The *count record* defines how many types are defined in the types
892 block. Following the types count record are records that define types used by
893 the PNaCl program.
894
895 **Syntax**
896
897 .. naclcode::
898
899 count: N; <A>
900
901 **Record**
902
903 AA: <1, N>
904
905 **Semantics**
906
907 This construct defines the number of types used by the PNaCl program. *N* is
908 the number of types defined in the types block. It is an error to define more
909 (or fewer) types than value *N*, within the enclosing types block. *A* is the
910 (optional) abbreviation associated with the record.
911
912 **Constraints**
913
914 .. naclcode::
915
916 AA == AbbrevIndex(A)
917 0 == NumTypes
918
919 **Updates**
920
921 .. naclcode::
922
923 ExpectedTypes = N;
924
925 **Examples**
926
927 .. naclcode::
928
929 types {
930 count: 2;
931 @t0 = float;
932 @t1 = i32;
933 }
934
935 This example defines two types. A 32 bit integer and a 32 bit floating types.
936 The corresponding records are:
937
938 .. naclcode::
939
940 1: <65535, 17, 2>
941 3: <1, 2>
942 3: <3>
943 3: <7, 32>
944 0: <65534>
945
946 Void Type
947 ---------
948
949 The *void* type record defines the void type, which corresponds to the type that
950 doesn't define any value, and has no size.
951
952 **Syntax**
953
954 .. naclcode::
955
956 @tN = void; <A>
957
958 **Record**
959
960 .. naclcode::
961
962 AA: <2>
963
964 **Semantics**
965
966 The void type record defines the type that has no values and has no size. *A*
967 is the (optional) abbreviation associated with the record.
968
969 **Constraints**
970
971 .. naclcode::
972
973 AA == AbbrevIndex(A)
974 N == NumTypes
975 NumTypes < ExpectedTypes
976
977 **Updates**
978
979 .. naclcode::
980
981 ++NumTypes;
982 TypeOf(@tN) = void;
983
984 **Examples**
985
986 .. naclcode::
987
988 @t0 = void;
989
990 defines the record
991
992 .. naclcode::
993
994 3: <2>
995
996 Integer Types
997 -------------
998
999 PNaClAsm allows integral types for various bit sizes. Valid bit sizes are 1, 8,
1000 16, 32, and 64. Integers can be signed or unsigned, but the signed component of
1001 an integer is not specified by the type. Rather, individual instructions
1002 determine whether the value is assumed to be signed or unsigned.
1003
1004 It should be noted that in PNaClAsm, all pointers are implemented as 32-bit
1005 (unsigned) integers. There isn't a separate type for pointers. The only way to
1006 tell that a 32-bit integer is a pointer, is when it is used in an instruction
1007 that requires a pointer (such as load and store instructions).
1008
1009 **Syntax**
1010
1011 .. naclcode::
1012
1013 @tN = iB; <A>
1014
1015 **Record**
1016
1017 AA: <7, B>
1018
1019 **Semantics**
1020
1021 An integer type record defines an integral type. *B* defines the number of bits
1022 of the integral type. *A* is the (optional) abbreviation associated with the
1023 record.
1024
1025 **Constraints**
1026
1027 .. naclcode::
1028
1029 AA == AbbrevIndex(A)
1030 N == NumTypes
1031 NumTypes < ExpectedTypes
1032 B in {1, 8, 16, 32, 64}
1033
1034 **Updates**
1035
1036 .. naclcode::
1037
1038 ++NumTypes;
1039 TypeOf(@tN) = iB;
1040
1041 **Examples**
1042
1043 .. naclcode::
1044
1045 @t1 = i32;
1046 @t2 = i1;
1047 @t3 = i64;
1048
1049 defines the records
1050
1051 .. naclcode::
1052
1053 3: <7, 32>
1054 3: <7, 1>
1055 3: <7, 64>
1056
1057 32-Bit Floating Type
1058 --------------------
1059
1060 PNaClAsm allows computation on 32-bit floating values. A floating type record
jvoung (off chromium) 2014/06/06 20:09:13 "floating type record" --> "float type record" ?
1061 defines the 32-bit floating type.
1062
1063 **Syntax**
1064
1065 .. naclcode::
1066
1067 @tN = float; <A>
1068
1069 **Record**
1070
1071 .. naclcode::
1072
1073 AA: <3>
1074
1075 **Semantics**
1076
1077 A floating type record defines the 32-bit floating type. *A* is the (optional)
1078 abbreviation associated with the record.
1079
1080 **Constraints**
1081
1082 .. naclcode::
1083
1084 AA == AbbrevIndex(A).
1085 N == NumTypes
1086 NumTypes < ExpectedTypes
1087
1088 **Updates**
1089
1090 .. naclcode::
1091
1092 ++NumTypes;
1093 TypeOf(@tN) = float;
1094
1095 **Examples**
1096
1097 .. naclcode::
1098
1099 @t5 = float;
1100
1101 defines the record
1102
1103 .. naclcode::
1104
1105 3: <3>
1106
1107 64-bit Floating Type
1108 --------------------
1109
1110 PNaClAsm allows computation on 64-bit floating values. A double type record
1111 defines the 64-bit floating type.
1112
1113 **Syntax**
1114
1115 .. naclcode::
1116
1117 @tN = double; <A>
1118
1119 **Record**
1120
1121 .. naclcode::
1122
1123 AA: <4>
1124
1125 **Semantics**
1126
1127 A double type record defines the 64-bit floating type. *A* is the (optional)
1128 abbreviation associated with the record.
1129
1130 **Constraints**
1131
1132 .. naclcode::
1133
1134 AA == AbbrevIndex(A)
1135 N == NumTypes
1136 NumTypes < ExpectedTypes
1137
1138 **Updates**
1139
1140 .. naclcode::
1141
1142 ++NumTypes;
1143 TypeOf(@tN) = double;
1144
1145 **Examples**
1146
1147 .. naclcode::
1148
1149 @t3 = double;
1150
1151 defines the record
1152
1153 .. naclcode::
1154
1155 3: <4>
1156
1157 Vector Types
1158 ------------
1159
1160 TODO(kschimpf) <N x T>
1161
1162 TODO(kschimpf) Define integral and floating vector types.
1163
1164 Function Type
1165 -------------
1166
1167 The *function* type can be thought of as a function signature. It consists of a
1168 return type, and a (possibly empty) list of formal parameter types.
1169
1170 **Syntax**
1171
1172 .. naclcode::
1173
1174 %tN = RT (T1, ... , TM) <A>
1175
1176 **Record**
1177
1178 .. naclcode::
1179
1180 AA: <21, 0, IRT, IT1, ... , ITM>
1181
1182 **Semantics**
1183
1184 The function type defines the signature of a function. *RT* is the return type
1185 of the function, while types *T1* through *TM* are the types of the
1186 arguments. Indicies to the corresponding type identifiers is stored in the
Jim Stichnoth 2014/06/06 18:24:48 are stored
Jim Stichnoth 2014/06/06 18:24:48 Indices
Karl 2014/06/30 22:09:03 Done.
Karl 2014/06/30 22:09:06 Done.
1187 corresponding record.
1188
1189 The return value must either be a primitive type, type *void*, or a vector type.
1190 Parameter types can be a primitive or vector type.
1191
1192 For the integral types, only i32 and i64 can be used for a return or parameter
1193 type. All other integral types are not allowed.
1194
1195
1196 **Constraints**
1197
1198 .. naclcode::
1199
1200 AA = AbbrevIndex(A)
1201 M >= 0
1202 IRT = AbsoluteIndex(TypeID(RT))
1203 IT1 = AbsoluteIndex(TypeID(T1))
1204 ...
1205 ITM = AbsoluteIndex(TypeID(TM))
1206 N == NumTypes
1207 NumTypes < ExpectedTypes
1208
1209 **Updates**
1210
1211 .. naclcode::
1212
1213 ++NumTypes;
1214 TypeOf(@tN) = RT (T1, ... , TM)
1215
1216 **Examples**
1217
1218 The following example defines two function signatures (*@t4* and *@t5*):
1219
1220 .. naclcode:
1221
1222 types {
1223 count: 6;
1224 @t0 = i32;
1225 @t1 = i64;
1226 @t2 = float;
1227 @t3 = void;
1228 @t4 = void (i32, float, i64);
1229 @t5 = i32();
1230 }
1231
1232 The corresponding records are:
1233
1234 .. naclcode::
1235
1236 1: <65535, 17, 2>
1237 3: <1, 6>
1238 3: <7, 32>
1239 3: <7, 64>
1240 3: <3>
1241 3: <2>
1242 3: <21, 3, 0, 2, 1>
1243 3: <21, 0>
1244 0: <65534>
1245
1246 Globals block
1247 =============
1248
1249 The globals block defines global addresses of variables and constants, used by
1250 the PNaCl program. It also defines the memory associated with the global
1251 addresses, and how to initialize each global variable/constant. It must appear
1252 in the module block. It must appear after the types block, as well as after all
1253 function address records. But, it must also appear before the valuesymtab block,
1254 and any function blocks.
1255
1256 The globals block begins with a count record, defining how many global addresses
1257 are defined by the PNaCl program. It is then followed by a sequence of records
1258 that defines how each global address is initialized.
1259
1260 The standard sequence, for defining global addresses, begins with a global
1261 address record. It is then followed by a sequence of records defining how the
1262 global address is initialized. If the initializer is simple, a single record is
1263 used. Otherwise, the initializer is preceded with a compound record, specifying
1264 a number *N*, followed by sequence of *N* simple initializer records.
1265
1266 The size of the memory referenced by each global address is defined by its
1267 initializer records. All simple initializer records define a sequence of
1268 bytes. A compound initializer defines the sequence of bytes by concatenating the
1269 corresponding sequence of bytes for each of its simple initializer records.
1270
1271 For notational convenience, PNaClAsm begins a compound record with a "{", and
1272 inserts a "}" after the last initializer record associated compound record. This
1273 latter "}" does not correspond to any record. It is implicitly assumed by the
1274 size specified in the compound record, and is added only to improve readability.
1275
1276 Explicit alignment is specified for global addresses, and must be a power
1277 of 2. If the alignment is 0, the alignment of the global is set by the target to
1278 whatever it feels convenient. If the value is greater than zero, the global is
1279 forced to have exactly that alignment.
1280
1281 For example, consider the following:
1282
1283 .. naclcode::
1284
1285 globals {
1286 count: 2;
1287 const @g0 =
1288 zerofill 8;
1289 var @g1 =
1290 initializers 2 {
1291 {1, 2, 3, 4},
1292 zerofill 2;
1293 }
1294 }
1295
1296
1297 TODO: Generate a pnacl-dis output to show relationship?
1298
1299 The corresponding records are:
1300
1301 .. naclcode::
1302
1303 1: <65535, 19, 2>
1304 3: <5, 2>
1305 3: <0, 0, 1>
1306 3: <2, 8>
1307 3: <0, 0, 0>
1308 3: <1, 2>
1309 3: <3, 1, 2, 3, 4>
1310 3: <2, 2>
1311 0: <65534>
1312
1313 Count Record
1314 ------------
1315
1316 The count record defines the number of global addresses used by the PNaCl
1317 program.
1318
1319 **Syntax**
1320
1321 .. naclcode::
1322
1323 count: N; <A>
1324
1325 **Record**
1326
1327 .. naclcode::
1328
1329 AA: <5, N>
1330
1331 **Semantics**
1332
1333 This record must appear first in the globals block. The count record defines
1334 the number of global addresses used by the program. *A* is the (optional)
1335 abbreviation associated with the record.
1336
1337 **Constraints**
1338
1339 .. naclcode::
1340
1341 AA = AbbrevIndex(A)
1342
1343 **Updates**
1344
1345 .. naclcode::
1346
1347 ExpectedGlobals = N;
1348 ExpectedInitializers = 0;
1349
1350 Global Variable Addressses
1351 --------------------------
1352
1353 A global variable address record defines a global address to global data. The
1354 global variable address record must be immediately followed by initializer
1355 record(s) that define how the corresponding global variable is initialized.
1356
1357 **Syntax**
1358
1359 .. naclcode::
1360
1361 var @gN, align V = <A>
1362 var @gN = <A>
1363
1364 **Record**
1365
1366 .. naclcode::
1367
1368 AA: <0, VV, 0>
1369
1370 **Semantics**
1371
1372 A global variable address record defines a global address for a global variable.
1373 *V* is the alignment to for the global variable. The alignment *V* clause can
1374 be omitted if *V* is zero. *A* is the (optional) abbreviation associated with
1375 the record.
1376
1377 It is assumed that the memory, referenced by the global variable address, can be
1378 both read and written to.
1379
1380 **Constraints**
1381
1382 .. naclcode::
1383
1384 AA = AbbrevIndex(A)
1385 N = NumGlobalAddresses
1386 NumGlobalAddresses < ExpectedGlobals
1387 ExpectedInitializers = 0
1388 VV = Log2(V+1)
1389
1390 **Updates**
1391
1392 .. naclcode::
1393
1394 ++NumGlobalAddresses;
1395 ExpectedInitializers = 1;
1396 TypeOf(@gN) = i32;
1397
1398 **Examples**
1399
1400 .. naclcode::
1401
1402 var @g0 =
1403 zerofill 8;
1404 var @g1 =
1405 {1, 2, 3, 4}
1406
1407 This example defines two global variable addresses, *@g0* and *@g1*. Both use
1408 memory alignment of 0. *@g0* is an 8 byte variable initialized to zero. *@g1*
1409 is a 4 byte variable, initialized by the sequence of bytes 1, 2, 3, and 4.
1410
1411 The corresponding records defined by the example above are:
1412
1413 .. naclcode::
1414
1415 3: <0, 0, 0>
1416 3: <2, 8>
1417 3: <0, 0, 0>
1418 3: <3, 1, 2, 3, 4>
1419
1420 Global Constant Addresses
1421 -------------------------
1422
1423 A global constant address record defines an address corresponding to a global
1424 constant that can't be modified by the program. The global constant address
1425 record must be immediately followed by initializer record(s) that define how
1426 the corresponding global constant is initialized.
1427
1428 **Syntax**
1429
1430 .. naclcode::
1431
1432 const @gN, align V = <A>
1433 const @gN = <A>
1434
1435 **Record**
1436
1437 .. naclcode::
1438
1439 AA: <0, VV, 1>
1440
1441 **Semantics**
1442
1443 A global constant address record defines a global address for a global constant.
1444 *V* is the memory alignment for the global constant. *VV* is the corresponding
1445 number of bits associated with alignment *V* (see *constraints*). The alignment
1446 *V* caluse can be omitted if *V* is zero. *A* is the (optional) abbreviation
Jim Stichnoth 2014/06/06 18:24:48 clause
Karl 2014/06/30 22:09:03 Done.
1447 associated with the record.
1448
1449 It is assumed that the memory, referenced by the global constant
1450 address, is only read, and can't be written to.
1451
1452 Note that the only difference between a global variable address and a global
1453 constant address record is the third element of the record. If the value is
1454 zero, it defines a global variable address. If the value is one, it defines a
1455 global constant address.
1456
1457 **Constraints**
1458
1459 .. naclcode::
1460
1461 AA = AbbrevIndex(A)
1462 N = NumGlobalAddresses
1463 NumGlobalAddresses < ExpectedGlobals
1464 ExpectedInitializers = 0
1465 VV = Log2(V+1)
1466
1467 **Updates**
1468
1469 .. naclcode::
1470
1471 ++NumGlobalAddresses;
1472 ExpectedInitializers = 1;
1473 TypeOf(@gN) = i32;
1474
1475 **Examples**
1476
1477 .. naclcode::
1478
1479 const @g0 =
1480 zerofill 8;
1481 var @g1 =
1482 {1, 2}
1483
1484 This example defines two global constants, with global addresses *@g0* and
1485 *@g1*. *@g0* is an 8 byte constant initialized to zero. *@g1* is a 2 byte
1486 variable, initialized by the sequence of bytes 1 and 2.
1487
1488 The corresponding PNaCl bitcode records are:
1489
1490 .. naclcode::
1491
1492 3: <0, 0, 1>
1493 3: <2, 8>
1494 3: <0, 0, 1>
1495 3: <3, 1, 2>
1496
1497 Zerofill Initializer
1498 --------------------
1499
1500 The zerofill initializer record initializes a sequence of bytes, associated with
1501 a global address, with zeros.
1502
1503 **Syntax**
1504
1505 .. naclcode::
1506
1507 zerofill N; <A>
1508
1509 **Record**
1510
1511 .. naclcode::
1512
1513 AA: <2, N>
1514
1515 **Semantics**
1516
1517 A zerofill initializer record intializes a sequence of bytes, associated with a
1518 global address, with zeros. *A* is the (optional) abbreviation of the associated
1519 record.
1520
1521 **Constraints**
1522
1523 .. naclcode::
1524
1525 AA = AbbrevIndex(A)
1526 ExpectedInitializers > 0;
1527
1528 **Updates**
1529
1530 .. naclcode::
1531
1532 --ExpectedInitializers;
1533
1534 **Examples**
1535
1536 .. naclcode::
1537
1538 const @g0 =
1539 zerofill 8;
1540 var @g1 =
1541 zerofill 4;
1542
1543 This example defines two global constants, with global addresses *@g0* and
1544 *@g1*. The global memory associated with address *@g0*, is an eight byte value,
1545 initialized to zero. The global memory associated with address *@g1*, is a 4
1546 byte value, initialized to zero.
1547
1548 The corresponding PNaCl records are:
1549
1550 .. naclcode::
1551
1552 3: <0, 0, 1>
1553 3: <2, 8>
1554 3: <0, 0, 1>
1555 3: <2, 4>
1556
1557 Data Initializer
1558 ----------------
1559
1560 Data records define a sequence of bytes. These bytes define the initial value of
1561 the contents of the corresponding memory.
1562
1563 **Syntax**
1564
1565 .. naclcode::
1566
1567 { B1 , .... , BN } <A>
1568
1569 **Record**
1570
1571 .. naclcode::
1572
1573 AA: <3, B1, ..., BN>
1574
1575 **Semantics**
1576
1577 A data record defines a sequence of bytes *B1* through *BN*, that initialize *N*
1578 bytes of memory. *A* is the (optional) abbreviation associated with the record.
1579
1580 **Constraints**
1581
1582 .. naclcode::
1583
1584 AA = AbbrevIndex(A)
1585 ExpectedInitializers > 0
1586
1587 **Updates**
1588
1589 .. naclcode::
1590
1591 --ExpectedInitializers;
1592
1593 **Examples**
1594
1595 .. naclcode::
1596
1597 const @g0 =
1598 {1, 2, 97, 36, 44, 88, 44}
1599 const @g1 =
1600 initializers 3 {
1601 {4, 5, 6, 7}
1602 reloc @f1;
1603 {99, 66, 22, 12}
1604 }
1605
1606 The corresponding PNaCl records are:
1607
1608 .. naclcode::
1609
1610 3: <0, 0, 1>
1611 3: <3, 1, 2, 97, 36, 44, 88, 44>
1612 3: <0, 0, 1>
1613 3: <1, 3>
1614 3: <3, 4, 5, 6, 7>
1615 3: <4, 1>
1616 3: <3, 99, 66, 22, 12>
1617
1618 Relocation Initializer
1619 ----------------------
1620
1621 A relocation initializer record allows one to define the initial value of a
1622 global address with the value of another global address (i.e. either function,
1623 variable, or constant). Since addresses are pointers, a relocation initializer
1624 record defines 4 bytes of memory.
1625
1626 **Syntax**
1627
1628 .. naclcode::
1629
1630 reloc V; <A>
1631
1632 **Record**
1633
1634 .. naclcode::
1635
1636 AA: <4, VV>
1637
1638 **Semantics**
1639
1640 A relocation initializer record defines a 4-byte value containing the specified
1641 global address *V*. *A* is the (optional) abbreviation associated with the
1642 record.
1643
1644 **Constraints**
1645
1646 .. naclcode::
1647
1648 AA = AbbrevIndex(A)
1649 VV = AbsoluteIndex(V);
1650 ExpectedInitializers > 0
1651
1652 **Updates**
1653
1654 .. naclcode::
1655
1656 --ExpectedInitializers;
1657
1658 **Examples**
1659
1660 .. naclcode::
1661
1662 var @g0 =
1663 initializers 3 {
1664 reloc @f1;
1665 reloc @g0;
1666 reloc @g10;
1667 }
1668
1669 This example defines global address *@g0*. It defines 12 bytes of memory, and is
1670 initialized with three addresses *@f1*, *@g0*, and *@g10*. Note that all globals
1671 can be used in a relocation initialization record, even if it isn't defined yet.
1672
1673 Assuming
1674
1675 .. naclcode::
1676
1677 100 = AbsoluteIndex(@g0))
1678
1679 The corresponding PNaCl bitcode records are:
1680
1681 .. naclcode::
1682
1683 3: <0, 0, 0>
1684 3: <1, 3>
1685 3: <4, 1>
1686 3: <4, 100>
1687 3: <4, 110>
1688
1689 Subfield Relocation Initializer
1690 -------------------------------
1691
1692 A subfield relocation initializer record allows one to define the initial value
1693 of a global address with the value of another (non-function) global address
1694 (i.e. either variable or constant), plus a constant. Since addresses are
1695 pointers, a relocation initializer record defines 4 bytes of memory.
1696
1697 **Syntax**
1698
1699 .. naclcode::
1700
1701 reloc V + O; <A>
1702 reloc V - O; <A>
1703
1704 **Record**
1705
1706 .. naclcode::
1707
1708 AA: <4, VV, OOO>
1709
1710 **Semantics**
1711
1712 A relocation initializer record defines a 4-byte value containing the specified
1713 global (non-function) address *V*, modified by the unsigned offset *O*. *OO* is
1714 the corresponding signed offset. In the first form, *OO == O*. In the second
1715 form, *OO == - O*. *A* is the (optional) abbreviation associated with the
1716 record. *a* is the corresponding abbreviation index of *A*. When *A* is omitted,
1717 *a=3*.
1718
1719 **Constraints**
1720
1721 .. naclcode::
1722
1723 AA = AbbrevIndex(A)
1724 VV == AbsoluteIndex(V)
1725 ExpectedInitializers > 0
1726 OOO == SignRotate(OO)
1727
1728 **Updates**
1729
1730 .. naclcode::
1731
1732 --ExpectedInitializers;
1733
1734 **Examples**
1735
1736 .. naclcode::
1737
1738 var @g0 =
1739 initializers 3 {
1740 reloc @f1;
1741 reloc @g0 + 4;
1742 reloc @g10 - 3;
1743 }
1744
1745 This example defines global address *@g0*, and is initialized with three
1746 pointers, addresses *@f1*, *@g0+4*, and *@g10-3*. Note that all global addresses
1747 can be used in a relocation initialization record, even if it isn't defined
1748 yet. Validity of the reference can be verified, since a global address *@g10*
1749 must be smaller than the value specified in the globals count record.
1750
1751 Assuming
1752
1753 .. naclcode::
1754
1755 100 = AbsoluteIndex(@g0))
1756
1757 The corresponding PNaCl bitcode records are:
1758
1759 .. naclcode::
1760
1761 3: <0, 0, 0>
1762 3: <1, 3>
1763 3: <4, 1>
1764 3: <4, 100, 8>
1765 3: <4, 110, 7>
1766
1767 Compound Initializer
1768 --------------------
1769
1770 The compound initializer record must immediately follow a global
1771 variable/constant address record. It defines how many (non-compound) initializer
1772 records are used to define the initializer. The size of the corresponding memory
1773 is the sum of the bytes needed for each of the succeeding initializers.
1774
1775 **Syntax**
1776
1777 .. naclcode::
1778
1779 initializers N { <A>
1780 ...
1781 }
1782
1783 **Record**
1784
1785 .. naclcode::
1786
1787 AA: <1, N>
1788
1789 **Semantics**
1790
1791 Defines that the next *N* initializers should be associated with the global
1792 address of the previous record. *A* is the (optional) abbreviation index
1793 associated with the record.
1794
1795 **Constraints**
1796
1797 .. naclcode::
1798
1799 AA = AbbrevIndex(A)
1800 ExpectedInitializers == 1
1801
1802 **Updates**
1803
1804 .. naclcode::
1805
1806 ExpectedInitializers = N;
1807
1808 **Examples**
1809
1810 .. naclcode::
1811
1812 const @g1 =
1813 initializers 3 {
1814 {4, 5, 6, 7}
1815 reloc @f1;
1816 {99, 66, 22, 12}
1817 }
1818
1819 The corresponding PNaCl records are:
1820
1821 .. naclcode::
1822
1823 3: <0, 0, 1>
1824 3: <1, 3>
1825 3: <3, 4, 5, 6, 7>
1826 3: <4, 1>
1827 3: <3, 99, 66, 22, 12>
1828
1829 Valuesymtab Block
1830 =================
1831
1832 TODO(kschimpf)
1833
1834
1835 The *valuesymtab block* [ref] does not define any values. Rather, its only goal
1836 is to associate text names with previously defined global addresses
1837 (i.e. function, constant, and variable). Each association is defined by a
1838 record in the valuesymtab block. Currently, only *intrinsic* [ref] function
1839 addresses need a name. All other entries in this block are considered as a hint
1840 for debugging. The PNaCl translator may (or may not) pass these names to the
1841 running executable, allowing the (runtime) debugger to associate names with
1842 addresses.
1843
1844
1845 Module Block
1846 ============
1847
1848 The module block, like all blocks, is enclosed in a pair of enter/exit records,
1849 using block ID 8. A well-formed module block consists of the following records
1850 (in order):
1851
1852 A version record
1853 The version record communicates which version of the PNaCl bitcode
1854 reader/writer should be used. Note that this is different than the PNaCl
1855 bitcode (ABI) version. The PNaCl bitcode (ABI) version defines what is
1856 expected in records, and is defined in the header record of the bitcode
1857 file. The version record defines the version of the PNaCL bitcode
Jim Stichnoth 2014/06/06 18:24:48 PNaCL --> PNaCl
Jim Stichnoth 2014/06/06 18:24:48 PNaCL --> PNaCl
Karl 2014/06/30 22:09:03 Done.
1858 reader/writer to use to convert records into bit sequences.
1859
1860 Optional local abbreviations
1861 Defines a list of local abbreviations to use for records within the module
1862 block.
1863
1864 An abbreviations block
1865 The abbreviations block defines user-defined, global abbreviations that are
1866 used to convert PNaCl records to bit sequences in blocks following the
1867 abbreviations block.
1868
1869 A types block
1870 The types block defines the set of all types used in the program.
1871
1872 A non-empty sequence of function address records
1873 Each record defines a function address used by the program. Function
1874 addresses must either be external, or defined internally by the program. If
1875 they are defined by the program, there must be a function block (appearing
1876 later in the module) that defines the sequence of instructions for each
1877 defined function.
1878
1879 A globals block defining the global variables.
1880 This block defines the set of global variable (addresses) used by the
1881 program. In addition to the addresses, each global variable also defines how
1882 the corresponding global variable is initialized.
1883
1884 An optional value symbol table block.
1885 This block, if defined, provides textual names for function and global
1886 variable addresses (previously defined in the module). Note that only names
1887 for intrinsic functions must be provided [ref]. Any additional names are
1888 hints that may (or may not) be used by the PNaCl translator, and be available
1889 for debugging when executed.
1890
1891 A sequence of function blocks.
1892 Each function block defines the corresponding control flow graph for each
1893 defined function. The order of function blocks is used to associate them with
1894 function addresses. The order of the defined function blocks must follow the
1895 same order as the corresponding function addresses defined in the module
1896 block.
1897
1898 Descriptions of the abbreviations [ref], types [ref], global variables [ref],
1899 value symbol table [ref], and function [ref] blocks are not provided here. See
1900 the appropriate reference for more details. The following subsections describe
1901 each of the records that can appear in a module block.
1902
1903 Version
1904 -------
1905
1906 The version record defines the implementation of the PNaCl reader/writer to
1907 use. That is, the implementation that converts PNaCl records to bit
1908 sequences. Note that this is different than the PNaCl version of the bitcode
1909 file (encoded in the header record of the bitcode file). The PNaCl version
1910 defines the valid forms of PNaCl records. The version record is specific to the
1911 PNaCl version, and may have different values for different PNaCl versions.
1912
1913 Note that currently, only PNaCl bitcode version 2, and version record value 1 is
1914 defined.
1915
1916 **Syntax**
1917
1918 .. naclcode::
1919
1920 version N; <A>
1921
1922 **Record**
1923
1924 .. naclcode::
1925
1926 AA: <1, N>
1927
1928 **Semantics**
1929
1930 The version record defines which PNaCl reader/writer rules should be
1931 followed. *N* is the version number. Currently *N* must be 1. Future versions of
1932 PNaCl may define additional legal values. *A* is the (optional) abbreviation
1933 index associated with the record.
1934
1935 **Constraints**
1936
1937 .. naclcode::
1938
1939 AA = AbbrevIndex(A)
1940
1941 *Examples*
1942
1943 .. naclcode::
1944
1945 version 1;
1946
1947 The corresponding record is:
1948
1949 .. naclcode::
1950
1951 3: <1, 1>
1952
1953 Function Address
1954 ----------------
1955
1956 A function address record defines a function address. Defining a function
1957 address also implies a corresponding implementation. *Defined* function
1958 addresses define implementations while *declared* function addresses do not.
1959
1960 The implementation of a *defined* function address is provided by a
1961 corresponding function block, appearing later in the module block. The
1962 association of defining function address with the corresponding function block
1963 is based on position. The *Nth* defining function address record, in the module
1964 block, has its implementation in the *Nth* function block of that module block.
1965
1966 **Syntax**
1967
1968 .. naclcode::
1969
1970 PN LN T0 @fN ( T1 , ... , TM ); <A>
1971
1972 **Record**
1973
1974 .. naclcode::
1975
1976 AA: <8, T, C, P, L>
1977
1978 **Semantics**
1979
1980 Defines the function address *@fN*. *PN* is the name that specifies
1981 the prototype value *P* associated with the function. A function
1982 address is defined only if *P==0*. Otherwise, it is only declared.
1983 The type of the function is defined by function type *@tT*. *L*
1984 is the linkage specification corresponding to name *LN*. *C* is the
1985 calling convention used by the function. *A* is the
1986 (optional) abbreviation associated with the record.
1987
1988 Note that the function signature must be defined by a function type in the types
1989 block. Hence, the return value must either be a primitive type, type *void*, or
1990 a vector type. Parameter types can be a primitive or vector type. For the
1991 integral types, only i32 and i64 can be used for a return or parameter type. All
1992 other integer types are not allowed.
1993
1994 Valid prototype names *PN*, and corresponding *P* values, are:
1995
1996 = =======
1997 P PN
1998 = =======
1999 1 declare
2000 0 define
2001 = =======
2002
2003 Valid linkage names *LN*, and corresponding *L* values, are:
2004
2005 = ========
2006 L LN
2007 = ========
2008 3 internal
2009 0 external
2010 = ========
2011
2012 Currently, only one calling convention *C* is supported:
2013
2014 = ====================
2015 C Calling Convention
2016 = ====================
2017 0 C calling convention
2018 = ====================
2019
2020 **Constraint**
2021
2022 .. naclcode::
2023
2024 AA = AbbrevIndex(A)
2025 T = TypeID(TypeOf(T0 ( T1 , ... , TN )))
2026 N = NumFuncAddresses
2027
2028 **Updates**
2029
2030 .. naclcode::
2031
2032 ++NumFuncAddresses;
2033 TypeOf(@fN) = TypeOf(TypeID(i32));
2034 TypeOfFcn(@fN) = TypeOf(@tT);
2035
2036 if PN == 0:
2037 DefiningFcnIDs += @FN;
2038 ++NumDefinedFunctionAddresses;
2039
2040 **Examples**
2041
2042 .. naclcode::
2043
2044 module {
2045 ...
2046 types {
2047 @t0 = void;
2048 @t1 = i32;
2049 @t3 = float;
2050 @t4 = void (i32, float);
2051 @t5 = i32 ();
2052 }
2053 ...
2054 declare external void @f0(i32, float);
2055 define internal i32 @f1();
2056
2057 This defines function addresses *@f0* and *@f1*. Function address *@f0* is
2058 defined externally while *@f1* has an implementation (defined by a corresponding
2059 function block). The type signature of *@f0* is defined by type *@t4* while the
2060 type signature of *@f1* is *@t5*.
2061
2062 The corresponding records for these two function addresses are:
2063
2064 .. naclcode::
2065
2066 3: <8, 4, 0, 1, 0>
2067 3: <8, 5, 0, 0, 1>
2068
2069 Constants Blocks
2070 ================
2071
2072 TODO(kschimpf)
2073
2074 Function Blocks
2075 ===============
2076
2077 A function block defines the implementation of a *defined* function address. The
2078 function address it defines is based on the position of the corresponding
2079 *defined* function address. The Nth *defined* function address always
2080 corresponds to the Nth function block in the module block.
2081
2082 A function definition contains a list of basic blocks, forming the CFG (control
2083 flow graph). Each basic block contains a list of instructions, and ends with a
2084 *terminator* [ref] (e.g. branch) instruction.
2085
2086 Basic blocks are not represented by records. Rather, context is implicit. The
2087 first basic block begins with the first instruction record in the function
2088 block. Blocks boundaries are determined by *terminator* instructions. The
2089 instruction that follows a temrinator instruction begins a new basic block.
Jim Stichnoth 2014/06/06 18:24:48 terminator
Karl 2014/06/30 22:09:03 Done.
2090
2091 The first basic block in a function is special in two ways: it is immediately
2092 executed on entrance to the function, and it is not allowed to have predecessor
2093 basic blocks (i.e. there can't be any branches to the entry block of a
2094 function). Because the entry block has no predecessors, it also can't have any
2095 *PHI instructions* [ref].
2096
2097 The parameters are implied by the type of the corresponding function
2098 address. One parameter is defined for each argument of the function type
2099 signature.
2100
2101 The number of basic blocks is defined by the count record. Each terminator
2102 instruction ends the current basic block, and the next instruction begins a new
2103 basic block. Basic blocks are numbered by the order they appear (starting with
2104 index 0). Basic block IDs have the form *%bN*, where *N* corresponds to the
2105 position of the basic block within the function block.
2106
2107 Each instruction, within a function block, corresponds to a corresponding PNaCl
2108 record. The layout of a function block is the (basic block) count record,
2109 followed by a sequence of instruction records.
2110
2111 For readability, PNaClAsm introduces block IDs. These block IDs do not
2112 correspond to PNaCl records, since basic block boundaries are defined
2113 implicitly, after terminator instructions. They appear only for readability.
2114
2115 Operands are typically defined using an *absolute index* [ref]. This absolute
2116 index implicitly encodes function addresses, global addresses, parameters,
2117 constants, and instructions that generate values. The encoding takes advantage
2118 of the implied ordering of these values in the bitcode file, defining a block of
2119 indices for each kind of identifier. That is, Indices are ordered by putting
Jim Stichnoth 2014/06/06 18:24:47 Indices --> indices
Karl 2014/06/30 22:09:04 Done.
2120 function identifier indices first, followed by global address identifiers,
2121 followed by parameter identifiers, followed by constant identifiers, and lastly
2122 instruction value identifiers.
2123
2124 Most operands of instructions are encoded using a relative index value, rather
2125 than absolute. The is done because most instruction operands refer to values
Jim Stichnoth 2014/06/06 18:24:49 The is done --> This is done
Karl 2014/06/30 22:09:04 Done.
2126 defined earlier in the (same) basic block. As a result, the relative distance
2127 (back) from the next value defining instruction is frequently a small
2128 number. Small numbers tend to require fewer bits when they are converted to bit
2129 sequences.
2130
2131 The following subsections define records that can appear in a function block.
2132
2133 Function enter
2134 --------------
2135
2136 PNaClAsm defines a function enter block construct. The corresponding record is
2137 simply an enter block record, with BlockID value 12. All context about the
2138 defining address is implicit by the position of the function block, and the
2139 corresponding defining function address. To improve readability, PNaClAsm
2140 includes the function signature into the syntax rule.
2141
2142 **Syntax**
2143
2144 .. naclcode::
2145
2146 function TR @fN ( T0 %p0, ... , TM %pM) { <B>
2147
2148 **Record**
2149
2150 1: <65535, 12, B>
2151
2152 **Semantics**
2153
2154 *B* is the number of bits reserved for abbreviations in the block. See
2155 enter block records [ref] for more details.
2156
2157 The value of *N* corresponds to the positional index of the corresponding
2158 defining function address this block is associated with. *M* is the number of
2159 defined parameters (minus one) in the function heading.
2160
2161 **Constraints**
2162
2163 .. naclcode::
2164
2165 N == NumFcnImpls
2166 @fN in DefiningFcnIDs
2167 TypeOfFcn(@fN) == TypeOf(TypeID(TR (T0, ... , TM)))
2168
2169 **Updates**
2170
2171 .. naclcode::
2172
2173 ++NumFcnImpls;
2174 EnclosingFcnID = @fN;
2175 NumBasicBlocks = 0;
2176 ExpectedBlocks = 0;
2177 NumParams = M;
2178 for I in [0..M]:
2179 TypeOf(%pI) = TypeOf(TypeID(TI));
2180
2181 **Examples**
2182
2183 .. naclcode::
2184
2185 types {
2186 ...
2187 @t10 = void (i32, float);
2188 ...
2189 }
2190 ...
2191 define internal void @f12(i32, float);
2192 ...
2193 function void @f12(i32 %p0, float %p1) {
2194 ...
2195 }
2196
2197 defines the enter block record:
2198
2199 .. naclcode::
2200
2201 1: <65535, 12, 2>
2202
2203 Count Record
2204 ------------
2205
2206 The count record, within a function block, defines the number of basic blocks
2207 used to define the function implementation. It should be the first record in the
2208 function block.
2209
2210 **Syntax**
2211
2212 .. naclcode::
2213
2214 blocks: N; <A>
2215 %b0:
2216
2217 **Record**
2218
2219 .. naclcode::
2220
2221 AA: <1, N>
2222
2223 **Semantics**
2224
2225 The count record defines the number *N* of basic blocks in the implemented
2226 function. *A* is the (optional) abbreviation associated with the record.
2227
2228 **Constraints**
2229
2230 .. naclcode::
2231
2232 AA = AbbrevIndex(A)
2233 ExpectedBasicBlocks = 0
2234 NumBasicBlocks = 0
2235
2236 **Updates**
2237
2238 .. naclcode::
2239
2240 ExpectedBlocks = N;
2241
2242 **Examples**
2243
2244 .. naclcode::
2245
2246 blocks: 5
2247
2248 The corresponding PNaCl bitcode record is:
2249
2250 .. naclcode::
2251
2252 3: <1, 5>
2253
2254 Terminator Instructions
2255 -----------------------
2256
2257 Terminator instructions are instructions that appear in a function block, and
2258 define the end of the current basic block. A terminator instruction indicates
2259 which block should be executed after the current block is finished. The function
2260 block is well formed only if the number of terminator instructions, in the
2261 function block, corresponds to the value defined by the corresponding count
2262 block.
2263
2264 Return Void Instruction
2265 ^^^^^^^^^^^^^^^^^^^^^^^
2266
2267 The return void instruction is used to return control from a function back to
2268 the caller, without returning any value.
2269
2270 **Syntax**
2271
2272 .. naclcode::
2273
2274 ret; <A>
2275 %bB:
2276
2277 **Record**
2278
2279 .. naclcode::
2280
2281 AA: <10>
2282
2283 **Semantics**
2284
2285 The return instruction returns control to the calling function.
2286
2287 *B* is the number associated with the next basic block. Label *%bB:* only
2288 appears if *B < ExpectedBasicBlocks*. That is, the label is omitted only if this
2289 terminator instruction is the last instruction in the function block. *A* is
2290 the (optional) abbreviation index associated with the record.
2291
2292 **Constraints**
2293
2294 .. naclcode::
2295
2296 AA = AbbrevIndex(A)
2297 B == NumBasicBlocks + 1
2298 NumBasicBlocks < ExpectedBasicBLocks
2299 ReturnType(TypeOf(EnclosingFcnID)) == void
2300
2301 **Updates**
2302
2303 .. naclcode::
2304
2305 ++NumBasicBlocks;
2306
2307 **Examples**
2308
2309 The following shows the implementation of a function that simply returns.
2310
2311 .. naclcode::
2312
2313 function void @f5() {
2314 blocks: 1;
2315 %b0:
2316 ret;
2317 }
2318
2319 The corresponding PNaCl records are:
2320
2321 .. naclcode::
2322
2323 1: <65535, 12, 2>
2324 3: <1, 1>
2325 3: <10>
2326 0: <65534>
2327
2328 Return Value Instruction
2329 ^^^^^^^^^^^^^^^^^^^^^^^^
2330
2331 The return value instruction is used to return control from a function back to
2332 the caller, including a value. The value must correspond to the return type of
2333 the enclosing function.
2334
2335 **Syntax**
2336
2337 .. naclcode::
2338
2339 ret T V; <A>
2340 %bB:
2341
2342 **Record**
2343
2344 .. naclcode::
2345
2346 AA: <10, VV>
2347
2348 **Semantics**
2349
2350 The return value instruction returns control to the calling function, returning
2351 the provided value.
2352
2353 *V* is the value to return. Type *T* must be of the type returned by the
2354 function. It must also be the type associated with value *V*. *A* is the
2355 (optional) abbreviation index associated with the record.
2356
2357 *B* is the number associated with the next basic block. Label *%bB:* only
2358 appears if *B < ExpectedBasicBlocks*. That is, the label is omitted only if this
2359 terminator instruction is the last instruction in the function block.
2360
2361 The return type *T* must either be a primitive type, or a vector type. If the
2362 return type is an integral type, it must be either i32 or i64.
2363
2364 **Constraints**
2365
2366 .. naclcode::
2367
2368 AA = AbbrevIndex(A)
2369 VV = RelativeIndex(V)
2370 B = NumBasicBlocks + 1
2371 NumBasicBlocks < ExpectedBasicBlocks
2372 T = TypeOf(V) = ReturnType(TypeOf(EnclosingFcnID))
2373
2374 **Updates**
2375
2376 .. naclcode::
2377
2378 ++NumBasicBlocks;
2379
2380 **Examples**
2381
2382 The following shows a return statement that returns the value generated by the
2383 previous instruction:
2384
2385 .. naclcode::
2386
2387 function i32 @f5(i32 %p0) {
2388 blocks: 1;
2389 @b0:
2390 ret i32 @p0;
2391 }
2392
2393 The corresponding records are:
2394
2395 .. naclcode::
2396
2397 1: <65535, 12, 2>
2398 3: <1, 1>
2399 3: <10, 1>
2400 0: <65534>
2401
2402 Unconditional Branch Instruction
2403 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2404
2405 The unconditional branch instruction is used to cause control flow to transfer
2406 to a different basic block of the function.
2407
2408 **Syntax**
2409
2410 .. naclcode::
2411
2412 br %bN; <A>
2413 %bB:
2414
2415 **Record**
2416
2417 .. naclcode::
2418
2419 AA: <11, N>
2420
2421 **Semantics**
2422
2423 The unconditional branch instruction causes control flow to transfer to basic
2424 block *N*. *A* is the (optional) abbreviation index associated with the record.
2425
2426 *B* is the number associated with the next basic block. Label *%bB:* only
2427 appears if *B < ExpectedBasicBlocks*. That is, the label is omitted only if this
2428 terminator instruction is the last instruction in the function block.
2429
2430 **Constraints**
2431
2432 .. naclcode::
2433
2434 AA = AbbrevIndex(A)
2435 0 < N
2436 N < ExpectedBasicBlocks
2437 B = NumBasicBlocks + 1
2438 NumBasicBlocks < ExpectedBasicBlocks
2439
2440 **Updates**
2441
2442 .. naclcode::
2443
2444 ++NumBasicBlocks;
2445
2446 **Examples**
2447
2448 .. naclcode::
2449
2450 br %b2;
2451
2452 This branch instruction branches to the 3rd basic block of the function. It
2453 defines the following PNaCl record:
2454
2455 .. naclcode::
2456
2457 3: <11, 2>
2458
2459 Conditional Branch Instruction
2460 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2461
2462 The conditional branch instruction is used to cause control flow to transfer to
2463 a different basic block of the function, based on a boolean test condition.
2464
2465 **Syntax**
2466
2467 .. naclcode::
2468
2469 br i1 C, %bT, %bBF; <A>
2470 %bB:
2471
2472 **Record**
2473
2474 .. naclcode::
2475
2476 AA: <11, T, F, V>
2477
2478 **Semantics**
2479
2480 Upon execution of a conditional branch instruction, the *i1* (boolean) argument
2481 *C* is evaluated. If the value is *true*, control flows to basic block
2482 *%bT*. Otherwise control flows to basic block *%bF*. *A* is the (optional)
2483 abbreviation index associated with the record.
2484
2485 *B* is the number associated with the next basic block. Label *%bB:* only
2486 appears if *B < ExpectedBasicBlocks*. That is, the label is omitted only if this
2487 terminator instruction is the last instruction in the function block.
2488
2489 **Constraints**
2490
2491 .. naclcode::
2492
2493 AA = AbbrevIndex(A)
2494 V = RelativeIndex(C)
2495 0 < T
2496 B1 < ExpectedBasicBlocks
2497 0 < F
2498 B2 < ExpectedBasicBlocks
2499 B = NumBasicBlocks + 1
2500 NumBasicBlocks < ExpectedBasicBlocks
2501 TypeOf(C) == i1
2502
2503 **Updates**
2504
2505 .. naclcode::
2506
2507 ++NumBasicBlocks;
2508
2509 **Examples**
2510
2511 .. naclcode::
2512
2513 function i32 @f2(i32 %p0, i32 %p1) {
2514 blocks: 3;
2515 %b0:
2516 %v0 = cmp eq i32 %p0, %p1;
2517 br i1 %v0, %b1, %b2;
2518 %b1:
2519 ret i32 %p0;
2520 %b2:
2521 ret i32 %p1;
2522
2523 The corresponding records are:
2524
2525 .. naclcode::
2526
2527 1: <65535, 12, 2>
2528 3: <1, 3>
2529 3: <28, 2, 1, 32>
2530 3: <11, 2, 1, 1>
2531 3: <10, 3>
2532 3: <10, 2>
2533 0: <65534>
2534
2535 Unreachable
2536 ^^^^^^^^^^^
2537
2538 The unreachable instruction has no defined semantics. The instruction is used to
2539 inform the *PNaCl translator* that control can't reach this instruction.
2540
2541 **Syntax**
2542
2543 .. naclcode::
2544
2545 unreachable; <A>
2546 %bB:
2547
2548 **Record**
2549
2550 .. naclcode::
2551
2552 AA: <15>
2553
2554 **Semantics**
2555
2556 Directive to the *PNaCl translator* that this instruction is unreachable. *A*
2557 is the (optional) abbreviation index associated with the record.
2558
2559 *B* is the number associated with the next basic block. Label *%bB:* only
2560 appears if *B < ExpectedBasicBlocks*. That is, the label is omitted only if this
2561 terminator instruction is the last instruction in the function block.
2562
2563 **Constraints**
2564
2565 .. naclcode::
2566
2567 AA = AbbrevIndex(A)
2568 B = NumBasicBlocks + 1
2569 NumBasicBlocks < ExpectedBasicBlocks
2570
2571 **Updates**
2572
2573 .. naclcode::
2574
2575 ++NumBasicBlocks;
2576
2577 **Examples**
2578
2579 TODO(kschimpf)
2580
2581 Switch Instruction
2582 ^^^^^^^^^^^^^^^^^^
2583
2584 TODO(kschimpf)
2585
2586 Integer Binary Instructions
2587 -----------------------------
2588
2589 Binary instructions are used to do most of the computation in a program. This
2590 section focusses on binary instructions that operator on integral values, or
Jim Stichnoth 2014/06/06 18:24:49 focusses --> focuses
jvoung (off chromium) 2014/06/06 20:09:15 focuses
2591 vectors of integral values.
2592
2593 All binary operations require two operands of the same type, execute an
2594 operation on them, and produce a value. The value may represent multiple values
2595 if the type is a vector type. The result value always has the same type as its
2596 operands.
2597
2598 Some integer binary operations can be applied to both signed and unsigned
2599 integers. Others, the sign is significant. In general, if the sign plays a role
2600 in the instruction, the sign information is encoded into the name of the
2601 instruction.
2602
2603 For most binary operations (except some of the logical operations), integral
2604 type i1 is disallowed.
2605
2606 Integer Add
2607 ^^^^^^^^^^^
2608
2609 The integer add instruction returns the sum of its two arguments. Both arguments
2610 and the result must be of the same type. That type must be integral, or an
2611 integral vector type.
2612
2613 **Syntax**
2614
2615 .. naclcode::
2616
2617 %vN = add T V1, V2; <A>
2618
2619 **Record**
2620
2621 AA: <2, VV1, VV2, 0>
2622
2623 **Semantics**
2624
2625 The integer add instruction returns the sum of its two arguments. Arguments *V1* and
Jim Stichnoth 2014/06/06 18:24:47 80-col
Karl 2014/06/30 22:09:05 Done.
2626 *V2*, and the result *%vN*, must be of type *T*. *T* must be an integral type,
2627 or an integral vector type. *N* is defined by the record position, defining the
2628 corresponding value generated by the instruction. *A* is the (optional)
2629 abbreviation associated with the corresponding record.
2630
2631 Overflow conditions are ignored, and the result returned is the mathematical
jvoung (off chromium) 2014/06/06 20:09:15 "Overflow conditions are ignored, and ..." Is "ig
Karl 2014/06/30 22:09:04 Done.
2632 result modulo *exp(2,n)*, where *n* is the bitwidth of the integer result.
2633
2634 Because integers are assumed to use a two's complement representation,
2635 this instruction is appropriate for both signed and unsigned integers.
2636
2637 In the add instruction, Integral type i1 (and vectors on integral type i1) is
Jim Stichnoth 2014/06/06 18:24:49 Integral --> integral
Karl 2014/06/30 22:09:05 Done.
2638 disallowed.
2639
2640 **Constraints**
2641
2642 .. naclcode::
2643
2644 AA = AbbrevIndex(A)
2645 VV1 = RelativeIndex(V1)
2646 VV2 = RelativeIndex(V2)
2647 T = TypeOf(V1) = TypeOf(V2)
2648 IsInteger(UnderlyingType(T))
2649 UnderlyingType(T) != i1
2650 N = NumValuedInsts
2651 NumBasicBlocks < ExpectedBasicBlocks
2652
2653 **Updates**
2654
2655 .. naclcode::
2656
2657 ++NumValuedInsts;
2658 TypeOf(%vN) = T
2659
2660 **Examples**
2661
2662 .. naclcode::
2663
2664 function i32 @f0(i32 %p0, i32 %p1) {
2665 blocks: 1;
2666 %b0:
2667 %v0 = add i32 %p0, %p1;
2668 %v1 = add i32 %p0, %v0;
2669 ret i32 %v1;
2670 }
2671
2672 The corresponding records are:
2673
2674 .. naclcode::
2675
2676 1: <65535, 12, 2>
2677 3: <1, 1>
2678 3: <2, 2, 1, 0>
2679 3: <2, 3, 1, 0>
2680 3: <10, 1>
2681 0: <65534>
2682
2683 Integer Subtract
2684 ^^^^^^^^^^^^^^^^
2685
2686 The integer subtract instruction returns the difference of its two arguments.
2687 Both arguments and the result must be of the same type. That type must be
2688 integral, or an integral vector type.
2689
2690 Note: Since there isn't a negate instruction, subtraction from constant zero
2691 should be used to negate values.
2692
2693 **Syntax**
2694
2695 .. naclcode::
2696
2697 %vN = sub T V1, V2; <A>
2698
2699 **Record**
2700
2701 .. naclcode::
2702
2703 AA: <2, VV1, VV2, 1>
2704
2705 **Semantics**
2706
2707 The integer subtract returns the difference of its two arguments. Arguments *V1*
2708 and *V2*, and the result *%vN* must be of type *T*. *T* must be an integral
2709 type, or an integral vector type. *N* is defined by the record position, definin g
Jim Stichnoth 2014/06/06 18:24:49 80-col
2710 the corresponding value generated by the instruction. *A* is the (optional)
2711 abbreviation ¯associated with the corresponding record.
2712
2713 Underflow conditions are ignored, and the result returned is the mathematical
2714 result modulo *exp(2, n)*, where *n* is the integer bitwidth of the result.
2715
2716 Because integers are assumed to use a two's complement representation,
2717 this instruction is appropriate for both signed and unsigned integers.
2718
2719 In the subtract instruction, Integral type i1 is disallowed.
Jim Stichnoth 2014/06/06 18:24:48 Integral --> integral
2720
2721 **Constraints**
2722
2723 .. naclcode::
2724
2725 AA == AbbrevIndex(A)
2726 VV1 == RelativeIndex(V1)
2727 VV2 == RelativeIndex(V2)
2728 T == TypeOf(V1) == TypeOf(V2)
2729 IsInteger(UnderlyingType(T))
2730 UnderlyingType(T) != i1
2731 N == NumValuedInsts
2732 NumBasicBlocks < ExpectedBasicBlocks
2733
2734 **Updates**
2735
2736 .. naclcode::
2737
2738 ++NumValuedInsts;
2739 TypeOf(%vN) = T
2740
2741 **Examples**
2742
2743 .. naclcode::
2744
2745 function i32 @f0(i32 %p0, i32 %p1) {
2746 blocks: 1;
2747 %b0:
2748 %v0 = sub i32 %p0, %p1;
2749 %v1 = sub i32 %p0, %v0;
2750 ret i32 %v1;
2751 }
2752
2753 The corresponding records are:
2754
2755 .. naclcode::
2756
2757 1: <65535, 12, 2>
2758 3: <1, 1>
2759 3: <2, 2, 1, 1>
2760 3: <2, 3, 1, 1>
2761 3: <10, 1>
2762 0: <65534>
2763
2764 Integer Multiply
2765 ^^^^^^^^^^^^^^^^
2766
2767 The integer multiply instruction returns the product of its two arguments. Both
2768 arguments and the result must be of the same type. That type must be integral,
2769 or an integral based vector type.
2770
2771 **Syntax**
2772
2773 .. naclcode::
2774
2775 &vN = mul T V1, V2; <A>
2776
2777 **Record**
2778
2779 .. naclcode::
2780
2781 AA: <2, VV1, VV2, 2>
2782
2783 **Semantics**
2784
2785 The intebger multiply instruction returns the product of its two
Jim Stichnoth 2014/06/06 18:24:46 integer
Karl 2014/06/30 22:09:05 Done.
2786 arguments. Arguments *V1* and *V2*, and the result *%vN*, must be of type *T*.
2787 *T* must be an integral type, or an integral vector type. *N* is defined by the
2788 record position, defining the corresponding value generated by the
2789 instruction. *A* is the (optional) abbreviation associated with the
2790 corresponding record.
2791
2792 Overflow conditions are ignored, and the result returned is the mathematical
2793 result modulo *exp(2, n)*, where *n* is the bitwidth of the result.
2794
2795 Because integers are assumed to use a two's complement representation,
2796 this instruction is appropriate for both signed and unsigned integers.
2797
2798 In the subtract instruction, Integral type i1 is disallowed.
Jim Stichnoth 2014/06/06 18:24:47 Integral --> integral
Karl 2014/06/30 22:09:05 Done.
2799
2800 **Constraints**
2801
2802 .. naclcode::
2803
2804 AA == AbbrevIndex(A)
2805 VV1 == RelativeIndex(V1)
2806 VV2 == RelativeIndex(V2)
2807 T == TypeOf(V1) == TypeOf(V2)
2808 IsInteger(UnderlyingType(T))
2809 UnderlyingType(T) != i1
2810 N == NumValuedInsts
2811 NumBasicBlocks < ExpectedBasicBlocks
2812
2813 **Updates**
2814
2815 .. naclcode::
2816
2817 ++NumValuedInsts;
2818 TypeOf(%vN) = T
2819
2820 **Examples**
2821
2822 .. naclcode::
2823
2824 function i32 @f0(i32 %p0, i32 %p1) {
2825 blocks: 1;
2826 %b0:
2827 %v0 = mul i32 %p0, %p1;
2828 %v1 = mul i32 %v0, %p1;
2829 ret i32 %v1;
2830 }
2831
2832 The corresponding records are:
2833
2834 .. naclcode::
2835
2836 1: <65535, 12, 2>
2837 3: <1, 1>
2838 3: <2, 2, 1, 2>
2839 3: <2, 1, 2, 2>
2840 3: <10, 1>
2841 0: <65534>
2842
2843 Signed Integer Divide
2844 ^^^^^^^^^^^^^^^^^^^^^
2845
2846 The signed integer divide instruction returns the quotient of its two arguments.
2847 Both arguments and the result must be of the same type. That type must be
2848 integral, or an integral vector type.
2849
2850 **Syntax**
2851
2852 .. naclcode::
2853
2854 %vN = sdiv T V1, V2; <A>
2855
2856 **Record**
2857
2858 .. naclcode::
2859
2860 AA: <2, VV1, VV2, 4>
2861
2862 **Semantics**
2863
2864 The divide instruction returns the quotient of its two arguments. Arguments *V1*
2865 and *V2*, and the result *%vN*, must be of type *T*. *T* must be a integral
2866 type, or an integral vector type. *N* is defined by the record position,
2867 defining the corresponding value generated by the instruction. *A* is the
2868 (optional) abbreviation associated with the corresponding record.
2869
2870 Signed values are assumed. Note that signed and unsigned integer division are
2871 distinct operations. For unsigned integer division use the unsigned integer
2872 divide instruction (udiv).
2873
2874 In the signed integer divide instruction, integral type i1 is
2875 disallowed. Integer division by zero is guaranteed to trap. Overflow is also
2876 undefined.
jvoung (off chromium) 2014/06/06 20:09:14 Maybe keep the clarification that overflow happens
Karl 2014/06/30 22:09:03 While I agree we should consider tightening this,
2877
2878 **Constraints**
2879
2880 .. naclcode::
2881
2882 AA == AbbrevIndex(A)
2883 VV1 == RelativeIndex(V1)
2884 VV2 == RelativeIndex(V2)
2885 T == TypeOf(V1) == TypeOf(V2)
2886 IsInteger(UnderlyingType(T))
2887 UnderlyingType(T) != i1
2888 N == NumValuedInsts
2889 NumBasicBlocks < ExpectedBasicBlocks
2890
2891 **Updates**
2892
2893 .. naclcode::
2894
2895 ++NumValuedInsts;
2896 TypeOf(%vN) = T
2897
2898 **Examples**
2899
2900 .. naclcode::
2901
2902 function i32 @f0(i32 %p0, i32 %p1) {
2903 blocks: 1;
2904 %b0:
2905 %v0 = sdiv i32 %p0, %p1;
2906 %v1 = sdiv i32 %v0, %p1;
2907 ret i32 %v1;
2908 }
2909
2910 The corresponding records are:
2911
2912 .. naclcode::
2913
2914 1: <65535, 12, 2>
2915 3: <1, 1>
2916 3: <2, 2, 1, 4>
2917 3: <2, 1, 2, 4>
2918 3: <10, 1>
2919 0: <65534>
2920
2921 Unsigned Integer Divide
2922 ^^^^^^^^^^^^^^^^^^^^^^^
2923
2924 The unsigned integer divide instruction returns the quotient of its two
2925 arguments. Both the arguments and the result must be of the same type. That type
2926 must be integral, or an integral vector type.
2927
2928 **Syntax**
2929
2930 .. naclcode::
2931
2932 %vN = udiv T V1, V2; <a>
2933
2934 **Record**
2935
2936 .. naclcode::
2937
2938 AA: <2, A1, A2, 3>
2939
2940 **Semantics**
2941
2942 The unsigned integer divide instruction returns the quotient of its two
2943 arguments. Arguments *V1* and *V2*, and the result *%vN*, must be of type
2944 *T*. *T* must be an integral type, or an integral vector type. *N* is defined
2945 by the record position, defining the corresponding value generated by the
2946 instruction. *A* is the (optional) abbreviation associated with the
2947 corresponding record.
2948
2949 Unsigned integral values are assumed. Note that signed and unsigned integer
2950 division are distinct operations. For signed integer division use the signed
2951 integer divide instruction (sdiv).
2952
2953 In the unsigned integer divide instruction, Integral type i1 is
Jim Stichnoth 2014/06/06 18:24:46 Integral --> integral
Karl 2014/06/30 22:09:05 Done.
2954 disallowed. Division by zero is guaranteed to trap. Overflow is also undefined.
jvoung (off chromium) 2014/06/06 20:09:14 When would overflow happen, if these are unsigned?
Karl 2014/06/30 22:09:03 Removing sentence.
2955
2956 **Constraints**
2957
2958 .. naclcode::
2959
2960 AA == AbbrevIndex(A)
2961 VV1 == RelativeIndex(V1)
2962 VV2 == RelativeIndex(V2)
2963 T == TypeOf(V1) == TypeOf(V2)
2964 IsInteger(UnderlyingType(T))
2965 UnderlyingType(T) != i1
2966 N == NumValuedInsts
2967 NumBasicBlocks < ExpectedBasicBlocks
2968
2969 **Updates**
2970
2971 .. naclcode::
2972
2973 ++NumValuedInsts;
2974 TypeOf(%vN) = T
2975
2976 **Examples**
2977
2978 .. naclcode::
2979
2980 function i32 @f0(i32 %p0, i32 %p1) {
2981 blocks: 1;
2982 %b0:
2983 %v0 = udiv i32 %p0, %p1;
2984 %v1 = udiv i32 %v0, %p1;
2985 ret i32 %v1;
2986 }
2987
2988 The corresponding records are:
2989
2990 .. naclcode::
2991
2992 1: <65535, 12, 2>
2993 3: <1, 1>
2994 3: <2, 2, 1, 3>
2995 3: <2, 1, 2, 3>
2996 3: <10, 1>
2997 0: <65534>
2998
2999 Signed Integer Remainder
3000 ^^^^^^^^^^^^^^^^^^^^^^^^
3001
3002 The signed integer remainder instruction returns the remainder of the quotient
3003 of its two arguments. Both arguments and the result must be of the same
3004 type. That type must be integral, or an integral based vector type.
3005
3006 **Syntax**
3007
3008 .. naclcode::
3009
3010 %vN = srem T V1, V2; <A>
3011
3012 **Record**
3013
3014 .. naclcode::
3015
3016 AA: <2, VV1, VV2, 6>
3017
3018 **Semantics**
3019
3020 The signed integer remainder instruction returns the remainder of the quotient
3021 of its two arguments. Arguments *V1* and *V2*, and the result *%vN*, must be of
3022 type *T*. *T* must be a integral type, or an integral vector type. *N* is
3023 defined by the record position, defining the corresponding value generated by
3024 the instruction. *A* is the (optional) abbreviation associated with the
3025 corresponding record.
3026
3027 Signed values are assumed. Note that signed and unsigned integer division are
3028 distinct operations. For unsigned integer division use the unsigned integer
3029 remainder instruction (urem).
3030
3031 In the signed integer remainder instruction, Integral type i1 is disallowed.
Jim Stichnoth 2014/06/06 18:24:47 Integral --> integral
3032 Division by zero is guaranteed to trap. Overflow is also undefined.
3033
3034 **Constraints**
3035
3036 .. naclcode::
3037
3038 AA == AbbrevIndex(A)
3039 VV1 == RelativeIndex(V1)
3040 VV2 == RelativeIndex(V2)
3041 T == TypeOf(V1) == TypeOf(V2)
3042 IsInteger(UnderlyingType(T))
3043 UnderlyingType(T) != i1
3044 N == NumValuedInsts
3045 NumBasicBlocks < ExpectedBasicBlocks
3046
3047 **Updates**
3048
3049 .. naclcode::
3050
3051 ++NumValuedInsts;
3052 TypeOf(%vN) = T
3053
3054 **Examples**
3055
3056 .. naclcode::
3057
3058 function i32 @f0(i32 %p0, i32 %p1) {
3059 blocks: 1;
3060 %b0:
3061 %v0 = srem i32 %p0, %p1;
3062 %v1 = srem i32 %v0, %p1;
3063 ret i32 %v1;
3064 }
3065
3066 The corresponding records are:
3067
3068 .. naclcode::
3069
3070 1: <65535, 12, 2>
3071 3: <1, 1>
3072 3: <2, 2, 1, 6>
3073 3: <2, 1, 2, 6>
3074 3: <10, 1>
3075 0: <65534>
3076
3077 Unsigned Integer Remainder Instruction
3078 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3079
3080 The unsigned integer remainder instruction returns the remainder of the quotient
3081 of its two arguments. Both the arguments and the result must be of the same
3082 type. The type must be integral, or an integral vector type.
3083
3084 **Syntax**
3085
3086 .. naclcode::
3087
3088 %vN = urem T V1, V2; <A>
3089
3090 **Record**
3091
3092 .. naclcode::
3093
3094 AA: <2, A1, A2, 5>
3095
3096 **Semantics**
3097
3098 The unsigned integer remainder instruction returns the remainder of the quotient
3099 of its two arguments. Arguments *V1* and *V2*, and the result *%vN*, must be of
3100 type *T*. *T* must be an integral type, or an integral vector type. *N* is
3101 defined by the record position, defining the corresponding value generated by
3102 the instruction. *A* is the (optional) abbreviation associated with the
3103 corresponding record.
3104
3105 Unsigned values are assumed. Note that signed and unsigned integer division are
3106 distinct operations. For signed integer division use the remainder instruction
3107 (srem).
3108
3109 In the unsigned integer remainder instruction, Integral type i1 is disallowed.
Jim Stichnoth 2014/06/06 18:24:46 Integral --> integral
3110 Division by zero is guaranteed to trap. Overflow is also undefined.
jvoung (off chromium) 2014/06/06 20:09:14 similar, overflow?
Karl 2014/06/30 22:09:03 Done.
3111
3112 **Constraints**
3113
3114 .. naclcode::
3115
3116 AA == AbbrevIndex(A)
3117 VV1 == RelativeIndex(V1)
3118 VV2 == RelativeIndex(V2)
3119 T == TypeOf(V1) == TypeOf(V2)
3120 IsInteger(UnderlyingType(T))
3121 UnderlyingType(T) != i1
3122 N == NumValuedInsts
3123 NumBasicBlocks < ExpectedBasicBlocks
3124
3125 **Updates**
3126
3127 .. naclcode::
3128
3129 ++NumValuedInsts;
3130 TypeOf(%vN) = T
3131
3132 **Examples**
3133
3134 .. naclcode::
3135
3136 function i32 @f0(i32 %p0, i32 %p1) {
3137 blocks: 1;
3138 %b0:
3139 %v0 = srem i32 %p0, %p1;
3140 %v1 = srem i32 %v0, %p1;
3141 ret i32 %v1;
3142 }
3143
3144 The corresponding records are:
3145
3146 .. naclcode::
3147
3148 1: <65535, 12, 2>
3149 3: <1, 1>
3150 3: <2, 2, 1, 5>
3151 3: <2, 1, 2, 5>
3152 3: <10, 1>
3153 0: <65534>
3154
3155 Shift Left
3156 ^^^^^^^^^^
3157
3158 The (integer) shift left instruction returns the first operand, shifted to the
3159 left a specified number of bits with zero fill. The shifted value must be
3160 integral, or an integral vector type.
3161
3162 **Syntax**
3163
3164 .. naclcode::
3165
3166 %vN = shl T V1, V2; <A>
3167
3168 **Record**
3169
3170 .. naclcode::
3171
3172 AA: <2, VV1, VV2, 7>
3173
3174 **Semantics**
3175
3176 This instruction performs a shift left operation. Argument *V1* and the result
3177 *%vN* must be of type *T*. *T* nust be an integral, or a vector of
3178 integrals. *V2* must be an integral type. *N* is defined by the record position,
3179 defining the corresponding value generated by the instruction. *A* is the
3180 (optional) abbreviation associated with the corresponding record.
3181
3182 *V2* is assumed to be unsigned. The least significant bits of the result will
3183 be filled with zero bits after the shift. If *V2* is (statically or dynamically)
3184 is negative or equal to or larger than the number of bits in *V1*, the result is
3185 undefined. If the arguments are vectors, each vector element of *V1* is shifted
3186 by the corresponding shift amount in *V2*.
3187
3188 In the shift left instruction, Integral type i1 is disallowed for either
Jim Stichnoth 2014/06/06 18:24:50 Integral --> integral
3189 argument.
3190
3191 **Constraints**
3192
3193 .. naclcode::
3194
3195 AA == AbbrevIndex(A)
3196 VV1 == RelativeIndex(V1)
3197 VV2 == RelativeIndex(V2)
3198 T == TypeOf(V1)
3199 IsInteger(TypeOf(V2))
3200 IsInteger(UnderlyingType(T))
3201 UnderlyingType(T) != i1
3202 UnderlyingType(TypeOf(V2)) != i1
3203 N == NumValuedInsts
3204 NumBasicBlocks < ExpectedBasicBlocks
3205
3206 **Updates**
3207
3208 .. naclcode::
3209
3210 ++NumValuedInsts;
3211 TypeOf(%vN) = T
3212
3213 **Examples**
3214
3215 .. naclcode::
3216
3217 function i32 @f0(i32 %p0, i32 %p1) {
3218 blocks: 1;
3219 %b0:
3220 %v0 = shl i32 %p0, %p1;
3221 %v1 = shl i32 %v0, %p1;
3222 ret i32 %v1;
3223 }
3224
3225 The corresponding records are:
3226
3227 .. naclcode::
3228
3229 1: <65535, 12, 2>
3230 3: <1, 1>
3231 3: <2, 2, 1, 7>
3232 3: <2, 1, 2, 7>
3233 3: <10, 1>
3234 0: <65534>
3235
3236 Logical Shift Right
3237 ^^^^^^^^^^^^^^^^^^^
3238
3239 The logical shift right instruction returns the first operand, shifted
3240 to the right a specified number of bits with zero fill.
3241
3242 **Syntax**
3243
3244 .. naclcode::
3245
3246 %vN = lshr T V1, V2; <A>
3247
3248 **Record**
3249
3250 .. naclcode::
3251
3252 AA: <2, VV1, VV2, 8>
3253
3254 **Semantics**
3255
3256 This instruction performs a logical shift right operation. Arguments *V1* and
3257 the result *%vN* must be of type *T*. *T* nust be an integral, or a vector of
3258 integrals. *V2* must be an integral type. *N* is defined by the record position,
3259 defining the corresponding value generated by the instruction. *A* is the
3260 (optional) abbreviation associated with the corresponding record.
3261
3262 *V2* is assumed to be unsigned. The most significant bits of the result will be
3263 filled with zero bits after the shift. If *V2* is (statically or dynamically)
3264 negative or equal to or larger than the number of bits in *V1*, the result is
3265 undefined. If the arguments are vectors, each vector element of *V1* is shifted
3266 by the corresponding shift amount in *V2*.
3267
3268 In the logical shift right instruction, Integral type i1 is disallowed for
Jim Stichnoth 2014/06/06 18:24:49 Integral --> integral
3269 either argument.
3270
3271 **Constraints**
3272
3273 .. naclcode::
3274
3275 AA = AbbrevIndex(A)
3276 VV1 == RelativeIndex(V1)
3277 VV2 == RelativeIndex(V2)
3278 T == TypeOf(V1)
3279 IsInteger(TypeOf(V2))
3280 IsInteger(UnderlyingType(T))
3281 UnderlyingType(T) != i1
3282 UnderlyingType(TypeOf(V2)) != i1
3283 N == NumValuedInsts
3284 NumBasicBlocks < ExpectedBasicBlocks
3285
3286 **Updates**
3287
3288 .. naclcode::
3289
3290 ++NumValuedInsts;
3291 TypeOf(%vN) = T
3292
3293 **Examples**
3294
3295 .. naclcode::
3296
3297 function i32 @f0(i32 %p0, i32 %p1) {
3298 blocks: 1;
3299 %b0:
3300 %v0 = lshr i32 %p0, %p1;
3301 %v1 = lshr i32 %v0, %p1;
3302 ret i32 %v1;
3303 }
3304
3305 The corresponding records are:
3306
3307 .. naclcode::
3308
3309 1: <65535, 12, 2>
3310 3: <1, 1>
3311 3: <2, 2, 1, 8>
3312 3: <2, 1, 2, 8>
3313 3: <10, 1>
3314 0: <65534>
3315
3316 Arithmetic Shift Right
3317 ^^^^^^^^^^^^^^^^^^^^^^
3318
3319 The arithmetic shift right instruction returns the first operand,
3320 shifted to the right a specified number of bits with sign extension.
3321
3322 **Syntax**
3323
3324 .. naclcode::
3325
3326 %vN = ashr T V1, V2; <A>
3327
3328 **Record**
3329
3330 .. naclcode::
3331
3332 AA: <2, VV1, VVA2, 9>
3333
3334 **Semantics**
3335
3336 This instruction performs an arithmetic shift right operation. Arguments *V1*
3337 and the result *%vN* must be of type *T*. *T* nust be an integral, or a vector
3338 of integrals. *V2* must be an integral type. *N* is defined by the record
3339 position, defining the corresponding value generated by the instruction. *A* is
3340 the (optional) abbreviation associated with the corresponding record.
3341
3342 *V2* is assumed to be unsigned. The most significant bits of the result will be
3343 filled with the sign bit of *V1*. If *V2* is (statically or dynamically)
3344 negative or equal to or larger than the number of bits in *V1*, the result is
3345 undefined. If the arguments are vectors, each vector element of *V1* is shifted
3346 by the corresponding shift amount in *V2*.
3347
3348 In the arithmetic shift right instruction, integral type i1 is disallowed for
3349 either argument.
3350
3351 **Constraints**
3352
3353 .. naclcode::
3354
3355 AA == AbbrevIndex(A)
3356 VV1 == RelativeIndex(V1)
3357 VV2 == RelativeIndex(V2)
3358 T == TypeOf(V1)
3359 IsInteger(TypeOf(V2))
3360 UnderlyingType(T) != i1
3361 UnderlyingType(TypeOf(V2)) != i1
3362 N == NumValuedInsts
3363 NumBasicBlocks < ExpectedBasicBlocks
3364
3365 **Updates**
3366
3367 .. naclcode::
3368
3369 ++NumValuedInsts;
3370 TypeOf(%vN) = T
3371
3372 **Examples**
3373
3374 .. naclcode::
3375
3376 function i32 @f0(i32 %p0, i32 %p1) {
3377 blocks: 1;
3378 %b0:
3379 %v0 = ashr i32 %p0, %p1;
3380 %v1 = ashr i32 %v0, %p1;
3381 ret i32 %v1;
3382 }
3383
3384 The corresponding records are:
3385
3386 .. naclcode::
3387
3388 1: <65535, 12, 2>
3389 3: <1, 1>
3390 3: <2, 2, 1, 9>
3391 3: <2, 1, 2, 9>
3392 3: <10, 1>
3393 0: <65534>
3394
3395 Logical And
3396 ^^^^^^^^^^^
3397
3398 The *and* instruction returns the bitwise logical and of its two operands.
3399
3400 **Syntax**
3401
3402 .. naclcode::
3403
3404 %vN = and T V1, V2; <A>
3405
3406 **Record**
3407
3408 .. naclcode::
3409
3410 AA: <2, VV1, VV2, 10>
3411
3412 **Semantics**
3413
3414 This instruction performs a bitwise logical and of its arguments. Arguments
3415 *V1* and *V2*, and the result *%vN* must be of type *T*. *T* nust be an
3416 integral, or a vector of integrals. *N* is defined by the record position,
3417 defining the corresponding value generated by the instruction. *A* is the
3418 (optional) abbreviation associated with the corresponding record.
3419
3420 The truth table used for the *and* instruction is:
3421
3422 ===== ===== ======
3423 Arg 1 Arg 2 Result
3424 ===== ===== ======
3425 0 0 0
3426 0 1 0
3427 1 0 0
3428 1 1 1
3429 ===== ===== ======
3430
3431 **Constraints**
3432
3433 .. naclcode::
3434
3435 AA == AbbrevIndex(A)
3436 VV1 == RelativeIndex(V1)
3437 VV2 == RelativeIndex(V2)
3438 T == TypeOf(V1) == TypeOf(V2)
3439 IsInteger(UnderlyingType(T)))
3440 N == NumValuedInsts
3441 NumBasicBlocks < ExpectedBasicBlocks
3442
3443 **Updates**
3444
3445 .. naclcode::
3446
3447 ++NumValuedInsts;
3448 TypeOf(%vN) = T
3449
3450 **Examples**
3451
3452 .. naclcode::
3453
3454 function i32 @f0(i32 %p0, i32 %p1) {
3455 blocks: 1;
3456 %b0:
3457 %v0 = and i32 %p0, %p1;
3458 %v1 = and i32 %v0, %p1;
3459 ret i32 %v1;
3460 }
3461
3462 The corresponding records are:
3463
3464 .. naclcode::
3465
3466 1: <65535, 12, 2>
3467 3: <1, 1>
3468 3: <2, 2, 1, 10>
3469 3: <2, 1, 2, 10>
3470 3: <10, 1>
3471 0: <65534>
3472
3473 Logical Or
3474 ^^^^^^^^^^
3475
3476 The *or* instruction returns the bitwise logical inclusive or of its
3477 two operands.
3478
3479 **Syntax**
3480
3481 .. naclcode::
3482
3483 %vN = or T V1, V2; <A>
3484
3485 **Record**
3486
3487 .. naclcode::
3488
3489 AA: <2, VV1, VV2, 11>
3490
3491 **Semantics**
3492
3493 This instruction performs a bitwise logical inclusive or of its arguments.
3494 Arguments *V1* and *V2*, and the result *%vN* must be of type *T*. *T* nust be
3495 an integral, or a vector of integrals. *N* is defined by the record position,
3496 defining the corresponding value generated by the instruction. *A* is the
3497 (optional) abbreviation associated with the corresponding record.
3498
3499 The truth table used for the *or* instruction is:
3500
3501 ===== ===== ======
3502 Arg 1 Arg 2 Result
3503 ===== ===== ======
3504 0 0 0
3505 0 1 1
3506 1 0 1
3507 1 1 1
3508 ===== ===== ======
3509
3510 **Constraints**
3511
3512 .. naclcode::
3513
3514 AA == AbbrevIndex(A)
3515 VV1 == RelativeIndex(V1)
3516 VV2 == RelativeIndex(V2)
3517 T == TypeOf(V1) == TypeOf(V2)
3518 IsInteger(UnderlyingType(T)))
3519 N == NumValuedInsts
3520 NumBasicBlocks < ExpectedBasicBlocks
3521
3522 **Updates**
3523
3524 .. naclcode::
3525
3526 ++NumValuedInsts;
3527 TypeOf(%vN) = T
3528
3529 **Examples**
3530
3531 .. naclcode::
3532
3533 function i32 @f0(i32 %p0, i32 %p1) {
3534 blocks: 1;
3535 %b0:
3536 %v0 = or i32 %p0, %p1;
3537 %v1 = or i32 %v0, %p1;
3538 ret i32 %v1;
3539 }
3540
3541 The corresponding records are:
3542
3543 .. naclcode::
3544
3545 1: <65535, 12, 2>
3546 3: <1, 1>
3547 3: <2, 2, 1, 11>
3548 3: <2, 1, 2, 11>
3549 3: <10, 1>
3550 0: <65534>
3551
3552 Logical Xor
3553 ^^^^^^^^^^^
3554
3555 The *xor* instruction returns the bitwise logical exclusive or of its
3556 two operands.
3557
3558 **Syntax**
3559
3560 .. naclcode::
3561
3562 %vN = xor T V1, V2; <A>
3563
3564 **Record**
3565
3566 .. naclcode::
3567
3568 AA: <2, VV1, VV2, 12>
3569
3570 **Semantics**
3571
3572 This instruction performs a bitwise logical exclusive or of its
3573 arguments. Arguments *V1* and *V2*, and the result *%vN* must be of
3574 type *T*. *T* nust be an integral, or a vector of integrals. *N* is
3575 defined by the record position, defining the corresponding value
3576 generated by the instruction. *A* is the (optional) abbreviation
3577 associated with the corresponding record.
3578
3579 The truth table used for the *or* instruction is:
3580
3581 ===== ===== ======
3582 Arg 1 Arg 2 Result
3583 ===== ===== ======
3584 0 0 0
3585 0 1 1
3586 1 0 1
3587 1 1 0
3588 ===== ===== ======
3589
3590 **Constraints**
3591
3592 .. naclcode::
3593
3594 AA == AbbrevIndex(A)
3595 A1 == RelativeIndex(V1)
3596 A2 == RelativeIndex(V2)
3597 T == TypeOf(V1) == TypeOf(V2)
3598 IsInteger(UnderlyingType(T)))
3599 N == NumValuedInsts
3600 NumBasicBlocks < ExpectedBasicBlocks
3601
3602 **Updates**
3603
3604 .. naclcode::
3605
3606 ++NumValuedInsts;
3607 TypeOf(%vN) = T
3608
3609 **Examples**
3610
3611 .. naclcode::
3612
3613 function i32 @f0(i32 %p0, i32 %p1) {
3614 blocks: 1;
3615 %b0:
3616 %v0 = xor i32 %p0, %p1;
3617 %v1 = xor i32 %v0, %p1;
3618 ret i32 %v1;
3619 }
3620
3621 The corresponding records are:
3622
3623 .. naclcode::
3624
3625 1: <65535, 12, 2>
3626 3: <1, 1>
3627 3: <2, 2, 1, 12>
3628 3: <2, 1, 2, 12>
3629 3: <10, 1>
3630 0: <65534>
3631
3632 Floating Binary Instructions
jvoung (off chromium) 2014/06/06 20:09:15 Floating Point Binary?
Karl 2014/06/30 22:09:03 Done.
3633 ------------------------------
3634
3635 Floating Binary instructions require two operands of the same type, execute an
Jim Stichnoth 2014/06/06 18:24:49 Do you want binary capitalized?
Karl 2014/06/30 22:09:05 Done.
3636 operation on them, and produce a value. The value may represent multiple values
3637 if the type is a vector type. The result value always has the same type as its
3638 operands.
3639
3640 Float Add
3641 ^^^^^^^^^
3642
3643 The float add instruction returns the sum of its two arguments. Both arguments
3644 and the result must be of the same type. That type must be floating, or a
3645 floating vector type.
3646
3647 **Syntax**
3648
3649 .. naclcode::
3650
3651 %vN = add T V1, V2; <A>
3652
3653 **Record**
3654
3655 AA: <2, VV1, VV2, 0>
3656
3657 **Semantics**
3658
3659 The float add instruction returns the sum of its two arguments. Arguments *V1*
3660 and *V2* and the result *%vN* must be of type *T*. *T* must be a floating type,
3661 or a floating vector type. *N* is defined by the record position, defining the
3662 corresponding value generated by the instruction. *A* is the (optional)
3663 abbreviation associated with the corresponding record.
3664
3665 **Constraints**
3666
3667 .. naclcode::
3668
3669 AA == AbbrevIndex(A)
3670 VV1 == RelativeIndex(V1)
3671 VV2 == RelativeIndex(V2)
3672 T == TypeOf(V1) == TypeOf(V2)
3673 IsFloat(UnderlyingType(T))
3674 N == NumValuedInsts
3675 NumBasicBlocks < ExpectedBasicBlocks
3676
3677 **Updates**
3678
3679 .. naclcode::
3680
3681 ++NumValuedInsts;
3682 TypeOf(%vN) = T
3683
3684 **Examples**
3685
3686 .. naclcode::
3687
3688 function float @f0(float %p0, float %p1) {
3689 blocks: 1;
3690 %b0:
3691 %v0 = add float %p0, %p1;
3692 %v1 = add float %p0, %v0;
3693 ret float %v1;
3694 }
3695
3696 The corresponding records are:
3697
3698 .. naclcode::
3699
3700 1: <65535, 12, 2>
3701 3: <1, 1>
3702 3: <2, 2, 1, 0>
3703 3: <2, 3, 1, 0>
3704 3: <10, 1>
3705 0: <65534>
3706
3707 Float Subtract
3708 ^^^^^^^^^^^^^^
3709
3710 The floatsubtract instruction returns the difference of its two arguments. Both
Jim Stichnoth 2014/06/06 18:24:46 float subtract
Karl 2014/06/30 22:09:05 Done.
3711 arguments and the result must be of the same type. That type must be a floating,
3712 or an floating based vector type.
Jim Stichnoth 2014/06/06 18:24:48 an floating --> a floating
Karl 2014/06/30 22:09:05 Done.
3713
3714 **Syntax**
3715
3716 .. naclcode::
3717
3718 %vN = sub T V1, V2; <a>
3719
3720 **Record**
3721
3722 .. naclcode::
3723
3724 AA: <2, VV1, VV2, 1>
3725
3726 **Semantics**
3727
3728 The float subtract instruction returns the difference of its two
3729 arguments. Arguments *V1* and *V2*, and the result *%vN* must be of type
3730 *T*. *T* must be an floating type, or a floating vector type. *N* is defined by
Jim Stichnoth 2014/06/06 18:24:49 a floating
Karl 2014/06/30 22:09:05 Done.
3731 the record position, defining the corresponding value generated by the
3732 instruction. *A* is the (optional) abbreviation ¯associated with the
Jim Stichnoth 2014/06/06 18:24:49 You have an interesting unicode character between
Karl 2014/06/30 22:09:05 Done.
3733 corresponding record.
3734
3735 **Constraints**
3736
3737 .. naclcode::
3738
3739 AA == AbbrevIndex(A)
3740 VV1 == RelativeIndex(V1)
3741 VV2 == RelativeIndex(V2)
3742 T == TypeOf(V1) == TypeOf(V2)
3743 IsFloat(UnderlyingType(T))
3744 N == NumValuedInsts
3745 NumBasicBlocks < ExpectedBasicBlocks
3746
3747 **Updates**
3748
3749 .. naclcode::
3750
3751 ++NumValuedInsts;
3752 TypeOf(%vN) = T
3753
3754 **Examples**
3755
3756 .. naclcode::
3757
3758 function float @f0(float %p0, float %p1) {
3759 blocks: 1;
3760 %b0:
3761 %v0 = sub float %p0, %p1;
3762 %v1 = sub float %p0, %v0;
3763 ret float %v1;
3764 }
3765
3766 The corresponding records are:
3767
3768 .. naclcode::
3769
3770 1: <65535, 12, 2>
3771 3: <1, 1>
3772 3: <2, 2, 1, 1>
3773 3: <2, 3, 1, 1>
3774 3: <10, 1>
3775 0: <65534>
3776
3777 Float Multiply
3778 ^^^^^^^^^^^^^^
3779
3780 The float multiply instruction returns the product of its two arguments. Both
3781 arguments and the result must be of the same type. That type must be floating,
3782 or a floating based vector type.
3783
3784 **Syntax**
3785
3786 .. naclcode::
3787
3788 &vN = mul T V1, V2; <A>
3789
3790 **Record**
3791
3792 .. naclcode::
3793
3794 AA: <2, VV1, VV2, 2>
3795
3796 **Semantics**
3797
3798 The multiply instruction returns the product of its two arguments. Arguments
3799 *V1* and *V2*, and the result *%vN* must be of type *T*. *T* must be an
3800 floating type, or a floating vector type. *N* is defined by the record position,
3801 defining the corresponding value generated by the instruction. *A* is the
3802 (optional) abbreviation associated with the corresponding record.
3803
3804 **Constraints**
3805
3806 .. naclcode::
3807
3808 AA == AbbrevIndex(A)
3809 VV1 == RelativeIndex(V1)
3810 VV2 == RelativeIndex(V2)
3811 T == TypeOf(V1) == TypeOf(V2)
3812 IsFloat(UnderlyingType(T))
3813 N == NumValuedInsts
3814 NumBasicBlocks < ExpectedBasicBlocks
3815
3816 **Updates**
3817
3818 .. naclcode::
3819
3820 ++NumValuedInsts;
3821 TypeOf(%vN) = T
3822
3823 **Examples**
3824
3825 .. naclcode::
3826
3827 function float @f0(float %p0, float %p1) {
3828 blocks: 1;
3829 %b0:
3830 %v0 = mul float %p0, %p1;
3831 %v1 = mul float %p0, %v0;
3832 ret float %v1;
3833 }
3834
3835 The corresponding records are:
3836
3837 .. naclcode::
3838
3839 1: <65535, 12, 2>
3840 3: <1, 1>
3841 3: <2, 2, 1, 2>
3842 3: <2, 3, 1, 2>
3843 3: <10, 1>
3844 0: <65534>
3845
3846 Float Divide
3847 ^^^^^^^^^^^^
3848
3849 The float divide instruction returns the quotient of its two arguments. Both
3850 arguments and the result must be of the same type. That type must be a floating
3851 type, or a floating based vector type.
3852
3853 **Syntax**
3854
3855 .. naclcode::
3856
3857 %vN = div T V1, V2; <A>
3858
3859 **Record**
3860
3861 .. naclcode::
3862
3863 AA: <2, V1, V2, 4>
3864
3865 **Semantics**
3866
3867 The float divide instruction returns the quotient of its two
3868 arguments. Arguments *V1* and *V2*, and the result *%vN* must be of type
3869 *T*. *T* must be a floating type, or a floating vector type. *N* is defined by
3870 the record position, defining the corresponding value generated by the
3871 instruction. *A* is the (optional) abbreviation associated with the
3872 corresponding record.
3873
3874 **Constraints**
3875
3876 .. naclcode::
3877
3878 AA == AbbrevIndex(A)
3879 VV1 == RelativeIndex(V1)
3880 VV22 == RelativeIndex(V2)
3881 T == TypeOf(V1) == TypeOf(V2)
3882 IsFloat(UnderlyingType(T))
3883 N == NumValuedInsts
3884 NumBasicBlocks < ExpectedBasicBlocks
3885
3886 **Updates**
3887
3888 .. naclcode::
3889
3890 ++NumValuedInsts;
3891 TypeOf(%vN) = T
3892
3893 **Examples**
3894
3895 .. naclcode::
3896
3897 function double @f0(double %p0, double %p1) {
3898 blocks: 1;
3899 %b0:
3900 %v0 = div double %p0, %p1;
3901 %v1 = div double %p0, %v0;
3902 ret double %v1;
3903 }
3904
3905 The corresponding records are:
3906
3907 .. naclcode::
3908
3909 1: <65535, 12, 2>
3910 3: <1, 1>
3911 3: <2, 2, 1, 4>
3912 3: <2, 3, 1, 4>
3913 3: <10, 1>
3914 0: <65534>
3915
3916 Float Remainder
3917 ^^^^^^^^^^^^^^^
3918
3919 The float remainder instruction returns the remainder of the quotient of its two
3920 arguments. Both arguments and the result must be of the same type. That type
3921 must be a floating type, or a floating based vector type.
3922
3923 **Syntax**
3924
3925 .. naclcode::
3926
3927 %vN = rem T V1, V2; <A>
3928
3929 **Record**
3930
3931 .. naclcode::
3932
3933 AA: <2, VV1, VV2, 6>
3934
3935 **Semantics**
3936
3937 The float remainder instruction returns the remainder of the quotient of its two
3938 arguments. Arguments *V1* and *V2*, and the result *%vN* must be of type
3939 *T*. *T* must be a floating type, or a floating vector type. *N* is defined by
3940 the record position, defining the corresponding value generated by the
3941 instruction. *A* is the (optional) abbreviation associated with the
3942 corresponding record.
3943
3944 **Constraints**
3945
3946 .. naclcode::
3947
3948 AA == AbbrevIndex(A)
3949 VV1 == RelativeIndex(V1)
3950 VV2 == RelativeIndex(V2)
3951 T == TypeOf(V1) == TypeOf(V2)
3952 IsFloat(UnderlyingType(T))
3953 N == NumValuedInsts
3954 NumBasicBlocks < ExpectedBasicBlocks
3955
3956 **Updates**
3957
3958 .. naclcode::
3959
3960 ++NumValuedInsts;
3961 TypeOf(%vN) = T
3962
3963 **Examples**
3964
3965 .. naclcode::
3966
3967 function double @f0(double %p0, double %p1) {
3968 blocks: 1;
3969 %b0:
3970 %v0 = rem double %p0, %p1;
3971 %v1 = rem double %p0, %v0;
3972 ret double %v1;
3973 }
3974
3975 The corresponding records are:
3976
3977 .. naclcode::
3978
3979 1: <65535, 12, 2>
3980 3: <1, 1>
3981 3: <2, 2, 1, 6>
3982 3: <2, 3, 1, 6>
3983 3: <10, 1>
3984 0: <65534>
3985
3986 Memory creation and access Instructions
Jim Stichnoth 2014/06/06 18:24:47 Do something more consistent with capitalization.
3987 ---------------------------------------
3988
3989 A key design point of SSA-based representation is how it represents
3990 memory. In PNaCl bitcode files, no memory locations are in SSA
3991 form. This makes things very simple.
3992
3993 Alloca Instruction
3994 ^^^^^^^^^^^^^^^^^^
3995
3996 The *alloca* instruction allocates memory on the stack frame of the
3997 currently executing function. This memory is automatically released
3998 when the function returns to its caller.
3999
4000 **Syntax**
4001
4002 .. naclcode::
4003
4004 %vN = alloca i8, i32 S, align V; <A>
4005 %vN = alloca i8, i32 S; <A>
4006
4007 **Record**
4008
4009 .. naclcode::
4010
4011 AA: <19, SS, VV>
4012
4013 **Semantics**
4014
4015 The *alloca* instruction allocates memory on the stack frame of the currently
4016 executing function. The resulting value is a pointer to the allocated memory
4017 (i.e. of type i32). *S* is the number of bytes that are allocated on the
4018 stack. *S* must be of integral type i32. *V* is the aligment of the generated
Jim Stichnoth 2014/06/06 18:24:47 alignment
Karl 2014/06/30 22:09:05 Done.
4019 stack address. *A* is the corresponding number of bits associated with the
4020 record.
4021
4022 Alignment must be a power of 2. A value of 0 means that the address
4023 has the ABI alignment of the target. If alignment is not specified,
4024 zero is used. Alignment on the stack is guaranteed to be aligned to at least
4025 the boundary specified by the alignment.
4026
4027 TODO(kschimpf) Other alignment issues?
4028
4029 **Constraints**
4030
4031 .. naclcode::
4032
4033 AA == AbbrevIndex(A)
4034 VV == Log2(V+1)
4035 SS == RelativeIndex(S)
4036 i32 == TypeOf(S)
4037 N == NumValuedInsts
4038 NumBasicBlocks < ExpectedBasicBlocks
4039
4040 **Updates**
4041
4042 .. naclcode::
4043
4044 ++NumValuedInsts;
4045 TypeOf(%vN) = i32;
4046
4047 **Examples**
4048
4049 The following instructions allocates memory for a 32-bit integer and a
Jim Stichnoth 2014/06/06 18:24:48 instructions allocate
4050 64-bit floating value:
4051
4052 .. naclcode::
4053
4054 function void @f() {
4055 blocks: 1;
4056 constants {
4057 i32:
4058 %c0 = 4; // == sizeof(i32)
4059 %c1 = 8; // == sizeof(double)
4060 }
4061 %b0:
4062 %v0 = alloca i8, i32 %c0;
4063 %v1 = alloca i8, i32 %c1;
4064 ret;
4065 }
4066
4067 Assuming *TypeId(i32) == @t1*, the corresponding records are:
4068
4069 .. naclcode::
4070
4071 1: <65535, 12, 2>
4072 3: <1, 1>
4073 1: <65535, 11, 2>
4074 3: <1, 1>
4075 3: <4, 8>
4076 3: <4, 16>
4077 0: <65534>
4078 3: <19, 2, 0>
4079 3: <19, 2, 0>
4080 3: <10>
4081 0: <65534>
4082
4083 Load Instruction
4084 ^^^^^^^^^^^^^^^^
4085
4086 The *load* instruction is used to read from memory.
4087
4088 **Syntax**
4089
4090 .. naclcode::
4091
4092 %vN = load T* P, align V; <A>
4093
4094 **Record**
4095
4096 .. naclcode::
4097
4098 AA: <20, PP, VV, TT>
4099
4100 **Semantics**
4101
4102 The load instruction is used to read from memory. *P* is identifier of the
Jim Stichnoth 2014/06/06 18:24:48 is the identifier
Karl 2014/06/30 22:09:03 Done.
4103 memory address to read. The type of *P* must be an i32 integer. *T* is the type
4104 of value to read. *V* is the alignment of the memory address. *A* is the
jvoung (off chromium) 2014/06/06 20:09:14 Should we say more about alignment? What happens i
Karl 2014/06/30 22:09:05 Done.
4105 (optional) abbreviation associated with the record.
4106
4107 Type *T* must be an integral or floating type. Both float and double types
4108 are allowed for floating types. All integral types except i1 is allowed.
Jim Stichnoth 2014/06/06 18:24:47 are allowed
Karl 2014/06/30 22:09:03 Done.
4109
4110 Valid alignment *V* values are:
4111
4112 === =================
4113 *V* Types
4114 === =================
4115 1 i8, i16, i32, i64
4116 4 float
4117 8 double
4118 === =================
4119
4120 **Constraints**
4121
4122 AA == AbbrevIndex(A)
4123 i32 == TypeOf(P)
4124 PP == RelativeIndex(P)
4125 VV == Log2(V+1)
4126 %tTT == TypeID(T)
4127 N == NumValuedInsts
4128 NumBasicBlocks < ExpectedBasicBlocks
4129
4130 **Updates**
4131
4132 .. naclcode::
4133
4134 ++NumValuedInsts;
4135 TypeOf(%vN) = T;
4136
4137 **Examples**
4138
4139 The following instructions load an i32 integer and a 64-bit floating value:
4140
4141 .. naclcode::
4142
4143 function void @f(i32 %p0) {
4144 blocks: 1;
4145 %b0:
4146 %v0 = load i32* %p0, align 1;
4147 %v1 = load double* %v0, align 8;
4148 ret;
4149 }
4150
4151 The corresponding records are:
4152
4153 .. naclcode::
4154
4155 1: <65535, 12, 2>
4156 3: <1, 1>
4157 3: <20, 1, 1>
4158 3: <20, 1, 4>
4159 3: <10>
4160 0: <65534>
4161
4162 Store Instruction
4163 ^^^^^^^^^^^^^^^^^
4164
4165 The *store* instruction is used to write to memory.
4166
4167 **Syntax**
4168
4169 .. naclcode::
4170
4171 store T S, T* P, align V; <A>
4172
4173 **Record**
4174
4175 .. naclcode::
4176
4177 AA: <24, PP, SS, VV>
4178
4179 **Semantics**
4180
4181 The store instruction is used to write to memory. *P* is the identifier of the
4182 memory address to write to. The type of *P* must be an i32 integer. *T* is the
4183 type of value to store. *S* is the value to store, and must be of type *T*. *V*
4184 is the alignment of the memory address. *A* is the (optional) abbreviation
4185 index associated with the record.
4186
4187 Type *T* must be an integral or floating type. Both float and double types
4188 are allowed for floating types. All integral types except i1 is allowed.
Jim Stichnoth 2014/06/06 18:24:46 are allowed
Karl 2014/06/30 22:09:03 Done.
4189
4190 Valid alignment *V* values are:
4191
4192 === =================
4193 *V* Types
4194 === =================
4195 1 i8, i16, i32, i64
4196 4 float
4197 8 double
4198 === =================
4199
4200 **Constraints**
4201
4202 .. naclcode::
4203
4204 AA == AbbrevIndex(A)
4205 i32 == TypeOf(P)
4206 PP == RelativeIndex(P)
4207 VV == Log2(V+1)
4208 NumBasicBlocks < ExpectedBasicBlocks
4209
4210 **Examples**
4211
4212 The following instructions store an i32 integer and a 32-bit floating
4213 value.
4214
4215 .. naclcode::
4216
4217 function void @f(i32 %p0, i32 %p1, i32 %p2, float %p3) {
4218 blocks: 1;
4219 %b0:
4220 store i32 %p1, i32* %p2, align 1;
4221 store float %p3, float* %p3, align 4;
4222 ret;
4223 }
4224
4225 The corresponding records are:
4226
4227 .. naclcode::
4228
4229 1: <65535, 12, 2>
4230 3: <1, 1>
4231 3: <24, 4, 3, 1>
4232 3: <24, 1, 2, 4>
4233 3: <10>
4234 0: <65534>
4235
4236 Conversion Instructions
4237 -----------------------
4238
4239 Conversion instructions all take a single operand and a type. The
4240 value is converted to the corresponding type.
4241
4242 Integer truncating Instruction
Jim Stichnoth 2014/06/06 18:24:48 capitalization?
Karl 2014/06/30 22:09:06 Done.
4243 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4244
4245 The integer truncating instruction takes a value to truncate, and a type
4246 defining the truncated type. Both types must be integer types, or integral
4247 vectors of the same size. The bit size of the value must be larger than the bit
4248 size of the destination type. Equal sized types are not allowed.
4249
4250 **Syntax**
4251
4252 .. naclcode::
4253
4254 %vN = trunc T1 V to T2; <A>
4255
4256 **Record**
4257
4258 .. naclcode::
4259
4260 AA: <3, VV, TT2, 0>
4261
4262 **Semantics**
4263
4264 The integer truncating instruction takes a value *V*, and truncates to type
4265 *T2*. *A* is the (optional) abbreviation associated with the corresponding
4266 record. Both *T1* and *T2* must be integer types, or integral vectors of the
jvoung (off chromium) 2014/06/06 20:09:14 same number of elements instead of same "size" ?
Karl 2014/06/30 22:09:04 This was implied by the constratiants, but I agree
4267 same size.
4268
4269 **Constraints**
4270
4271 .. naclcode::
4272
4273 AA == AbbrevIndex(A)
4274 TypeOf(V) = T1
jvoung (off chromium) 2014/06/06 20:09:15 Earlier you use == for these TypeOf constraints, b
Karl 2014/06/30 22:09:05 You are right. I am inconsistent with this. Fixing
4275 *VV* == RelativeIndex(*V*)
4276 %tTT2 = TypeID(T2)
4277 BitSizeOf(UnderlyingType(T1)) > BitSizeOf(UnderlyingType(T2))
4278 UnderlyingCount(T1) == UnderlyingCount(T2)
4279 IsInteger(UnderlyingType(T1))
4280 IsInteger(UnderlyingType(T2))
4281 N == NumValuedInsts
4282 NumBasicBlocks < ExpectedBasicBlocks
4283
4284 **Updates**
4285
4286 .. naclcode::
4287
4288 ++NumValuedInsts;
4289 TypeOf(%vN) = T2;
4290
4291 **Examples**
4292
4293 .. naclcode::
4294
4295 %v10 = trunc i32 %v9 to i8;
4296
4297 Assuming
4298
4299 .. naclcode::
4300
4301 @t2 = i8;
4302
4303 the corresponding record is:
4304
4305 .. naclcode::
4306
4307 <3, 1, 2, 0>
4308
4309 Floating truncating Instruction
Jim Stichnoth 2014/06/06 18:24:49 capitalization?
4310 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4311
4312 The floating truncating instruction takes a value to truncate, and a type
4313 defining the truncated type. Both types must be floating types, or floating
4314 vectors of the same size. The bit size of the value must be larger than the bit
4315 size of the destination type. Equal sized types are not allowed.
4316
4317 **Syntax**
4318
4319 .. naclcode::
4320
4321 %vN = fptrunc T1 V to T2; <A>
4322
4323 **Record**
4324
4325 .. naclcode::
4326
4327 AA: <3, VV, TT2, 7>
4328
4329 **Semantics**
4330
4331 The floating truncating instruction takes a value *V*, and truncates to type
4332 *T2*. *A* is the (optional) abbreviation associated with the corresponding
4333 record. Both *T1* and *T2* must be integer types, or integral vectors of the
jvoung (off chromium) 2014/06/06 20:09:14 floating point types / vectors (seems copy pasted
Karl 2014/06/30 22:09:04 Done.
4334 same size.
4335
4336 If the value can't fit within the destination type *T2*, the results are
4337 undefined.
4338
4339 **Constraints**
4340
4341 .. naclcode::
4342
4343 TypeOf(V) = T1
4344 double == UnderlyingType(T1)
4345 float == UnderlyingType(T2)
4346 *VV* == RelativeIndex(*V*)
4347 %tTT2 = TypeID(T2)
4348 BitSizeOf(UnderlyingType(T1)) > BitSizeOf(UnderlyingType(T2))
4349 UnderlyingCount(T1) == UnderlyingCount(T2)
4350 IsFloat(UnderlyingType(T1))
4351 IsFloat(UnderlyingType(T2))
4352 N == NumValuedInsts
4353 NumBasicBlocks < ExpectedBasicBlocks
4354
4355 **Updates**
4356
4357 .. naclcode::
4358
4359 ++NumValuedInsts;
4360 TypeOf(%vN) = T2;
4361
4362 **Examples**
4363
4364 .. naclcode::
4365
4366 %v10 = fptrunc double %v9 to float;
4367
4368 Assuming
4369
4370 .. naclcode::
4371
4372 @t4 = float;
4373
4374 the corresponding record is:
4375
4376 .. naclcode::
4377
4378 <3, 1, 4, 7>
4379
4380 Zero Extending Instruction
4381 ^^^^^^^^^^^^^^^^^^^^^^^^^^
4382
4383 The zero extending instruction takes an value to cast, and a type to extend it
Jim Stichnoth 2014/06/06 18:24:47 a value
4384 to. Both types must be integer types, or integral vectors of the same size. The
4385 bit size of the value must be smaller than the bitsize of the destination
Jim Stichnoth 2014/06/06 18:24:47 bitsize --> bit size
Karl 2014/06/30 22:09:05 Done.
4386 type. Equal sized types are not allowed.
4387
4388 **Syntax**
4389
4390 .. naclcode::
4391
4392 %vN = zext T1 V to T2; <A>
4393
4394 **Record**
4395
4396 .. naclcode::
4397
4398 AA: <3, VV, TT2, 1>
4399
4400
4401 **Semantics**
4402
4403 The zero extending instruction takes a value *V*, and expands it to type
4404 *T2*. *I* is the (optional) abbreviation associated with the corresponding
4405 record. Both *T1* and *T2* must be integer types, or vectors of the same number
4406 of integers.
4407
4408 The instruction fills the high order bits of the value with zero bits
4409 until it reaches the size of the destination type. When zero extending
4410 from i1, the result will always be either 0 or 1.
4411
4412 **Constraints**
4413
4414 .. naclcode::
4415
4416 AA == AbbrevIndex(A)
4417 TypeOf(V) = T1
4418 *VV* == RelativeIndex(*V*)
4419 %tTT2 = TypeID(T2)
4420 BitSizeOf(UnderlyingType(T1)) < BitSizeOf(UnderlyingType(T2))
4421 UnderlyingCount(T1) == UnderlyingCount(T2)
4422 IsInteger(UnderlyingType(T1))
4423 IsInteger(UnderlyingType(T2))
4424 N == NumValuedInsts
4425 NumBasicBlocks < ExpectedBasicBlocks
4426
4427 **Updates**
4428
4429 .. naclcode::
4430
4431 ++NumValuedInsts;
4432 TypeOf(%vN) = T2;
4433
4434 **Examples**
4435
4436 .. naclcode::
4437
4438 %v12 = zext i8 %v11 to i32;
4439
4440 Assuming
4441
4442 .. naclcode::
4443
4444 @t0 = i32;
4445
4446 the corresponding record is:
4447
4448 .. naclcode::
4449
4450 <3, 1, 0, 2>
4451
4452 Sign Extending Instruction
4453 ^^^^^^^^^^^^^^^^^^^^^^^^^^
4454
4455 The sign extending instruction takes an value to cast, and a type to
Jim Stichnoth 2014/06/06 18:24:47 a value
Karl 2014/06/30 22:09:04 Done.
4456 extend it to. Both types must be integer types, or vectors of the same
4457 number of integers. The bit size of the value must be smaller than the
4458 bitsize of the destination type. Equal sized types are not allowed.
Jim Stichnoth 2014/06/06 18:24:47 bit size
Karl 2014/06/30 22:09:04 Done.
4459
4460 **Syntax**
4461
4462 .. naclcode::
4463
4464 %vN = sext T1 V to T2; <I>
4465
4466 **Record**
4467
4468 .. naclcode::
4469
4470 I: <3, VV, TT2, 2>
4471
4472
4473 **Semantics**
4474
4475 The sign extending instruction takes a value *V*, and expands it to
4476 type *T2*. *VV* is the relative index of *V*. *I* is the (optional)
4477 abbreviation associated with the corresponding record. Both *T1* and
4478 *T2* must be integer types, or vectors of the same number of integers.
4479
4480 When sign extending, the instruction fills the high order bits of the
4481 value with the (current) high order bit of the value. When sign
4482 extending from i1, the extension always results in -1 or 0.
4483
4484 **Constraints**
4485
4486 .. naclcode::
4487
4488 TypeOf(V) = T1
4489 *VV* == RelativeIndex(*V*)
4490 %tTT2 = TypeID(T2)
4491 BitSizeOf(UnderlyingType(T1)) < BitSizeOf(UnderlyingType(T2))
4492 UnderlyingCount(T1) == UnderlyingCount(T2)
4493 IsInteger(UnderlyingType(T1))
4494 IsInteger(UnderlyingType(T2))
4495 N == NumValuedInsts
4496 NumBasicBlocks < ExpectedBasicBlocks
4497
4498 **Updates**
4499
4500 .. naclcode::
4501
4502 ++NumValuedInsts;
4503 TypeOf(%vN) = T2;
4504
4505 **Examples**
4506
4507 .. naclcode::
4508
4509 %v12 = sext i8 %v11 to i32;
4510
4511 Assuming
4512
4513 .. naclcode::
4514
4515 @t0 = i32;
4516
4517 the corresponding record is:
4518
4519 .. naclcode::
4520
4521 <3, 1, 0, 2>
4522
4523 fpext
4524 ^^^^^
4525
4526 TODO(kschimpf)
4527
4528 fptoui
4529 ^^^^^^
4530
4531 TODO(kschimpf)
4532
4533 fptosi
4534 ^^^^^^
4535
4536 TODO(kschimpf)
4537
4538 sitofp
4539 ^^^^^^
4540
4541 TODO(kschimpf)
4542
4543 bitcast
4544 ^^^^^^^
4545
4546 TODO(kschimpf)
4547
4548 Comparison Instructions
4549 -----------------------
4550
4551 TODO(kschimpf): cmp
4552
4553 Other Instructions
4554 ------------------
4555
4556 TODO(kschimpf)
4557
4558 Forward type declarations
4559 ^^^^^^^^^^^^^^^^^^^^^^^^^
4560
4561 TODO(kschimpf)
4562
4563 Phi Instruction
4564 ^^^^^^^^^^^^^^^
4565
4566 TODO(kschimpf)
4567
4568
4569 Select Instruction
4570 ^^^^^^^^^^^^^^^^^^
4571
4572 TODO(kschimpf)
4573
4574 Call Instructions
4575 ^^^^^^^^^^^^^^^^^
4576
4577 TODO(kschimpf)
4578
4579 Intrinsic Functions
4580 -------------------
4581
4582 TODO(kschimpf)
4583
4584 Support Functions
4585 =================
4586
4587 Defines functions used to convert syntactic representation to corresponding
4588 records.
4589
4590 SignRotate
4591 ----------
4592
4593 The SignRotate function encodes a signed integer in an easily compressable
Jim Stichnoth 2014/06/06 18:24:48 compressible
Karl 2014/06/30 22:09:04 Done.
4594 form. This is done by rotating the sign bit to the rightmost bit, rather than
4595 the leftmost bit. By doing this rotation, both small positive and negative
4596 integers are small (unsigned) integers. Therefore, all small integers can be
4597 encoded as a small (unsigned) integers.
4598
4599 The definition of SignRotate(N) is:
4600
4601 ======== ============= =========
4602 Argument Value Condition
4603 ======== ============= =========
4604 N abs(N)<<1 N >= 0
4605 N abs(N)<<1 + 1 N < 0
4606 ======== ============= =========
4607
4608 AbsoluteIndex
4609 -------------
4610
4611 Bitcode ID's of the forms *@fN*, *@gN*, *%pN*, *%cN*, and *%vN*, are combined
4612 into a single index space. This can be done because of the ordering imposed by
4613 PNaClAsm. All function address bitcode IDs must be defined before any of the
4614 other forms of bitcode IDs. All global address bitcode IDs must be defined
4615 before any local bitcode IDs. Within a function block, the parameter bitcode IDs
4616 must be defined before constant IDs, and constant IDs must be defined before
4617 instruction value IDs.
4618
4619 Hence, within a function block, it is safe to refer to all of these
4620 bitcode IDs using a single *absolute* index. The absolute index for
4621 each kind of bitcode ID is computed as follows:
4622
4623 ========== ===================================================================== =====
4624 Bitcode ID AbsoluteIndex
4625 ========== ===================================================================== =====
4626 @fN N
4627 @gN N + NumDefinedFcnAddresses
4628 @pN N + NumDefinedFcnAddresses + NumGlobalAddresses
4629 @cN N + NumDefinedFcnAddresses + NumGlobalAddresses + NumParams
4630 @vN N + NumDefinedFcnAddresses + NumGlobalAddresses + NumParams + NumFcnC onsts
4631 ========== ===================================================================== =====
4632
4633 RelativeIndex
4634 -------------
4635
4636 Relative indices are used to refer to values within instructions of a
4637 function. The relative index of an ID is always defined in terms of
4638 the index associated with the next value generating instruction. It is
4639 defined as follows:
4640
4641 .. naclcode::
4642
4643 RelativeIndex(J) = AbsoluteIndex(NumValuedInsts) - AbsoluteIndex(J)
4644
4645 AbbrevIndex
4646 -----------
4647
4648 This function converts user-defined abbreviation indices to the corresponding
4649 internal abbreviation index saved in the bitcode file. It adds 4 to its argument ,
Jim Stichnoth 2014/06/06 18:24:47 80-col
Karl 2014/06/30 22:09:03 Done.
4650 since there are 4 predefined internal abbreviation indices (0, 1, 2, and 3).
4651
4652 ========= ==============
4653 N AbbrevIndex(N)
4654 ========= ==============
4655 undefined 3
4656 %aA A + 4
4657 @aA A + 4
4658 ========= ==============
4659
4660 Log2
4661 ----
4662
4663 This is the 32-bit log2 value of its argument.
4664
4665 exp
4666 ---
4667
4668 .. naclcode::
4669
4670 exp(n, m)
4671
4672 Denotes the *m* power of *n*.
4673
4674 BitSizeOf
4675 ---------
4676
4677 Returns the number of bits needed to represent its argument (a type).
4678
4679 UnderlyingType
4680 --------------
4681
4682 Returns the primitive type of the type construct. For primitive types,
4683 the *UnderlyingType* is itself. For vector types, the base type of the
4684 vector is the underlying type.
Jim Stichnoth 2014/06/06 18:24:47 What if the type is a vector of vectors? (or is t
Karl 2014/06/30 22:09:06 This isn't possible.
4685
4686 UnderlyingCount
4687 ---------------
4688
4689 Returns the number of primitive types in the construct. For primitive
4690 types, the *UnderlyingCount* is 1. For vector types, it returns the
4691 number of elements in the vector.
4692
4693 IsInteger
4694 ---------
4695
4696 Returns true if the argument is in {i1, i8, i16, i32, i64}.
4697
4698 IsFloat
4699 -------
4700
4701 Returns true if the argument is in {float, double}.
4702
4703 Abbreviations
4704 -------------
4705
4706 TODO(kschimpf)
4707
4708 Introduction
4709 ^^^^^^^^^^^^
4710
4711 TODO(kschimpf)
4712
4713 * Blocks
4714 * Data Records
4715 * Abbreviations
4716 * Abbreviation Ids.
4717
4718 Bitstream Format
4719 ^^^^^^^^^^^^^^^^
4720
4721 TODO(kschimpf)
4722
4723 * Header
4724 * Block Structure
4725 * Primitives
4726 * Abbreviations
4727 * BlockInfoBlock
4728
4729 The *abbreviations block* [ref] is the first block in the module buld.. The
Jim Stichnoth 2014/06/06 18:24:46 buld?
Karl 2014/06/30 22:09:03 Done.
4730 block is divided into sections. Each section is a sequence of records. Each
4731 record in the sequence defines a user-defined abbreviation. Each section
4732 defines abbreviations that can be applied to all (succeeding) blocks of a
4733 particular kind. These abbreviations are denoted by the (global) ID of the form
4734 *@aN*.
4735
4736 Reference Implementation
4737 ------------------------
4738
4739 TODO(kschimpf)
4740
OLDNEW
« no previous file with comments | « native_client_sdk/src/doc/_book.yaml ('k') | native_client_sdk/src/doc/sitemap.rst » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698