From: Chris Lattner
__builtin_overload is used to implement type-generic "overloaded" -functions in C. This builtin is used to implement the <tgmath.h> -header file, but is intended to be usable for a broad variety of other similar -situations, like the <altivec.h> header. -In the future, we intend to eliminate __builtin_overload in favor of function overloading in C, which provides a better solution for type-generic "overloaded" functions. +
__builtin_shufflevector is used to expression generic vector +permutation/shuffle/swizzle operations. This builtin is also very important for +the implementation of various target-specific header files like +<xmmintrin.h>.
Syntax:
-__builtin_overload(FnNameStr, PromotionRuleStr, NumArgs, arg1, arg2, ... - overloadcandidate1, overloadcandidate2, ...) +__builtin_shufflevector(vec1, vec2, index1, index2, ...)
Examples:
-#define sin(x) \ - (__builtin_overload("sin", "tgmath", 1, x, sinf, sin, sinl, - csinf, csin, csinl)(x)) -#define fma(x,y,z) \ - (__builtin_overload("fma", "tgmath", 3, x, y, z, fmaf, fma, fmal)(x,y,z)) -#define ldexp(x, y) \ - (__builtin_overload("ldexp", "tgmath1", 2, x, 0, ldexpf, ldexp, ldexpl)(x,y)) -+ // Identity operation - return 4-element vector V1. + __builtin_shufflevector(V1, V1, 0, 1, 2, 3) -
Description:
+ // "Splat" element 0 of V1 into a 4-element result. + __builtin_shufflevector(V1, V1, 0, 0, 0, 0) -The first argument to __builtin_overload is a string that is the name of the -"function" being implemented. This is used to produce diagnostics that make -sense to the user. For example, if you accidentally pass a pointer argument to -"sin" in GCC, it emits 6 errors about incompatible types. This name allows -Clang to diagnose the error in a way the user can understand. -
+ // Reverse 4-element vector V1. + __builtin_shufflevector(V1, V1, 3, 2, 1, 0) -The second argument is a string that indicates a set of promotion rules to -apply to the arguments before prototype matching occurs. The currently -supported rules are:
- -The third argument is an integer that specifies the arity of the function - being overloaded. After this are N expression arguments which are promoted - according to the rules specified by the promotion rule string.
- -The final arguments are functions or function pointers with different - signatures. __builtin_overload will match and evaluate to the first function - pointer whose signature is compatible and does not cause value truncation of - any arguments to the function.
+ // Concatenate every other element of 4-element vectors V1 and V2. + __builtin_shufflevector(V1, V2, 0, 2, 4, 6) + // Concatenate every other element of 8-element vectors V1 and V2. + __builtin_shufflevector(V1, V2, 0, 2, 4, 6, 8, 10, 12, 14) + - -Description:
-todo describe me.
+The first two arguments to __builtin_shufflevector are vectors that have the +same element type. The remaining arguments are a list of integers that specify +the elements indices of the first two vectors that should be extracted and +returned in a new vector. These element indices are numbered sequentially +starting with the first vector, continuing into the second vector. Thus, if +vec1 is a 4-element vector, index 5 would refer to the second element of vec2. +
+The result of __builtin_shufflevector is a vector +with the same element type as vec1/vec2 but that has an element count equal to +the number of indices specified. +