SPRUJG0 December   2024 F29H850TU

 

  1.   1
  2.   Abstract
  3.   Trademarks
  4. 1Introduction
  5. 2Performance Optimization
    1. 2.1 Compiler Settings
      1. 2.1.1 Enabling Debug and Source Inter-listing
      2. 2.1.2 Optimization Control
      3. 2.1.3 Floating-Point Math
      4. 2.1.4 Fixed-Point Division
      5. 2.1.5 Single vs Double Precision Floating-Point
    2. 2.2 Memory Settings
      1. 2.2.1 Executing Code From RAM
      2. 2.2.2 Executing Code From Flash
      3. 2.2.3 Data Placement
    3. 2.3 Code Construction and Configuration
      1. 2.3.1 Inlining
      2. 2.3.2 Intrinsics
      3. 2.3.3 Volatile Variables
      4. 2.3.4 Function Arguments
    4. 2.4 Application Code Optimization
      1. 2.4.1 Optimized SDK Libraries
      2. 2.4.2 Optimizing Code-Size With Libraries
      3. 2.4.3 C29 Special Instructions
      4. 2.4.4 C29 Parallelism
      5. 2.4.5 32-Bit Variables and Writes Preferred
  6. 3References

Function Arguments

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; 
    }
}
Note: When passing a structure as a function argument, passing structure pointers instead of structure members results in improved performance.