SPRUIG8J January 2018 – March 2024
Ternary operators are supported for vector types
by the C7000 compiler, however the code that is generated will not be optimal and
the results will be evaluated lane-by-lane. Consider the following example if
src1
and src2
are vectors:
int16 ex_ternary(int16 src1, int16 src2)
{
return (src1 > src2) ? (src1 - src2) : (src2 - src1);
}
To generate more optimal code, you should instead
use the vector comparison intrinsics listed in the c7x.h
runtime
support header file to construct a vector predicate as well as the vector select
intrinsic __select(vpred, ...)
. Vector predicates are described in
Section 5.14.8.
Or, use conditional operations, such as
__add(vpred, ...)
and __sub_cond(vpred, ...)
,
to implement the same behavior as shown in the following example.
int16 ex_ternary_supported(int16 src1, int16 src2)
{
vpred condition =__cmp_gt_pred(src1, src2);
int16 result1 = src1 - src2; // if-clause
int16 result2 = src2 - src1; // else-clause
return __select(condition, result1, result2); // Lane-dependent select operation
}