www.gusucode.com > ecoder 案例源码程序 matlab代码 > ecoder/OptimizeGeneratedCodeForProcessorByUsingCodeReplacementExample.m

    %% Optimize Generated Code for a Processor By Using Code Replacement
%
% Generate code that is optimized for a specific processor by using code replacement. 
%
% Supported IDE/tool chain:
%
% * Texas Instruments(TM) Code Composer Studio(TM)
%
% Supported processors:
%
% * All processors supported by IDE Link for use with 
% <matlab:web('http://www.mathworks.com/hardware-support/texas-instruments.html') Texas Instruments Code Composer Studio>
 
% Copyright 2008-2016 The MathWorks, Inc.
 
%% Introduction
% Embedded processors and associated compilers have instructions or
% "intrinsics" to support certain operations that are used frequently in
% typical embedded applications. Such processor-specific instructions and
% intrinsics execute much faster than their ANSI(R)/ISO(R) C equivalents.
% Using these instructions or intrinsics can optimize code performance
% significantly. Selecting a processor code replacement library
% enables you to generate processor-specific code that takes advantage of
% special processor instructions or intrinsics.
%  
%% Model Setup
% *1.* Open the <matlab:codeopt_tfl |codeopt_tfl|> model.
%
% *2.* Open the Model Configuration Parameters dialog box and set *Code
% Generation > System target file* to |idelink_ert.tlc|. Click
% *Apply*.
%
% *3.* Select *Code Generation > Coder Target*. Select *Target Hardware Resources* 
% and set the parameters to match your target hardware. Click *OK*.

close
open_system('codeopt_tfl');
 
%% Task 1: Generate and Profile ANSI(R) C Code
%
% Profile generated code that uses only ANSI(R) C.
% This establishes a performance baseline before optimization.
% After you set up the model for profiling, click *Build Model* to generate code.
 
 
%% Task 2: Generate Processor-Specific Code
%
% Specify the code replacement library for your processor to
% generate processor-specific embedded code.
%
% *1.* In the model window, select *Simulation > Model Configuration Parameters*.
%
% *2.* Click *Code Generation > Interface > Code replacement library* and select 
% the code replacement library that matches your processor family, such as TI C64x.
%
% *3.* Click *OK* to save the configuration and close the dialog box.
%
% *4.* Click *Build Model* to generate code.
%
% Inspect the generated code. Note the processor-specific code, such as 
% |c62x_mul_s32_s32_s32_sr_sat| in the |step| function.
%
% In addition to visual inspection, you can use the Code Replacement
% Viewer to browse replacement functions and operations that the code replacement 
% library supports. The tool can help you identify required
% conditions for target-specific code replacements. To invoke the viewer,
% enter the following command in the MATLAB(R) command window:
%
% <matlab:crviewer crviewer> 
%
% For more information on using the Code Replacement Viewer, see
% <docid:ecoder_ref.buiyjqb>. 
 
 
%% Task 3: Assess Performance Improvement
% 
% Profile the processor-specific code to verify that 
% performance improved. Follow the profiling instructions you used in Task 1.
%
% You can explore further performance improvement opportunities by using
% the Code Replacement Viewer. For example, if you are generating
% code for a TI C64x(TM) DSP, the Code Replacement Viewer shows you that
% the TI C64x code replacement library contains many arithmetic operations
% for integer and fixed-point data types. In this model, the Sum4 block
% outputs data of type |double|, which is not supported by an entry in the
% TI C64x code replacement library table. If you change the Sum4 block
% output data type to fixed-point, such as |fixdt(1, 32, 11)|, your code
% gains additional performance improvement by using TI C64x intrinsic code
% for the block's addition operation at the cost of a decrease in numerical
% precision.
%
% Regenerate and profile the generated code to confirm further performance
% improvement.
 
%% Task 4: Develop and Register a Custom Code Replacement Library
%
% If you prefer your own implementation for code replacement library, 
% you can develop and register your own code replacement library. See the
% example <docid:ecoder_examples.example-rtwdemo_crl_script_sc>.
 
close_system('codeopt_tfl', 0);

% LocalWords:  supportedio intrinsics helptargets tgtprefsetup idelinkdemodir
% LocalWords:  ticcs lfccsworkflow mul sr rtwdemo crl