Skip to content

Commit f2b1641

Browse files
author
xinoip
committed
done some
1 parent ebb91cd commit f2b1641

File tree

6 files changed

+136
-4
lines changed

6 files changed

+136
-4
lines changed

PLODE.pro

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ SOURCES += \
2727
mainwindow.cpp \
2828
singlepath.cpp \
2929
variationmodel.cpp \
30-
delay_file.cpp
30+
delay_file.cpp \
31+
atpg_circuit.cpp
3132

3233
HEADERS += \
3334
PLODELib.h \
@@ -39,7 +40,9 @@ HEADERS += \
3940
mainwindow.h \
4041
singlepath.h \
4142
variationmodel.h \
42-
delay_file.h
43+
delay_file.h \
44+
atpg_circuit_element.h \
45+
atpg_circuit.h
4346

4447
FORMS += \
4548
mainwindow.ui

atpg_circuit.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "atpg_circuit.h"
2+
3+
ATPGCircuitElement& ATPGCircuit::get_element(std::string name) {
4+
for(auto& element : elements) {
5+
if(element.name == name) {
6+
return element;
7+
}
8+
}
9+
printf("shouldnt come here..\n");
10+
}

atpg_circuit.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef ATPG_CIRCUIT_H
2+
#define ATPG_CIRCUIT_H
3+
4+
#include <vector>
5+
#include "atpg_circuit_element.h"
6+
7+
class ATPGCircuit {
8+
public:
9+
std::vector<ATPGCircuitElement> elements;
10+
11+
ATPGCircuitElement& get_element(std::string name);
12+
};
13+
14+
#endif

atpg_circuit_element.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef ATPG_CIRCUIT_ELEMENT_H
2+
#define ATPG_CIRCUIT_ELEMENT_H
3+
4+
#include <vector>
5+
#include <string>
6+
7+
enum class ATPGCircuitElementType {
8+
WIRE,
9+
AND,
10+
NAND,
11+
OR,
12+
NOR
13+
};
14+
15+
enum class ATPGValue {
16+
ONE,
17+
ZERO,
18+
DONT_CARE,
19+
CRIT_PATH,
20+
NOT_INITIALIZED
21+
};
22+
23+
class ATPGCircuitElement {
24+
public:
25+
std::vector<std::string> inputs;
26+
std::vector<std::string> outputs;
27+
ATPGCircuitElementType type;
28+
std::string name;
29+
ATPGValue value = ATPGValue::NOT_INITIALIZED;
30+
};
31+
32+
#endif

circuitelement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#ifndef CIRCUITELEMENT_H
2+
23
#define CIRCUITELEMENT_H
34

45
#include <QGraphicsItem>

currentcircuit.cpp

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <stack>
44
#include <vector>
5+
#include "atpg_circuit.h"
56

67
Circuit CurrentCircuit::circ;
78

@@ -60,6 +61,7 @@ void CurrentCircuit::topological_sort() {
6061
topological_sort_helper(circ.elements[i].elementName, visited, stack);
6162

6263
std::vector<std::pair<std::string, int>> top_list {};
64+
std::vector<CircuitElement> top_list_circ {};
6365

6466
while (stack.empty() == false) {
6567
int vertex = stack.top();
@@ -93,6 +95,7 @@ void CurrentCircuit::topological_sort() {
9395

9496
// if(element.isGate()) {
9597
top_list.push_back({element.elementName, element.arrivalTime});
98+
top_list_circ.push_back(element);
9699
// }
97100
// printf("%s(d:%d)(a:%d)\n", element.elementName.c_str(), element.delay, element.arrivalTime);
98101
stack.pop();
@@ -104,6 +107,45 @@ void CurrentCircuit::topological_sort() {
104107
}
105108
printf("\n");
106109

110+
ATPGCircuit atpg_circuit;
111+
for(auto& top_element : top_list) {
112+
CircuitElement element;
113+
for(auto& pair : adj) {
114+
if(pair.first.elementName == top_element.first) {
115+
element = pair.first;
116+
break;
117+
}
118+
}
119+
120+
ATPGCircuitElement atpg_element;
121+
atpg_element.name = element.elementName;
122+
//TODO: only NAND for testing
123+
if(element.isGate()) {
124+
atpg_element.type = ATPGCircuitElementType::NAND;
125+
} else {
126+
atpg_element.type = ATPGCircuitElementType::WIRE;
127+
}
128+
129+
// find outputs
130+
for(auto& pair : adj) {
131+
if(pair.first.elementName == top_element.first) {
132+
for(auto& output : pair.second) {
133+
atpg_element.outputs.push_back(output.elementName);
134+
}
135+
}
136+
}
137+
138+
// find inputs
139+
for(auto& pair : adj) {
140+
for(auto& pair_second : pair.second) {
141+
if(pair_second.elementName == top_element.first) {
142+
atpg_element.inputs.push_back(pair.first.elementName);
143+
}
144+
}
145+
}
146+
atpg_circuit.elements.push_back(atpg_element);
147+
}
148+
107149
printf("Critical path:\n");
108150
int slowest_output_index = 0;
109151
for(int i = 0, current_max = 0; i < top_list.size(); i++) {
@@ -113,7 +155,10 @@ void CurrentCircuit::topological_sort() {
113155
slowest_output_index = i;
114156
}
115157
}
158+
std::vector<std::string> crit_path_names;
159+
crit_path_names.push_back(top_list[slowest_output_index].first);
116160
printf("%s[%d]\n", top_list[slowest_output_index].first.c_str(), top_list[slowest_output_index].second);
161+
std::vector<CircuitElement> crit_path_list {};
117162
while(true) {
118163
std::vector<CircuitElement> predecessor_elements;
119164
// get pred elements
@@ -156,9 +201,36 @@ void CurrentCircuit::topological_sort() {
156201
break;
157202
}
158203
}
159-
printf("%s[%d] \n", slowest_pred.elementName.c_str(), slowest_pred.arrivalTime);
204+
crit_path_list.push_back(slowest_pred);
205+
// printf("%s[%d] \n", slowest_pred.elementName.c_str(), slowest_pred.arrivalTime);
160206
slowest_output_index = found_index;
161207
}
162-
// printf("DEBUG slowest output index %d\n", slowest_output_index);
208+
// print critical path
209+
for(auto& element : crit_path_list) {
210+
printf("%s[%d] \n", element.elementName.c_str(), element.arrivalTime);
211+
crit_path_names.push_back(element.elementName);
212+
}
163213
printf("\n");
214+
215+
// sensitize path
216+
for(auto& name : crit_path_names) {
217+
auto& element = atpg_circuit.get_element(name);
218+
if(element.type == ATPGCircuitElementType::WIRE) {
219+
element.value = ATPGValue::CRIT_PATH;
220+
} else {
221+
// assume NAND for now..
222+
for(auto& input : element.inputs) {
223+
if(std::find(crit_path_names.begin(), crit_path_names.end(), input) != crit_path_names.end()) {
224+
atpg_circuit.get_element(input).value = ATPGValue::CRIT_PATH;
225+
} else {
226+
atpg_circuit.get_element(input).value = ATPGValue::ONE;
227+
}
228+
}
229+
}
230+
}
231+
printf("************************\n");
232+
for(auto& element : atpg_circuit.elements) {
233+
printf("%s[%d]\n", element.name.c_str(), element.value);
234+
}
235+
printf("************************\n");
164236
}

0 commit comments

Comments
 (0)