%% Replace Code Generated from MATLAB Code
% This example shows how to replace generated code, using a code replacement library. Code replacement is a technique you can use to change the code that the code generator produces for functions and operators to meet application code requirements. For example, you can replace generated code to meet requirements such as:
% Optimization for a specific run-time environment, including, but not limited to, specific target hardware.
% Integration with existing application code.
% Compliance with a standard, such as AUTOSAR.
% Modification of code behavior, such as enabling or disabling nonfinite or inline support.
% Application- or project-specific code requirements, such as elimination of math.h, system header files, or calls to memcpy or memset, or use of BLAS.
%% Prepare for Code Replacement
% 1. Make sure that MATLAB®, MATLAB Coder™, and a C compiler are installed on your system. Some code replacement libraries available in your development environment can require Embedded Coder®.
% For instructions on installing MathWorks® products, see the MATLAB installation documentation. If you have installed MATLAB and want to see which other MathWorks products are installed, in the Command Window, enter  ver.
% 2. Identify an existing MATLAB function or create a MATLAB function for which you want the code generator to replace code.
%% Choose a Code Replacement Library
% By default, the code generator does not apply a code replacement library. You can choose from the following libraries that MathWorks® provides. If you are not sure which library to use, see Choose a Code Replacement Library.
% GNU C99 extensions—GNU® gcc math library, which provides C99 extensions as defined by compiler option -std=gnu99.
% AUTOSAR 4.0—Produces code that more closely aligns with the AUTOSAR standard. Requires an Embedded Coder® license.
% Intel IPP for x86-64 (Windows)—Generates calls to the Intel® Performance Primitives (IPP) library for the x86-64 Windows® platform.
% Intel IPP/SSE for x86-64 (Windows)—Generates calls to the IPP and Streaming SIMD Extensions (SSE) libraries for the x86-64 Windows platform.
% Intel IPP for x86-64 (Windows using MinGW compiler)—Generates calls to the IPP library for the x86-64 Windows platform and MinGW compiler.
% Intel IPP/SSE for x86-64 (Windows using MinGW compiler)—Generates calls to the IPP and SSE libraries for the x86-64 Windows platform and MinGW compiler.
% Intel IPP for x86/Pentium (Windows)—Generates calls to the IPP library for the x86/Pentium Windows platform.
% Intel IPP/SSE for x86/Pentium (Windows)—Generates calls to the Intel Performance IPP and SSE libraries for the x86/Pentium Windows platform.
% Intel IPP for x86-64 (Linux)—Generates calls to the IPP library for the x86-64 Linux® platform.
% Intel IPP/SSE with GNU99 extensions for x86-64 (Linux)—Generates calls to the GNU libraries for IPP and SSE, with GNU C99 extensions, for the x86-64 Linux platform.
% Libraries that include GNU99 extensions are intended for use with the GCC compiler. If you use one of those libraries with another compiler, generated code might not compile.
% Depending on the product licenses that you have, other libraries might be available. If you have an Embedded Coder license, you can view and choose from other libraries and you can create custom code replacement libraries.
%% Configure Code Generator to Use Code Replacement Library
% 1. Configure the code generator to apply a code replacement library during code generation for the MATLAB function. Do one of the following:
% In a project, on the Custom Code tab, set the docid:docid:coder_csh.buxuqfu parameter.
% In a code configuration object, set the CodeReplacementLibrary parameter.
% 2. Configure the code generator to produce only code. Before you build an executable program, verify your code replacements. Do one of the following:
% In a project, in the Generate dialog box, select Generate Code.
% In a code configuration object, set the GenCodeOnly parameter.
%% Include Code Replacement Information in Code Generation Report
% If you have an Embedded Coder license, you can configure the code generator to include a code replacement section in the code generation report. The additional information can help you verify code replacements. For more information, see Verify Code Replacements in the Embedded Coder documentation.
%% Generate Replacement Code
% Generate C/C++ code from the MATLAB code. If you configured the code generator to produce a report, generate a code generation report. For example, in the MATLAB Coder app, on the Generate Code page, click Generate. Or, at the command prompt, enter:
% codegen -report myFunction -args {5} -config cfg
% The code generator produces the code and displays the report.
%% Verify Code Replacements
% Verify code replacements by examining the generated code. Code replacement can sometimes behave differently than you expect. For example, data types that you observe in the code generator input might not match what the code generator uses as intermediate data types during an operation.
%% More About
% docid:coder_ug.buhn_n9
% Choose a Code Replacement Library
% Configure Build Settings
% Copyright 2016 The MathWorks, Inc.