SPRUIG8J January 2018 – March 2024
Each Streaming Address Generator (SA) has an implicit predicate that is set when storing to memory based on the number of valid vector elements. However, expressing this behavior using C semantics is not possible, because the compiler does not see or track how or when the hardware does the predication, since the predication is based upon the SA configuration and may vary for each invocation of the store.
In order to express this functionality in C, the compiler provides an explicit semantic framework that you can leverage. The framework explicitly predicates a store operation with a predicate value extracted from the corresponding SA. If the compiler detects that the extracted predicate type matches the SA accessor (and corresponding memory operation), the compiler then attempts to collapse this down in order to leverage the SA’s implicit predication capability.
The API to extract the predicate value into a value of type
__vpred
includes the following:
__SA0_VPRED(type)
__SA1_VPRED(type)
__SA2_VPRED(type)
__SA3_VPRED(type)
The following is an example of this use:
__SA0_OPEN(params);
for (I = 0; I < ((ROW * COL) / SIMD); I++)
{
vpred sa0_vp = __SA0_VPRED(int16); // EXTRACT SA0 PREDICATE
int16 *addr = __SA0ADV(int16, (int16 *)data); // EXTRACT SA0 ADDRESS
__vstore_pred(sa0_vp, addr, data); // USE PREDICATED INTRINSIC
}
__SA0_CLOSE();
As indicated in the example, extraction of the vector predicate associated with a particular Streaming Address Generator must be done outside of the call to the store intrinsic. If this were not the case, according to C rules, the order in which parameters of a call are evaluated would be unspecified. Therefore doing this:
__vstore_pred(__SA0_VPRED(int16), __SA0ADV(int16, (int16 *)data);
results in undefined behavior because SA0ADV modifies the value returned by SA0_VPRED().
Regardless of the type used in the predicate extraction API or the SA access, an SA advance will always increment based on its preconfigured state. The given typename does not impact how an SA advance is done.