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/scheduler.hh" 35#include "systemc/ext/core/sc_export.hh" 36#include "systemc/ext/core/sc_interface.hh" 37#include "systemc/ext/core/sc_port.hh" 38 39namespace sc_gem5 40{ 41
|
42/* 43 * Common sensitivity interface. 44 */ 45 |
46void 47Sensitivity::satisfy() 48{ 49 process->satisfySensitivity(this); 50} 51 52bool 53Sensitivity::notify(Event *e) 54{ 55 if (process->disabled()) 56 return false; 57 return notifyWork(e); 58} 59 60
|
61/* 62 * Dynamic vs. static sensitivity. 63 */ 64 |
65void 66DynamicSensitivity::addToEvent(const ::sc_core::sc_event *e) 67{ 68 Event::getFromScEvent(e)->addSensitivity(this); 69} 70 71void 72DynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e) 73{ 74 Event::getFromScEvent(e)->delSensitivity(this); 75} 76 77void 78StaticSensitivity::addToEvent(const ::sc_core::sc_event *e) 79{ 80 Event::getFromScEvent(e)->addSensitivity(this); 81} 82 83void 84StaticSensitivity::delFromEvent(const ::sc_core::sc_event *e) 85{ 86 Event::getFromScEvent(e)->delSensitivity(this); 87} 88
|
89 90/* 91 * Static sensitivities. 92 */ 93 |
94void
|
81StaticSensitivityInterface::finalize()
|
95newStaticSensitivityEvent(Process *p, const sc_core::sc_event *e) |
96{
|
83 event = &interface->default_event();
84 SensitivityEvent::finalize();
|
97 auto s = new StaticSensitivityEvent(p, e); 98 s->addToEvent(s->event); 99 p->addStatic(s); |
100} 101 102void
|
88StaticSensitivityPort::finalize()
|
103newStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i) |
104{
|
90 for (int i = 0; i < port->size(); i++) {
91 const ::sc_core::sc_event *event =
92 &port->_gem5Interface(i)->default_event();
93 events.insert(event);
94 addToEvent(event);
95 }
|
105 auto s = new StaticSensitivityInterface(p, i); 106 s->addToEvent(s->event); 107 p->addStatic(s); |
108} 109 110void
|
99StaticSensitivityExport::finalize()
|
111newStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb) |
112{
|
101 event = &exp->get_interface()->default_event();
102 SensitivityEvent::finalize();
|
113 auto s = new StaticSensitivityPort(p); 114 Port *port = Port::fromPort(pb); 115 port->sensitive(s); 116 p->addStatic(s); |
117} 118 119void
|
106StaticSensitivityFinder::finalize()
|
120newStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp) |
121{
|
108 const ::sc_core::sc_port_base *port = finder->port();
109 int size = port->size();
110 for (int i = 0; i < size; i++) {
111 ::sc_core::sc_interface *interface = port->_gem5Interface(i);
112 const ::sc_core::sc_event *event = &finder->find_event(interface);
113 events.insert(event);
114 addToEvent(event);
115 }
|
122 auto s = new StaticSensitivityExport(p, exp); 123 s->addToEvent(s->event); 124 p->addStatic(s); |
125} 126
|
118bool
119DynamicSensitivityEventOrList::notifyWork(Event *e)
|
127void 128newStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) |
129{
|
121 events.erase(e->sc_event());
|
130 auto s = new StaticSensitivityFinder(p, f); 131 Port *port = Port::fromPort(f->port()); 132 port->sensitive(s); 133 p->addStatic(s); 134} |
135
|
123 // All the other events need this deleted from their lists since this
124 // sensitivity has been satisfied without them triggering.
125 for (auto le: events)
126 delFromEvent(le);
|
136
|
128 satisfy();
129 return true;
130}
|
137StaticSensitivityInterface::StaticSensitivityInterface( 138 Process *p, const sc_core::sc_interface *i) : 139 Sensitivity(p), StaticSensitivity(p), 140 SensitivityEvent(p, &i->default_event()) 141{} |
142
|
132DynamicSensitivityEventOrList::DynamicSensitivityEventOrList(
133 Process *p, const sc_core::sc_event_or_list *eol) :
134 Sensitivity(p), DynamicSensitivity(p), events(eol->events)
|
143StaticSensitivityExport::StaticSensitivityExport( 144 Process *p, const sc_core::sc_export_base *exp) : 145 Sensitivity(p), StaticSensitivity(p), 146 SensitivityEvent(p, &exp->get_interface()->default_event()) |
147{} 148
|
149const ::sc_core::sc_event & 150StaticSensitivityFinder::find(::sc_core::sc_interface *i) 151{ 152 return finder->find_event(i); 153} 154 155 156/* 157 * Dynamic sensitivities. 158 */ 159 |
160void
|
138DynamicSensitivityEventOrList::finalize()
|
161newDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e) |
162{
|
140 for (auto e: events)
141 addToEvent(e);
|
163 auto s = new DynamicSensitivityEvent(p, e); 164 s->addToEvent(s->event); 165 p->setDynamic(s); |
166} 167 168void
|
145DynamicSensitivityEventOrList::clear()
|
169newDynamicSensitivityEventOrList( 170 Process *p, const sc_core::sc_event_or_list *eol) |
171{
|
147 for (auto e: events)
148 delFromEvent(e);
|
172 auto s = new DynamicSensitivityEventOrList(p, eol); 173 for (auto event: s->events) 174 s->addToEvent(event); 175 p->setDynamic(s); |
176} 177
|
178void newDynamicSensitivityEventAndList( 179 Process *p, const sc_core::sc_event_and_list *eal) 180{ 181 auto s = new DynamicSensitivityEventAndList(p, eal); 182 for (auto event: s->events) 183 s->addToEvent(event); 184 p->setDynamic(s); 185} 186 187 188DynamicSensitivityEventOrList::DynamicSensitivityEventOrList( 189 Process *p, const sc_core::sc_event_or_list *eol) : 190 Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eol->events) 191{} 192 |
193bool
|
152DynamicSensitivityEventAndList::notifyWork(Event *e)
|
194DynamicSensitivityEventOrList::notifyWork(Event *e) |
195{ 196 events.erase(e->sc_event()); 197
|
156 // This sensitivity is satisfied if all events have triggered.
157 if (events.empty())
158 satisfy();
|
198 // All the other events need this deleted from their lists since this 199 // sensitivity has been satisfied without them triggering. 200 for (auto le: events) 201 delFromEvent(le); |
202
|
203 satisfy(); |
204 return true; 205} 206 207DynamicSensitivityEventAndList::DynamicSensitivityEventAndList( 208 Process *p, const sc_core::sc_event_and_list *eal) :
|
165 Sensitivity(p), DynamicSensitivity(p), events(eal->events)
|
209 Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eal->events) |
210{} 211
|
168void
169DynamicSensitivityEventAndList::finalize()
|
212bool 213DynamicSensitivityEventAndList::notifyWork(Event *e) |
214{
|
171 for (auto e: events)
172 addToEvent(e);
173}
|
215 events.erase(e->sc_event()); |
216
|
175void
176DynamicSensitivityEventAndList::clear()
177{
178 for (auto e: events)
179 delFromEvent(e);
|
217 // This sensitivity is satisfied if all events have triggered. 218 if (events.empty()) 219 satisfy(); 220 221 return true; |
222} 223 224} // namespace sc_gem5
|