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;
}
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<Gate*> affectd;
std::unordered_map<Gate*, int> gate_level;
std::priority_queue<Gate*, std::vector<Gate*>,
std::function<bool(Gate*, Gate*)>> 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;
}

View File

@ -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

View File

@ -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; i<lut->fanins.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; i<lut->fanins.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]);

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]);
// }
// 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]);
}