SPRUJG0 December 2024 F29H850TU
When pointers are passed as function arguments, using the "restrict" keyword on the pointer can result in performance improvements. By applying restrict to the type declaration of a pointer p, the programmer is making the following guarantee to the compiler:
Within the scope of the declaration of p , only p or expressions based on p will be used to access the object pointed to by p.
The compiler can take advantage of this guarantee to generate more efficient code.
Example:
void matrix_vector_product(float32_t *restrict A, float32_t *restrict b, int nr, int nc, float32_t *restrict c)
{
int i, j;
float32_t s;
for(i = nr -1; i >=0; i--)
{
s =c[i];
for(j = nc -1; j >=0; j--)
{
s = s +A[j*nr+i]*b[j];
}
c[i] = s;
}
}