From 9fdc584fe67a0b0bf72cf3d6e0ebcef1ca28698c Mon Sep 17 00:00:00 2001
From: YuhangQ
Date: Sat, 11 Nov 2023 04:20:22 +0000
Subject: [PATCH] newc
---
.gitignore | 0
.vscode/c_cpp_properties.json | 0
.vscode/launch.json | 0
.vscode/settings.json | 3 +-
.vscode/tasks.json | 0
CMakeLists.txt | 0
README.md | 0
benchmark/b01.bench | 0
benchmark/b03.bench | 0
benchmark/b04.bench | 0
benchmark/b06.bench | 0
benchmark/b07.bench | 0
benchmark/b08.bench | 0
benchmark/b09.bench | 0
benchmark/b10.bench | 0
benchmark/b11.bench | 0
benchmark/b12.bench | 0
benchmark/b13.bench | 0
benchmark/b17.bench | 0
benchmark/b20.bench | 0
benchmark/b21.bench | 0
benchmark/b22.bench | 0
benchmark/c1355.bench | 0
benchmark/c17.bench | 0
benchmark/c1908.bench | 0
benchmark/c2670.bench | 0
benchmark/c3540.bench | 0
benchmark/c432.bench | 0
benchmark/c499.bench | 0
benchmark/c5315.bench | 0
benchmark/c6288.bench | 0
benchmark/c7552.bench | 0
benchmark/c880.bench | 0
report/atalanta_b10000_iscas85.txt | 0
report/atalanta_b1000_itc99.txt | 0
report/atalanta_b20_itc99.txt | 0
report/atalanta_itc99.txt | 0
report/atpg-ls-动态增量-仿真.txt | 0
report/atpg-ls-动态增量.txt | 0
report/atpg-ls.txt | 0
report/tgpro_iscas85.txt | 0
report/tgpro_itc99.txt | 0
report/tgpro_itc99_cutoff1000.txt | 0
src/CMakeLists.txt | 0
src/checker.cpp | 16 +-
src/checker.h | 4 +-
src/circuit.cpp | 500 ++++++-------
src/circuit.h | 68 +-
src/cmdline.h | 0
src/fault.h | 15 +
src/gate.cpp | 2 +
src/gate.h | 31 +-
src/ls.cpp | 770 ++++++++------------
src/lut.cpp | 205 ------
src/lut.h | 78 --
src/main.cpp | 26 +-
src/paras.cpp | 0
src/paras.h | 0
src/parse.cpp | 0
src/pattern.h | 2 +-
src/sat_atpg.cpp | 5 +-
src/sat_atpg.h | 0
src/score.cpp | 143 +---
src/simulator.cpp | 94 +--
src/simulator.h | 4 +-
test.txt | 1086 ++++++++++++++++++++++++++++
66 files changed, 1776 insertions(+), 1276 deletions(-)
mode change 100644 => 100755 .gitignore
mode change 100644 => 100755 .vscode/c_cpp_properties.json
mode change 100644 => 100755 .vscode/launch.json
mode change 100644 => 100755 .vscode/settings.json
mode change 100644 => 100755 .vscode/tasks.json
mode change 100644 => 100755 CMakeLists.txt
mode change 100644 => 100755 README.md
mode change 100644 => 100755 benchmark/b01.bench
mode change 100644 => 100755 benchmark/b03.bench
mode change 100644 => 100755 benchmark/b04.bench
mode change 100644 => 100755 benchmark/b06.bench
mode change 100644 => 100755 benchmark/b07.bench
mode change 100644 => 100755 benchmark/b08.bench
mode change 100644 => 100755 benchmark/b09.bench
mode change 100644 => 100755 benchmark/b10.bench
mode change 100644 => 100755 benchmark/b11.bench
mode change 100644 => 100755 benchmark/b12.bench
mode change 100644 => 100755 benchmark/b13.bench
mode change 100644 => 100755 benchmark/b17.bench
mode change 100644 => 100755 benchmark/b20.bench
mode change 100644 => 100755 benchmark/b21.bench
mode change 100644 => 100755 benchmark/b22.bench
mode change 100644 => 100755 benchmark/c1355.bench
mode change 100644 => 100755 benchmark/c17.bench
mode change 100644 => 100755 benchmark/c1908.bench
mode change 100644 => 100755 benchmark/c2670.bench
mode change 100644 => 100755 benchmark/c3540.bench
mode change 100644 => 100755 benchmark/c432.bench
mode change 100644 => 100755 benchmark/c499.bench
mode change 100644 => 100755 benchmark/c5315.bench
mode change 100644 => 100755 benchmark/c6288.bench
mode change 100644 => 100755 benchmark/c7552.bench
mode change 100644 => 100755 benchmark/c880.bench
mode change 100644 => 100755 report/atalanta_b10000_iscas85.txt
mode change 100644 => 100755 report/atalanta_b1000_itc99.txt
mode change 100644 => 100755 report/atalanta_b20_itc99.txt
mode change 100644 => 100755 report/atalanta_itc99.txt
mode change 100644 => 100755 report/atpg-ls-动态增量-仿真.txt
mode change 100644 => 100755 report/atpg-ls-动态增量.txt
mode change 100644 => 100755 report/atpg-ls.txt
mode change 100644 => 100755 report/tgpro_iscas85.txt
mode change 100644 => 100755 report/tgpro_itc99.txt
mode change 100644 => 100755 report/tgpro_itc99_cutoff1000.txt
mode change 100644 => 100755 src/CMakeLists.txt
mode change 100644 => 100755 src/checker.cpp
mode change 100644 => 100755 src/checker.h
mode change 100644 => 100755 src/circuit.cpp
mode change 100644 => 100755 src/circuit.h
mode change 100644 => 100755 src/cmdline.h
mode change 100644 => 100755 src/fault.h
mode change 100644 => 100755 src/gate.cpp
mode change 100644 => 100755 src/gate.h
mode change 100644 => 100755 src/ls.cpp
delete mode 100644 src/lut.cpp
delete mode 100644 src/lut.h
mode change 100644 => 100755 src/main.cpp
mode change 100644 => 100755 src/paras.cpp
mode change 100644 => 100755 src/paras.h
mode change 100644 => 100755 src/parse.cpp
mode change 100644 => 100755 src/pattern.h
mode change 100644 => 100755 src/sat_atpg.cpp
mode change 100644 => 100755 src/sat_atpg.h
mode change 100644 => 100755 src/score.cpp
mode change 100644 => 100755 src/simulator.cpp
mode change 100644 => 100755 src/simulator.h
create mode 100755 test.txt
diff --git a/.gitignore b/.gitignore
old mode 100644
new mode 100755
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
old mode 100644
new mode 100755
diff --git a/.vscode/launch.json b/.vscode/launch.json
old mode 100644
new mode 100755
diff --git a/.vscode/settings.json b/.vscode/settings.json
old mode 100644
new mode 100755
index 6b25936..269d781
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -90,6 +90,7 @@
"csignal": "cpp",
"strstream": "cpp",
"codecvt": "cpp",
- "cfenv": "cpp"
+ "cfenv": "cpp",
+ "*.ipp": "cpp"
}
}
\ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
old mode 100644
new mode 100755
diff --git a/CMakeLists.txt b/CMakeLists.txt
old mode 100644
new mode 100755
diff --git a/README.md b/README.md
old mode 100644
new mode 100755
diff --git a/benchmark/b01.bench b/benchmark/b01.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b03.bench b/benchmark/b03.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b04.bench b/benchmark/b04.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b06.bench b/benchmark/b06.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b07.bench b/benchmark/b07.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b08.bench b/benchmark/b08.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b09.bench b/benchmark/b09.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b10.bench b/benchmark/b10.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b11.bench b/benchmark/b11.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b12.bench b/benchmark/b12.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b13.bench b/benchmark/b13.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b17.bench b/benchmark/b17.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b20.bench b/benchmark/b20.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b21.bench b/benchmark/b21.bench
old mode 100644
new mode 100755
diff --git a/benchmark/b22.bench b/benchmark/b22.bench
old mode 100644
new mode 100755
diff --git a/benchmark/c1355.bench b/benchmark/c1355.bench
old mode 100644
new mode 100755
diff --git a/benchmark/c17.bench b/benchmark/c17.bench
old mode 100644
new mode 100755
diff --git a/benchmark/c1908.bench b/benchmark/c1908.bench
old mode 100644
new mode 100755
diff --git a/benchmark/c2670.bench b/benchmark/c2670.bench
old mode 100644
new mode 100755
diff --git a/benchmark/c3540.bench b/benchmark/c3540.bench
old mode 100644
new mode 100755
diff --git a/benchmark/c432.bench b/benchmark/c432.bench
old mode 100644
new mode 100755
diff --git a/benchmark/c499.bench b/benchmark/c499.bench
old mode 100644
new mode 100755
diff --git a/benchmark/c5315.bench b/benchmark/c5315.bench
old mode 100644
new mode 100755
diff --git a/benchmark/c6288.bench b/benchmark/c6288.bench
old mode 100644
new mode 100755
diff --git a/benchmark/c7552.bench b/benchmark/c7552.bench
old mode 100644
new mode 100755
diff --git a/benchmark/c880.bench b/benchmark/c880.bench
old mode 100644
new mode 100755
diff --git a/report/atalanta_b10000_iscas85.txt b/report/atalanta_b10000_iscas85.txt
old mode 100644
new mode 100755
diff --git a/report/atalanta_b1000_itc99.txt b/report/atalanta_b1000_itc99.txt
old mode 100644
new mode 100755
diff --git a/report/atalanta_b20_itc99.txt b/report/atalanta_b20_itc99.txt
old mode 100644
new mode 100755
diff --git a/report/atalanta_itc99.txt b/report/atalanta_itc99.txt
old mode 100644
new mode 100755
diff --git a/report/atpg-ls-动态增量-仿真.txt b/report/atpg-ls-动态增量-仿真.txt
old mode 100644
new mode 100755
diff --git a/report/atpg-ls-动态增量.txt b/report/atpg-ls-动态增量.txt
old mode 100644
new mode 100755
diff --git a/report/atpg-ls.txt b/report/atpg-ls.txt
old mode 100644
new mode 100755
diff --git a/report/tgpro_iscas85.txt b/report/tgpro_iscas85.txt
old mode 100644
new mode 100755
diff --git a/report/tgpro_itc99.txt b/report/tgpro_itc99.txt
old mode 100644
new mode 100755
diff --git a/report/tgpro_itc99_cutoff1000.txt b/report/tgpro_itc99_cutoff1000.txt
old mode 100644
new mode 100755
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
old mode 100644
new mode 100755
diff --git a/src/checker.cpp b/src/checker.cpp
old mode 100644
new mode 100755
index b40fe1a..6ffefe3
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -8,7 +8,7 @@ namespace atpg_ls {
Circuit *right_circuit;
Circuit *wrong_circuit;
-int check_fault(const Pattern &p, const TMP_FAULT &f) {
+int check_fault(const Pattern &p, const Fault &f) {
for(int i=0; i
PIs[i]->value = p.input_vector[i];
wrong_circuit->PIs[i]->value = p.input_vector[i];
@@ -19,7 +19,7 @@ int check_fault(const Pattern &p, const TMP_FAULT &f) {
}
for(Gate* gate : wrong_circuit->gates) {
- if(gate->name == f.g->name) {
+ if(gate->name == f.gate->name) {
gate->value = f.stuck_at;
continue;
}
@@ -34,14 +34,14 @@ int check_fault(const Pattern &p, const TMP_FAULT &f) {
return false;
}
-int final_check(const std::set &faults, const std::vector &patterns) {
+int final_check(const std::set &faults, const std::vector &patterns) {
- std::set detected_faults;
+ std::set detected_faults;
for(auto &p : patterns) {
for(auto &f : p.detected_faults) {
- printf("checking fault %s %d ... ", f.g->name.c_str(), f.stuck_at);
+ // printf("checking fault %s %d ... ", f.g->name.c_str(), f.stuck_at);
assert(faults.count(f));
assert(detected_faults.count(f) == 0);
@@ -56,16 +56,16 @@ int final_check(const std::set &faults, const std::vector &p
int detected = check_fault(p, f);
if(detected) {
- printf("detected\n");
+ // printf("detected\n");
detected_faults.insert(f);
} else {
- printf("undetected\n");
+ // printf("undetected\n");
assert(false);
}
}
}
- printf("final coverage: %d/%d(%.2f) pattern: %d\n", detected_faults.size(), faults.size(), (double)detected_faults.size()/faults.size(), patterns.size());
+ printf("final coverage: (%.2f)%d/%d pattern: %d\n", (double)detected_faults.size()/faults.size() * 100,detected_faults.size(), faults.size(), , patterns.size());
return 1;
}
diff --git a/src/checker.h b/src/checker.h
old mode 100644
new mode 100755
index 517f000..ff3869c
--- a/src/checker.h
+++ b/src/checker.h
@@ -8,8 +8,8 @@
namespace atpg_ls {
-int check_fault(const Pattern &p, const TMP_FAULT &f);
-int final_check(const std::set &faults, const std::vector &patterns);
+int check_fault(const Pattern &p, const Fault &f);
+int final_check(const std::set &faults, const std::vector &patterns);
void init_final_checker();
};
diff --git a/src/circuit.cpp b/src/circuit.cpp
old mode 100644
new mode 100755
index 52ce829..fb6f191
--- a/src/circuit.cpp
+++ b/src/circuit.cpp
@@ -1,159 +1,230 @@
#include
#include
+#include
#include "circuit.h"
+#include "simulator.h"
#include "paras.h"
using namespace atpg_ls;
-void LUTCircuit::print() {
-
- std::set st;
-
- int total_gate = 0;
-
- printf("PIs: ( ");
- for(LUT* lut : PIs) {
- printf("%s ", lut->gate->name.c_str());
- }
- printf(")\n");
- printf("POs: ( ");
- for(LUT* lut : POs) {
- printf("%s ", lut->gate->name.c_str());
- }
- printf(")\n");
-
-
-
- for(LUT* lut : luts) {
-
- printf("[v:%d vs:%d fd0:%d fd1:%d] ", lut->value, lut->vsat, lut->fd[0], lut->fd[1]);
- printf("lut: %s inputs: ( ", lut->gate->name.c_str());
-
- total_gate += lut->inner_gates.size();
-
- for(LUT* in : lut->fanins) {
- printf("%s ", in->gate->name.c_str());
- }
- printf(")\n");
- }
-
- printf("total gate: %d\n", total_gate);
+std::string gen_name() {
+ static int i = 0;
+ return "E" + std::to_string(++i);
}
+Gate* create_not_gate(Gate* gate) {
+ Gate* not_gate = new Gate();
+ not_gate->name = gen_name();
+ not_gate->is_extra_gate = 1;
+ not_gate->type = Gate::NOT;
+ not_gate->fanins.push_back(gate);
+ gate->fanouts.push_back(not_gate);
+ return not_gate;
+}
+void Circuit::rebuild_atpg_circuit() {
+ int sz = gates.size();
+ assert(sz == simulator->gates.size());
+ for(Gate* gate : rtopo_gates) {
-LUTCircuit* Circuit::build_lut_circuit() {
+ // 对于 PO 直接可以输出 SA0 = value 和 SA1 = NOT(value)
+ if(gate->isPO) {
+ Gate* extra_gate0 = new Gate();
+ extra_gate0->type = Gate::BUF;
+ extra_gate0->fanins.push_back(gate);
+ gate->fanouts.push_back(extra_gate0);
+ extra_gate0->is_extra_gate = 1;
+ gates.push_back(extra_gate0);
+ extra_gate0->name = "SA0_" + gate->name;
- LUTCircuit* C = new LUTCircuit();
- C->C = this;
+ Gate* extra_gate1 = new Gate();
+ extra_gate1->type = Gate::NOT;
+ extra_gate1->fanins.push_back(gate);
+ gate->fanouts.push_back(extra_gate1);
+ extra_gate1->is_extra_gate = 1;
+ gates.push_back(extra_gate1);
+ extra_gate1->name = "SA1_" + gate->name;
- std::unordered_map gate2LUT;
+ // gate->isPO = false;
- std::queue q;
- std::set done;
-
- for(Gate* gate : gates) {
- // assert fanouts >= 2
- if(gate->fanouts.size() >= 2 || gate->isPI || (gate->isPO && gate->fanouts.size() == 0)) {
- q.push(gate);
- done.insert(gate);
+ gate->stuck_at_gate[0] = extra_gate0;
+ gate->stuck_at_gate[1] = extra_gate1;
+ continue;
}
- }
- while(!q.empty()) {
- Gate* gate = q.front();
- q.pop();
+ // create a gate for SA_i
- LUT* lut = new LUT(gate, C);
-
- gate2LUT[gate] = lut;
-
- // printf("size: %d lut: %s inputs: ( ", lut->inner_gates.size(), lut->gate->name.c_str());
- // for(Gate* in : lut->__gate_fanins) {
- // printf("%s ", in->name.c_str());
- // }
- // printf(") [");
+ std::vector or_inputs;
- // for(Gate* inner : lut->inner_gates) {
- // printf("%s ", inner->name.c_str());
- // }
- // printf("]\n");
+ for(Gate *out : gate->fanouts) {
- for(Gate* in : lut->__gate_fanins) {
- if(in->fanouts.size() < 2 && !in->isPI && done.count(in) == 0) {
- done.insert(in);
- q.push(in);
+ if(out->is_extra_gate) continue;
+
+ // if the fault SA(!out->value) can be detected
+ Gate* out_detected = new Gate();
+ out_detected->name = gen_name();
+ out_detected->is_extra_gate = 1;
+ out_detected->type = Gate::OR;
+ out_detected->fanins.push_back(out->stuck_at_gate[0]);
+ out_detected->fanins.push_back(out->stuck_at_gate[1]);
+
+ assert(out->stuck_at_gate[0]);
+ assert(out->stuck_at_gate[1]);
+
+ out->stuck_at_gate[0]->fanouts.push_back(out_detected);
+ out->stuck_at_gate[1]->fanouts.push_back(out_detected);
+
+ gates.push_back(out_detected);
+
+ if(out->type == Gate::XOR || out->type == Gate::XNOR || out->type == Gate::NOT || out->type == Gate::BUF || out->type == Gate::LINE) {
+ or_inputs.push_back(out_detected);
+ continue;
+ }
+
+ Gate *extra_gate = new Gate();
+ extra_gate->is_extra_gate = 1;
+ extra_gate->type = Gate::AND;
+ extra_gate->name = gen_name();
+ gates.push_back(extra_gate);
+
+
+ for(Gate *in_of_out : out->fanins) {
+ if(in_of_out == gate) continue;
+
+ if(out->type == Gate::AND || out->type == Gate::NAND) {
+
+ in_of_out->fanouts.push_back(extra_gate);
+ extra_gate->fanins.push_back(in_of_out);
+
+ } else if(out->type == Gate::OR || out->type == Gate::NOR) {
+
+ Gate* not_gate = create_not_gate(in_of_out);
+ not_gate->name = gen_name();
+ gates.push_back(not_gate);
+ not_gate->fanouts.push_back(extra_gate);
+ extra_gate->fanins.push_back(not_gate);
+
+ } else {
+ assert(0);
+ }
+ }
+
+ extra_gate->fanins.push_back(out_detected);
+ out_detected->fanouts.push_back(extra_gate);
+
+ or_inputs.push_back(extra_gate);
+ }
+
+ Gate* or_gate;
+ if(or_inputs.size() == 1) {
+ or_gate = or_inputs[0];
+ } else {
+ or_gate = new Gate();
+ gates.push_back(or_gate);
+ or_gate->name = gen_name();
+ or_gate->is_extra_gate = 1;
+ or_gate->type = Gate::OR;
+ for(Gate* in : or_inputs) {
+ or_gate->fanins.push_back(in);
+ in->fanouts.push_back(or_gate);
}
}
- C->luts.push_back(lut);
+ Gate* p_sa0 = new Gate();
+ gates.push_back(p_sa0);
+ p_sa0->is_extra_gate = 1;
+ p_sa0->type = Gate::AND;
+ p_sa0->fanins.push_back(or_gate);
+ p_sa0->fanins.push_back(gate);
+ or_gate->fanouts.push_back(p_sa0);
+ gate->fanouts.push_back(p_sa0);
+
+ Gate* p_sa1 = new Gate();
+ gates.push_back(p_sa1);
+ p_sa1->is_extra_gate = 1;
+ p_sa1->type = Gate::AND;
+ p_sa1->fanins.push_back(or_gate);
+ or_gate->fanouts.push_back(p_sa1);
+
+ Gate* not_gate = create_not_gate(gate);
+ not_gate->name = gen_name();
+ gates.push_back(not_gate);
+
+ p_sa1->fanins.push_back(not_gate);
+ not_gate->fanouts.push_back(p_sa1);
+
+ gate->stuck_at_gate[0] = p_sa0;
+ gate->stuck_at_gate[1] = p_sa1;
+
+ p_sa0->name = "SA0_" + gate->name;
+ p_sa1->name = "SA1_" + gate->name;
}
- for(LUT* lut : C->luts) {
+ // for(Gate* po : POs) {
+ // po->isPO = false;
+ // }
+ // POs.clear();
- lut->name = lut->gate->name.c_str();
+ for(Gate* g : gates) {
+ if(g->is_extra_gate) continue;
+ assert(g->stuck_at_gate[0]);
+ assert(g->stuck_at_gate[1]);
- std::sort(lut->inner_gates.begin(), lut->inner_gates.end(), [](Gate* a, Gate* b) {
- return a->id < b->id;
- });
+ g->stuck_at_gate[0]->isPO = 1;
+ g->stuck_at_gate[1]->isPO = 1;
- for(Gate* in : lut->__gate_fanins) {
- assert(gate2LUT.count(in) > 0);
-
- lut->fanins.push_back(gate2LUT[in]);
- gate2LUT[in]->fanouts.push_back(lut);
- }
+ POs.push_back(g->stuck_at_gate[0]);
+ POs.push_back(g->stuck_at_gate[1]);
- if(lut->isPI) {
- C->PIs.push_back(lut);
- lut->isPI = 1;
- }
- if(lut->isPO) {
- C->POs.push_back(lut);
- lut->isPO = 1;
+ }
+
+ init_topo_index();
+
+ for(Gate* pi : PIs) {
+ pi->value = rand() % 2;
+ }
+
+ for(Gate* g : gates) {
+ g->value = g->cal_value();
+ }
+
+ for(Gate* g : rtopo_gates) {
+ if(g->is_extra_gate) continue;
+
+ g->fault_detected[0] = g->cal_fault_detected(0);
+ g->fault_detected[1] = g->cal_fault_detected(1);
+
+ assert(g->fault_detected[0] == g->stuck_at_gate[0]->value);
+ assert(g->fault_detected[1] == g->stuck_at_gate[1]->value);
+ }
+
+ for(Gate* g : gates) {
+ if(g->is_extra_gate) continue;
+ original_gates.push_back(g);
+ }
+
+ for(int i=0; iindex = i;
+ simulator->name2gate[original_gates[i]->name]->index = i;
+ }
+
+ std::vector t_POs;
+
+ for(Gate* po : POs) {
+ if(po->is_extra_gate) {
+ t_POs.push_back(po);
}
}
- for(LUT* lut : C->luts) {
- C->rtopo_luts.push_back(lut);
- }
-
- std::sort(C->luts.begin(), C->luts.end(), [](LUT* a, LUT* b) {
- return a->gate->id < b->gate->id;
- });
-
- std::sort(C->rtopo_luts.begin(), C->rtopo_luts.end(), [](LUT* a, LUT* b) {
- return a->gate->rtopo < b->gate->rtopo;
- });
-
- for(LUT* lut : C->luts) {
- for(int i=0; iinner_gates.size(); i++) {
- Gate *g = lut->inner_gates[i];
- g->parent_lut = lut;
- g->id_in_lut = lut->fanins.size() + i;
- }
- }
-
- for(LUT* lut : C->luts) {
- for(int i=0; ifanins.size(); i++) {
- LUT* in = lut->fanins[i];
- in->fanouts_with_id.push_back(std::make_pair(lut, i));
- }
- }
-
- for(LUT* lut : C->luts) {
- assert(lut->fanouts.size() == lut->fanouts_with_id.size());
- }
-
- return C;
+ POs = t_POs;
+ assert(original_gates.size() * 2 == POs.size());
+ assert(original_gates.size() == sz);
}
-
-
void Circuit::insert_lines_for_stem() {
for(int j=0; jname, line));
}
- printf(">>>> now: %s\n", g->name.c_str());
+ // printf(">>>> now: %s\n", g->name.c_str());
- printf("outs: [ ");
- for(Gate* out :g->fanouts){
- printf("%s ", out->name.c_str());
- }
- printf("]\n");
+ // printf("outs: [ ");
+ // for(Gate* out :g->fanouts){
+ // printf("%s ", out->name.c_str());
+ // }
+ // printf("]\n");
for(int i=0; ifanouts.size(); i++) {
Gate* out = g->fanouts[i];
if(out->type == Gate::LINE) break;
- printf(" g_name: %s outname: %s\n", g->name.c_str(), out->name.c_str());
+ // printf(" g_name: %s outname: %s\n", g->name.c_str(), out->name.c_str());
Gate* line = new Gate();
line->name = g->name + "_line_" + out->name;
line->type = Gate::LINE;
line->isPI = false;
line->isPO = false;
+ line->is_stem = false;
line->fanins.push_back(g);
line->fanouts.push_back(out);
@@ -224,72 +296,6 @@ void Circuit::insert_lines_for_stem() {
}
-void Circuit::init_avg_dist() {
-
- int *now_dist = new int[gates.size() + 1] { 0 };
- int *total_dist = new int[gates.size() + 1] { 0 };
- int *total_cnt = new int[gates.size() + 1] { 0 };
- // int *topo_cnt = new int[gates.size() + 1] { 0 };
-
- // memset(total_dist, 0, sizeof(int) * (gates.size() + 1));
-
- for(Gate* po : POs) {
- // memset(topo_cnt, 0, sizeof(int) * (gates.size() + 1));
- // memset(now_dist, 0x3f, sizeof(int) * (gates.size() + 1));
- for(Gate* g : gates) {
- if(g->isPO) {
- now_dist[g->id] = 0;
- } else {
- now_dist[g->id] = 0x3f3f3f3f;
- }
- }
-
- // printf(">> po: %s\n", po->name.c_str());
-
- std::queue q;
- q.push(po);
-
- while(!q.empty()) {
- Gate* u = q.front(); q.pop();
-
- total_dist[u->id] += now_dist[u->id];
- total_cnt[u->id] ++;
-
- // printf("now: %s\n", u->name.c_str());
-
- for(Gate* in : u->fanins) {
- if(now_dist[u->id] + 1 < now_dist[in->id]) {
- now_dist[in->id] = now_dist[u->id] + 1;
- q.push(in);
- }
- }
-
- // printf("dist: %d\n", total_dist[name2gate["G132"]->id]);
- }
- }
-
- for(Gate* g : gates) {
-
- if(total_cnt[g->id] <= 0) {
- printf("ERROR: gate: %s total: %d cnt: %d\n", g->name.c_str(), total_dist[g->id], total_cnt[g->id]);
- exit(-1);
- }
-
- assert(total_cnt[g->id] > 0);
-
- g->avg_dist = total_dist[g->id] / total_cnt[g->id];
-
- printf("ERROR: gate: %s total: %d cnt: %d\n", g->name.c_str(), total_dist[g->id], total_cnt[g->id]);
-
- // if(g->id)
- if(!g->isPO) assert(g->avg_dist > 0);
- }
-
- delete [] now_dist;
- delete [] total_dist;
- delete [] total_cnt;
-}
-
void Circuit::init_topo_index() {
int topo = 1;
std::queue q;
@@ -315,6 +321,8 @@ void Circuit::init_topo_index() {
}
}
+ rtopo_gates.clear();
+
// 计算反向拓扑序
topo = 1;
std::unordered_map outs;
@@ -346,6 +354,8 @@ void Circuit::init_topo_index() {
}
}
+ assert(gates.size() == rtopo_gates.size());
+
std::sort(gates.begin(), gates.end(), [](Gate* a, Gate* b) {
return a->id < b->id;
});
@@ -362,8 +372,14 @@ void Circuit::print() {
const char *name[10] = {"AND", "NAND", "OR", "NOR", "XOR", "XNOR", "NOT", "BUF", "INPUT", "LINE"};
+
+
for(Gate* g : gates) {
- printf("[sa0: %d sa1: %d v: %d vsat: %d] %s = %s (",g->fault_detected[0], g->fault_detected[1], g->value, g->cal_value() == g->value, g->name.c_str(), name[g->type]);
+ std::string out_name = "unknown";
+ if(g->name != "") {
+ out_name = g->name;
+ }
+ printf("[sa0: %d sa1: %d v: %d vsat: %d] %s = %s (",g->fault_detected[0], g->fault_detected[1], g->value, g->cal_value() == g->value, out_name.c_str(), name[g->type]);
for(Gate* in : g->fanins) {
printf("%s ", in->name.c_str());
}
@@ -377,76 +393,64 @@ void Circuit::print() {
printf(")\n");
}
-double LUTCircuit::check() {
- // static bool init = 0;
- // static std::unordered_set dt;
- printf("checking circuit ...\n");
+void Circuit::init_faults() {
- double score_value_unsatisfied_cost = 0;
- double score_fault_detected_weight = 0;
- double score_fault_propagated_weight = 0;
- double score_fault_update_cost = 0;
- int unsatisfied_lut = 0;
+ int sz = gates.size();
+ assert(sz == simulator->gates.size());
+ for(int i=0; iname == simulator->gates[i]->name);
+ simulator->gates[i]->ori_gate = gates[i];
+ gates[i]->sim_gate = simulator->gates[i];
+ }
- for(LUT* lut : luts) {
- assert(lut->vsat == (lut->value == lut->cal_value()));
+ std::vector faults;
- if(!lut->vsat) {
- score_value_unsatisfied_cost += lut->vunat_cost;
- unsatisfied_lut++;
- // printf("vunsat: %s\n", lut->name);
- }
+ for(Gate* g : gates) {
- if(lut->uptag) {
- score_fault_update_cost += lut->up_cost;
+ std::string name = g->name;
+
+ if(g->is_stem) {
+ faults.push_back(TMP_FAULT{g, name, 0, 1, 0});
+ faults.push_back(TMP_FAULT{g, name, 1, 1, 0});
} else {
- int t_fd[2], t_fpl[2];
- lut->cal_fault_info(t_fd, t_fpl);
- assert(t_fd[0] == lut->fd[0]);
- assert(t_fd[1] == lut->fd[1]);
- assert(t_fpl[0] == lut->fpl[0]);
- assert(t_fpl[1] == lut->fpl[1]);
- }
- int input = 0;
- for(int i=0; ifanins.size(); i++) {
- input |= (lut->fanins[i]->value << i);
- }
- input <<= 1;
- input |= lut->value;
+ if(g->isPO) {
+ faults.push_back(TMP_FAULT{g, name, 0, g->type != Gate::LINE, g->type == Gate::LINE});
+ faults.push_back(TMP_FAULT{g, name, 1, g->type != Gate::LINE, g->type == Gate::LINE});
+ continue;
+ }
- for(int i=lut->fanins.size(); ifanins.size()+lut->inner_gates.size(); i++) {
- LUT::FaultInfo &info = lut->fault_table[i][input];
- Gate* g = lut->inner_gates[i-lut->fanins.size()];
-
- int t_fd[2], t_fpl[2];
- t_fd[0] = info.fd[0] && lut->fd[!lut->value];
- t_fd[1] = info.fd[1] && lut->fd[!lut->value];
- t_fpl[0] = info.fpl[0] + info.fd[0] * lut->fpl[!lut->value];
- t_fpl[1] = info.fpl[1] + info.fd[1] * lut->fpl[!lut->value];
+ assert(g->fanouts.size() == 1);
- score_fault_detected_weight += t_fd[0] * g->fault_detected_weight[0];
- score_fault_detected_weight += t_fd[1] * g->fault_detected_weight[1];
+ Gate *fanout = g->fanouts[0];
- if(!g->isPO) {
- score_fault_propagated_weight += (double)t_fpl[0] / g->avg_dist * g->fault_detected_weight[0];
- score_fault_propagated_weight += (double)t_fpl[1] / g->avg_dist * g->fault_detected_weight[1];
+ int stem = (!g->isPI) && (g->type != Gate::LINE);
+
+ if(fanout->type == Gate::Type::BUF || fanout->type == Gate::Type::NOT) {
+ continue;
+ } else if(fanout->type == Gate::Type::XOR || fanout->type == Gate::Type::XNOR) {
+ faults.push_back(TMP_FAULT{g, name, 0, stem, 0});
+ faults.push_back(TMP_FAULT{g, name, 1, stem, 0});
+ } else if(fanout->type == Gate::Type::NAND || fanout->type == Gate::Type::AND) {
+ faults.push_back(TMP_FAULT{g, name, 1, stem, 0});
+ } else if(fanout->type == Gate::Type::NOR || fanout->type == Gate::Type::OR) {
+ faults.push_back(TMP_FAULT{g, name, 0, stem, 0});
+ } else {
+ assert(false);
}
}
}
- printf("=====================================\n");
- printf("unsat_lut: %d\n", unsatisfied_lut);
- printf("score_value_unsatisfied_cost: %.2f\n", score_value_unsatisfied_cost);
- printf("score_fault_detected_weight: %.2f\n", score_fault_detected_weight);
- printf("score_fault_propagated_weight: %.2f\n", score_fault_propagated_weight);
- printf("score_fault_update_cost: %.2f\n", score_fault_update_cost);
-
- double score = - score_value_unsatisfied_cost + score_fault_detected_weight + score_fault_propagated_weight - score_fault_update_cost;
+ printf("fault-size: %d\n", faults.size());
- printf("score: %d\n", score);
+ for(TMP_FAULT &f : faults) {
+ mp[Fault{f.g, f.stuck_at}] = f;
+ this->faults.insert(Fault{f.g, f.stuck_at});
+ }
- return score;
+ this->unknown_faults = this->faults;
+
+ assert(faults.size() == mp.size());
}
\ No newline at end of file
diff --git a/src/circuit.h b/src/circuit.h
old mode 100644
new mode 100755
index 5951cd0..c55354f
--- a/src/circuit.h
+++ b/src/circuit.h
@@ -1,44 +1,15 @@
#pragma once
#include "fault.h"
-#include "lut.h"
+
+#include