Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / native_client_sdk / doc_generated / reference / pnacl-c-cpp-language-support.html
blob3b76173177ad762ee82cff4cbda9083416c39dcb
1 {{+bindTo:partials.standard_nacl_article}}
3 <section id="pnacl-c-c-language-support">
4 <h1 id="pnacl-c-c-language-support">PNaCl C/C++ Language Support</h1>
5 <div class="contents local" id="contents" style="display: none">
6 <ul class="small-gap">
7 <li><p class="first"><a class="reference internal" href="#source-language-support" id="id3">Source language support</a></p>
8 <ul class="small-gap">
9 <li><a class="reference internal" href="#versions" id="id4">Versions</a></li>
10 <li><a class="reference internal" href="#preprocessor-definitions" id="id5">Preprocessor definitions</a></li>
11 </ul>
12 </li>
13 <li><p class="first"><a class="reference internal" href="#memory-model-and-atomics" id="id6">Memory Model and Atomics</a></p>
14 <ul class="small-gap">
15 <li><a class="reference internal" href="#memory-model-for-concurrent-operations" id="id7">Memory Model for Concurrent Operations</a></li>
16 <li><a class="reference internal" href="#atomic-memory-ordering-constraints" id="id8">Atomic Memory Ordering Constraints</a></li>
17 <li><a class="reference internal" href="#volatile-memory-accesses" id="id9">Volatile Memory Accesses</a></li>
18 </ul>
19 </li>
20 <li><a class="reference internal" href="#threading" id="id10">Threading</a></li>
21 <li><a class="reference internal" href="#setjmp-and-longjmp" id="id11"><code>setjmp</code> and <code>longjmp</code></a></li>
22 <li><a class="reference internal" href="#c-exception-handling" id="id12">C++ Exception Handling</a></li>
23 <li><a class="reference internal" href="#inline-assembly" id="id13">Inline Assembly</a></li>
24 <li><p class="first"><a class="reference internal" href="#portable-simd-vectors" id="id14">Portable SIMD Vectors</a></p>
25 <ul class="small-gap">
26 <li><a class="reference internal" href="#hand-coding-vector-extensions" id="id15">Hand-Coding Vector Extensions</a></li>
27 <li><a class="reference internal" href="#auto-vectorization" id="id16">Auto-Vectorization</a></li>
28 </ul>
29 </li>
30 <li><a class="reference internal" href="#undefined-behavior" id="id17">Undefined Behavior</a></li>
31 <li><a class="reference internal" href="#floating-point" id="id18">Floating-Point</a></li>
32 <li><a class="reference internal" href="#computed-goto" id="id19">Computed <code>goto</code></a></li>
33 <li><p class="first"><a class="reference internal" href="#future-directions" id="id20">Future Directions</a></p>
34 <ul class="small-gap">
35 <li><a class="reference internal" href="#inter-process-communication" id="id21">Inter-Process Communication</a></li>
36 <li><a class="reference internal" href="#posix-style-signal-handling" id="id22">POSIX-style Signal Handling</a></li>
37 </ul>
38 </li>
39 </ul>
41 </div><h2 id="source-language-support">Source language support</h2>
42 <p>The currently supported languages are C and C++. The PNaCl toolchain is
43 based on recent Clang, which fully supports C++11 and most of C11. A
44 detailed status of the language support is available <a class="reference external" href="http://clang.llvm.org/cxx_status.html">here</a>.</p>
45 <p>For information on using languages other than C/C++, see the <a class="reference internal" href="/native-client/faq.html#other-languages"><em>FAQ
46 section on other languages</em></a>.</p>
47 <p>As for the standard libraries, the PNaCl toolchain is currently based on
48 <code>libc++</code>, and the <code>newlib</code> standard C library. <code>libstdc++</code> is also
49 supported but its use is discouraged; see <a class="reference internal" href="/native-client/devguide/devcycle/building.html#building-cpp-libraries"><em>C++ standard libraries</em></a>
50 for more details.</p>
51 <h3 id="versions">Versions</h3>
52 <p>Version information can be obtained:</p>
53 <ul class="small-gap">
54 <li>Clang/LLVM: run <code>pnacl-clang -v</code>.</li>
55 <li><code>newlib</code>: use the <code>_NEWLIB_VERSION</code> macro.</li>
56 <li><code>libc++</code>: use the <code>_LIBCPP_VERSION</code> macro.</li>
57 <li><code>libstdc++</code>: use the <code>_GLIBCXX_VERSION</code> macro.</li>
58 </ul>
59 <h3 id="preprocessor-definitions">Preprocessor definitions</h3>
60 <p>When compiling C/C++ code, the PNaCl toolchain defines the <code>__pnacl__</code>
61 macro. In addition, <code>__native_client__</code> is defined for compatibility
62 with other NaCl toolchains.</p>
63 <h2 id="memory-model-and-atomics"><span id="id1"></span>Memory Model and Atomics</h2>
64 <h3 id="memory-model-for-concurrent-operations">Memory Model for Concurrent Operations</h3>
65 <p>The memory model offered by PNaCl relies on the same coding guidelines
66 as the C11/C++11 one: concurrent accesses must always occur through
67 atomic primitives (offered by <a class="reference internal" href="/native-client/reference/pnacl-bitcode-abi.html#bitcode-atomicintrinsics"><em>atomic intrinsics</em></a>), and these accesses must always
68 occur with the same size for the same memory location. Visibility of
69 stores is provided on a happens-before basis that relates memory
70 locations to each other as the C11/C++11 standards do.</p>
71 <p>Non-atomic memory accesses may be reordered, separated, elided or fused
72 according to C and C++&#8217;s memory model before the pexe is created as well
73 as after its creation. Accessing atomic memory location through
74 non-atomic primitives is <a class="reference internal" href="/native-client/reference/pnacl-undefined-behavior.html#undefined-behavior"><em>Undefined Behavior</em></a>.</p>
75 <p>As in C11/C++11 some atomic accesses may be implemented with locks on
76 certain platforms. The <code>ATOMIC_*_LOCK_FREE</code> macros will always be
77 <code>1</code>, signifying that all types are sometimes lock-free. The
78 <code>is_lock_free</code> methods and <code>atomic_is_lock_free</code> will return the
79 current platform&#8217;s implementation at translation time. These macros,
80 methods and functions are in the C11 header <code>&lt;stdatomic.h&gt;</code> and the
81 C++11 header <code>&lt;atomic&gt;</code>.</p>
82 <p>The PNaCl toolchain supports concurrent memory accesses through legacy
83 GCC-style <code>__sync_*</code> builtins, as well as through C11/C++11 atomic
84 primitives and the underlying <a class="reference external" href="http://gcc.gnu.org/wiki/Atomic/GCCMM">GCCMM</a> <code>__atomic_*</code>
85 primitives. <code>volatile</code> memory accesses can also be used, though these
86 are discouraged. See <a class="reference internal" href="#volatile-memory-accesses">Volatile Memory Accesses</a>.</p>
87 <p>PNaCl supports concurrency and parallelism with some restrictions:</p>
88 <ul class="small-gap">
89 <li>Threading is explicitly supported and has no restrictions over what
90 prevalent implementations offer. See <a class="reference internal" href="#threading">Threading</a>.</li>
91 <li><code>volatile</code> and atomic operations are address-free (operations on the
92 same memory location via two different addresses work atomically), as
93 intended by the C11/C++11 standards. This is critical in supporting
94 synchronous &#8220;external modifications&#8221; such as mapping underlying memory
95 at multiple locations.</li>
96 <li>Inter-process communication through shared memory is currently not
97 supported. See <a class="reference internal" href="#future-directions">Future Directions</a>.</li>
98 <li>Signal handling isn&#8217;t supported, PNaCl therefore promotes all
99 primitives to cross-thread (instead of single-thread). This may change
100 at a later date. Note that using atomic operations which aren&#8217;t
101 lock-free may lead to deadlocks when handling asynchronous
102 signals. See <a class="reference internal" href="#future-directions">Future Directions</a>.</li>
103 <li>Direct interaction with device memory isn&#8217;t supported, and there is no
104 intent to support it. The embedding sandbox&#8217;s runtime can offer APIs
105 to indirectly access devices.</li>
106 </ul>
107 <p>Setting up the above mechanisms requires assistance from the embedding
108 sandbox&#8217;s runtime (e.g. NaCl&#8217;s Pepper APIs), but using them once setup
109 can be done through regular C/C++ code.</p>
110 <h3 id="atomic-memory-ordering-constraints">Atomic Memory Ordering Constraints</h3>
111 <p>Atomics follow the same ordering constraints as in regular C11/C++11,
112 but all accesses are promoted to sequential consistency (the strongest
113 memory ordering) at pexe creation time. We plan to support more of the
114 C11/C++11 memory orderings in the future.</p>
115 <p>Some additional restrictions, following the C11/C++11 standards:</p>
116 <ul class="small-gap">
117 <li>Atomic accesses must at least be naturally aligned.</li>
118 <li>Some accesses may not actually be atomic on certain platforms,
119 requiring an implementation that uses global locks.</li>
120 <li>An atomic memory location must always be accessed with atomic
121 primitives, and these primitives must always be of the same bit size
122 for that location.</li>
123 <li>Not all memory orderings are valid for all atomic operations.</li>
124 </ul>
125 <h3 id="volatile-memory-accesses">Volatile Memory Accesses</h3>
126 <p>The C11/C++11 standards mandate that <code>volatile</code> accesses execute in
127 program order (but are not fences, so other memory operations can
128 reorder around them), are not necessarily atomic, and can’t be
129 elided. They can be separated into smaller width accesses.</p>
130 <p>Before any optimizations occur, the PNaCl toolchain transforms
131 <code>volatile</code> loads and stores into sequentially consistent <code>volatile</code>
132 atomic loads and stores, and applies regular compiler optimizations
133 along the above guidelines. This orders <code>volatiles</code> according to the
134 atomic rules, and means that fences (including <code>__sync_synchronize</code>)
135 act in a better-defined manner. Regular memory accesses still do not
136 have ordering guarantees with <code>volatile</code> and atomic accesses, though
137 the internal representation of <code>__sync_synchronize</code> attempts to
138 prevent reordering of memory accesses to objects which may escape.</p>
139 <p>Relaxed ordering could be used instead, but for the first release it is
140 more conservative to apply sequential consistency. Future releases may
141 change what happens at compile-time, but already-released pexes will
142 continue using sequential consistency.</p>
143 <p>The PNaCl toolchain also requires that <code>volatile</code> accesses be at least
144 naturally aligned, and tries to guarantee this alignment.</p>
145 <p>The above guarantees ease the support of legacy (i.e. non-C11/C++11)
146 code, and combined with builtin fences these programs can do meaningful
147 cross-thread communication without changing code. They also better
148 reflect the original code&#8217;s intent and guarantee better portability.</p>
149 <h2 id="threading"><span id="language-support-threading"></span>Threading</h2>
150 <p>Threading is explicitly supported through C11/C++11&#8217;s threading
151 libraries as well as POSIX threads.</p>
152 <p>Communication between threads should use atomic primitives as described
153 in <a class="reference internal" href="#id1">Memory Model and Atomics</a>.</p>
154 <h2 id="setjmp-and-longjmp"><code>setjmp</code> and <code>longjmp</code></h2>
155 <p>PNaCl and NaCl support <code>setjmp</code> and <code>longjmp</code> without any
156 restrictions beyond C&#8217;s.</p>
157 <h2 id="c-exception-handling"><span id="exception-handling"></span>C++ Exception Handling</h2>
158 <p>PNaCl currently supports C++ exception handling through <code>setjmp()</code> and
159 <code>longjmp()</code>, which can be enabled with the <code>--pnacl-exceptions=sjlj</code> linker
160 flag (set with <code>LDFLAGS</code> when using Make). Exceptions are disabled by default
161 so that faster and smaller code is generated, and <code>throw</code> statements are
162 replaced with calls to <code>abort()</code>. The usual <code>-fno-exceptions</code> flag is also
163 supported, though the default is <code>-fexceptions</code>. PNaCl will support full
164 zero-cost exception handling in the future.</p>
165 <aside>
166 When using <a class="reference external" href="https://code.google.com/p/naclports">naclports</a> or other prebuilt static libraries, you don&#8217;t
167 need to recompile because the exception handling support is
168 implemented at link time (when all the static libraries are put
169 together with your application).
170 </aside>
171 <p>NaCl supports full zero-cost C++ exception handling.</p>
172 <h2 id="inline-assembly">Inline Assembly</h2>
173 <p>Inline assembly isn&#8217;t supported by PNaCl because it isn&#8217;t portable. The
174 one current exception is the common compiler barrier idiom
175 <code>asm(&quot;&quot;:::&quot;memory&quot;)</code>, which gets transformed to a sequentially
176 consistent memory barrier (equivalent to <code>__sync_synchronize()</code>). In
177 PNaCl this barrier is only guaranteed to order <code>volatile</code> and atomic
178 memory accesses, though in practice the implementation attempts to also
179 prevent reordering of memory accesses to objects which may escape.</p>
180 <p>PNaCl supports <a class="reference internal" href="#portable-simd-vectors"><em>Portable SIMD Vectors</em></a>,
181 which are traditionally expressed through target-specific intrinsics or
182 inline assembly.</p>
183 <p>NaCl supports a fairly wide subset of inline assembly through GCC&#8217;s
184 inline assembly syntax, with the restriction that the sandboxing model
185 for the target architecture has to be respected.</p>
186 <h2 id="portable-simd-vectors"><span id="id2"></span>Portable SIMD Vectors</h2>
187 <p>SIMD vectors aren&#8217;t part of the C/C++ standards and are traditionally
188 very hardware-specific. Portable Native Client offers a portable version
189 of SIMD vector datatypes and operations which map well to modern
190 architectures and offer performance which matches or approaches
191 hardware-specific uses.</p>
192 <p>SIMD vector support was added to Portable Native Client for version 37 of Chrome
193 and more features, including performance enhancements, have been added in
194 subsequent releases, see the <a class="reference internal" href="/native-client/sdk/release-notes.html#sdk-release-notes"><em>Release Notes</em></a> for more
195 details.</p>
196 <h3 id="hand-coding-vector-extensions">Hand-Coding Vector Extensions</h3>
197 <p>The initial vector support in Portable Native Client adds <a class="reference external" href="http://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors">LLVM vectors</a>
198 and <a class="reference external" href="http://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html">GCC vectors</a> since these
199 are well supported by different hardware platforms and don&#8217;t require any
200 new compiler intrinsics.</p>
201 <p>Vector types can be used through the <code>vector_size</code> attribute:</p>
202 <pre class="prettyprint">
203 #define VECTOR_BYTES 16
204 typedef int v4s __attribute__((vector_size(VECTOR_BYTES)));
205 v4s a = {1,2,3,4};
206 v4s b = {5,6,7,8};
207 v4s c, d, e;
208 c = a + b; /* c = {6,8,10,12} */
209 d = b &gt;&gt; a; /* d = {2,1,0,0} */
210 </pre>
211 <p>Vector comparisons are represented as a bitmask as wide as the compared
212 elements of all <code>0</code> or all <code>1</code>:</p>
213 <pre class="prettyprint">
214 typedef int v4s __attribute__((vector_size(16)));
215 v4s snip(v4s in) {
216 v4s limit = {32,64,128,256};
217 v4s mask = in &gt; limit;
218 v4s ret = in &amp; mask;
219 return ret;
221 </pre>
222 <p>Vector datatypes are currently expected to be 128-bit wide with one of the
223 following element types, and they&#8217;re expected to be aligned to the underlying
224 element&#8217;s bit width (loads and store will otherwise be broken up into scalar
225 accesses to prevent faults):</p>
226 <table border="1" class="docutils">
227 <colgroup>
228 </colgroup>
229 <thead valign="bottom">
230 <tr class="row-odd"><th class="head">Type</th>
231 <th class="head">Num Elements</th>
232 <th class="head">Vector Bit Width</th>
233 <th class="head">Expected Bit Alignment</th>
234 </tr>
235 </thead>
236 <tbody valign="top">
237 <tr class="row-even"><td><code>uint8_t</code></td>
238 <td>16</td>
239 <td>128</td>
240 <td>8</td>
241 </tr>
242 <tr class="row-odd"><td><code>int8_t</code></td>
243 <td>16</td>
244 <td>128</td>
245 <td>8</td>
246 </tr>
247 <tr class="row-even"><td><code>uint16_t</code></td>
248 <td>8</td>
249 <td>128</td>
250 <td>16</td>
251 </tr>
252 <tr class="row-odd"><td><code>int16_t</code></td>
253 <td>8</td>
254 <td>128</td>
255 <td>16</td>
256 </tr>
257 <tr class="row-even"><td><code>uint32_t</code></td>
258 <td>4</td>
259 <td>128</td>
260 <td>32</td>
261 </tr>
262 <tr class="row-odd"><td><code>int32_t</code></td>
263 <td>4</td>
264 <td>128</td>
265 <td>32</td>
266 </tr>
267 <tr class="row-even"><td><code>float</code></td>
268 <td>4</td>
269 <td>128</td>
270 <td>32</td>
271 </tr>
272 </tbody>
273 </table>
274 <p>64-bit integers and double-precision floating point will be supported in
275 a future release, as will 256-bit and 512-bit vectors.</p>
276 <p>Vector element bit width alignment can be stated explicitly (this is assumed by
277 PNaCl, but not necessarily by other compilers), and smaller alignments can also
278 be specified:</p>
279 <pre class="prettyprint">
280 typedef int v4s_element __attribute__((vector_size(16), aligned(4)));
281 typedef int v4s_unaligned __attribute__((vector_size(16), aligned(1)));
282 </pre>
283 <p>The following operators are supported on vectors:</p>
284 <table border="1" class="docutils">
285 <colgroup>
286 </colgroup>
287 <tbody valign="top">
288 <tr class="row-odd"><td>unary <code>+</code>, <code>-</code></td>
289 </tr>
290 <tr class="row-even"><td><code>++</code>, <code>--</code></td>
291 </tr>
292 <tr class="row-odd"><td><code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>%</code></td>
293 </tr>
294 <tr class="row-even"><td><code>&amp;</code>, <code>|</code>, <code>^</code>, <code>~</code></td>
295 </tr>
296 <tr class="row-odd"><td><code>&gt;&gt;</code>, <code>&lt;&lt;</code></td>
297 </tr>
298 <tr class="row-even"><td><code>!</code>, <code>&amp;&amp;</code>, <code>||</code></td>
299 </tr>
300 <tr class="row-odd"><td><code>==</code>, <code>!=</code>, <code>&gt;</code>, <code>&lt;</code>, <code>&gt;=</code>, <code>&lt;=</code></td>
301 </tr>
302 <tr class="row-even"><td><code>=</code></td>
303 </tr>
304 </tbody>
305 </table>
306 <p>C-style casts can be used to convert one vector type to another without
307 modifying the underlying bits. <code>__builtin_convertvector</code> can be used
308 to convert from one type to another provided both types have the same
309 number of elements, truncating when converting from floating-point to
310 integer.</p>
311 <pre class="prettyprint">
312 typedef unsigned v4u __attribute__((vector_size(16)));
313 typedef float v4f __attribute__((vector_size(16)));
314 v4u a = {0x3f19999a,0x40000000,0x40490fdb,0x66ff0c30};
315 v4f b = (v4f) a; /* b = {0.6,2,3.14159,6.02214e+23} */
316 v4u c = __builtin_convertvector(b, v4u); /* c = {0,2,3,0} */
317 </pre>
318 <p>It is also possible to use array-style indexing into vectors to extract
319 individual elements using <code>[]</code>.</p>
320 <pre class="prettyprint">
321 typedef unsigned v4u __attribute__((vector_size(16)));
322 template&lt;typename T&gt;
323 void print(const T v) {
324 for (size_t i = 0; i != sizeof(v) / sizeof(v[0]); ++i)
325 std::cout &lt;&lt; v[i] &lt;&lt; ' ';
326 std::cout &lt;&lt; std::endl;
328 </pre>
329 <p>Vector shuffles (often called permutation or swizzle) operations are
330 supported through <code>__builtin_shufflevector</code>. The builtin has two
331 vector arguments of the same element type, followed by a list of
332 constant integers that specify the element indices of the first two
333 vectors that should be extracted and returned in a new vector. These
334 element indices are numbered sequentially starting with the first
335 vector, continuing into the second vector. Thus, if <code>vec1</code> is a
336 4-element vector, index <code>5</code> would refer to the second element of
337 <code>vec2</code>. An index of <code>-1</code> can be used to indicate that the
338 corresponding element in the returned vector is a don’t care and can be
339 optimized by the backend.</p>
340 <p>The result of <code>__builtin_shufflevector</code> is a vector with the same
341 element type as <code>vec1</code> / <code>vec2</code> but that has an element count equal
342 to the number of indices specified.</p>
343 <pre class="prettyprint">
344 // identity operation - return 4-element vector v1.
345 __builtin_shufflevector(v1, v1, 0, 1, 2, 3)
347 // &quot;Splat&quot; element 0 of v1 into a 4-element result.
348 __builtin_shufflevector(v1, v1, 0, 0, 0, 0)
350 // Reverse 4-element vector v1.
351 __builtin_shufflevector(v1, v1, 3, 2, 1, 0)
353 // Concatenate every other element of 4-element vectors v1 and v2.
354 __builtin_shufflevector(v1, v2, 0, 2, 4, 6)
356 // Concatenate every other element of 8-element vectors v1 and v2.
357 __builtin_shufflevector(v1, v2, 0, 2, 4, 6, 8, 10, 12, 14)
359 // Shuffle v1 with some elements being undefined
360 __builtin_shufflevector(v1, v1, 3, -1, 1, -1)
361 </pre>
362 <p>One common use of <code>__builtin_shufflevector</code> is to perform
363 vector-scalar operations:</p>
364 <pre class="prettyprint">
365 typedef int v4s __attribute__((vector_size(16)));
366 v4s shift_right_by(v4s shift_me, int shift_amount) {
367 v4s tmp = {shift_amount};
368 return shift_me &gt;&gt; __builtin_shuffle_vector(tmp, tmp, 0, 0, 0, 0);
370 </pre>
371 <h3 id="auto-vectorization">Auto-Vectorization</h3>
372 <p>Auto-vectorization is currently not enabled for Portable Native Client,
373 but will be in a future release.</p>
374 <h2 id="undefined-behavior">Undefined Behavior</h2>
375 <p>The C and C++ languages expose some undefined behavior which is
376 discussed in <a class="reference internal" href="/native-client/reference/pnacl-undefined-behavior.html#undefined-behavior"><em>PNaCl Undefined Behavior</em></a>.</p>
377 <h2 id="floating-point"><span id="c-cpp-floating-point"></span>Floating-Point</h2>
378 <p>PNaCl exposes 32-bit and 64-bit floating point operations which are
379 mostly IEEE-754 compliant. There are a few caveats:</p>
380 <ul class="small-gap">
381 <li>Some <a class="reference internal" href="/native-client/reference/pnacl-undefined-behavior.html#undefined-behavior-fp"><em>floating-point behavior is currently left as undefined</em></a>.</li>
382 <li>The default rounding mode is round-to-nearest and other rounding modes
383 are currently not usable, which isn&#8217;t IEEE-754 compliant. PNaCl could
384 support switching modes (the 4 modes exposed by C99 <code>FLT_ROUNDS</code>
385 macros).</li>
386 <li>Signaling <code>NaN</code> never fault.</li>
387 <li><p class="first">Fast-math optimizations are currently supported before <em>pexe</em> creation
388 time. A <em>pexe</em> loses all fast-math information when it is
389 created. Fast-math translation could be enabled at a later date,
390 potentially at a perf-function granularity. This wouldn&#8217;t affect
391 already-existing <em>pexe</em>; it would be an opt-in feature.</p>
392 <ul class="small-gap">
393 <li>Fused-multiply-add have higher precision and often execute faster;
394 PNaCl currently disallows them in the <em>pexe</em> because they aren&#8217;t
395 supported on all platforms and can&#8217;t realistically be
396 emulated. PNaCl could (but currently doesn&#8217;t) only generate them in
397 the backend if fast-math were specified and the hardware supports
398 the operation.</li>
399 <li>Transcendentals aren&#8217;t exposed by PNaCl&#8217;s ABI; they are part of the
400 math library that is included in the <em>pexe</em>. PNaCl could, but
401 currently doesn&#8217;t, use hardware support if fast-math were provided
402 in the <em>pexe</em>.</li>
403 </ul>
404 </li>
405 </ul>
406 <h2 id="computed-goto">Computed <code>goto</code></h2>
407 <p>PNaCl supports computed <code>goto</code>, a non-standard GCC extension to C used
408 by some interpreters, by lowering them to <code>switch</code> statements. The
409 resulting use of <code>switch</code> might not be as fast as the original
410 indirect branches. If you are compiling a program that has a
411 compile-time option for using computed <code>goto</code>, it&#8217;s possible that the
412 program will run faster with the option turned off (e.g., if the program
413 does extra work to take advantage of computed <code>goto</code>).</p>
414 <p>NaCl supports computed <code>goto</code> without any transformation.</p>
415 <h2 id="future-directions">Future Directions</h2>
416 <h3 id="inter-process-communication">Inter-Process Communication</h3>
417 <p>Inter-process communication through shared memory is currently not
418 supported by PNaCl/NaCl. When implemented, it may be limited to
419 operations which are lock-free on the current platform (<code>is_lock_free</code>
420 methods). It will rely on the address-free properly discussed in <a class="reference internal" href="#memory-model-for-concurrent-operations">Memory
421 Model for Concurrent Operations</a>.</p>
422 <h3 id="posix-style-signal-handling">POSIX-style Signal Handling</h3>
423 <p>POSIX-style signal handling really consists of two different features:</p>
424 <ul class="small-gap">
425 <li><p class="first"><strong>Hardware exception handling</strong> (synchronous signals): The ability
426 to catch hardware exceptions (such as memory access faults and
427 division by zero) using a signal handler.</p>
428 <p>PNaCl currently doesn&#8217;t support hardware exception handling.</p>
429 <p>NaCl supports hardware exception handling via the
430 <code>&lt;nacl/nacl_exception.h&gt;</code> interface.</p>
431 </li>
432 <li><p class="first"><strong>Asynchronous interruption of threads</strong> (asynchronous signals): The
433 ability to asynchronously interrupt the execution of a thread,
434 forcing the thread to run a signal handler.</p>
435 <p>A similar feature is <strong>thread suspension</strong>: The ability to
436 asynchronously suspend and resume a thread and inspect or modify its
437 execution state (such as register state).</p>
438 <p>Neither PNaCl nor NaCl currently support asynchronous interruption
439 or suspension of threads.</p>
440 </li>
441 </ul>
442 <p>If PNaCl were to support either of these, the interaction of
443 <code>volatile</code> and atomics with same-thread signal handling would need
444 to be carefully detailed.</p>
445 </section>
447 {{/partials.standard_nacl_article}}