Main Content

setTflCOperationEntryParameters

Set specified parameters for operator entry in code replacement table

Description

setTflCOperationEntryParameters(hEntry,varargin) sets specified parameters for an operator entry in a code replacement table.

example

Examples

collapse all

This example shows how to use the setTflCOperationEntryParameters function to set parameters for a code replacement operator entry for uint8 addition that matches a cast-after-sum algorithm.

op_entry = RTW.TflCOperationEntry;
op_entry.setTflCOperationEntryParameters( ...
    'Key',                      'RTW_OP_ADD', ...
    'EntryInfoAlgorithm',       'RTW_CAST_AFTER_OP', ...
    'Priority',                 90, ...
    'SaturationMode',           'RTW_SATURATE_UNSPECIFIED', ...
    'RoundingModes',            {'RTW_ROUND_UNSPECIFIED'}, ...
    'ImplementationName',       'u8_add_u8_u8', ...
    'ImplementationHeaderFile', 'u8_add_u8_u8.h', ...
    'ImplementationSourceFile', 'u8_add_u8_u8.c');

This example shows how to use the setTflCOperationEntryParameters function to set parameters for a code replacement operator entry for fixed-point int16 division. The table entry specifies a net scaling between the operator inputs and output to map a range of slope and bias values to a replacement operation.

op_entry = RTW.TflCOperationEntryGenerator_NetSlope;
op_entry.setTflCOperationEntryParameters( ...
    'Key',                      'RTW_OP_DIV', ...
    'Priority',                 90, ...
    'SaturationMode',           'RTW_WRAP_ON_OVERFLOW', ...
    'RoundingModes',            {'RTW_ROUND_CEILING'}, ...
    'NetSlopeAdjustmentFactor',   1.0, ...
    'NetFixedExponent',           0.0, ...
    'ImplementationName',       's16_div_s16_s16', ...
    'ImplementationHeaderFile', 's16_div_s16_s16.h', ...
    'ImplementationSourceFile', 's16_div_s16_s16.c' );

This example shows how to use the setTflCOperationEntryParameters function to set parameters for a code replacement operator entry for fixed-point uint16 addition that matches a cast-after-sum algorithm. The parameters 'SlopesMustBeTheSame' and 'MustHaveZeroNetBias' must be set to true to specify equal slope and zero net bias across operator inputs and output. This maps relative slope and bias values (rather than a specific slope and bias combination) to a replacement operation.

op_entry = RTW.TflCOperationEntryGenerator;
op_entry.setTflCOperationEntryParameters( ...
    'Key',                     'RTW_OP_ADD', ...
    'EntryInfoAlgorithm',      'RTW_CAST_AFTER_OP', ...
    'Priority',                 90, ...
    'SaturationMode',           'RTW_WRAP_ON_OVERFLOW', ...
    'RoundingModes',            {'RTW_ROUND_UNSPECIFIED'}, ...
    'SlopesMustBeTheSame',      true, ...
    'MustHaveZeroNetBias',      true, ...
    'ImplementationName',       'u16_add_SameSlopeZeroBias', ...
    'ImplementationHeaderFile', 'u16_add_SameSlopeZeroBias.h', ...
    'ImplementationSourceFile', 'u16_add_SameSlopeZeroBias.c');

Input Arguments

collapse all

The hEntry is a handle to a code replacement table entry previously returned by one of the class instantiations in the table.

Class InstantiationSupport

hEntry = RTW.TflCOperationEntry;

Supports operator replacement.

hEntry = RTW.TflCOperationEntryGenerator;

Provides parameters for fixed-point addition and subtraction that are not available in RTW.TflCOperationEntry (SlopesMustBeTheSame and MustHaveZeroNetBias).

hEntry = RTW.TflCOperationEntryGenerator_NetSlope;

Provides net slope parameters for fixed-point multiplication and division that are not available in RTW.TflCOperationEntry (NetSlopeAdjustmentFactor and NetFixedExponent).

hEntry = RTW.TflBlasEntryGenerator;

Supports replacement of nonscalar operators with MathWorks BLAS functions.

hEntry = RTW.TflCBlasEntryGenerator;

