Target Optimized
Note |
|---|
For the Target Optimized strategy, the native int size of the compiler must be 16 bit or 32 bit. |
Type casting can introduce inefficiencies in the generated code:
- calculating with a larger type than necessary (e.g. multiplying two 32 bit values on a 16 bit target, where everything fits in 16 bits)
- unnecessary conversions to a larger type (e.g. extending a 16 bit value to 32 bits on a 16 bit target)
- unnecessary conversions to a smaller type (e.g., casting a 32 bit value to 16 bits on a 32 bit target)
The Target Optimized casting strategy avoids these inefficiencies. To be able to do that, the controller bit size must be specified in the Integer Bit Size option of the compiler declaration file<compiler>.acd.xml. The controller bit size is independent of the integer bit size in the project properties, Integer Arithmetic node. The native integer type is the "int", which may be 16 or 32 bits wide.
The target optimized casting strategy works as follows:
The operands of an expression are casted and the type of the expression is determined according to the C integer conversion. The
union interval (i.e. the union of the result interval and all operand intervals) is determined.If the expression type can represent all values of the union interval, another check is done.
- If there is a smaller type that is at least as big as a native integer on the target and can represent the union interval, the operation type is set to that smaller type.
- If no such smaller type exists, the operation type is set to the expression type determined in step 1.
- If the expression type determined in step 1 cannot represent all values of the union interval, the operation type is set to the smallest type that is at least as big as the native integer and can represent the union interval
- Both operands are casted to the operation type (unless they already have that type or are implicitly casted to that type).
A type is smaller than another type if it needs less memory.
Note |
|---|
The Target Optimized strategy does not allow the use of arithmetic services. |
See also