Skip to content

Commit 8b4d878

Browse files
committed
simulation version 1.0
1 parent 8219c4c commit 8b4d878

File tree

2 files changed

+70
-23
lines changed

2 files changed

+70
-23
lines changed

DSnP2016/fraig/cirGate.cpp

+27-8
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,46 @@ vector< vector<unsigned> > CirGate::FECGSet = vector< vector<unsigned> >();
4040

4141
void
4242
CirGate::reportGate() const {
43-
unsigned intSored = bitList[fanin[0] / 2];
43+
unsigned i, j, k, x, numPrinted;
4444
char bitStored[32];
45-
for (char i = 32; i > 0; --i, intSored /= 2) bitStored[i - 1] = ('0' + (intSored % 2));
45+
unsigned intSored = bitList[fanin[0] / 2];
46+
for (i = 32; i > 0; --i, intSored /= 2) bitStored[i - 1] = ('0' + (intSored % 2));
4647

47-
char j = 12 + (char(getTypeStr().length())) + uIntLen(fanin[0] / 2) + uIntLen(lineNo);
48+
j = 12 + getTypeStr().length() + uIntLen(fanin[0] / 2) + uIntLen(lineNo);
4849
if (symbol.length() != 0) j += (symbol.length() + 2);
49-
for (char i = 0; i < 50; ++i) cout << '=';
50+
for (i = 0; i < 50; ++i) cout << '=';
5051
cout << "\n= " << getTypeStr() << '(' << (fanin[0] / 2) << ')';
5152
if (symbol.length() != 0) cout << '\"' << symbol << '\"';
5253
cout << ", line " << lineNo;
5354
for (; j < 50; ++j) cout << ' '; cout << "=\n";
5455

55-
cout << "= FECs:"; cout << "=";
56+
intSored = FECNo;
57+
cout << "= FECs:";
58+
if (!intSored) for (i = 0; i < 41; ++i) cout << ' ';
59+
else {
60+
j = (--intSored) % 2;
61+
intSored /= 2;
62+
for (k = 0, x = FECGSet[intSored].size(), i = 0; k < x; ++k) {
63+
numPrinted = FECGSet[intSored][k];
64+
if (numPrinted / 2 != fanin[0] / 2) {
65+
i += (1 + uIntLen(numPrinted / 2));
66+
cout << ' ';
67+
if ((numPrinted + j) % 2) { ++i; cout << '!'; }
68+
cout << numPrinted / 2;
69+
}
70+
}
71+
for (; i < 41; ++i) cout << ' ';
72+
}
73+
cout << " =";
5674

5775
cout << "\n= Value: ";
58-
for (char i = 0; i < 32; ++i) {
59-
if ((i % 4 == 0) && (i != 0)) cout << '_';
76+
cout << bitStored[0];
77+
for (i = 1; i < 32; ++i) {
78+
if (i % 4 == 0) cout << '_';
6079
cout << bitStored[i];
6180
}
6281
cout << " =\n";
63-
for (char i = 0; i < 50; ++i) cout << '=';
82+
for (i = 0; i < 50; ++i) cout << '=';
6483
cout << endl;
6584
}
6685

DSnP2016/fraig/cirSim.cpp

+43-15
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,15 @@ CirMgr::randomSim() {
166166
void
167167
CirMgr::fileSim(ifstream& patternFile) {
168168
unsigned i, x, j, y;
169+
string patIn;
169170
vector<unsigned> dummyArr;
171+
vector< vector<unsigned> > newFECG;
172+
unsigned remainTime = 0;
173+
size_t caseCount = 0;
174+
unsigned* bl = CirGate::bitList;
175+
unsigned* caseOut = new unsigned[param[2]];
170176
CirGate** g = CirGate::gateArr;
177+
171178
if (!hasBeenSim) {
172179
CirGate::FECGSet.push_back(vector<unsigned>());
173180
CirGate::FECGSet[0].push_back(0);
@@ -179,23 +186,46 @@ CirMgr::fileSim(ifstream& patternFile) {
179186
g[i] = (CirGate*)(((size_t)g[i]) - 1);
180187
CirGate::flipped.pop_back();
181188
}
182-
if (CirGate::FECGSet[0].size() < 2) { CirGate::FECGSet.clear(); return; }
189+
if (CirGate::FECGSet[0].size() < 2) CirGate::FECGSet.clear();
183190
} else for (i = 0, x = CirGate::FECGSet.size(); i < x; ++i)
184191
for (j = 0, y = CirGate::FECGSet[i].size(); j < y; ++j) {
185192
CirGate::FECGSet[i][j] /= 2;
186193
g[CirGate::FECGSet[i][j]]->FECNo = 0;
187194
}
195+
196+
dummyArr.clear(); remainTime = 0;
197+
while (patternFile >> patIn) {
198+
x = patIn.size();
199+
if (x != param[1]) {
200+
cout << "Error: Pattern(" << patIn << ") length(" << x
201+
<< ") does not match the number of inputs(" << param[1] << ") in a circuit!!" << endl;
202+
dummyArr.clear();
203+
caseCount = 0;
204+
break;
205+
}
206+
for (i = 0; i < x; ++i) if ((patIn[i] != '0') && (patIn[i] != '1')) {
207+
cout << "Error: Pattern(" << patIn << ") contains a non-0/1 character(\'"
208+
<< patIn[i] << "\')." << endl;
209+
dummyArr.clear();
210+
caseCount = 0;
211+
remainTime = 1;
212+
break;
213+
}
214+
if (remainTime) break;
215+
216+
++caseCount;
217+
if (caseCount % 32 == 1) {
218+
j = 1;
219+
for (i = 0; i < x; ++i) dummyArr.push_back((unsigned)(patIn[i] - '0'));
220+
} else {
221+
j = j << 1;
222+
for (i = 0; i < x; ++i) if (patIn[i] == '1') dummyArr[dummyArr.size() - x + i] += j;
223+
}
188224

189-
vector< vector<unsigned> > newFECG;
190-
unsigned remainTime = 0;
191-
size_t caseCount = 0;
192-
unsigned* bl = CirGate::bitList;
193-
unsigned* caseIn = new unsigned[param[1]];
194-
unsigned* caseOut = new unsigned[param[2]];
195-
while ((CirGate::FECGSet.size()) && (remainTime < 5)) {
196-
caseGen(caseIn, param[1]);
197-
caseCount += 32;
198-
for (i = 0, x = param[1]; i < x; ++i) bl[PIList[i]] = caseIn[i];
225+
}
226+
227+
for (unsigned k = 0, z = dummyArr.size(), l = param[1]; k < z; k += l) {
228+
for (i = 0; i < l; ++i) bl[PIList[i]] = dummyArr[k + i];
199229
for (i = param[0] + 1, x = i + param[2], j = 0; i < x; ++i, ++j) {
200230
bitSim(i);
201231
caseOut[j] = bl[i];
@@ -206,16 +236,15 @@ CirMgr::fileSim(ifstream& patternFile) {
206236
CirGate::flipped.pop_back();
207237
}
208238
if (_simLog) for (i = 0; i < 32; ++i) {
209-
for (j = 0, y = param[1]; j < y; ++j) { (*_simLog) << (caseIn[j] % 2); caseIn[j] /= 2; }
239+
for (j = 0; j < l; ++j) { (*_simLog) << (dummyArr[k + j] % 2); dummyArr[k + j] /= 2; }
210240
(*_simLog) << ' ';
211241
for (j = 0, y = param[2]; j < y; ++j) { (*_simLog) << (caseOut[j] % 2); caseOut[j] /= 2; }
212242
(*_simLog) << endl;
213243
}
214244

215245
y = 0; //changeExist
216246
for (i = 0, x = CirGate::FECGSet.size(); i < x; ++i) if (FECGHash(i, newFECG)) ++y;
217-
if (y) { remainTime = 0; CirGate::FECGSet.swap(newFECG); }
218-
else ++remainTime;
247+
if (y) CirGate::FECGSet.swap(newFECG);
219248
newFECG.clear();
220249
}
221250

@@ -237,7 +266,6 @@ CirMgr::fileSim(ifstream& patternFile) {
237266

238267
hasBeenSim = true;
239268
delete [] caseOut;
240-
delete [] caseIn;
241269
cout << caseCount << " patterns simulated." << endl;
242270
}
243271

0 commit comments

Comments
 (0)