BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / native_client_sdk / doc_generated / reference / pnacl-bitcode-abi.html
blob6367b419585ae125b91a4d6b28992ddd847f9b15
1 {{+bindTo:partials.standard_nacl_article}}
3 <section id="pnacl-bitcode-reference-manual">
4 <h1 id="pnacl-bitcode-reference-manual">PNaCl Bitcode 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="id1">Introduction</a></li>
8 <li><p class="first"><a class="reference internal" href="#high-level-structure" id="id2">High Level Structure</a></p>
9 <ul class="small-gap">
10 <li><a class="reference internal" href="#data-model" id="id3">Data Model</a></li>
11 <li><a class="reference internal" href="#linkage-types" id="id4">Linkage Types</a></li>
12 <li><a class="reference internal" href="#calling-conventions" id="id5">Calling Conventions</a></li>
13 <li><a class="reference internal" href="#visibility-styles" id="id6">Visibility Styles</a></li>
14 <li><a class="reference internal" href="#global-variables" id="id7">Global Variables</a></li>
15 <li><a class="reference internal" href="#functions" id="id8">Functions</a></li>
16 <li><a class="reference internal" href="#aliases" id="id9">Aliases</a></li>
17 <li><a class="reference internal" href="#named-metadata" id="id10">Named Metadata</a></li>
18 <li><a class="reference internal" href="#module-level-inline-assembly" id="id11">Module-Level Inline Assembly</a></li>
19 <li><a class="reference internal" href="#volatile-memory-accesses" id="id12">Volatile Memory Accesses</a></li>
20 <li><a class="reference internal" href="#memory-model-for-concurrent-operations" id="id13">Memory Model for Concurrent Operations</a></li>
21 <li><a class="reference internal" href="#fast-math-flags" id="id14">Fast-Math Flags</a></li>
22 </ul>
23 </li>
24 <li><p class="first"><a class="reference internal" href="#type-system" id="id15">Type System</a></p>
25 <ul class="small-gap">
26 <li><a class="reference internal" href="#scalar-types" id="id16">Scalar types</a></li>
27 <li><a class="reference internal" href="#vector-types" id="id17">Vector types</a></li>
28 <li><a class="reference internal" href="#array-and-struct-types" id="id18">Array and struct types</a></li>
29 <li><a class="reference internal" href="#pointer-types" id="id19">Pointer types</a></li>
30 <li><a class="reference internal" href="#undefined-values" id="id20">Undefined Values</a></li>
31 <li><a class="reference internal" href="#constant-expressions" id="id21">Constant Expressions</a></li>
32 </ul>
33 </li>
34 <li><p class="first"><a class="reference internal" href="#other-values" id="id22">Other Values</a></p>
35 <ul class="small-gap">
36 <li><a class="reference internal" href="#metadata-nodes-and-metadata-strings" id="id23">Metadata Nodes and Metadata Strings</a></li>
37 </ul>
38 </li>
39 <li><a class="reference internal" href="#intrinsic-global-variables" id="id24">Intrinsic Global Variables</a></li>
40 <li><a class="reference internal" href="#errno-and-errors-in-arithmetic-instructions" id="id25">Errno and errors in arithmetic instructions</a></li>
41 <li><p class="first"><a class="reference internal" href="#instruction-reference" id="id26">Instruction Reference</a></p>
42 <ul class="small-gap">
43 <li><a class="reference internal" href="#list-of-allowed-instructions" id="id27">List of allowed instructions</a></li>
44 <li><a class="reference internal" href="#alloca" id="id28"><code>alloca</code></a></li>
45 </ul>
46 </li>
47 <li><p class="first"><a class="reference internal" href="#intrinsic-functions" id="id29">Intrinsic Functions</a></p>
48 <ul class="small-gap">
49 <li><a class="reference internal" href="#list-of-allowed-intrinsics" id="id30">List of allowed intrinsics</a></li>
50 <li><a class="reference internal" href="#thread-pointer-related-intrinsics" id="id31">Thread pointer related intrinsics</a></li>
51 <li><a class="reference internal" href="#setjmp-and-longjmp" id="id32">Setjmp and Longjmp</a></li>
52 <li><a class="reference internal" href="#atomic-intrinsics" id="id33">Atomic intrinsics</a></li>
53 </ul>
54 </li>
55 </ul>
57 </div><h2 id="introduction">Introduction</h2>
58 <p>This document is a reference manual for the PNaCl bitcode format. It describes
59 the bitcode on a <em>semantic</em> level; the physical encoding level will be described
60 elsewhere. For the purpose of this document, the textual form of LLVM IR is
61 used to describe instructions and other bitcode constructs.</p>
62 <p>Since the PNaCl bitcode is based to a large extent on LLVM IR as of
63 version 3.3, many sections in this document point to a relevant section
64 of the LLVM language reference manual. Only the changes, restrictions
65 and variations specific to PNaCl are described&#8212;full semantic
66 descriptions are not duplicated from the LLVM reference manual.</p>
67 <h2 id="high-level-structure">High Level Structure</h2>
68 <p>A PNaCl portable executable (<strong>pexe</strong> in short) is a single LLVM IR module.</p>
69 <h3 id="data-model">Data Model</h3>
70 <p>The data model for PNaCl bitcode is fixed at little-endian ILP32: pointers are
71 32 bits in size. 64-bit integer types are also supported natively via the i64
72 type (for example, a front-end can generate these from the C/C++ type
73 <code>long long</code>).</p>
74 <p>Floating point support is fixed at IEEE 754 32-bit and 64-bit values (f32 and
75 f64, respectively).</p>
76 <h3 id="linkage-types"><span id="bitcode-linkagetypes"></span>Linkage Types</h3>
77 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#linkage">LLVM LangRef: Linkage Types</a></p>
78 <p>The linkage types supported by PNaCl bitcode are <code>internal</code> and <code>external</code>.
79 A single function in the pexe, named <code>_start</code>, has the linkage type
80 <code>external</code>. All the other functions and globals have the linkage type
81 <code>internal</code>.</p>
82 <h3 id="calling-conventions">Calling Conventions</h3>
83 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#callingconv">LLVM LangRef: Calling Conventions</a></p>
84 <p>The only calling convention supported by PNaCl bitcode is <code>ccc</code> - the C
85 calling convention.</p>
86 <h3 id="visibility-styles">Visibility Styles</h3>
87 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#visibility-styles">LLVM LangRef: Visibility Styles</a></p>
88 <p>PNaCl bitcode does not support visibility styles.</p>
89 <h3 id="global-variables"><span id="bitcode-globalvariables"></span>Global Variables</h3>
90 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#globalvars">LLVM LangRef: Global Variables</a></p>
91 <p>Restrictions on global variables:</p>
92 <ul class="small-gap">
93 <li>PNaCl bitcode does not support LLVM IR TLS models. See
94 <a class="reference internal" href="/native-client/reference/pnacl-c-cpp-language-support.html#language-support-threading"><em>Threading</em></a> for more details.</li>
95 <li>Restrictions on <a class="reference internal" href="#bitcode-linkagetypes"><em>linkage types</em></a>.</li>
96 <li>The <code>addrspace</code>, <code>section</code>, <code>unnamed_addr</code> and
97 <code>externally_initialized</code> attributes are not supported.</li>
98 </ul>
99 <p>Every global variable must have an initializer. Each initializer must be
100 either a <em>SimpleElement</em> or a <em>CompoundElement</em>, defined as follows.</p>
101 <p>A <em>SimpleElement</em> is one of the following:</p>
102 <ol class="arabic simple">
103 <li>An i8 array literal or <code>zeroinitializer</code>:</li>
104 </ol>
105 <pre>
106 [SIZE x i8] c&quot;DATA&quot;
107 [SIZE x i8] zeroinitializer
108 </pre>
109 <ol class="arabic simple" start="2">
110 <li>A reference to a <em>GlobalValue</em> (a function or global variable) with an
111 optional 32-bit byte offset added to it (the addend, which may be
112 negative):</li>
113 </ol>
114 <pre>
115 ptrtoint (TYPE* &#64;GLOBAL to i32)
116 add (i32 ptrtoint (TYPE* &#64;GLOBAL to i32), i32 ADDEND)
117 </pre>
118 <p>A <em>CompoundElement</em> is a unnamed, packed struct containing more than one
119 <em>SimpleElement</em>.</p>
120 <h3 id="functions">Functions</h3>
121 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#functionstructure">LLVM LangRef: Functions</a></p>
122 <p>The restrictions on <a class="reference internal" href="#bitcode-linkagetypes"><em>linkage types</em></a>, calling
123 conventions and visibility styles apply to functions. In addition, the following
124 are not supported for functions:</p>
125 <ul class="small-gap">
126 <li>Function attributes (either for the the function itself, its parameters or its
127 return type).</li>
128 <li>Garbage collector name (<code>gc</code>).</li>
129 <li>Functions with a variable number of arguments (<em>vararg</em>).</li>
130 <li>Alignment (<code>align</code>).</li>
131 </ul>
132 <h3 id="aliases">Aliases</h3>
133 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#aliases">LLVM LangRef: Aliases</a></p>
134 <p>PNaCl bitcode does not support aliases.</p>
135 <h3 id="named-metadata">Named Metadata</h3>
136 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#namedmetadatastructure">LLVM LangRef: Named Metadata</a></p>
137 <p>While PNaCl bitcode has provisions for debugging metadata, it is not considered
138 part of the stable ABI. It exists for tool support and should not appear in
139 distributed pexes.</p>
140 <p>Other kinds of LLVM metadata are not supported.</p>
141 <h3 id="module-level-inline-assembly">Module-Level Inline Assembly</h3>
142 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#moduleasm">LLVM LangRef: Module-Level Inline Assembly</a></p>
143 <p>PNaCl bitcode does not support inline assembly.</p>
144 <h3 id="volatile-memory-accesses">Volatile Memory Accesses</h3>
145 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#volatile">LLVM LangRef: Volatile Memory Accesses</a></p>
146 <p>PNaCl bitcode does not support volatile memory accesses. The
147 <code>volatile</code> attribute on loads and stores is not supported. See the
148 <a class="reference internal" href="/native-client/reference/pnacl-c-cpp-language-support.html"><em>PNaCl C/C++ Language Support</em></a> for more details.</p>
149 <h3 id="memory-model-for-concurrent-operations">Memory Model for Concurrent Operations</h3>
150 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#memmodel">LLVM LangRef: Memory Model for Concurrent Operations</a></p>
151 <p>See the <a class="reference internal" href="/native-client/reference/pnacl-c-cpp-language-support.html"><em>PNaCl C/C++ Language Support</em></a>
152 for details.</p>
153 <h3 id="fast-math-flags">Fast-Math Flags</h3>
154 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#fastmath">LLVM LangRef: Fast-Math Flags</a></p>
155 <p>Fast-math mode is not currently supported by the PNaCl bitcode.</p>
156 <h2 id="type-system">Type System</h2>
157 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#typesystem">LLVM LangRef: Type System</a></p>
158 <p>The LLVM types allowed in PNaCl bitcode are restricted, as follows:</p>
159 <h3 id="scalar-types">Scalar types</h3>
160 <ul class="small-gap">
161 <li><p class="first">The only scalar types allowed are integer, float (32-bit floating point),
162 double (64-bit floating point) and void.</p>
163 <ul class="small-gap">
164 <li>The only integer sizes allowed are i1, i8, i16, i32 and i64.</li>
165 <li>The only integer sizes allowed for function arguments and function return
166 values are i32 and i64.</li>
167 </ul>
168 </li>
169 </ul>
170 <h3 id="vector-types">Vector types</h3>
171 <p>The only vector types allowed are:</p>
172 <ul class="small-gap">
173 <li>128-bit vectors integers of elements size i8, i16, i32.</li>
174 <li>128-bit vectors of float elements.</li>
175 <li>Vectors of i1 type with element counts corresponding to the allowed
176 element counts listed previously (their width is therefore not
177 128-bits).</li>
178 </ul>
179 <h3 id="array-and-struct-types">Array and struct types</h3>
180 <p>Array and struct types are only allowed in
181 <a class="reference internal" href="#bitcode-globalvariables"><em>global variable initializers</em></a>.</p>
182 <h3 id="pointer-types"><span id="bitcode-pointertypes"></span>Pointer types</h3>
183 <p>Only the following pointer types are allowed:</p>
184 <ul class="small-gap">
185 <li>Pointers to valid PNaCl bitcode scalar types, as specified above, except for
186 <code>i1</code>.</li>
187 <li>Pointers to valid PNaCl bitcode vector types, as specified above, except for
188 <code>&lt;? x i1&gt;</code>.</li>
189 <li>Pointers to functions.</li>
190 </ul>
191 <p>In addition, the address space for all pointers must be 0.</p>
192 <p>A pointer is <em>inherent</em> when it represents the return value of an <code>alloca</code>
193 instruction, or is an address of a global value.</p>
194 <p>A pointer is <em>normalized</em> if it&#8217;s either:</p>
195 <ul class="small-gap">
196 <li><em>inherent</em></li>
197 <li>Is the return value of a <code>bitcast</code> instruction.</li>
198 <li>Is the return value of a <code>inttoptr</code> instruction.</li>
199 </ul>
200 <h3 id="undefined-values">Undefined Values</h3>
201 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#undefvalues">LLVM LangRef: Undefined Values</a></p>
202 <p><code>undef</code> is only allowed within functions, not in global variable initializers.</p>
203 <h3 id="constant-expressions">Constant Expressions</h3>
204 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#constant-expressions">LLVM LangRef: Constant Expressions</a></p>
205 <p>Constant expressions are only allowed in
206 <a class="reference internal" href="#bitcode-globalvariables"><em>global variable initializers</em></a>.</p>
207 <h2 id="other-values">Other Values</h2>
208 <h3 id="metadata-nodes-and-metadata-strings">Metadata Nodes and Metadata Strings</h3>
209 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#metadata">LLVM LangRef: Metadata Nodes and Metadata Strings</a></p>
210 <p>While PNaCl bitcode has provisions for debugging metadata, it is not considered
211 part of the stable ABI. It exists for tool support and should not appear in
212 distributed pexes.</p>
213 <p>Other kinds of LLVM metadata are not supported.</p>
214 <h2 id="intrinsic-global-variables">Intrinsic Global Variables</h2>
215 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#intrinsic-global-variables">LLVM LangRef: Intrinsic Global Variables</a></p>
216 <p>PNaCl bitcode does not support intrinsic global variables.</p>
217 <h2 id="errno-and-errors-in-arithmetic-instructions"><span id="ir-and-errno"></span>Errno and errors in arithmetic instructions</h2>
218 <p>Some arithmetic instructions and intrinsics have the similar semantics to
219 libc math functions, but differ in the treatment of <code>errno</code>. While the
220 libc functions may set <code>errno</code> for domain errors, the instructions and
221 intrinsics do not. This is because the variable <code>errno</code> is not special
222 and is not required to be part of the program.</p>
223 <h2 id="instruction-reference">Instruction Reference</h2>
224 <h3 id="list-of-allowed-instructions">List of allowed instructions</h3>
225 <p>This is a list of LLVM instructions supported by PNaCl bitcode. Where
226 applicable, PNaCl-specific restrictions are provided.</p>
227 <p>The following attributes are disallowed for all instructions:</p>
228 <ul class="small-gap">
229 <li><code>nsw</code> and <code>nuw</code></li>
230 <li><code>exact</code></li>
231 </ul>
232 <p>Only the LLVM instructions listed here are supported by PNaCl bitcode.</p>
233 <ul class="small-gap">
234 <li><code>ret</code></li>
235 <li><code>br</code></li>
236 <li><p class="first"><code>switch</code></p>
237 <p>i1 values are disallowed for <code>switch</code>.</p>
238 </li>
239 <li><p class="first"><code>add</code>, <code>sub</code>, <code>mul</code>, <code>shl</code>, <code>udiv</code>, <code>sdiv</code>, <code>urem</code>, <code>srem</code>,
240 <code>lshr</code>, <code>ashr</code></p>
241 <p>These arithmetic operations are disallowed on values of type <code>i1</code>.</p>
242 <p>Integer division (<code>udiv</code>, <code>sdiv</code>, <code>urem</code>, <code>srem</code>) by zero is
243 guaranteed to trap in PNaCl bitcode.</p>
244 </li>
245 <li><code>and</code></li>
246 <li><code>or</code></li>
247 <li><code>xor</code></li>
248 <li><code>fadd</code></li>
249 <li><code>fsub</code></li>
250 <li><code>fmul</code></li>
251 <li><code>fdiv</code></li>
252 <li><p class="first"><code>frem</code></p>
253 <p>The frem instruction has the semantics of the libc fmod function for
254 computing the floating point remainder. If the numerator is infinity, or
255 denominator is zero, or either are NaN, then the result is NaN.
256 Unlike the libc fmod function, this does not set <code>errno</code> when the
257 result is NaN (see the <a class="reference internal" href="#ir-and-errno"><em>instructions and errno</em></a>
258 section).</p>
259 </li>
260 <li><p class="first"><code>alloca</code></p>
261 <p>See <a class="reference internal" href="#bitcode-allocainst"><em>alloca instructions</em></a>.</p>
262 </li>
263 <li><p class="first"><code>load</code>, <code>store</code></p>
264 <p>The pointer argument of these instructions must be a <em>normalized</em> pointer (see
265 <a class="reference internal" href="#bitcode-pointertypes"><em>pointer types</em></a>). The <code>volatile</code> and <code>atomic</code>
266 attributes are not supported. Loads and stores of the type <code>i1</code> and <code>&lt;? x
267 i1&gt;</code> are not supported.</p>
268 <p>These instructions must follow the following alignment restrictions:</p>
269 <ul class="small-gap">
270 <li>On integer memory accesses: <code>align 1</code>.</li>
271 <li>On <code>float</code> memory accesses: <code>align 1</code> or <code>align 4</code>.</li>
272 <li>On <code>double</code> memory accesses: <code>align 1</code> or <code>align 8</code>.</li>
273 <li>On vector memory accesses: alignment at the vector&#8217;s element width, for
274 example <code>&lt;4 x i32&gt;</code> must be <code>align 4</code>.</li>
275 </ul>
276 </li>
277 <li><code>trunc</code></li>
278 <li><code>zext</code></li>
279 <li><code>sext</code></li>
280 <li><code>fptrunc</code></li>
281 <li><code>fpext</code></li>
282 <li><code>fptoui</code></li>
283 <li><code>fptosi</code></li>
284 <li><code>uitofp</code></li>
285 <li><code>sitofp</code></li>
286 <li><p class="first"><code>ptrtoint</code></p>
287 <p>The pointer argument of a <code>ptrtoint</code> instruction must be a <em>normalized</em>
288 pointer (see <a class="reference internal" href="#bitcode-pointertypes"><em>pointer types</em></a>) and the integer
289 argument must be an i32.</p>
290 </li>
291 <li><p class="first"><code>inttoptr</code></p>
292 <p>The integer argument of a <code>inttoptr</code> instruction must be an i32.</p>
293 </li>
294 <li><p class="first"><code>bitcast</code></p>
295 <p>The pointer argument of a <code>bitcast</code> instruction must be a <em>inherent</em> pointer
296 (see <a class="reference internal" href="#bitcode-pointertypes"><em>pointer types</em></a>).</p>
297 </li>
298 <li><code>icmp</code></li>
299 <li><code>fcmp</code></li>
300 <li><code>phi</code></li>
301 <li><code>select</code></li>
302 <li><code>call</code></li>
303 <li><code>unreachable</code></li>
304 <li><code>insertelement</code></li>
305 <li><code>extractelement</code></li>
306 </ul>
307 <h3 id="alloca"><span id="bitcode-allocainst"></span><code>alloca</code></h3>
308 <p>The only allowed type for <code>alloca</code> instructions in PNaCl bitcode is i8. The
309 size argument must be an i32. For example:</p>
310 <pre>
311 %buf = alloca i8, i32 8, align 4
312 </pre>
313 <h2 id="intrinsic-functions">Intrinsic Functions</h2>
314 <p><a class="reference external" href="http://llvm.org/releases/3.3/docs/LangRef.html#intrinsics">LLVM LangRef: Intrinsic Functions</a></p>
315 <h3 id="list-of-allowed-intrinsics">List of allowed intrinsics</h3>
316 <p>The only intrinsics supported by PNaCl bitcode are the following.</p>
317 <ul class="small-gap">
318 <li><code>llvm.memcpy</code></li>
319 <li><code>llvm.memmove</code></li>
320 <li><p class="first"><code>llvm.memset</code></p>
321 <p>These intrinsics are only supported with an i32 <code>len</code> argument.</p>
322 </li>
323 <li><p class="first"><code>llvm.bswap</code></p>
324 <p>The overloaded <code>llvm.bswap</code> intrinsic is only supported with the following
325 argument types: i16, i32, i64 (the types supported by C-style GCC builtins).</p>
326 </li>
327 <li><code>llvm.ctlz</code></li>
328 <li><code>llvm.cttz</code></li>
329 <li><p class="first"><code>llvm.ctpop</code></p>
330 <p>The overloaded <code>llvm.ctlz</code>, <code>llvm.cttz</code>, and <code>llvm.ctpop</code> intrinsics
331 are only supported with the i32 and i64 argument types (the types
332 supported by C-style GCC builtins).</p>
333 </li>
334 <li><p class="first"><code>llvm.fabs</code></p>
335 <p>The overloaded <code>llvm.fabs</code> intrinsic is supported for float, double and
336 <code>&lt;4 x float&gt;</code> argument types. It returns the absolute value of
337 the argument. Some notable points: it returns <code>+0.0</code> when given <code>-0.0</code>,
338 <code>+inf</code> when given <code>-inf</code>, and a positive <code>NaN</code> when given any
339 signed <code>NaN</code>.</p>
340 <p>NOTE: This intrinsic was introduced in the pepper_42 SDK.</p>
341 </li>
342 <li><p class="first"><code>llvm.sqrt</code></p>
343 <p>The overloaded <code>llvm.sqrt</code> intrinsic is only supported for float
344 and double arguments types. This has the same semantics as the libc
345 sqrt function, returning <code>NaN</code> for values less than <code>-0.0</code>.
346 However, this does not set <code>errno</code> when the result is NaN (see the
347 <a class="reference internal" href="#ir-and-errno"><em>instructions and errno</em></a> section).</p>
348 </li>
349 <li><code>llvm.stacksave</code></li>
350 <li><p class="first"><code>llvm.stackrestore</code></p>
351 <p>These intrinsics are used to implement language features like scoped automatic
352 variable sized arrays in C99. <code>llvm.stacksave</code> returns a value that
353 represents the current state of the stack. This value may only be used as the
354 argument to <code>llvm.stackrestore</code>, which restores the stack to the given
355 state.</p>
356 </li>
357 <li><p class="first"><code>llvm.trap</code></p>
358 <p>This intrinsic is lowered to a target dependent trap instruction, which aborts
359 execution.</p>
360 </li>
361 <li><p class="first"><code>llvm.nacl.read.tp</code></p>
362 <p>See <a class="reference internal" href="#bitcode-threadpointerintrinsics"><em>thread pointer related intrinsics</em></a>.</p>
363 </li>
364 <li><code>llvm.nacl.longjmp</code></li>
365 <li><p class="first"><code>llvm.nacl.setjmp</code></p>
366 <p>See <a class="reference internal" href="#bitcode-setjmplongjmp"><em>Setjmp and Longjmp</em></a>.</p>
367 </li>
368 <li><code>llvm.nacl.atomic.store</code></li>
369 <li><code>llvm.nacl.atomic.load</code></li>
370 <li><code>llvm.nacl.atomic.rmw</code></li>
371 <li><code>llvm.nacl.atomic.cmpxchg</code></li>
372 <li><code>llvm.nacl.atomic.fence</code></li>
373 <li><code>llvm.nacl.atomic.fence.all</code></li>
374 <li><p class="first"><code>llvm.nacl.atomic.is.lock.free</code></p>
375 <p>See <a class="reference internal" href="#bitcode-atomicintrinsics"><em>atomic intrinsics</em></a>.</p>
376 </li>
377 </ul>
378 <h3 id="thread-pointer-related-intrinsics"><span id="bitcode-threadpointerintrinsics"></span>Thread pointer related intrinsics</h3>
379 <pre>
380 declare i8* &#64;llvm.nacl.read.tp()
381 </pre>
382 <p>Returns a read-only thread pointer. The value is controlled by the embedding
383 sandbox&#8217;s runtime.</p>
384 <h3 id="setjmp-and-longjmp"><span id="bitcode-setjmplongjmp"></span>Setjmp and Longjmp</h3>
385 <pre>
386 declare void &#64;llvm.nacl.longjmp(i8* %jmpbuf, i32)
387 declare i32 &#64;llvm.nacl.setjmp(i8* %jmpbuf)
388 </pre>
389 <p>These intrinsics implement the semantics of C11 <code>setjmp</code> and <code>longjmp</code>. The
390 <code>jmpbuf</code> pointer must be 64-bit aligned and point to at least 1024 bytes of
391 allocated memory.</p>
392 <h3 id="atomic-intrinsics"><span id="bitcode-atomicintrinsics"></span>Atomic intrinsics</h3>
393 <pre>
394 declare iN &#64;llvm.nacl.atomic.load.&lt;size&gt;(
395 iN* &lt;source&gt;, i32 &lt;memory_order&gt;)
396 declare void &#64;llvm.nacl.atomic.store.&lt;size&gt;(
397 iN &lt;operand&gt;, iN* &lt;destination&gt;, i32 &lt;memory_order&gt;)
398 declare iN &#64;llvm.nacl.atomic.rmw.&lt;size&gt;(
399 i32 &lt;computation&gt;, iN* &lt;object&gt;, iN &lt;operand&gt;, i32 &lt;memory_order&gt;)
400 declare iN &#64;llvm.nacl.atomic.cmpxchg.&lt;size&gt;(
401 iN* &lt;object&gt;, iN &lt;expected&gt;, iN &lt;desired&gt;,
402 i32 &lt;memory_order_success&gt;, i32 &lt;memory_order_failure&gt;)
403 declare void &#64;llvm.nacl.atomic.fence(i32 &lt;memory_order&gt;)
404 declare void &#64;llvm.nacl.atomic.fence.all()
405 </pre>
406 <p>Each of these intrinsics is overloaded on the <code>iN</code> argument, which is
407 reflected through <code>&lt;size&gt;</code> in the overload&#8217;s name. Integral types of
408 8, 16, 32 and 64-bit width are supported for these arguments.</p>
409 <p>The <code>&#64;llvm.nacl.atomic.rmw</code> intrinsic implements the following
410 read-modify-write operations, from the general and arithmetic sections
411 of the C11/C++11 standards:</p>
412 <blockquote>
413 <div><ul class="small-gap">
414 <li><code>add</code></li>
415 <li><code>sub</code></li>
416 <li><code>or</code></li>
417 <li><code>and</code></li>
418 <li><code>xor</code></li>
419 <li><code>exchange</code></li>
420 </ul>
421 </div></blockquote>
422 <p>For all of these read-modify-write operations, the returned value is
423 that at <code>object</code> before the computation. The <code>computation</code> argument
424 must be a compile-time constant.</p>
425 <p>All atomic intrinsics also support C11/C++11 memory orderings, which
426 must be compile-time constants.</p>
427 <p>Integer values for these computations and memory orderings are defined
428 in <code>&quot;llvm/IR/NaClAtomicIntrinsics.h&quot;</code>.</p>
429 <p>The <code>&#64;llvm.nacl.atomic.fence.all</code> intrinsic is equivalent to the
430 <code>&#64;llvm.nacl.atomic.fence</code> intrinsic with sequentially consistent
431 ordering and compiler barriers preventing most non-atomic memory
432 accesses from reordering around it.</p>
433 <aside class="note">
434 <blockquote>
435 <div>These intrinsics allow PNaCl to support C11/C++11 style atomic
436 operations as well as some legacy GCC-style <code>__sync_*</code> builtins
437 while remaining stable as the LLVM codebase changes. The user isn&#8217;t
438 expected to use these intrinsics directly.</div></blockquote>
440 </aside>
441 <pre>
442 declare i1 &#64;llvm.nacl.atomic.is.lock.free(i32 &lt;byte_size&gt;, i8* &lt;address&gt;)
443 </pre>
444 <p>The <code>llvm.nacl.atomic.is.lock.free</code> intrinsic is designed to
445 determine at translation time whether atomic operations of a certain
446 <code>byte_size</code> (a compile-time constant), at a particular <code>address</code>,
447 are lock-free or not. This reflects the C11 <code>atomic_is_lock_free</code>
448 function from header <code>&lt;stdatomic.h&gt;</code> and the C++11 <code>is_lock_free</code>
449 member function in header <code>&lt;atomic&gt;</code>. It can be used through the
450 <code>__nacl_atomic_is_lock_free</code> builtin.</p>
451 </section>
453 {{/partials.standard_nacl_article}}