Supports replacement of nonscalar operators with ANSI®/ISO® C BLAS functions.

hEntry = MyCustomOperationEntry;

(where MyCustomOperationEntry is a class derived from RTW.TflCOperationEntry)

Supports operator replacement using custom code replacement table entries.

If you want to specify SlopesMustBeTheSame or MustHaveZeroNetBias for your operator entry, instantiate your table entry using hEntry = RTW.TflCOperationEntryGenerator rather than hEntry = RTW.TflCOperationEntry. If you want to use NetSlopeAdjustmentFactor and NetFixedExponent, instantiate your table entry by using hEntry = RTW.TflCOperationEntryGenerator_NetSlope.

Example: op_entry

Example: 'Key','RTW_OP_ADD'

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'Key','RTW_OP_ADD'

The AcceptExprInput value flags the code generator that the implementation function described by this entry accepts expression inputs. The default value is true if ImplType equals FCN_IMPL_FUNCT and false if ImplType equals FCN_IMPL_MACRO.

If the value is true, expression inputs are integrated into the generated code in a form similar to this form:

 rtY.Out1 = myAdd(rtU.In1, rtU.In2 * rtU.In3);

If the value is false, a temporary variable is generated for the expression input:

real_T temp;

temp = rtU.In2 * rtU.In3;
rtY.Out1 = myAdd(rtU.In1, temp);

Example: 'AcceptExprInput',true

The AdditionalHeaderFiles value specifies additional header files for a code replacement table entry. The character vectors or string array can include tokens. For example, in the token $mytoken$, mytoken is a variable defined as a character vector or string scalar in the MATLAB® workspace or as a MATLAB function in the search path that returns a character vector.

Example: 'AdditionalHeaderFiles',{}

The AdditionalIncludePaths value specifies the full path of additional include paths for a code replacement entry. The character vectors or string array can include tokens. For example, in the token $mytoken$, mytoken is a variable defined as a character vector or string scalar in the MATLAB workspace or as a MATLAB function in the search path that returns a character vector.

Example: 'AdditionalIncludePaths',{}

The AdditionalLinkObjs value specifies additional link objects for a code replacement table entry. The character vectors or string array can include tokens. For example, in the token $mytoken$, mytoken is a variable defined as a character vector or string scalar in the MATLAB workspace or as a MATLAB function in the search path that returns a character vector.

Example: 'AdditionalLinkObjs',{}

The AdditionalLinkObjsPaths value specifies the full path of additional link object paths for a code replacement entry. The character vectors or string array can include tokens. For example, in the token $mytoken$, mytoken is a variable defined as a character vector or string scalar in the MATLAB workspace or as a MATLAB function in the search path that returns a character vector.

Example: 'AdditionalLinkObjsPaths',{}

The AdditionalSourceFiles value specifies additional source files for a code replacement table entry. The character vectors or string array can include tokens. For example, in the token $mytoken$, mytoken is a variable defined as a character vector or string scalar in the MATLAB workspace or as a MATLAB function in the search path that returns a character vector.

Example: 'AdditionalSourceFiles',{}

The AdditionalSourcePaths value specifies the full path of additional source paths for a code replacement entry. The character vectors or string array can include tokens. For example, in the token $mytoken$, mytoken is a variable defined as a character vector or string scalar in the MATLAB workspace or as a MATLAB function in the search path that returns a character vector.

Example: 'AdditionalSourcePaths',{}

The AdditionalCompileFlags value specifies additional flags required to compile the source files defined for a code replacement table entry.

Example: 'AdditionalCompileFlags',{}

The AdditionalLinkFlags value specifies additional flags required to link the compiled files for a code replacement table entry.

Example: 'AdditionalLinkFlags',{}

The AllowShapeAgnosticMatch value enables code replacement match based on total number of elements rather than specific matrix shape for matrices that are contiguously allocated in memory. For more information, see Allow Shape Agnostic Match.

Example: 'AllowShapeAgnosticMatch', false

The ArrayLayout value specifies the order of array elements in memory supported by the replacement implementation. By default, the replacement implementation supports column-major data layout. For ROW-MAJOR, the replacement implementation supports row-major data layout. For COLUMN_AND_ROW, the replacement implementation supports column-major and row-major data layouts.

