OLD | NEW |
1 {{+bindTo:partials.standard_nacl_article}} | 1 {{+bindTo:partials.standard_nacl_article}} |
2 | 2 |
3 <section id="pnacl-c-c-language-support"> | 3 <section id="pnacl-c-c-language-support"> |
4 <h1 id="pnacl-c-c-language-support">PNaCl C/C++ Language Support</h1> | 4 <h1 id="pnacl-c-c-language-support">PNaCl C/C++ Language Support</h1> |
5 <div class="contents local" id="contents" style="display: none"> | 5 <div class="contents local" id="contents" style="display: none"> |
6 <ul class="small-gap"> | 6 <ul class="small-gap"> |
7 <li><p class="first"><a class="reference internal" href="#source-language-suppor
t" id="id3">Source language support</a></p> | 7 <li><p class="first"><a class="reference internal" href="#source-language-suppor
t" id="id3">Source language support</a></p> |
8 <ul class="small-gap"> | 8 <ul class="small-gap"> |
9 <li><a class="reference internal" href="#versions" id="id4">Versions</a></li> | 9 <li><a class="reference internal" href="#versions" id="id4">Versions</a></li> |
10 <li><a class="reference internal" href="#preprocessor-definitions" id="id5">Prep
rocessor definitions</a></li> | 10 <li><a class="reference internal" href="#preprocessor-definitions" id="id5">Prep
rocessor definitions</a></li> |
(...skipping 20 matching lines...) Expand all Loading... |
31 <li><a class="reference internal" href="#floating-point" id="id18">Floating-Poin
t</a></li> | 31 <li><a class="reference internal" href="#floating-point" id="id18">Floating-Poin
t</a></li> |
32 <li><a class="reference internal" href="#computed-goto" id="id19">Computed <code
>goto</code></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> | 33 <li><p class="first"><a class="reference internal" href="#future-directions" id=
"id20">Future Directions</a></p> |
34 <ul class="small-gap"> | 34 <ul class="small-gap"> |
35 <li><a class="reference internal" href="#inter-process-communication" id="id21">
Inter-Process Communication</a></li> | 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> | 36 <li><a class="reference internal" href="#posix-style-signal-handling" id="id22">
POSIX-style Signal Handling</a></li> |
37 </ul> | 37 </ul> |
38 </li> | 38 </li> |
39 </ul> | 39 </ul> |
40 | 40 |
41 </div><section id="source-language-support"> | 41 </div><h2 id="source-language-support">Source language support</h2> |
42 <h2 id="source-language-support">Source language support</h2> | |
43 <p>The currently supported languages are C and C++. The PNaCl toolchain is | 42 <p>The currently supported languages are C and C++. The PNaCl toolchain is |
44 based on recent Clang, which fully supports C++11 and most of C11. A | 43 based on recent Clang, which fully supports C++11 and most of C11. A |
45 detailed status of the language support is available <a class="reference externa
l" href="http://clang.llvm.org/cxx_status.html">here</a>.</p> | 44 detailed status of the language support is available <a class="reference externa
l" href="http://clang.llvm.org/cxx_status.html">here</a>.</p> |
46 <p>For information on using languages other than C/C++, see the <a class="refere
nce internal" href="/native-client/faq.html#other-languages"><em>FAQ | 45 <p>For information on using languages other than C/C++, see the <a class="refere
nce internal" href="/native-client/faq.html#other-languages"><em>FAQ |
47 section on other languages</em></a>.</p> | 46 section on other languages</em></a>.</p> |
48 <p>As for the standard libraries, the PNaCl toolchain is currently based on | 47 <p>As for the standard libraries, the PNaCl toolchain is currently based on |
49 <code>libc++</code>, and the <code>newlib</code> standard C library. <code>libst
dc++</code> is also | 48 <code>libc++</code>, and the <code>newlib</code> standard C library. <code>libst
dc++</code> is also |
50 supported but its use is discouraged; see <a class="reference internal" href="/n
ative-client/devguide/devcycle/building.html#building-cpp-libraries"><em>C++ sta
ndard libraries</em></a> | 49 supported but its use is discouraged; see <a class="reference internal" href="/n
ative-client/devguide/devcycle/building.html#building-cpp-libraries"><em>C++ sta
ndard libraries</em></a> |
51 for more details.</p> | 50 for more details.</p> |
52 <section id="versions"> | |
53 <h3 id="versions">Versions</h3> | 51 <h3 id="versions">Versions</h3> |
54 <p>Version information can be obtained:</p> | 52 <p>Version information can be obtained:</p> |
55 <ul class="small-gap"> | 53 <ul class="small-gap"> |
56 <li>Clang/LLVM: run <code>pnacl-clang -v</code>.</li> | 54 <li>Clang/LLVM: run <code>pnacl-clang -v</code>.</li> |
57 <li><code>newlib</code>: use the <code>_NEWLIB_VERSION</code> macro.</li> | 55 <li><code>newlib</code>: use the <code>_NEWLIB_VERSION</code> macro.</li> |
58 <li><code>libc++</code>: use the <code>_LIBCPP_VERSION</code> macro.</li> | 56 <li><code>libc++</code>: use the <code>_LIBCPP_VERSION</code> macro.</li> |
59 <li><code>libstdc++</code>: use the <code>_GLIBCXX_VERSION</code> macro.</li> | 57 <li><code>libstdc++</code>: use the <code>_GLIBCXX_VERSION</code> macro.</li> |
60 </ul> | 58 </ul> |
61 </section><section id="preprocessor-definitions"> | |
62 <h3 id="preprocessor-definitions">Preprocessor definitions</h3> | 59 <h3 id="preprocessor-definitions">Preprocessor definitions</h3> |
63 <p>When compiling C/C++ code, the PNaCl toolchain defines the <code>__pnacl__</c
ode> | 60 <p>When compiling C/C++ code, the PNaCl toolchain defines the <code>__pnacl__</c
ode> |
64 macro. In addition, <code>__native_client__</code> is defined for compatibility | 61 macro. In addition, <code>__native_client__</code> is defined for compatibility |
65 with other NaCl toolchains.</p> | 62 with other NaCl toolchains.</p> |
66 </section></section><section id="memory-model-and-atomics"> | 63 <h2 id="memory-model-and-atomics"><span id="id1"></span>Memory Model and Atomics
</h2> |
67 <span id="id1"></span><h2 id="memory-model-and-atomics"><span id="id1"></span>Me
mory Model and Atomics</h2> | |
68 <section id="memory-model-for-concurrent-operations"> | |
69 <h3 id="memory-model-for-concurrent-operations">Memory Model for Concurrent Oper
ations</h3> | 64 <h3 id="memory-model-for-concurrent-operations">Memory Model for Concurrent Oper
ations</h3> |
70 <p>The memory model offered by PNaCl relies on the same coding guidelines | 65 <p>The memory model offered by PNaCl relies on the same coding guidelines |
71 as the C11/C++11 one: concurrent accesses must always occur through | 66 as the C11/C++11 one: concurrent accesses must always occur through |
72 atomic primitives (offered by <a class="reference external" href="PNaClLangRef.h
tml#atomicintrinsics">atomic intrinsics</a>), and these accesses must always | 67 atomic primitives (offered by <a class="reference external" href="PNaClLangRef.h
tml#atomicintrinsics">atomic intrinsics</a>), and these accesses must always |
73 occur with the same size for the same memory location. Visibility of | 68 occur with the same size for the same memory location. Visibility of |
74 stores is provided on a happens-before basis that relates memory | 69 stores is provided on a happens-before basis that relates memory |
75 locations to each other as the C11/C++11 standards do.</p> | 70 locations to each other as the C11/C++11 standards do.</p> |
76 <p>Non-atomic memory accesses may be reordered, separated, elided or fused | 71 <p>Non-atomic memory accesses may be reordered, separated, elided or fused |
77 according to C and C++’s memory model before the pexe is created as well | 72 according to C and C++’s memory model before the pexe is created as well |
78 as after its creation. Accessing atomic memory location through | 73 as after its creation. Accessing atomic memory location through |
(...skipping 26 matching lines...) Expand all Loading... |
105 at a later date. Note that using atomic operations which aren’t | 100 at a later date. Note that using atomic operations which aren’t |
106 lock-free may lead to deadlocks when handling asynchronous | 101 lock-free may lead to deadlocks when handling asynchronous |
107 signals. See <a class="reference internal" href="#future-directions">Future Dire
ctions</a>.</li> | 102 signals. See <a class="reference internal" href="#future-directions">Future Dire
ctions</a>.</li> |
108 <li>Direct interaction with device memory isn’t supported, and there is no | 103 <li>Direct interaction with device memory isn’t supported, and there is no |
109 intent to support it. The embedding sandbox’s runtime can offer APIs | 104 intent to support it. The embedding sandbox’s runtime can offer APIs |
110 to indirectly access devices.</li> | 105 to indirectly access devices.</li> |
111 </ul> | 106 </ul> |
112 <p>Setting up the above mechanisms requires assistance from the embedding | 107 <p>Setting up the above mechanisms requires assistance from the embedding |
113 sandbox’s runtime (e.g. NaCl’s Pepper APIs), but using them once set
up | 108 sandbox’s runtime (e.g. NaCl’s Pepper APIs), but using them once set
up |
114 can be done through regular C/C++ code.</p> | 109 can be done through regular C/C++ code.</p> |
115 </section><section id="atomic-memory-ordering-constraints"> | |
116 <h3 id="atomic-memory-ordering-constraints">Atomic Memory Ordering Constraints</
h3> | 110 <h3 id="atomic-memory-ordering-constraints">Atomic Memory Ordering Constraints</
h3> |
117 <p>Atomics follow the same ordering constraints as in regular C11/C++11, | 111 <p>Atomics follow the same ordering constraints as in regular C11/C++11, |
118 but all accesses are promoted to sequential consistency (the strongest | 112 but all accesses are promoted to sequential consistency (the strongest |
119 memory ordering) at pexe creation time. We plan to support more of the | 113 memory ordering) at pexe creation time. We plan to support more of the |
120 C11/C++11 memory orderings in the future.</p> | 114 C11/C++11 memory orderings in the future.</p> |
121 <p>Some additional restrictions, following the C11/C++11 standards:</p> | 115 <p>Some additional restrictions, following the C11/C++11 standards:</p> |
122 <ul class="small-gap"> | 116 <ul class="small-gap"> |
123 <li>Atomic accesses must at least be naturally aligned.</li> | 117 <li>Atomic accesses must at least be naturally aligned.</li> |
124 <li>Some accesses may not actually be atomic on certain platforms, | 118 <li>Some accesses may not actually be atomic on certain platforms, |
125 requiring an implementation that uses global locks.</li> | 119 requiring an implementation that uses global locks.</li> |
126 <li>An atomic memory location must always be accessed with atomic | 120 <li>An atomic memory location must always be accessed with atomic |
127 primitives, and these primitives must always be of the same bit size | 121 primitives, and these primitives must always be of the same bit size |
128 for that location.</li> | 122 for that location.</li> |
129 <li>Not all memory orderings are valid for all atomic operations.</li> | 123 <li>Not all memory orderings are valid for all atomic operations.</li> |
130 </ul> | 124 </ul> |
131 </section><section id="volatile-memory-accesses"> | |
132 <h3 id="volatile-memory-accesses">Volatile Memory Accesses</h3> | 125 <h3 id="volatile-memory-accesses">Volatile Memory Accesses</h3> |
133 <p>The C11/C++11 standards mandate that <code>volatile</code> accesses execute i
n | 126 <p>The C11/C++11 standards mandate that <code>volatile</code> accesses execute i
n |
134 program order (but are not fences, so other memory operations can | 127 program order (but are not fences, so other memory operations can |
135 reorder around them), are not necessarily atomic, and can’t be | 128 reorder around them), are not necessarily atomic, and can’t be |
136 elided. They can be separated into smaller width accesses.</p> | 129 elided. They can be separated into smaller width accesses.</p> |
137 <p>Before any optimizations occur, the PNaCl toolchain transforms | 130 <p>Before any optimizations occur, the PNaCl toolchain transforms |
138 <code>volatile</code> loads and stores into sequentially consistent <code>volati
le</code> | 131 <code>volatile</code> loads and stores into sequentially consistent <code>volati
le</code> |
139 atomic loads and stores, and applies regular compiler optimizations | 132 atomic loads and stores, and applies regular compiler optimizations |
140 along the above guidelines. This orders <code>volatiles</code> according to the | 133 along the above guidelines. This orders <code>volatiles</code> according to the |
141 atomic rules, and means that fences (including <code>__sync_synchronize</code>) | 134 atomic rules, and means that fences (including <code>__sync_synchronize</code>) |
142 act in a better-defined manner. Regular memory accesses still do not | 135 act in a better-defined manner. Regular memory accesses still do not |
143 have ordering guarantees with <code>volatile</code> and atomic accesses, though | 136 have ordering guarantees with <code>volatile</code> and atomic accesses, though |
144 the internal representation of <code>__sync_synchronize</code> attempts to | 137 the internal representation of <code>__sync_synchronize</code> attempts to |
145 prevent reordering of memory accesses to objects which may escape.</p> | 138 prevent reordering of memory accesses to objects which may escape.</p> |
146 <p>Relaxed ordering could be used instead, but for the first release it is | 139 <p>Relaxed ordering could be used instead, but for the first release it is |
147 more conservative to apply sequential consistency. Future releases may | 140 more conservative to apply sequential consistency. Future releases may |
148 change what happens at compile-time, but already-released pexes will | 141 change what happens at compile-time, but already-released pexes will |
149 continue using sequential consistency.</p> | 142 continue using sequential consistency.</p> |
150 <p>The PNaCl toolchain also requires that <code>volatile</code> accesses be at l
east | 143 <p>The PNaCl toolchain also requires that <code>volatile</code> accesses be at l
east |
151 naturally aligned, and tries to guarantee this alignment.</p> | 144 naturally aligned, and tries to guarantee this alignment.</p> |
152 <p>The above guarantees ease the support of legacy (i.e. non-C11/C++11) | 145 <p>The above guarantees ease the support of legacy (i.e. non-C11/C++11) |
153 code, and combined with builtin fences these programs can do meaningful | 146 code, and combined with builtin fences these programs can do meaningful |
154 cross-thread communication without changing code. They also better | 147 cross-thread communication without changing code. They also better |
155 reflect the original code’s intent and guarantee better portability.</p> | 148 reflect the original code’s intent and guarantee better portability.</p> |
156 </section></section><section id="threading"> | 149 <h2 id="threading"><span id="language-support-threading"></span>Threading</h2> |
157 <span id="language-support-threading"></span><h2 id="threading"><span id="langua
ge-support-threading"></span>Threading</h2> | |
158 <p>Threading is explicitly supported through C11/C++11’s threading | 150 <p>Threading is explicitly supported through C11/C++11’s threading |
159 libraries as well as POSIX threads.</p> | 151 libraries as well as POSIX threads.</p> |
160 <p>Communication between threads should use atomic primitives as described | 152 <p>Communication between threads should use atomic primitives as described |
161 in <a class="reference internal" href="#id1">Memory Model and Atomics</a>.</p> | 153 in <a class="reference internal" href="#id1">Memory Model and Atomics</a>.</p> |
162 </section><section id="setjmp-and-longjmp"> | |
163 <h2 id="setjmp-and-longjmp"><code>setjmp</code> and <code>longjmp</code></h2> | 154 <h2 id="setjmp-and-longjmp"><code>setjmp</code> and <code>longjmp</code></h2> |
164 <p>PNaCl and NaCl support <code>setjmp</code> and <code>longjmp</code> without a
ny | 155 <p>PNaCl and NaCl support <code>setjmp</code> and <code>longjmp</code> without a
ny |
165 restrictions beyond C’s.</p> | 156 restrictions beyond C’s.</p> |
166 </section><section id="c-exception-handling"> | 157 <h2 id="c-exception-handling"><span id="exception-handling"></span>C++ Exception
Handling</h2> |
167 <span id="exception-handling"></span><h2 id="c-exception-handling"><span id="exc
eption-handling"></span>C++ Exception Handling</h2> | |
168 <p>PNaCl currently supports C++ exception handling through <code>setjmp()</code>
and | 158 <p>PNaCl currently supports C++ exception handling through <code>setjmp()</code>
and |
169 <code>longjmp()</code>, which can be enabled with the <code>--pnacl-exceptions=s
jlj</code> | 159 <code>longjmp()</code>, which can be enabled with the <code>--pnacl-exceptions=s
jlj</code> |
170 linker flag. Exceptions are disabled by default so that faster and | 160 linker flag. Exceptions are disabled by default so that faster and |
171 smaller code is generated, and <code>throw</code> statements are replaced with | 161 smaller code is generated, and <code>throw</code> statements are replaced with |
172 calls to <code>abort()</code>. The usual <code>-fno-exceptions</code> flag is al
so | 162 calls to <code>abort()</code>. The usual <code>-fno-exceptions</code> flag is al
so |
173 supported. PNaCl will support full zero-cost exception handling in the | 163 supported. PNaCl will support full zero-cost exception handling in the |
174 future.</p> | 164 future.</p> |
175 <p>NaCl supports full zero-cost C++ exception handling.</p> | 165 <p>NaCl supports full zero-cost C++ exception handling.</p> |
176 </section><section id="inline-assembly"> | |
177 <h2 id="inline-assembly">Inline Assembly</h2> | 166 <h2 id="inline-assembly">Inline Assembly</h2> |
178 <p>Inline assembly isn’t supported by PNaCl because it isn’t portabl
e. The | 167 <p>Inline assembly isn’t supported by PNaCl because it isn’t portabl
e. The |
179 one current exception is the common compiler barrier idiom | 168 one current exception is the common compiler barrier idiom |
180 <code>asm("":::"memory")</code>, which gets transformed to a
sequentially | 169 <code>asm("":::"memory")</code>, which gets transformed to a
sequentially |
181 consistent memory barrier (equivalent to <code>__sync_synchronize()</code>). In | 170 consistent memory barrier (equivalent to <code>__sync_synchronize()</code>). In |
182 PNaCl this barrier is only guaranteed to order <code>volatile</code> and atomic | 171 PNaCl this barrier is only guaranteed to order <code>volatile</code> and atomic |
183 memory accesses, though in practice the implementation attempts to also | 172 memory accesses, though in practice the implementation attempts to also |
184 prevent reordering of memory accesses to objects which may escape.</p> | 173 prevent reordering of memory accesses to objects which may escape.</p> |
185 <p>PNaCl supports <a class="reference internal" href="#portable-simd-vectors"><e
m>Portable SIMD Vectors</em></a>, | 174 <p>PNaCl supports <a class="reference internal" href="#portable-simd-vectors"><e
m>Portable SIMD Vectors</em></a>, |
186 which are traditionally expressed through target-specific intrinsics or | 175 which are traditionally expressed through target-specific intrinsics or |
187 inline assembly.</p> | 176 inline assembly.</p> |
188 <p>NaCl supports a fairly wide subset of inline assembly through GCC’s | 177 <p>NaCl supports a fairly wide subset of inline assembly through GCC’s |
189 inline assembly syntax, with the restriction that the sandboxing model | 178 inline assembly syntax, with the restriction that the sandboxing model |
190 for the target architecture has to be respected.</p> | 179 for the target architecture has to be respected.</p> |
191 </section><section id="portable-simd-vectors"> | 180 <h2 id="portable-simd-vectors"><span id="id2"></span>Portable SIMD Vectors</h2> |
192 <span id="id2"></span><h2 id="portable-simd-vectors"><span id="id2"></span>Porta
ble SIMD Vectors</h2> | |
193 <p>SIMD vectors aren’t part of the C/C++ standards and are traditionally | 181 <p>SIMD vectors aren’t part of the C/C++ standards and are traditionally |
194 very hardware-specific. Portable Native Client offers a portable version | 182 very hardware-specific. Portable Native Client offers a portable version |
195 of SIMD vector datatypes and operations which map well to modern | 183 of SIMD vector datatypes and operations which map well to modern |
196 architectures and offer performance which matches or approaches | 184 architectures and offer performance which matches or approaches |
197 hardware-specific uses.</p> | 185 hardware-specific uses.</p> |
198 <p>SIMD vector support was added to Portable Native Client for version 37 of Chr
ome | 186 <p>SIMD vector support was added to Portable Native Client for version 37 of Chr
ome |
199 and more features, including performance enhancements, have been added in | 187 and more features, including performance enhancements, have been added in |
200 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 | 188 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 |
201 details.</p> | 189 details.</p> |
202 <section id="hand-coding-vector-extensions"> | |
203 <h3 id="hand-coding-vector-extensions">Hand-Coding Vector Extensions</h3> | 190 <h3 id="hand-coding-vector-extensions">Hand-Coding Vector Extensions</h3> |
204 <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> | 191 <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> |
205 and <a class="reference external" href="http://gcc.gnu.org/onlinedocs/gcc/Vector
-Extensions.html">GCC vectors</a> since these | 192 and <a class="reference external" href="http://gcc.gnu.org/onlinedocs/gcc/Vector
-Extensions.html">GCC vectors</a> since these |
206 are well supported by different hardware platforms and don’t require any | 193 are well supported by different hardware platforms and don’t require any |
207 new compiler intrinsics.</p> | 194 new compiler intrinsics.</p> |
208 <p>Vector types can be used through the <code>vector_size</code> attribute:</p> | 195 <p>Vector types can be used through the <code>vector_size</code> attribute:</p> |
209 <pre class="prettyprint"> | 196 <pre class="prettyprint"> |
210 #define VECTOR_BYTES 16 | 197 #define VECTOR_BYTES 16 |
211 typedef int v4s __attribute__((vector_size(VECTOR_BYTES))); | 198 typedef int v4s __attribute__((vector_size(VECTOR_BYTES))); |
212 v4s a = {1,2,3,4}; | 199 v4s a = {1,2,3,4}; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 </pre> | 355 </pre> |
369 <p>One common use of <code>__builtin_shufflevector</code> is to perform | 356 <p>One common use of <code>__builtin_shufflevector</code> is to perform |
370 vector-scalar operations:</p> | 357 vector-scalar operations:</p> |
371 <pre class="prettyprint"> | 358 <pre class="prettyprint"> |
372 typedef int v4s __attribute__((vector_size(16))); | 359 typedef int v4s __attribute__((vector_size(16))); |
373 v4s shift_right_by(v4s shift_me, int shift_amount) { | 360 v4s shift_right_by(v4s shift_me, int shift_amount) { |
374 v4s tmp = {shift_amount}; | 361 v4s tmp = {shift_amount}; |
375 return shift_me >> __builtin_shuffle_vector(tmp, tmp, 0, 0, 0, 0); | 362 return shift_me >> __builtin_shuffle_vector(tmp, tmp, 0, 0, 0, 0); |
376 } | 363 } |
377 </pre> | 364 </pre> |
378 </section><section id="auto-vectorization"> | |
379 <h3 id="auto-vectorization">Auto-Vectorization</h3> | 365 <h3 id="auto-vectorization">Auto-Vectorization</h3> |
380 <p>Auto-vectorization is currently not enabled for Portable Native Client, | 366 <p>Auto-vectorization is currently not enabled for Portable Native Client, |
381 but will be in a future release.</p> | 367 but will be in a future release.</p> |
382 </section></section><section id="undefined-behavior"> | |
383 <h2 id="undefined-behavior">Undefined Behavior</h2> | 368 <h2 id="undefined-behavior">Undefined Behavior</h2> |
384 <p>The C and C++ languages expose some undefined behavior which is | 369 <p>The C and C++ languages expose some undefined behavior which is |
385 discussed in <a class="reference internal" href="/native-client/reference/pnacl-
undefined-behavior.html#undefined-behavior"><em>PNaCl Undefined Behavior</em></a
>.</p> | 370 discussed in <a class="reference internal" href="/native-client/reference/pnacl-
undefined-behavior.html#undefined-behavior"><em>PNaCl Undefined Behavior</em></a
>.</p> |
386 </section><section id="floating-point"> | |
387 <h2 id="floating-point">Floating-Point</h2> | 371 <h2 id="floating-point">Floating-Point</h2> |
388 <p>PNaCl exposes 32-bit and 64-bit floating point operations which are | 372 <p>PNaCl exposes 32-bit and 64-bit floating point operations which are |
389 mostly IEEE-754 compliant. There are a few caveats:</p> | 373 mostly IEEE-754 compliant. There are a few caveats:</p> |
390 <ul class="small-gap"> | 374 <ul class="small-gap"> |
391 <li>Some <a class="reference internal" href="/native-client/reference/pnacl-unde
fined-behavior.html#undefined-behavior-fp"><em>floating-point behavior is curren
tly left as undefined</em></a>.</li> | 375 <li>Some <a class="reference internal" href="/native-client/reference/pnacl-unde
fined-behavior.html#undefined-behavior-fp"><em>floating-point behavior is curren
tly left as undefined</em></a>.</li> |
392 <li>The default rounding mode is round-to-nearest and other rounding modes | 376 <li>The default rounding mode is round-to-nearest and other rounding modes |
393 are currently not usable, which isn’t IEEE-754 compliant. PNaCl could | 377 are currently not usable, which isn’t IEEE-754 compliant. PNaCl could |
394 support switching modes (the 4 modes exposed by C99 <code>FLT_ROUNDS</code> | 378 support switching modes (the 4 modes exposed by C99 <code>FLT_ROUNDS</code> |
395 macros).</li> | 379 macros).</li> |
396 <li>Signaling <code>NaN</code> never fault.</li> | 380 <li>Signaling <code>NaN</code> never fault.</li> |
397 <li><p class="first">Fast-math optimizations are currently supported before <em>
pexe</em> creation | 381 <li><p class="first">Fast-math optimizations are currently supported before <em>
pexe</em> creation |
398 time. A <em>pexe</em> loses all fast-math information when it is | 382 time. A <em>pexe</em> loses all fast-math information when it is |
399 created. Fast-math translation could be enabled at a later date, | 383 created. Fast-math translation could be enabled at a later date, |
400 potentially at a perf-function granularity. This wouldn’t affect | 384 potentially at a perf-function granularity. This wouldn’t affect |
401 already-existing <em>pexe</em>; it would be an opt-in feature.</p> | 385 already-existing <em>pexe</em>; it would be an opt-in feature.</p> |
402 <ul class="small-gap"> | 386 <ul class="small-gap"> |
403 <li>Fused-multiply-add have higher precision and often execute faster; | 387 <li>Fused-multiply-add have higher precision and often execute faster; |
404 PNaCl currently disallows them in the <em>pexe</em> because they aren’t | 388 PNaCl currently disallows them in the <em>pexe</em> because they aren’t |
405 supported on all platforms and can’t realistically be | 389 supported on all platforms and can’t realistically be |
406 emulated. PNaCl could (but currently doesn’t) only generate them in | 390 emulated. PNaCl could (but currently doesn’t) only generate them in |
407 the backend if fast-math were specified and the hardware supports | 391 the backend if fast-math were specified and the hardware supports |
408 the operation.</li> | 392 the operation.</li> |
409 <li>Transcendentals aren’t exposed by PNaCl’s ABI; they are part of
the | 393 <li>Transcendentals aren’t exposed by PNaCl’s ABI; they are part of
the |
410 math library that is included in the <em>pexe</em>. PNaCl could, but | 394 math library that is included in the <em>pexe</em>. PNaCl could, but |
411 currently doesn’t, use hardware support if fast-math were provided | 395 currently doesn’t, use hardware support if fast-math were provided |
412 in the <em>pexe</em>.</li> | 396 in the <em>pexe</em>.</li> |
413 </ul> | 397 </ul> |
414 </li> | 398 </li> |
415 </ul> | 399 </ul> |
416 </section><section id="computed-goto"> | |
417 <h2 id="computed-goto">Computed <code>goto</code></h2> | 400 <h2 id="computed-goto">Computed <code>goto</code></h2> |
418 <p>PNaCl supports computed <code>goto</code>, a non-standard GCC extension to C
used | 401 <p>PNaCl supports computed <code>goto</code>, a non-standard GCC extension to C
used |
419 by some interpreters, by lowering them to <code>switch</code> statements. The | 402 by some interpreters, by lowering them to <code>switch</code> statements. The |
420 resulting use of <code>switch</code> might not be as fast as the original | 403 resulting use of <code>switch</code> might not be as fast as the original |
421 indirect branches. If you are compiling a program that has a | 404 indirect branches. If you are compiling a program that has a |
422 compile-time option for using computed <code>goto</code>, it’s possible th
at the | 405 compile-time option for using computed <code>goto</code>, it’s possible th
at the |
423 program will run faster with the option turned off (e.g., if the program | 406 program will run faster with the option turned off (e.g., if the program |
424 does extra work to take advantage of computed <code>goto</code>).</p> | 407 does extra work to take advantage of computed <code>goto</code>).</p> |
425 <p>NaCl supports computed <code>goto</code> without any transformation.</p> | 408 <p>NaCl supports computed <code>goto</code> without any transformation.</p> |
426 </section><section id="future-directions"> | |
427 <h2 id="future-directions">Future Directions</h2> | 409 <h2 id="future-directions">Future Directions</h2> |
428 <section id="inter-process-communication"> | |
429 <h3 id="inter-process-communication">Inter-Process Communication</h3> | 410 <h3 id="inter-process-communication">Inter-Process Communication</h3> |
430 <p>Inter-process communication through shared memory is currently not | 411 <p>Inter-process communication through shared memory is currently not |
431 supported by PNaCl/NaCl. When implemented, it may be limited to | 412 supported by PNaCl/NaCl. When implemented, it may be limited to |
432 operations which are lock-free on the current platform (<code>is_lock_free</code
> | 413 operations which are lock-free on the current platform (<code>is_lock_free</code
> |
433 methods). It will rely on the address-free properly discussed in <a class="refer
ence internal" href="#memory-model-for-concurrent-operations">Memory | 414 methods). It will rely on the address-free properly discussed in <a class="refer
ence internal" href="#memory-model-for-concurrent-operations">Memory |
434 Model for Concurrent Operations</a>.</p> | 415 Model for Concurrent Operations</a>.</p> |
435 </section><section id="posix-style-signal-handling"> | |
436 <h3 id="posix-style-signal-handling">POSIX-style Signal Handling</h3> | 416 <h3 id="posix-style-signal-handling">POSIX-style Signal Handling</h3> |
437 <p>POSIX-style signal handling really consists of two different features:</p> | 417 <p>POSIX-style signal handling really consists of two different features:</p> |
438 <ul class="small-gap"> | 418 <ul class="small-gap"> |
439 <li><p class="first"><strong>Hardware exception handling</strong> (synchronous s
ignals): The ability | 419 <li><p class="first"><strong>Hardware exception handling</strong> (synchronous s
ignals): The ability |
440 to catch hardware exceptions (such as memory access faults and | 420 to catch hardware exceptions (such as memory access faults and |
441 division by zero) using a signal handler.</p> | 421 division by zero) using a signal handler.</p> |
442 <p>PNaCl currently doesn’t support hardware exception handling.</p> | 422 <p>PNaCl currently doesn’t support hardware exception handling.</p> |
443 <p>NaCl supports hardware exception handling via the | 423 <p>NaCl supports hardware exception handling via the |
444 <code><nacl/nacl_exception.h></code> interface.</p> | 424 <code><nacl/nacl_exception.h></code> interface.</p> |
445 </li> | 425 </li> |
446 <li><p class="first"><strong>Asynchronous interruption of threads</strong> (asyn
chronous signals): The | 426 <li><p class="first"><strong>Asynchronous interruption of threads</strong> (asyn
chronous signals): The |
447 ability to asynchronously interrupt the execution of a thread, | 427 ability to asynchronously interrupt the execution of a thread, |
448 forcing the thread to run a signal handler.</p> | 428 forcing the thread to run a signal handler.</p> |
449 <p>A similar feature is <strong>thread suspension</strong>: The ability to | 429 <p>A similar feature is <strong>thread suspension</strong>: The ability to |
450 asynchronously suspend and resume a thread and inspect or modify its | 430 asynchronously suspend and resume a thread and inspect or modify its |
451 execution state (such as register state).</p> | 431 execution state (such as register state).</p> |
452 <p>Neither PNaCl nor NaCl currently support asynchronous interruption | 432 <p>Neither PNaCl nor NaCl currently support asynchronous interruption |
453 or suspension of threads.</p> | 433 or suspension of threads.</p> |
454 </li> | 434 </li> |
455 </ul> | 435 </ul> |
456 <p>If PNaCl were to support either of these, the interaction of | 436 <p>If PNaCl were to support either of these, the interaction of |
457 <code>volatile</code> and atomics with same-thread signal handling would need | 437 <code>volatile</code> and atomics with same-thread signal handling would need |
458 to be carefully detailed.</p> | 438 to be carefully detailed.</p> |
459 </section></section></section> | 439 </section> |
460 | 440 |
461 {{/partials.standard_nacl_article}} | 441 {{/partials.standard_nacl_article}} |
OLD | NEW |