v1.8: 仍然存在各种BUG

This commit is contained in:
YuhangQ 2023-08-22 07:06:18 +00:00
parent 5ba2dbde89
commit dcc8a7262b
4 changed files with 66 additions and 33 deletions

View File

@ -122,15 +122,51 @@ int Gate::cal_value() {
return res; return res;
} }
int Gate::lut_get_value() { void Gate::cal_fault_info(int fd[2], int fpl[2]) {
return parent_lut->fault_table[id_in_lut][parent_lut->input_var<<1|parent_lut->value].value; 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) { std::vector<Gate*> affectd;
LUT::FaultInfo &info = parent_lut->fault_table[id_in_lut][parent_lut->input_var<<1|parent_lut->value]; std::unordered_map<Gate*, int> gate_level;
fd[0] = info.fd[0] && parent_lut->fd[!parent_lut->value]; std::priority_queue<Gate*, std::vector<Gate*>,
fd[1] = info.fd[1] && parent_lut->fd[!parent_lut->value]; std::function<bool(Gate*, Gate*)>> q([](Gate* p1, Gate* p2) {
fpl[0] = info.fpl[0] + info.fd[0] * parent_lut->fpl[!parent_lut->value]; return p1->id < p2->id;
fpl[1] = info.fpl[1] + info.fd[1] * parent_lut->fpl[!parent_lut->value]; });
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;
} }

View File

@ -52,8 +52,7 @@ public:
int is_stem; int is_stem;
int lut_get_value(); void cal_fault_info(int fd[2], int fpl[2]);
void lut_get_fault(int *fd, int *fpl);
// ( partical ) score // ( partical ) score

View File

@ -157,13 +157,13 @@ void LUTCircuit::ls_main() {
// } // }
if(g->is_stem) { 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, 0, 1, 0});
faults.push(TMP_FAULT{g, name, 1, 1, 0}); faults.push(TMP_FAULT{g, name, 1, 1, 0});
} else { } else {
if(g->isPO) { 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, 0, g->type != Gate::LINE, g->type == Gate::LINE});
faults.push(TMP_FAULT{g, name, 1, g->type != Gate::LINE, g->type == Gate::LINE}); faults.push(TMP_FAULT{g, name, 1, g->type != Gate::LINE, g->type == Gate::LINE});
continue; continue;
@ -286,16 +286,8 @@ void LUTCircuit::ls_main() {
int score; int score;
simulator->simulate(PIs, score, fault_detected); simulator->simulate(PIs, score, fault_detected);
if(g->name == "G6") {
simulator->print();
}
if(simulator->name2gate[g->name]->fault_detected[stuck_at]) { if(simulator->name2gate[g->name]->fault_detected[stuck_at]) {
printf(" successful!\n"); printf(" successful!\n");
} else {
printf(" failed!\n");
// exit(-1);
}
for(LUT* lut : luts) { for(LUT* lut : luts) {
lut->input_var = 0; lut->input_var = 0;
@ -310,6 +302,12 @@ void LUTCircuit::ls_main() {
int res = simulator->verify(this, fault_detected); int res = simulator->verify(this, fault_detected);
assert(res == 1); assert(res == 1);
} else {
printf(" failed!\n");
simulator->name2gate[g->name]->fault_detected[stuck_at] = 1;
// exit(-1);
}
// printf("g: %s\n", g->name.c_str()); // printf("g: %s\n", g->name.c_str());
// assert(simulator->name2gate[g->name]->fault_detected[stuck_at]); // assert(simulator->name2gate[g->name]->fault_detected[stuck_at]);

View File

@ -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]); // 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(info.value == sim_g->value);
// assert(t_fd[0] == sim_g->fault_detected[0]); assert(t_fd[0] == sim_g->fault_detected[0]);
// assert(t_fd[1] == sim_g->fault_detected[1]); assert(t_fd[1] == sim_g->fault_detected[1]);
// assert(t_fpl[0] == sim_g->fault_propagated_len[0]); // assert(t_fpl[0] == sim_g->fault_propagated_len[0]);
// assert(t_fpl[1] == sim_g->fault_propagated_len[1]); // assert(t_fpl[1] == sim_g->fault_propagated_len[1]);
} }