-
Notifications
You must be signed in to change notification settings - Fork 34
/
lsim.cpp
191 lines (163 loc) · 5.41 KB
/
lsim.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/***********************************************************************
Copyright (C) 1991,
Virginia Polytechnic Institute & State University
This program was originally written by Mr. Hyung K. Lee
under the supervision of Dr. Dong S. Ha, in the Bradley
Department of Electrical Engineering, VPI&SU, in 1991.
This program is released for research use only. This program,
or any derivative thereof, may not be reproduced nor used
for any commercial product without the written permission
of the authors.
For detailed information, please contact to
Dr. Dong S. Ha
Bradley Department of Electrical Engineering
Virginia Polytechnic Institute & State University
Blacksburg, VA 24061
Ph.: (540) 231-4942
Fax: (540) 231-3362
E-Mail: [email protected]
Web: http://www.ee.vt.edu/ha
REFERENCE:
H. K. Lee and D. S. Ha, "On the Generation of Test Patterns
for Combinational Circuits," Technical Report No. 12_93,
Dep't of Electrical Eng., Virginia Polytechnic Institute
and State University.
***********************************************************************/
/**************************** HISTORY **********************************
atalanta: version 2.0 H. K. Lee, 6/30/1997
Linked HOPE with ATALANTA
***********************************************************************/
/*-----------------------------------------------------------------
lsim.c
contains all subroutines necessary for
zero gate delay event driven logic simulation.
list all modifications below:
original: 8/15/1991 Hyung K. Lee compiled and checked
-------------------------------------------------------------------*/
#include "stdafx.h"
#include <stdio.h>
#include "lsim.h"
#include "parameter.h"
#include "define.h"
#include "macro.h"
extern int g_iNoGate, g_iNoPI, g_iNoPO, g_iNoFF, g_iMaxLevel, g_iPOLevel, g_iPPOLevel;
extern int *g_PrimaryIn, *g_PrimaryOut, *g_FlipFlop;
extern GATEPTR *g_net;
extern STACKTYPE *g_pEventListStack;
extern level g_PIValues[];
extern char initialmode;
#define twoBitsDifferent(V1, V2) (V1[0] != V2[0] || V1[1] != V2[1])
#define twoBitsCopy(Dest, Sour) Dest[0] = Sour[0]; Dest[1] = Sour[1];
level g_TABLE[Z + 1][2] =
{
{ALL1,ALL0}, {ALL0,ALL1}, {ALL0,ALL0}, {ALL1,ALL1}
};
extern level g_truthTable1[MAXGTYPE][MAXLEVEL];
extern level g_truthTable2[MAXGTYPE][MAXLEVEL][MAXLEVEL];
#define valueDifferent(V1, V2) (V1 != V2)
#define valueCopy(Dest, Sour) Dest = Sour
/*-----GoodSim------------------------------------------------------
Performs good circuit logic simulation.
Input patterns are stored in InVal[i].
Current Flip-Flop values in inputs of each FF.
Logic values in GVs of each gate structure are
updated and old values are eliminated.
------------------------------------------------------------------*/
void GoodSim_HOPE(int iNoPatterns) //GoodSim
{
//NO PARAMETER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
//
//
//
//iNoPatterns is current generated patterns in [tgen_sim]
//iNoPatterns is 2 in [shuffle_hope]
//DO NOT give you the 1st time in [shuffle_hope]
register int i, j;
register GATEPTR pGate, pTempGate;
level iValue;
/* schedule events in flip-flops
--- FFs are modeled as Delay Elements */
if (iNoPatterns == 1) //The 1st Time !!
{
//STOP************************************STOP
for (i = 0; i < g_iNoFF; i++)
{
pGate = g_net[g_FlipFlop[i]];
iValue = (initialmode == '0') ? ZERO : (initialmode == '1') ? ONE : X;
if (valueDifferent(pGate->SGV, iValue))
{
valueCopy(pGate->SGV, iValue);
twoBitsCopy(pGate->GV, g_TABLE[iValue]);
pushGateOutputs2(pGate, j, pTempGate);
}
}
}
else //The 2rd Time and so on ..
{
//STOP************************************STOP
for (i = 0; i < g_iNoFF; i++)
{
pGate = g_net[g_FlipFlop[i]];
valueCopy(iValue, pGate->inList[0]->SGV);
if (valueDifferent(pGate->SGV, iValue))
{
valueCopy(pGate->SGV, iValue);
twoBitsCopy(pGate->GV, g_TABLE[iValue]);
pushGateOutputs2(pGate, j, pTempGate);
}
}
}
/* schedule event in primary inputs */
for (i = 0; i < g_iNoPI; i++)
{
//InVal == 0 | 1 | X | Z
pGate = g_net[g_PrimaryIn[i]];
if (valueDifferent(pGate->SGV, g_PIValues[i]))
{
valueCopy(pGate->SGV, g_PIValues[i]);
twoBitsCopy(pGate->GV, g_TABLE[g_PIValues[i]]);
pushGateOutputs2(pGate, j, pTempGate);
}
}
for (i = 0; i < g_iPPOLevel; i++)
{
while (!is_empty(g_pEventListStack[i]))
{
pGate = pop(g_pEventListStack[i]);
reset(pGate->changed);
/* gate evaluation */
//
if (pGate->inCount == 1)
{
//InGates' SGV + Gate's type ----------> Gate's SGV
iValue = g_truthTable1[pGate->type][pGate->inList[0]->SGV]; //Core Sentence
valueCopy(pGate->SGV, iValue);
twoBitsCopy(pGate->GV, g_TABLE[iValue]);
pushGateOutputs2(pGate, j, pTempGate);
}
else //pGate->inCount >= 2
{
//InGates' SGV + Gate's type ----------> Gate's SGV
iValue = g_truthTable1[pGate->type][pGate->inList[0]->SGV]; //Core Sentence
for (j = 1; j< pGate->inCount; j++)
{
iValue = g_truthTable2[pGate->type][iValue][pGate->inList[j]->SGV];
}
if (valueDifferent(pGate->SGV, iValue))
{
valueCopy(pGate->SGV, iValue);
twoBitsCopy(pGate->GV, g_TABLE[iValue]);
pushGateOutputs2(pGate, j, pTempGate);
}
}
}
}
/* Pseudo-Primary outputs */
while (!is_empty(g_pEventListStack[g_iPPOLevel]))
{
//STOP************************************STOP
pGate = pop(g_pEventListStack[g_iPPOLevel]);
reset(pGate->changed);
}
}