Main Content

createCRLEntry

Create code replacement table entry from conceptual and implementation argument string specifications

Description

example

tableEntry = createCRLEntry(crTable,conceptualSpecification,implementationSpecification) returns a code replacement table entry. The entry maps a conceptual representation of a function or operator to an implementation representation. The conceptualSpecification argument is a character vector or string scalar that defines the name and conceptual arguments, familiar to the code generator, for the function or operator to replace. The implementationSpecification argument is a character vector or string scalar that defines the name and C/C++ implementation arguments for the replacement function.

This function does not support:

  • C++ implementations

  • Data alignment

  • Operator replacement with net slope arguments

  • Entry parameter specifications (for example, priority, algorithm, building information)

  • Semaphore and mutex function replacements

In the syntax specifications, place a space before and after an operator symbol. For example, use double u1 + double u2 instead of double u1+double u2. Also, asterisk (*), tilde (~), and semicolon (;) have the following meaning.

SymbolMeaning
*
  • Following a supported data type, such as int32*, pass by reference (pointer). If the conceptual arguments are not scalar, in the implementation specification, pass them by reference.

  • As part of a fixed-point data type definition, such as fixdt(1,32,*), wildcard.

~Based on the position of the symbol, slopes or bias must be the same across data types.
;Separates dimension ranges. For example, [1 10; 1 100] specifies a vector with length from 10 through 100.

The following table shows syntax for the conceptual and implementation specifications based on:

  • Whether you are creating an entry for a function or operator.

  • The type or characterization of the code replacement.

Type of ReplacementConceptual SyntaxImplementation Syntax
Function Code Replacement Syntax
Typical double y1 = sin(double u1)double y1 = mySin(double u1)
Derive implementation argument data types from conceptual specificationdouble y1 = sin(double u1)y1 = mySin(u1)
Derive implementation arguments and data types from conceptual specificationdouble y1 = sin(double u1)mySin
Change data typesingle y1 = sin(single u1)double y1 = mySin(double u1)
Reorder argumentsdouble y1 = atan2(double u1, double u2)y1 = myAtan(u2, u1)
Specify column vector argumentsdouble y1 = sin(double u1[10])double y1 = mySin(double* u1)
Specify column vector arguments and dimension rangedouble y1[1 100; 1 100] = sin(double u1[1 100; 1 100])mySin(double* u1, double* y1)
Remap return value as output argumentdouble y1 = sin(double u1)mySin(double u1, double* y1)
Specify fixed-point data typesfixdt(1,16,3) y1 = sin(fixdt(1,16,3) u1)int16 y1 = mySin(int16 u1)
Specify fixed-point data types and set CheckSlope to false, CheckBias to true, and Bias to 0fixdt(1,16,*) y1 = sin(fixdt(1,16,*) u1)int16 y1 = mySin(int16 u1)
Specify fixed-point data types and set SlopesMustBeTheSame to true, CheckSlope to false, CheckBias to true, and Bias to 0fixdt(1,16,~) y1 = sin(fixdt(1,16,~) u1)int16 y1 = mySin(int16 u1)
Specify fixed-point data types and set SlopesMustBeTheSame to true, BiasMustBeTheSame to true, CheckSlope to false, and CheckBias to falsefixdt(1,16,~,~) y1 = sin(fixdt(1,16,~,~) u1)int16 y1 = mySin(int16 u1)
Specify multiple output arguments[double y1 double y2] = foo(double u1, double u2)double y1 = myFoo(double u1, double u2, double* y2)
Operator Code Replacement Syntax
Typical int16 y1 = int16 u1 + int16 u2int16 y1 = myAdd(int16 u1, int16 u2)
Specify fixed-point data typesfixdt(1,16,3) y1 = fixdt(1,16,3) u1 + fixdt(1,16,3) u2int16 y1 = myAdd(int16 u1, int16 u2)
Specify fixed-point data types and set CheckSlope to false, CheckBias to true, and Bias to 0fixdt(1,16,*) y1 = fixdt(1,16,*) u1 + fixdt(1,16,*) u2int16 y1 = myAdd(int16 u1, int16 u2)
Specify fixed-point data types, wildcard, slopes must be the same, and zero biasfixdt(1,16,~,0) y1 = fixdt(1,16,~,0) u1 + fixdt(1,16,~,0) u2int16 y1 = myAdd(int16 u1, int16 u2)
Typecastint16 y1 = int8 u1int16 y1 = myCast(int8 u1)
Shiftint16 y1 = int16 u1 << int16 u2
int16 y1 = int16 u1 >> int16 u2
int16 y1 = int16 u1 .>> int16 u2
int16 y1 = myShiftLeft(int16 u1, int16 u2)
int16 y1 = myShiftRightArithmetic(int16 u1, int16 u2)
int16 y1 = myShiftRightLogical(int16 u1, int16 u2)
Specify relational operatorbool y1 = int16 u1 < int16 u2bool y1 = myLessThan(int6 u1, int16 u2)
Specify multiplication and divisionint32 y1 = int32 u1 * in32 u2 / in32 u3int32 y1 = myMultDiv(int32 u1, int32 u2, int32 u3)
Specify matrix multiplicationdouble y1[10][10] = double u1[10][10] * double u2[10][10]myMult(double* u1, double* u2, double* y1)
Specify element-wise matrix multiplicationdouble y1[10][10] = double u1[10][10] .* double u2[10][10]myMult(double* u1, double* u2, double* y1)
Specify matrix multiplication with transpose of an input argumentdouble y1[10][10] = double u1[10][10]' * double u2[10][10]myMult(double* u1, double* u2, double* y1)
Specify matrix multiplication with Hermitian of an input argumentcdouble y1[10][10] = cdouble u1[10][10]' * cdouble u2[10][10]
cdouble y1[10][10] = cdouble u1[10][10] * cdouble u2[10][10]'
myMult(cdouble* u1, cdouble* u2, cdouble* y1)
Specify left matrix divisiondouble y1[10][10] = double u1[10][10] \ double u2[10][10]myLeftDiv(double* u1, double* u2, double* y1)
Specify right matrix divisiondouble y1[10][10] = double u1[10][10] / double u2[10][10]myRightDiv(double* u1, double* u2, double* y1)

