From dcc8a7262b59c8e3b2349cf568ad2ff92e2a37ad Mon Sep 17 00:00:00 2001 From: YuhangQ Date: Tue, 22 Aug 2023 07:06:18 +0000 Subject: [PATCH] =?UTF-8?q?v1.8:=20=E4=BB=8D=E7=84=B6=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E5=90=84=E7=A7=8DBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gate.cpp | 54 +++++++++++++++++++++++++++++++++++++++-------- src/gate.h | 3 +-- src/ls.cpp | 36 +++++++++++++++---------------- src/simulator.cpp | 6 +++--- 4 files changed, 66 insertions(+), 33 deletions(-) diff --git a/src/gate.cpp b/src/gate.cpp index ba41cc2..c1cdc70 100644 --- a/src/gate.cpp +++ b/src/gate.cpp @@ -122,15 +122,51 @@ int Gate::cal_value() { return res; } -int Gate::lut_get_value() { - return parent_lut->fault_table[id_in_lut][parent_lut->input_var<<1|parent_lut->value].value; -} +void Gate::cal_fault_info(int fd[2], int fpl[2]) { + if(isPO) { + fd[!value] = 1; + fd[value] = 0; + fpl[!value] = 0; + fpl[value] = 0; + return; + } + value ^= 1; -void Gate::lut_get_fault(int *fd, int *fpl) { - LUT::FaultInfo &info = parent_lut->fault_table[id_in_lut][parent_lut->input_var<<1|parent_lut->value]; - fd[0] = info.fd[0] && parent_lut->fd[!parent_lut->value]; - fd[1] = info.fd[1] && parent_lut->fd[!parent_lut->value]; - fpl[0] = info.fpl[0] + info.fd[0] * parent_lut->fpl[!parent_lut->value]; - fpl[1] = info.fpl[1] + info.fd[1] * parent_lut->fpl[!parent_lut->value]; + std::vector affectd; + std::unordered_map gate_level; + std::priority_queue, + std::function> q([](Gate* p1, Gate* p2) { + return p1->id < p2->id; + }); + + for(Gate* out : fanouts) { + if(out->value != out->cal_value()) { + out->value ^= 1; + gate_level[out] = 1; + affectd.push_back(out); + q.push(out); + } + } + + while(!q.empty()) { + Gate* cur = q.top(); q.pop(); + for(Gate* out : cur->fanouts) { + if(out->value != out->cal_value()) { + out->value ^= 1; + gate_level[out] = std::max(gate_level[out], gate_level[cur] + 1); + affectd.push_back(out); + q.push(out); + } + } + } + + for(Gate* gate : affectd) { + fault_detected[value] |= gate->fault_detected[gate->value]; + fault_propagated_len[value] = std::max(fpl[value], gate_level[gate] + gate->fault_propagated_len[gate->value]); + + gate->value ^= 1; + } + + value ^= 1; } \ No newline at end of file diff --git a/src/gate.h b/src/gate.h index 28e9cf3..1b85eb1 100644 --- a/src/gate.h +++ b/src/gate.h @@ -52,8 +52,7 @@ public: int is_stem; - int lut_get_value(); - void lut_get_fault(int *fd, int *fpl); + void cal_fault_info(int fd[2], int fpl[2]); // ( partical ) score diff --git a/src/ls.cpp b/src/ls.cpp index 47041fd..95ed632 100644 --- a/src/ls.cpp +++ b/src/ls.cpp @@ -157,13 +157,13 @@ void LUTCircuit::ls_main() { // } if(g->is_stem) { - printf("stem: %s\n", name.c_str()); + // printf("stem: %s\n", name.c_str()); faults.push(TMP_FAULT{g, name, 0, 1, 0}); faults.push(TMP_FAULT{g, name, 1, 1, 0}); } else { if(g->isPO) { - printf("out: %s\n", name.c_str()); + // printf("out: %s\n", name.c_str()); faults.push(TMP_FAULT{g, name, 0, g->type != Gate::LINE, g->type == Gate::LINE}); faults.push(TMP_FAULT{g, name, 1, g->type != Gate::LINE, g->type == Gate::LINE}); continue; @@ -286,30 +286,28 @@ void LUTCircuit::ls_main() { int score; simulator->simulate(PIs, score, fault_detected); - if(g->name == "G6") { - simulator->print(); - } - if(simulator->name2gate[g->name]->fault_detected[stuck_at]) { printf(" successful!\n"); + + for(LUT* lut : luts) { + lut->input_var = 0; + for(int i=0; ifanins.size(); i++) { + LUT* in = lut->fanins[i]; + lut->input_var |= (in->value << i); + } + } + + ls_gen_sol(g, stuck_at); + + int res = simulator->verify(this, fault_detected); + assert(res == 1); + } else { printf(" failed!\n"); + simulator->name2gate[g->name]->fault_detected[stuck_at] = 1; // exit(-1); } - for(LUT* lut : luts) { - lut->input_var = 0; - for(int i=0; ifanins.size(); i++) { - LUT* in = lut->fanins[i]; - lut->input_var |= (in->value << i); - } - } - - ls_gen_sol(g, stuck_at); - - int res = simulator->verify(this, fault_detected); - assert(res == 1); - // printf("g: %s\n", g->name.c_str()); // assert(simulator->name2gate[g->name]->fault_detected[stuck_at]); diff --git a/src/simulator.cpp b/src/simulator.cpp index 69a8167..ad95b01 100644 --- a/src/simulator.cpp +++ b/src/simulator.cpp @@ -70,9 +70,9 @@ int Simulator::verify(LUTCircuit *lut_circuit, int** fault_detected) { // printf("s_fd[0]: %d, s_fd[1]: %d, s_fpl[0]: %d, s_fpl[1]: %d\n\n", sim_g->fault_detected[0], sim_g->fault_detected[1], sim_g->fault_propagated_len[0], sim_g->fault_propagated_len[1]); // } - // assert(info.value == sim_g->value); - // assert(t_fd[0] == sim_g->fault_detected[0]); - // assert(t_fd[1] == sim_g->fault_detected[1]); + assert(info.value == sim_g->value); + assert(t_fd[0] == sim_g->fault_detected[0]); + assert(t_fd[1] == sim_g->fault_detected[1]); // assert(t_fpl[0] == sim_g->fault_propagated_len[0]); // assert(t_fpl[1] == sim_g->fault_propagated_len[1]); }