OLD | NEW |
1 ============================ | 1 ============================ |
2 PNaCl C/C++ Language Support | 2 PNaCl C/C++ Language Support |
3 ============================ | 3 ============================ |
4 | 4 |
5 .. contents:: | 5 .. contents:: |
6 :local: | 6 :local: |
7 :backlinks: none | 7 :backlinks: none |
8 :depth: 3 | 8 :depth: 3 |
9 | 9 |
10 Source language support | 10 Source language support |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 ``asm("":::"memory")``, which gets transformed to a sequentially | 191 ``asm("":::"memory")``, which gets transformed to a sequentially |
192 consistent memory barrier (equivalent to ``__sync_synchronize()``). In | 192 consistent memory barrier (equivalent to ``__sync_synchronize()``). In |
193 PNaCl this barrier is only guaranteed to order ``volatile`` and atomic | 193 PNaCl this barrier is only guaranteed to order ``volatile`` and atomic |
194 memory accesses, though in practice the implementation attempts to also | 194 memory accesses, though in practice the implementation attempts to also |
195 prevent reordering of memory accesses to objects which may escape. | 195 prevent reordering of memory accesses to objects which may escape. |
196 | 196 |
197 NaCl supports a fairly wide subset of inline assembly through GCC's | 197 NaCl supports a fairly wide subset of inline assembly through GCC's |
198 inline assembly syntax, with the restriction that the sandboxing model | 198 inline assembly syntax, with the restriction that the sandboxing model |
199 for the target architecture has to be respected. | 199 for the target architecture has to be respected. |
200 | 200 |
| 201 .. _portable_simd_vectors: |
| 202 |
| 203 Portable SIMD Vectors |
| 204 ===================== |
| 205 |
| 206 SIMD vectors aren't part of the C/C++ standards and are traditionally |
| 207 very hardware-specific. Portable Native Client offers a portable version |
| 208 of SIMD vector datatypes and operations which map well to modern |
| 209 architectures and offer performance which matches or approaches |
| 210 hardware-specific uses. |
| 211 |
| 212 SIMD vector support was added to Portable Native Client for version 36 |
| 213 of Chrome, and more features are expected to be added in subsequent |
| 214 releases. |
| 215 |
| 216 Hand-Coding Vector Extensions |
| 217 ----------------------------- |
| 218 |
| 219 The initial vector support in Portable Native Client adds `LLVM vectors |
| 220 <http://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors
>`_ |
| 221 and `GCC vectors |
| 222 <http://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html>`_ since these |
| 223 are well supported by different hardware platforms and don't require any |
| 224 new compiler intrinsics. |
| 225 |
| 226 Vector types can be used through the ``vector_size`` attribute: |
| 227 |
| 228 .. naclcode:: |
| 229 |
| 230 typedef int v4si __attribute__((vector_size(16))); |
| 231 v4si a = {1,2,3,4}; |
| 232 v4si b = {5,6,7,8}; |
| 233 v4si c, d, e; |
| 234 c = b + 1; /* c = b + {1,1,1,1}; */ |
| 235 d = 2 * b; /* d = {2,2,2,2} * b; */ |
| 236 e = c + d; |
| 237 |
| 238 Vector comparisons are represented as a bitmask as wide as the compared |
| 239 elements of all ``0`` or all ``1``: |
| 240 |
| 241 .. naclcode:: |
| 242 |
| 243 typedef int v4si __attribute__((vector_size(16))); |
| 244 v4si snip(v2si in) { |
| 245 v4si limit = {32,64,128,256}; |
| 246 vs4i mask = in > limit; |
| 247 vs4i ret = in & mask; |
| 248 return ret; |
| 249 } |
| 250 |
| 251 Vector datatypes are currently expected to be 128-bit wide with one of |
| 252 the following element types: |
| 253 |
| 254 ============ ============ ================ |
| 255 Type Num Elements Vector Bit Width |
| 256 ============ ============ ================ |
| 257 ``uint8_t`` 16 128 |
| 258 ``int8_t`` 16 128 |
| 259 ``uint16_t`` 8 128 |
| 260 ``int16_t`` 8 128 |
| 261 ``uint32_t`` 4 128 |
| 262 ``int32_t`` 4 128 |
| 263 ``float`` 4 128 |
| 264 ============ ============ ================ |
| 265 |
| 266 64-bit integers and double-precision floating point will be supported in |
| 267 a future release, as will 256-bit and 512-bit vectors. |
| 268 |
| 269 The following operators are supported on vectors: |
| 270 |
| 271 +----------------------------------------------+ |
| 272 | unary ``+``, ``-`` | |
| 273 +----------------------------------------------+ |
| 274 | ``++``, ``--`` | |
| 275 +----------------------------------------------+ |
| 276 | ``+``, ``-``, ``*``, ``/``, ``%`` | |
| 277 +----------------------------------------------+ |
| 278 | ``&``, ``|``, ``^``, ``~`` | |
| 279 +----------------------------------------------+ |
| 280 | ``>>``, ``<<`` | |
| 281 +----------------------------------------------+ |
| 282 | ``!``, ``&&``, ``||`` | |
| 283 +----------------------------------------------+ |
| 284 | ``==``, ``!=``, ``>``, ``<``, ``>=``, ``<=`` | |
| 285 +----------------------------------------------+ |
| 286 | ``=`` | |
| 287 +----------------------------------------------+ |
| 288 |
| 289 Furthermore, C-style casts can be used for: |
| 290 |
| 291 * Truncation. |
| 292 * Zero- and sign-extension. |
| 293 * Conversion to/from floating-point and signed/unsigned integer. |
| 294 |
| 295 It is also possible to use array-style indexing into vectors to extract |
| 296 individual elements using ``[]``. |
| 297 |
| 298 Vector shuffles are currently unsupported but will be added soon. |
| 299 |
| 300 Auto-Vectorization |
| 301 ------------------ |
| 302 |
| 303 Auto-vectorization is currently not enabled for Portable Native Client, |
| 304 but will be in a future release. |
| 305 |
201 Undefined Behavior | 306 Undefined Behavior |
202 ================== | 307 ================== |
203 | 308 |
204 The C and C++ languages expose some undefined behavior which is | 309 The C and C++ languages expose some undefined behavior which is |
205 discussed in :ref:`PNaCl Undefined Behavior <undefined_behavior>`. | 310 discussed in :ref:`PNaCl Undefined Behavior <undefined_behavior>`. |
206 | 311 |
207 Floating-Point | 312 Floating-Point |
208 ============== | 313 ============== |
209 | 314 |
210 PNaCl exposes 32-bit and 64-bit floating point operations which are | 315 PNaCl exposes 32-bit and 64-bit floating point operations which are |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 indirect branches. If you are compiling a program that has a | 348 indirect branches. If you are compiling a program that has a |
244 compile-time option for using computed ``goto``, it's possible that the | 349 compile-time option for using computed ``goto``, it's possible that the |
245 program will run faster with the option turned off (e.g., if the program | 350 program will run faster with the option turned off (e.g., if the program |
246 does extra work to take advantage of computed ``goto``). | 351 does extra work to take advantage of computed ``goto``). |
247 | 352 |
248 NaCl supports computed ``goto`` without any transformation. | 353 NaCl supports computed ``goto`` without any transformation. |
249 | 354 |
250 Future Directions | 355 Future Directions |
251 ================= | 356 ================= |
252 | 357 |
253 SIMD | |
254 ---- | |
255 | |
256 PNaCl currently doesn't support SIMD. We plan to add SIMD support in the | |
257 very near future. | |
258 | |
259 NaCl supports SIMD. | |
260 | |
261 Inter-Process Communication | 358 Inter-Process Communication |
262 --------------------------- | 359 --------------------------- |
263 | 360 |
264 Inter-process communication through shared memory is currently not | 361 Inter-process communication through shared memory is currently not |
265 supported by PNaCl/NaCl. When implemented, it may be limited to | 362 supported by PNaCl/NaCl. When implemented, it may be limited to |
266 operations which are lock-free on the current platform (``is_lock_free`` | 363 operations which are lock-free on the current platform (``is_lock_free`` |
267 methods). It will rely on the address-free properly discussed in `Memory | 364 methods). It will rely on the address-free properly discussed in `Memory |
268 Model for Concurrent Operations`_. | 365 Model for Concurrent Operations`_. |
269 | 366 |
270 POSIX-style Signal Handling | 367 POSIX-style Signal Handling |
(...skipping 17 matching lines...) Expand all Loading... |
288 A similar feature is **thread suspension**: The ability to | 385 A similar feature is **thread suspension**: The ability to |
289 asynchronously suspend and resume a thread and inspect or modify its | 386 asynchronously suspend and resume a thread and inspect or modify its |
290 execution state (such as register state). | 387 execution state (such as register state). |
291 | 388 |
292 Neither PNaCl nor NaCl currently support asynchronous interruption | 389 Neither PNaCl nor NaCl currently support asynchronous interruption |
293 or suspension of threads. | 390 or suspension of threads. |
294 | 391 |
295 If PNaCl were to support either of these, the interaction of | 392 If PNaCl were to support either of these, the interaction of |
296 ``volatile`` and atomics with same-thread signal handling would need | 393 ``volatile`` and atomics with same-thread signal handling would need |
297 to be carefully detailed. | 394 to be carefully detailed. |
OLD | NEW |