Generate Shared Utility Code for Fixed-Point Functions
An important set of generated functions that the model build places in the shared utility folder are the fixed-point support functions. Based on model and block properties, there are many possible versions of fixed-point utilities functions that make it impractical to provide a complete set as static files. Generating only the required fixed-point utility functions during the code generation process is an efficient alternative.
The shared utility checksum mechanism makes sure that several critical properties are identical for models that use the shared utilities. For the fixed-point functions, there are additional properties that determine function behavior. The mechanism codes these properties into the functions and file names to maintain requirements. The additional properties include:
Category | Function/Property |
---|---|
Block properties |
|
Model properties | get_param(bdroot,
'NoFixptDivByZeroProtection') |
The property-based naming convention for the fixed-point utilities is as follows:
operation + [zero protection] + output data type + output bits + [input1 data] + input1 bits + [input2 data type + input2 bits] + [shift direction] + [saturate mode] + [round mode]
The file names shown are examples of generated fixed-point utility files. The function or macro names in the file are identical to the file name without the extension.
FIX2FIX_U12_U16.c FIX2FIX_S9_S9_SR99.c ACCUM_POS_S30_S30.h MUL_S30_S30_S16.h div_nzp_s16s32_floor.c div_s32_sat_floor.c
For these examples, the table shows how the respective fields correspond.
The ACCUM_POS
example uses
the output variable as one of the input variables. So, the file and macro name only contain
the output and second input.
The second div
example has
identical data type and bits for both inputs and the output. So, the file and function name
only include the output.
Operation | FIX2FIX | FIX2FIX | ACCUM_POS | MUL | div | div |
---|---|---|---|---|---|---|
Zero protection | NULL | NULL | NULL | NULL | _nzp | NULL |
Output data type | _U | _S | _S | _S | _s | _s |
Output bits | 12 | 9 | 30 | 30 | 16 | 32 |
Input data type | _U | _S | _S | _S [and _S] | s | NULL |
Input bits | 16 | 9 | 30 | 30 [and 16] | 32 | NULL |
Shift direction | NULL | SR99 | NULL | NULL | NULL | NULL |
Saturate mode | NULL | NULL | NULL | NULL | NULL | _sat |
Round mode | NULL | NULL | NULL | NULL | _floor | _floor |