Optimize generated code by storing logical signals as Boolean data. When you select the model configuration parameter Implement logic signals as Boolean data (vs. double), blocks that generate logic signals output Boolean signals.
The optimization:
Reduces the ROM and RAM consumption.
Improves execution speed.
Consider the model rtwdemo_logicalAsBoolean. The outputs of the Relational Operator
, Logical Operator
and HitCrossing
blocks are double
, even though they represent logical data.
model = 'rtwdemo_logicalAsBoolean';
open_system(model);
Create a temporary folder (in your system temporary folder) for the build and inspection process.
currentDir = pwd; [~,cgDir] = rtwdemodir();
Build the model.
rtwbuild(model)
### Starting build procedure for: rtwdemo_logicalAsBoolean ### Successful completion of build procedure for: rtwdemo_logicalAsBoolean Build Summary Top model targets built: Model Action Rebuild Reason ========================================================================================================= rtwdemo_logicalAsBoolean Code generated and compiled Code generation information file does not exist. 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 20.248s
View the generated code without the optimization. These lines of code are in rtwdemo_logicalAsBoolean.h
.
hfile = fullfile(cgDir,'rtwdemo_logicalAsBoolean_ert_rtw',... 'rtwdemo_logicalAsBoolean.h'); rtwdemodbtype(hfile,'/* External outputs','/* Parameters (default storage) */',1,0);
/* External outputs (root outports fed by signals with default storage) */ typedef struct { real_T Out1; /* '<Root>/Out1' */ real_T Out2; /* '<Root>/Out2' */ real_T Out3; /* '<Root>/Out3' */ } ExtY_rtwdemo_logicalAsBoolean_T;
Open the Configuration Parameters dialog box.
Select the Implement logic signals as Boolean data (vs. double) parameter.
Alternatively, you can use the command-line API to enable the optimization:
set_param(model,'BooleanDataType','on');
The generated code stores the logical signal output as Boolean data.
Build the model.
rtwbuild(model)
### Starting build procedure for: rtwdemo_logicalAsBoolean ### Successful completion of build procedure for: rtwdemo_logicalAsBoolean Build Summary Top model targets built: Model Action Rebuild Reason ======================================================================================== rtwdemo_logicalAsBoolean Code generated and compiled Generated code was out of date. 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 8.9345s
View the generated code with the optimization. These lines of code are in rtwdemo_logicalAsBoolean.h
.
rtwdemodbtype(hfile,'/* External outputs','/* Parameters (default storage) */',1,0);
/* External outputs (root outports fed by signals with default storage) */ typedef struct { boolean_T Out1; /* '<Root>/Out1' */ boolean_T Out2; /* '<Root>/Out2' */ boolean_T Out3; /* '<Root>/Out3' */ } ExtY_rtwdemo_logicalAsBoolean_T;
Close the model and code generation report.
bdclose(model) rtwdemoclean; cd(currentDir)
Implement logic signals as Boolean data (vs. double)