sensitivity.cc (13208:6703cb024823) sensitivity.cc (13260:4d18f1d20093)
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Authors: Gabe Black
28 */
29
30#include "systemc/core/sensitivity.hh"
31
32#include "systemc/core/event.hh"
33#include "systemc/core/port.hh"
34#include "systemc/core/process.hh"
35#include "systemc/core/scheduler.hh"
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Authors: Gabe Black
28 */
29
30#include "systemc/core/sensitivity.hh"
31
32#include "systemc/core/event.hh"
33#include "systemc/core/port.hh"
34#include "systemc/core/process.hh"
35#include "systemc/core/scheduler.hh"
36#include "systemc/ext/channel/sc_in.hh"
37#include "systemc/ext/channel/sc_inout.hh"
38#include "systemc/ext/channel/sc_out.hh"
36#include "systemc/ext/core/sc_export.hh"
37#include "systemc/ext/core/sc_interface.hh"
38#include "systemc/ext/core/sc_port.hh"
39
40namespace sc_gem5
41{
42
43/*
44 * Common sensitivity interface.
45 */
46
47void
48Sensitivity::satisfy()
49{
50 process->satisfySensitivity(this);
51}
52
53bool
54Sensitivity::notify(Event *e)
55{
56 if (process->disabled())
57 return false;
58 return notifyWork(e);
59}
60
61bool
62Sensitivity::ofMethod()
63{
64 return process->procKind() == sc_core::SC_METHOD_PROC_;
65}
66
67
68/*
69 * Dynamic vs. static sensitivity.
70 */
71
72void
73DynamicSensitivity::addToEvent(const ::sc_core::sc_event *e)
74{
75 Event::getFromScEvent(e)->addSensitivity(this);
76}
77
78void
79DynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e)
80{
81 Event::getFromScEvent(e)->delSensitivity(this);
82}
83
84void
85StaticSensitivity::addToEvent(const ::sc_core::sc_event *e)
86{
87 Event::getFromScEvent(e)->addSensitivity(this);
88}
89
90void
91StaticSensitivity::delFromEvent(const ::sc_core::sc_event *e)
92{
93 Event::getFromScEvent(e)->delSensitivity(this);
94}
95
39#include "systemc/ext/core/sc_export.hh"
40#include "systemc/ext/core/sc_interface.hh"
41#include "systemc/ext/core/sc_port.hh"
42
43namespace sc_gem5
44{
45
46/*
47 * Common sensitivity interface.
48 */
49
50void
51Sensitivity::satisfy()
52{
53 process->satisfySensitivity(this);
54}
55
56bool
57Sensitivity::notify(Event *e)
58{
59 if (process->disabled())
60 return false;
61 return notifyWork(e);
62}
63
64bool
65Sensitivity::ofMethod()
66{
67 return process->procKind() == sc_core::SC_METHOD_PROC_;
68}
69
70
71/*
72 * Dynamic vs. static sensitivity.
73 */
74
75void
76DynamicSensitivity::addToEvent(const ::sc_core::sc_event *e)
77{
78 Event::getFromScEvent(e)->addSensitivity(this);
79}
80
81void
82DynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e)
83{
84 Event::getFromScEvent(e)->delSensitivity(this);
85}
86
87void
88StaticSensitivity::addToEvent(const ::sc_core::sc_event *e)
89{
90 Event::getFromScEvent(e)->addSensitivity(this);
91}
92
93void
94StaticSensitivity::delFromEvent(const ::sc_core::sc_event *e)
95{
96 Event::getFromScEvent(e)->delSensitivity(this);
97}
98
99void
100ResetSensitivity::addToEvent(const ::sc_core::sc_event *e)
101{
102 Event::getFromScEvent(e)->addSensitivity(this);
103}
96
104
105void
106ResetSensitivity::delFromEvent(const ::sc_core::sc_event *e)
107{
108 Event::getFromScEvent(e)->delSensitivity(this);
109}
110
111
97/*
98 * Static sensitivities.
99 */
100
101void
102newStaticSensitivityEvent(Process *p, const sc_core::sc_event *e)
103{
104 auto s = new StaticSensitivityEvent(p, e);
105 s->addToEvent(s->event);
106 p->addStatic(s);
107}
108
109void
110newStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i)
111{
112 auto s = new StaticSensitivityInterface(p, i);
113 s->addToEvent(s->event);
114 p->addStatic(s);
115}
116
117void
118newStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb)
119{
120 auto s = new StaticSensitivityPort(p);
121 Port *port = Port::fromPort(pb);
122 port->sensitive(s);
123 p->addStatic(s);
124}
125
126void
127newStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp)
128{
129 auto s = new StaticSensitivityExport(p, exp);
130 s->addToEvent(s->event);
131 p->addStatic(s);
132}
133
134void
135newStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f)
136{
137 auto s = new StaticSensitivityFinder(p, f);
138 Port *port = Port::fromPort(f->port());
139 port->sensitive(s);
140 p->addStatic(s);
141}
142
143
144StaticSensitivityInterface::StaticSensitivityInterface(
145 Process *p, const sc_core::sc_interface *i) :
146 Sensitivity(p), StaticSensitivity(p),
147 SensitivityEvent(p, &i->default_event())
148{}
149
150StaticSensitivityExport::StaticSensitivityExport(
151 Process *p, const sc_core::sc_export_base *exp) :
152 Sensitivity(p), StaticSensitivity(p),
153 SensitivityEvent(p, &exp->get_interface()->default_event())
154{}
155
156const ::sc_core::sc_event &
157StaticSensitivityFinder::find(::sc_core::sc_interface *i)
158{
159 return finder->find_event(i);
160}
161
162
163/*
164 * Dynamic sensitivities.
165 */
166
167void
168newDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e)
169{
170 auto s = new DynamicSensitivityEvent(p, e);
171 s->addToEvent(s->event);
172 p->setDynamic(s);
173}
174
175void
176newDynamicSensitivityEventOrList(
177 Process *p, const sc_core::sc_event_or_list *eol)
178{
179 auto s = new DynamicSensitivityEventOrList(p, eol);
180 for (auto event: s->events)
181 s->addToEvent(event);
182 p->setDynamic(s);
183}
184
185void newDynamicSensitivityEventAndList(
186 Process *p, const sc_core::sc_event_and_list *eal)
187{
188 auto s = new DynamicSensitivityEventAndList(p, eal);
189 for (auto event: s->events)
190 s->addToEvent(event);
191 p->setDynamic(s);
192}
193
194
195DynamicSensitivityEventOrList::DynamicSensitivityEventOrList(
196 Process *p, const sc_core::sc_event_or_list *eol) :
197 Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eol->events)
198{}
199
200bool
201DynamicSensitivityEventOrList::notifyWork(Event *e)
202{
203 events.erase(e->sc_event());
204
205 // All the other events need this deleted from their lists since this
206 // sensitivity has been satisfied without them triggering.
207 for (auto le: events)
208 delFromEvent(le);
209
210 satisfy();
211 return true;
212}
213
214DynamicSensitivityEventAndList::DynamicSensitivityEventAndList(
215 Process *p, const sc_core::sc_event_and_list *eal) :
216 Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eal->events)
217{}
218
219bool
220DynamicSensitivityEventAndList::notifyWork(Event *e)
221{
222 events.erase(e->sc_event());
223
224 // This sensitivity is satisfied if all events have triggered.
225 if (events.empty())
226 satisfy();
227
228 return true;
229}
230
112/*
113 * Static sensitivities.
114 */
115
116void
117newStaticSensitivityEvent(Process *p, const sc_core::sc_event *e)
118{
119 auto s = new StaticSensitivityEvent(p, e);
120 s->addToEvent(s->event);
121 p->addStatic(s);
122}
123
124void
125newStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i)
126{
127 auto s = new StaticSensitivityInterface(p, i);
128 s->addToEvent(s->event);
129 p->addStatic(s);
130}
131
132void
133newStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb)
134{
135 auto s = new StaticSensitivityPort(p);
136 Port *port = Port::fromPort(pb);
137 port->sensitive(s);
138 p->addStatic(s);
139}
140
141void
142newStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp)
143{
144 auto s = new StaticSensitivityExport(p, exp);
145 s->addToEvent(s->event);
146 p->addStatic(s);
147}
148
149void
150newStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f)
151{
152 auto s = new StaticSensitivityFinder(p, f);
153 Port *port = Port::fromPort(f->port());
154 port->sensitive(s);
155 p->addStatic(s);
156}
157
158
159StaticSensitivityInterface::StaticSensitivityInterface(
160 Process *p, const sc_core::sc_interface *i) :
161 Sensitivity(p), StaticSensitivity(p),
162 SensitivityEvent(p, &i->default_event())
163{}
164
165StaticSensitivityExport::StaticSensitivityExport(
166 Process *p, const sc_core::sc_export_base *exp) :
167 Sensitivity(p), StaticSensitivity(p),
168 SensitivityEvent(p, &exp->get_interface()->default_event())
169{}
170
171const ::sc_core::sc_event &
172StaticSensitivityFinder::find(::sc_core::sc_interface *i)
173{
174 return finder->find_event(i);
175}
176
177
178/*
179 * Dynamic sensitivities.
180 */
181
182void
183newDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e)
184{
185 auto s = new DynamicSensitivityEvent(p, e);
186 s->addToEvent(s->event);
187 p->setDynamic(s);
188}
189
190void
191newDynamicSensitivityEventOrList(
192 Process *p, const sc_core::sc_event_or_list *eol)
193{
194 auto s = new DynamicSensitivityEventOrList(p, eol);
195 for (auto event: s->events)
196 s->addToEvent(event);
197 p->setDynamic(s);
198}
199
200void newDynamicSensitivityEventAndList(
201 Process *p, const sc_core::sc_event_and_list *eal)
202{
203 auto s = new DynamicSensitivityEventAndList(p, eal);
204 for (auto event: s->events)
205 s->addToEvent(event);
206 p->setDynamic(s);
207}
208
209
210DynamicSensitivityEventOrList::DynamicSensitivityEventOrList(
211 Process *p, const sc_core::sc_event_or_list *eol) :
212 Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eol->events)
213{}
214
215bool
216DynamicSensitivityEventOrList::notifyWork(Event *e)
217{
218 events.erase(e->sc_event());
219
220 // All the other events need this deleted from their lists since this
221 // sensitivity has been satisfied without them triggering.
222 for (auto le: events)
223 delFromEvent(le);
224
225 satisfy();
226 return true;
227}
228
229DynamicSensitivityEventAndList::DynamicSensitivityEventAndList(
230 Process *p, const sc_core::sc_event_and_list *eal) :
231 Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eal->events)
232{}
233
234bool
235DynamicSensitivityEventAndList::notifyWork(Event *e)
236{
237 events.erase(e->sc_event());
238
239 // This sensitivity is satisfied if all events have triggered.
240 if (events.empty())
241 satisfy();
242
243 return true;
244}
245
246/*
247 * Reset sensitivities.
248 */
249
250void
251newResetSensitivitySignal(
252 Process *p, const sc_core::sc_signal_in_if<bool> *signal,
253 bool val, bool sync)
254{
255 auto s = new ResetSensitivitySignal(p, signal, val, sync);
256 s->addToEvent(s->event);
257 p->addReset(s);
258}
259
260void
261newResetSensitivityPort(Process *p, const sc_core::sc_in<bool> *port,
262 bool val, bool sync)
263{
264 auto s = new ResetSensitivityPort(p, port, val, sync);
265 Port::fromPort(port)->sensitive(s);
266 p->addReset(s);
267}
268void
269newResetSensitivityPort(Process *p, const sc_core::sc_inout<bool> *port,
270 bool val, bool sync)
271{
272 auto s = new ResetSensitivityPort(p, port, val, sync);
273 Port::fromPort(port)->sensitive(s);
274 p->addReset(s);
275}
276void
277newResetSensitivityPort(Process *p, const sc_core::sc_out<bool> *port,
278 bool val, bool sync)
279{
280 auto s = new ResetSensitivityPort(p, port, val, sync);
281 Port::fromPort(port)->sensitive(s);
282 p->addReset(s);
283}
284
285ResetSensitivitySignal::ResetSensitivitySignal(
286 Process *p, const sc_core::sc_signal_in_if<bool> *signal,
287 bool _val, bool _sync) :
288 Sensitivity(p), ResetSensitivity(p, _val, _sync),
289 SensitivityEvent(p, signal ? &signal->value_changed_event() : nullptr),
290 _signal(signal)
291{
292 if (signal && signal->read() == val())
293 process->signalReset(true, sync());
294}
295
296bool
297ResetSensitivitySignal::notifyWork(Event *e)
298{
299 process->signalReset(_signal->read() == val(), sync());
300 return true;
301}
302
303void
304ResetSensitivityPort::setSignal(const ::sc_core::sc_signal_in_if<bool> *signal)
305{
306 _signal = signal;
307 event = &_signal->value_changed_event();
308 addToEvent(event);
309 if (signal->read() == val())
310 process->signalReset(true, sync());
311}
312
231} // namespace sc_gem5
313} // namespace sc_gem5