Replace multiplications by powers of two with signed bitwise shifts

Description

Specify whether to replace multiplications by powers of two with signed bitwise shifts. Some coding standards, such as MISRA, do not allow bitwise operations on signed integers. Clearing this option increases the likelihood of generating MISRA C® compliant code.

Category: Code Generation > Code Style

Settings

Default: on

On

Generate code that replaces multiplications by powers of two with signed bitwise shifts.

For example, when you select this option, multiplications by 8 are left-shifted in the generated code:

Y.Out1 = (U.In1 << ((int8_T)3));

Similarly, multiplications by 16 are left-shifted in the generated code:

Y.Out4 = (U.In2 << ((int8_T)4));

Off

Do not allow replacement of multiplications by powers of two with signed shifts. Clearing this option supports MISRA C compliance.

For example, when you clear this option, multiplications by 8 are not replaced by bitwise shifts:

Y.Out1 = U.In1 * ((int64_T)8);

Similarly, multiplications by 16 are not replaced by bitwise shifts:

Y.Out4 = U.In2 * ((int32_T)16);

Command-Line Information

Parameter: EnableSignedLeftShifts
Type: character vector
Value: 'on' | 'off'
Default: 'on'

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyOn
Safety precautionNo impact

Related Topics