Code You Can Replace from MATLAB Code - MATLAB & Simulink (original) (raw)

Main Content

Code that the code generator replaces depends on the code replacement library (CRL) that you use. By default, the code generator does not apply a code replacement library. Your choice of libraries is dependent on product licensing and whether you have access to custom libraries.

Math Functions

When generating C/C++ code from MATLABĀ® code, depending on code replacement libraries available in your development environment, you can configure the code generator to replace instances of the following math functions with application-specific implementations.

Function Data Type Support Scalar, Vector, Matrix Support Real, Complex Support
abs1 Floating point ScalarVectorMatrix RealComplex
acos Floating point ScalarVectorMatrix RealComplexComplex input/complex outputReal input/complex output
acosd Floating point ScalarVectorMatrix RealComplex
acot Floating point ScalarVectorMatrix RealComplex
acotd Floating point ScalarVectorMatrix RealComplex
acoth Floating point ScalarVectorMatrix RealComplex
acsc Floating point ScalarVectorMatrix RealComplex
acscd Floating point ScalarVectorMatrix RealComplex
acsch Floating point ScalarVectorMatrix RealComplex
asec Floating point ScalarVectorMatrix RealComplex
asecd Floating point ScalarVectorMatrix RealComplex
asech Floating point ScalarVectorMatrix RealComplex
asin Floating point ScalarVectorMatrix RealComplexComplex input/complex outputReal input/complex output
asind Floating point ScalarVectorMatrix RealComplex
atan Floating point ScalarVectorMatrix RealComplexComplex input/complex outputReal input/complex output
atan2 Floating point ScalarVectorMatrix Real
atan2d Floating point ScalarVectorMatrix Real
atand Floating point ScalarVectorMatrix RealComplex
cos Floating point ScalarVectorMatrix RealComplexComplex input/complex outputReal input/complex output
ceil Floating-pointScalar Floating-pointScalar Floating-pointScalar
cosd Floating point ScalarVectorMatrix RealComplex
cosh Floating point ScalarVectorMatrix RealComplexComplex input/complex outputReal input/complex output
cot Floating point ScalarVectorMatrix RealComplex
cotd Floating point ScalarVectorMatrix RealComplex
coth Floating point ScalarVectorMatrix RealComplex
csc Floating point ScalarVectorMatrix RealComplex
cscd Floating point ScalarVectorMatrix RealComplex
csch Floating point ScalarVectorMatrix RealComplex
exp Floating point ScalarVectorMatrix Real
fix Floating point Scalar Real
floor Floating-pointScalar Floating-pointScalar Floating-pointScalar
hypot Floating point ScalarVectorMatrix Real
ldexp Floating point Scalar Real
log Floating point ScalarVectorMatrix RealComplex
log10 Floating point ScalarVectorMatrix RealComplex
log2 Floating point ScalarVectorMatrix RealComplex
max IntegerFloating point Scalar Real
min IntegerFloating point Scalar Real
pow Floating point Scalar Real
rem Floating point Scalar Real
round Floating point Scalar Real
sec Floating point ScalarVectorMatrix RealComplex
secd Floating point ScalarVectorMatrix RealComplex
sech Floating point ScalarVectorMatrix RealComplex
sign Floating point Scalar Real
sin Floating point ScalarVectorMatrix RealComplexComplex input/complex outputReal input/complex output
sind Floating point ScalarVectorMatrix RealComplex
sinh Floating point ScalarVectorMatrix RealComplexComplex input/complex outputReal input/complex output
sqrt Floating point Scalar Real
tan Floating point ScalarVectorMatrix RealComplexComplex input/complex outputReal input/complex output
tand Floating point ScalarVectorMatrix RealComplex
tanh Floating point ScalarVectorMatrix RealComplexComplex input/complex outputReal input/complex output
1 Wrap on integer overflow only

Memory Functions

Depending on code replacement libraries available in your development environment, you can configure the code generator to replace instances of the following memory functions with application-specific implementations.

Function Data Type Support Scalar, Vector, Matrix Support Real, Complex Support
memcmp Void pointer (void*) ScalarVectorMatrix RealComplex
memcpy Void pointer (void*) ScalarVectorMatrix RealComplex
memset Void pointer (void*) ScalarVectorMatrix RealComplex
memset2zero Void pointer (void*) ScalarVectorMatrix RealComplex

Some target processors provide optimized functions to set memory to zero. Use the code replacement library programming interface to replace the memset2zero function with more efficient target-specific functions.

