Use miss reason messages that appear in the Code Replacement Viewer to analyze and correct code replacement misses.
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.
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
while the code replacement table entry specifies
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.
The following example shows how to use Code Replacement Viewer trace information to troubleshoot code replacement misses. You must have already reviewed and tested code replacements for your MATLAB® code.
Review the code generated for a specific code element, looking for expected code
replacement. Regenerate or reopen the code generation report for your MATLAB code. If you already generated the code generation report that includes
the Code Replacements Report for
open the file
information on how to regenerate the report, see Verify Code Replacement Library.
To examine the code generated for the function, from the code generation report,
open the generated file
extern void addsub_two_int16(double u1, double u2, short *b_y1, short *y2);
The code generator replaced code, but the replacement is for the signed version of the 16-bit addition and subtraction operations. You expected code replacements for operations on unsigned data.
Open the Code Replacements Report for the MATLAB code.
Click the link to open the Code Replacement Viewer.
In the viewer left pane, select your code replacement table. For this example,
select code replacement table
In the middle pane, select table entry
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 addition operator. The code generator uses this object to query the code replacement library for a match.
A link to the source location in the MATLAB function where the code generator considered replacing code.
The reasons that the miss occurred. See Miss Reason Messages.
For this example, the report shows misses for function
Find the source in the trace information. Depending on your situation and the reported miss reason, consider looking for a condition such as a typo in the code replacement table entry definition or a source parameter setting. For a list of conditions to consider, seeMiss Reason Messages.
For this example, determine why code for function
addsub_two_int16 is not replaced with code for an unsigned 16-bit
addition operation. The miss reasons for the function indicate data type and algorithm
The data type in the call site object is a signed 16-bit integer. The code replacement entry specifies an unsigned 16-bit integer.
The algorithm property in the call site object is
RTW_CAST_AFTER_OP while the code replacement entry specifies
Fix the specified MATLAB code and relevant specifications or code replacement table entry. If the
issue concerns the MATLAB code, use the source location in the trace information to find the code to
fix. For this example, you expected an unsigned addition operation to occur for the
To fix the mismatches, in the test file
change the data types definitions for
u1 = uint16(10) u2 = uint16(10)
In the MATLAB Coder™ app:
Open the project that contains the
Use the updated test file
automatically redefine the input types.
Change the addition and subtraction algorithm setting. Open the code replacement
crl_table_addsub. Change the entry
Algorithm parameter setting from
Cast after operation
Regenerate code and a report.
From the Code Replacements Report, open the Code Replacement Viewer. Use the Code
Replacement Viewer trace information to verify that your MATLAB code or code replacement table entry corrects the code replacement issue.
The trace information shows a hit for function