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

Side by Side Diff: native_client_sdk/doc_generated/reference/pnacl-bitcode-manual.html

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
OLDNEW
(Empty)
1 {{+bindTo:partials.standard_nacl_article}}
2
3 <section id="pnacl-bitcode-file-reference-manual">
4 <h1 id="pnacl-bitcode-file-reference-manual">PNaCl Bitcode File Reference Manual </h1>
5 <div class="contents local" id="contents" style="display: none">
6 <ul class="small-gap">
7 <li><a class="reference internal" href="#introduction" id="id5">Introduction</a> </li>
8 <li><a class="reference internal" href="#data-model" id="id6">Data Model</a></li >
9 <li><a class="reference internal" href="#high-level-basics" id="id7">High Level Basics</a></li>
10 <li><a class="reference internal" href="#pnacl-blocks" id="id8">PNaCl Blocks</a> </li>
11 <li><a class="reference internal" href="#pnacl-records" id="id9">PNaCl Records</ a></li>
12 <li><a class="reference internal" href="#conventions-for-describing-records" id= "id10">Conventions for describing records</a></li>
13 <li><a class="reference internal" href="#factorial-example" id="id11">Factorial Example</a></li>
14 <li><p class="first"><a class="reference internal" href="#parse-state" id="id12" >Parse State</a></p>
15 <ul class="small-gap">
16 <li><a class="reference internal" href="#typing" id="id13">Typing</a></li>
17 <li><a class="reference internal" href="#id-counters" id="id14">ID Counters</a>< /li>
18 <li><a class="reference internal" href="#size-variables" id="id15">Size Variable s</a></li>
19 <li><a class="reference internal" href="#other-variables" id="id16">Other Variab les</a></li>
20 </ul>
21 </li>
22 <li><p class="first"><a class="reference internal" href="#special-records" id="i d17">Special records</a></p>
23 <ul class="small-gap">
24 <li><a class="reference internal" href="#header-record" id="id18">Header Record< /a></li>
25 <li><a class="reference internal" href="#enter-block-record" id="id19">Enter Blo ck Record</a></li>
26 <li><a class="reference internal" href="#exit-block-record" id="id20">Exit Block Record</a></li>
27 </ul>
28 </li>
29 <li><p class="first"><a class="reference internal" href="#types-block" id="id21" >Types Block</a></p>
30 <ul class="small-gap">
31 <li><a class="reference internal" href="#count-record" id="id22">Count Record</a ></li>
32 <li><a class="reference internal" href="#void-type" id="id23">Void Type</a></li>
33 <li><a class="reference internal" href="#integer-types" id="id24">Integer Types< /a></li>
34 <li><a class="reference internal" href="#bit-floating-type" id="id25">32-Bit Flo ating Type</a></li>
35 <li><a class="reference internal" href="#id1" id="id26">64-bit Floating Type</a> </li>
36 <li><a class="reference internal" href="#vector-types" id="id27">Vector Types</a ></li>
37 <li><a class="reference internal" href="#function-type" id="id28">Function Type< /a></li>
38 </ul>
39 </li>
40 <li><p class="first"><a class="reference internal" href="#globals-block" id="id2 9">Globals block</a></p>
41 <ul class="small-gap">
42 <li><a class="reference internal" href="#id2" id="id30">Count Record</a></li>
43 <li><a class="reference internal" href="#global-variable-addressses" id="id31">G lobal Variable Addressses</a></li>
44 <li><a class="reference internal" href="#global-constant-addresses" id="id32">Gl obal Constant Addresses</a></li>
45 <li><a class="reference internal" href="#zerofill-initializer" id="id33">Zerofil l Initializer</a></li>
46 <li><a class="reference internal" href="#data-initializer" id="id34">Data Initia lizer</a></li>
47 <li><a class="reference internal" href="#relocation-initializer" id="id35">Reloc ation Initializer</a></li>
48 <li><a class="reference internal" href="#subfield-relocation-initializer" id="id 36">Subfield Relocation Initializer</a></li>
49 <li><a class="reference internal" href="#compound-initializer" id="id37">Compoun d Initializer</a></li>
50 </ul>
51 </li>
52 <li><a class="reference internal" href="#valuesymtab-block" id="id38">Valuesymta b Block</a></li>
53 <li><p class="first"><a class="reference internal" href="#module-block" id="id39 ">Module Block</a></p>
54 <ul class="small-gap">
55 <li><a class="reference internal" href="#version" id="id40">Version</a></li>
56 <li><a class="reference internal" href="#function-address" id="id41">Function Ad dress</a></li>
57 </ul>
58 </li>
59 <li><a class="reference internal" href="#constants-blocks" id="id42">Constants B locks</a></li>
60 <li><p class="first"><a class="reference internal" href="#function-blocks" id="i d43">Function Blocks</a></p>
61 <ul class="small-gap">
62 <li><a class="reference internal" href="#function-enter" id="id44">Function ente r</a></li>
63 <li><a class="reference internal" href="#id3" id="id45">Count Record</a></li>
64 <li><p class="first"><a class="reference internal" href="#terminator-instruction s" id="id46">Terminator Instructions</a></p>
65 <ul class="small-gap">
66 <li><a class="reference internal" href="#return-void-instruction" id="id47">Retu rn Void Instruction</a></li>
67 <li><a class="reference internal" href="#return-value-instruction" id="id48">Ret urn Value Instruction</a></li>
68 <li><a class="reference internal" href="#unconditional-branch-instruction" id="i d49">Unconditional Branch Instruction</a></li>
69 <li><a class="reference internal" href="#conditional-branch-instruction" id="id5 0">Conditional Branch Instruction</a></li>
70 <li><a class="reference internal" href="#unreachable" id="id51">Unreachable</a>< /li>
71 <li><a class="reference internal" href="#switch-instruction" id="id52">Switch In struction</a></li>
72 </ul>
73 </li>
74 <li><p class="first"><a class="reference internal" href="#integer-binary-inststr uctions" id="id53">Integer Binary Inststructions</a></p>
75 <ul class="small-gap">
76 <li><a class="reference internal" href="#integer-add" id="id54">Integer Add</a>< /li>
77 <li><a class="reference internal" href="#integer-subtract" id="id55">Integer Sub tract</a></li>
78 <li><a class="reference internal" href="#integer-multiply" id="id56">Integer Mul tiply</a></li>
79 <li><a class="reference internal" href="#signed-integer-divide" id="id57">Signed Integer Divide</a></li>
80 <li><a class="reference internal" href="#unsigned-integer-divide" id="id58">Unsi gned Integer Divide</a></li>
81 <li><a class="reference internal" href="#signed-integer-remainder" id="id59">Sig ned Integer Remainder</a></li>
82 <li><a class="reference internal" href="#unsigned-integer-remainder-instruction" id="id60">Unsigned Integer Remainder Instruction</a></li>
83 <li><a class="reference internal" href="#shift-left" id="id61">Shift left</a></l i>
84 <li><a class="reference internal" href="#logical-shift-right" id="id62">Logical Shift right</a></li>
85 <li><a class="reference internal" href="#arithmetic-shift-right" id="id63">Arith metic Shift Right</a></li>
86 <li><a class="reference internal" href="#logical-and" id="id64">Logical And</a>< /li>
87 <li><a class="reference internal" href="#logical-or" id="id65">Logical Or</a></l i>
88 <li><a class="reference internal" href="#logical-xor" id="id66">Logical Xor</a>< /li>
89 </ul>
90 </li>
91 <li><p class="first"><a class="reference internal" href="#floating-binary-instst ructions" id="id67">Floating Binary Inststructions</a></p>
92 <ul class="small-gap">
93 <li><a class="reference internal" href="#float-add" id="id68">Float Add</a></li>
94 <li><a class="reference internal" href="#float-subtract" id="id69">Float Subtrac t</a></li>
95 <li><a class="reference internal" href="#float-multiply" id="id70">Float Multipl y</a></li>
96 <li><a class="reference internal" href="#float-divide" id="id71">Float Divide</a ></li>
97 <li><a class="reference internal" href="#float-remainder" id="id72">Float Remain der</a></li>
98 </ul>
99 </li>
100 <li><p class="first"><a class="reference internal" href="#memory-creation-and-ac cess-instructions" id="id73">Memory creation and access Instructions</a></p>
101 <ul class="small-gap">
102 <li><a class="reference internal" href="#alloca-instruction" id="id74">Alloca In struction</a></li>
103 <li><a class="reference internal" href="#load-instruction" id="id75">Load Instru ction</a></li>
104 <li><a class="reference internal" href="#store-instruction" id="id76">Store Inst ruction</a></li>
105 </ul>
106 </li>
107 <li><p class="first"><a class="reference internal" href="#conversion-instruction s" id="id77">Conversion Instructions</a></p>
108 <ul class="small-gap">
109 <li><a class="reference internal" href="#integer-truncating-instruction" id="id7 8">Integer truncating Instruction</a></li>
110 <li><a class="reference internal" href="#floating-truncating-instruction" id="id 79">Floating truncating Instruction</a></li>
111 <li><a class="reference internal" href="#zero-extending-instruction" id="id80">Z ero Extending Instruction</a></li>
112 <li><a class="reference internal" href="#sign-extending-instruction" id="id81">S ign Extending Instruction</a></li>
113 <li><a class="reference internal" href="#fpext" id="id82">fpext</a></li>
114 <li><a class="reference internal" href="#fptoui" id="id83">fptoui</a></li>
115 <li><a class="reference internal" href="#fptosi" id="id84">fptosi</a></li>
116 <li><a class="reference internal" href="#sitofp" id="id85">sitofp</a></li>
117 <li><a class="reference internal" href="#bitcast" id="id86">bitcast</a></li>
118 </ul>
119 </li>
120 <li><a class="reference internal" href="#comparison-instructions" id="id87">Comp arison Instructions</a></li>
121 <li><p class="first"><a class="reference internal" href="#other-instructions" id ="id88">Other Instructions</a></p>
122 <ul class="small-gap">
123 <li><a class="reference internal" href="#phi-instruction" id="id89">Phi Instruct ion</a></li>
124 <li><a class="reference internal" href="#forward-type-declarations" id="id90">Fo rward type declarations</a></li>
125 <li><a class="reference internal" href="#select-instruction" id="id91">Select In struction</a></li>
126 <li><a class="reference internal" href="#call-instructions" id="id92">Call Instr uctions</a></li>
127 </ul>
128 </li>
129 <li><a class="reference internal" href="#intrinsic-functions" id="id93">Intrinsi c Functions</a></li>
130 </ul>
131 </li>
132 <li><p class="first"><a class="reference internal" href="#support-functions" id= "id94">Support Functions</a></p>
133 <ul class="small-gap">
134 <li><a class="reference internal" href="#signrotate" id="id95">SignRotate</a></l i>
135 <li><a class="reference internal" href="#absoluteindex" id="id96">AbsoluteIndex< /a></li>
136 <li><a class="reference internal" href="#relativeindex" id="id97">RelativeIndex< /a></li>
137 <li><a class="reference internal" href="#abbrevindex" id="id98">AbbrevIndex</a>< /li>
138 <li><a class="reference internal" href="#log2" id="id99">Log2</a></li>
139 <li><a class="reference internal" href="#exp" id="id100">exp</a></li>
140 <li><a class="reference internal" href="#bitsizeof" id="id101">BitSizeOf</a></li >
141 <li><a class="reference internal" href="#underlyingtype" id="id102">UnderlyingTy pe</a></li>
142 <li><a class="reference internal" href="#underlyingcount" id="id103">UnderlyingC ount</a></li>
143 <li><a class="reference internal" href="#isinteger" id="id104">IsInteger</a></li >
144 <li><a class="reference internal" href="#isfloat" id="id105">IsFloat</a></li>
145 <li><p class="first"><a class="reference internal" href="#abbreviations" id="id1 06">Abbreviations</a></p>
146 <ul class="small-gap">
147 <li><a class="reference internal" href="#id4" id="id107">Introduction</a></li>
148 <li><a class="reference internal" href="#bitstream-format" id="id108">Bitstream Format</a></li>
149 </ul>
150 </li>
151 <li><a class="reference internal" href="#reference-implementation" id="id109">Re ference Implementation</a></li>
152 </ul>
153 </li>
154 </ul>
155
156 </div><section id="introduction">
157 <h2 id="introduction">Introduction</h2>
158 <p>This document is a reference manual for the contents of PNaCl bitcode files. It
159 is presented using assembly language <em>PNaClAsm</em>. PNaClAsm uses a <em>stat ic single
160 assignment</em> (SSA) based representation that requires generated results to ha ve a
161 single (assignment) source. PNaClAsm is the textual version of the bitcode file. </p>
162 <p>PNaClAsm focusses on the semantic content of the file, not the bit-encoding o f
163 that content. However, it does provide annotations that allow one to specify
164 how the PNaCl bitcode writer converts the semantic content of a PNaClAsm
165 program, into a specific bit sequence.</p>
166 <p>Below PNaClAsm is the high-level form of the data stored in PNaCl bitcode
167 files. Each construct in PNaClAsm defines a corresponding <em>PNaCl record</em> [ref].
168 A PNaCl bitcode file is simply a sequence of PNaCl records. The goal of PNaClAsm
169 is to make records easier to read, and not to define a high-level user
170 programming language.</p>
171 <p>PNaCl records are an abstract encoding of structured data, similar to XML. Li ke
172 XML, PNaCl records have a notion of tags (i.e. the first element in a record,
173 called a <em>code</em>), and nested structures. The nested structures are define d by
174 corresponding <em>enter</em> and <em>exit</em> block records.</p>
175 <p>These block records must be used like parentheses to define the block structu re
176 that is imposed on top of records. Each exit record must be preceded by a
177 corresponding enter record. Blocks can be nested by nesting enter/exit records
178 appropriately.</p>
179 <p>The <em>PNaCl bitcode writer</em> takes the sequence of records, defined by a PNaClAsm
180 program, and converts each record into a (variable) sequence of bits. The output
181 of each bit sequence is appended together. The resulting generated sequence of
182 bits is the contents of the PNaCl bitcode file.</p>
183 <p>For every kind of record, there is a default method for converting records in to
184 bit sequences. These methods correspond to a notion of <em>abbreviations</em>
185 [ref]. Each abbreviation defines a specific bit sequence conversion to be
186 applied. The default conversion methods are simply predefined abbreviations.</p>
187 <p>The default abbreviations can be overridden with user-specified abbreviations .
188 All user-specified abbreviations are included in the generated bitcode
189 file. Each abbreviation defines how a record is converted to a bit sequences. Th e
190 <em>PNaCl bitcode writer</em> uses these abbreviations to convert the correspond ing
191 record sequence into a corresponding bit sequence. As a result, all records have
192 an abbreviation (user or default) associated with them.</p>
193 <p>The <em>PNaCl bitcode reader</em> then uses these abbreviations to convert th e bit
194 sequences back into the corresponding records.</p>
195 <p>Conceptually, abbreviations are used to define how to pack the contents of
196 records into bit sequences. The main reason for defining abbreviations is to
197 save space. The default abbreviations are simplistic and are intended to handle
198 all possible records. The default abbreviations do not really worry about being
199 efficient, in terms of the number of bits generated.</p>
200 <p>By separating the concepts of PNaCl records and abbreviations, the notion of
201 data compression is cleanly separated from semantic content. This allows
202 different use cases to decide how much effort should be spent on compressing
203 records.</p>
204 <p>For a JIT compiler that produces bitcode, little (if any) compression should be
205 applied. In fact, the API to the JIT may just be the records themselves. The
206 goal of a JIT is to perform the final translation to machine code as quickly as
207 possible. On the other hand, when delivering across the web, one may want to
208 compress the sequence of bits considerably, to reduce costs in delivering web
209 pages.</p>
210 </section><section id="data-model">
211 <h2 id="data-model">Data Model</h2>
212 <p>The data model for PNaCl bitcode is fixed at little-endian ILP32: pointers ar e
213 32 bits in size. 64-bit integer types are also supported natively via the i64
214 type (for example, a front-end can generate these from the C/C++ type <em>long
215 long</em>).</p>
216 <p>Integers are assumed to be modeled using two&#8217;s complement. Floating po int
217 support is fixed at IEEE 754 32-bit and 64-bit values (f32 and f64,
218 respectively).</p>
219 </section><section id="high-level-basics">
220 <h2 id="high-level-basics">High Level Basics</h2>
221 <p>A program is defined as a sequence of top-level <em>blocks</em>. Blocks can b e nested
222 within other blocks. Each block defines a sequence of records.</p>
223 <p>Most of the records, within a block, also define a unique values. Each uniqu e
224 value is given a corresponding unique identifier (i.e. <em>ID</em>). In PNaClAsm . each
225 kind of block defines its own kind of identifiers. The names of these
226 identifiers are defined by concatenating a prefix character (&#8216;&#64;&#8217; or &#8216;%&#8217;), the
227 kind of block (a single character), and a suffix index. The suffix index is
228 defined by the positional location of the defined value within the records of
229 the corresponding block. The indices are all zero based, meaning that the first
230 defined value (within a block) is defined using index 0.</p>
231 <p>Identifiers are categorized into two types, <em>local</em> and <em>global</em >. Local
232 identifiers are identifiers that are associated with the implementation of a
233 single function. All other identifiers are global. This split is
234 intentional. Global identifiers are used by multiple functions, and therefore
235 must be unique across all function implementations. Local identifiers only apply
236 to a single function, and can be reused between functions. The <em>PNaCl
237 translator</em> uses this separation to parallelize the compilation of functions .</p>
238 <p>Global identifiers use the prefix character <em>&#8216;&#64;&#8217;</em> whil e local identifiers use
239 the prefix character <em>&#8216;%&#8217;</em>.</p>
240 <p>Note: There is one exception to this separation of local and global identifie rs.
241 Abbreviations can be defined locally and globally. An abbreviation is local if
242 it only applies to the block it appears in. If it is global, the abbreviation
243 can apply to multiple block instances.</p>
244 <p>Note that by using positional location to define identifiers (within a block) ,
245 the values defined in PNaCl bitcode files need not be explicitly included in the
246 bitcode file. Rather, they are inferred by the (ordered) position of the record
247 in the block. This is also intentional. It is used to reduce the amount of data
248 that must be (explicitly) passed to the PNaCl translator.</p>
249 <p>In general, most of the records within blocks are assumed to be topologically
250 sorted, putting value definitions before their uses. This implies that records
251 do not need to encode data if they can deduce the corresponding information from
252 their uses.</p>
253 <p>The most common use of this is that many instructions use the type of their
254 operands to determine the type of the instruction. Again, this is
255 intentional. It allows less information to be stored.</p>
256 <p>However, for function blocks (which define instructions), no topological sort
257 exists. Loop carried value dependencies simply do not allow topologically
258 sorting. To deal with this, function blocks have a notion of a forward
259 (instruction value) declaration. These declarations must appear before any of
260 the uses of that value, if the (instruction) value is defined later in the
261 function than its first use.</p>
262 </section><section id="pnacl-blocks">
263 <h2 id="pnacl-blocks">PNaCl Blocks</h2>
264 <p>Blocks are used to organize records in the bitcode file. The kinds of blocks
265 defined in PNaClAsm are:</p>
266 <dl class="docutils">
267 <dt>Types block</dt>
268 <dd>Defines the set of types used by the program. All types used in the program
269 must be defined in this block. These types consist of primitive types as well
270 as high level constructs such as vectors and function signatures.</dd>
271 <dt>Globals block</dt>
272 <dd>Defines the set of global addresses of global variables and constants, used by
273 the program. It also defines how each global (associated with the global
274 address) is initialized.</dd>
275 <dt>Valuesymtab block</dt>
276 <dd>Defines textual names for global and function addresses.</dd>
277 <dt>Function block</dt>
278 <dd>Each function (implemented) in a program has its own block that defines the
279 implementation of the corresponding function.</dd>
280 <dt>Constants block</dt>
281 <dd>Each implemented function, that uses constants in its instructions, defines a
282 constant block. Constants blocks appear within the corresponding function
283 block.</dd>
284 <dt>Module block</dt>
285 <dd>A top-level block defining the program. This block defines global informatio n
286 used by the program, followed by function blocks defining the implementation
287 of functions within the program.</dd>
288 <dt>Abbreviations block</dt>
289 <dd>Defines abbreviations that are used to compress PNaCl records. This block is
290 segmented into multiple sections, one section for each kind of block. This
291 block appears at the beginning of the module block.</dd>
292 </dl>
293 <p>A PNaCl program consists of a header record and a module block. The header
294 defines a sequence of bytes uniquely identifying the file as a bitcode file. The
295 module block defines the program to run.</p>
296 <p>Each block, within a bitcode file, defines values. These values are associate d
297 with IDs. Each type of block defines different kinds of IDs.</p>
298 <p>The <em>abbreviations block</em> [ref] is the first block in the module buld. . The
299 block is divided into sections. Each section is a sequence of records. Each
300 record in the sequence defines a user-defined abbreviation. Each section
301 defines abbreviations that can be applied to all (succeeding) blocks of a
302 particular kind. These abbreviations are denoted by the (global) ID of the form
303 <em>&#64;aN</em>.</p>
304 <p>The <em>types block</em> [ref] defines types used by the program. Each record in the
305 types block defines a separate type. Valid types include various sizes of
306 integer and floating types. They also define higher level constructs such as
307 vectors and function signatures. For each definition, a type ID is defined. A
308 type ID is of the form <em>&#64;tN</em>, where <em>N</em> corresponds to the (re lative) position
309 of the corresponding defining record in the types block.</p>
310 <p>The types block must appear within the module block, and must appear before a ny
311 block that uses a typed value. Many PNaClAsm constructs allow one to use
312 explicit type names, rather than type IDs. However, they are internally
313 converted to the corresponding type ID in the types block. Hence, the
314 requirement that the types block must appear early in the module block.</p>
315 <p>The <em>module block</em> [ref] contains all other blocks. The only values d efined in
316 a module block are function addresses. All remaining definitions appear within
317 blocks of the module block.</p>
318 <p>Function addresses are global IDs of the form <em>&#64;fN</em>, where <em>N</ em> corresponds to
319 the position of the corresponding function address record in the module
320 block. Function addresses must appear after the types block.</p>
321 <p>The <em>globals block</em> [ref] defines global addresses for global variable s and
322 constants, used in the program. This block not only defines the addresses, but
323 also the size of the corresponding memory associated with these addresses, and
324 how the memory should be initialized.</p>
325 <p>The globals block must appear in the module block, and after all function
326 address records. Global addresses (defined by the globals block) are of the
327 form <em>&#64;gN</em>, where <em>N</em> is the (relative) position of the corres ponding defining
328 records.</p>
329 <p>The <em>valuesymtab block</em> [ref] does not define any values. Rather, its only goal
330 is to associate text names with previously defined global addresses
331 (i.e. function, constant, and variable). Each association is defined by a
332 record in the valuesymtab block. Currently, only <em>intrinsic</em> [ref] functi on
333 addresses need a name. All other entries in this block are considered as a hint
334 for debugging. The PNaCl translator may (or may not) pass these names to the
335 running executable, allowing the (runtime) debugger to associate names with
336 addresses.</p>
337 <p>Each <em>function block</em> [ref] defines the implementation of a single
338 function. Each function block defines the intermediate representation of the
339 function, consisting of basic blocks and instructions. If constants are used
340 within instructions, they are defined in a <em>constants block</em>, nested with in the
341 corresponding function block.</p>
342 <p>All function blocks are associated with a corresponding function address. Thi s
343 association is (again) positional rather than explicit. That is, the Nth
344 function block in a module block corresponds to the Nth defining (rather than
345 declared) function address record in the module block.</p>
346 <p>Hence, within a function block, there is no explicit reference to the
347 function address the block defines. For readability, PNaClAsm uses the
348 corresponding function heading, associated with the corresponding
349 function address record, even though that data does not appear in the
350 corresponding records.</p>
351 <p>Unlike other blocks, a function block defines multiple kinds of
352 values: parameter, basic block, and instruction. Parameter IDs (in
353 PNaClAsm) are identified using local IDs of the form <em>%pN</em>. Basic
354 block IDs are identified using local IDs of the form
355 <em>%bN</em>. Instructions that generate values are identified using local
356 IDs of the form <em>%vN</em>.</p>
357 <p>Hence, <em>%pN</em> denotes the Nth parameter of the function. <em>%bN</em> d enotes
358 the <em>Nth</em> basic block within the function. <em>%vN</em> denotes the value
359 generated by the <em>Nth</em> instruction that generates a value. Note: <em>%vN< /em>
360 does not necessarily refer to the <em>Nth</em> instruction in the function
361 block, because not all instructions generate values.</p>
362 <p>Within a function block, basic blocks are not explicitly defined in the recor ds
363 of a function block. Rather, the first record of the block identifies how many
364 basic blocks appear in the control flow graph of the function. This record is
365 then followed by a sequence of records, each record defining a single
366 instruction. Special <em>terminating</em> [ref] (e.g. branch) instructions are u sed to
367 determine block boundaries.</p>
368 <p>Each <em>constants block</em> [ref] defines constants that are used by the en closing
369 function block. The purpose of the constants block is to merge all uses of a
370 constant (within a function) into a single defining ID. Constant IDs are of the
371 form <em>%cN</em>, where <em>N</em> corresponds to the (relative) position of th e constant
372 defined in the corresponding constants block. The constants block must appear
373 before any instruction.</p>
374 </section><section id="pnacl-records">
375 <h2 id="pnacl-records">PNaCl Records</h2>
376 <p>A PNaCl record is a non-empty sequence of unsigned, 64-bit, integers. A recor d
377 is identified by the record <em>code</em>, which is the first element in the
378 sequence. Record codes are unique within a specific kind of block, but are not
379 necessarily unique across different kinds of blocks. The record code acts as the
380 variant discriminator (i.e. tag) within a block, to identify what kind of record
381 it is.</p>
382 <p>Record codes are typically small numbers. In an ideal world, they would be a
383 consecutive sequence of integers, starting at zero. However, the reality is that
384 PNaCl records evolved over time (and actually started as LLVM records [ref]).
385 For backwards compatibility, old numbers have not been reused, leaving gaps in
386 the actual record code values used.</p>
387 <p>The exception of using small numbers for record codes, are four special kinds of
388 records. What makes these four kinds of records special is that they either
389 apply in multiple blocks, or don&#8217;t occur in any block. To make these cases
390 clear, and to leave room for lots of future growth in PNaClAsm, these special
391 records have record codes close to the value 2**16. Note: Well-formed PNaCl
392 bitcode files do not have record codes &gt;= 2**16.</p>
393 <p>A PNaCl record is denoted as follows:</p>
394 <pre class="prettyprint">
395 a: &lt;v0, v1, ... , vN&gt;
396 </pre>
397 <p>The value <em>v0</em> is the record code. The remaining values, <em>v1</em> t hrough <em>vN</em>, are
398 parameters that fill in additional information needed by the construct it
399 represents. All records must have a record code. Hence, empty PNaCl records are
400 not allowed.</p>
401 <p>While most records (for a given record code) are of the same length, it is no t
402 true of all record codes. Some record codes can have arbitrary length. In
403 particular, function type signatures, call instructions, phi nodes, switch
404 instructions, and global variable initialization records all have variable
405 length.</p>
406 <p>Records are converted to bit sequences using an abbreviation. Let <em>a</em> the the index
407 identifying the abbreviation that is used to convert the record to a sequence of
408 bits. If a user-defined abbreviation <em>%aA</em> (or <em>&#64;aA</em> if global ) is specified in
409 the syntax, then <em>a = AbbrevIndex(%aA)</em>.</p>
410 <p>The PNaCl bitcode writer, which converts records to bit sequences, does this by
411 writing out the abbreviation index used to encode the record, followed by the
412 contents of the record. The details of this are left to section on abbreviations
413 [ref]. However, at the record level, one important aspect of this appears in
414 block enter records. These records must define how many bits are required to
415 hold abbreviation indices associated with records of that block.</p>
416 <p>There are 4 predefined (default) abbreviation indices, used as the default
417 abbreviations for PNaCl records. They are:</p>
418 <dl class="docutils">
419 <dt>0</dt>
420 <dd>Abbreviation index for the abbreviation used to bit-encode an exit block
421 record.</dd>
422 <dt>1</dt>
423 <dd>Abbreviation index for the abbreviation used to bit-encode a enter block
424 record.</dd>
425 <dt>2</dt>
426 <dd>Abbreviation index for the abbreviation used to bit-encode a user-defined
427 abbreviation record.</dd>
428 <dt>3</dt>
429 <dd>Abbreviation index for the default abbreviation to bit-encode all other
430 records in the bitcode file.</dd>
431 </dl>
432 <p>A block may (in addition), define a list of block specific, user-defined,
433 abbreviations (of length <em>U</em>). The number of bits <em>B</em> specified fo r an enter
434 record must be sufficiently large such that</p>
435 <pre class="prettyprint">
436 2**B &gt;= U + 4
437 </pre>
438 <p>In addition, the upper limit for B is 32.</p>
439 <p>PNaClAsm requires that you specify the number of bits needed to read
440 abbreviations as part of the enter block record. This allows the PNaCl bitcode
441 reader/writer to use the specified number of bits to encode abbreviation
442 indices.</p>
443 </section><section id="conventions-for-describing-records">
444 <h2 id="conventions-for-describing-records">Conventions for describing records</ h2>
445 <p>PNaClAsm is the textual representation of PNaCl records. Each PNaCl record i s
446 described by a corresponding PNaClAsm construct. These constructs are described
447 using syntax rules, and semantics on how they are converted to records. The
448 parser also has state, that is updated after the record is processed. These
449 state updates are part of the semantics of the corresponding record construct.</ p>
450 <p>For each PNaCl construct, we define multiple subsections. The <strong>Syntax< /strong>
451 subsection defines a syntax rule for the construct. The <strong>Record</strong> subsection
452 defines the corresponding record associated with the syntax rule. The
453 <strong>Semantics</strong> subsection describes the semantics associated with th e record, in
454 terms of data within the parse state and the corresponding syntax.</p>
455 <p>The <strong>Constraints</strong> subsection (if present) defines any constrai nts associated
456 with the construct. The <strong>Updates</strong> subsection (if present) defines how the
457 parse state is updated when the construct is parsed. The <strong>Examples</stro ng>
458 subsection gives one (or more) examples of using the corresponding PNaClAsm
459 construct.</p>
460 <p>Some semantics subsections use functions to compute values. The meaning of
461 functions can be found in <em>Support Functions</em> [ref].</p>
462 <p>Within a syntax rule, there may specifications about abbreviations. These
463 abbreviation specifications, if allowed, are at the end of the construct, and
464 enclosed in <em>&lt;</em> and <em>&gt;</em> brackets. These abbreviation specifi cations are optional
465 in the syntax, and can be omitted. If they are used, the abbreviation brackets
466 are part of the actual syntax of the construct. To make it clear that
467 abbreviation specifications are optional, syntax rules separate abbreviation
468 specifications using plenty of whitespace.</p>
469 <p>Abbreviation specifications consist of user-defined abbreviations, abbreviati on
470 identifiers, and the number of bits required to represent abbreviations in a
471 block. These notations appear, as appropriate, in the corresponding syntax
472 rules.</p>
473 <p>The most common abbreviation syntax is the corresponding abbreviation identif ier
474 to use to read/write the corresponding record. In such cases, if the specified
475 abbreviation identifier is omitted, the corresponding default abbreviation will
476 be used by the PNaCl reader/writer.</p>
477 <p>Also, within the syntax rule, all alphabetic characters are lower case unless
478 they appear within a literal value. Hence, if we mix lower and upper case
479 letters within a name appearing in a syntax rule, the lower case letters are
480 literal while the upper case sequence of letters denote (rule specific)
481 values. If an upper case sequence of letters is followed by digits, the
482 corresponding embedded name includes both the upper case letters and the digits.
483 The valid values for each of these names will be defined in the corresponding
484 semantics subsection.</p>
485 <p>For example, consider the following syntax rule:</p>
486 <pre class="prettyprint">
487 %vN = add T O1, O2; &lt;A&gt;
488 </pre>
489 <p>This rule defines a PNaClAsm add instruction. This construct defines an
490 instruction that adds to two values (<em>O1</em> and <em>O2</em>) to generate in struction
491 value <em>%vN</em>. The types of the arguments, and the result, are all of type
492 <em>T</em>. Since abbreviation ID <em>A</em> is present, the record is encoded u sing that
493 abbreviation.</p>
494 <p>To be concrete, the syntactic rule above defines the structure of the followi ng
495 PNaClAsm examples.</p>
496 <pre class="prettyprint">
497 %v10 = add i32 %v1, %v2; &lt;&#64;a5&gt;
498 %v11 = add i32 %v10, %v3;
499 </pre>
500 <p>In addition to specifying the syntax, each syntax rule also specifies the
501 contents of the corresponding record in the corresponding record subsection. In
502 simple cases, the elements of the corresponding record are predefined (literal)
503 constants. Otherwise the record element is a name that is defined by the other
504 subsections associated with the construct.</p>
505 </section><section id="factorial-example">
506 <h2 id="factorial-example">Factorial Example</h2>
507 <p>This section provides a simple example of a PNaCl bticode file. Its contents
508 describes a bitcode file that only defines a function to compute the factorial
509 value of a number.</p>
510 <p>In C, the factorial function can be defined as:</p>
511 <pre class="prettyprint">
512 int fact(int n) {
513 if (n == 0) return 1;
514 return n * fact(n-1);
515 }
516 </pre>
517 <p>Compiling this into a PEXE file, and dumping out its contents with utility
518 <em>pnacl-bcdis</em>, the corresponding output is:</p>
519 <pre class="prettyprint">
520 0:0|&lt;65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, 88, 69)
521 | 8, 0, 17, 0, 4, 0, 2, 0, 0, |PNaCl Version: 2
522 | 0&gt; |
523 16:0|1: &lt;65535, 8, 3&gt; |module { // BlockID = 8
524 24:0| 3: &lt;1, 1&gt; | version 1;
525 26:5| 1: &lt;65535, 0, 2&gt; | abbreviations { // BlockID = 0
526 36:0| 0: &lt;65534&gt; | }
527 40:0| 1: &lt;65535, 17, 4&gt; | types { // BlockID = 17
528 48:0| 3: &lt;1, 4&gt; | count 4;
529 50:6| 3: &lt;7, 32&gt; | &#64;t0 = i32;
530 54:2| 3: &lt;2&gt; | &#64;t1 = void;
531 56:2| 3: &lt;21, 0, 0, 0&gt; | &#64;t2 = i32 (i32);
532 60:4| 3: &lt;7, 1&gt; | &#64;t3 = i1;
533 63:2| 0: &lt;65534&gt; | }
534 64:0| 3: &lt;8, 2, 0, 0, 0&gt; | define external i32 &#64;f0(i32);
535 68:7| 1: &lt;65535, 19, 4&gt; | globals { // BlockID = 19
536 76:0| 3: &lt;5, 0&gt; | count 0;
537 78:6| 0: &lt;65534&gt; | }
538 80:0| 1: &lt;65535, 14, 4&gt; | valuesymtab { // BlockID = 14
539 88:0| 3: &lt;1, 0, 102, 97, 99, | &#64;f0 : &quot;fact&quot;;
540 | 116&gt; |
541 96:6| 0: &lt;65534&gt; | }
542 100:0| 1: &lt;65535, 12, 5&gt; | function i32 &#64;f0(i32 %p0) {
543 | | // BlockID = 12
544 108:0| 3: &lt;1, 3&gt; | blocks 3;
545 110:7| 1: &lt;65535, 11, 4&gt; | constants { // BlockID = 11
546 120:0| 3: &lt;1, 0&gt; | i32:
547 122:6| 3: &lt;4, 2&gt; | %c0 = i32 1;
548 125:4| 3: &lt;4, 0&gt; | %c1 = i32 0;
549 128:2| 0: &lt;65534&gt; | }
550 | | %b0:
551 132:0| 3: &lt;28, 1, 2, 32&gt; | %v0 = icmp eq i32 %c1, %c0;
552 137:1| 3: &lt;11, 1, 2, 1&gt; | br i1 %v0, %b1, %b2;
553 | | %b1:
554 141:4| 3: &lt;10, 3&gt; | ret i32 %c0;
555 | | %b2:
556 144:3| 3: &lt;2, 4, 3, 1&gt; | %v1 = sub i32 %p0, %c0;
557 148:6| 3: &lt;34, 0, 6, 1&gt; | %v2 = call i32 &#64;f0(i32 %p0);
558 153:7| 3: &lt;2, 6, 1, 2&gt; | %v2 = mul i32 &#64;f0, %v1;
559 158:2| 3: &lt;10, 1&gt; | ret i32 %v2;
560 161:1| 0: &lt;65534&gt; | }
561 164:0|0: &lt;65534&gt; |}
562 </pre>
563 <p>Note that there are three columns in this output. The first column contains t he
564 bit positions of the records within the bitcode file. The second column contains
565 the sequence of records within the bitcode file. The third column contains the
566 corresponding PNaClAsm program.</p>
567 <p>Bit positions are defined by a pair <em>B:N</em>. <em>B</em> is the number of bytes, while <em>N</em>
568 is the bit offset within the <em>B+1</em> byte. Hence, the bit position (in bits ) is:</p>
569 <pre class="prettyprint">
570 B*8 + N
571 </pre>
572 <p>Hence, the first <em>header</em> record is at bit offset 0 (0*8+0). The secon d record
573 is at bit offset 128 (16*8+0). The third record is at bit offset 192 (24*8+0).
574 The fourth record is at bit offset 213 (26*8+5).</p>
575 <p>The header record is a sequence of 16 bytes, defining the contents of the fir st
576 16 bytes of the bitcode file. The first four bytes define the magic number of
577 the file. That is, &#8216;PEXE&#8217;. All PEXE bitcode files begin with these f our bytes.
578 Byte 13 defines the PNaCl bitcode version of the file. Currently, only version 2
579 is allowed.</p>
580 <p>All but the header record has an abbreviation index associated with it. Since no
581 user-defined abbreviations are provided, all records use the default
582 abbreviation.</p>
583 <p>The types block (starting at bit address 40:0), defines 4 types: <em>i1</em>, <em>i32</em>,
584 <em>void</em>, and function signature <em>i32(i32)</em>.</p>
585 <p>Bit address 64:0 declares the factorial function address &#64;f0, and its
586 corresponding type signature. Bit address 88:0 associates the name &#8220;fact&# 8221; with
587 function address &#64;f0.</p>
588 <p>Bit address 100:0 defines the function block that implemnts function &#8220;f act&#8221;. The
589 entry point is %b0 (at bit address 132:0). It uses the 32-bit integer constants
590 1 and 0 (defined at bit addresses 122:6 and 125:4). Bit address 132:0 defines an
591 equality comparison of the argument %p0 with 0 (constant %c1). Bit address 137:1
592 defines a conditional branch. If the result of the previous comparison (%v0) is true,
593 the program will branch to block %b1. Otherwise it will branch to block %b2.</p>
594 <p>Bit address 141:4 returns constant 1 (%c0) when the input parameter is 0.
595 Instructions between bit address 144:3 and 158:2 compute and return &#8220;n *
596 fact(n-1)&#8221;.</p>
597 </section><section id="parse-state">
598 <h2 id="parse-state">Parse State</h2>
599 <p>This section describes the parse state of the PNaClAsm assembler. It is used to
600 define contextual data that is carried between records. The following
601 subsections describe each element of the parse state.</p>
602 <section id="typing">
603 <h3 id="typing">Typing</h3>
604 <p>Associated with most identifiers is a type. This type defines what type the
605 corresponding value has. It is defined by the (initially empty) map</p>
606 <pre class="prettyprint">
607 TypeOf: ID -&gt; Type
608 </pre>
609 <p>For each type in the <em>types block</em> [ref], a corresponding inverse map< /p>
610 <pre class="prettyprint">
611 TypeID: Type -&gt; ID
612 </pre>
613 <p>is maintained to convert syntactic types to the corresponding type ID.</p>
614 <p>Note: This document assumes that map <em>TypeID</em> is automatically maintai ned during
615 updates to map <em>TypeOf</em> (when given a type ID). Hence, <em>updates</em> s ubsections
616 will not contain assignments to this map.</p>
617 <p>Associated with each function identifier is its type signature. This is
618 different than the type of the function identifier, since function identifiers
619 are pointers (and always implemented as a 32-bit integer).</p>
620 <p>Function type signatures are maintained using:</p>
621 <pre class="prettyprint">
622 TypeOfFcn: ID -&gt; Type
623 </pre>
624 <p>In addition, if a function address has an implementing block, there is a
625 corresponding implementation associated with the function address. To capture
626 this association, we use the set:</p>
627 <pre class="prettyprint">
628 DefiningFcnIDs: set(ID)
629 </pre>
630 </section><section id="id-counters">
631 <h3 id="id-counters">ID Counters</h3>
632 <p>Each block defines one (or more) kinds of values. Value indices are generate d
633 sequentially, starting at zero. To capture this, the following counters are
634 defined:</p>
635 <dl class="docutils">
636 <dt>NumTypes</dt>
637 <dd>The number of types defined so far (in the types block)</dd>
638 <dt>NumFuncAddresses</dt>
639 <dd>The number of function addresses defined so far (in the module block).</dd>
640 <dt>NumDefinedFcnAddresses</dt>
641 <dd>The number of defining function addresses defined so far (in the module
642 block).</dd>
643 <dt>NumFuncImpls</dt>
644 <dd>The number of implemented functions defined so far (in the module block).</d d>
645 <dt>NumGlobalAddresses</dt>
646 <dd>The number of global variable/constant addresses defined so far (in the
647 globals block).</dd>
648 <dt>NumParams</dt>
649 <dd>The number of parameters defined for a function.</dd>
650 <dt>NumFcnConsts</dt>
651 <dd>The number of constants defined in a function.</dd>
652 <dt>NumBasicBlocks</dt>
653 <dd>The number of basic blocks defined so far (within a function block).</dd>
654 <dt>NumValuedInsts</dt>
655 <dd>The number of instructions, generating values, defined so far (within a
656 function block).</dd>
657 </dl>
658 </section><section id="size-variables">
659 <h3 id="size-variables">Size Variables</h3>
660 <p>A number of blocks define expected sizes of constructs. These sizes are recor ded
661 in the following size variables:</p>
662 <dl class="docutils">
663 <dt>ExpectedBasicBlocks</dt>
664 <dd>The expected number of basic blocks within a function implementation.</dd>
665 <dt>ExpectTypes</dt>
666 <dd>The expected number of types defined in the types block.</dd>
667 <dt>ExpectedGlobals</dt>
668 <dd>The expected number of global variable/constant addresses in the globals
669 block.</dd>
670 <dt>ExpectedInitializers</dt>
671 <dd>The expected number of initializers for a global variable/constant address i n
672 the globals block.</dd>
673 </dl>
674 </section><section id="other-variables">
675 <h3 id="other-variables">Other Variables</h3>
676 <dl class="docutils">
677 <dt>EnclosingFcnID</dt>
678 <dd>The function ID of the function block being processed.</dd>
679 </dl>
680 </section></section><section id="special-records">
681 <h2 id="special-records">Special records</h2>
682 <p>There are four special PNaCl records, each having its own record code. These
683 special records are:</p>
684 <dl class="docutils">
685 <dt>Header</dt>
686 <dd>The header record is the first record of a PNaCl bitcode file, and identifie s
687 the file&#8217;s magic number, as well as the bitcode version it uses. The recor d
688 defines the sequence of bytes that make up the header and uniquely identifies
689 the file as a PNaCl bitcode file.</dd>
690 <dt>Enter</dt>
691 <dd>An enter record defines the beginning of a block. Since blocks can be nested ,
692 one can appear inside other blocks, as well as at the top level.</dd>
693 <dt>Exit</dt>
694 <dd>An exit record defines the end of a block. Hence, it must appear in every
695 block, to end the block.</dd>
696 <dt>Abbreviation</dt>
697 <dd>An abbreviation record defines a user-defined abbreviation to be applied to
698 records within blocks. Abbreviation records appearing in the abbreviations
699 block define global abbreviations. All other abbreviations are local to the
700 block they appear in, and can only be used in that block.</dd>
701 </dl>
702 <p>All special records can&#8217;t have user-defined abbreviations associated wi th
703 them. The default abbreviation is always used.</p>
704 <p>The following subsections define valid special records, other than abbreviati on
705 records. Abbreviation records are described in the Abbreviations [ref] section.< /p>
706 <section id="header-record">
707 <h3 id="header-record">Header Record</h3>
708 <p>The header record must be the first record in the file. It is the only record in
709 the bitcode file that doesn&#8217;t have a corresponding construct in
710 PNaClAsm.</p>
711 <p><strong>Syntax</strong></p>
712 <p>There is no syntax for header records in PNaClAsm. It is automatically insert ed
713 by the PNaCl bitcode writer.</p>
714 <p><strong>Record</strong></p>
715 <pre class="prettyprint">
716 &lt;65532, 80, 69, 88, 69, 1, 0, 8, 0, 17, 0, 4, 0, 2, 0, 0, 0&gt;
717 </pre>
718 <p><strong>Semantics</strong></p>
719 <p>The header record defines the initial sequence of bytes that must appear at t he
720 beginning of all (PNaCl bitcode version 2) files. That sequence is the list of
721 bytes inside the record (excluding the record code). As such, it uniquely
722 identifies PNaCl bitcode files.</p>
723 <p><strong>Examples</strong></p>
724 <p>There are no examples for the header record, since it is not part of PNaClAsm .</p>
725 </section><section id="enter-block-record">
726 <h3 id="enter-block-record">Enter Block Record</h3>
727 <p>Block records can be top-level, as well as nested in other blocks. Blocks mus t
728 begin with an <em>enter</em> record, and end with an <em>exit</em> record.</p>
729 <p><strong>Syntax</strong></p>
730 <pre class="prettyprint">
731 N { &lt;B&gt;
732 </pre>
733 <p><strong>Record</strong></p>
734 <pre class="prettyprint">
735 1: &lt;65535, ID, B&gt;
736 </pre>
737 <p><strong>Semantics</strong></p>
738 <p>Enter block records define the beginning of a block. <em>B</em>, if present, is the
739 number of bits needed to represent all possible abbreviation indices used within
740 the block. If omitted, B=2 is assumed.</p>
741 <p>The block <em>ID</em> value is dependent on the name <em>N</em>. Valid names and corresponding
742 <em>BlockID</em> values are defined as follows:</p>
743 <table border="1" class="docutils">
744 <colgroup>
745 </colgroup>
746 <thead valign="bottom">
747 <tr class="row-odd"><th class="head">N</th>
748 <th class="head">Block ID</th>
749 </tr>
750 </thead>
751 <tbody valign="top">
752 <tr class="row-even"><td>abbreviations</td>
753 <td>0</td>
754 </tr>
755 <tr class="row-odd"><td>constants</td>
756 <td>11</td>
757 </tr>
758 <tr class="row-even"><td>function</td>
759 <td>12</td>
760 </tr>
761 <tr class="row-odd"><td>globals</td>
762 <td>19</td>
763 </tr>
764 <tr class="row-even"><td>module</td>
765 <td>8</td>
766 </tr>
767 <tr class="row-odd"><td>types</td>
768 <td>17</td>
769 </tr>
770 <tr class="row-even"><td>valuesymtab</td>
771 <td>14</td>
772 </tr>
773 </tbody>
774 </table>
775 <p>Note: For readability, PNaClAsm allows a more readable form of a function blo ck
776 enter record. See <em>function blocks</em> [ref] for more details.</p>
777 <p><strong>Examples</strong></p>
778 <pre class="prettyprint">
779 module {
780 types {
781 count: 0;
782 }
783 globals {
784 count: 0;
785 }
786 }
787 </pre>
788 <p>This example defines a module, types, and globals block. Both the type and th e
789 globals block appear within the module block.</p>
790 <p>The corresponding records are:</p>
791 <pre class="prettyprint">
792 1: &lt;65535, 8, 2&gt;
793 1: &lt;65535, 17, 2&gt;
794 3: &lt;1, 0&gt;
795 0: &lt;65534&gt;
796 1: &lt;65535, 19, 2&gt;
797 3: &lt;5, 0&gt;
798 0: &lt;65534&gt;
799 0: &lt;65534&gt;
800 </pre>
801 </section><section id="exit-block-record">
802 <h3 id="exit-block-record">Exit Block Record</h3>
803 <p>Block records can be top-level, as well as nested, records. Blocks must begin
804 with an <em>enter</em> record, and end with an <em>exit</em> record.</p>
805 <p><strong>Syntax</strong></p>
806 <pre class="prettyprint">
807 }
808 </pre>
809 <p><strong>Record</strong></p>
810 <pre class="prettyprint">
811 0: &lt;65534&gt;
812 </pre>
813 <p><strong>Semantics</strong></p>
814 <p>All exit records are identical, no matter what block they are ending. An exit
815 record defines the end of the block.</p>
816 <p><strong>Examples</strong></p>
817 <pre class="prettyprint">
818 module {
819 types {
820 count: 0;
821 }
822 globals {
823 count: 0;
824 }
825 }
826 </pre>
827 <p>This example defines a module, types, and globals block. Both the type and th e
828 globals block appear within the module block.</p>
829 <p>The corresponding records are:</p>
830 <pre class="prettyprint">
831 1: &lt;65535, 8, 2&gt;
832 1: &lt;65535, 17, 2&gt;
833 3: &lt;1, 0&gt;
834 0: &lt;65534&gt;
835 1: &lt;65535, 19, 2&gt;
836 3: &lt;5, 0&gt;
837 0: &lt;65534&gt;
838 0: &lt;65534&gt;
839 </pre>
840 </section></section><section id="types-block">
841 <h2 id="types-block">Types Block</h2>
842 <p>The types block defines all types used in a program. It must appear in the
843 module block, before any function address records, the globals block, the
844 valuesymtab block, and any function blocks.</p>
845 <p>Each record in the types block defines a type used by the program. Types can be
846 broken into the following groups:</p>
847 <dl class="docutils">
848 <dt>Primitive Value types</dt>
849 <dd>Defines the set of base types for values. This includes various sizes of
850 integral and floating types.</dd>
851 <dt>Void type</dt>
852 <dd>A primitive type that doesn&#8217;t represent any value and has no size.</dd >
853 <dt>Function types</dt>
854 <dd>The type signatures of functions.</dd>
855 <dt>Vector type</dt>
856 <dd>Defines vectors of primitive types.</dd>
857 </dl>
858 <p>In addition, any type that is not defined using another type is a primitive
859 type. All other types (i.e. function and vector) are composite types.</p>
860 <p>Types must be defined in a topological order, causing primitive types to appe ar
861 before the composite types that use them. Each type must be unique. There are no
862 additional restrictions on the order that types can be defined in a types block. </p>
863 <p>The following subsections introduce each valid PNaClAsm type, and the
864 corresponding PNaClAsm construct that defines the type. Types not defined in the
865 types block, can&#8217;t be used in a PNaCl program.</p>
866 <p>The first record of a types block must be a <em>count</em> record, defining h ow many
867 types are defined by the types block. All remaining records defines a type. The
868 following subsections define valid records within a types block. The order of
869 type records is important. The position of each defining record implicitly
870 defines the type ID that will be used to denote that type, within other PNaCl
871 records of the bitcode file.</p>
872 <p>To make this more concrete, consider the following example types block:</p>
873 <pre class="prettyprint">
874 types {
875 count: 4;
876 &#64;t0 = void;
877 &#64;t1 = i32;
878 &#64;t2 = float;
879 &#64;t3 = void (i32, float);
880 }
881 </pre>
882 <p>This example defines a types block that defines four type IDs:</p>
883 <ol class="arabic simple" start="0">
884 <li>The void type.</li>
885 <li>A 32-bit integer type.</li>
886 <li>A 32-bit floating type.</li>
887 <li>A function, taking 32-bit integer and float arguments that returns void.</li >
888 </ol>
889 <p>Note that the order defines the corresponding identifier that will be used fo r
890 that type, and is based on the position of the type within the types
891 record. Hence, the assignment to identifier <em>&#64;tN</em> can never appear be fore the
892 assignment to identifier <em>&#64;tN-1</em>. Further, if type identifier <em>&#6 4;tN</em> is assigned,
893 it must appear immediately after the assignment to identifier <em>&#64;tN-1</em> .</p>
894 <section id="count-record">
895 <h3 id="count-record">Count Record</h3>
896 <p>The <em>count record</em> defines how many types are defined in the types
897 block. Following the types count record are records that define types used by
898 the PNaCl program.</p>
899 <p><strong>Syntax</strong></p>
900 <pre class="prettyprint">
901 count: N; &lt;A&gt;
902 </pre>
903 <p><strong>Record</strong></p>
904 <blockquote>
905 <div>AA: &lt;1, N&gt;</div></blockquote>
906 <p><strong>Semantics</strong></p>
907 <p>This construct defines the number of types used by the PNaCl program. <em>N< /em> is
908 the number of types defined in the types block. It is an error to define more
909 (or fewer) types than value <em>N</em>, within the enclosing types block. <em>A< /em> is the
910 (optional) abbreviation associated with the record.</p>
911 <p><strong>Constraints</strong></p>
912 <pre class="prettyprint">
913 AA == AbbrevIndex(A)
914 0 == NumTypes
915 </pre>
916 <p><strong>Updates</strong></p>
917 <pre class="prettyprint">
918 ExpectedTypes = N;
919 </pre>
920 <p><strong>Examples</strong></p>
921 <pre class="prettyprint">
922 types {
923 count: 2;
924 &#64;t0 = float;
925 &#64;t1 = i32;
926 }
927 </pre>
928 <p>This example defines two types. A 32 bit integer and a 32 bit floating types .
929 The corresponding records are:</p>
930 <pre class="prettyprint">
931 1: &lt;65535, 17, 2&gt;
932 3: &lt;1, 2&gt;
933 3: &lt;3&gt;
934 3: &lt;7, 32&gt;
935 0: &lt;65534&gt;
936 </pre>
937 </section><section id="void-type">
938 <h3 id="void-type">Void Type</h3>
939 <p>The <em>void</em> type record defines the void type, which corresponds to the type that
940 doesn&#8217;t define any value, and has no size.</p>
941 <p><strong>Syntax</strong></p>
942 <pre class="prettyprint">
943 &#64;tN = void; &lt;A&gt;
944 </pre>
945 <p><strong>Record</strong></p>
946 <pre class="prettyprint">
947 AA: &lt;2&gt;
948 </pre>
949 <p><strong>Semantics</strong></p>
950 <p>The void type record defines the type that has no values and has no size. <e m>A</em>
951 is the (optional) abbreviation associated with the record.</p>
952 <p><strong>Constraints</strong></p>
953 <pre class="prettyprint">
954 AA == AbbrevIndex(A)
955 N == NumTypes
956 NumTypes &lt; ExpectedTypes
957 </pre>
958 <p><strong>Updates</strong></p>
959 <pre class="prettyprint">
960 ++NumTypes;
961 TypeOf(&#64;tN) = void;
962 </pre>
963 <p><strong>Examples</strong></p>
964 <pre class="prettyprint">
965 &#64;t0 = void;
966 </pre>
967 <p>defines the record</p>
968 <pre class="prettyprint">
969 3: &lt;2&gt;
970 </pre>
971 </section><section id="integer-types">
972 <h3 id="integer-types">Integer Types</h3>
973 <p>PNaClAsm allows integral types for various bit sizes. Valid bit sizes are 1, 8,
974 16, 32, and 64. Integers can be signed or unsigned, but the signed component of
975 an integer is not specified by the type. Rather, individual instructions
976 determine whether the value is assumed to be signed or unsigned.</p>
977 <p>It should be noted that in PNaClAsm, all pointers are implemented as 32-bit
978 (unsigned) integers. There isn&#8217;t a separate type for pointers. The only w ay to
979 tell that a 32-bit integer is a pointer, is when it is used in an instruction
980 that requires a pointer (such as load and store instructions).</p>
981 <p><strong>Syntax</strong></p>
982 <pre class="prettyprint">
983 &#64;tN = iB; &lt;A&gt;
984 </pre>
985 <p><strong>Record</strong></p>
986 <blockquote>
987 <div>AA: &lt;7, B&gt;</div></blockquote>
988 <p><strong>Semantics</strong></p>
989 <p>An integer type record defines an integral type. <em>B</em> defines the numbe r of bits
990 of the integral type. <em>A</em> is the (optional) abbreviation associated with the
991 record.</p>
992 <p><strong>Constraints</strong></p>
993 <pre class="prettyprint">
994 AA == AbbrevIndex(A)
995 N == NumTypes
996 NumTypes &lt; ExpectedTypes
997 B in {1, 8, 16, 32, 64}
998 </pre>
999 <p><strong>Updates</strong></p>
1000 <pre class="prettyprint">
1001 ++NumTypes;
1002 TypeOf(&#64;tN) = iB;
1003 </pre>
1004 <p><strong>Examples</strong></p>
1005 <pre class="prettyprint">
1006 &#64;t1 = i32;
1007 &#64;t2 = i1;
1008 &#64;t3 = i64;
1009 </pre>
1010 <p>defines the records</p>
1011 <pre class="prettyprint">
1012 3: &lt;7, 32&gt;
1013 3: &lt;7, 1&gt;
1014 3: &lt;7, 64&gt;
1015 </pre>
1016 </section><section id="bit-floating-type">
1017 <h3 id="bit-floating-type">32-Bit Floating Type</h3>
1018 <p>PNaClAsm allows computation on 32-bit floating values. A floating type record
1019 defines the 32-bit floating type.</p>
1020 <p><strong>Syntax</strong></p>
1021 <pre class="prettyprint">
1022 &#64;tN = float; &lt;A&gt;
1023 </pre>
1024 <p><strong>Record</strong></p>
1025 <pre class="prettyprint">
1026 AA: &lt;3&gt;
1027 </pre>
1028 <p><strong>Semantics</strong></p>
1029 <p>A floating type record defines the 32-bit floating type. <em>A</em> is the ( optional)
1030 abbreviation associated with the record.</p>
1031 <p><strong>Constraints</strong></p>
1032 <pre class="prettyprint">
1033 AA == AbbrevIndex(A).
1034 N == NumTypes
1035 NumTypes &lt; ExpectedTypes
1036 </pre>
1037 <p><strong>Updates</strong></p>
1038 <pre class="prettyprint">
1039 ++NumTypes;
1040 TypeOf(&#64;tN) = float;
1041 </pre>
1042 <p><strong>Examples</strong></p>
1043 <pre class="prettyprint">
1044 &#64;t5 = float;
1045 </pre>
1046 <p>defines the record</p>
1047 <pre class="prettyprint">
1048 3: &lt;3&gt;
1049 </pre>
1050 </section><section id="id1">
1051 <h3 id="id1">64-bit Floating Type</h3>
1052 <p>PNaClAsm allows computation on 64-bit floating values. A double type record
1053 defines the 64-bit floating type.</p>
1054 <p><strong>Syntax</strong></p>
1055 <pre class="prettyprint">
1056 &#64;tN = double; &lt;A&gt;
1057 </pre>
1058 <p><strong>Record</strong></p>
1059 <pre class="prettyprint">
1060 AA: &lt;4&gt;
1061 </pre>
1062 <p><strong>Semantics</strong></p>
1063 <p>A double type record defines the 64-bit floating type. <em>A</em> is the (op tional)
1064 abbreviation associated with the record.</p>
1065 <p><strong>Constraints</strong></p>
1066 <pre class="prettyprint">
1067 AA == AbbrevIndex(A)
1068 N == NumTypes
1069 NumTypes &lt; ExpectedTypes
1070 </pre>
1071 <p><strong>Updates</strong></p>
1072 <pre class="prettyprint">
1073 ++NumTypes;
1074 TypeOf(&#64;tN) = double;
1075 </pre>
1076 <p><strong>Examples</strong></p>
1077 <pre class="prettyprint">
1078 &#64;t3 = double;
1079 </pre>
1080 <p>defines the record</p>
1081 <pre class="prettyprint">
1082 3: &lt;4&gt;
1083 </pre>
1084 </section><section id="vector-types">
1085 <h3 id="vector-types">Vector Types</h3>
1086 <p>TODO(kschimpf) &lt;N x T&gt;</p>
1087 <p>TODO(kschimpf) Define integral and floating vector types.</p>
1088 </section><section id="function-type">
1089 <h3 id="function-type">Function Type</h3>
1090 <p>The <em>function</em> type can be thought of as a function signature. It cons ists of a
1091 return type, and a (possibly empty) list of formal parameter types.</p>
1092 <p><strong>Syntax</strong></p>
1093 <pre class="prettyprint">
1094 %tN = RT (T1, ... , TM) &lt;A&gt;
1095 </pre>
1096 <p><strong>Record</strong></p>
1097 <pre class="prettyprint">
1098 AA: &lt;21, 0, IRT, IT1, ... , ITM&gt;
1099 </pre>
1100 <p><strong>Semantics</strong></p>
1101 <p>The function type defines the signature of a function. <em>RT</em> is the ret urn type
1102 of the function, while types <em>T1</em> through <em>TM</em> are the types of th e
1103 arguments. Indicies to the corresponding type identifiers is stored in the
1104 corresponding record.</p>
1105 <p>The return value must either be a primitive type, type <em>void</em>, or a ve ctor type.
1106 Parameter types can be a primitive or vector type.</p>
1107 <p>For the integral types, only i32 and i64 can be used for a return or paramete r
1108 type. All other integral types are not allowed.</p>
1109 <p><strong>Constraints</strong></p>
1110 <pre class="prettyprint">
1111 AA = AbbrevIndex(A)
1112 M &gt;= 0
1113 IRT = AbsoluteIndex(TypeID(RT))
1114 IT1 = AbsoluteIndex(TypeID(T1))
1115 ...
1116 ITM = AbsoluteIndex(TypeID(TM))
1117 N == NumTypes
1118 NumTypes &lt; ExpectedTypes
1119 </pre>
1120 <p><strong>Updates</strong></p>
1121 <pre class="prettyprint">
1122 ++NumTypes;
1123 TypeOf(&#64;tN) = RT (T1, ... , TM)
1124 </pre>
1125 <p><strong>Examples</strong></p>
1126 <p>The following example defines two function signatures (<em>&#64;t4</em> and < em>&#64;t5</em>):</p>
1127 <p>The corresponding records are:</p>
1128 <pre class="prettyprint">
1129 1: &lt;65535, 17, 2&gt;
1130 3: &lt;1, 6&gt;
1131 3: &lt;7, 32&gt;
1132 3: &lt;7, 64&gt;
1133 3: &lt;3&gt;
1134 3: &lt;2&gt;
1135 3: &lt;21, 3, 0, 2, 1&gt;
1136 3: &lt;21, 0&gt;
1137 0: &lt;65534&gt;
1138 </pre>
1139 </section></section><section id="globals-block">
1140 <h2 id="globals-block">Globals block</h2>
1141 <p>The globals block defines global addresses of variables and constants, used b y
1142 the PNaCl program. It also defines the memory associated with the global
1143 addresses, and how to initialize each global variable/constant. It must appear
1144 in the module block. It must appear after the types block, as well as after all
1145 function address records. But, it must also appear before the valuesymtab block,
1146 and any function blocks.</p>
1147 <p>The globals block begins with a count record, defining how many global addres ses
1148 are defined by the PNaCl program. It is then followed by a sequence of records
1149 that defines how each global address is initialized.</p>
1150 <p>The standard sequence, for defining global addresses, begins with a global
1151 address record. It is then followed by a sequence of records defining how the
1152 global address is initialized. If the initializer is simple, a single record is
1153 used. Otherwise, the initializer is preceded with a compound record, specifying
1154 a number <em>N</em>, followed by sequence of <em>N</em> simple initializer recor ds.</p>
1155 <p>The size of the memory referenced by each global address is defined by its
1156 initializer records. All simple initializer records define a sequence of
1157 bytes. A compound initializer defines the sequence of bytes by concatenating the
1158 corresponding sequence of bytes for each of its simple initializer records.</p>
1159 <p>For notational convenience, PNaClAsm begins a compound record with a &#8220;{ &#8221;, and
1160 inserts a &#8220;}&#8221; after the last initializer record associated compound record. This
1161 latter &#8220;}&#8221; does not correspond to any record. It is implicitly assum ed by the
1162 size specified in the compound record, and is added only to improve readability. </p>
1163 <p>Explicit alignment is specified for global addresses, and must be a power
1164 of 2. If the alignment is 0, the alignment of the global is set by the target to
1165 whatever it feels convenient. If the value is greater than zero, the global is
1166 forced to have exactly that alignment.</p>
1167 <p>For example, consider the following:</p>
1168 <pre class="prettyprint">
1169 globals {
1170 count: 2;
1171 const &#64;g0 =
1172 zerofill 8;
1173 var &#64;g1 =
1174 initializers 2 {
1175 {1, 2, 3, 4},
1176 zerofill 2;
1177 }
1178 }
1179 </pre>
1180 <p>TODO: Rewrite this: Base example by line number and corresponding record.</p>
1181 <p>In this example, the globals block contains 9 records. All lines, inside the
1182 block delimiters of this example (except the second to last) defines a
1183 record. The first record, &#8220;globals {&#8221;, is the beginning of the globa ls block.
1184 The second record, &#8220;count: 2;&#8221;, defines the number of global address es defined
1185 by the program, i.e. 2.</p>
1186 <p>The third record, &#8220;const &#64;g0 = &#8221;, defines the global constant address <em>&#64;g0</em>.
1187 The forth record, &#8220;zerofill 8;&#8221;, defines to initialize the constant with 8
1188 bytes, all with the value zero. Thus, the size of <em>&#64;g0</em> is 8 bytes.</ p>
1189 <p>The fifth record, &#8220;var &#64;g1 =&#8221;, defines the global variable ad dress <em>&#64;g1</em>. The
1190 sixth record, &#8220;initializers 2 ..&#8221;, defines that the initial value of <em>&#64;g1</em> is
1191 defined by the sequence of bytes defined by the following 2 initializer
1192 records. The seventh record, &#8220;{1, 2, 3, 4}, defines that the first 4 bytes of
1193 <em>&#64;g1</em> are initialized with bytes 1, 2, 3, 4. The eighth record, &#822 0;zerofill 2&#8221;;
1194 initializes bytes 5 and 6 to zero. The size of <em>&#64;g1</em> is therefore 6 b ytes.</p>
1195 <p>The nine record is the exit block record.</p>
1196 <p>In other words, the corresponding records are:</p>
1197 <pre class="prettyprint">
1198 1: &lt;65535, 19, 2&gt;
1199 3: &lt;5, 2&gt;
1200 3: &lt;0, 0, 1&gt;
1201 3: &lt;2, 8&gt;
1202 3: &lt;0, 0, 0&gt;
1203 3: &lt;1, 2&gt;
1204 3: &lt;3, 1, 2, 3, 4&gt;
1205 3: &lt;2, 2&gt;
1206 0: &lt;65534&gt;
1207 </pre>
1208 <section id="id2">
1209 <h3 id="id2">Count Record</h3>
1210 <p>The count record defines the number of global addresses used by the PNaCl
1211 program.</p>
1212 <p><strong>Syntax</strong></p>
1213 <pre class="prettyprint">
1214 count: N; &lt;A&gt;
1215 </pre>
1216 <p><strong>Record</strong></p>
1217 <pre class="prettyprint">
1218 AA: &lt;5, N&gt;
1219 </pre>
1220 <p><strong>Semantics</strong></p>
1221 <p>This record must appear first in the globals block. The count record defines
1222 the number of global addresses used by the program. <em>A</em> is the (optional)
1223 abbreviation associated with the record.</p>
1224 <p><strong>Constraints</strong></p>
1225 <pre class="prettyprint">
1226 AA = AbbrevIndex(A)
1227 </pre>
1228 <p><strong>Updates</strong></p>
1229 <pre class="prettyprint">
1230 ExpectedGlobals = N;
1231 ExpectedInitializers = 0;
1232 </pre>
1233 </section><section id="global-variable-addressses">
1234 <h3 id="global-variable-addressses">Global Variable Addressses</h3>
1235 <p>A global variable address record defines a global address to global data. Th e
1236 global variable address record must be immediatedly followed by initializer
1237 record(s) that define how the corresponding global variable is initialized.</p>
1238 <p><strong>Syntax</strong></p>
1239 <pre class="prettyprint">
1240 var &#64;gN, align V = &lt;A&gt;
1241 var &#64;gN = &lt;A&gt;
1242 </pre>
1243 <p><strong>Record</strong></p>
1244 <pre class="prettyprint">
1245 AA: &lt;0, VV, 0&gt;
1246 </pre>
1247 <p><strong>Semantics</strong></p>
1248 <p>A global varaible address record defines a global address for a global variab le.
1249 <em>V</em> is the alignment to for the global variable. <em>VVA</em> is the corr esponding
1250 number of bits associated with alignment <em>V</em> (see <em>constraints</em>). The alignment
1251 <em>V</em> clause can be omitted if <em>V</em> is zero. <em>A</em> is the (optio nal) abbreviation
1252 associated with the record.</p>
1253 <p>It is assumed that the memory, referenced by the global variable address, can be
1254 both read and written to.</p>
1255 <p><strong>Constraints</strong></p>
1256 <pre class="prettyprint">
1257 AA = AbbrevIndex(A)
1258 N = NumGlobalAddresses
1259 NumGlobalAddresses &lt; ExpectedGlobals
1260 ExpectedInitializers = 0
1261 VV = Log2(V+1)
1262 </pre>
1263 <p><strong>Updates</strong></p>
1264 <pre class="prettyprint">
1265 ++NumGlobalAddresses;
1266 ExpectedInitializers = 1;
1267 TypeOf(&#64;gN) = i32;
1268 </pre>
1269 <p><strong>Examples</strong></p>
1270 <pre class="prettyprint">
1271 var &#64;g0 =
1272 zerofill 8;
1273 var &#64;g1 =
1274 {1, 2, 3, 4}
1275 </pre>
1276 <p>This example defines two global variable addresses, <em>&#64;g0</em> and <em> &#64;g1</em>. Both use
1277 memory alignment of 0. <em>&#64;g0</em> is an 8 byte variable initialized to zer o. <em>&#64;g1</em>
1278 is a 4 byte variable, initialized by the sequence of bytes 1, 2, 3, and 4.</p>
1279 <p>The corresponding records defined by the example above are:</p>
1280 <pre class="prettyprint">
1281 3: &lt;0, 0, 0&gt;
1282 3: &lt;2, 8&gt;
1283 3: &lt;0, 0, 0&gt;
1284 3: &lt;3, 1, 2, 3, 4&gt;
1285 </pre>
1286 </section><section id="global-constant-addresses">
1287 <h3 id="global-constant-addresses">Global Constant Addresses</h3>
1288 <p>A global constant address record defines an address corresponding to a global
1289 constant that can&#8217;t be modified by the program. The global constant addres s
1290 record must be immediatedly followed by initializer record(s) that define how
1291 the corresponding global constant is initialized.</p>
1292 <p><strong>Syntax</strong></p>
1293 <pre class="prettyprint">
1294 const &#64;gN, align V = &lt;A&gt;
1295 const &#64;gN = &lt;A&gt;
1296 </pre>
1297 <p><strong>Record</strong></p>
1298 <pre class="prettyprint">
1299 AA: &lt;0, VV, 1&gt;
1300 </pre>
1301 <p><strong>Semantics</strong></p>
1302 <p>A global constant address record defines a global address for a global consta nt.
1303 <em>V</em> is the memory alignment for the global constant. <em>VV</em> is the c orresponding
1304 number of bits associated with alignment <em>V</em> (see <em>constraints</em>). The alignment
1305 <em>V</em> caluse can be omitted if <em>V</em> is zero. <em>A</em> is the (optio nal) abbreviation
1306 associated with the record.</p>
1307 <p>It is assumed that the memory, referenced by the global constant
1308 address, is only read, and can&#8217;t be written to.</p>
1309 <p>Note that the only difference between a global variable address and a global
1310 constant address record is the third element of the record. If the value is
1311 zero, it defines a global variable address. If the value is one, it defines a
1312 global constant address.</p>
1313 <p><strong>Constraints</strong></p>
1314 <pre class="prettyprint">
1315 AA = AbbrevIndex(A)
1316 N = NumGlobalAddresses
1317 NumGlobalAddresses &lt; ExpectedGlobals
1318 ExpectedInitializers = 0
1319 VV = Log2(V+1)
1320 </pre>
1321 <p><strong>Updates</strong></p>
1322 <pre class="prettyprint">
1323 ++NumGlobalAddresses;
1324 ExpectedInitializers = 1;
1325 TypeOf(&#64;gN) = i32;
1326 </pre>
1327 <p><strong>Examples</strong></p>
1328 <pre class="prettyprint">
1329 const &#64;g0 =
1330 zerofill 8;
1331 var &#64;g1 =
1332 {1, 2}
1333 </pre>
1334 <p>This example defines two global constants, with global addresses <em>&#64;g0< /em> and
1335 <em>&#64;g1</em>. <em>&#64;g0</em> is an 8 byte constant initialized to zero. < em>&#64;g1</em> is a 2 byte
1336 variable, initialized by the sequence of bytes 1 and 2.</p>
1337 <p>The corresponding PNaCl bitcode records are:</p>
1338 <pre class="prettyprint">
1339 3: &lt;0, 0, 1&gt;
1340 3: &lt;2, 8&gt;
1341 3: &lt;0, 0, 1&gt;
1342 3: &lt;3, 1, 2&gt;
1343 </pre>
1344 </section><section id="zerofill-initializer">
1345 <h3 id="zerofill-initializer">Zerofill Initializer</h3>
1346 <p>The zerofill initializer record intializes a sequence of bytes, associated wi th
1347 a global address, with zeros.</p>
1348 <p><strong>Syntax</strong></p>
1349 <pre class="prettyprint">
1350 zerofill N; &lt;A&gt;
1351 </pre>
1352 <p><strong>Record</strong></p>
1353 <pre class="prettyprint">
1354 AA: &lt;2, N&gt;
1355 </pre>
1356 <p><strong>Semantics</strong></p>
1357 <p>A zerofill initializer record intializes a sequence of bytes, associated with a
1358 global address, with zeros. <em>A</em> is the (optional) abbreviation of the ass ociated
1359 record.</p>
1360 <p><strong>Constraints</strong></p>
1361 <pre class="prettyprint">
1362 AA = AbbrevIndex(A)
1363 ExpectedInitializers &gt; 0;
1364 </pre>
1365 <p><strong>Updates</strong></p>
1366 <pre class="prettyprint">
1367 --ExpectedInitializers;
1368 </pre>
1369 <p><strong>Examples</strong></p>
1370 <pre class="prettyprint">
1371 const &#64;g0 =
1372 zerofill 8;
1373 var &#64;g1 =
1374 zerofill 4;
1375 </pre>
1376 <p>This example defines two global constants, with global addresses <em>&#64;g0< /em> and
1377 <em>&#64;g1</em>. The global memory associated with address <em>&#64;g0</em>, i s an eight byte value,
1378 initialized to zero. The global memory associated with address <em>&#64;g1</em> , is a 4
1379 byte value, initialized to zero.</p>
1380 <p>The corresponding PNaCl records are:</p>
1381 <pre class="prettyprint">
1382 3: &lt;0, 0, 1&gt;
1383 3: &lt;2, 8&gt;
1384 3: &lt;0, 0, 1&gt;
1385 3: &lt;2, 4&gt;
1386 </pre>
1387 </section><section id="data-initializer">
1388 <h3 id="data-initializer">Data Initializer</h3>
1389 <p>Data records define a sequence of bytes. These bytes define the initial value of
1390 the contents of the corresponding memory.</p>
1391 <p><strong>Syntax</strong></p>
1392 <pre class="prettyprint">
1393 { B1 , .... , BN } &lt;A&gt;
1394 </pre>
1395 <p><strong>Record</strong></p>
1396 <pre class="prettyprint">
1397 AA: &lt;3, B1, ..., BN&gt;
1398 </pre>
1399 <p><strong>Semantics</strong></p>
1400 <p>A data record defines a sequence of bytes <em>B1</em> throught <em>BN</em>, t hat intialize <em>N</em>
1401 bytes of memory. <em>A</em> is the (optional) abbreviation associated with the
1402 record.</p>
1403 <p><strong>Constraints</strong></p>
1404 <pre class="prettyprint">
1405 AA = AbbrevIndex(A)
1406 ExpectedInitializers &gt; 0
1407 </pre>
1408 <p><strong>Updates</strong></p>
1409 <pre class="prettyprint">
1410 --ExpectedInitializers;
1411 </pre>
1412 <p><strong>Examples</strong></p>
1413 <pre class="prettyprint">
1414 const &#64;g0 =
1415 {1, 2, 97, 36, 44, 88, 44}
1416 const &#64;g1 =
1417 initializers 3 {
1418 {4, 5, 6, 7}
1419 reloc &#64;f1;
1420 {99, 66, 22, 12}
1421 }
1422 </pre>
1423 <p>The corresponding PNaCl records are:</p>
1424 <pre class="prettyprint">
1425 3: &lt;0, 0, 1&gt;
1426 3: &lt;3, 1, 2, 97, 36, 44, 88, 44&gt;
1427 3: &lt;0, 0, 1&gt;
1428 3: &lt;1, 3&gt;
1429 3: &lt;3, 4, 5, 6, 7&gt;
1430 3: &lt;4, 1&gt;
1431 3: &lt;3, 99, 66, 22, 12&gt;
1432 </pre>
1433 </section><section id="relocation-initializer">
1434 <h3 id="relocation-initializer">Relocation Initializer</h3>
1435 <p>A relocation initializer record allows one to define the initial value of a
1436 global address with the value of another global address (i.e. either function,
1437 variable, or constant). Since addresses are pointers, a relocation initializer
1438 record defines 4 bytes of memory.</p>
1439 <p><strong>Syntax</strong></p>
1440 <pre class="prettyprint">
1441 reloc V; &lt;A&gt;
1442 </pre>
1443 <p><strong>Record</strong></p>
1444 <pre class="prettyprint">
1445 AA: &lt;4, VV&gt;
1446 </pre>
1447 <p><strong>Semantics</strong></p>
1448 <p>A relocation initializer record defines a 4-byte value containing the specifi ed
1449 global address <em>V</em>. <em>A</em> is the (optional) abbreviation associated with the
1450 record.</p>
1451 <p><strong>Constraints</strong></p>
1452 <pre class="prettyprint">
1453 AA = AbbrevIndex(A)
1454 VV = AbsoluteIndex(V);
1455 ExpectedInitializers &gt; 0
1456 </pre>
1457 <p><strong>Updates</strong></p>
1458 <pre class="prettyprint">
1459 --ExpectedInitializers;
1460 </pre>
1461 <p><strong>Examples</strong></p>
1462 <pre class="prettyprint">
1463 var &#64;g0 =
1464 initializers 3 {
1465 reloc &#64;f1;
1466 reloc &#64;g0;
1467 reloc &#64;g10;
1468 }
1469 </pre>
1470 <p>This example defines global address <em>&#64;g0</em>. It defines 12 bytes of memory, and is
1471 initialized with three addresses <em>&#64;f1</em>, <em>&#64;g0</em>, and <em>&#6 4;g10</em>. Note that all globals
1472 can be used in a relocation initialization record, even if it isn&#8217;t define d yet.</p>
1473 <p>Assuming</p>
1474 <pre class="prettyprint">
1475 100 = AbsoluteIndex(&#64;g0))
1476 </pre>
1477 <p>The corresponding PNaCl bitcode records are:</p>
1478 <pre class="prettyprint">
1479 3: &lt;0, 0, 0&gt;
1480 3: &lt;1, 3&gt;
1481 3: &lt;4, 1&gt;
1482 3: &lt;4, 100&gt;
1483 3: &lt;4, 110&gt;
1484 </pre>
1485 </section><section id="subfield-relocation-initializer">
1486 <h3 id="subfield-relocation-initializer">Subfield Relocation Initializer</h3>
1487 <p>A subfield relocation initializer record allows one to define the initial val ue
1488 of a global address with the value of another (non-function) global address
1489 (i.e. either variable or constant), plus a constant. Since addresses are
1490 pointers, a relocation initializer record defines 4 bytes of memory.</p>
1491 <p><strong>Syntax</strong></p>
1492 <pre class="prettyprint">
1493 reloc V + O; &lt;A&gt;
1494 reloc V - O; &lt;A&gt;
1495 </pre>
1496 <p><strong>Record</strong></p>
1497 <pre class="prettyprint">
1498 AA: &lt;4, VV, OOO&gt;
1499 </pre>
1500 <p><strong>Semantics</strong></p>
1501 <p>A relocation initializer record defines a 4-byte value containing the specifi ed
1502 global (non-funciton) address <em>V</em>, modified by the unsigned offset <em>O< /em>. <em>OO</em> is
1503 the corresponding signed offset. In the first form, <em>OO == O</em>. In the sec ond
1504 form, <em>OO == - O</em>. <em>A</em> is the (optional) abbreviation associated with the
1505 record. <em>a</em> is the corresponding abbreviation index of <em>A</em>. When < em>A</em> is omitted,
1506 <em>a=3</em>.</p>
1507 <p><strong>Constraints</strong></p>
1508 <pre class="prettyprint">
1509 AA = AbbrevIndex(A)
1510 VV == AbsoluteIndex(V)
1511 ExpectedInitializers &gt; 0
1512 OOO == SignRotate(OO)
1513 </pre>
1514 <p><strong>Updates</strong></p>
1515 <pre class="prettyprint">
1516 --ExpectedInitializers;
1517 </pre>
1518 <p><strong>Examples</strong></p>
1519 <pre class="prettyprint">
1520 var &#64;g0 =
1521 initializers 3 {
1522 reloc &#64;f1;
1523 reloc &#64;g0 + 4;
1524 reloc &#64;g10 - 3;
1525 }
1526 </pre>
1527 <p>This example defines global address <em>&#64;g0</em>, and is initialized with three
1528 pointers, addresses <em>&#64;f1</em>, <em>&#64;g0+4</em>, and <em>&#64;g10-3</em >. Note that all global addresses
1529 can be used in a relocation initialization record, even if it isn&#8217;t define d
1530 yet. Validity of the reference can be verified, since a global address <em>&#64; g10</em>
1531 must be smaller than the value specified in the globals count record.</p>
1532 <p>Assuming</p>
1533 <pre class="prettyprint">
1534 100 = AbsoluteIndex(&#64;g0))
1535 </pre>
1536 <p>The corresponding PNaCl bitcode records are:</p>
1537 <pre class="prettyprint">
1538 3: &lt;0, 0, 0&gt;
1539 3: &lt;1, 3&gt;
1540 3: &lt;4, 1&gt;
1541 3: &lt;4, 100, 8&gt;
1542 3: &lt;4, 110, 7&gt;
1543 </pre>
1544 </section><section id="compound-initializer">
1545 <h3 id="compound-initializer">Compound Initializer</h3>
1546 <p>The compound initializer record must immediately follow a global
1547 variable/constant address record. It defines how many (non-compound) initializer
1548 records are used to define the initializer. The size of the corresponding memory
1549 is the sum of the bytes needed for each of the succeeding initializers.</p>
1550 <p><strong>Syntax</strong></p>
1551 <pre class="prettyprint">
1552 initializers N { &lt;A&gt;
1553 ...
1554 }
1555 </pre>
1556 <p><strong>Record</strong></p>
1557 <pre class="prettyprint">
1558 AA: &lt;1, N&gt;
1559 </pre>
1560 <p><strong>Semantics</strong></p>
1561 <p>Defines that the next <em>N</em> initializers should be associated with the g lobal
1562 address of the previous record. <em>A</em> is the (optional) abbreviation index
1563 associated with the record.</p>
1564 <p><strong>Constraints</strong></p>
1565 <pre class="prettyprint">
1566 AA = AbbrevIndex(A)
1567 ExpectedInitializers == 1
1568 </pre>
1569 <p><strong>Updates</strong></p>
1570 <pre class="prettyprint">
1571 ExpectedInitializers = N;
1572 </pre>
1573 <p><strong>Examples</strong></p>
1574 <pre class="prettyprint">
1575 const &#64;g1 =
1576 initializers 3 {
1577 {4, 5, 6, 7}
1578 reloc &#64;f1;
1579 {99, 66, 22, 12}
1580 }
1581 </pre>
1582 <p>The corresponding PNaCl records are:</p>
1583 <pre class="prettyprint">
1584 3: &lt;0, 0, 1&gt;
1585 3: &lt;1, 3&gt;
1586 3: &lt;3, 4, 5, 6, 7&gt;
1587 3: &lt;4, 1&gt;
1588 3: &lt;3, 99, 66, 22, 12&gt;
1589 </pre>
1590 </section></section><section id="valuesymtab-block">
1591 <h2 id="valuesymtab-block">Valuesymtab Block</h2>
1592 <p>TODO(kschimpf)</p>
1593 </section><section id="module-block">
1594 <h2 id="module-block">Module Block</h2>
1595 <p>The module block, like all blocks, are enclosed in a pair of enter/exit recor ds,
1596 using block ID 8. A well-formed module block consists The following records (in
1597 order):</p>
1598 <dl class="docutils">
1599 <dt>A version record</dt>
1600 <dd>The version record communicates which version of the PNaCl bitcode
1601 reader/writer should be used. Note that this is different than the PNaCl
1602 bitcode (ABI) verion. The PNaCl bitcode (ABI) version defines what is
1603 expected in records, and is defined in the header record of the bitcode
1604 file. The version record defines the version of the PNaC bitcode
1605 reader/writer to use to convert records into bit sequences.</dd>
1606 <dt>Optional local abbreviations</dt>
1607 <dd>Defines a list of local abbreviations to use for records within the module
1608 block.</dd>
1609 <dt>An abbreviations block</dt>
1610 <dd>The abbreviations block defines user-defined, global abbreviations that are
1611 used to convert PNaCl records to bit sequences in blocks following the
1612 abbreviations block.</dd>
1613 <dt>A types block</dt>
1614 <dd>The types block defines the set of all types used in the program.</dd>
1615 <dt>A non-empty sequence of function address records</dt>
1616 <dd>Each record defines a function address used by the program. Function
1617 addresses must either be external, or defined internally by the program. If
1618 they are defined by the program, there must be a function block (appearing
1619 later in the module) that defines the sequence of instructions for each
1620 defined function.</dd>
1621 <dt>A globals block defining the global variables.</dt>
1622 <dd>This block defines the set of global variable (addresses) used by the
1623 program. In addition to the addresses, each global variable also defines how
1624 the corresponding global variable is initialized.</dd>
1625 <dt>An optional value symbol table block.</dt>
1626 <dd>This block, if defined, provides textual names for function and global
1627 variable addresses (previously defined in the module). Note that only names
1628 for instrinsic functions must be provided. Any additional names are hints
1629 that may (or may not) be used by the PNaCl translator, and be available for
1630 debugging when executed.</dd>
1631 <dt>A sequence of function blocks.</dt>
1632 <dd>Each function block defines the corresponding control flow graph for each
1633 defined function. The order of function blocks is used to associate them with
1634 function addresses. The order of the defined function blocks must follow the
1635 same order as the corresponding function addresses defined in the module
1636 block.</dd>
1637 </dl>
1638 <p>Descriptions of the abbreviations [ref], types [ref], global variables [ref],
1639 value symbol table [ref], and function [ref] blocks are not provided here. See
1640 the appropriate reference for more details. The following subsections describe
1641 each of the records that can appear in a module block.</p>
1642 <section id="version">
1643 <h3 id="version">Version</h3>
1644 <p>The version record defines the implementation of the PNaCl reader/writer to
1645 use. That is, the implementation that converts PNaCl records to bit
1646 sequences. Note that this is different than the PNaCl version of the bitcode
1647 file (encoded in the header record of the bitcode file). The PNaCl version
1648 defines the valid forms of PNaCl records. The version record is specific to the
1649 PNaCl version, and may have different values for different PNaCl versions.</p>
1650 <p>Note that currently, only PNaCl bitcode version 2, and version record value 1 is
1651 defined.</p>
1652 <p><strong>Syntax</strong></p>
1653 <pre class="prettyprint">
1654 version N; &lt;A&gt;
1655 </pre>
1656 <p><strong>Record</strong></p>
1657 <pre class="prettyprint">
1658 AA: &lt;1, N&gt;
1659 </pre>
1660 <p><strong>Semantics</strong></p>
1661 <p>The version record defines which PNaCl reader/writer rules should be
1662 followed. <em>N</em> is the version number. Currently <em>N</em> must be 1. Futu re versions of
1663 PNaCl may define additional legal values. <em>A</em> is the (optional) abbreviat ion
1664 index associated with the record.</p>
1665 <p><strong>Constraints</strong></p>
1666 <pre class="prettyprint">
1667 AA = AbbrevIndex(A)
1668 </pre>
1669 <p><em>Examples</em></p>
1670 <pre class="prettyprint">
1671 version 1;
1672 </pre>
1673 <p>The corresponding record is:</p>
1674 <pre class="prettyprint">
1675 3: &lt;1, 1&gt;
1676 </pre>
1677 </section><section id="function-address">
1678 <h3 id="function-address">Function Address</h3>
1679 <p>A function address record defines a function address. Defining function
1680 addresses can also imply a corresponding implementation. <em>Defined</em> functi on
1681 addresses define implementations while <em>declared</em> function addresses do n ot.</p>
1682 <p>The implementation of a <em>defined</em> function address is provided by a
1683 corresponding function block, appearing later in the module block. The
1684 association of defining function address with the corresponding function block
1685 is based on position. The <em>Nth</em> defining function address record, in the module
1686 block, has its implementation in the <em>Nth</em> function block of that module block.</p>
1687 <p><strong>Syntax</strong></p>
1688 <pre class="prettyprint">
1689 PN LN T0 &#64;fN ( T1 , ... , TM ); &lt;A&gt;
1690 </pre>
1691 <p><strong>Record</strong></p>
1692 <pre class="prettyprint">
1693 AA: &lt;8, T, C, P, L&gt;
1694 </pre>
1695 <p><strong>Semnatics</strong></p>
1696 <p>Defines the function address <em>&#64;fN</em>. <em>PN</em> is the name that s pecifies
1697 the prototype value <em>P</em> associated with the function. A function
1698 address is defining only if <em>P==0</em>. Otherwise, it is only declared.
1699 The type of the function is defined by function type <em>&#64;tT</em>. <em>L</em >
1700 is the linkage specification corresponding to name <em>LN</em>. <em>C</em> is th e
1701 calling convention used by the function. <em>A</em> is the
1702 (optional) abbreviation associated with the record.</p>
1703 <p>Note that the function signature must be defined by a function type in the ty pes
1704 block. Hence, the return value must either be a primitive type, type <em>void</e m>, or
1705 a vector type. Parameter types can be a primitive or vector type. For the
1706 integral types, only i32 and i64 can be used for a return or parameter type. All
1707 other integer types are not allowed.</p>
1708 <p>Valid prototype names <em>PN</em>, and corresponding <em>P</em> values, are:< /p>
1709 <table border="1" class="docutils">
1710 <colgroup>
1711 </colgroup>
1712 <thead valign="bottom">
1713 <tr class="row-odd"><th class="head">P</th>
1714 <th class="head">PN</th>
1715 </tr>
1716 </thead>
1717 <tbody valign="top">
1718 <tr class="row-even"><td>1</td>
1719 <td>declare</td>
1720 </tr>
1721 <tr class="row-odd"><td>0</td>
1722 <td>define</td>
1723 </tr>
1724 </tbody>
1725 </table>
1726 <p>Valid linkage names <em>LN</em>, and corresponding <em>L</em> values, are:</p >
1727 <table border="1" class="docutils">
1728 <colgroup>
1729 </colgroup>
1730 <thead valign="bottom">
1731 <tr class="row-odd"><th class="head">L</th>
1732 <th class="head">LN</th>
1733 </tr>
1734 </thead>
1735 <tbody valign="top">
1736 <tr class="row-even"><td>3</td>
1737 <td>internal</td>
1738 </tr>
1739 <tr class="row-odd"><td>0</td>
1740 <td>external</td>
1741 </tr>
1742 </tbody>
1743 </table>
1744 <p>Currently, only one calling convention <em>C</em> is supported:</p>
1745 <table border="1" class="docutils">
1746 <colgroup>
1747 </colgroup>
1748 <thead valign="bottom">
1749 <tr class="row-odd"><th class="head">C</th>
1750 <th class="head">Calling Convention</th>
1751 </tr>
1752 </thead>
1753 <tbody valign="top">
1754 <tr class="row-even"><td>0</td>
1755 <td>C calling convention</td>
1756 </tr>
1757 </tbody>
1758 </table>
1759 <p><strong>Constraint</strong></p>
1760 <pre class="prettyprint">
1761 AA = AbbrevIndex(A)
1762 T = TypeID(TypeOf(T0 ( T1 , ... , TN )))
1763 N = NumFuncAddresses
1764 </pre>
1765 <p><strong>Updates</strong></p>
1766 <pre class="prettyprint">
1767 ++NumFuncAddresses;
1768 TypeOf(&#64;fN) = TypeOf(TypeID(i32));
1769 TypeOfFcn(&#64;fN) = TypeOf(&#64;tT);
1770
1771 if PN == 0:
1772 DefiningFcnIDs += &#64;FN;
1773 ++NumDefinedFunctionAddresses;
1774 </pre>
1775 <p><strong>Examples</strong></p>
1776 <pre class="prettyprint">
1777 module {
1778 ...
1779 types {
1780 &#64;t0 = void;
1781 &#64;t1 = i32;
1782 &#64;t3 = float;
1783 &#64;t4 = void (i32, float);
1784 &#64;t5 = i32 ();
1785 }
1786 ...
1787 declare external void &#64;f0(i32, float);
1788 define internal i32 &#64;f1();
1789 </pre>
1790 <p>This defines function addresses <em>&#64;f0</em> and <em>&#64;f1</em>. Functi on address <em>&#64;f0</em> is
1791 defined externally while <em>&#64;f1</em> has an implementation (defined by a co rresponding
1792 function block). The type signature of <em>&#64;f0</em> is defined by type <em>& #64;t4</em> while the
1793 type signature of <em>&#64;f1</em> is <em>&#64;t5</em>.</p>
1794 <p>The corresopnding records for these two function addresses are:</p>
1795 <pre class="prettyprint">
1796 3: &lt;8, 4, 0, 1, 0&gt;
1797 3: &lt;8, 5, 0, 0, 1&gt;
1798 </pre>
1799 </section></section><section id="constants-blocks">
1800 <h2 id="constants-blocks">Constants Blocks</h2>
1801 <p>TODO(kschimpf)</p>
1802 </section><section id="function-blocks">
1803 <h2 id="function-blocks">Function Blocks</h2>
1804 <p>A function block defines the implementation of a <em>defined</em> function ad dress. The
1805 function address it defines is based on the position of the corresponding
1806 <em>defined</em> function address. The Nth <em>defined</em> function address alw ays
1807 corresponds to the Nth function block in the module block.</p>
1808 <p>A function definition contains a list of basic block, forming the CFG (contro l
1809 flow graph). Each basic block contains a list of instructions, and ends with a
1810 <em>terminator</em> [ref] (branch) instruction.</p>
1811 <p>Basic blocks are not represented by records. Rather, context is implicit. The
1812 first basic block begins with the first instruction record in the function
1813 block. Blocks boundaries are determined by <em>terminator</em> instructions. Th e
1814 instruction that follows a temrinator instruction begins a new basic block.</p>
1815 <p>The first basic block in a function is special in two ways: it is immediately
1816 executed on entrance to the function, and it is not allowed to have predecessor
1817 basic blocks (i.e. there can&#8217;t be any branches to the entry block of a
1818 function). Because the entry block has no predecessors, it also can&#8217;t have any
1819 <em>PHI nodes</em> [ref].</p>
1820 <p>The parameters are implied by the type of the corresponding function
1821 address. One parameter is defined for each argument of the function type
1822 signature.</p>
1823 <p>The number of basic blocks are defined by the count record. Each termimintor
1824 instruction ends the current basic block, and the next instruction begins a new
1825 basic block. Basic blocks are numbered by the order they appear (starting with
1826 index 0). Basic block IDs have the form <em>%bN</em>, where <em>N</em> correspon ds to the
1827 position of the basic block within the function block.</p>
1828 <p>Each instruction, within a function block, corresponds to a corresponding PNa Cl
1829 record. The layout of a function block is the (basic block) count record,
1830 followed by a sequence of instruction records.</p>
1831 <p>For readability, PNaClAsm introduces block IDs. These block IDs do not
1832 correspond to PNaCl records, since basic block boundaries are defined
1833 implicitly, after terminator instructions. They appear only for readability.</p>
1834 <p>Operands are typically defined using an <em>absolute index</em> [ref]. This a bsolute
1835 index implicitly encodes function addresses, global addresses, parameters,
1836 constants, and instructions that generate values. The encoding takes advantage
1837 of the implied ordering of these values in the bitcode file, defining a block of
1838 indices for each kind of identifier. That is, Indices are ordered by putting
1839 function identifier indices first, followed by global address identifiers,
1840 followed by parameter identifiers, followed by constant identifiers, and lastly
1841 instruction value identifiers.</p>
1842 <p>Most operands of instructions are encoded using a relative index value, rathe r
1843 than abolute. The is done because most instruction operands refer to values
1844 defined earlier in the (same) basic block. As a result, the relative distance
1845 (back) from the next value defining instruction is frequently a small
1846 number. Small numbers tend to require less bits when they are converted to bit
1847 sequences.</p>
1848 <p>The following subsections define records that can appear in a function block. </p>
1849 <section id="function-enter">
1850 <h3 id="function-enter">Function enter</h3>
1851 <p>PNaClAsm defines a function enter block construct. The corresponding record i s
1852 simply an enter block record, with BlockID value 12. All context about the
1853 defining address is implicit by the position of the function block, and the
1854 corresponding defining function address. To improve readability, PNaClAsm
1855 includes the function signature into the syntax rule.</p>
1856 <p><strong>Syntax</strong></p>
1857 <pre class="prettyprint">
1858 function TR &#64;fN ( T0 %p0, ... , TM %pM) { &lt;B&gt;
1859 </pre>
1860 <p><strong>Record</strong></p>
1861 <blockquote>
1862 <div>1: &lt;65535, 12, B&gt;</div></blockquote>
1863 <p><strong>Semantics</strong></p>
1864 <p><em>B</em> is the number of bits reserved for abbreviations in the block. See
1865 enter block records [ref] for more details.</p>
1866 <p>The value of <em>N</em> corresponds the the positional index of the correspon ding
1867 defining function address this block is associated with. <em>M</em> is the numbe r of
1868 defined paramaters (minus one) in the function heading.</p>
1869 <p><strong>Constraints</strong></p>
1870 <pre class="prettyprint">
1871 N == NumFcnImpls
1872 &#64;fN in DefiningFcnIDs
1873 TypeOfFcn(&#64;fN) == TypeOf(TypeID(TR (T0, ... , TM)))
1874 </pre>
1875 <p><strong>Updates</strong></p>
1876 <pre class="prettyprint">
1877 ++NumFcnImpls;
1878 EnclosingFcnID = &#64;fN;
1879 NumBasicBlocks = 0;
1880 ExpectedBlocks = 0;
1881 NumParams = M;
1882 for I in [0..M]:
1883 TypeOf(%pI) = TypeOf(TypeID(TI));
1884 </pre>
1885 <p><strong>Examples</strong></p>
1886 <pre class="prettyprint">
1887 types {
1888 ...
1889 &#64;t10 = void (i32, float);
1890 ...
1891 }
1892 ...
1893 define internal void &#64;f12(i32, float);
1894 ...
1895 function void &#64;f12(i32 %p0, float %p1) {
1896 ...
1897 }
1898 </pre>
1899 <p>defines the enter block record:</p>
1900 <pre class="prettyprint">
1901 1: &lt;65535, 12, 2&gt;
1902 </pre>
1903 </section><section id="id3">
1904 <h3 id="id3">Count Record</h3>
1905 <p>The count record, within a function block, defines the number of basic blocks
1906 used to define the function implementation. It should be the first record in the
1907 function block.</p>
1908 <p><strong>Syntax</strong></p>
1909 <pre class="prettyprint">
1910 blocks: N; &lt;A&gt;
1911 %b0:
1912 </pre>
1913 <p><strong>Record</strong></p>
1914 <pre class="prettyprint">
1915 AA: &lt;1, N&gt;
1916 </pre>
1917 <p><strong>Semantics</strong></p>
1918 <p>The count record defines the number <em>N</em> of basic blocks in the impleme nted
1919 function. <em>A</em> is the (optional) abbreviation associated with the record.< /p>
1920 <p><strong>Constraints</strong></p>
1921 <pre class="prettyprint">
1922 AA = AbbrevIndex(A)
1923 ExpectedBasicBlocks = 0
1924 NumBasicBlocks = 0
1925 </pre>
1926 <p><strong>Updates</strong></p>
1927 <pre class="prettyprint">
1928 ExpectedBlocks = N;
1929 </pre>
1930 <p><strong>Examples</strong></p>
1931 <pre class="prettyprint">
1932 blocks: 5
1933 </pre>
1934 <p>The corresponding PNaCl bitcode record is:</p>
1935 <pre class="prettyprint">
1936 3: &lt;1, 5&gt;
1937 </pre>
1938 </section><section id="terminator-instructions">
1939 <h3 id="terminator-instructions">Terminator Instructions</h3>
1940 <p>Terminator instructions are instructions that appear in a function block, and
1941 define the end of the current basic block. A terminator instuction indicates
1942 which block should be executed after the current block is finished. The function
1943 block is well formed only if the number of terminator instructions, in the
1944 function block, corresponds to the value defined by the corresponding count
1945 block.</p>
1946 <section id="return-void-instruction">
1947 <h4 id="return-void-instruction">Return Void Instruction</h4>
1948 <p>The return void instruction is used to return control from a function back to
1949 the caller, without returning any value.</p>
1950 <p><strong>Syntax</strong></p>
1951 <pre class="prettyprint">
1952 ret; &lt;A&gt;
1953 %bB:
1954 </pre>
1955 <p><strong>Record</strong></p>
1956 <pre class="prettyprint">
1957 AA: &lt;10&gt;
1958 </pre>
1959 <p><strong>Semantics</strong></p>
1960 <p>The return instruction returns control to the calling function.</p>
1961 <p><em>B</em> is the number associated with the next basic block. Label <em>%bB: </em> only
1962 appears if <em>B &lt; ExpectedBasicBlocks</em>. That is, the label is omitted on ly if this
1963 terminator instruction is the last instruction in the function block. <em>A</em > is
1964 the (optional) abbreviation index associated with the record.</p>
1965 <p><strong>Constraints</strong></p>
1966 <pre class="prettyprint">
1967 AA = AbbrevIndex(A)
1968 B == NumBasicBlocks + 1
1969 NumBasicBlocks &lt; ExpectedBasicBLocks
1970 ReturnType(TypeOf(EnclosingFcnID)) == void
1971 </pre>
1972 <p><strong>Updates</strong></p>
1973 <pre class="prettyprint">
1974 ++NumBasicBlocks;
1975 </pre>
1976 <p><strong>Examples</strong></p>
1977 <p>The following shows the implementation of a function that simply returns.</p>
1978 <pre class="prettyprint">
1979 function void &#64;f5() {
1980 blocks: 1;
1981 %b0:
1982 ret;
1983 }
1984 </pre>
1985 <p>The corresponding PNaCl records are:</p>
1986 <pre class="prettyprint">
1987 1: &lt;65535, 12, 2&gt;
1988 3: &lt;1, 1&gt;
1989 3: &lt;10&gt;
1990 0: &lt;65534&gt;
1991 </pre>
1992 </section><section id="return-value-instruction">
1993 <h4 id="return-value-instruction">Return Value Instruction</h4>
1994 <p>The return value instruction is used to return control from a function back t o
1995 the caller, including a value. The value must correspond to the return type of
1996 the enclosing function.</p>
1997 <p><strong>Syntax</strong></p>
1998 <pre class="prettyprint">
1999 ret T V; &lt;A&gt;
2000 %bB:
2001 </pre>
2002 <p><strong>Record</strong></p>
2003 <pre class="prettyprint">
2004 AA: &lt;10, VV&gt;
2005 </pre>
2006 <p><strong>Semantics</strong></p>
2007 <p>The return instruction returns control to the calling function, returning the
2008 provided value.</p>
2009 <p><em>V</em> is the value to return. Type <em>T</em> must be of the type return ed by the
2010 function. It must also be the type associated with value <em>V</em>. <em>A</em > is the
2011 (optional) abbreviation index associated with the record.</p>
2012 <p><em>B</em> is the number associated with the next basic block. Label <em>%bB :</em> only
2013 appears if <em>B &lt; ExpectedBasicBlocks</em>. That is, the label is omitted on ly if this
2014 terminator instruction is the last instruction in the function block.</p>
2015 <p>The return type <em>T</em> must either be a primitive type, or a vector type. If the
2016 return type is an integral type, it must be either i32 or i64.</p>
2017 <p><strong>Constraints</strong></p>
2018 <pre class="prettyprint">
2019 AA = AbbrevIndex(A)
2020 VV = RelativeIndex(V)
2021 B = NumBasicBlocks + 1
2022 NumBasicBlocks &lt; ExpectedBasicBlocks
2023 T = TypeOf(V) = ReturnType(TypeOf(EnclosingFcnID))
2024 </pre>
2025 <p><strong>Updates</strong></p>
2026 <pre class="prettyprint">
2027 ++NumBasicBlocks;
2028 </pre>
2029 <p><strong>Examples</strong></p>
2030 <p>The following shows a return statement that returns the value generated by th e
2031 previous instruction:</p>
2032 <pre class="prettyprint">
2033 function i32 &#64;f5(i32 %p0) {
2034 blocks: 1;
2035 &#64;b0:
2036 ret i32 &#64;p0;
2037 }
2038 </pre>
2039 <p>The corresponding records are:</p>
2040 <pre class="prettyprint">
2041 1: &lt;65535, 12, 2&gt;
2042 3: &lt;1, 1&gt;
2043 3: &lt;10, 1&gt;
2044 0: &lt;65534&gt;
2045 </pre>
2046 </section><section id="unconditional-branch-instruction">
2047 <h4 id="unconditional-branch-instruction">Unconditional Branch Instruction</h4>
2048 <p>The unconditional branch instruction is used to cause control flow to transfe r
2049 to a different basic block of the function.</p>
2050 <p><strong>Syntax</strong></p>
2051 <pre class="prettyprint">
2052 br %bN; &lt;A&gt;
2053 %bB:
2054 </pre>
2055 <p><strong>Record</strong></p>
2056 <pre class="prettyprint">
2057 AA: &lt;11, N&gt;
2058 </pre>
2059 <p><strong>Semantics</strong></p>
2060 <p>The unconditional branch instruction causes control flow to transfer to basic
2061 block <em>N</em>. <em>A</em> is the (optional) abbreviation index associated wi th the record.</p>
2062 <p><em>B</em> is the number associated with the next basic block. Label <em>%bB: </em> only
2063 appears if <em>B &lt; ExpectedBasicBlocks</em>. That is, the label is omitted on ly if this
2064 terminator instruction is the last instruction in the function block.</p>
2065 <p><strong>Constraints</strong></p>
2066 <pre class="prettyprint">
2067 AA = AbbrevIndex(A)
2068 0 &lt; N
2069 N &lt; ExpectedBasicBlocks
2070 B = NumBasicBlocks + 1
2071 NumBasicBlocks &lt; ExpectedBasicBlocks
2072 </pre>
2073 <p><strong>Updates</strong></p>
2074 <pre class="prettyprint">
2075 ++NumBasicBlocks;
2076 </pre>
2077 <p><strong>Examples</strong></p>
2078 <pre class="prettyprint">
2079 br %b2;
2080 </pre>
2081 <p>This branch instruction branches to the 3rd basic block of the function. It
2082 defines the following PNaCL record:</p>
2083 <pre class="prettyprint">
2084 3: &lt;11, 2&gt;
2085 </pre>
2086 </section><section id="conditional-branch-instruction">
2087 <h4 id="conditional-branch-instruction">Conditional Branch Instruction</h4>
2088 <p>The conditional branch instruction is used to cause control flow to transfer to
2089 a different basic block of the function, based on a boolean test condition.</p>
2090 <p><strong>Syntax</strong></p>
2091 <pre class="prettyprint">
2092 br i1 C, %bT, %bBF; &lt;A&gt;
2093 %bB:
2094 </pre>
2095 <p><strong>Record</strong></p>
2096 <pre class="prettyprint">
2097 AA: &lt;11, T, F, V&gt;
2098 </pre>
2099 <p><strong>Semantics</strong></p>
2100 <p>Upon execution of a conditional branch instruction, the <em>i1</em> (boolean) argument
2101 <em>C</em> is evaluated. If the value is <em>true</em>, control flows to basic b lock
2102 <em>%bT</em>. Otherwise control flows to basic block <em>%bF</em>. <em>A</em> i s the (optional)
2103 abbreviation index associated with the record.</p>
2104 <p><em>B</em> is the number associated with the next basic block. Label <em>%bB: </em> only
2105 appears if <em>B &lt; ExpectedBasicBlocks</em>. That is, the label is omitted on ly if this
2106 terminator instruction is the last instruction in the function block.</p>
2107 <p><strong>Constraints</strong></p>
2108 <pre class="prettyprint">
2109 AA = AbbrevIndex(A)
2110 V = RelativeIndex(C)
2111 0 &lt; T
2112 B1 &lt; ExpectedBasicBlocks
2113 0 &lt; F
2114 B2 &lt; ExpectedBasicBlocks
2115 B = NumBasicBlocks + 1
2116 NumBasicBlocks &lt; ExpectedBasicBlocks
2117 TypeOf(C) == i1
2118 </pre>
2119 <p><strong>Updates</strong></p>
2120 <pre class="prettyprint">
2121 ++NumBasicBlocks;
2122 </pre>
2123 <p><strong>Examples</strong></p>
2124 <pre class="prettyprint">
2125 function i32 &#64;f2(i32 %p0, i32 %p1) {
2126 blocks: 3;
2127 %b0:
2128 %v0 = cmp eq i32 %p0, %p1;
2129 br i1 %v0, %b1, %b2;
2130 %b1:
2131 ret i32 %p0;
2132 %b2:
2133 ret i32 %p1;
2134 </pre>
2135 <p>The corresponding records are:</p>
2136 <pre class="prettyprint">
2137 1: &lt;65535, 12, 2&gt;
2138 3: &lt;1, 3&gt;
2139 3: &lt;28, 2, 1, 32&gt;
2140 3: &lt;11, 2, 1, 1&gt;
2141 3: &lt;10, 3&gt;
2142 3: &lt;10, 2&gt;
2143 0: &lt;65534&gt;
2144 </pre>
2145 </section><section id="unreachable">
2146 <h4 id="unreachable">Unreachable</h4>
2147 <p>The unreachable instruction has no defined semantics. The instruction is used to
2148 inform the <em>PNaCl translator</em> that control can&#8217;t reach this instruc tion.</p>
2149 <p><strong>Syntax</strong></p>
2150 <pre class="prettyprint">
2151 unreachable; &lt;A&gt;
2152 %bB:
2153 </pre>
2154 <p><strong>Record</strong></p>
2155 <pre class="prettyprint">
2156 AA: &lt;15&gt;
2157 </pre>
2158 <p><strong>Semantics</strong></p>
2159 <p>Directive to the <em>PNaCl translator</em> that this instruction is unreachab le. <em>A</em>
2160 is the (optional) abbreviation index associated with the record.</p>
2161 <p><em>B</em> is the number associated with the next basic block. Label <em>%bB: </em> only
2162 appears if <em>B &lt; ExpectedBasicBlocks</em>. That is, the label is omitted on ly if this
2163 terminator instruction is the last instruction in the function block.</p>
2164 <p><strong>Constraints</strong></p>
2165 <pre class="prettyprint">
2166 AA = AbbrevIndex(A)
2167 B = NumBasicBlocks + 1
2168 NumBasicBlocks &lt; ExpectedBasicBlocks
2169 </pre>
2170 <p><strong>Updates</strong></p>
2171 <pre class="prettyprint">
2172 ++NumBasicBlocks;
2173 </pre>
2174 <p><strong>Examples</strong></p>
2175 <p>TODO(kschimpf)</p>
2176 </section><section id="switch-instruction">
2177 <h4 id="switch-instruction">Switch Instruction</h4>
2178 <p>TODO(kschimpf)</p>
2179 </section></section><section id="integer-binary-inststructions">
2180 <h3 id="integer-binary-inststructions">Integer Binary Inststructions</h3>
2181 <p>Binary instructions are used to do most of the computation in a program. This
2182 section focusses on binary instructions that operator on integral values, or
2183 vectors of integral values.</p>
2184 <p>All binary operations require two operands of the same type, execute an
2185 operation on them, and produce a value. The value may represent multiple values
2186 if the type is a vector type. The result value always has the same type as its
2187 operands.</p>
2188 <p>Some integer binary operations can be applied to both signed and unsigned
2189 integers. Others, the sign is significant. In general, if the sign plays a role
2190 in the instruction, the sign information is encoded into the name of the
2191 instruction.</p>
2192 <p>For most binary operations (except some of the logical operations), integral
2193 type i1 is disallowed.</p>
2194 <section id="integer-add">
2195 <h4 id="integer-add">Integer Add</h4>
2196 <p>The integer add instruction returns the sum of its two arguments. Both argume nts
2197 and the result must be of the same type. That type must be integral, or an
2198 integral vector type.</p>
2199 <p><strong>Syntax</strong></p>
2200 <pre class="prettyprint">
2201 %vN = add T V1, V2; &lt;A&gt;
2202 </pre>
2203 <p><strong>Record</strong></p>
2204 <blockquote>
2205 <div>AA: &lt;2, VV1, VV2, 0&gt;</div></blockquote>
2206 <p><strong>Semantics</strong></p>
2207 <p>The integer add instruction returns the sum of its two arguments. Arguments < em>V1</em> and
2208 <em>V2</em>, and the result <em>%vN</em>, must be of type <em>T</em>. <em>T</em> must be an integral type,
2209 or an integral vector type. <em>N</em> is defined by the record position, defin ing the
2210 corresponding value generated by the instruction. <em>A</em> is the (optional)
2211 abbreviation associated with the corresponding record.</p>
2212 <p>Overflow conditions are ignored, and the result returned is the mathematical
2213 result modulo <em>exp(2,n)</em>, where <em>n</em> is the bitwidth of the integer result.</p>
2214 <p>Because integers are assumed to use a two&#8217;s complement representation,
2215 this instruction is appropriate for both signed and unsigned integers.</p>
2216 <p>In the add instruction, Integral type i1 (and vectors on integral type i1) is
2217 disallowed.</p>
2218 <p><strong>Constraints</strong></p>
2219 <pre class="prettyprint">
2220 AA = AbbrevIndex(A)
2221 VV1 = RelativeIndex(V1)
2222 VV2 = RelativeIndex(V2)
2223 T = TypeOf(V1) = TypeOf(V2)
2224 IsInteger(UnderlyingType(T))
2225 UnderlyingType(T) != i1
2226 N = NumValuedInsts
2227 NumBasicBlocks &lt; ExpectedBasicBlocks
2228 </pre>
2229 <p><strong>Updates</strong></p>
2230 <pre class="prettyprint">
2231 ++NumValuedInsts;
2232 TypeOf(%vN) = T
2233 </pre>
2234 <p><strong>Examples</strong></p>
2235 <pre class="prettyprint">
2236 function i32 &#64;f0(i32 %p0, i32 %p1) {
2237 blocks: 1;
2238 %b0:
2239 %v0 = add i32 %p0, %p1;
2240 %v1 = add i32 %p0, %v0;
2241 ret i32 %v1;
2242 }
2243 </pre>
2244 <p>The corresponding records are:</p>
2245 <pre class="prettyprint">
2246 1: &lt;65535, 12, 2&gt;
2247 3: &lt;1, 1&gt;
2248 3: &lt;2, 2, 1, 0&gt;
2249 3: &lt;2, 3, 1, 0&gt;
2250 3: &lt;10, 1&gt;
2251 0: &lt;65534&gt;
2252 </pre>
2253 </section><section id="integer-subtract">
2254 <h4 id="integer-subtract">Integer Subtract</h4>
2255 <p>The integer subtract instruction returns the difference of its two arguments.
2256 Both arguments and the result must be of the same type. That type must be
2257 integral, or an integral vector type.</p>
2258 <p>Note: Since there isn&#8217;t a negate instruction, subtraction from constant zero
2259 should be used to negate values.</p>
2260 <p><strong>Syntax</strong></p>
2261 <pre class="prettyprint">
2262 %vN = sub T V1, V2; &lt;A&gt;
2263 </pre>
2264 <p><strong>Record</strong></p>
2265 <pre class="prettyprint">
2266 AA: &lt;2, VV1, VV2, 1&gt;
2267 </pre>
2268 <p><strong>Semantics</strong></p>
2269 <p>The integer subtract returns the difference of its two arguments. Arguments < em>V1</em>
2270 and <em>V2</em>, and the result <em>%vN</em> must be of type <em>T</em>. <em>T</ em> must be an integral
2271 type, or an integral vector type. <em>N</em> is defined by the record position, defining
2272 the corresponding value generated by the instruction. <em>A</em> is the (optiona l)
2273 abbreviation ¯associated with the corresponding record.</p>
2274 <p>Underflow conditions are ignored, and the result returned is the mathematical
2275 result modulo <em>exp(2, n)</em>, where <em>n</em> is the integer bitwidth of th e result.</p>
2276 <p>Because integers are assumed to use a two&#8217;s complement representation,
2277 this instruction is appropriate for both signed and unsigned integers.</p>
2278 <p>In the subtract instruction, Integral type i1 is disallowed.</p>
2279 <p><strong>Constraints</strong></p>
2280 <pre class="prettyprint">
2281 AA == AbbrevIndex(A)
2282 VV1 == RelativeIndex(V1)
2283 VV2 == RelativeIndex(V2)
2284 T == TypeOf(V1) == TypeOf(V2)
2285 IsInteger(UnderlyingType(T))
2286 UnderlyingType(T) != i1
2287 N == NumValuedInsts
2288 NumBasicBlocks &lt; ExpectedBasicBlocks
2289 </pre>
2290 <p><strong>Updates</strong></p>
2291 <pre class="prettyprint">
2292 ++NumValuedInsts;
2293 TypeOf(%vN) = T
2294 </pre>
2295 <p><strong>Examples</strong></p>
2296 <pre class="prettyprint">
2297 function i32 &#64;f0(i32 %p0, i32 %p1) {
2298 blocks: 1;
2299 %b0:
2300 %v0 = sub i32 %p0, %p1;
2301 %v1 = sub i32 %p0, %v0;
2302 ret i32 %v1;
2303 }
2304 </pre>
2305 <p>The corresponding records are:</p>
2306 <pre class="prettyprint">
2307 1: &lt;65535, 12, 2&gt;
2308 3: &lt;1, 1&gt;
2309 3: &lt;2, 2, 1, 1&gt;
2310 3: &lt;2, 3, 1, 1&gt;
2311 3: &lt;10, 1&gt;
2312 0: &lt;65534&gt;
2313 </pre>
2314 </section><section id="integer-multiply">
2315 <h4 id="integer-multiply">Integer Multiply</h4>
2316 <p>The integer multiply instruction returns the product of its two arguments. B oth
2317 arguments and the result must be of the same type. That type must be integral,
2318 or an integral based vector type.</p>
2319 <p><strong>Syntax</strong></p>
2320 <pre class="prettyprint">
2321 &amp;vN = mul T V1, V2; &lt;A&gt;
2322 </pre>
2323 <p><strong>Record</strong></p>
2324 <pre class="prettyprint">
2325 AA: &lt;2, VV1, VV2, 2&gt;
2326 </pre>
2327 <p><strong>Semantics</strong></p>
2328 <p>The intebger multiply instruction returns the product of its two
2329 arguments. Arguments <em>V1</em> and <em>V2</em>, and the result <em>%vN</em>, m ust be of type <em>T</em>.
2330 <em>T</em> must be an integral type, or an integral vector type. <em>N</em> is d efined by the
2331 record position, defining the corresponding value generated by the
2332 instruction. <em>A</em> is the (optional) abbreviation associated with the
2333 corresponding record.</p>
2334 <p>Overflow conditions are ignored, and the result returned is the mathematical
2335 result modulo <em>exp(2, n)</em>, where <em>n</em> is the bitwidth of the result .</p>
2336 <p>Because integers are assumed to use a two&#8217;s complement representation,
2337 this instruction is appropriate for both signed and unsigned integers.</p>
2338 <p>In the subtract instruction, Integral type i1 is disallowed.</p>
2339 <p><strong>Constraints</strong></p>
2340 <pre class="prettyprint">
2341 AA == AbbrevIndex(A)
2342 VV1 == RelativeIndex(V1)
2343 VV2 == RelativeIndex(V2)
2344 T == TypeOf(V1) == TypeOf(V2)
2345 IsInteger(UnderlyingType(T))
2346 UnderlyingType(T) != i1
2347 N == NumValuedInsts
2348 NumBasicBlocks &lt; ExpectedBasicBlocks
2349 </pre>
2350 <p><strong>Updates</strong></p>
2351 <pre class="prettyprint">
2352 ++NumValuedInsts;
2353 TypeOf(%vN) = T
2354 </pre>
2355 <p><strong>Examples</strong></p>
2356 <pre class="prettyprint">
2357 function i32 &#64;f0(i32 %p0, i32 %p1) {
2358 blocks: 1;
2359 %b0:
2360 %v0 = mul i32 %p0, %p1;
2361 %v1 = mul i32 %v0, %p1;
2362 ret i32 %v1;
2363 }
2364 </pre>
2365 <p>The corresponding records are:</p>
2366 <pre class="prettyprint">
2367 1: &lt;65535, 12, 2&gt;
2368 3: &lt;1, 1&gt;
2369 3: &lt;2, 2, 1, 2&gt;
2370 3: &lt;2, 1, 2, 2&gt;
2371 3: &lt;10, 1&gt;
2372 0: &lt;65534&gt;
2373 </pre>
2374 </section><section id="signed-integer-divide">
2375 <h4 id="signed-integer-divide">Signed Integer Divide</h4>
2376 <p>The signed integer divide instruction returns the quotient of its two argumen ts.
2377 Both arguments and the result must be of the same type. That type must be
2378 integral, or an integral vector type.</p>
2379 <p><strong>Syntax</strong></p>
2380 <pre class="prettyprint">
2381 %vN = sdiv T V1, V2; &lt;A&gt;
2382 </pre>
2383 <p><strong>Record</strong></p>
2384 <pre class="prettyprint">
2385 AA: &lt;2, VV1, VV2, 4&gt;
2386 </pre>
2387 <p><strong>Semantics</strong></p>
2388 <p>The divide instruction returns the quotient of its two arguments. Arguments < em>V1</em>
2389 and <em>V2</em>, and the result <em>%vN</em>, must be of type <em>T</em>. <em>T< /em> must be a integral
2390 type, or an integral vector type. <em>N</em> is defined by the record position,
2391 defining the corresponding value generated by the instruction. <em>A</em> is the
2392 (optional) abbreviation associated with the corresponding record.</p>
2393 <p>Signed values are assumed. Note that signed and unsigned integer division ar e
2394 distinct operations. For unsigned integer division use the unsigned integer
2395 divide instruction (udiv).</p>
2396 <p>In the signed integer divide instruction, integral type i1 is
2397 disallowed. Integer division by zero is guaranteed to trap. Overflow is also
2398 undefined.</p>
2399 <p><strong>Constraints</strong></p>
2400 <pre class="prettyprint">
2401 AA == AbbrevIndex(A)
2402 VV1 == RelativeIndex(V1)
2403 VV2 == RelativeIndex(V2)
2404 T == TypeOf(V1) == TypeOf(V2)
2405 IsInteger(UnderlyingType(T))
2406 UnderlyingType(T) != i1
2407 N == NumValuedInsts
2408 NumBasicBlocks &lt; ExpectedBasicBlocks
2409 </pre>
2410 <p><strong>Updates</strong></p>
2411 <pre class="prettyprint">
2412 ++NumValuedInsts;
2413 TypeOf(%vN) = T
2414 </pre>
2415 <p><strong>Examples</strong></p>
2416 <pre class="prettyprint">
2417 function i32 &#64;f0(i32 %p0, i32 %p1) {
2418 blocks: 1;
2419 %b0:
2420 %v0 = sdiv i32 %p0, %p1;
2421 %v1 = sdiv i32 %v0, %p1;
2422 ret i32 %v1;
2423 }
2424 </pre>
2425 <p>The corresponding records are:</p>
2426 <pre class="prettyprint">
2427 1: &lt;65535, 12, 2&gt;
2428 3: &lt;1, 1&gt;
2429 3: &lt;2, 2, 1, 4&gt;
2430 3: &lt;2, 1, 2, 4&gt;
2431 3: &lt;10, 1&gt;
2432 0: &lt;65534&gt;
2433 </pre>
2434 </section><section id="unsigned-integer-divide">
2435 <h4 id="unsigned-integer-divide">Unsigned Integer Divide</h4>
2436 <p>The unsigned integer divide instruction returns the quotient of its two
2437 arguments. Both the arguments and the result must be of the same type. That type
2438 must be integral, or an integral vector type.</p>
2439 <p><strong>Syntax</strong></p>
2440 <pre class="prettyprint">
2441 %vN = udiv T V1, V2; &lt;a&gt;
2442 </pre>
2443 <p><strong>Record</strong></p>
2444 <pre class="prettyprint">
2445 AA: &lt;2, A1, A2, 3&gt;
2446 </pre>
2447 <p><strong>Semantics</strong></p>
2448 <p>The unsigned integer divide instruction returns the quotient of its two
2449 arguments. Arguments <em>V1</em> and <em>V2</em>, and the result <em>%vN</em>, m ust be of type
2450 <em>T</em>. <em>T</em> must be an integral type, or an integral vector type. <e m>N</em> is defined
2451 by the record position, defining the corresponding value generated by the
2452 instruction. <em>A</em> is the (optional) abbreviation associated with the
2453 corresponding record.</p>
2454 <p>Unsigned integral values are assumed. Note that signed and unsigned integer
2455 division are distinct operations. For signed integer division use the signed
2456 integer divide instruction (sdiv).</p>
2457 <p>In the unsigned integer divide instruction, Integral type i1 is
2458 disallowed. Division by zero is guaranteed to trap. Overflow is also undefined.< /p>
2459 <p><strong>Constraints</strong></p>
2460 <pre class="prettyprint">
2461 AA == AbbrevIndex(A)
2462 VV1 == RelativeIndex(V1)
2463 VV2 == RelativeIndex(V2)
2464 T == TypeOf(V1) == TypeOf(V2)
2465 IsInteger(UnderlyingType(T))
2466 UnderlyingType(T) != i1
2467 N == NumValuedInsts
2468 NumBasicBlocks &lt; ExpectedBasicBlocks
2469 </pre>
2470 <p><strong>Updates</strong></p>
2471 <pre class="prettyprint">
2472 ++NumValuedInsts;
2473 TypeOf(%vN) = T
2474 </pre>
2475 <p><strong>Examples</strong></p>
2476 <pre class="prettyprint">
2477 function i32 &#64;f0(i32 %p0, i32 %p1) {
2478 blocks: 1;
2479 %b0:
2480 %v0 = udiv i32 %p0, %p1;
2481 %v1 = udiv i32 %v0, %p1;
2482 ret i32 %v1;
2483 }
2484 </pre>
2485 <p>The corresponding records are:</p>
2486 <pre class="prettyprint">
2487 1: &lt;65535, 12, 2&gt;
2488 3: &lt;1, 1&gt;
2489 3: &lt;2, 2, 1, 3&gt;
2490 3: &lt;2, 1, 2, 3&gt;
2491 3: &lt;10, 1&gt;
2492 0: &lt;65534&gt;
2493 </pre>
2494 </section><section id="signed-integer-remainder">
2495 <h4 id="signed-integer-remainder">Signed Integer Remainder</h4>
2496 <p>The signed integer remainder instruction returns the remainder of the quotien t
2497 of its two arguments. Both arguments and the result must be of the same
2498 type. That type must be integral, or an integral based vector type.</p>
2499 <p><strong>Syntax</strong></p>
2500 <pre class="prettyprint">
2501 %vN = srem T V1, V2; &lt;A&gt;
2502 </pre>
2503 <p><strong>Record</strong></p>
2504 <pre class="prettyprint">
2505 AA: &lt;2, VV1, VV2, 6&gt;
2506 </pre>
2507 <p><strong>Semantics</strong></p>
2508 <p>The signed integer remainder instruction returns the remainder of the quotien t
2509 of its two arguments. Arguments <em>V1</em> and <em>V2</em>, and the result <em> %vN</em>, must be of
2510 type <em>T</em>. <em>T</em> must be a integral type, or an integral vector type. <em>N</em> is
2511 defined by the record position, defining the corresponding value generated by
2512 the instruction. <em>A</em> is the (optional) abbreviation associated with the
2513 corresponding record.</p>
2514 <p>Signed values are assumed. Note that signed and unsigned integer division ar e
2515 distinct operations. For unsigned integer division use the unsigned integer
2516 remainder instruction (urem).</p>
2517 <p>In the signed integer remainder instruction, Integral type i1 is disallowed.
2518 Division by zero is guaranteed to trap. Overflow is also undefined.</p>
2519 <p><strong>Constraints</strong></p>
2520 <pre class="prettyprint">
2521 AA == AbbrevIndex(A)
2522 VV1 == RelativeIndex(V1)
2523 VV2 == RelativeIndex(V2)
2524 T == TypeOf(V1) == TypeOf(V2)
2525 IsInteger(UnderlyingType(T))
2526 UnderlyingType(T) != i1
2527 N == NumValuedInsts
2528 NumBasicBlocks &lt; ExpectedBasicBlocks
2529 </pre>
2530 <p><strong>Updates</strong></p>
2531 <pre class="prettyprint">
2532 ++NumValuedInsts;
2533 TypeOf(%vN) = T
2534 </pre>
2535 <p><strong>Examples</strong></p>
2536 <pre class="prettyprint">
2537 function i32 &#64;f0(i32 %p0, i32 %p1) {
2538 blocks: 1;
2539 %b0:
2540 %v0 = srem i32 %p0, %p1;
2541 %v1 = srem i32 %v0, %p1;
2542 ret i32 %v1;
2543 }
2544 </pre>
2545 <p>The corresponding records are:</p>
2546 <pre class="prettyprint">
2547 1: &lt;65535, 12, 2&gt;
2548 3: &lt;1, 1&gt;
2549 3: &lt;2, 2, 1, 6&gt;
2550 3: &lt;2, 1, 2, 6&gt;
2551 3: &lt;10, 1&gt;
2552 0: &lt;65534&gt;
2553 </pre>
2554 </section><section id="unsigned-integer-remainder-instruction">
2555 <h4 id="unsigned-integer-remainder-instruction">Unsigned Integer Remainder Instr uction</h4>
2556 <p>The unsigned integer remainder instruction returns the remainder of the quoti ent
2557 of its two arguments. Both the arguments and the result must be of the same
2558 type. The type must be integral, or an integral vector type.</p>
2559 <p><strong>Syntax</strong></p>
2560 <pre class="prettyprint">
2561 %vN = urem T V1, V2; &lt;A&gt;
2562 </pre>
2563 <p><strong>Record</strong></p>
2564 <pre class="prettyprint">
2565 AA: &lt;2, A1, A2, 5&gt;
2566 </pre>
2567 <p><strong>Semantics</strong></p>
2568 <p>The unsigned integer remainder instruction returns the remainder of the quoti ent
2569 of its two arguments. Arguments <em>V1</em> and <em>V2</em>, and the result <em> %vN</em>, must be of
2570 type <em>T</em>. <em>T</em> must be an integral type, or an integral vector type . <em>N</em> is
2571 defined by the record position, defining the corresponding value generated by
2572 the instruction. <em>A</em> is the (optional) abbreviation associated with the
2573 corresponding record.</p>
2574 <p>Unsigned values are assumed. Note that signed and unsigned integer division a re
2575 distinct operations. For signed integer division use the remainder instruction
2576 (srem).</p>
2577 <p>In the unsigned integer remainder instruction, Integral type i1 is disallowed .
2578 Division by zero is guaranteed to trap. Overflow is also undefined.</p>
2579 <p><strong>Constraints</strong></p>
2580 <pre class="prettyprint">
2581 AA == AbbrevIndex(A)
2582 VV1 == RelativeIndex(V1)
2583 VV2 == RelativeIndex(V2)
2584 T == TypeOf(V1) == TypeOf(V2)
2585 IsInteger(UnderlyingType(T))
2586 UnderlyingType(T) != i1
2587 N == NumValuedInsts
2588 NumBasicBlocks &lt; ExpectedBasicBlocks
2589 </pre>
2590 <p><strong>Updates</strong></p>
2591 <pre class="prettyprint">
2592 ++NumValuedInsts;
2593 TypeOf(%vN) = T
2594 </pre>
2595 <p><strong>Examples</strong></p>
2596 <pre class="prettyprint">
2597 function i32 &#64;f0(i32 %p0, i32 %p1) {
2598 blocks: 1;
2599 %b0:
2600 %v0 = srem i32 %p0, %p1;
2601 %v1 = srem i32 %v0, %p1;
2602 ret i32 %v1;
2603 }
2604 </pre>
2605 <p>The corresponding records are:</p>
2606 <pre class="prettyprint">
2607 1: &lt;65535, 12, 2&gt;
2608 3: &lt;1, 1&gt;
2609 3: &lt;2, 2, 1, 5&gt;
2610 3: &lt;2, 1, 2, 5&gt;
2611 3: &lt;10, 1&gt;
2612 0: &lt;65534&gt;
2613 </pre>
2614 </section><section id="shift-left">
2615 <h4 id="shift-left">Shift left</h4>
2616 <p>The (integer) shift left instruction returns the first operand, shifted to th e
2617 left a specified number of bits with zero fill. The shifted value must be
2618 integral, or an integral vector type.</p>
2619 <p><strong>Syntax</strong></p>
2620 <pre class="prettyprint">
2621 %vN = shl T V1, V2; &lt;A&gt;
2622 </pre>
2623 <p><strong>Record</strong></p>
2624 <pre class="prettyprint">
2625 AA: &lt;2, VV1, VV2, 7&gt;
2626 </pre>
2627 <p><strong>Semantics</strong></p>
2628 <p>This instruction performs a shift left operation. Argument <em>V1</em> and th e result
2629 <em>%vN</em> must be of type <em>T</em>. <em>T</em> nust be an integral, or a ve ctor of
2630 integrals. <em>V2</em> must be an integral type. <em>N</em> is defined by the re cord position,
2631 defining the corresponding value generated by the instruction. <em>A</em> is th e
2632 (optional) abbreviation associated with the corresponding record.</p>
2633 <p><em>V2</em> is assumed to be unsigned. The least significant bits of the res ult will
2634 be filled with zero bits after the shift. If <em>V2</em> is (statically or dynam ically)
2635 is negative or equal to or larger than the number of bits in <em>V1</em>, the re sult is
2636 undefined. If the arguments are vectors, each vector element of <em>V1</em> is s hifted
2637 by the corresponding shift amount in <em>V2</em>.</p>
2638 <p>In the shift left instruction, Integral type i1 is disallowed for either
2639 argument.</p>
2640 <p><strong>Constraints</strong></p>
2641 <pre class="prettyprint">
2642 AA == AbbrevIndex(A)
2643 VV1 == RelativeIndex(V1)
2644 VV2 == RelativeIndex(V2)
2645 T == TypeOf(V1)
2646 IsInteger(TypeOf(V2))
2647 IsInteger(UnderlyingType(T))
2648 UnderlyingType(T) != i1
2649 UnderlyingType(TypeOf(V2)) != i1
2650 N == NumValuedInsts
2651 NumBasicBlocks &lt; ExpectedBasicBlocks
2652 </pre>
2653 <p><strong>Updates</strong></p>
2654 <pre class="prettyprint">
2655 ++NumValuedInsts;
2656 TypeOf(%vN) = T
2657 </pre>
2658 <p><strong>Examples</strong></p>
2659 <pre class="prettyprint">
2660 function i32 &#64;f0(i32 %p0, i32 %p1) {
2661 blocks: 1;
2662 %b0:
2663 %v0 = shl i32 %p0, %p1;
2664 %v1 = shl i32 %v0, %p1;
2665 ret i32 %v1;
2666 }
2667 </pre>
2668 <p>The corresponding records are:</p>
2669 <pre class="prettyprint">
2670 1: &lt;65535, 12, 2&gt;
2671 3: &lt;1, 1&gt;
2672 3: &lt;2, 2, 1, 7&gt;
2673 3: &lt;2, 1, 2, 7&gt;
2674 3: &lt;10, 1&gt;
2675 0: &lt;65534&gt;
2676 </pre>
2677 </section><section id="logical-shift-right">
2678 <h4 id="logical-shift-right">Logical Shift right</h4>
2679 <p>The logical shift right instruction returns the first operand, shifted
2680 to the right a specified number of bits with zero fill.</p>
2681 <p><strong>Syntax</strong></p>
2682 <pre class="prettyprint">
2683 %vN = lshr T V1, V2; &lt;A&gt;
2684 </pre>
2685 <p><strong>Record</strong></p>
2686 <pre class="prettyprint">
2687 AA: &lt;2, VV1, VV2, 8&gt;
2688 </pre>
2689 <p><strong>Semantics</strong></p>
2690 <p>This instruction performs a logical shift right operation. Arguments <em>V1</ em> and
2691 the result <em>%vN</em> must be of type <em>T</em>. <em>T</em> nust be an integr al, or a vector of
2692 integrals. <em>V2</em> must be an integral type. <em>N</em> is defined by the re cord position,
2693 defining the corresponding value generated by the instruction. <em>A</em> is th e
2694 (optional) abbreviation associated with the corresponding record.</p>
2695 <p><em>V2</em> is assumed to be unsigned. The most significant bits of the resul t will be
2696 filled with zero bits after the shift. If <em>V2</em> is (statically or dynamica lly)
2697 negative or equal to or larger than the number of bits in <em>V1</em>, the resul t is
2698 undefined. If the arguments are vectors, each vector element of <em>V1</em> is s hifted
2699 by the corresponding shift amount in <em>V2</em>.</p>
2700 <p>In the logical shift right instruction, Integral type i1 is disallowed for
2701 either argument.</p>
2702 <p><strong>Constraints</strong></p>
2703 <pre class="prettyprint">
2704 AA = AbbrevIndex(A)
2705 VV1 == RelativeIndex(V1)
2706 VV2 == RelativeIndex(V2)
2707 T == TypeOf(V1)
2708 IsInteger(TypeOf(V2))
2709 IsInteger(UnderlyingType(T))
2710 UnderlyingType(T) != i1
2711 UnderlyingType(TypeOf(V2)) != i1
2712 N == NumValuedInsts
2713 NumBasicBlocks &lt; ExpectedBasicBlocks
2714 </pre>
2715 <p><strong>Updates</strong></p>
2716 <pre class="prettyprint">
2717 ++NumValuedInsts;
2718 TypeOf(%vN) = T
2719 </pre>
2720 <p><strong>Examples</strong></p>
2721 <pre class="prettyprint">
2722 function i32 &#64;f0(i32 %p0, i32 %p1) {
2723 blocks: 1;
2724 %b0:
2725 %v0 = lshr i32 %p0, %p1;
2726 %v1 = lshr i32 %v0, %p1;
2727 ret i32 %v1;
2728 }
2729 </pre>
2730 <p>The corresponding records are:</p>
2731 <pre class="prettyprint">
2732 1: &lt;65535, 12, 2&gt;
2733 3: &lt;1, 1&gt;
2734 3: &lt;2, 2, 1, 8&gt;
2735 3: &lt;2, 1, 2, 8&gt;
2736 3: &lt;10, 1&gt;
2737 0: &lt;65534&gt;
2738 </pre>
2739 </section><section id="arithmetic-shift-right">
2740 <h4 id="arithmetic-shift-right">Arithmetic Shift Right</h4>
2741 <p>The arithmetic shift right instruction returns the first operand,
2742 shifted to the right a specified number of bits with sign extension.</p>
2743 <p><strong>Syntax</strong></p>
2744 <pre class="prettyprint">
2745 %vN = ashr T V1, V2; &lt;A&gt;
2746 </pre>
2747 <p><strong>Record</strong></p>
2748 <pre class="prettyprint">
2749 AA: &lt;2, VV1, VVA2, 9&gt;
2750 </pre>
2751 <p><strong>Semantics</strong></p>
2752 <p>This instruction performs an arithmetic shift right operation. Arguments <em> V1</em>
2753 and the result <em>%vN</em> must be of type <em>T</em>. <em>T</em> nust be an in tegral, or a vector
2754 of integrals. <em>V2</em> must be an integral type. <em>N</em> is defined by the record
2755 position, defining the corresponding value generated by the instruction. <em>A< /em> is
2756 the (optional) abbreviation associated with the corresponding record.</p>
2757 <p><em>V2</em> is assumed to be unsigned. The most significant bits of the resul t will be
2758 filled with the sign bit of <em>V1</em>. If <em>V2</em> is (statically or dynami cally)
2759 negative or equal to or larger than the number of bits in <em>V1</em>, the resul t is
2760 undefined. If the arguments are vectors, each vector element of <em>V1</em> is s hifted
2761 by the corresponding shift amount in <em>V2</em>.</p>
2762 <p>In the arithmetic shift right instruction, integral type i1 is disallowed for
2763 either argument.</p>
2764 <p><strong>Constraints</strong></p>
2765 <pre class="prettyprint">
2766 AA == AbbrevIndex(A)
2767 VV1 == RelativeIndex(V1)
2768 VV2 == RelativeIndex(V2)
2769 T == TypeOf(V1)
2770 IsInteger(TypeOf(V2))
2771 UnderlyingType(T) != i1
2772 UnderlyingType(TypeOf(V2)) != i1
2773 N == NumValuedInsts
2774 NumBasicBlocks &lt; ExpectedBasicBlocks
2775 </pre>
2776 <p><strong>Updates</strong></p>
2777 <pre class="prettyprint">
2778 ++NumValuedInsts;
2779 TypeOf(%vN) = T
2780 </pre>
2781 <p><strong>Examples</strong></p>
2782 <pre class="prettyprint">
2783 function i32 &#64;f0(i32 %p0, i32 %p1) {
2784 blocks: 1;
2785 %b0:
2786 %v0 = ashr i32 %p0, %p1;
2787 %v1 = ashr i32 %v0, %p1;
2788 ret i32 %v1;
2789 }
2790 </pre>
2791 <p>The corresponding records are:</p>
2792 <pre class="prettyprint">
2793 1: &lt;65535, 12, 2&gt;
2794 3: &lt;1, 1&gt;
2795 3: &lt;2, 2, 1, 9&gt;
2796 3: &lt;2, 1, 2, 9&gt;
2797 3: &lt;10, 1&gt;
2798 0: &lt;65534&gt;
2799 </pre>
2800 </section><section id="logical-and">
2801 <h4 id="logical-and">Logical And</h4>
2802 <p>The <em>and</em> instruction returns the bitwise logical and of its two opera nds.</p>
2803 <p><strong>Syntax</strong></p>
2804 <pre class="prettyprint">
2805 %vN = and T V1, V2; &lt;A&gt;
2806 </pre>
2807 <p><strong>Record</strong></p>
2808 <pre class="prettyprint">
2809 AA: &lt;2, VV1, VV2, 10&gt;
2810 </pre>
2811 <p><strong>Semantics</strong></p>
2812 <p>This instruction performs a bitwise logical and of its arguments. Arguments
2813 <em>V1</em> and <em>V2</em>, and the result <em>%vN</em> must be of type <em>T</ em>. <em>T</em> nust be an
2814 integral, or a vector of integrals. <em>N</em> is defined by the record position ,
2815 defining the corresponding value generated by the instruction. <em>A</em> is th e
2816 (optional) abbreviation associated with the corresponding record.</p>
2817 <p>The truth table used for the <em>and</em> instruction is:</p>
2818 <table border="1" class="docutils">
2819 <colgroup>
2820 </colgroup>
2821 <thead valign="bottom">
2822 <tr class="row-odd"><th class="head">Arg 1</th>
2823 <th class="head">Arg 2</th>
2824 <th class="head">Result</th>
2825 </tr>
2826 </thead>
2827 <tbody valign="top">
2828 <tr class="row-even"><td>0</td>
2829 <td>0</td>
2830 <td>0</td>
2831 </tr>
2832 <tr class="row-odd"><td>0</td>
2833 <td>1</td>
2834 <td>0</td>
2835 </tr>
2836 <tr class="row-even"><td>1</td>
2837 <td>0</td>
2838 <td>0</td>
2839 </tr>
2840 <tr class="row-odd"><td>1</td>
2841 <td>1</td>
2842 <td>1</td>
2843 </tr>
2844 </tbody>
2845 </table>
2846 <p><strong>Constraints</strong></p>
2847 <pre class="prettyprint">
2848 AA == AbbrevIndex(A)
2849 VV1 == RelativeIndex(V1)
2850 VV2 == RelativeIndex(V2)
2851 T == TypeOf(V1) == TypeOf(V2)
2852 IsInteger(UnderlyingType(T)))
2853 N == NumValuedInsts
2854 NumBasicBlocks &lt; ExpectedBasicBlocks
2855 </pre>
2856 <p><strong>Updates</strong></p>
2857 <pre class="prettyprint">
2858 ++NumValuedInsts;
2859 TypeOf(%vN) = T
2860 </pre>
2861 <p><strong>Examples</strong></p>
2862 <pre class="prettyprint">
2863 function i32 &#64;f0(i32 %p0, i32 %p1) {
2864 blocks: 1;
2865 %b0:
2866 %v0 = and i32 %p0, %p1;
2867 %v1 = and i32 %v0, %p1;
2868 ret i32 %v1;
2869 }
2870 </pre>
2871 <p>The corresponding records are:</p>
2872 <pre class="prettyprint">
2873 1: &lt;65535, 12, 2&gt;
2874 3: &lt;1, 1&gt;
2875 3: &lt;2, 2, 1, 10&gt;
2876 3: &lt;2, 1, 2, 10&gt;
2877 3: &lt;10, 1&gt;
2878 0: &lt;65534&gt;
2879 </pre>
2880 </section><section id="logical-or">
2881 <h4 id="logical-or">Logical Or</h4>
2882 <p>The <em>or</em> instruction returns the bitwise logical inclusive or of its
2883 two operands.</p>
2884 <p><strong>Syntax</strong></p>
2885 <pre class="prettyprint">
2886 %vN = or T V1, V2; &lt;A&gt;
2887 </pre>
2888 <p><strong>Record</strong></p>
2889 <pre class="prettyprint">
2890 AA: &lt;2, VV1, VV2, 11&gt;
2891 </pre>
2892 <p><strong>Semantics</strong></p>
2893 <p>This instruction performs a bitwise logical inclusive or of its arguments.
2894 Arguments <em>V1</em> and <em>V2</em>, and the result <em>%vN</em> must be of ty pe <em>T</em>. <em>T</em> nust be
2895 an integral, or a vector of integrals. <em>N</em> is defined by the record posit ion,
2896 defining the corresponding value generated by the instruction. <em>A</em> is th e
2897 (optional) abbreviation associated with the corresponding record.</p>
2898 <p>The truth table used for the <em>or</em> instruction is:</p>
2899 <table border="1" class="docutils">
2900 <colgroup>
2901 </colgroup>
2902 <thead valign="bottom">
2903 <tr class="row-odd"><th class="head">Arg 1</th>
2904 <th class="head">Arg 2</th>
2905 <th class="head">Result</th>
2906 </tr>
2907 </thead>
2908 <tbody valign="top">
2909 <tr class="row-even"><td>0</td>
2910 <td>0</td>
2911 <td>0</td>
2912 </tr>
2913 <tr class="row-odd"><td>0</td>
2914 <td>1</td>
2915 <td>1</td>
2916 </tr>
2917 <tr class="row-even"><td>1</td>
2918 <td>0</td>
2919 <td>1</td>
2920 </tr>
2921 <tr class="row-odd"><td>1</td>
2922 <td>1</td>
2923 <td>1</td>
2924 </tr>
2925 </tbody>
2926 </table>
2927 <p><strong>Constraints</strong></p>
2928 <pre class="prettyprint">
2929 AA == AbbrevIndex(A)
2930 VV1 == RelativeIndex(V1)
2931 VV2 == RelativeIndex(V2)
2932 T == TypeOf(V1) == TypeOf(V2)
2933 IsInteger(UnderlyingType(T)))
2934 N == NumValuedInsts
2935 NumBasicBlocks &lt; ExpectedBasicBlocks
2936 </pre>
2937 <p><strong>Updates</strong></p>
2938 <pre class="prettyprint">
2939 ++NumValuedInsts;
2940 TypeOf(%vN) = T
2941 </pre>
2942 <p><strong>Examples</strong></p>
2943 <pre class="prettyprint">
2944 function i32 &#64;f0(i32 %p0, i32 %p1) {
2945 blocks: 1;
2946 %b0:
2947 %v0 = or i32 %p0, %p1;
2948 %v1 = or i32 %v0, %p1;
2949 ret i32 %v1;
2950 }
2951 </pre>
2952 <p>The corresponding records are:</p>
2953 <pre class="prettyprint">
2954 1: &lt;65535, 12, 2&gt;
2955 3: &lt;1, 1&gt;
2956 3: &lt;2, 2, 1, 11&gt;
2957 3: &lt;2, 1, 2, 11&gt;
2958 3: &lt;10, 1&gt;
2959 0: &lt;65534&gt;
2960 </pre>
2961 </section><section id="logical-xor">
2962 <h4 id="logical-xor">Logical Xor</h4>
2963 <p>The <em>xor</em> instruction returns the bitwise logical exclusive or of its
2964 two operands.</p>
2965 <p><strong>Syntax</strong></p>
2966 <pre class="prettyprint">
2967 %vN = xor T V1, V2; &lt;A&gt;
2968 </pre>
2969 <p><strong>Record</strong></p>
2970 <pre class="prettyprint">
2971 AA: &lt;2, VV1, VV2, 12&gt;
2972 </pre>
2973 <p><strong>Semantics</strong></p>
2974 <p>This instruction performs a bitwise logical exclusive or of its
2975 arguments. Arguments <em>V1</em> and <em>V2</em>, and the result <em>%vN</em> m ust be of
2976 type <em>T</em>. <em>T</em> nust be an integral, or a vector of integrals. <em>N </em> is
2977 defined by the record position, defining the corresponding value
2978 generated by the instruction. <em>A</em> is the (optional) abbreviation
2979 associated with the corresponding record.</p>
2980 <p>The truth table used for the <em>or</em> instruction is:</p>
2981 <table border="1" class="docutils">
2982 <colgroup>
2983 </colgroup>
2984 <thead valign="bottom">
2985 <tr class="row-odd"><th class="head">Arg 1</th>
2986 <th class="head">Arg 2</th>
2987 <th class="head">Result</th>
2988 </tr>
2989 </thead>
2990 <tbody valign="top">
2991 <tr class="row-even"><td>0</td>
2992 <td>0</td>
2993 <td>0</td>
2994 </tr>
2995 <tr class="row-odd"><td>0</td>
2996 <td>1</td>
2997 <td>1</td>
2998 </tr>
2999 <tr class="row-even"><td>1</td>
3000 <td>0</td>
3001 <td>1</td>
3002 </tr>
3003 <tr class="row-odd"><td>1</td>
3004 <td>1</td>
3005 <td>0</td>
3006 </tr>
3007 </tbody>
3008 </table>
3009 <p><strong>Constraints</strong></p>
3010 <pre class="prettyprint">
3011 AA == AbbrevIndex(A)
3012 A1 == RelativeIndex(V1)
3013 A2 == RelativeIndex(V2)
3014 T == TypeOf(V1) == TypeOf(V2)
3015 IsInteger(UnderlyingType(T)))
3016 N == NumValuedInsts
3017 NumBasicBlocks &lt; ExpectedBasicBlocks
3018 </pre>
3019 <p><strong>Updates</strong></p>
3020 <pre class="prettyprint">
3021 ++NumValuedInsts;
3022 TypeOf(%vN) = T
3023 </pre>
3024 <p><strong>Examples</strong></p>
3025 <pre class="prettyprint">
3026 function i32 &#64;f0(i32 %p0, i32 %p1) {
3027 blocks: 1;
3028 %b0:
3029 %v0 = xor i32 %p0, %p1;
3030 %v1 = xor i32 %v0, %p1;
3031 ret i32 %v1;
3032 }
3033 </pre>
3034 <p>The corresponding records are:</p>
3035 <pre class="prettyprint">
3036 1: &lt;65535, 12, 2&gt;
3037 3: &lt;1, 1&gt;
3038 3: &lt;2, 2, 1, 12&gt;
3039 3: &lt;2, 1, 2, 12&gt;
3040 3: &lt;10, 1&gt;
3041 0: &lt;65534&gt;
3042 </pre>
3043 </section></section><section id="floating-binary-inststructions">
3044 <h3 id="floating-binary-inststructions">Floating Binary Inststructions</h3>
3045 <p>Floating Binary instructions require two operands of the same type, execute a n
3046 operation on them, and produce a value. The value may represent multiple values
3047 if the type is a vector type. The result value always has the same type as its
3048 operands.</p>
3049 <section id="float-add">
3050 <h4 id="float-add">Float Add</h4>
3051 <p>The float add instruction returns the sum of its two arguments. Both argument s
3052 and the result must be of the same type. That type must be floating, or a
3053 floating vector type.</p>
3054 <p><strong>Syntax</strong></p>
3055 <pre class="prettyprint">
3056 %vN = add T V1, V2; &lt;A&gt;
3057 </pre>
3058 <p><strong>Record</strong></p>
3059 <blockquote>
3060 <div>AA: &lt;2, VV1, VV2, 0&gt;</div></blockquote>
3061 <p><strong>Semantics</strong></p>
3062 <p>The float add instruction returns the sum of its two arguments. Arguments <em >V1</em>
3063 and <em>V2</em> and the result <em>%vN</em> must be of type <em>T</em>. <em>T</e m> must be a floating type,
3064 or a floating vector type. <em>N</em> is defined by the record position, definin g the
3065 corresponding value generated by the instruction. <em>A</em> is the (optional)
3066 abbreviation associated with the corresponding record.</p>
3067 <p><strong>Constraints</strong></p>
3068 <pre class="prettyprint">
3069 AA == AbbrevIndex(A)
3070 VV1 == RelativeIndex(V1)
3071 VV2 == RelativeIndex(V2)
3072 T == TypeOf(V1) == TypeOf(V2)
3073 IsFloat(UnderlyingType(T))
3074 N == NumValuedInsts
3075 NumBasicBlocks &lt; ExpectedBasicBlocks
3076 </pre>
3077 <p><strong>Updates</strong></p>
3078 <pre class="prettyprint">
3079 ++NumValuedInsts;
3080 TypeOf(%vN) = T
3081 </pre>
3082 <p><strong>Examples</strong></p>
3083 <pre class="prettyprint">
3084 function float &#64;f0(float %p0, float %p1) {
3085 blocks: 1;
3086 %b0:
3087 %v0 = add float %p0, %p1;
3088 %v1 = add float %p0, %v0;
3089 ret float %v1;
3090 }
3091 </pre>
3092 <p>The corresponding records are:</p>
3093 <pre class="prettyprint">
3094 1: &lt;65535, 12, 2&gt;
3095 3: &lt;1, 1&gt;
3096 3: &lt;2, 2, 1, 0&gt;
3097 3: &lt;2, 3, 1, 0&gt;
3098 3: &lt;10, 1&gt;
3099 0: &lt;65534&gt;
3100 </pre>
3101 </section><section id="float-subtract">
3102 <h4 id="float-subtract">Float Subtract</h4>
3103 <p>The floatsubtract instruction returns the difference of its two arguments. Bo th
3104 arguments and the result must be of the same type. That type must be a floating,
3105 or an floating based vector type.</p>
3106 <p><strong>Syntax</strong></p>
3107 <pre class="prettyprint">
3108 %vN = sub T V1, V2; &lt;a&gt;
3109 </pre>
3110 <p><strong>Record</strong></p>
3111 <pre class="prettyprint">
3112 AA: &lt;2, VV1, VV2, 1&gt;
3113 </pre>
3114 <p><strong>Semantics</strong></p>
3115 <p>The float subtract instruction returns the difference of its two
3116 arguments. Arguments <em>V1</em> and <em>V2</em>, and the result <em>%vN</em> mu st be of type
3117 <em>T</em>. <em>T</em> must be an floating type, or a floating vector type. <em> N</em> is defined by
3118 the record position, defining the corresponding value generated by the
3119 instruction. <em>A</em> is the (optional) abbreviation ¯associated with the
3120 corresponding record.</p>
3121 <p><strong>Constraints</strong></p>
3122 <pre class="prettyprint">
3123 AA == AbbrevIndex(A)
3124 VV1 == RelativeIndex(V1)
3125 VV2 == RelativeIndex(V2)
3126 T == TypeOf(V1) == TypeOf(V2)
3127 IsFloat(UnderlyingType(T))
3128 N == NumValuedInsts
3129 NumBasicBlocks &lt; ExpectedBasicBlocks
3130 </pre>
3131 <p><strong>Updates</strong></p>
3132 <pre class="prettyprint">
3133 ++NumValuedInsts;
3134 TypeOf(%vN) = T
3135 </pre>
3136 <p><strong>Examples</strong></p>
3137 <pre class="prettyprint">
3138 function float &#64;f0(float %p0, float %p1) {
3139 blocks: 1;
3140 %b0:
3141 %v0 = sub float %p0, %p1;
3142 %v1 = sub float %p0, %v0;
3143 ret float %v1;
3144 }
3145 </pre>
3146 <p>The corresponding records are:</p>
3147 <pre class="prettyprint">
3148 1: &lt;65535, 12, 2&gt;
3149 3: &lt;1, 1&gt;
3150 3: &lt;2, 2, 1, 1&gt;
3151 3: &lt;2, 3, 1, 1&gt;
3152 3: &lt;10, 1&gt;
3153 0: &lt;65534&gt;
3154 </pre>
3155 </section><section id="float-multiply">
3156 <h4 id="float-multiply">Float Multiply</h4>
3157 <p>The float multiply instruction returns the product of its two arguments. Both
3158 arguments and the result must be of the same type. That type must be floating,
3159 or a floating based vector type.</p>
3160 <p><strong>Syntax</strong></p>
3161 <pre class="prettyprint">
3162 &amp;vN = mul T V1, V2; &lt;A&gt;
3163 </pre>
3164 <p><strong>Record</strong></p>
3165 <pre class="prettyprint">
3166 AA: &lt;2, VV1, VV2, 2&gt;
3167 </pre>
3168 <p><strong>Semantics</strong></p>
3169 <p>The multiply instruction returns the product of its two arguments. Arguments
3170 <em>V1</em> and <em>V2</em>, and the result <em>%vN</em> must be of type <em>T</ em>. <em>T</em> must be an
3171 floating type, or a floating vector type. <em>N</em> is defined by the record po sition,
3172 defining the corresponding value generated by the instruction. <em>A</em> is the
3173 (optional) abbreviation associated with the corresponding record.</p>
3174 <p><strong>Constraints</strong></p>
3175 <pre class="prettyprint">
3176 AA == AbbrevIndex(A)
3177 VV1 == RelativeIndex(V1)
3178 VV2 == RelativeIndex(V2)
3179 T == TypeOf(V1) == TypeOf(V2)
3180 IsFloat(UnderlyingType(T))
3181 N == NumValuedInsts
3182 NumBasicBlocks &lt; ExpectedBasicBlocks
3183 </pre>
3184 <p><strong>Updates</strong></p>
3185 <pre class="prettyprint">
3186 ++NumValuedInsts;
3187 TypeOf(%vN) = T
3188 </pre>
3189 <p><strong>Examples</strong></p>
3190 <pre class="prettyprint">
3191 function float &#64;f0(float %p0, float %p1) {
3192 blocks: 1;
3193 %b0:
3194 %v0 = mul float %p0, %p1;
3195 %v1 = mul float %p0, %v0;
3196 ret float %v1;
3197 }
3198 </pre>
3199 <p>The corresponding records are:</p>
3200 <pre class="prettyprint">
3201 1: &lt;65535, 12, 2&gt;
3202 3: &lt;1, 1&gt;
3203 3: &lt;2, 2, 1, 2&gt;
3204 3: &lt;2, 3, 1, 2&gt;
3205 3: &lt;10, 1&gt;
3206 0: &lt;65534&gt;
3207 </pre>
3208 </section><section id="float-divide">
3209 <h4 id="float-divide">Float Divide</h4>
3210 <p>The float divide instruction returns the quotient of its two arguments. Both
3211 arguments and the result must be of the same type. That type must be a floating
3212 type, or a floating based vector type.</p>
3213 <p><strong>Syntax</strong></p>
3214 <pre class="prettyprint">
3215 %vN = div T V1, V2; &lt;A&gt;
3216 </pre>
3217 <p><strong>Record</strong></p>
3218 <pre class="prettyprint">
3219 AA: &lt;2, V1, V2, 4&gt;
3220 </pre>
3221 <p><strong>Semantics</strong></p>
3222 <p>The float divide instruction returns the quotient of its two
3223 arguments. Arguments <em>V1</em> and <em>V2</em>, and the result <em>%vN</em> mu st be of type
3224 <em>T</em>. <em>T</em> must be a floating type, or a floating vector type. <em>N </em> is defined by
3225 the record position, defining the corresponding value generated by the
3226 instruction. <em>A</em> is the (optional) abbreviation associated with the
3227 corresponding record.</p>
3228 <p><strong>Constraints</strong></p>
3229 <pre class="prettyprint">
3230 AA == AbbrevIndex(A)
3231 VV1 == RelativeIndex(V1)
3232 VV22 == RelativeIndex(V2)
3233 T == TypeOf(V1) == TypeOf(V2)
3234 IsFloat(UnderlyingType(T))
3235 N == NumValuedInsts
3236 NumBasicBlocks &lt; ExpectedBasicBlocks
3237 </pre>
3238 <p><strong>Updates</strong></p>
3239 <pre class="prettyprint">
3240 ++NumValuedInsts;
3241 TypeOf(%vN) = T
3242 </pre>
3243 <p><strong>Examples</strong></p>
3244 <pre class="prettyprint">
3245 function double &#64;f0(double %p0, double %p1) {
3246 blocks: 1;
3247 %b0:
3248 %v0 = div double %p0, %p1;
3249 %v1 = div double %p0, %v0;
3250 ret double %v1;
3251 }
3252 </pre>
3253 <p>The corresponding records are:</p>
3254 <pre class="prettyprint">
3255 1: &lt;65535, 12, 2&gt;
3256 3: &lt;1, 1&gt;
3257 3: &lt;2, 2, 1, 4&gt;
3258 3: &lt;2, 3, 1, 4&gt;
3259 3: &lt;10, 1&gt;
3260 0: &lt;65534&gt;
3261 </pre>
3262 </section><section id="float-remainder">
3263 <h4 id="float-remainder">Float Remainder</h4>
3264 <p>The float remainder instruction returns the remainder of the quotient of its two
3265 arguments. Both arguments and the result must be of the same type. That type
3266 must be a floating type, or a floating based vector type.</p>
3267 <p><strong>Syntax</strong></p>
3268 <pre class="prettyprint">
3269 %vN = rem T V1, V2; &lt;A&gt;
3270 </pre>
3271 <p><strong>Record</strong></p>
3272 <pre class="prettyprint">
3273 AA: &lt;2, VV1, VV2, 6&gt;
3274 </pre>
3275 <p><strong>Semantics</strong></p>
3276 <p>The float remainder instruction returns the remainder of the quotient of its two
3277 arguments. Arguments <em>V1</em> and <em>V2</em>, and the result <em>%vN</em> mu st be of type
3278 <em>T</em>. <em>T</em> must be a floating type, or a floating vector type. <em>N </em> is defined by
3279 the record position, defining the corresponding value generated by the
3280 instruction. <em>A</em> is the (optional) abbreviation associated with the
3281 corresponding record.</p>
3282 <p><strong>Constraints</strong></p>
3283 <pre class="prettyprint">
3284 AA == AbbrevIndex(A)
3285 VV1 == RelativeIndex(V1)
3286 VV2 == RelativeIndex(V2)
3287 T == TypeOf(V1) == TypeOf(V2)
3288 IsFloat(UnderlyingType(T))
3289 N == NumValuedInsts
3290 NumBasicBlocks &lt; ExpectedBasicBlocks
3291 </pre>
3292 <p><strong>Updates</strong></p>
3293 <pre class="prettyprint">
3294 ++NumValuedInsts;
3295 TypeOf(%vN) = T
3296 </pre>
3297 <p><strong>Examples</strong></p>
3298 <pre class="prettyprint">
3299 function double &#64;f0(double %p0, double %p1) {
3300 blocks: 1;
3301 %b0:
3302 %v0 = rem double %p0, %p1;
3303 %v1 = rem double %p0, %v0;
3304 ret double %v1;
3305 }
3306 </pre>
3307 <p>The corresponding records are:</p>
3308 <pre class="prettyprint">
3309 1: &lt;65535, 12, 2&gt;
3310 3: &lt;1, 1&gt;
3311 3: &lt;2, 2, 1, 6&gt;
3312 3: &lt;2, 3, 1, 6&gt;
3313 3: &lt;10, 1&gt;
3314 0: &lt;65534&gt;
3315 </pre>
3316 </section></section><section id="memory-creation-and-access-instructions">
3317 <h3 id="memory-creation-and-access-instructions">Memory creation and access Inst ructions</h3>
3318 <p>A key design point of SSA-based representation is how it represents
3319 memory. In PNaCl bitcode files, no memory locations are in SSA
3320 form. This makes things very simple.</p>
3321 <section id="alloca-instruction">
3322 <h4 id="alloca-instruction">Alloca Instruction</h4>
3323 <p>The <em>alloca</em> instruction allocates memory on the stack frame of the
3324 currently executing function. This memory is automatically released
3325 when the function returns to its caller.</p>
3326 <p><strong>Syntax</strong></p>
3327 <pre class="prettyprint">
3328 %vN = alloca i8, i32 S, align V; &lt;A&gt;
3329 %vN = alloca i8, i32 S; &lt;A&gt;
3330 </pre>
3331 <p><strong>Record</strong></p>
3332 <pre class="prettyprint">
3333 AA: &lt;19, SS, VV&gt;
3334 </pre>
3335 <p><strong>Semantics</strong></p>
3336 <p>The <em>alloca</em> instruction allocates memory on the stack frame of the cu rrently
3337 executing function. The resulting value is a pointer to the allocated memory
3338 (i.e. of type i32). <em>S</em> is the number of bytes that are allocated on the
3339 stack. <em>S</em> must be of integral type i32. <em>V</em> is the aligment of th e generated
3340 stack address. <em>A</em> is the corresponding number of bits associated with th e
3341 record.</p>
3342 <p>Alignment must be a power of 2. A value of 0 means that the address
3343 has the ABI alignment of the target. If alignment is not specified,
3344 zero is used. Alignment on the stack is guaranteed to be aligned to at least
3345 the boundary specified by the alignment.</p>
3346 <p>TODO(kschimpf) Other alignment issues?</p>
3347 <p><strong>Constraints</strong></p>
3348 <pre class="prettyprint">
3349 AA == AbbrevIndex(A)
3350 VV == Log2(V+1)
3351 SS == RelativeIndex(S)
3352 i32 == TypeOf(S)
3353 N == NumValuedInsts
3354 NumBasicBlocks &lt; ExpectedBasicBlocks
3355 </pre>
3356 <p><strong>Updates</strong></p>
3357 <pre class="prettyprint">
3358 ++NumValuedInsts;
3359 TypeOf(%vN) = i32;
3360 </pre>
3361 <p><strong>Examples</strong></p>
3362 <p>The following instructions allocates memory for a 32-bit integer and a
3363 64-bit floating value:</p>
3364 <pre class="prettyprint">
3365 function void &#64;f() {
3366 blocks: 1;
3367 constants {
3368 i32:
3369 %c0 = 4; // == sizeof(i32)
3370 %c1 = 8; // == sizeof(double)
3371 }
3372 %b0:
3373 %v0 = alloca i8, i32 %c0;
3374 %v1 = alloca i8, i32 %c1;
3375 ret;
3376 }
3377 </pre>
3378 <p>Assuming <em>TypeId(i32) == &#64;t1</em>, the corresponding records are:</p>
3379 <pre class="prettyprint">
3380 1: &lt;65535, 12, 2&gt;
3381 3: &lt;1, 1&gt;
3382 1: &lt;65535, 11, 2&gt;
3383 3: &lt;1, 1&gt;
3384 3: &lt;4, 8&gt;
3385 3: &lt;4, 16&gt;
3386 0: &lt;65534&gt;
3387 3: &lt;19, 2, 0&gt;
3388 3: &lt;19, 2, 0&gt;
3389 3: &lt;10&gt;
3390 0: &lt;65534&gt;
3391 </pre>
3392 </section><section id="load-instruction">
3393 <h4 id="load-instruction">Load Instruction</h4>
3394 <p>The <em>load</em> instruction is used to read from memory.</p>
3395 <p><strong>Syntax</strong></p>
3396 <pre class="prettyprint">
3397 %vN = load T* P, align V; &lt;A&gt;
3398 </pre>
3399 <p><strong>Record</strong></p>
3400 <pre class="prettyprint">
3401 AA: &lt;20, PP, VV, TT&gt;
3402 </pre>
3403 <p><strong>Semantics</strong></p>
3404 <p>The load instruction is used to read from memory. <em>P</em> is identifier of the
3405 memory address to read. The type of <em>P</em> must be an i32 integer. <em>T</e m> is the type
3406 of value to read. <em>V</em> is the alignment of the memory address. <em>A</em> is the
3407 (optional) abbreviation associated with the record.</p>
3408 <p>Type <em>T</em> must be an integral or floating type. Both float and double t ypes
3409 are allowed for floating types. All integral types except i1 is allowed.</p>
3410 <p>Valid alignment <em>V</em> values are:</p>
3411 <table border="1" class="docutils">
3412 <colgroup>
3413 </colgroup>
3414 <thead valign="bottom">
3415 <tr class="row-odd"><th class="head"><em>V</em></th>
3416 <th class="head">Types</th>
3417 </tr>
3418 </thead>
3419 <tbody valign="top">
3420 <tr class="row-even"><td>1</td>
3421 <td>i8, i16, i32, i64</td>
3422 </tr>
3423 <tr class="row-odd"><td>4</td>
3424 <td>float</td>
3425 </tr>
3426 <tr class="row-even"><td>8</td>
3427 <td>double</td>
3428 </tr>
3429 </tbody>
3430 </table>
3431 <p><strong>Constraints</strong></p>
3432 <blockquote>
3433 <div>AA == AbbrevIndex(A)
3434 i32 == TypeOf(P)
3435 PP == RelativeIndex(P)
3436 VV == Log2(V+1)
3437 %tTT == TypeID(T)
3438 N == NumValuedInsts
3439 NumBasicBlocks &lt; ExpectedBasicBlocks</div></blockquote>
3440 <p><strong>Updates</strong></p>
3441 <pre class="prettyprint">
3442 ++NumValuedInsts;
3443 TypeOf(%vN) = T;
3444 </pre>
3445 <p><strong>Examples</strong></p>
3446 <p>The following instructions load an i32 integer and a 64-bit floating value:</ p>
3447 <pre class="prettyprint">
3448 function void &#64;f(i32 %p0) {
3449 blocks: 1;
3450 %b0:
3451 %v0 = load i32* %p0, align 1;
3452 %v1 = load double* %v0, align 8;
3453 ret;
3454 }
3455 </pre>
3456 <p>The corresponding records are:</p>
3457 <pre class="prettyprint">
3458 1: &lt;65535, 12, 2&gt;
3459 3: &lt;1, 1&gt;
3460 3: &lt;20, 1, 1&gt;
3461 3: &lt;20, 1, 4&gt;
3462 3: &lt;10&gt;
3463 0: &lt;65534&gt;
3464 </pre>
3465 </section><section id="store-instruction">
3466 <h4 id="store-instruction">Store Instruction</h4>
3467 <p>The <em>store</em> instruction is used to write to memory.</p>
3468 <p><strong>Syntax</strong></p>
3469 <pre class="prettyprint">
3470 store T S, T* P, align V; &lt;A&gt;
3471 </pre>
3472 <p><strong>Record</strong></p>
3473 <pre class="prettyprint">
3474 AA: &lt;24, PP, SS, VV&gt;
3475 </pre>
3476 <p><strong>Semantics</strong></p>
3477 <p>The store instruction is used to write to memory. <em>P</em> is the identifie r of the
3478 memory address to write to. The type of <em>P</em> must be an i32 integer. <em >T</em> is the
3479 type of value to store. <em>S</em> is the value to store, and must be of type <e m>T</em>. <em>V</em>
3480 is the alignment of the memory address. <em>A</em> is the (optional) abbreviati on
3481 index associated with the record.</p>
3482 <p>Type <em>T</em> must be an integral or floating type. Both float and double t ypes
3483 are allowed for floating types. All integral types except i1 is allowed.</p>
3484 <p>Valid alignment <em>V</em> values are:</p>
3485 <table border="1" class="docutils">
3486 <colgroup>
3487 </colgroup>
3488 <thead valign="bottom">
3489 <tr class="row-odd"><th class="head"><em>V</em></th>
3490 <th class="head">Types</th>
3491 </tr>
3492 </thead>
3493 <tbody valign="top">
3494 <tr class="row-even"><td>1</td>
3495 <td>i8, i16, i32, i64</td>
3496 </tr>
3497 <tr class="row-odd"><td>4</td>
3498 <td>float</td>
3499 </tr>
3500 <tr class="row-even"><td>8</td>
3501 <td>double</td>
3502 </tr>
3503 </tbody>
3504 </table>
3505 <p><strong>Constraints</strong></p>
3506 <pre class="prettyprint">
3507 AA == AbbrevIndex(A)
3508 i32 == TypeOf(P)
3509 PP == RelativeIndex(P)
3510 VV == Log2(V+1)
3511 NumBasicBlocks &lt; ExpectedBasicBlocks
3512 </pre>
3513 <p><strong>Examples</strong></p>
3514 <p>The following instructions store an i32 integer and a 32-bit floating
3515 value.</p>
3516 <pre class="prettyprint">
3517 function void &#64;f(i32 %p0, i32 %p1, i32 %p2, float %p3) {
3518 blocks: 1;
3519 %b0:
3520 store i32 %p1, i32* %p2, align 1;
3521 store float %p3, float* %p3, align 4;
3522 ret;
3523 }
3524 </pre>
3525 <p>The corresponding records are:</p>
3526 <pre class="prettyprint">
3527 1: &lt;65535, 12, 2&gt;
3528 3: &lt;1, 1&gt;
3529 3: &lt;24, 4, 3, 1&gt;
3530 3: &lt;24, 1, 2, 4&gt;
3531 3: &lt;10&gt;
3532 0: &lt;65534&gt;
3533 </pre>
3534 </section></section><section id="conversion-instructions">
3535 <h3 id="conversion-instructions">Conversion Instructions</h3>
3536 <p>Conversion instructions all take a single operand and a type. The
3537 value is converted to the corresponding type.</p>
3538 <section id="integer-truncating-instruction">
3539 <h4 id="integer-truncating-instruction">Integer truncating Instruction</h4>
3540 <p>The integer truncating instruction takes a value to truncate, and a type
3541 defining the truncated type. Both types must be integer types, or integral
3542 vectors of the same size. The bit size of the value must be larger than the bit
3543 size of the destination type. Equal sized types are not allowed.</p>
3544 <p><strong>Syntax</strong></p>
3545 <pre class="prettyprint">
3546 %vN = trunc T1 V to T2; &lt;A&gt;
3547 </pre>
3548 <p><strong>Record</strong></p>
3549 <pre class="prettyprint">
3550 AA: &lt;3, VV, TT2, 0&gt;
3551 </pre>
3552 <p><strong>Semantics</strong></p>
3553 <p>The integer truncating instruction takes a value <em>V</em>, and truncates to type
3554 <em>T2</em>. <em>A</em> is the (optional) abbreviation associated with the corre sponding
3555 record. Both <em>T1</em> and <em>T2</em> must be integer types, or integral vect ors of the
3556 same size.</p>
3557 <p><strong>Constraints</strong></p>
3558 <pre class="prettyprint">
3559 AA == AbbrevIndex(A)
3560 TypeOf(V) = T1
3561 *VV* == RelativeIndex(*V*)
3562 %tTT2 = TypeID(T2)
3563 BitSizeOf(UnderlyingType(T1)) &gt; BitSizeOf(UnderlyingType(T2))
3564 UnderlyingCount(T1) == UnderlyingCount(T2)
3565 IsInteger(UnderlyingType(T1))
3566 IsInteger(UnderlyingType(T2))
3567 N == NumValuedInsts
3568 NumBasicBlocks &lt; ExpectedBasicBlocks
3569 </pre>
3570 <p><strong>Updates</strong></p>
3571 <pre class="prettyprint">
3572 ++NumValuedInsts;
3573 TypeOf(%vN) = T2;
3574 </pre>
3575 <p><strong>Examples</strong></p>
3576 <pre class="prettyprint">
3577 %v10 = trunc i32 %v9 to i8;
3578 </pre>
3579 <p>Assuming</p>
3580 <pre class="prettyprint">
3581 &#64;t2 = i8;
3582 </pre>
3583 <p>the corresponding record is:</p>
3584 <pre class="prettyprint">
3585 &lt;3, 1, 2, 0&gt;
3586 </pre>
3587 </section><section id="floating-truncating-instruction">
3588 <h4 id="floating-truncating-instruction">Floating truncating Instruction</h4>
3589 <p>The floating truncating instruction takes a value to truncate, and a type
3590 defining the truncated type. Both types must be floating types, or floating
3591 vectors of the same size. The bit size of the value must be larger than the bit
3592 size of the destination type. Equal sized types are not allowed.</p>
3593 <p><strong>Syntax</strong></p>
3594 <pre class="prettyprint">
3595 %vN = fptrunc T1 V to T2; &lt;A&gt;
3596 </pre>
3597 <p><strong>Record</strong></p>
3598 <pre class="prettyprint">
3599 AA: &lt;3, VV, TT2, 7&gt;
3600 </pre>
3601 <p><strong>Semantics</strong></p>
3602 <p>The floating truncating instruction takes a value <em>V</em>, and truncates t o type
3603 <em>T2</em>. <em>A</em> is the (optional) abbreviation associated with the corre sponding
3604 record. Both <em>T1</em> and <em>T2</em> must be integer types, or integral vect ors of the
3605 same size.</p>
3606 <p>If the value can&#8217;t fit within the destination type <em>T2</em>, the res ults are
3607 undefined.</p>
3608 <p><strong>Constraints</strong></p>
3609 <pre class="prettyprint">
3610 TypeOf(V) = T1
3611 double == UnderlyingType(T1)
3612 float == UnderlyingType(T2)
3613 *VV* == RelativeIndex(*V*)
3614 %tTT2 = TypeID(T2)
3615 BitSizeOf(UnderlyingType(T1)) &gt; BitSizeOf(UnderlyingType(T2))
3616 UnderlyingCount(T1) == UnderlyingCount(T2)
3617 IsFloat(UnderlyingType(T1))
3618 IsFloat(UnderlyingType(T2))
3619 N == NumValuedInsts
3620 NumBasicBlocks &lt; ExpectedBasicBlocks
3621 </pre>
3622 <p><strong>Updates</strong></p>
3623 <pre class="prettyprint">
3624 ++NumValuedInsts;
3625 TypeOf(%vN) = T2;
3626 </pre>
3627 <p><strong>Examples</strong></p>
3628 <pre class="prettyprint">
3629 %v10 = fptrunc double %v9 to float;
3630 </pre>
3631 <p>Assuming</p>
3632 <pre class="prettyprint">
3633 &#64;t4 = float;
3634 </pre>
3635 <p>the corresponding record is:</p>
3636 <pre class="prettyprint">
3637 &lt;3, 1, 4, 7&gt;
3638 </pre>
3639 </section><section id="zero-extending-instruction">
3640 <h4 id="zero-extending-instruction">Zero Extending Instruction</h4>
3641 <p>The zero extending instruction takes an value to cast, and a type to extend i t
3642 to. Both types must be integer types, or integral vectors of the same size. The
3643 bit size of the value must be smaller than the bitsize of the destination
3644 type. Equal sized types are not allowed.</p>
3645 <p><strong>Syntax</strong></p>
3646 <pre class="prettyprint">
3647 %vN = zext T1 V to T2; &lt;A&gt;
3648 </pre>
3649 <p><strong>Record</strong></p>
3650 <pre class="prettyprint">
3651 AA: &lt;3, VV, TT2, 1&gt;
3652 </pre>
3653 <p><strong>Semantics</strong></p>
3654 <p>The zero extending instruction takes a value <em>V</em>, and expands it to ty pe
3655 <em>T2</em>. <em>I</em> is the (optional) abbreviation associated with the corre sponding
3656 record. Both <em>T1</em> and <em>T2</em> must be integer types, or vectors of t he same number
3657 of integers.</p>
3658 <p>The instruction fills the high order bits of the value with zero bits
3659 until it reaches the size of the destination type. When zero extending
3660 from i1, the result will always be either 0 or 1.</p>
3661 <p><strong>Constraints</strong></p>
3662 <pre class="prettyprint">
3663 AA == AbbrevIndex(A)
3664 TypeOf(V) = T1
3665 *VV* == RelativeIndex(*V*)
3666 %tTT2 = TypeID(T2)
3667 BitSizeOf(UnderlyingType(T1)) &lt; BitSizeOf(UnderlyingType(T2))
3668 UnderlyingCount(T1) == UnderlyingCount(T2)
3669 IsInteger(UnderlyingType(T1))
3670 IsInteger(UnderlyingType(T2))
3671 N == NumValuedInsts
3672 NumBasicBlocks &lt; ExpectedBasicBlocks
3673 </pre>
3674 <p><strong>Updates</strong></p>
3675 <pre class="prettyprint">
3676 ++NumValuedInsts;
3677 TypeOf(%vN) = T2;
3678 </pre>
3679 <p><strong>Examples</strong></p>
3680 <pre class="prettyprint">
3681 %v12 = zext i8 %v11 to i32;
3682 </pre>
3683 <p>Assuming</p>
3684 <pre class="prettyprint">
3685 &#64;t0 = i32;
3686 </pre>
3687 <p>the corresponding record is:</p>
3688 <pre class="prettyprint">
3689 &lt;3, 1, 0, 2&gt;
3690 </pre>
3691 </section><section id="sign-extending-instruction">
3692 <h4 id="sign-extending-instruction">Sign Extending Instruction</h4>
3693 <p>The sign extending instruction takes an value to cast, and a type to
3694 extend it to. Both types must be integer types, or vectors of the same
3695 number of integers. The bit size of the value must be smaller than the
3696 bitsize of the destination type. Equal sized types are not allowed.</p>
3697 <p><strong>Syntax</strong></p>
3698 <pre class="prettyprint">
3699 %vN = sext T1 V to T2; &lt;I&gt;
3700 </pre>
3701 <p><strong>Record</strong></p>
3702 <pre class="prettyprint">
3703 I: &lt;3, VV, TT2, 2&gt;
3704 </pre>
3705 <p><strong>Semantics</strong></p>
3706 <p>The sign extending instruction takes a value <em>V</em>, and expands it to
3707 type <em>T2</em>. <em>VV</em> is the relative index of <em>V</em>. <em>I</em> is the (optional)
3708 abbreviation associated with the corresponding record. Both <em>T1</em> and
3709 <em>T2</em> must be integer types, or vectors of the same number of integers.</p >
3710 <p>When sign extending, the instruction fills the high order bits of the
3711 value with the (current) high order bit of the value. When sign
3712 extending from i1, the extension always results in -1 or 0.</p>
3713 <p><strong>Constraints</strong></p>
3714 <pre class="prettyprint">
3715 TypeOf(V) = T1
3716 *VV* == RelativeIndex(*V*)
3717 %tTT2 = TypeID(T2)
3718 BitSizeOf(UnderlyingType(T1)) &lt; BitSizeOf(UnderlyingType(T2))
3719 UnderlyingCount(T1) == UnderlyingCount(T2)
3720 IsInteger(UnderlyingType(T1))
3721 IsInteger(UnderlyingType(T2))
3722 N == NumValuedInsts
3723 NumBasicBlocks &lt; ExpectedBasicBlocks
3724 </pre>
3725 <p><strong>Updates</strong></p>
3726 <pre class="prettyprint">
3727 ++NumValuedInsts;
3728 TypeOf(%vN) = T2;
3729 </pre>
3730 <p><strong>Examples</strong></p>
3731 <pre class="prettyprint">
3732 %v12 = sext i8 %v11 to i32;
3733 </pre>
3734 <p>Assuming</p>
3735 <pre class="prettyprint">
3736 &#64;t0 = i32;
3737 </pre>
3738 <p>the corresponding record is:</p>
3739 <pre class="prettyprint">
3740 &lt;3, 1, 0, 2&gt;
3741 </pre>
3742 </section><section id="fpext">
3743 <h4 id="fpext">fpext</h4>
3744 <p>TODO(kschimpf)</p>
3745 </section><section id="fptoui">
3746 <h4 id="fptoui">fptoui</h4>
3747 <p>TODO(kschimpf)</p>
3748 </section><section id="fptosi">
3749 <h4 id="fptosi">fptosi</h4>
3750 <p>TODO(kschimpf)</p>
3751 </section><section id="sitofp">
3752 <h4 id="sitofp">sitofp</h4>
3753 <p>TODO(kschimpf)</p>
3754 </section><section id="bitcast">
3755 <h4 id="bitcast">bitcast</h4>
3756 <p>TODO(kschimpf)</p>
3757 </section></section><section id="comparison-instructions">
3758 <h3 id="comparison-instructions">Comparison Instructions</h3>
3759 <p>TODO(kschimpf): cmp</p>
3760 </section><section id="other-instructions">
3761 <h3 id="other-instructions">Other Instructions</h3>
3762 <p>TODO(kschimpf)</p>
3763 <section id="phi-instruction">
3764 <h4 id="phi-instruction">Phi Instruction</h4>
3765 <p>TODO(kschimpf)</p>
3766 </section><section id="forward-type-declarations">
3767 <h4 id="forward-type-declarations">Forward type declarations</h4>
3768 <p>TODO(kschimpf)</p>
3769 </section><section id="select-instruction">
3770 <h4 id="select-instruction">Select Instruction</h4>
3771 <p>TODO(kschimpf)</p>
3772 </section><section id="call-instructions">
3773 <h4 id="call-instructions">Call Instructions</h4>
3774 <p>TODO(kschimpf)</p>
3775 </section></section><section id="intrinsic-functions">
3776 <h3 id="intrinsic-functions">Intrinsic Functions</h3>
3777 <p>TODO(kschimpf)</p>
3778 </section></section><section id="support-functions">
3779 <h2 id="support-functions">Support Functions</h2>
3780 <p>Defines functions used to convert syntactic representation to corresponding
3781 records.</p>
3782 <section id="signrotate">
3783 <h3 id="signrotate">SignRotate</h3>
3784 <p>The SignRotate function encodes a signed integer in an easily compressable
3785 form. This is done by rotating the sign bit to the rightmost bit, rather than
3786 the leftmost bit. By doing this rotation, both small positive and negative
3787 integers are small (unsigned) integers. Therefore, all small integers can be
3788 encoded as a small (unsigned) integers.</p>
3789 <p>The definition of SignRotate(N) is:</p>
3790 <table border="1" class="docutils">
3791 <colgroup>
3792 </colgroup>
3793 <thead valign="bottom">
3794 <tr class="row-odd"><th class="head">Argument</th>
3795 <th class="head">Value</th>
3796 <th class="head">Condition</th>
3797 </tr>
3798 </thead>
3799 <tbody valign="top">
3800 <tr class="row-even"><td>N</td>
3801 <td>abs(N)&lt;&lt;1</td>
3802 <td>N &gt;= 0</td>
3803 </tr>
3804 <tr class="row-odd"><td>N</td>
3805 <td>abs(N)&lt;&lt;1 + 1</td>
3806 <td>N &lt; 0</td>
3807 </tr>
3808 </tbody>
3809 </table>
3810 </section><section id="absoluteindex">
3811 <h3 id="absoluteindex">AbsoluteIndex</h3>
3812 <p>Bitcode ID&#8217;s of the forms <em>&#64;fN</em>, <em>&#64;gN</em>, <em>%pN</ em>, <em>%cN</em>, and <em>%vN</em>, are combined
3813 into a single index space. This can be done because of the ordering imposed by
3814 PNaClAsm. All function address bitcode IDs must be defined before any of the
3815 other forms of bitcode IDs. All global address bitcode IDs must be defined
3816 before any local bitcode IDs. Within a function block, the parameter bitcode IDs
3817 must be defined before constant IDs, and constant IDs must be defined before
3818 instruction value IDs.</p>
3819 <p>Hence, within a function block, it is safe to refer to all of these
3820 bitcode IDs using a single <em>absolute</em> index. The abolute index for
3821 each kind of bitcode ID is computed as follows:</p>
3822 <table border="1" class="docutils">
3823 <colgroup>
3824 </colgroup>
3825 <thead valign="bottom">
3826 <tr class="row-odd"><th class="head">Bitcode ID</th>
3827 <th class="head">AbsoluteIndex</th>
3828 </tr>
3829 </thead>
3830 <tbody valign="top">
3831 <tr class="row-even"><td>&#64;fN</td>
3832 <td>N</td>
3833 </tr>
3834 <tr class="row-odd"><td>&#64;gN</td>
3835 <td>N + NumDefinedFcnAddresses</td>
3836 </tr>
3837 <tr class="row-even"><td>&#64;pN</td>
3838 <td>N + NumDefinedFcnAddresses + NumGlobalAddresses</td>
3839 </tr>
3840 <tr class="row-odd"><td>&#64;cN</td>
3841 <td>N + NumDefinedFcnAddresses + NumGlobalAddresses + NumParams</td>
3842 </tr>
3843 <tr class="row-even"><td>&#64;vN</td>
3844 <td>N + NumDefinedFcnAddresses + NumGlobalAddresses + NumParams + NumFcnConsts</ td>
3845 </tr>
3846 </tbody>
3847 </table>
3848 </section><section id="relativeindex">
3849 <h3 id="relativeindex">RelativeIndex</h3>
3850 <p>Relative indices are used to refer to values within instructions of a
3851 function. The relative index of an ID is always defined in terms of
3852 the index associated with the next value generating instruction. It is
3853 defined as follows:</p>
3854 <pre class="prettyprint">
3855 RelativeIndex(J) = AbsoluteIndex(NumValuedInsts) - AbsoluteIndex(J)
3856 </pre>
3857 </section><section id="abbrevindex">
3858 <h3 id="abbrevindex">AbbrevIndex</h3>
3859 <p>This function converts user-defined abbreviation indices to the corresponding
3860 internal abbreviation index saved in the bitcode file. It adds 4 to its argument ,
3861 since there are 4 predefined internal abbreviation indices (0, 1, 2, and 3).</p>
3862 <table border="1" class="docutils">
3863 <colgroup>
3864 </colgroup>
3865 <thead valign="bottom">
3866 <tr class="row-odd"><th class="head">N</th>
3867 <th class="head">AbbrevIndex(N)</th>
3868 </tr>
3869 </thead>
3870 <tbody valign="top">
3871 <tr class="row-even"><td>undefined</td>
3872 <td>3</td>
3873 </tr>
3874 <tr class="row-odd"><td>%aA</td>
3875 <td>A + 4</td>
3876 </tr>
3877 <tr class="row-even"><td>&#64;aA</td>
3878 <td>A + 4</td>
3879 </tr>
3880 </tbody>
3881 </table>
3882 </section><section id="log2">
3883 <h3 id="log2">Log2</h3>
3884 <p>This is the 32-bit log2 value of its argument.</p>
3885 </section><section id="exp">
3886 <h3 id="exp">exp</h3>
3887 <pre class="prettyprint">
3888 exp(n, m)
3889 </pre>
3890 <p>Denotes the <em>m</em> power of <em>n</em>.</p>
3891 </section><section id="bitsizeof">
3892 <h3 id="bitsizeof">BitSizeOf</h3>
3893 <p>Returns the number of bits needed to represent its argument (a type).</p>
3894 </section><section id="underlyingtype">
3895 <h3 id="underlyingtype">UnderlyingType</h3>
3896 <p>Returns the primitive type of the type construct. For primitive types,
3897 the <em>UnderlyingType</em> is itself. For vector types, the base type of the
3898 vector is the underlying type.</p>
3899 </section><section id="underlyingcount">
3900 <h3 id="underlyingcount">UnderlyingCount</h3>
3901 <p>Returns the number of primitive types in the construct. For primitive
3902 types, the <em>UnderlyingCount</em> is 1. For vector types, it returns the
3903 number of elements in the vector.</p>
3904 </section><section id="isinteger">
3905 <h3 id="isinteger">IsInteger</h3>
3906 <p>Returns true if the argument is in {i1, i8, i16, i32, i64}.</p>
3907 </section><section id="isfloat">
3908 <h3 id="isfloat">IsFloat</h3>
3909 <p>Returns true if the argument is in {float, double}.</p>
3910 </section><section id="abbreviations">
3911 <h3 id="abbreviations">Abbreviations</h3>
3912 <p>TODO(kschimpf)</p>
3913 <section id="id4">
3914 <h4 id="id4">Introduction</h4>
3915 <p>TODO(kschimpf)</p>
3916 <ul class="small-gap">
3917 <li>Blocks</li>
3918 <li>Data Records</li>
3919 <li>Abbreviations</li>
3920 <li>Abbreviation Ids.</li>
3921 </ul>
3922 </section><section id="bitstream-format">
3923 <h4 id="bitstream-format">Bitstream Format</h4>
3924 <p>TODO(kschimpf)</p>
3925 <ul class="small-gap">
3926 <li>Header</li>
3927 <li>Block Structue</li>
3928 <li>Primitives</li>
3929 <li>Abbreviations</li>
3930 <li>BlockInfoBlock</li>
3931 </ul>
3932 </section></section><section id="reference-implementation">
3933 <h3 id="reference-implementation">Reference Implementation</h3>
3934 <p>TODO(kschimpf)</p>
3935 </section></section></section>
3936
3937 {{/partials.standard_nacl_article}}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698