Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: native_client_sdk/src/doc/reference/pnacl-c-cpp-language-support.rst

Issue 255813009: PNaCl SIMD documentation: improve documentation on casts and __builtin_convertvector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Explain truncation. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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, truncating when converting from
292 floating-point to integer.
290 293
291 * Truncation. 294 .. naclcode::
292 * Zero- and sign-extension. 295
293 * Conversion to/from floating-point and signed/unsigned integer. 296 typedef unsigned v4u __attribute__((vector_size(16)));
297 typedef float v4f __attribute__((vector_size(16)));
298 v4u a = {0x3f19999a,0x40000000,0x40490fdb,0x66ff0c30};
299 v4f b = (v4f) a; /* b = {0.6,2,3.14159,6.02214e+23} */
300 v4u c = __builtin_convertvector(b, v4u); /* c = {0,2,3,0} */
294 301
295 It is also possible to use array-style indexing into vectors to extract 302 It is also possible to use array-style indexing into vectors to extract
296 individual elements using ``[]``. 303 individual elements using ``[]``.
297 304
305 .. naclcode::
306
307 typedef unsigned v4u __attribute__((vector_size(16)));
308 template<typename T>
309 void print(const T v) {
310 for (size_t i = 0; i != sizeof(v) / sizeof(v[0]); ++i)
311 std::cout << v[i] << ' ';
312 std::cout << std::endl;
313 }
314
298 Vector shuffles are currently unsupported but will be added soon. 315 Vector shuffles are currently unsupported but will be added soon.
299 316
300 Auto-Vectorization 317 Auto-Vectorization
301 ------------------ 318 ------------------
302 319
303 Auto-vectorization is currently not enabled for Portable Native Client, 320 Auto-vectorization is currently not enabled for Portable Native Client,
304 but will be in a future release. 321 but will be in a future release.
305 322
306 Undefined Behavior 323 Undefined Behavior
307 ================== 324 ==================
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 A similar feature is **thread suspension**: The ability to 402 A similar feature is **thread suspension**: The ability to
386 asynchronously suspend and resume a thread and inspect or modify its 403 asynchronously suspend and resume a thread and inspect or modify its
387 execution state (such as register state). 404 execution state (such as register state).
388 405
389 Neither PNaCl nor NaCl currently support asynchronous interruption 406 Neither PNaCl nor NaCl currently support asynchronous interruption
390 or suspension of threads. 407 or suspension of threads.
391 408
392 If PNaCl were to support either of these, the interaction of 409 If PNaCl were to support either of these, the interaction of
393 ``volatile`` and atomics with same-thread signal handling would need 410 ``volatile`` and atomics with same-thread signal handling would need
394 to be carefully detailed. 411 to be carefully detailed.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698