C Code Generation
C Code Generation
C/C++ Coders
MATLAB Coder - Code from MATLAB Portable code for numerical algorithms Desktop applications (standalone, library) Simulink Coder - Code from Simulink
Generate
Rapid prototyping or HIL applications Real-time machines (xPC Target) Embedded Coder Production optimized code Embedded applications MCU and DSP (fixed or float) Code verification (in-the-loop) Target-specific support (APIs and examples)
Verify
C/C++
2
November 2013
Simplify integration with existing C code Runtime errors handled using setjmp/longjmp rather than try/catch
10
Optimize X = [X C]
codegen -config:lib grow_a_vec_pattern -args {} -report
This is a typical pattern of growing a vector but it generates data copies in previous releases R2013a generates optimized code, improves RAM/ROM and speed
for (i = 0; i < 10; i++) { ...................... for (i0 = 0; i0 < loop_ub; i0++) { b_x_data[i0] = (int8_T)x_data[i0]; } b_x_data[y_size[1]] = (int8_T)(1 + i); ....................... for (i0 = 0; i0 < x_size_idx_1; i0++) { x_data[i0] = (real_T)b_x_data[i0]; } ...................... }
concat
assign
R2013a
R2012b
11
12
13
14
15
November 2013
17
18
19
>> coderdemo_contrast_enhancer
20
Use built-in C types in the generated code Make generated code look more like handwritten code Revert to old behavior if desired
22
Generate multiword code for hardware target not having 64bit integer C type
Leverage long long C Type
23
24
November 2013
Allows Reusable (CSC) buffer specification at Simulink model root IO Reusable buffers are reused in the generated code (buffers are merged for a pair of specified root input and output) Feature-controlled
Reuse of abc
slfeature(ReuseReusableCSCAtRootIO,
1)
28
Easily Run Generated Code in the Microsoft Visual C++ Source Level Debugger
Step through the generated code in the MSVC debugger during SIL simulations
Supports top-model and Model block SIL Automatically compiles generated code with debug symbols Automatically launches MSVC and adds breakpoints at entry point functions in generated code
29
30
Easily Review Function Execution Times for Code Running on Embedded Hardware
Comprehensive measurement of function call execution times
Call-site instrumentation to measure execution time of functions in the generated code Now includes initialization, shared utility and math library functions Configurable units for reporting of measured execution times
rtwdemo_sil_topmodel
31
Results automatically imported into Simulation Data Inspector Use extensive capabilities to plot execution times and to manage and compare runs Faster alternative to the command line API
rtwdemo_sil_topmodel
32
rtwdemo_custom_pil_script
33
November 2013
37
39
40
R2013a
void sys(real_T in1, real_T in2, real_T *out) { *out = in1 + in2; } Void model(void) { sys(U.In1, U.In2, &rtb_sum); Y.out = rtb_sum + U.In3; }
R2013b
real_T sys(real_T in1, real_T in2) { return in1 + in2; } void model(void) { rtb_sum = sys(U.In1, U.In2); Y.out = rtbsum + U.In3; }
41
42
Example: Code Replacement Library enables FIR filter code to use ARM CMSIS DSP library: arm_fir_f32()
43
44
Average Global RAM Reduction Since R2008b (Using 70+ Industry Models)
Global RAM Usage
Relative to R2008b
Code Report
45
Unnecessary Data Copy Reduction Since R2008b (Using 70+ Industry Models)
Data Copy Measurement
MathWorks has developed a target-independent method to measure data copies, which helps prioritize our code efficiency efforts
46
Relative to R2008b
Thank you
47