Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 175 lines (145 sloc) 4.322 kb
2094a2f Catch some simple identity compareoptimizations.
steve authored
1 /*
29ade50 @caryr Remove some cppcheck warnings in the main and vvp diretory.
caryr authored
2 * Copyright (c) 2000-2012 Stephen Williams (steve@icarus.com)
2094a2f Catch some simple identity compareoptimizations.
steve authored
3 *
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
f5aafc3 @arunpersaud updated FSF-address
arunpersaud authored
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2094a2f Catch some simple identity compareoptimizations.
steve authored
18 */
19
b825f8d Create a config.h.in file to hold all the config
steve authored
20 # include "config.h"
21
2094a2f Catch some simple identity compareoptimizations.
steve authored
22 # include "netlist.h"
23 # include "netmisc.h"
24
f4443a7 Add support for supply nets (PR#17)
steve authored
25 /*
26 * Scan the link for drivers. If there are only constant drivers, then
27 * the nexus has a known constant value. If there is a supply net,
28 * then the nexus again has a known constant value.
29 */
58c2e12 Make link_drive_constant cache its results in
steve authored
30 bool Nexus::drivers_constant() const
ea96c3e Support initialization of FF Q value.
steve authored
31 {
58c2e12 Make link_drive_constant cache its results in
steve authored
32 if (driven_ == VAR)
33 return false;
34 if (driven_ != NO_GUESS)
35 return true;
f4443a7 Add support for supply nets (PR#17)
steve authored
36
782c55f @steveicarus Restructure Nexus lists of Links to handle large net lists.
authored
37 for (const Link*cur = first_nlink() ; cur ; cur = cur->next_nlink()) {
d7fb472 Shuffle link_drivers_constant for speed.
steve authored
38 Link::DIR cur_dir;
ea96c3e Support initialization of FF Q value.
steve authored
39
d7fb472 Shuffle link_drivers_constant for speed.
steve authored
40 cur_dir = cur->get_dir();
41 if (cur_dir == Link::INPUT)
ea96c3e Support initialization of FF Q value.
steve authored
42 continue;
42e4ff4 Move inital value handling from NetNet to Nexus
steve authored
43
e35ed6e Change the NetAssign_ class to refer to the signal
steve authored
44 /* If this is an input or inout port of a root module,
d3bff8a links to root inputs are not constant.
steve authored
45 then the is probably not a constant value. I
e35ed6e Change the NetAssign_ class to refer to the signal
steve authored
46 certainly don't know what the value is, anyhow. This
47 can happen in cases like this:
48
49 module main(sig);
50 input sig;
51 endmodule
52
53 If main is a root module (it has no parent) then sig
54 is not constant because it connects to an unspecified
55 outside world. */
d3bff8a links to root inputs are not constant.
steve authored
56
d7fb472 Shuffle link_drivers_constant for speed.
steve authored
57 if (cur_dir == Link::PASSIVE) {
29ade50 @caryr Remove some cppcheck warnings in the main and vvp diretory.
caryr authored
58 const NetNet*sig;
e4ae832 Clean up spurious trailing white space.
steve authored
59
b292a5f @steveicarus Create a branch object to be the argument to the access function.
authored
60 const NetPins*obj = cur->get_obj();
61 const NetObj*as_obj = dynamic_cast<const NetObj*>(obj);
62 if (as_obj == 0 || as_obj->scope()->parent() != 0)
d7fb472 Shuffle link_drivers_constant for speed.
steve authored
63 continue;
d3bff8a links to root inputs are not constant.
steve authored
64
d7fb472 Shuffle link_drivers_constant for speed.
steve authored
65 sig = dynamic_cast<const NetNet*>(cur->get_obj());
66 assert(sig);
d3bff8a links to root inputs are not constant.
steve authored
67
d7fb472 Shuffle link_drivers_constant for speed.
steve authored
68 if (sig->port_type() == NetNet::NOT_A_PORT)
69 continue;
d3bff8a links to root inputs are not constant.
steve authored
70
d7fb472 Shuffle link_drivers_constant for speed.
steve authored
71 if (sig->port_type() == NetNet::POUTPUT)
72 continue;
d3bff8a links to root inputs are not constant.
steve authored
73
58c2e12 Make link_drive_constant cache its results in
steve authored
74 driven_ = VAR;
d7fb472 Shuffle link_drivers_constant for speed.
steve authored
75 return false;
d3bff8a links to root inputs are not constant.
steve authored
76
d7fb472 Shuffle link_drivers_constant for speed.
steve authored
77 }
42e4ff4 Move inital value handling from NetNet to Nexus
steve authored
78
f4443a7 Add support for supply nets (PR#17)
steve authored
79 /* If there is a supply net, then this nexus will have a
80 constant value independent of any drivers. */
3adcbb5 @ldoolitt Shadow reduction part 2
ldoolitt authored
81 if (const NetNet*s = dynamic_cast<const NetNet*>(cur->get_obj()))
82 switch (s->type()) {
f4443a7 Add support for supply nets (PR#17)
steve authored
83 case NetNet::SUPPLY0:
58c2e12 Make link_drive_constant cache its results in
steve authored
84 driven_ = V0;
85 return true;
f4443a7 Add support for supply nets (PR#17)
steve authored
86 case NetNet::SUPPLY1:
58c2e12 Make link_drive_constant cache its results in
steve authored
87 driven_ = V1;
f4443a7 Add support for supply nets (PR#17)
steve authored
88 return true;
89 default:
90 break;
91 }
58c2e12 Make link_drive_constant cache its results in
steve authored
92
93 if (! dynamic_cast<const NetConst*>(cur->get_obj())) {
94 driven_ = VAR;
95 return false;
96 }
ea96c3e Support initialization of FF Q value.
steve authored
97 }
98
d7fb472 Shuffle link_drivers_constant for speed.
steve authored
99 return true;
ea96c3e Support initialization of FF Q value.
steve authored
100 }
101
9fc4e1e Cache calculated driven value.
steve authored
102 verinum::V Nexus::driven_value() const
ea96c3e Support initialization of FF Q value.
steve authored
103 {
9fc4e1e Cache calculated driven value.
steve authored
104 switch (driven_) {
105 case V0:
106 return verinum::V0;
107 case V1:
108 return verinum::V1;
109 case Vx:
110 return verinum::Vx;
111 case Vz:
112 return verinum::Vz;
113 case VAR:
114 assert(0);
115 break;
116 case NO_GUESS:
117 break;
118 }
119
120 const Link*cur = list_;
121
122 verinum::V val = verinum::Vz;
f4443a7 Add support for supply nets (PR#17)
steve authored
123
782c55f @steveicarus Restructure Nexus lists of Links to handle large net lists.
authored
124 for (cur = first_nlink() ; cur ; cur = cur->next_nlink()) {
ea96c3e Support initialization of FF Q value.
steve authored
125
126 const NetConst*obj;
f4443a7 Add support for supply nets (PR#17)
steve authored
127 const NetNet*sig;
61195c5 Harmless fixup of warnings.
steve authored
128 if ((obj = dynamic_cast<const NetConst*>(cur->get_obj()))) {
f4443a7 Add support for supply nets (PR#17)
steve authored
129 val = obj->value(cur->get_pin());
ea96c3e Support initialization of FF Q value.
steve authored
130
61195c5 Harmless fixup of warnings.
steve authored
131 } else if ((sig = dynamic_cast<const NetNet*>(cur->get_obj()))) {
ea96c3e Support initialization of FF Q value.
steve authored
132
d3a5454 Properly account for tri0 connected to otherwise open mux input.
steve authored
133 // If we find an attached SUPPLY0/1, the we know
134 // from that what the driven value is. Stop now.
9fc4e1e Cache calculated driven value.
steve authored
135 if (sig->type() == NetNet::SUPPLY0) {
136 driven_ = V0;
f4443a7 Add support for supply nets (PR#17)
steve authored
137 return verinum::V0;
9fc4e1e Cache calculated driven value.
steve authored
138 }
139 if (sig->type() == NetNet::SUPPLY1) {
140 driven_ = V1;
f4443a7 Add support for supply nets (PR#17)
steve authored
141 return verinum::V1;
9fc4e1e Cache calculated driven value.
steve authored
142 }
d3a5454 Properly account for tri0 connected to otherwise open mux input.
steve authored
143
144 // If we find an attached TRI0/1, then this is a
145 // good guess for the driven value, but keep
146 // looking for something better.
147 if (sig->type() == NetNet::TRI0) {
148 val = verinum::V0;
149 }
150 if (sig->type() == NetNet::TRI1) {
151 val = verinum::V1;
152 }
f4443a7 Add support for supply nets (PR#17)
steve authored
153 }
2094a2f Catch some simple identity compareoptimizations.
steve authored
154 }
155
9fc4e1e Cache calculated driven value.
steve authored
156 /* Cache the result. */
157 switch (val) {
158 case verinum::V0:
159 driven_ = V0;
160 break;
161 case verinum::V1:
162 driven_ = V1;
163 break;
164 case verinum::Vx:
165 driven_ = Vx;
166 break;
167 case verinum::Vz:
168 driven_ = Vz;
169 break;
170 }
171
4823238 Whoops, return the calculated constant value rom driven_value.
steve authored
172 return val;
2094a2f Catch some simple identity compareoptimizations.
steve authored
173 }
174
Something went wrong with that request. Please try again.