Example: 'ArrayLayout','ROW_MAJOR'

The EntryInfoAlgorithm value specifies the algorithm for the specified math function that must be matched for operator replacement to occur. Code replacement libraries support replacement based on the algorithm for math operations RTW_OP_ADD and RTW_OP_MINUS. Valid arguments for the supported operations are listed in the table. The arguments have the same meaning for both operations.

ArgumentMeaning

RTW_CAST_BEFORE_OP

Before performing the operation, type cast input values to the output data type. If the output type cannot exactly represent the input values, losses can occur as a result of the cast to the output type. Additional loss can occur when the result of the operation is cast to the final output type.

RTW_CAST_AFTER_OP

Compute the ideal result of the operation of inputs. Then, type cast the result to the output data type. Loss occurs during the type cast. This algorithm behaves similarly to the C language except when the signedness of the operands does not match. For example, when you add a signed long operation to an unsigned long operand, standard C language rules convert the signed long operand to an unsigned long operand. The result is a value that is not ideal.

Example: 'EntryInfoAlgorithm','RTW_CAST_AFTER_OP'

The GenCallback specifies a callback that follows code generation. If you specify 'RTW.copyFileToBuildDir', and if this operation entry is matched and used, the code generator calls function RTW.copyFileToBuildDir after code generation. This callback function copies additional header, source, or object files that you have specified for this entry to the build folder.

Example: 'GenCallback','RTW.copyFileToBuildDir'

The ImplementationHeaderFile value specifies the name of the header file that declares the implementation function. The character vector or string scalar can include tokens. For example, in the token $mytoken$, mytoken is a variable defined as a character vector or string scalar in the MATLAB workspace or as a MATLAB function in the search path that returns a character vector.

Example: 'ImplementationHeaderFile','s32_mul.h'

The ImplementationHeaderPath value specifies the full path to the implementation header file. The character vector or string scalar can include tokens. For example, in the token $mytoken$, mytoken is a variable defined as a character vector or string scalar in the MATLAB workspace or as a MATLAB function in the search path that returns a character vector.

Example: 'ImplementationHeaderPath', fullfile('$MATLAB_ROOT', 'crl')

The ImplementationName value specifies the name of the implementation function, which can match or differ from the Key name.

Example: 'ImplementationName','s32_mul_s32_s32_sat'

The ImplementationSourceFile value specifies the name of the implementation source file. The character vector or string scalar can include tokens. For example, in the token $mytoken$, mytoken is a variable defined as a character vector or string scalar in the MATLAB workspace or as a MATLAB function in the search path that returns a character vector.

Example: 'ImplementationSourceFile','s32_mul.c'

The ImplementationSourcePath value specifies the full path to the implementation source file. The character vector or string scalar can include tokens. For example, in the token $mytoken$, mytoken is a variable defined as a character vector or string scalar in the MATLAB workspace or as a MATLAB function in the search path that returns a character vector.

Example: 'ImplementationSourcePath', fullfile('$MATLAB_ROOT', 'crl')

The ImplType value specifies the type of table entry. Use FCN_IMPL_FUNCT for function or FCN_IMPL_MACRO for macro.

Example: 'ImplType','FCN_IMPL_FUNCT'

The Key value specifies the key for the operator to replace. The key must match an operator key listed in Code You Can Replace from MATLAB Code or Code You Can Replace From Simulink Models.

Example: 'Key','RTW_OP_ADD'

The MustHaveZeroNetBias value specifies whether a replacement match requires that the net bias for conceptual arguments of Add/Minus entries is zero. For the Add/Minus of fixed-point operator inputs and output this parameter must be set to true. Instantiate the entry by using hEntry = RTW.TflCOperationEntryGenerator rather than hEntry = RTW.TflCOperationEntry.

For Mul/Div/MulDiv/Shift/Cast entries:

  • The code generator ignores the value of this argument.

  • The bias of the conceptual arguments for Mul/Div/MulDiv/Shift/Cast entries must be zero for a replacement match to occur.

Example: 'MustHaveZeroNetBias',true

