Unnecessary copies in code when using nested non-virtual buses with atomic subsystems

7 ビュー (過去 30 日間)
Ali
Ali 2025 年 9 月 22 日
コメント済み: Ali 2025 年 9 月 29 日
I'm using Matlab/Simulink r2017B with Embedded Coder, to generate C code of my model. In my model, I have nested atomic subsystems, packaged as 'Reusable Function', which emits nonvirtual bus signals. Going deep to surface, those nonvirtual bus signals at the same level, combined into another nonvirtual bus signal.
The problem is, when I look to the generated code, in each subsystem function that have nonvirtual bus output with nested buses, there are unnecessary copies occured. For example:
void subsys_inner(uint32 rtu_in1, uint32 rtu_in2, Out_Bus* rty_out, /* some other args like block struct and DWorks */)
{
uint32 rtb_outsig1;
uint32 rtb_outsig2;
rtb_outsig1 = rtu_in1 + 1;
rtb_outsig2 = rtu_in2 + 1;
/* It uses local signal copies and assigns to output instead of using rty_out
inside code directly
*/
rty_out->outsig1 = rtb_outsig1;
rty_out->outsig2 = rtb_outsig2;
}
void subsys_outer(Outer_Bus* rty_out, /* some other args like block struct and DWorks */)
{
/* It creates a local copy of the nested bus */
Out_Bus rtb_Out_Bus_signal;
subsys_inner(1, 2, &rtb_Out_Bus_signal ...);
/* Again it made a deep copy instead of using rty_out->outbus directly in the above call */
rty_out->outbus = rtb_Out_Bus_signal;
}
That code is something I've made up right now to express the thing briefly, not a direct output of Embedded Coder.
I tried a lot of configuration options in Model Configuration pane but could not succeed to eliminate those copies. Is there any way to eliminate those copies?
Thanks in advance.

回答 (1 件)

Mark McBroom
Mark McBroom 2025 年 9 月 29 日
Each release of Embedded Coder incluces improved optimization, and removing data copies is one of the most common improvements. Do you have access to a newer MATLAB release?
Thanks.
Mark.
  1 件のコメント
Ali
Ali 2025 年 9 月 29 日

Unfortunately I don’t have.

Due to my observations, ExpressionFolding optimization eliminates the deep copies on local scope, so it solves the deep copy problem presented in “subsys_inner” function, but it does not help when crossing atomic boundary.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDeployment, Integration, and Supported Hardware についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by