Main Content

Code You Can Replace from MATLAB Code

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.

FunctionData Type SupportScalar, Vector, Matrix SupportReal, Complex Support
abs1Floating pointScalar
Vector
Matrix
Real
Complex
acosFloating pointScalar
Vector
Matrix
Real
Complex
Complex input/complex output
Real input/complex output
acosdFloating pointScalar
Vector
Matrix
Real
Complex
acotFloating pointScalar
Vector
Matrix
Real
Complex
acotdFloating pointScalar
Vector
Matrix
Real
Complex
acothFloating pointScalar
Vector
Matrix
Real
Complex
acscFloating pointScalar
Vector
Matrix
Real
Complex
acscdFloating pointScalar
Vector
Matrix
Real
Complex
acschFloating pointScalar
Vector
Matrix
Real
Complex
asecFloating pointScalar
Vector
Matrix
Real
Complex
asecdFloating pointScalar
Vector
Matrix
Real
Complex
asechFloating pointScalar
Vector
Matrix
Real
Complex
asinFloating pointScalar
Vector
Matrix
Real
Complex
Complex input/complex output
Real input/complex output
asindFloating pointScalar
Vector
Matrix
Real
Complex
atanFloating pointScalar
Vector
Matrix
Real
Complex
Complex input/complex output
Real input/complex output
atan2Floating pointScalar
Vector
Matrix
Real
atan2dFloating pointScalar
Vector
Matrix
Real
atandFloating pointScalar
Vector
Matrix
Real
Complex
cosFloating pointScalar
Vector
Matrix
Real
Complex
Complex input/complex output
Real input/complex output
ceil
  • Floating-point

  • Scalar

  • Floating-point

  • Scalar

  • Floating-point

  • Scalar

cosdFloating pointScalar
Vector
Matrix
Real
Complex
coshFloating pointScalar
Vector
Matrix
Real
Complex
Complex input/complex output
Real input/complex output
cotFloating pointScalar
Vector
Matrix
Real
Complex
cotdFloating pointScalar
Vector
Matrix
Real
Complex
cothFloating pointScalar
Vector
Matrix
Real
Complex
cscFloating pointScalar
Vector
Matrix
Real
Complex
cscdFloating pointScalar
Vector
Matrix
Real
Complex
cschFloating pointScalar
Vector
Matrix
Real
Complex
expFloating pointScalar
Vector
Matrix
Real
fixFloating pointScalarReal
floor
  • Floating-point

  • Scalar

  • Floating-point

  • Scalar

  • Floating-point

  • Scalar

hypotFloating pointScalar
Vector
Matrix
Real
ldexpFloating pointScalarReal
logFloating pointScalar
Vector
Matrix
Real
Complex
log10Floating pointScalar
Vector
Matrix
Real
Complex
log2Floating pointScalar
Vector
Matrix
Real
Complex
maxInteger
Floating point
ScalarReal
minInteger
Floating point
ScalarReal
powFloating pointScalarReal
remFloating pointScalarReal
roundFloating pointScalarReal
secFloating pointScalar
Vector
Matrix
Real
Complex
secdFloating pointScalar
Vector
Matrix
Real
Complex
sechFloating pointScalar
Vector
Matrix
Real
Complex
signFloating pointScalarReal
sinFloating pointScalar
Vector
Matrix
Real
Complex
Complex input/complex output
Real input/complex output
sindFloating pointScalar
Vector
Matrix
Real
Complex
sinhFloating pointScalar
Vector
Matrix
Real
Complex
Complex input/complex output
Real input/complex output
sqrtFloating pointScalarReal
tanFloating pointScalar
Vector
Matrix
Real
Complex
Complex input/complex output
Real input/complex output
tandFloating pointScalar
Vector
Matrix
Real
Complex
tanhFloating pointScalar
Vector
Matrix
Real
Complex
Complex input/complex output
Real 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.

FunctionData Type SupportScalar, Vector, Matrix SupportReal, Complex Support
memcmpVoid pointer (void*)Scalar
Vector
Matrix
Real
Complex
memcpyVoid pointer (void*)Scalar
Vector
Matrix
Real
Complex
memsetVoid pointer (void*)Scalar
Vector
Matrix
Real
Complex
memset2zeroVoid pointer (void*)Scalar
Vector
Matrix
Real
Complex

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.

OperatorKeyData Type SupportScalar, Vector, Matrix SupportReal, Complex Support
Addition (+)1RTW_OP_ADDInteger
Floating point
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Complex
Subtraction (-)1RTW_OP_MINUSInteger
Floating point
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Complex
Multiplication (*)2RTW_OP_MULInteger
Floating point
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Complex
Division (/)RTW_OP_DIVInteger
Floating point
Fixed-point
Mixed
Scalar
Real
Complex
Data type conversion (cast)RTW_OP_CASTInteger
Floating point3
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Complex
Shift left (<<)RTW_OP_SLInteger
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Shift right arithmetic (>>)4RTW_OP_SRA
Integer
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Shift right logical (>>)RTW_OP_SRL Integer
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Element-wise matrix multiplication (.*)5RTW_OP_ELEM_MULInteger
Floating point
Fixed-point
Mixed
Vector
Matrix
Real
Complex
Complex conjugationRTW_OP_CONJUGATEInteger
Floating point
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Complex
Transposition (.')RTW_OP_TRANSInteger
Floating point
Fixed-point
Mixed
Vector
Matrix
Real
Complex
Hermitian (complex conjugate) transposition (')RTW_OP_HERMITIANInteger
Floating point
Fixed-point
Mixed
Vector
Matrix
Real
Complex
Multiplication with transposition2RTW_OP_TRMULInteger
Floating point
Fixed-point
Mixed
Vector
Matrix
Real
Complex
Multiplication with Hermitian transposition2RTW_OP_HMMULInteger
Floating point
Fixed-point
Mixed
Vector
Matrix
Real
Complex
Multiplication followed by shift right arithmetic (u1*u2>>u3)6RTW_OP_MUL_SRAInteger
Fixed-point
ScalarReal
Multiplication followed by division (u1*u2/u3)7RTW_OP_MULDIVInteger
Fixed-point
ScalarReal
Greater than (>)RTW_OP_GREATER_
THAN
Integer
Floating point
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Complex
Greater than or equal (>=)RTW_OP_GREATER_
THAN_OR_EQUAL
Integer
Floating point
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Complex
Less than (<)RTW_OP_LESS_THANInteger
Floating point
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Complex
Less than or equal (<=)RTW_OP_LESS_THAN_
OR_EQUAL
Integer
Floating point
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Complex
Equal (==)RTW_OP_EQUALInteger
Floating point
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Complex
Not equal (!=)RTW_OP_NOT_EQUALInteger
Floating point
Fixed-point
Mixed
Scalar
Vector
Matrix
Real
Complex

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

Related Topics