Skip to content

Commit 48988e8

Browse files
author
xinoip
committed
just save everythinggg
1 parent c1ce139 commit 48988e8

File tree

8 files changed

+1013
-195
lines changed

8 files changed

+1013
-195
lines changed

PLODE.pro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ SOURCES += \
2828
singlepath.cpp \
2929
variationmodel.cpp \
3030
delay_file.cpp \
31-
atpg_circuit.cpp
31+
atpg_circuit.cpp \
32+
gate_tables.cpp
3233

3334
HEADERS += \
3435
PLODELib.h \
@@ -42,7 +43,8 @@ HEADERS += \
4243
variationmodel.h \
4344
delay_file.h \
4445
atpg_circuit_element.h \
45-
atpg_circuit.h
46+
atpg_circuit.h \
47+
gate_tables.h
4648

4749
FORMS += \
4850
mainwindow.ui

atpg_circuit.cpp

Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "atpg_circuit.h"
2+
#include "gate_tables.h"
23

34
ATPGCircuitElement& ATPGCircuit::get_element(std::string name) {
45
for(auto& element : elements) {
@@ -8,3 +9,325 @@ ATPGCircuitElement& ATPGCircuit::get_element(std::string name) {
89
}
910
printf("shouldnt come here..\n");
1011
}
12+
13+
std::vector<ATPGCircuitElement*> ATPGCircuit::get_inputs(std::string name) {
14+
ATPGCircuitElement& element = get_element(name);
15+
std::vector<ATPGCircuitElement*> inputs;
16+
for(std::string& input : element.inputs) {
17+
ATPGCircuitElement& input_element = get_element(input);
18+
inputs.push_back(&input_element);
19+
}
20+
return inputs;
21+
}
22+
23+
// input has 1 or more D/D', output has X
24+
std::vector<ATPGCircuitElement*> ATPGCircuit::get_d_frontiers() {
25+
std::vector<ATPGCircuitElement*> d_frontiers;
26+
for(auto& element : elements) {
27+
if(element.type == ATPGCircuitElementType::WIRE) {
28+
continue;
29+
}
30+
31+
auto gate_inputs = get_inputs(element.name);
32+
auto& output = get_element(element.outputs[0]);
33+
if(output.cvalue != 'x') {
34+
continue;
35+
}
36+
37+
for(auto input : gate_inputs) {
38+
if(input->cvalue == 'D' || input->cvalue == 'E') {
39+
d_frontiers.push_back(&get_element(element.name));
40+
break;
41+
}
42+
}
43+
}
44+
return d_frontiers;
45+
}
46+
47+
// output value assigned, inputs not decided
48+
std::vector<ATPGCircuitElement*> ATPGCircuit::get_j_frontiers() {
49+
std::vector<ATPGCircuitElement*> j_frontiers;
50+
for(auto& element : elements) {
51+
if(element.type == ATPGCircuitElementType::WIRE) {
52+
continue;
53+
}
54+
55+
auto gate_inputs = get_inputs(element.name);
56+
auto& output = get_element(element.outputs[0]);
57+
if(output.cvalue == 'x') {
58+
continue;
59+
}
60+
61+
bool all_x = true;
62+
for(auto input : gate_inputs) {
63+
if(input->cvalue != 'x') {
64+
all_x = false;
65+
break;
66+
}
67+
}
68+
69+
if(all_x) {
70+
j_frontiers.push_back(&get_element(element.name));
71+
}
72+
}
73+
return j_frontiers;
74+
}
75+
76+
// bool ATPGCircuit::justify_gate(std::string name) {
77+
// ATPGCircuitElement& gate = get_element(name);
78+
// if(gate.type == ATPGCircuitElementType::WIRE) {
79+
// return true;
80+
// }
81+
82+
// // get input values
83+
// std::vector<ATPGCircuitElement*> inputs;
84+
// for(std::string& input : gate.inputs) {
85+
// ATPGCircuitElement& input_element = get_element(input);
86+
// inputs.push_back(&input_element);
87+
// }
88+
// ATPGCircuitElement& output = get_element(gate.outputs[0]);
89+
90+
// switch (output.value)
91+
// {
92+
// case ATPGValue::ONE: {
93+
// switch (gate.type)
94+
// {
95+
// case ATPGCircuitElementType::AND: {
96+
// for(auto input : inputs) {
97+
// if(input->value == ATPGValue::NOT_INITIALIZED) {
98+
// input->value = ATPGValue::ONE;
99+
// } else if(input->value != ATPGValue::ONE) {
100+
// printf("fault 36\n");
101+
// return false;
102+
// }
103+
// }
104+
// break;
105+
// }
106+
// case ATPGCircuitElementType::NAND: {
107+
// bool got_zero = false;
108+
// int D_count = 0;
109+
// int D_not_count = 0;
110+
// for(auto input : inputs) {
111+
// if(got_zero) {
112+
// if(input->value == ATPGValue::NOT_INITIALIZED) {
113+
// input->value = ATPGValue::DONT_CARE;
114+
// }
115+
// }
116+
117+
// if(input->value == ATPGValue::NOT_INITIALIZED) {
118+
// input->value = ATPGValue::ZERO;
119+
// got_zero = true;
120+
// } else if(input->value == ATPGValue::D) {
121+
// D_count++;
122+
// } else if(input->value == ATPGValue::D_NOT) {
123+
// D_not_count++;
124+
// } else if(input->value == ATPGValue::ZERO) {
125+
// got_zero = true;
126+
// }
127+
// }
128+
// if(!got_zero) {
129+
// if(!(D_count >= 1 && D_not_count >= 1)) { // case for D-D' inputs
130+
// printf("fault 49\n");
131+
// return false;
132+
// }
133+
// }
134+
// break;
135+
// }
136+
// case ATPGCircuitElementType::OR: {
137+
// bool got_one = false;
138+
// int D_count = 0;
139+
// int D_not_count = 0;
140+
// for(auto input : inputs) {
141+
// if(got_one) {
142+
// if(input->value == ATPGValue::NOT_INITIALIZED) {
143+
// input->value = ATPGValue::DONT_CARE;
144+
// }
145+
// }
146+
147+
// if(input->value == ATPGValue::NOT_INITIALIZED) {
148+
// input->value = ATPGValue::ONE;
149+
// got_one = true;
150+
// } else if(input->value == ATPGValue::D) {
151+
// D_count++;
152+
// } else if(input->value == ATPGValue::D_NOT) {
153+
// D_not_count++;
154+
// } else if(input->value == ATPGValue::ONE) {
155+
// got_one = true;
156+
// }
157+
// }
158+
// if(!got_one) {
159+
// if(!(D_count >= 1 && D_not_count >= 1)) { // case for D-D' inputs
160+
// printf("fault 94\n");
161+
// return false;
162+
// }
163+
// }
164+
// break;
165+
// }
166+
// case ATPGCircuitElementType::NOR: {
167+
// for(auto input : inputs) {
168+
// if(input->value == ATPGValue::NOT_INITIALIZED) {
169+
// input->value = ATPGValue::ZERO;
170+
// } else if(input->value != ATPGValue::ZERO) {
171+
// printf("fault 104\n");
172+
// return false;
173+
// }
174+
// }
175+
// break;
176+
// }
177+
// default: {
178+
// printf("unsupported gate type\n");
179+
// break;
180+
// }
181+
// }
182+
// break;
183+
// }
184+
185+
// case ATPGValue::ZERO: {
186+
// switch (gate.type)
187+
// {
188+
// case ATPGCircuitElementType::AND: {
189+
// bool got_zero = false;
190+
// int D_count = 0;
191+
// int D_not_count = 0;
192+
// for(auto input : inputs) {
193+
// if(got_zero) {
194+
// if(input->value == ATPGValue::NOT_INITIALIZED) {
195+
// input->value = ATPGValue::DONT_CARE;
196+
// }
197+
// }
198+
199+
// if(input->value == ATPGValue::NOT_INITIALIZED) {
200+
// input->value = ATPGValue::ZERO;
201+
// got_zero = true;
202+
// } else if(input->value == ATPGValue::D) {
203+
// D_count++;
204+
// } else if(input->value == ATPGValue::D_NOT) {
205+
// D_not_count++;
206+
// } else if(input->value == ATPGValue::ZERO) {
207+
// got_zero = true;
208+
// }
209+
// }
210+
// if(!got_zero) {
211+
// if(!(D_count >= 1 && D_not_count >= 1)) { // case for D-D' inputs
212+
// printf("fault 49\n");
213+
// return false;
214+
// }
215+
// }
216+
// break;
217+
// }
218+
// case ATPGCircuitElementType::NAND: {
219+
// for(auto input : inputs) {
220+
// if(input->value == ATPGValue::NOT_INITIALIZED) {
221+
// input->value = ATPGValue::ONE;
222+
// } else if(input->value != ATPGValue::ONE) {
223+
// printf("fault 36\n");
224+
// return false;
225+
// }
226+
// }
227+
// break;
228+
// }
229+
// case ATPGCircuitElementType::OR: {
230+
// for(auto input : inputs) {
231+
// if(input->value == ATPGValue::NOT_INITIALIZED) {
232+
// input->value = ATPGValue::ZERO;
233+
// } else if(input->value != ATPGValue::ZERO) {
234+
// printf("fault 104\n");
235+
// return false;
236+
// }
237+
// }
238+
// break;
239+
// }
240+
// case ATPGCircuitElementType::NOR: {
241+
// bool got_one = false;
242+
// int D_count = 0;
243+
// int D_not_count = 0;
244+
// for(auto input : inputs) {
245+
// if(got_one) {
246+
// if(input->value == ATPGValue::NOT_INITIALIZED) {
247+
// input->value = ATPGValue::DONT_CARE;
248+
// }
249+
// }
250+
251+
// if(input->value == ATPGValue::NOT_INITIALIZED) {
252+
// input->value = ATPGValue::ONE;
253+
// got_one = true;
254+
// } else if(input->value == ATPGValue::D) {
255+
// D_count++;
256+
// } else if(input->value == ATPGValue::D_NOT) {
257+
// D_not_count++;
258+
// } else if(input->value == ATPGValue::ONE) {
259+
// got_one = true;
260+
// }
261+
// }
262+
// if(!got_one) {
263+
// if(!(D_count >= 1 && D_not_count >= 1)) { // case for D-D' inputs
264+
// printf("fault 94\n");
265+
// return false;
266+
// }
267+
// }
268+
// break;
269+
// }
270+
// default: {
271+
// printf("unsupported gate type\n");
272+
// break;
273+
// }
274+
// }
275+
// break;
276+
// }
277+
// case ATPGValue::D:
278+
// case ATPGValue::D_NOT:
279+
// case ATPGValue::DONT_CARE:
280+
// case ATPGValue::NOT_INITIALIZED:
281+
// case ATPGValue::CRIT_PATH:
282+
// break;
283+
// }
284+
285+
// switch (gate.type)
286+
// {
287+
// case ATPGCircuitElementType::AND:
288+
// case ATPGCircuitElementType::NAND:
289+
// case ATPGCircuitElementType::OR:
290+
// case ATPGCircuitElementType::NOR:
291+
// }
292+
// }
293+
294+
bool ATPGCircuit::has_conflict(std::string exclude_gate) {
295+
for(auto& element : elements) {
296+
if(element.type == ATPGCircuitElementType::WIRE) {
297+
continue;
298+
}
299+
if(element.name == exclude_gate) {
300+
continue;
301+
}
302+
303+
auto inputs = get_inputs(element.name);
304+
auto& output = get_element(element.outputs[0]);
305+
306+
std::string i0{inputs[0]->cvalue};
307+
std::string i1{inputs[1]->cvalue};
308+
std::string map_output{output.cvalue};
309+
std::string map_input = i0 + i1;
310+
311+
std::string map_value;
312+
switch (element.type)
313+
{
314+
case ATPGCircuitElementType::AND:
315+
map_value = GateTables::gate_table_and[map_input];
316+
break;
317+
case ATPGCircuitElementType::NAND:
318+
// todo change this
319+
map_value = GateTables::gate_table_and[map_input];
320+
break;
321+
case ATPGCircuitElementType::OR:
322+
case ATPGCircuitElementType::NOR:
323+
default:
324+
printf("Gate type %d is not supported! has_conflict()\n", element.type);
325+
return true;
326+
}
327+
328+
if(map_value != map_output) {
329+
return true;
330+
}
331+
}
332+
return false;
333+
}

atpg_circuit.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@
44
#include <vector>
55
#include "atpg_circuit_element.h"
66

7+
struct ATPGStep {
8+
std::string name;
9+
std::string subject;
10+
char value;
11+
bool alternative_tried;
12+
};
13+
714
class ATPGCircuit {
815
public:
916
std::vector<ATPGCircuitElement> elements;
1017

1118
ATPGCircuitElement& get_element(std::string name);
19+
std::vector<ATPGCircuitElement*> get_inputs(std::string name);
20+
21+
bool justify_gate(std::string name);
22+
23+
std::vector<ATPGCircuitElement*> get_d_frontiers();
24+
std::vector<ATPGCircuitElement*> get_j_frontiers();
25+
26+
bool has_conflict(std::string exclude_gate);
1227
};
1328

1429
#endif

0 commit comments

Comments
 (0)