| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 <http://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors
>`_ | 220 <http://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors
>`_ |
| 221 and `GCC vectors | 221 and `GCC vectors |
| 222 <http://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html>`_ since these | 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 | 223 are well supported by different hardware platforms and don't require any |
| 224 new compiler intrinsics. | 224 new compiler intrinsics. |
| 225 | 225 |
| 226 Vector types can be used through the ``vector_size`` attribute: | 226 Vector types can be used through the ``vector_size`` attribute: |
| 227 | 227 |
| 228 .. naclcode:: | 228 .. naclcode:: |
| 229 | 229 |
| 230 typedef int v4si __attribute__((vector_size(16))); | 230 typedef int v4s __attribute__((vector_size(16))); |
| 231 v4si a = {1,2,3,4}; | 231 v4s a = {1,2,3,4}; |
| 232 v4si b = {5,6,7,8}; | 232 v4s b = {5,6,7,8}; |
| 233 v4si c, d, e; | 233 v4s c, d, e; |
| 234 c = b + 1; /* c = b + {1,1,1,1}; */ | 234 c = b + 1; /* c = b + {1,1,1,1}; */ |
| 235 d = 2 * b; /* d = {2,2,2,2} * b; */ | 235 d = 2 * b; /* d = {2,2,2,2} * b; */ |
| 236 e = c + d; | 236 e = c + d; |
| 237 | 237 |
| 238 Vector comparisons are represented as a bitmask as wide as the compared | 238 Vector comparisons are represented as a bitmask as wide as the compared |
| 239 elements of all ``0`` or all ``1``: | 239 elements of all ``0`` or all ``1``: |
| 240 | 240 |
| 241 .. naclcode:: | 241 .. naclcode:: |
| 242 | 242 |
| 243 typedef int v4si __attribute__((vector_size(16))); | 243 typedef int v4s __attribute__((vector_size(16))); |
| 244 v4si snip(v2si in) { | 244 v4s snip(v4s in) { |
| 245 v4si limit = {32,64,128,256}; | 245 v4s limit = {32,64,128,256}; |
| 246 vs4i mask = in > limit; | 246 v4s mask = in > limit; |
| 247 vs4i ret = in & mask; | 247 v4s ret = in & mask; |
| 248 return ret; | 248 return ret; |
| 249 } | 249 } |
| 250 | 250 |
| 251 Vector datatypes are currently expected to be 128-bit wide with one of | 251 Vector datatypes are currently expected to be 128-bit wide with one of |
| 252 the following element types: | 252 the following element types: |
| 253 | 253 |
| 254 ============ ============ ================ | 254 ============ ============ ================ |
| 255 Type Num Elements Vector Bit Width | 255 Type Num Elements Vector Bit Width |
| 256 ============ ============ ================ | 256 ============ ============ ================ |
| 257 ``uint8_t`` 16 128 | 257 ``uint8_t`` 16 128 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 279 +----------------------------------------------+ | 279 +----------------------------------------------+ |
| 280 | ``>>``, ``<<`` | | 280 | ``>>``, ``<<`` | |
| 281 +----------------------------------------------+ | 281 +----------------------------------------------+ |
| 282 | ``!``, ``&&``, ``||`` | | 282 | ``!``, ``&&``, ``||`` | |
| 283 +----------------------------------------------+ | 283 +----------------------------------------------+ |
| 284 | ``==``, ``!=``, ``>``, ``<``, ``>=``, ``<=`` | | 284 | ``==``, ``!=``, ``>``, ``<``, ``>=``, ``<=`` | |
| 285 +----------------------------------------------+ | 285 +----------------------------------------------+ |
| 286 | ``=`` | | 286 | ``=`` | |
| 287 +----------------------------------------------+ | 287 +----------------------------------------------+ |
| 288 | 288 |
| 289 Furthermore, C-style casts can be used for: | 289 C-style casts can be used to convert one vector type to another without |
| 290 modifying the underlying bits. ``__builtin_convertvector`` can be used |
| 291 to convert from one type to another. |
| 290 | 292 |
| 291 * Truncation. | 293 .. naclcode:: |
| 292 * Zero- and sign-extension. | 294 |
| 293 * Conversion to/from floating-point and signed/unsigned integer. | 295 typedef unsigned v4u __attribute__((vector_size(16))); |
| 296 typedef float v4f __attribute__((vector_size(16))); |
| 297 v4u a = {0,0x40000000,0x40490fdb,0x66ff0c30}; |
| 298 v4f b = (v4f) a; /* b = {0,2,3.14159,6.02214e+23} */ |
| 299 v4u c = __builtin_convertvector(b, v4u); /* c = {0,2,3,0} */ |
| 294 | 300 |
| 295 It is also possible to use array-style indexing into vectors to extract | 301 It is also possible to use array-style indexing into vectors to extract |
| 296 individual elements using ``[]``. | 302 individual elements using ``[]``. |
| 297 | 303 |
| 304 .. naclcode:: |
| 305 |
| 306 typedef unsigned v4u __attribute__((vector_size(16))); |
| 307 template<typename T> |
| 308 void print(const T v) { |
| 309 for (size_t i = 0; i != sizeof(v) / sizeof(v[0]); ++i) |
| 310 std::cout << v[i] << ' '; |
| 311 std::cout << std::endl; |
| 312 } |
| 313 |
| 298 Vector shuffles are currently unsupported but will be added soon. | 314 Vector shuffles are currently unsupported but will be added soon. |
| 299 | 315 |
| 300 Auto-Vectorization | 316 Auto-Vectorization |
| 301 ------------------ | 317 ------------------ |
| 302 | 318 |
| 303 Auto-vectorization is currently not enabled for Portable Native Client, | 319 Auto-vectorization is currently not enabled for Portable Native Client, |
| 304 but will be in a future release. | 320 but will be in a future release. |
| 305 | 321 |
| 306 Undefined Behavior | 322 Undefined Behavior |
| 307 ================== | 323 ================== |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 A similar feature is **thread suspension**: The ability to | 401 A similar feature is **thread suspension**: The ability to |
| 386 asynchronously suspend and resume a thread and inspect or modify its | 402 asynchronously suspend and resume a thread and inspect or modify its |
| 387 execution state (such as register state). | 403 execution state (such as register state). |
| 388 | 404 |
| 389 Neither PNaCl nor NaCl currently support asynchronous interruption | 405 Neither PNaCl nor NaCl currently support asynchronous interruption |
| 390 or suspension of threads. | 406 or suspension of threads. |
| 391 | 407 |
| 392 If PNaCl were to support either of these, the interaction of | 408 If PNaCl were to support either of these, the interaction of |
| 393 ``volatile`` and atomics with same-thread signal handling would need | 409 ``volatile`` and atomics with same-thread signal handling would need |
| 394 to be carefully detailed. | 410 to be carefully detailed. |
| OLD | NEW |