Operators

When generating C/C++ code from MATLAB code, depending on code replacement libraries available in your development environment, you can configure the code generator to replace instances of the following operators with application-specific implementations.

Mixed data type support indicates you can specify different data types of different inputs.

Operator Key Data Type Support Scalar, Vector, Matrix Support Real, Complex Support
Addition (+)1 RTW_OP_ADD IntegerFloating pointFixed-pointMixed ScalarVectorMatrix RealComplex
Subtraction (-)1 RTW_OP_MINUS IntegerFloating pointFixed-pointMixed ScalarVectorMatrix RealComplex
Multiplication (*)2 RTW_OP_MUL IntegerFloating pointFixed-pointMixed ScalarVectorMatrix RealComplex
Division (/) RTW_OP_DIV IntegerFloating pointFixed-pointMixed Scalar RealComplex
Data type conversion (cast) RTW_OP_CAST IntegerFloating point3Fixed-pointMixed ScalarVectorMatrix RealComplex
Shift left (<<) RTW_OP_SL IntegerFixed-pointMixed ScalarVectorMatrix Real
Shift right arithmetic (>>)4 RTW_OP_SRA IntegerFixed-pointMixed ScalarVectorMatrix Real
Shift right logical (>>) RTW_OP_SRL IntegerFixed-pointMixed ScalarVectorMatrix Real
Element-wise matrix multiplication (.*)5 RTW_OP_ELEM_MUL IntegerFloating pointFixed-pointMixed VectorMatrix RealComplex
Complex conjugation RTW_OP_CONJUGATE IntegerFloating pointFixed-pointMixed ScalarVectorMatrix RealComplex
Transposition (.') RTW_OP_TRANS IntegerFloating pointFixed-pointMixed VectorMatrix RealComplex
Hermitian (complex conjugate) transposition (') RTW_OP_HERMITIAN IntegerFloating pointFixed-pointMixed VectorMatrix RealComplex
Multiplication with transposition2 RTW_OP_TRMUL IntegerFloating pointFixed-pointMixed VectorMatrix RealComplex
Multiplication with Hermitian transposition2 RTW_OP_HMMUL IntegerFloating pointFixed-pointMixed VectorMatrix RealComplex
Multiplication followed by shift right arithmetic (u1*u2>>u3)6 RTW_OP_MUL_SRA IntegerFixed-point Scalar Real
Multiplication followed by division (u1*u2/u3)7 RTW_OP_MULDIV IntegerFixed-point Scalar Real
Greater than (>) RTW_OP_GREATER_THAN IntegerFloating pointFixed-pointMixed ScalarVectorMatrix RealComplex
Greater than or equal (>=) RTW_OP_GREATER_THAN_OR_EQUAL IntegerFloating pointFixed-pointMixed ScalarVectorMatrix RealComplex
Less than (<) RTW_OP_LESS_THAN IntegerFloating pointFixed-pointMixed ScalarVectorMatrix RealComplex
Less than or equal (<=) RTW_OP_LESS_THAN_OR_EQUAL IntegerFloating pointFixed-pointMixed ScalarVectorMatrix RealComplex
Equal (==) RTW_OP_EQUAL IntegerFloating pointFixed-pointMixed ScalarVectorMatrix RealComplex
Not equal (!=) RTW_OP_NOT_EQUAL IntegerFloating pointFixed-pointMixed ScalarVectorMatrix RealComplex
1 See Addition and Subtraction Operator Code Replacement for details to consider when defining mappings for addition and subtraction code replacements.2 Can map to Basic Linear Algebra Subroutine (BLAS) multiplication functions.3 Scaled floating point is not supported.4 Code replacement libraries that provide arithmetic shift right implementations should also provide logical shift right implementations, because some arithmetic shift rights are converted to logical shift rights during code generation.5 Use the multiplication (*) operator (RTW_OP_MUL) for scalar multiplication.6 Requires scalar, real, or fixed-point data types with zero bias; output type of the multiplication operation to accommodate all possible output values; shift operand is an unsigned integer; and net slope is equal to 1 (U1_slope * U2_slope == Mul_output_slope and Mul_output_slope == output_slope_of_shift_operation).7 Requires scalar, real, or fixed-point data types with zero bias; output type of the multiplication operation to accommodate all possible output values; and net slope is equal to 1 (U1_slope * U2_slope == Mul_output_slope == U3_slope * Div_output_slope).

See Also

Topics