Built-In Vector Functions

Table 7-9 lists the built-in functions that can take vector arguments and return a vector result. Unless otherwise specified, the function is applied to each element in the vectors. That is, each element in the resulting vector is the result of applying the function to the corresponding elements in the source vectors. Unless otherwise specified, the vector types of all the arguments and the vector returned must be identical.

Table 7-9 Built-In Functions that Accept Vector Arguments

Function Description Vector Types Supported
__hadd( x, y ) Returns average using (x + y) >> 1. The intermediate sum does not modulo overflow. The vector types of x, y, and the vector returned must be identical. short to short16
uchar to uchar16
__rhadd( x, y ) Returns average with rounding using (x + y + 1) >> 1. The intermediate sum does not modulo overflow. short to short16
uchar to uchar16
__max( x, y ) Returns the greater value of x and y in each element of the returned vector. short to short16
uchar to uchar16
__min( x, y ) Returns the lesser value of x and y in each element of the returned vector. short to short16
uchar to uchar16
__add_sat( x, y ) Returns x + y and saturates the result. That is, if there is an overflow, the maximum value in range for the type is returned. short to short16
ushort to ushort16
uchar to uchar16
int to int16
__sub_sat( x, y ) Returns x - y and saturates the result. That is, if there is an overflow, the maximum value in range for the type is returned. short to short16
int to int16
__abs_diff( x, y ) Returns the absolute difference using | x - y | without overflow. uchar to uchar16
__abs( x ) Returns the absolute value using | x | short to short16
__popcount( x ) Returns the number of non-zero bits in x. uchar to uchar16
__mpy_ext( x, y ) Extended precision multiplication. short to short16
ushort to ushort16
char to char16
uchar to uchar16
__mpy_fx_ext( x, y ) Fixed point multiplication. short to short16
__conj_cmpy( x, y ) Conjugate complex multiplication. cfloat to cfloat8
__cmpy_ext( x, y ) Extended precision complex multiplication. cshort to cshort8
__cmpyr_fx( x, y ) Fixed point complex multiplication with rounding. cshort to cshort8
__cmpy_fx( x, y ) Fixed point complex multiplication. cshort to cshort8
cint to cint8
__conj_cmpy_fx( x, y ) Fixed point conjugate complex multiplication. (C6600 only) cint to cint8
__crot90( x ) Rotate by 90 degrees. (C6600 only) cshort to cshort8
__crot270( x ) Rotate by 270 degrees. (C6600 only) cshort to cshort8
__dot_ext( x, y ) Extended precision dot product using xy. short2 factors give an int result
char4 factors give an int result
uchar4 factors give a uint result
short4 factors give an int result (C6600 only)
short4 and ushort4 factors give an int result (C6600 only)
__dot_extll( x, y ) Extended precision dot product using xy. short2 factors give a longlong result
short4 factors give a longlong result (C6600 only)
short4 and ushort4 factors give a longlong result (C6600 only)
__dot_fx( x, y ) Fixed point dot product using xy. short2 • ushort2 = int
__gmpy( x, y ) Galois field multiplication. uchar4
__ddot_ext( x, y ) Extended precision 2-way dot product. short2 • char4 = int4
short8 • short8 = int2 (C6600 only)
short8 • ushort8 = int2 (C6600 only)
__mpy_fx( x, y ) Fixed point multiplication. short2 * int = int2
int4 * int4 = int4 (C6600 only)
__apply_sign( x, y ) Uses the sign bit of x to determine whether to multiply the four 16-bit values in y by 1 or -1. Yields four signed 16-bit results. This function is an alias for the _dapys2() intrinsic. (C6600 only) short4
__cmpy_conj_ext( x, y ) Extended precision complex multiplication conjugate. (C6600 only) cshort2 * cshort2 = cint2
__cmpy_conj_fx( x, y ) Fixed point complex multiplication conjugate. (C6600 only) cshort2 * cshort2 = cshort2
__cmatmpy_ext( x, y ) Extended precision complex matrix multiplication. (C6600 only) cshort2 * cshort4 = cint2
__conj_cmatmpy_ext( x, y ) Extended precision complex matrix multiplication conjugate. (C6600 only) cshort2 * cshort4 = cint2
__cmatmpy_fx( x, y ) Fixed point complex matrix multiplication. (C6600 only) cshort2 * cshort4 = cshort2
__conj_cmatmpy_fx( x, y ) Fixed point complex matrix multiplication conjugate. (C6600 only) cshort2 * cshort4 = cshort2

Prototypes for all the supported vector built-in functions are listed in the "c6x_vec.h" header file, which is located in the "include" sub-directory of your Code Generation Tools installation. Please see the "c6x_vec.h" for a complete list of the vector built-in functions.

The following example vbif_ex.c file uses the __add_sat() and __sub_sat() built-in functions with vectors:

#include <stdio.h> #include <c6x_vec.h> void print_short4(char *s, short4 v) { printf("%s", s); printf(" <%d, %d, %d, %d>\n", v.x, v.y, v.z, v.w); } int main() { short4 va = (short4) (1, 2, 3, -32766); short4 vb = (short4) (5, 32767, -13, 17); short4 vc = va + vb; short4 vd = va - vb; short4 ve = __add_sat(va, vb); short4 vf = __sub_sat(va, vb); print_short4("va=", va); print_short4("vb=", vb); print_short4("vc=(va+vb)=", vc); print_short4("vd=(va-vb)=", vd); print_short4("ve=__add_sat(va,vb)=", ve); print_short4("vf=__sub_sat(va,vb)=", vf); return 0; }

Compile the example as follows:

%> cl6x -mv6400 --vectypes -o1 -k vbif_ex.c -z -o vbif_ex.out -llnk.cmd

Note that the lnk.cmd file contains a reference to rts6400.lib. The rts6400.libs library contains c6x_veclib.obj, which defines the built-in functions, __add_sat() and __sub_sat().

Running this example produces the following output:

va= <1, 2, 3, -32766> vb= <5, 32767, -13, 17> vc=(va+vb)= <6, -32767, -10, -32749> vd=(va-vb)= <-4, -32765, 16, 32753> ve=__add_sat(va,vb)= <6, 32767, -10, -32749> vf=__sub_sat(va,vb)= <-4, -32765, 16, -32768>