Troubleshoot Code Replacement Misses
Use miss reason messages that appear in the Code Replacement Viewer to analyze and correct code replacement misses. The code replacement miss reasons are part of the Code Replacements Report. To generate the Code Replacements Report, see Verify Library Replacement.
Miss Reason Messages
After you generate code with code replacement enabled, the Code Replacement Viewer displays miss reason messages in trace information for code replacement misses. A legend listing each message that appears in the miss report precedes the report details. A message consists of:
Numeric identifier, which identifies the message in the report details.
Message text, which in some cases includes placeholders for names of arguments, call site object values, table entry values, and property names.
For example:
1. Mismatched data types (argument name, CSO value, table entry value)
The parenthetical information represents placeholders for actual values that appear in the report details.
In the Miss Source Locations table that lists the miss details, the Reason column includes:
The message identifier, as listed in the legend.
The placeholder values for that instance of the miss reason message.
The following Reason details indicate a
data type mismatch because the call site object specifies data type int8
for
arguments y1
, u1
, and u2
,
while the code replacement table entry specifies uint32
.
1. y1, int8, uint32 u1, int8, uint32 u2, int8, uint32
Depending on your situation and the reported miss reason, troubleshoot reported misses by looking for instances of the following:
A typo in the code replacement table entry definition or a source parameter setting.
Information missing from the code replacement table entry or a source parameter setting.
Invalid or incorrect information in the code replacement table entry definition or a source parameter setting.
Arguments incorrectly ordered in the code replacement table entry definition or the source being replaced with replacement code.
Failed algorithm classification for an addition or subtraction operation due to:
An ideal accumulator not being calculated because the type of an input argument is not fixed-point or the slope adjustment factors of the input arguments are not equal.
Input or output casts with a floating-point cast type.
Input or output casts with cast types that have different slope adjustment factors or biases.
Output casts not being convertible to a single output cast.
Input casts resulting in loss of bits.
Analyze and Fix Code Replacement Misses
The following example shows how to use Code Replacement Viewer trace
information to troubleshoot code replacement misses. For this example use the code generated
for block Sub32
in the model CRLAdditionSubtraction
.
Open and build the model. In the MATLAB® Command Window enter:
openExample("CRLAdditionSubtraction"); set_param(bdroot,GenerateReport=true); slbuild(bdroot);
Review the generated code of block
Sub32
and look for code replacements. Right-click the block and select C/C++ Code > Navigate to C/C++ Code.The Code Generation Report opens to the location of the generated code for that block.
Note that the code generator replaced code. But the replacement was for the signed version of the 32-bit subtraction operation, while you expected it to be for the unsigned version.
Open the Code Replacement Viewer. In the report, in the Content pane in the left, click Code Replacement Report. Then, in the right pane, click the link to open the Code Replacement Viewer.
In the Code Replacement Viewer:
In the left pane select the
crl_table_addsub
replacement entry.In the middle pane select
RTW_OP_MINUS
with implementation functionu32_sub_u32_u32
.In the right pane select the Trace Information tab.
The Trace Information is a table that lists the following information for each miss:
Call site object preview. The call site object is the conceptual representation of a subtraction operator. The code generator uses this object to query the code replacement library for a match.
A link to the source location in the model for which the code generator considered replacing code.
The reasons that the miss occurred. For the list of reasons that misses occur, see Miss Reason Messages.
In this example, the report shows misses for two blocks:
Sub32
andSub8
.According to the information provided in the Trace Information table, the miss reason for the
Sub32
block was type mismatch. The data type in the call site object is signed 32-bit integer for the three arguments, while the code replacement entry specifies unsigned 32-bit integer for the arguments.Fix the model:
In the right pane of the trace report, click the link in the Source Location of the
Sub32
block. The model opens with theSub32
block highlighted.Right-click the block and select Block Parameters.
In the dialog that opens, select the Signal Attributes tab. Then, in the Output data type edit box, change the value from
int32
touint32
, then click the OK button.Right-click input port 9 and select Block Parameters. In the dialog that opens, select the Signal Attributes tab. Then, in the Data type edit box, change the value from
int32
touint32
, then click the OK button.Change the Data type of input port 10 from
int32
touint32
in the same way.
Regenerate the code. In the MATLAB Command Window enter:
slbuild(bdroot);
Reopen the Code Replacement Viewer trace information to verify that
Sub32
block is not listed as containing a miss. In the following display, the trace information shows a hit for blockSub32
.