Inline Keywords - 2023.2 English

AI Engine Tools and Flows User Guide (UG1076)

Document ID
UG1076
Release Date
2023-12-04
Version
2023.2 English

The AI Engine compiler provides the inline function to reduce function call overhead. Inline function is a function that is expanded in the line in which it is called. For larger functions, the overhead of the function call is insignificant compared to the amount of time the function takes to run. However, for smaller functions, the time needed to make the function call is greater than the time needed to execute the function’s code. This overhead occurs for small functions because the execution time of a small function is less than the switching time.

The advantages of using inline functions is there is no function call overhead. Another potential advantage is that the compiler is able to perform context-specific optimizations which are not possible when the function stands in its own. The drawbacks are a larger register consumption, an increase of the size of the program, and the function cannot be profiled as there are no clear start and stop program counters to check.

The following keywords indicate the usage of the inlining functions to the compiler:
  • inline: This keyword is an indicator that the AI Engine compiler is free to use a inline substitution or function call for any function marked inline.
  • inline __attribute__((always_inline))or __attribute__((always_inline)): This will force the compiler to inline the function.
  • inline __attribute__((noinline))or __attribute__((noinline)): This will force the compiler to always generate a function call.