Examples

collapse all

Create a table definition file that contains a function definition.

function crTable = crl_table_sinfcn()

Within the function body, create the code replacement table.

crTable = RTW.TflTable;

Create a table entry for the sin function.

tableEntry = createCRLEntry(crTable, ...
    'double y1 = sin(double u1)', ...
    'double y1 = mySin(double u1)');

Set entry parameters for the sin function. To generate the replacement code, specify that the code generator use the header and source files mySin.h and mySin.c.

setTflCFunctionEntryParameters(tableEntry, ...
    'ImplementationHeaderFile', 'mySin.h', ...
    'ImplementationSourceFile', 'mySin.c');

Add the entry to the table.

addEntry(crTable, tableEntry);

Create a table definition file that contains a function definition.

function crTable = crl_table_addfcn()

Within the function body, create the code replacement table.

crTable = RTW.TflTable;

Create a table entry for the addition operator.

tableEntry = createCRLEntry(crTable, ...
    'int16 y1 = int16 u1 + int16 u2', ...
    'int16 y1 = myAdd(int16 u1, int16 u2)');

Set entry parameters such that the entry specifies a cast-after-sum addition. To generate the replacement code, specify that the code generator use the header and source files myAdd.h and myAdd.c.

setTflCOperationEntryParameters(tableEntry, ...
    'EntryInfoAlgorithm', 'RTW_CAST_AFTER_OP', ...
    'ImplementationHeaderFile', 'myAdd.h', ...
    'ImplementationSourceFile', 'myAdd.c')); 

Add the entry to the table.

addEntry(crTable, tableEntry);

Create a table definition file that contains a function definition.

function crTable = crl_table_intaddfcn()

Within the function body, create the code replacement table.

crTable = RTW.TflTable;

Create a table entry for a signed fixed-point addition operation requiring the same slope across types.

tableEntry = createCRLEntry(crTable, ...
    'fixdt(1,16,~,0) y1 = fixdt(1,16,~,0) u1 + fixdt(1,16,~,0) u2', ...
    'int16 y1 = myAdd(int16 u1, int16 u2)');

Set entry parameters. Set algorithm parameters for a cast-after-sum addition and saturation and rounding modes. To generate the replacement code, specify that the code generator use the header and source files myIntAdd.h and myIntAdd.c.

setTflCOperationtionEntryParameters(tableEntry, ...
    'EntryInfoAlgorithm', 'RTW_CAST_AFTER_OP', ...
    'SaturationMode', 'RTW_SATURATE_ON_OVERFLOW', ...
    'RoundingMode', 'RTW_ROUND_SIMPLEST', ...
    'ImplementationHeaderFile', 'myIntAdd.h', ...
    'ImplementationSourceFile', 'myIntAdd.c');

Add the entry to the table.

addEntry(crTable, tableEntry);

Create a table definition file that contains a function definition.

function crTable = crl_table_sinfcn()

Within the function body, create the code replacement table.

crTable = RTW.TflTable;

Create a table entry for a sin function, where the implementation arguments are the same as the conceptual arguments.

tableEntry = createCRLEntry(crTable, ...
    'double y1 = sin(double u1)', ...
    'y1 = mySin(u1)');

Set entry parameters. To generate the replacement code, specify that the code generator use the header and source files mySin.h and mySin.c.

setTflCFunctionEntryParameters(tableEntry, ...
    'ImplementationHeaderFile', 'mySin.h', ...
    'ImplementationSourceFile', 'mySin.c'); 

Add the entry to the table.

addEntry(crTable, tableEntry);

Input Arguments

collapse all

Table that stores one or more code replacement entries, each representing a potential replacement for a function or operator. Each entry maps a conceptual representation of a function or operator to an implementation representation and priority.

Representation of the name or symbol and conceptual input and output arguments for a function or operator that the software replaces, specified as a character vector or string scalar. Conceptual arguments observe naming conventions ('y1', 'u1', 'u2', ...) and data types familiar to the code generator. Use the syntax table in Description to determine the syntax to use for your conceptual argument specification.

Example: 'double y1 = sin(double u1)'

Example: 'int16 y1 = int16 u1 + int16 u2'

Representation of the name and implementation input and output arguments for a C or C++ replacement function, specified as a character vector or string scalar. Implementation arguments observe C/C++ name and data type specifications. Use the syntax table in Description to determine the syntax for your implementation argument specification.

Example: 'double y1 = my_sin(double u1)'

Example: 'int16 y1 = myAdd(int16 u1, int16 u2)'

Output Arguments

collapse all

Code replacement table entry that represents a potential code replacement for a function or operator, returned as an object. Maps the conceptual representation of a function or operator, conceptualSpecification, to the C/C++ implementation representation, implementationSpecification.

Version History

Introduced in R2015a