I implement the following code in Simulink:
y = x * 128
M16C is a 16-bit microprocessor provided by RENESAS and it has some instructions (mnemonics) for shift operation depending on the data size of operand. For example if x and y are UINT16 the operation is coded as:
y = x << 7U;
If x is a UINT8, then it is possible to insert a Data Type Conversion block and the code generated using RTW-EC is :
y = (uint16_T)x << 7U;
RTW-EC deletes the cast operation represented by Data Type Conversion block if the following conditions are satisfied.
1. The cast data type is signed.
2. The cast data size is equal to "int" size in "hardware implementation" configuration.
In that case the generated code is:
y = x << 7U;
The result of right hand side makes precision loss (overflow). To avoid this overflow, x must be cast to 16-bit.
Best Answer