Skip to content

Commit 62f1e65

Browse files
author
xinoip
committed
support for or nor and nand
1 parent 48988e8 commit 62f1e65

File tree

4 files changed

+125
-116
lines changed

4 files changed

+125
-116
lines changed

atpg_circuit.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,17 +315,20 @@ bool ATPGCircuit::has_conflict(std::string exclude_gate) {
315315
map_value = GateTables::gate_table_and[map_input];
316316
break;
317317
case ATPGCircuitElementType::NAND:
318-
// todo change this
319-
map_value = GateTables::gate_table_and[map_input];
318+
map_value = GateTables::gate_table_nand[map_input];
320319
break;
321320
case ATPGCircuitElementType::OR:
321+
map_value = GateTables::gate_table_or[map_input];
322+
break;
322323
case ATPGCircuitElementType::NOR:
324+
map_value = GateTables::gate_table_nor[map_input];
325+
break;
323326
default:
324327
printf("Gate type %d is not supported! has_conflict()\n", element.type);
325328
return true;
326329
}
327330

328-
if(map_value != map_output) {
331+
if(map_output != "x" && map_value != map_output) {
329332
return true;
330333
}
331334
}

currentcircuit.cpp

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ CurrentCircuit::CurrentCircuit()
1212

1313
}
1414

15-
bool d_algorithm(ATPGCircuit circ, std::string fault_element_name);
15+
bool d_algorithm(ATPGCircuit circ, std::string fault_element_name, char fault);
1616

