@@ -1113,6 +1113,42 @@ template instantiation, so the value for ``T::number`` is known.
11131113 }];
11141114}
11151115
1116+ def ExtVectorTypeDocs : Documentation {
1117+ let Category = DocCatFunction;
1118+ let Content = [{
1119+ The ext_vector_type(N) attribute specifies that a type is a vector with N
1120+ elements, directly mapping to an LLVM vector type. Originally from OpenCL, it
1121+ allows element access the array subscript operator ``[]``, ``sN`` where ``N`` is
1122+ a hexadecimal value, or ``x``, ``y``, ``z``, ``w`` for graphics-style indexing.
1123+ This attribute enables efficient SIMD operations and is usable in
1124+ general-purpose code.
1125+
1126+ .. code-block:: c++
1127+
1128+ template <typename T, uint32_t N>
1129+ constexpr T simd_reduce(T [[clang::ext_vector_type(N)]] v) {
1130+ static_assert((N & (N - 1)) == 0, "N must be a power of two");
1131+ if constexpr (N == 1) {
1132+ return v[0];
1133+ } else {
1134+ T [[clang::ext_vector_type(N / 2)]] reduced = v.hi + v.lo;
1135+ return simd_reduce(reduced);
1136+ }
1137+ }
1138+
1139+ The vector type also supports swizzling up to sixteen elements. This can be done
1140+ using the object accessors. The OpenCL documentation lists the full list of
1141+ accepted values.
1142+ .. code-block:: c++
1143+
1144+ using f16_x16 = _Float16 __attribute__((ext_vector_type(16)));
1145+
1146+ f16_x16 reverse(f16_x16 v) { return v.sfedcba9876543210; }
1147+
1148+ See the OpenCL documentation for some more complete examples.
1149+ }];
1150+ }
1151+
11161152def DiagnoseIfDocs : Documentation {
11171153 let Category = DocCatFunction;
11181154 let Content = [{
0 commit comments