From b7fa127c8273c43453527ac4790e7a015abb549a Mon Sep 17 00:00:00 2001 From: joern274 Date: Sun, 3 Mar 2024 10:43:35 +0100 Subject: [PATCH 1/2] Debug output added to understand MacOS test failure --- tests/netlist/module.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/netlist/module.cpp b/tests/netlist/module.cpp index 1c85e69f817..a117838f640 100644 --- a/tests/netlist/module.cpp +++ b/tests/netlist/module.cpp @@ -1293,8 +1293,20 @@ namespace hal { // Trigger the event trigger_event[event_idx](); + Gate* gg = test_nl->get_gate_by_id(MIN_GATE_ID); + Module* mm = test_mod; + if (gg && mm) + { + for (ModulePin* mp : mm->get_pins()) + std::cerr << "Module pin " << mp->get_id() << " <" << mp->get_name() << ">" << std::endl; + for (Endpoint* ep : gg->get_fan_in_endpoints()) + std::cerr << "Gate in pin " << ep->get_pin()->get_id() << " <" << ep->get_pin()->get_name() << ">" << std::endl; + for (Endpoint* ep : gg->get_fan_out_endpoints()) + std::cerr << "Gate out pin " << ep->get_pin()->get_id() << " <" << ep->get_pin()->get_name() << ">" << std::endl; + } EXPECT_EQ(listener.get_event_count(), 1); + std::cerr << "Event " << event_idx << " <" << std::get<2>(listener.get_last_parameters()) << "> exp=<" << std::get<2>(expected_parameter[event_idx]) << ">" << std::endl; EXPECT_EQ(listener.get_last_parameters(), expected_parameter[event_idx]); // Unregister the callback From 6f97b6d192748c03d8ebdd5bc09f9d491c0aba20 Mon Sep 17 00:00:00 2001 From: joern274 Date: Sun, 3 Mar 2024 20:58:03 +0100 Subject: [PATCH 2/2] Bugfix: permutation order of truth table --- .../gatelibrary_tab_truth_table.cpp | 59 ++++++++----------- tests/netlist/module.cpp | 12 ---- 2 files changed, 24 insertions(+), 47 deletions(-) diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.cpp index 41f674dc7b2..b9817926f8c 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.cpp @@ -31,6 +31,10 @@ namespace hal if (getColumnNumber(gate)-1 > 8) { mTableWidget->hide(); + mDisclaimer->setText(QString("Cannot calculate truth table\nfor gate with %1 input pins\nand %2 output pins") + .arg(gate->get_input_pins().size()) + .arg(gate->get_output_pins().size())); + mDisclaimer->show(); return; } @@ -41,64 +45,50 @@ namespace hal mTableWidget->verticalHeader()->hide(); BooleanFunction boolFunc = gate->get_boolean_function(); + QStringList header; std::vector inputs = gate->get_input_pin_names(); std::vector outputs = gate->get_output_pin_names(); - auto truthTable = boolFunc.compute_truth_table(inputs, false).get().at(0); - - for (uint column = 0; column < inputs.size(); column++) { - - QTableWidgetItem* item = new QTableWidgetItem(QString::fromStdString(inputs[column])); - mTableWidget->setItem(0, column, item); - } - for (uint column = inputs.size(); column < outputs.size()+inputs.size(); column++) { + for (const std::string& inputPinName : inputs) + header << "Input\n" + QString::fromStdString(inputPinName); + for (const std::string& outputPinName : outputs) + header << "Output\n" + QString::fromStdString(outputPinName); + mTableWidget->setHorizontalHeaderLabels(header); - QTableWidgetItem* item = new QTableWidgetItem(QString::fromStdString(outputs[column-inputs.size()])); - mTableWidget->setItem(0, column, item); - } + auto truthTable = boolFunc.compute_truth_table(inputs, false).get().at(0); - for (uint truthTableIdx = 0; truthTableIdx < truthTable.size(); truthTableIdx++) + for (uint irow = 0; irow < truthTable.size(); irow++) { //iterate from 0..0 to 1..1 - for (uint i = 0; i < gate->get_input_pins().size(); i++) + for (uint icol = 0; icol < gate->get_input_pins().size(); icol++) { - u32 shift = gate->get_input_pins().size() - i - 1; - u8 inputBit = u8((truthTableIdx >> shift) & 1); - if(inputBit == 0) - { - QTableWidgetItem* item = new QTableWidgetItem("L"); - mTableWidget->setItem(truthTableIdx+1, i, item); - } - else - { - QTableWidgetItem* item = new QTableWidgetItem("H"); - mTableWidget->setItem(truthTableIdx+1, i, item); - } - - + u8 inputBit = u8((irow >> icol) & 1); + QTableWidgetItem* item = new QTableWidgetItem(inputBit ? "H" : "L"); + mTableWidget->setItem(irow, icol, item); } + //fill the output columns - for (int i = gate->get_input_pins().size(); i < gate->get_output_pins().size()+gate->get_input_pins().size(); i++) + for (uint icol = gate->get_input_pins().size(); icol < gate->get_output_pins().size()+gate->get_input_pins().size(); icol++) { - BooleanFunction::Value val = truthTable[truthTableIdx]; + BooleanFunction::Value val = truthTable[irow]; if (val == BooleanFunction::Value::ZERO) { QTableWidgetItem* item = new QTableWidgetItem("L"); - mTableWidget->setItem(truthTableIdx+1, i, item); + mTableWidget->setItem(irow, icol, item); } else if (val == BooleanFunction::Value::ONE) { QTableWidgetItem* item = new QTableWidgetItem("H"); - mTableWidget->setItem(truthTableIdx+1, i, item); + mTableWidget->setItem(irow, icol, item); } else if (val == BooleanFunction::Value::Z) { QTableWidgetItem* item = new QTableWidgetItem("Z"); - mTableWidget->setItem(truthTableIdx+1, i, item); + mTableWidget->setItem(irow, icol, item); } else { QTableWidgetItem* item = new QTableWidgetItem("X"); - mTableWidget->setItem(truthTableIdx+1, i, item); + mTableWidget->setItem(irow, icol, item); undefinedResult = true; } } @@ -125,7 +115,7 @@ namespace hal int GateLibraryTabTruthTable::getRowNumber(GateType* gate) { - return pow(2, gate->get_input_pins().size())+1; //iterate from 0..0 to 2^n + return pow(2, gate->get_input_pins().size()); //iterate from 0..0 to 2^n } int GateLibraryTabTruthTable::getColumnNumber(GateType* gate) @@ -136,5 +126,4 @@ namespace hal } return 0; } - } diff --git a/tests/netlist/module.cpp b/tests/netlist/module.cpp index a117838f640..1c85e69f817 100644 --- a/tests/netlist/module.cpp +++ b/tests/netlist/module.cpp @@ -1293,20 +1293,8 @@ namespace hal { // Trigger the event trigger_event[event_idx](); - Gate* gg = test_nl->get_gate_by_id(MIN_GATE_ID); - Module* mm = test_mod; - if (gg && mm) - { - for (ModulePin* mp : mm->get_pins()) - std::cerr << "Module pin " << mp->get_id() << " <" << mp->get_name() << ">" << std::endl; - for (Endpoint* ep : gg->get_fan_in_endpoints()) - std::cerr << "Gate in pin " << ep->get_pin()->get_id() << " <" << ep->get_pin()->get_name() << ">" << std::endl; - for (Endpoint* ep : gg->get_fan_out_endpoints()) - std::cerr << "Gate out pin " << ep->get_pin()->get_id() << " <" << ep->get_pin()->get_name() << ">" << std::endl; - } EXPECT_EQ(listener.get_event_count(), 1); - std::cerr << "Event " << event_idx << " <" << std::get<2>(listener.get_last_parameters()) << "> exp=<" << std::get<2>(expected_parameter[event_idx]) << ">" << std::endl; EXPECT_EQ(listener.get_last_parameters(), expected_parameter[event_idx]); // Unregister the callback