1717
void topological_sort_helper(std::string element_name, bool visited[], std::stack<int>& stack) {
1818
Circuit& circ = CurrentCircuit::circ;
@@ -449,7 +449,7 @@ void CurrentCircuit::topological_sort() {
449449
// d frontiers: has input D-D'
450450
// j frontiers: output known, input unknown
451451

452-
d_algorithm(atpg_circuit, "N11");
452+
d_algorithm(atpg_circuit, "N11", 'D');
453453

454454
// std::string fault_element_name = "N11";
455455
// std::stack<ATPGStep> atpg_step_stack;
@@ -538,34 +538,71 @@ void CurrentCircuit::topological_sort() {
538538
}
539539

540540
bool d_algorithm_helper(ATPGCircuit& circ, std::vector<std::string> tried_d_frontiers, std::string activated_gate);
541-
bool d_algorithm(ATPGCircuit circ, std::string fault_element_name) {
542-
// PDF
541+
bool d_algorithm(ATPGCircuit circ, std::string fault_element_name, char fault) {
543542
char gate_and_pdf[3][3] = {
544543
{'1', '1', 'D'},
545544
{'0', 'x', 'E'},
546545
{'x', '0', 'E'}
547546
};
547+
char gate_nand_pdf[3][3] = {
548+
{'1', '1', 'E'},
549+
{'0', 'x', 'D'},
550+
{'x', '0', 'D'}
551+
};
552+
char gate_or_pdf[3][3] = {
553+
{'0', '0', 'E'},
554+
{'x', '1', 'D'},
555+
{'1', 'x', 'D'}
556+
};
557+
char gate_nor_pdf[3][3] = {
558+
{'0', '0', 'D'},
559+
{'x', '1', 'E'},
560+
{'1', 'x', 'E'}
561+
};
548562

549563
std::string activated_gate;
550564

551565
for(auto& element : circ.elements) {
552566
if(element.name == fault_element_name) {
553-
element.cvalue = 'D';
567+
element.cvalue = fault;
554568

555569
auto& gate = circ.get_element(element.inputs[0]);
556570

557-
// TODO: gate types
558571
std::vector<char> i0_vector;
559572
std::vector<char> i1_vector;
560-
if(gate.type == ATPGCircuitElementType::NAND) {
561-
for(auto row : gate_and_pdf) {
562-
if(row[2] == 'D') {
563-
i0_vector.push_back(row[0]);
564-
i1_vector.push_back(row[1]);
565-
}
573+
574+
char (*pdf_table)[3][3];
575+
switch (gate.type)
576+
{
577+
case ATPGCircuitElementType::AND: {
578+
pdf_table = &gate_and_pdf;
579+
break;
580+
}
581+
case ATPGCircuitElementType::NAND: {
582+
pdf_table = &gate_nand_pdf;
583+
break;
584+
}
585+
case ATPGCircuitElementType::OR: {
586+
pdf_table = &gate_or_pdf;
587+
break;
588+
}
589+
case ATPGCircuitElementType::NOR: {
590+
pdf_table = &gate_nor_pdf;
591+
break;
592+
}
593+
default:
594+
printf("Gate %d is not supported! 581\n", gate.type);
595+
return false;
596+
}
597+
598+
for(auto row : *pdf_table) {
599+
if(row[2] == fault) {
600+
i0_vector.push_back(row[0]);
601+
i1_vector.push_back(row[1]);
566602
}
567603
}
568604
auto gate_inputs = circ.get_inputs(gate.name);
605+
// TODO: try with other possibilities?
569606
gate_inputs[0]->cvalue = i0_vector[0];
570607
gate_inputs[1]->cvalue = i1_vector[0];
571608
activated_gate = gate.name;
@@ -649,14 +686,24 @@ bool d_algorithm_helper(ATPGCircuit& circ, std::vector<std::string> tried_d_fron
649686

650687
// set all unassigned inputs of gate to non-controlling value
651688
auto gate_inputs = circ.get_inputs(gate->name);
689+
char fault_type;
652690
for(auto input : gate_inputs) {
653691
if(input->cvalue == 'x') {
654692
input->cvalue = non_controlling_value;
693+
} else {
694+
fault_type = input->cvalue;
655695
}
656696
}
657697
auto& gate_output = circ.get_element(gate->outputs[0]);
658-
// TODO: change this accordingly to nand/nor and also for D'
659-
gate_output.cvalue = 'D';
698+
699+
if(gate->type == ATPGCircuitElementType::NAND || gate->type == ATPGCircuitElementType::NOR) {
700+
if(fault_type == 'D') {
701+
fault_type = 'E';
702+
} else {
703+
fault_type = 'D';
704+
}
705+
}
706+
gate_output.cvalue = fault_type;
660707

661708

662709
bool result = d_algorithm_helper(circ, tried_d_frontiers, activated_gate);

gate_tables.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,59 @@ std::map<std::string, std::string> GateTables::gate_table_nand = {
5555
{"ED", "1"},
5656
{"EE", "D"},
5757
};
58+
59+
std::map<std::string, std::string> GateTables::gate_table_or = {
60+
{"00", "0"},
61+
{"01", "0"},
62+
{"0x", "x"},
63+
{"0D", "D"},
64+
{"0E", "E"},
65+
{"10", "1"},
66+
{"11", "1"},
67+
{"1x", "1"},
68+
{"1D", "1"},
69+
{"1E", "1"},
70+
{"x0", "x"},
71+
{"x1", "1"},
72+
{"xx", "x"},
73+
{"xD", "x"},
74+
{"xE", "x"},
75+
{"D0", "D"},
76+
{"D1", "1"},
77+
{"Dx", "x"},
78+
{"DD", "D"},
79+
{"DE", "1"},
80+
{"E0", "E"},
81+
{"E1", "1"},
82+
{"Ex", "x"},
83+
{"ED", "1"},
84+
{"EE", "E"},
85+
};
86+
87+
std::map<std::string, std::string> GateTables::gate_table_nor = {
88+
{"00", "1"},
89+
{"01", "1"},
90+
{"0x", "x"},
91+
{"0D", "E"},
92+
{"0E", "D"},
93+
{"10", "0"},
94+
{"11", "0"},
95+
{"1x", "0"},
96+
{"1D", "0"},
97+
{"1E", "0"},
98+
{"x0", "x"},
99+
{"x1", "0"},
100+
{"xx", "x"},
101+
{"xD", "x"},
102+
{"xE", "x"},
103+
{"D0", "E"},
104+
{"D1", "0"},
105+
{"Dx", "x"},
106+
{"DD", "E"},
107+
{"DE", "0"},
108+
{"E0", "D"},
109+
{"E1", "0"},
110+
{"Ex", "x"},
111+
{"ED", "0"},
112+
{"EE", "D"},
113+
};

gate_tables.h

Lines changed: 2 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -4,109 +4,12 @@
44
#include "atpg_circuit_element.h"
55
#include <map>
66

7-
// singular cover
8-
// char gate_and_sc[3][3] = {
9-
// {'0', 'x', '0'},
10-
// {'x', '0', '0'},
11-
// {'1', '1', '1'}
12-
// };
13-
// // fault activation
14-
15-
// // propagation d-cube
16-
// char gate_and_pdc[6][3] = {
17-
// {'1', 'D', 'D'},
18-
// {'D', '1', 'D'},
19-
// {'D', 'D', 'D'},
20-
// {'E', '1', 'E'},
21-
// {'1', 'E', 'E'},
22-
// {'E', 'E', 'E'}
23-
// };
24-
25-
26-
// SC: singular cover, outputs are 1/0
27-
// std::map<std::string, std::string> gate_table_sc_and = {
28-
// {"0x", "0"},
29-
// {"x0", "0"},
30-
// {"11", "1"},
31-
// };
32-
33-
// // PDC: propagation d-cube, outputs are D/D'
34-
// std::map<std::string, std::string> gate_table_pdc_and = {
35-
// {"D1", "D"},
36-
// {"1D", "D"},
37-
// {"DD", "D"},
38-
// {"E1", "E"},
39-
// {"1E", "E"},
40-
// {"EE", "E"},
41-
// };
42-
43-
// // PDCF: primitive d-cubes for a fault (fault activation)
44-
// std::map<std::string, std::string> gate_table_pdcf_and = {
45-
// {"11", "D"},
46-
// {"0x", "E"},
47-
// {"x0", "E"},
48-
// };
49-
50-
// std::map<std::string, std::string> gate_table_and = {
51-
// {"00", "0"},
52-
// {"01", "0"},
53-
// {"0x", "0"},
54-
// {"0D", "0"},
55-
// {"0E", "0"},
56-
// {"10", "0"},
57-
// {"11", "1"},
58-
// {"1x", "x"},
59-
// {"1D", "D"},
60-
// {"1E", "E"},
61-
// {"x0", "0"},
62-
// {"x1", "x"},
63-
// {"xx", "x"},
64-
// {"xD", "x"},
65-
// {"xE", "x"},
66-
// {"D0", "0"},
67-
// {"D1", "D"},
68-
// {"Dx", "x"},
69-
// {"DD", "D"},
70-
// {"DE", "0"},
71-
// {"E0", "0"},
72-
// {"E1", "E"},
73-
// {"Ex", "x"},
74-
// {"ED", "0"},
75-
// {"EE", "E"},
76-
// };
77-
78-
// std::map<std::string, std::string> gate_table_nand = {
79-
// {"00", "1"},
80-
// {"01", "1"},
81-
// {"0x", "1"},
82-
// {"0D", "1"},
83-
// {"0E", "1"},
84-
// {"10", "1"},
85-
// {"11", "0"},
86-
// {"1x", "x"},
87-
// {"1D", "E"},
88-
// {"1E", "D"},
89-
// {"x0", "1"},
90-
// {"x1", "x"},
91-
// {"xx", "x"},
92-
// {"xD", "x"},
93-
// {"xE", "x"},
94-
// {"D0", "1"},
95-
// {"D1", "E"},
96-
// {"Dx", "x"},
97-
// {"DD", "E"},
98-
// {"DE", "1"},
99-
// {"E0", "1"},
100-
// {"E1", "D"},
101-
// {"Ex", "x"},
102-
// {"ED", "1"},
103-
// {"EE", "D"},
104-
// };
105-
1067
class GateTables {
1078
public:
1089
static std::map<std::string, std::string> gate_table_and;
10910
static std::map<std::string, std::string> gate_table_nand;
11+
static std::map<std::string, std::string> gate_table_or;
12+
static std::map<std::string, std::string> gate_table_nor;
11013
};
11114

11215
#endif

0 commit comments

Comments
 (0)