SPRUIG8J January 2018 – March 2024
Boolean vectors are a vector data type in C/C++ source files. Vector data types are described in Section 5.3.2. Currently, Boolean vectors allow literals and concatenation (Section 5.14.1), the assignment operator (Section 5.14.2), swizzle operators for vectors (Section 5.14.4), conversion functions for vectors (Section 5.14.6), and re-interpretation functions for vectors (Section 5.14.7).
Unlike other integral vector types, Boolean vectors cannot be used as the condition of the vector ternary operator. Standard Boolean operations such as &&, ||, &, &=, |, |=, ^, ^=,!, ~, ==, !=, <=, <, >=, >, <=, <, >=, > are not currently supported for the Boolean vector type.
Boolean vectors may be used as an abstract alternative to the low-level vector predicate type (Section 5.14.8) on most predicated intrinsics on the C7000. The use of Boolean vectors as vector predicates is encouraged. However, the Boolean vector type is not fully interchangeable with the low-level vector predicate type.
When using a vector predicate type, you should perform proper scaling on predicates.
Vector predicates can be scaled up or down by a factor k={0-63} through the
intrinsics __expand_vpred(__vpred, k)
and
__pack_vpred(__vpred, k)
.
The two functions in the following example achieve the same result, one with a Boolean vector and the other with a low-level vector predicate type. This shows differences in the capabilities of vector predicates vs. Boolean vectors. Boolean vectors predicate input data by lane regardless of the element type.
// Boolean vector example
void foo(int4 *ptr, int4 data, char4 *ptr2, char4 data2)
{
bool4 pred = bool4(0,1,1,0);
__vstore_pred(pred, ptr, data); // Word-based store
__vstore_pred(pred, ptr2, data2); // Byte-based store
}
// Vector predicate example
void bar(int4 *ptr, int4 data, char4 *ptr2, char4 data2)
{
__vpred pred = _mvrp(0x0000000000000ff0); // Word-scaled predicate
__vstore_pred(pred, ptr, data);
pred = __pack_vpred(pred, 2); // Byte-scaled predicate
__vstore_pred(pred, ptr2, data2);
}