Main Content

Replace multiplications by powers of two with signed bitwise shifts

Replace multiplications by powers of two with signed bitwise shifts

Model Configuration Pane: Code Generation / Code Style

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.

Settings

on (default) | off

Default: on

On

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

Off

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

Examples

expand all

Compare how the generated code implements multiplications by powers of two when you set Replace multiplications by powers of two with signed bitwise shifts to different values.

Here is generated code that generated using the default Replace multiplications by powers of two with signed bitwise shifts value on. Multiplications by 8 are left-shifted in the generated code:

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

Here is the same code generated with Replace multiplications by powers of two with signed bitwise shifts set to off. Multiplications by 8 are not replaced by bitwise shifts:

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

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyOn
Safety precautionNo impact

Programmatic Use

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

Version History

Introduced in R2011b