Effacer les filtres
Effacer les filtres

Managing integer divide by zero checks in MATLAB R2016b codegen output

2 vues (au cours des 30 derniers jours)
JM
JM le 13 Nov 2017
Commenté : Birdman le 26 Nov 2017
When generating C code using codegen in at least MATLAB R2016b that contains integer divisions like:
out = uint32(a)/uint32(b)
an elaborate scheme to check for division by zero is implemented as follows in C:
if (b == 0U) {
if (a == 0U) {
out = 0U;
} else {
out = MAX_uint32_T;
}
} else {
// the actual division regular case
}
I would like to be able to tell codegen that these zero checks are not necessary and only output the commented line but I am not able to find a configuration option for this functionality.
I would like so see an option like SaturateOnIntegerOverflow that is able to turn off adding code for Inf special cases but for zero division.
A different option would be the ability to tell codegen what range of values to expect for various input parameters or values.
Are either of the two options above available?
I am using the regular MATLAB Coder Toolbox from the command line in MATLAB R2016b as follows:
configstruct = coder.config('mex'); % can be exe
configstruct.SomeOption1 = SomeValue1;
configstruct.SomeOption2 = SomeValue2;
codegen(...
'SomeFunction.m',...
'-config',configstruct,...
'args',{...},...
);
The Embedded Coder Toolbox and Simulink are available to me if absolutely required.
  4 commentaires
Birdman
Birdman le 13 Nov 2017
Why do you want to disable that check?
JM
JM le 13 Nov 2017
I would like to reduce ROM size and computation time using the knowlegde that the values to be divided by are always nonzero.

Connectez-vous pour commenter.

Réponses (1)

Birdman
Birdman le 13 Nov 2017
Go to Configuration Parameters->All Parameters and write Remove code that protects against division arithmetic exceptions. Its default value is off(unchecked). Make that on(checked).
  10 commentaires
JM
JM le 24 Nov 2017
To continue this story I could not find a way to use Simulink Coder to generate mex files from an .m file and still support this option. The option in question is only available when generating ERT files. :(
As a side note I could use many more of the code generation options presented in Simulink but not available in the command line code generator. :(
Birdman
Birdman le 26 Nov 2017
Don't you have a way to implement what you are doing right now in Simulink? Because it will be a lot easier for you.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by