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