The NetSlopeAdjustmentFactor value specifies the fixed exponent (E) part of the net slope (F2E, for example, -3.0) for fixed-point conceptual arguments required for a replacement match to occur for Mul/Div/MulDiv/Shift/Cast entries. Instantiate an entry by using hEntry = RTW.TflCOperationEntryGenerator_NetSlope rather than hEntry = RTW.TflCOperationEntry.

For Add/Minus entries:

  • The code generator ignores the value of this argument.

  • The slope adjustment factor part of the net slope of the conceptual arguments for Add/Minus entries must be zero for a replacement match to occur.

Example: 'NetFixedExponent', -3.0

The NetSlopeAdjustmentFactor value specifies the slope adjustment part of the net slope (F2E, for example, 1.0) for fixed-point conceptual arguments required for a replacement match to occur for Mul/Div/MulDiv/Shift/Cast entries. Instantiate an entry by using hEntry = RTW.TflCOperationEntryGenerator_NetSlope rather than hEntry = RTW.TflCOperationEntry.

For Add/Minus entries:

  • The code generator ignores the value of this argument.

  • The slope adjustment factor part of the net slope of the conceptual arguments for Add/Minus entries must be zero for a replacement match to occur.

Example: 'NetSlopeAdjustmentFactor',1.5

The Priority value specifies the search priority of the operation entry, relative to other entries of the same operation name and conceptual argument list within this table. Highest priority is 0, and lowest priority is 100. If the table provides two implementations for an operation, the implementation with the higher priority shadows the one with the lower priority.

Example: 'Priority',100

The RoundingModes value specifies one or more rounding modes supported by the implementation function.

Example: 'RoundingModes',{'RTW_ROUND_UNSPECIFIED'}

The SaturationMode value specifies the saturation mode supported by the implementation function.

Example: 'SaturationMode','RTW_SATURATE_UNSPECIFIED'

The SideEffects value flags the code generator not to optimize away the implementation function described by this entry. This parameter applies to implementation functions that return void but are not to be optimized away, such as a memcpy implementation or an implementation function that accesses global memory values. For those implementation functions only, you must include this parameter and specify the value true.

Example: 'SideEffects',false

The SlopesMustBeTheSame value specifies whether a replacement match requires that the slope is the same for conceptual arguments of Mul/Div/MulDiv/Shift/Cast entries. Instantiate the entry by using hEntry = RTW.TflCOperationEntryGenerator rather than hEntry = RTW.TflCOperationEntry.

For Add/Minus entries:

  • The code generator ignores the value of this argument.

  • This parameter must be set to true. When set to true, the slopes of the conceptual arguments are equal for a replacement match to occur.

Example: 'SlopesMustBeTheSame',true

The StoreFcnReturnInLocalVar value flags the code generator that the return value of the implementation function described by this entry must be stored in a local variable regardless of other expression folding settings. If the value is false, other expression folding settings determine whether the return value is folded. Storing function returns in a local variable can increase the clarity of generated code. This example shows code generated with expression folding:

void sw_step(void)
{
    if (ssub(sadd(sw_U.In1, sw_U.In2), sw_U.In3) <= 
        smul(ssub(sw_U.In4, sw_U.In5),sw_U.In6)) {  
      sw_Y.Out1 = sw_U.In7;  
    } else {
       sw_Y.Out1 = sw_U.In8;  
    }
}

With StoreFcnReturnInLocalVar set to true, the generated code is potentially easier to understand and debug:

void sw_step(void)
{  
    real32_T rtb_Switch;  
    real32_T hoistedExpr;
    ......  
    rtb_Switch = sadd(sw_U.In1, sw_U.In2);
    rtb_Switch = ssub(rtb_Switch, sw_U.In3);
    hoistedExpr = ssub(sw_U.In4, sw_U.In5); 
    hoistedExpr = smul(hoistedExpr, sw_U.In6);  
    if (rtb_Switch <= hoistedExpr) {
       sw_Y.Out1 = sw_U.In7;  
    } else { 
       sw_Y.Out1 = sw_U.In8;  
    }
}

Example: 'StoreFcnReturnInLocalVar',false

Version History

Introduced in R2007b