14 namespace module_identification
17 const std::vector<Net*>& output_nets,
18 const std::vector<Net*>& control_signals,
19 const std::vector<std::map<Net*, BooleanFunction::Value>>& control_signal_mappings,
20 const std::map<std::map<Net*, BooleanFunction::Value>,
BooleanFunction>& word_level_operations,
21 const std::vector<Gate*>& gates,
22 const std::vector<Gate*>& base_gates,
23 const std::map<std::string, std::string>& additional_data,
24 const std::set<CandidateType>& types)
25 : m_operands{operands}, m_output_nets{output_nets}, m_control_signals{control_signals}, m_control_signal_mappings{control_signal_mappings}, m_word_level_operations{word_level_operations},
26 m_gates{gates}, m_base_gates{base_gates}, m_total_input_nets{
get_input_nets(gates)}, m_total_output_nets{
get_output_nets(gates)}, m_types{types}, m_verified{!types.empty()},
27 m_additional_data{additional_data} {};
40 m_additional_data = {};
50 std::string result =
"";
51 result +=
"Verified: " + std::to_string(
m_verified) +
"\n";
52 result +=
"Candidate Types: \n";
58 result +=
"GATES [" + std::to_string(
m_gates.size()) +
"]" +
": \n";
61 result +=
"\t" + g->get_name() +
" / " + std::to_string(g->get_id()) +
"\n";
67 result +=
"OPERAND " + std::to_string(op_idx) +
" [" + std::to_string(nets.size()) +
"]" +
": \n";
68 for (
const auto& n : nets)
70 result +=
"\t" + n->get_name() +
" / " + std::to_string(n->get_id()) +
"\n";
73 result +=
"OUTPUT: [" + std::to_string(
m_output_nets.size()) +
"]\n";
76 result +=
"\t" + n->get_name() +
" / " + std::to_string(n->get_id()) +
"\n";
78 result +=
"CONTROL SIGNALS: [" + std::to_string(
m_control_signals.size()) +
"]\n";
83 for (
const auto& [n, v] : cm)
85 result +=
"\t" + n->get_name() +
" / " + std::to_string(n->get_id()) +
" : " + std::to_string(v) +
"\n";
87 result +=
"--------------------------------------------------\n";
89 result +=
"ADDITIONAL DATA: \n";
90 for (
const auto& [key,
data] : m_additional_data)
92 result +=
"\t" + key +
": " +
data +
"\n";
100 std::set<CandidateType> merged_types;
102 std::vector<Net*> merged_control_signals = candidates.front().m_control_signals;
103 std::vector<std::map<Net*, BooleanFunction::Value>> merged_control_signal_mappings;
104 std::map<std::map<Net*, BooleanFunction::Value>,
BooleanFunction> merged_word_level_operations;
106 std::vector<std::vector<Net*>> merged_operands;
108 std::vector<Gate*> merged_gates = candidates.front().m_gates;
109 std::vector<Gate*> merged_base_gates = candidates.front().m_base_gates;
112 std::vector<Net*> merged_output_nets = candidates.front().m_output_nets;
116 std::map<std::string, std::string> merged_additional_data;
119 std::set<Net*> assigned_to_operand;
121 for (
const auto& c : candidates)
123 merged_types.insert(c.m_types.begin(), c.m_types.end());
125 for (
const auto& cm : c.m_control_signal_mappings)
127 if (std::find(merged_control_signal_mappings.begin(), merged_control_signal_mappings.end(), cm) != merged_control_signal_mappings.end())
129 return ERR(
"cannot merge verified candidates with overlapping control signal mapping");
132 merged_control_signal_mappings.push_back(cm);
133 merged_word_level_operations.insert({cm, c.m_word_level_operations.at(cm)});
136 for (
const auto& nets : c.m_operands)
139 if (
const auto it = std::find(merged_operands.begin(), merged_operands.end(), nets); it != merged_operands.end())
144 bool is_not_intersecting =
true;
145 for (
const auto& n : nets)
147 if (n->is_gnd_net() || n->is_vcc_net())
152 if (assigned_to_operand.find(n) != assigned_to_operand.end())
154 log_warning(
"module_identification",
"found intersecting operand at net {} with ID {}", n->get_name(), n->get_id());
155 is_not_intersecting =
false;
160 if (is_not_intersecting)
162 merged_operands.push_back(nets);
163 for (
const auto& n : nets)
165 if (n->is_gnd_net() || n->is_vcc_net())
169 assigned_to_operand.insert(n);
177 merged_control_signals,
178 merged_control_signal_mappings,
179 merged_word_level_operations,
182 merged_additional_data,
190 return "NONE_CARRY_CHAIN";
203 if (ctrl_mapping.empty())
217 for (
const auto& [
net, val] : ctrl_mapping)
This file contains the enumeration and constants for the candidate types used in the module identific...
static Result< BooleanFunction > Ite(BooleanFunction &&p0, BooleanFunction &&p1, BooleanFunction &&p2, u16 size)
static Result< BooleanFunction > Eq(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
static BooleanFunction Var(const std::string &name, u16 size=1)
BooleanFunction clone() const
static BooleanFunction Const(const BooleanFunction::Value &value)
static Result< BooleanFunction > And(BooleanFunction &&p0, BooleanFunction &&p1, u16 size)
BooleanFunction get_boolean_variable() const
bool is_verified() const
Check if the candidate is verified.
std::string get_name() const
Get the name of the candidate that represents the functionality of the candidate.
BooleanFunction get_merged_word_level_operation() const
Get the merged word-level operation for the candidate.
std::vector< Net * > m_control_signals
VerifiedCandidate()
Default constructor for an empty/unverified VerifiedCandidate.
std::set< CandidateType > m_types
std::vector< Gate * > m_gates
std::vector< std::map< Net *, BooleanFunction::Value > > m_control_signal_mappings
std::string get_candidate_info() const
Get the candidate information as a string.
std::map< std::map< Net *, BooleanFunction::Value >, BooleanFunction > m_word_level_operations
static hal::Result< VerifiedCandidate > merge(const std::vector< VerifiedCandidate > &candidates)
Merge multiple verified candidates into a single candidate.
std::vector< std::vector< Net * > > m_operands
std::vector< Net * > m_output_nets
std::vector< Gate * > m_base_gates
#define log_error(channel,...)
#define log_warning(channel,...)
std::vector< Net * > get_input_nets(const std::vector< Gate * > &gates)
Get input nets from a list of gates.
std::vector< Net * > get_output_nets(const std::vector< Gate * > &gates, bool only_external_destinations=true)
Get output nets from a list of gates.
std::string join(const std::string &joiner, const Iterator &begin, const Iterator &end, const Transform &transform)
std::string enum_to_string(T e)
This file contains helper functions for module identification in the HAL framework.
The result of a module identification run containing the candidates.