Main Content

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:

CategoryFunction/Property
Block properties
  • Fixed-point operation that the block performs

  • Fixed-point data type and scaling (Slope, Bias) of function inputs and outputs

  • Overflow handling mode (Saturation, Wrap)

  • Rounding Mode (Floor, Ceil, Zero)

Model propertiesget_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.

OperationFIX2FIXFIX2FIXACCUM_POSMULdivdiv
Zero protectionNULLNULLNULLNULL_nzpNULL
Output data type _U_S_S_S_s_s
Output bits 12930301632
Input data type _U_S_S_S [and _S] sNULL
Input bits 1693030 [and 16]32NULL
Shift direction NULL SR99NULLNULLNULLNULL
Saturate mode NULLNULLNULLNULLNULL_sat
Round modeNULLNULLNULLNULL_floor_floor

Related Topics