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