Compiler directives

Like compiler intrinsics, compiler directives are crucial programming elements.

The restrict qualifier is well-known in many C/C++ implementations, and it is part of the SPU language extension. When the restrict keyword is used to qualify a pointer, it specifies that all accesses to the object pointed to are done through the pointer. For example:
 void *memcpy(void * restrict s1, void * restrict s2, size_t n);

By specifying s1 and s2 as pointers that are restricted, the programmer is specifying that the source and destination objects (for the memory copy) do not overlap.

Another directive is __builtin_expect . Since branch mispredicts are relatively expensive, __builtin_expect provides a way for the programmer to direct branch prediction. This example:
 int __builtin_expect(int exp, int value)

returns the result of evaluating exp , and means that the programmer expects exp to equal value . The value can be a constant for compile-time prediction, or a variable used for run-time prediction.

Two more directives are the aligned attribute, and the _align_hint directive. The aligned attribute is used to ensure proper DMA alignment, for efficient data transfer. The syntax is the same as in many implementations of gcc:
 float factor __attribute__((aligned (16));  //aligns “factor” to a quadword
The _align_hint directive helps compilers "auto-vectorize". Although it looks like an intrinsic, it is more properly described as a compiler directive, since no code is generated as a result of using the directive. The example:
 _align_hint(ptr, base, offset)

informs the compiler that the pointer, ptr , points to data with a base alignment of base , with a byte offset from the base alignment of offset . The base alignment must be a power of two. Giving 0 as the base alignment implies that the pointer has no known alignment. The offset must be less than the base, or, zero. The _align_hint directive should not be used with pointers that are not naturally aligned.