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

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: Number of elements must match. 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
« no previous file with comments | « native_client_sdk/doc_generated/reference/pnacl-c-cpp-language-support.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 provided both types have the same
292 number of elements, truncating when converting from floating-point to
293 integer.
290 294
291 * Truncation. 295 .. naclcode::
292 * Zero- and sign-extension. 296
293 * Conversion to/from floating-point and signed/unsigned integer. 297 typedef unsigned v4u __attribute__((vector_size(16)));
298 typedef float v4f __attribute__((vector_size(16)));
299 v4u a = {0x3f19999a,0x40000000,0x40490fdb,0x66ff0c30};
300 v4f b = (v4f) a; /* b = {0.6,2,3.14159,6.02214e+23} */
301 v4u c = __builtin_convertvector(b, v4u); /* c = {0,2,3,0} */
294 302
295 It is also possible to use array-style indexing into vectors to extract 303 It is also possible to use array-style indexing into vectors to extract
296 individual elements using ``[]``. 304 individual elements using ``[]``.
297 305
306 .. naclcode::
307
308 typedef unsigned v4u __attribute__((vector_size(16)));
309 template<typename T>
310 void print(const T v) {
311 for (size_t i = 0; i != sizeof(v) / sizeof(v[0]); ++i)
312 std::cout << v[i] << ' ';
313 std::cout << std::endl;
314 }
315
298 Vector shuffles are currently unsupported but will be added soon. 316 Vector shuffles are currently unsupported but will be added soon.
299 317
300 Auto-Vectorization 318 Auto-Vectorization
301 ------------------ 319 ------------------
302 320
303 Auto-vectorization is currently not enabled for Portable Native Client, 321 Auto-vectorization is currently not enabled for Portable Native Client,
304 but will be in a future release. 322 but will be in a future release.
305 323
306 Undefined Behavior 324 Undefined Behavior
307 ================== 325 ==================
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 A similar feature is **thread suspension**: The ability to 403 A similar feature is **thread suspension**: The ability to
386 asynchronously suspend and resume a thread and inspect or modify its 404 asynchronously suspend and resume a thread and inspect or modify its
387 execution state (such as register state). 405 execution state (such as register state).
388 406
389 Neither PNaCl nor NaCl currently support asynchronous interruption 407 Neither PNaCl nor NaCl currently support asynchronous interruption
390 or suspension of threads. 408 or suspension of threads.
391 409
392 If PNaCl were to support either of these, the interaction of 410 If PNaCl were to support either of these, the interaction of
393 ``volatile`` and atomics with same-thread signal handling would need 411 ``volatile`` and atomics with same-thread signal handling would need
394 to be carefully detailed. 412 to be carefully detailed.
OLDNEW
« no previous file with comments | « native_client_sdk/doc_generated/reference/pnacl-c-cpp-language-support.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698