136
edits
(Created page with "Code sinking is an optimization technique used in source-to-source compilers to improve execution efficiency by moving computations to less frequently executed parts of the code. This transformation reduces redundant calculations by relocating expressions outside loops or behind conditional statements, thereby minimizing execution overhead. By strategically repositioning code, code sinking enhances performance without altering program behavior. Code Sinking Transformati...") |
No edit summary |
||
Line 1: | Line 1: | ||
Idiom recognition is an optimization technique used in compilers to identify and replace common programming patterns with more efficient or specialized implementations. This transformation recognizes known mathematical or logical expressions and substitutes them with optimized equivalents, often leveraging platform-specific or hardware-accelerated functions. By standardizing these patterns, idiom recognition improves performance, enhances portability, and enables further optimizations such as vectorization or automatic replacement of low-level operations. This technique is particularly useful in optimizing code for specific hardware architectures while maintaining the original program's behavior. | |||
==Code Sinking Transformation in emmtrix Studio== | |||
emmtrix Studio can implement idiom recognizer using #pragma directives or via the GUI. Idiom Recognizer is a transformation that identifies known math.h functions by the implementation and replaces them with internal EMX functions. The EMX functions are defined in the emx_operators.h header file. | |||
===Typical Usage and Benefits=== | |||
The transformation is used to introduce flexibility with regard to function implementation. This flexibility increases potential for target platform optimizations. The optimizations can be performed when for instance the hardware manufacturer has specially efficient implementations of respective functions. | |||
Common application areas are vectorization and automatic replacement of assembly intrinsics. | |||
===Example=== | |||
{| class="wikitable" | |||
|- | |||
|<syntaxhighlight lang="c"> | |||
/* The following code tests idiom recognizer transformation applied to main function. | |||
*/ | |||
#pragma EMX_TRANSFORMATION IdiomRecognizer | |||
int main(void) { | |||
int i = 3; | |||
i = 2 < i ? 2 : i; | |||
return 0; | |||
} | |||
</syntaxhighlight> | |||
|<syntaxhighlight lang="c"> | |||
/* In the given example (on the left side), i = 2 < i ? 2 : i; is recognized as the math min function and it is replaced | |||
with an internal EMX implementation. | |||
*/ | |||
#include ”emx_operators.h” | |||
int main(void) { | int main(void) { | ||
int | int i = 3; | ||
i = __emx_min(2, i); | |||
return 0; | |||
} | } | ||
</syntaxhighlight> | |||
|} | |||
=== Note=== | |||
*This transformation currently supports limited number of functions and it is hence work in progress. More functions will be supported in the future. | |||
edits