Addition and Subtraction Algorithm Types for Code Replacement - MATLAB & Simulink (original) (raw)

Main Content

When you replace an addition or subtraction operator, your library function algorithm must match the algorithm type of the operator that you want to replace. Addition and subtraction operations are either cast-before-operation or cast-after-operation algorithms. First, determine which type of algorithm your library function implements. Then, to replace an operator in the generated code, determine how the code generator classifies the operator algorithm. Match your library function algorithm to the classification. For an example, seeReplace Addition and Subtraction Operator Code.

Algorithm Options

When creating a code replacement table entry for an addition or subtraction operator, first determine the type of algorithm that your library function implements.

Algorithm Classification

During code generation, the code generator examines addition and subtraction operations, including adjacent type cast operations, to determine the type of algorithm to compute the expression result. Based on the data types in the expression and the type of the accumulator (type used to hold the result of the addition or subtraction operation), the code generator uses these rules.

In many cases, the numerical result of a CBO operation is equal to that of a CAO operation. For example, if the input and output types are such that the operation produces the ideal result, as in the case of int8 + int8 —> int16. To maximize the probability of code replacement occurring in such cases, set the algorithm to cast-after-operation.

Limitations

See Also

Topics