Packed-Data Processing on the ’C64x
8-43
’C64x Programming Considerations
Example 8–16 illustrates an example that can benefit from the packed
compare and expand intrinsics in action. The
Clear Below Threshold kernel
scans an image of 8-bit unsigned pixels, and sets all pixels that are below a
certain threshold to 0.
Example 8–16. Clear Below Threshold Kernel
void clear_below_thresh(unsigned char *restrict image, int count,
unsigned char threshold)
{
int i;
for (i = 0; i < count; i++)
{
if (image[i] <= threshold)
image[i] = 0;
}
}
Vectorization techniques are applied to the code (as described in Section 8.2),
giving the result shown in Example 8–17. The _cmpgtu4() intrinsic compares
against the threshold values, and the _xpnd4() intrinsic generates a mask for
setting pixels to 0. Note that the new code has the restriction that the input
image must be double-word aligned, and must contain a multiple of 8 pixels.
These restrictions are reasonable as common image sizes have a multiple of
8 pixels.