PandA-2024.02
ReadWrite_arrayModuleGenerator.cpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2022-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
48 
49 #include "behavioral_helper.hpp"
50 #include "call_graph_manager.hpp"
51 #include "constant_strings.hpp"
52 #include "function_behavior.hpp"
53 #include "hls_manager.hpp"
54 #include "language_writer.hpp"
55 #include "math_function.hpp"
56 #include "structural_objects.hpp"
57 
58 enum in_port
59 {
60  i_clock = 0,
67  i_q,
69 };
70 
72 {
73  o_out1 = 0,
77  o_d,
79 };
80 
82 {
83 }
84 
85 void ReadWrite_arrayModuleGenerator::InternalExec(std::ostream& out, structural_objectRef mod, unsigned int function_id,
86  vertex /* op_v */, const HDLWriter_Language /* language */,
87  const std::vector<ModuleGenerator::parameter>& /* _p */,
88  const std::vector<ModuleGenerator::parameter>& _ports_in,
89  const std::vector<ModuleGenerator::parameter>& _ports_out,
90  const std::vector<ModuleGenerator::parameter>& /* _ports_inout */)
91 {
92  const auto bundle_name = mod->get_id().substr(0, mod->get_id().find(STR_CST_interface_parameter_keyword));
93  const auto top_fid = HLSMgr->CGetCallGraphManager()->GetRootFunction(function_id);
94  const auto top_fname = HLSMgr->CGetFunctionBehavior(top_fid)->CGetBehavioralHelper()->GetMangledFunctionName();
95  const auto func_arch = HLSMgr->module_arch->GetArchitecture(top_fname);
96  THROW_ASSERT(func_arch, "Expected function architecture for function " + top_fname);
97  const auto arraySize =
98  std::accumulate(func_arch->parms.begin(), func_arch->parms.end(), 0ULL, [&](auto& a, auto& it) {
99  const auto& parm_attrs = it.second;
100  if(parm_attrs.at(FunctionArchitecture::parm_bundle) == bundle_name)
101  {
102  THROW_ASSERT(parm_attrs.find(FunctionArchitecture::parm_elem_count) != parm_attrs.end(), "");
103  return a + std::stoull(parm_attrs.at(FunctionArchitecture::parm_elem_count));
104  }
105  return a;
106  });
107 
108  const auto isAlignedPowerOfTwo = _ports_in[i_in4].alignment == ceil_pow2(_ports_in[i_in4].alignment);
109  const auto addressMaxValue = _ports_in[i_in4].alignment * arraySize - 1U;
110  const auto nbitAddress =
111  addressMaxValue <= 1U ? 1U : (64u - static_cast<unsigned>(__builtin_clzll(addressMaxValue)));
112 
113  out << "//" << (isAlignedPowerOfTwo ? "T" : "F") << "\n";
114  out << "assign " << _ports_out[o_ce].name << " = " << _ports_in[i_start].name << "[0];\n";
115 
116  if(isAlignedPowerOfTwo)
117  {
118  out << "assign " << _ports_out[o_address].name << " = " << _ports_in[i_in4].name << "[BITSIZE_"
119  << _ports_in[i_in4].name << "*0+:" << nbitAddress << "] / " << _ports_in[i_in4].alignment << ";\n";
120  }
121  else
122  {
123  out << "assign " << _ports_out[o_address].name << " = " << _ports_in[i_in4].name << "[2+BITSIZE_"
124  << _ports_in[i_in4].name << "*0+:" << nbitAddress - 2U << "] / " << _ports_in[i_in4].alignment / 4 << ";\n";
125  }
126 
127  if(_ports_in.size() > i_q)
128  {
129  out << "assign " << _ports_out[o_out1].name << "[BITSIZE_" << _ports_out[o_out1].name << "*0+:BITSIZE_"
130  << _ports_out[o_out1].name << "] = " << _ports_in[i_q].name << ";\n";
131  }
132 
133  if(_ports_out.size() > o_d)
134  {
135  out << "assign " << _ports_out[o_we].name << " = " << _ports_in[i_start].name << "[0] & (|"
136  << _ports_in[i_in1].name << "[BITSIZE_" << _ports_in[i_in1].name << "*0+:BITSIZE_" << _ports_in[i_in1].name
137  << "]);\n";
138  out << "assign " << _ports_out[o_d].name << " = " << _ports_in[i_in3].name << "[BITSIZE_" << _ports_in[i_in3].name
139  << "*0+:BITSIZE_" << _ports_in[i_in3].name << "];\n";
140  }
141 }
Data structure representing the entire HLS information.
#define STR_CST_interface_parameter_keyword
interface_parameter_keyword
const std::string & get_id() const
Return the identifier associated with the structural_object.
mathematical utility function not provided by standard libraries
void InternalExec(std::ostream &out, structural_objectRef mod, unsigned int function_id, vertex op_v, const HDLWriter_Language language, const std::vector< ModuleGenerator::parameter > &_p, const std::vector< ModuleGenerator::parameter > &_ports_in, const std::vector< ModuleGenerator::parameter > &_ports_out, const std::vector< ModuleGenerator::parameter > &_ports_inout) final
HDLWriter_Language
This class writes different HDL based descriptions (VHDL, Verilog, SystemC) starting from a structura...
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
This class describes all classes used to represent a structural object.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
ReadWrite_arrayModuleGenerator(const HLS_managerRef &HLSMgr)
constant strings
Wrapper to call graph.
A brief description of the C++ Header File.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289

Generated on Mon Feb 12 2024 13:02:54 for PandA-2024.02 by doxygen 1.8.13