@@ -507,6 +507,83 @@ See also :ref:`langext-__builtin_shufflevector`, :ref:`langext-__builtin_convert
507
507
If it's an extension (OpenCL) vector, it's only available in C and OpenCL C.
508
508
And it selects base on signedness of the condition operands (OpenCL v1.1 s6.3.9).
509
509
510
+ Vector Builtins
511
+ ---------------
512
+
513
+ **Note: The implementation of vector builtins is work-in-progress and incomplete. **
514
+
515
+ In addition to the operators mentioned above, Clang provides a set of builtins
516
+ to perform additional operations on certain scalar and vector types.
517
+
518
+ Let ``T `` be one of the following types:
519
+
520
+ * an integer type (as in C2x 6.2.5p19), but excluding enumerated types and _Bool
521
+ * the standard floating types float or double
522
+ * a half-precision floating point type, if one is supported on the target
523
+ * a vector type.
524
+
525
+ For scalar types, consider the operation applied to a vector with a single element.
526
+
527
+ *Elementwise Builtins *
528
+
529
+ Each builtin returns a vector equivalent to applying the specified operation
530
+ elementwise to the input.
531
+
532
+ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±infinity
533
+
534
+ ========================================= ================================================================ =========================================
535
+ Name Operation Supported element types
536
+ ========================================= ================================================================ =========================================
537
+ T __builtin_elementwise_abs(T x) return the absolute value of a number x; the absolute value of signed integer and floating point types
538
+ the most negative integer remains the most negative integer
539
+ T __builtin_elementwise_ceil(T x) return the smallest integral value greater than or equal to x floating point types
540
+ T __builtin_elementwise_floor(T x) return the largest integral value less than or equal to x floating point types
541
+ T __builtin_elementwise_roundeven(T x) round x to the nearest integer value in floating point format, floating point types
542
+ rounding halfway cases to even (that is, to the nearest value
543
+ that is an even integer), regardless of the current rounding
544
+ direction.
545
+ T__builtin_elementwise_trunc(T x) return the integral value nearest to but no larger in floating point types
546
+ magnitude than x
547
+ T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer and floating point types
548
+ T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer and floating point types
549
+ ========================================= ================================================================ =========================================
550
+
551
+
552
+ *Reduction Builtins *
553
+
554
+ Each builtin returns a scalar equivalent to applying the specified
555
+ operation(x, y) as recursive even-odd pairwise reduction to all vector
556
+ elements. ``operation(x, y) `` is repeatedly applied to each non-overlapping
557
+ even-odd element pair with indices ``i * 2 `` and ``i * 2 + 1 `` with
558
+ ``i in [0, Number of elements / 2) ``. If the numbers of elements is not a
559
+ power of 2, the vector is widened with neutral elements for the reduction
560
+ at the end to the next power of 2.
561
+
562
+ Example:
563
+
564
+ .. code-block :: c++
565
+
566
+ __builtin_reduce_add([e3, e2, e1, e0]) = __builtin_reduced_add([e3 + e2, e1 + e0])
567
+ = (e3 + e2) + (e1 + e0)
568
+
569
+
570
+ Let ``VT `` be a vector type and ``ET `` the element type of ``VT ``.
571
+
572
+ ======================================= ================================================================ ==================================
573
+ Name Operation Supported element types
574
+ ======================================= ================================================================ ==================================
575
+ ET __builtin_reduce_max(VT a) return x or y, whichever is larger; If exactly one argument is integer and floating point types
576
+ a NaN, return the other argument. If both arguments are NaNs,
577
+ fmax() return a NaN.
578
+ ET __builtin_reduce_min(VT a) return x or y, whichever is smaller; If exactly one argument integer and floating point types
579
+ is a NaN, return the other argument. If both arguments are
580
+ NaNs, fmax() return a NaN.
581
+ ET __builtin_reduce_add(VT a) \+ integer and floating point types
582
+ ET __builtin_reduce_and(VT a) & integer types
583
+ ET __builtin_reduce_or(VT a) \| integer types
584
+ ET __builtin_reduce_xor(VT a) ^ integer types
585
+ ======================================= ================================================================ ==================================
586
+
510
587
Matrix Types
511
588
============
512
589
0 commit comments