Main Content

Troubleshoot Code Replacement Misses

Use miss reason messages that appear in the Code Replacement Viewer to analyze and correct code replacement misses.

Miss Reason Messages

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 Correct Code Replacement Misses

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 model.

  1. Review the code generated for a model element, looking for expected code replacements. For this example, examine the code generated for block Sub32 in model rtwdemo_crladdsub. 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.

    The code generator replaced code, but the replacement was for the signed version of the 32-bit subtraction operation. You expected an unsigned operation.

  2. Regenerate or reopen the Code Replacements Report for your model. If you already generated the code generation report that includes the Code Replacements Report for model rtwdemo_crladdsub, open the file rtwdemo_crladdsub_ert_rtw/html/rtwdemo_crladdsub_codegen_rpt.html. For information on how to regenerate the report, see Verify Code Replacement Library.

  3. Click the link to open the Code Replacement Viewer.

  4. In the viewer left pane, select your code replacement table. The following display shows entries for code replacement table crl_table_addsub.

  5. In the middle pane, select table entry RTW_OP_MINUS with implementation function u32_sub_u32_u32.

  6. 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.

    For this example, the report shows misses for two blocks: Sub32 and Sub8.

  7. Find that 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 in a source parameter setting. Miss Reason Messages lists conditions to consider.

    For this example, determine why code for the Sub32 block was not replaced with code for an unsigned 32-bit subtraction operation. The miss reason for the Sub32 block indicates a data type mismatch. The data type in the call site object for the three arguments is a signed 32-bit integer. The code replacement entry specifies an unsigned 32-bit integer.

  8. Correct the model or code replacement table entry. If the issue is in the model, use the source location link in the trace information to find the model element to correct. For this example, you expected an unsigned subtraction operation for the Sub32 block. Click the link in the trace report for the Sub32 block.

    The model opens with the Sub32 block highlighted.

    Change the data type setting for the two input signals and the output signal for the Sub32 block to uint32.

  9. Regenerate code. Use the Code Replacement Viewer trace information to verify that your model or code replacement table entry corrects the code replacement issue. In the following display, the trace information shows a hit for block Sub32.

Related Topics