sensitivity.cc revision 13208
112882Sspwilson2@wisc.edu/* 212882Sspwilson2@wisc.edu * Copyright 2018 Google, Inc. 312882Sspwilson2@wisc.edu * 412882Sspwilson2@wisc.edu * Redistribution and use in source and binary forms, with or without 512882Sspwilson2@wisc.edu * modification, are permitted provided that the following conditions are 612882Sspwilson2@wisc.edu * met: redistributions of source code must retain the above copyright 712882Sspwilson2@wisc.edu * notice, this list of conditions and the following disclaimer; 812882Sspwilson2@wisc.edu * redistributions in binary form must reproduce the above copyright 912882Sspwilson2@wisc.edu * notice, this list of conditions and the following disclaimer in the 1012882Sspwilson2@wisc.edu * documentation and/or other materials provided with the distribution; 1112882Sspwilson2@wisc.edu * neither the name of the copyright holders nor the names of its 1212882Sspwilson2@wisc.edu * contributors may be used to endorse or promote products derived from 1312882Sspwilson2@wisc.edu * this software without specific prior written permission. 1412882Sspwilson2@wisc.edu * 1512882Sspwilson2@wisc.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612882Sspwilson2@wisc.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712882Sspwilson2@wisc.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812882Sspwilson2@wisc.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912882Sspwilson2@wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012882Sspwilson2@wisc.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112882Sspwilson2@wisc.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212882Sspwilson2@wisc.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312882Sspwilson2@wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412882Sspwilson2@wisc.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512882Sspwilson2@wisc.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612882Sspwilson2@wisc.edu * 2712882Sspwilson2@wisc.edu * Authors: Gabe Black 2812882Sspwilson2@wisc.edu */ 2912882Sspwilson2@wisc.edu 3012882Sspwilson2@wisc.edu#include "systemc/core/sensitivity.hh" 3112882Sspwilson2@wisc.edu 3212882Sspwilson2@wisc.edu#include "systemc/core/event.hh" 3312882Sspwilson2@wisc.edu#include "systemc/core/port.hh" 3412882Sspwilson2@wisc.edu#include "systemc/core/process.hh" 3512882Sspwilson2@wisc.edu#include "systemc/core/scheduler.hh" 3612882Sspwilson2@wisc.edu#include "systemc/ext/core/sc_export.hh" 3712882Sspwilson2@wisc.edu#include "systemc/ext/core/sc_interface.hh" 3812882Sspwilson2@wisc.edu#include "systemc/ext/core/sc_port.hh" 3912882Sspwilson2@wisc.edu 4012882Sspwilson2@wisc.edunamespace sc_gem5 4112882Sspwilson2@wisc.edu{ 4212882Sspwilson2@wisc.edu 4312882Sspwilson2@wisc.edu/* 4412882Sspwilson2@wisc.edu * Common sensitivity interface. 4512882Sspwilson2@wisc.edu */ 4612882Sspwilson2@wisc.edu 4712882Sspwilson2@wisc.eduvoid 4812882Sspwilson2@wisc.eduSensitivity::satisfy() 4912882Sspwilson2@wisc.edu{ 5012882Sspwilson2@wisc.edu process->satisfySensitivity(this); 5112882Sspwilson2@wisc.edu} 5212882Sspwilson2@wisc.edu 5312882Sspwilson2@wisc.edubool 5412882Sspwilson2@wisc.eduSensitivity::notify(Event *e) 5512882Sspwilson2@wisc.edu{ 5612882Sspwilson2@wisc.edu if (process->disabled()) 5712882Sspwilson2@wisc.edu return false; 5812882Sspwilson2@wisc.edu return notifyWork(e); 5912882Sspwilson2@wisc.edu} 6012882Sspwilson2@wisc.edu 6112882Sspwilson2@wisc.edubool 6212882Sspwilson2@wisc.eduSensitivity::ofMethod() 6312882Sspwilson2@wisc.edu{ 6412882Sspwilson2@wisc.edu return process->procKind() == sc_core::SC_METHOD_PROC_; 6512882Sspwilson2@wisc.edu} 6612882Sspwilson2@wisc.edu 6712882Sspwilson2@wisc.edu 6812882Sspwilson2@wisc.edu/* 6912882Sspwilson2@wisc.edu * Dynamic vs. static sensitivity. 7012882Sspwilson2@wisc.edu */ 7112882Sspwilson2@wisc.edu 7212882Sspwilson2@wisc.eduvoid 7312882Sspwilson2@wisc.eduDynamicSensitivity::addToEvent(const ::sc_core::sc_event *e) 7412882Sspwilson2@wisc.edu{ 7512882Sspwilson2@wisc.edu Event::getFromScEvent(e)->addSensitivity(this); 7612882Sspwilson2@wisc.edu} 7712882Sspwilson2@wisc.edu 7812882Sspwilson2@wisc.eduvoid 7912882Sspwilson2@wisc.eduDynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e) 8012882Sspwilson2@wisc.edu{ 8112882Sspwilson2@wisc.edu Event::getFromScEvent(e)->delSensitivity(this); 8212882Sspwilson2@wisc.edu} 8312882Sspwilson2@wisc.edu 8412882Sspwilson2@wisc.eduvoid 8512882Sspwilson2@wisc.eduStaticSensitivity::addToEvent(const ::sc_core::sc_event *e) 8612882Sspwilson2@wisc.edu{ 8712882Sspwilson2@wisc.edu Event::getFromScEvent(e)->addSensitivity(this); 8812882Sspwilson2@wisc.edu} 8912882Sspwilson2@wisc.edu 9012882Sspwilson2@wisc.eduvoid 9112882Sspwilson2@wisc.eduStaticSensitivity::delFromEvent(const ::sc_core::sc_event *e) 9212882Sspwilson2@wisc.edu{ 9312882Sspwilson2@wisc.edu Event::getFromScEvent(e)->delSensitivity(this); 9412882Sspwilson2@wisc.edu} 9512882Sspwilson2@wisc.edu 9612882Sspwilson2@wisc.edu 9712882Sspwilson2@wisc.edu/* 9812882Sspwilson2@wisc.edu * Static sensitivities. 9912882Sspwilson2@wisc.edu */ 10012882Sspwilson2@wisc.edu 10112882Sspwilson2@wisc.eduvoid 10212882Sspwilson2@wisc.edunewStaticSensitivityEvent(Process *p, const sc_core::sc_event *e) 10312882Sspwilson2@wisc.edu{ 10412882Sspwilson2@wisc.edu auto s = new StaticSensitivityEvent(p, e); 10512882Sspwilson2@wisc.edu s->addToEvent(s->event); 10612882Sspwilson2@wisc.edu p->addStatic(s); 10712882Sspwilson2@wisc.edu} 10812882Sspwilson2@wisc.edu 10912882Sspwilson2@wisc.eduvoid 11012882Sspwilson2@wisc.edunewStaticSensitivityInterface(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 231} // namespace sc_gem5 232