Restrict Keyword - 2020.2 English

Versal ACAP AI Engine Programming Environment User Guide (UG1076)

Document ID
UG1076
Release Date
2020-11-24
Version
2020.2 English

The restrict keyword is mainly used in pointer declarations as a type qualifier for pointers. It does not add any new functionality. It is only a way for the programmer to inform the compiler about an optimization that compiler can make. When you use restrict with a pointer (ptr), it tells the compiler that ptr is the only way to access the object pointed at, and the compiler does not need to add any additional checks.

If a programmer uses the restrict keyword and violates the above condition, the result is an undefined behavior. The following is another example with pointers that by default have no aliasing.

Figure 1. No Aliasing Example

Apply the restrict keyword for performance improvement. The following example shows no memory dependencies with other pointers.

Figure 2. No Memory Dependencies with Other Pointers