%% Avoid Constant Block Connections to Subsystem Port Boundaries

% Copyright 2018 The MathWorks, Inc.

%% Guideline ID
% |1.2.4|

%% Severity
% _Mandatory_

%% Description
% It is recommended that you avoid directly connecting Constant blocks 
% to the output ports of a Subsystem. Synthesis tools may optimize and remove 
% the constants and create unconnected ports. 
%
% If you use floating-point data types with the |Native Floating Point| mode 
% enabled, and input constant values to an arithmetic operator such 
% as an Add block, HDL Coder(TM) replaces the Add block with a Constant block 
% when generating code. This optimization can result in a Constant block 
% directly connected to the output port. Therefore, it is 
% recommended that you avoid such modeling constructs. See also
% <matlab:helpview(fullfile(docroot,'hdlcoder/ug/constant-folding-and-peephole-optimizations-in-hdl-coder.html')) 
% Simplify Constant Operations and Reduce Design Complexity in HDL Coder>.
%% 
% For example, open the model |hdlcoder_constant_subsystem_boundary.slx|. The
% DUT contains two subsystems |Constant_subsys1| and |Constant_subsys2|,
% the outputs of which are inputs to a third Subsystem.
% |Constant_subsys1| contains Constant blocks directly connected to the
% output ports, and |Constant_subsys2| contains Constant blocks that have
% single data types as inputs to an Add block. 
load_system('hdlcoder_constant_subsystem_boundary.slx')
set_param('hdlcoder_constant_subsystem_boundary','SimulationCommand','Update')
open_system('hdlcoder_constant_subsystem_boundary/DUT/Constant_subsys1')
%%
open_system('hdlcoder_constant_subsystem_boundary/DUT/Constant_subsys2')
%%
% As |Constant_subsys2| uses single data types and the model has |Native
% Floating Point| mode enabled, when you generate HDL code for the DUT, the
% |Constant_subsys2| becomes a candidate for the optimization that simplifies
% constant operations. When you open the generated model, you see a Constant block
% directly connected to the output port.
open_system('gm_hdlcoder_constant_subsystem_boundary.slx')
set_param('gm_hdlcoder_constant_subsystem_boundary','SimulationCommand','Update')
open_system('gm_hdlcoder_constant_subsystem_boundary/DUT/Constant_subsys2')