Control Signed Left Shifts in Generated Code
If you have an Embedded Coder® license, you can control whether MATLAB® Coder™ replaces multiplications by powers of two with signed left bitwise shifts. Some coding standards, such as MISRA™, do not allow bitwise operations on signed integers.
By default, MATLAB Coder replaces multiplication by powers of two with signed left shifts. Here is an example of generated C code that uses a signed left shift for multiplication by eight.
i <<= 3;
To increase the likelihood of generating MISRA C:2012 compliant code, disable the replacement of multiplication by powers of two with signed left shifts. Here is an example of generated C code that does not use a signed left shift for multiplication by eight:
i = i * 8;
Control Signed Left Shifts Using the MATLAB Coder App
On the Generate Code page, to open the Generate dialog box, click the Generate arrow .
Set Build type to one of the following:
Static Library (.lib)
Dynamic Library (.dll)
Click More Settings.
On the Code Appearance tab, select or clear the Use signed shift left for fixed-point operations and multiplication by powers of 2 check box.
Control Signed Left Shifts Using the Command-Line Interface
Create a code configuration object for
'exe'. For example:
cfg = coder.config('lib','ecoder',true); % or dll or exe
false. For example:
cfg.EnableSignedLeftShifts = false;