Restrict Keyword - 2022.2 English

AI Engine Kernel and Graph Programming Guide (UG1079)

Document ID
UG1079
Release Date
2022-10-19
Version
2022.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 allows you to tell the compiler about a potential optimization. Using __restrict with a pointer informs the compiler that the pointer is the only way to access the object pointed at, and the compiler does not need to perform any additional checks.

Note: If a programmer uses the restrict keyword and violates the above condition, undefined behavior can occur.

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