sensitivity.cc revision 13260
113206Sgabeblack@google.com/* 213206Sgabeblack@google.com * Copyright 2018 Google, Inc. 313206Sgabeblack@google.com * 413206Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 513206Sgabeblack@google.com * modification, are permitted provided that the following conditions are 613206Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 713206Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 813206Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 913206Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1013206Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1113206Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1213206Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1313206Sgabeblack@google.com * this software without specific prior written permission. 1413206Sgabeblack@google.com * 1513206Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1613206Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1713206Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1813206Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1913206Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2013206Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2113206Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2213206Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2313206Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2413206Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2513206Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2613206Sgabeblack@google.com * 2713206Sgabeblack@google.com * Authors: Gabe Black 2813206Sgabeblack@google.com */ 2913206Sgabeblack@google.com 3013206Sgabeblack@google.com#include "systemc/core/sensitivity.hh" 3113206Sgabeblack@google.com 3213206Sgabeblack@google.com#include "systemc/core/event.hh" 3313207Sgabeblack@google.com#include "systemc/core/port.hh" 3413208Sgabeblack@google.com#include "systemc/core/process.hh" 3513206Sgabeblack@google.com#include "systemc/core/scheduler.hh" 3613260Sgabeblack@google.com#include "systemc/ext/channel/sc_in.hh" 3713260Sgabeblack@google.com#include "systemc/ext/channel/sc_inout.hh" 3813260Sgabeblack@google.com#include "systemc/ext/channel/sc_out.hh" 3913206Sgabeblack@google.com#include "systemc/ext/core/sc_export.hh" 4013206Sgabeblack@google.com#include "systemc/ext/core/sc_interface.hh" 4113206Sgabeblack@google.com#include "systemc/ext/core/sc_port.hh" 4213206Sgabeblack@google.com 4313206Sgabeblack@google.comnamespace sc_gem5 4413206Sgabeblack@google.com{ 4513206Sgabeblack@google.com 4613207Sgabeblack@google.com/* 4713207Sgabeblack@google.com * Common sensitivity interface. 4813207Sgabeblack@google.com */ 4913207Sgabeblack@google.com 5013206Sgabeblack@google.comvoid 5113206Sgabeblack@google.comSensitivity::satisfy() 5213206Sgabeblack@google.com{ 5313206Sgabeblack@google.com process->satisfySensitivity(this); 5413206Sgabeblack@google.com} 5513206Sgabeblack@google.com 5613206Sgabeblack@google.combool 5713206Sgabeblack@google.comSensitivity::notify(Event *e) 5813206Sgabeblack@google.com{ 5913206Sgabeblack@google.com if (process->disabled()) 6013206Sgabeblack@google.com return false; 6113206Sgabeblack@google.com return notifyWork(e); 6213206Sgabeblack@google.com} 6313206Sgabeblack@google.com 6413208Sgabeblack@google.combool 6513208Sgabeblack@google.comSensitivity::ofMethod() 6613208Sgabeblack@google.com{ 6713208Sgabeblack@google.com return process->procKind() == sc_core::SC_METHOD_PROC_; 6813208Sgabeblack@google.com} 6913208Sgabeblack@google.com 7013206Sgabeblack@google.com 7113207Sgabeblack@google.com/* 7213207Sgabeblack@google.com * Dynamic vs. static sensitivity. 7313207Sgabeblack@google.com */ 7413207Sgabeblack@google.com 7513206Sgabeblack@google.comvoid 7613206Sgabeblack@google.comDynamicSensitivity::addToEvent(const ::sc_core::sc_event *e) 7713206Sgabeblack@google.com{ 7813206Sgabeblack@google.com Event::getFromScEvent(e)->addSensitivity(this); 7913206Sgabeblack@google.com} 8013206Sgabeblack@google.com 8113206Sgabeblack@google.comvoid 8213206Sgabeblack@google.comDynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e) 8313206Sgabeblack@google.com{ 8413206Sgabeblack@google.com Event::getFromScEvent(e)->delSensitivity(this); 8513206Sgabeblack@google.com} 8613206Sgabeblack@google.com 8713206Sgabeblack@google.comvoid 8813206Sgabeblack@google.comStaticSensitivity::addToEvent(const ::sc_core::sc_event *e) 8913206Sgabeblack@google.com{ 9013206Sgabeblack@google.com Event::getFromScEvent(e)->addSensitivity(this); 9113206Sgabeblack@google.com} 9213206Sgabeblack@google.com 9313206Sgabeblack@google.comvoid 9413206Sgabeblack@google.comStaticSensitivity::delFromEvent(const ::sc_core::sc_event *e) 9513206Sgabeblack@google.com{ 9613206Sgabeblack@google.com Event::getFromScEvent(e)->delSensitivity(this); 9713206Sgabeblack@google.com} 9813206Sgabeblack@google.com 9913260Sgabeblack@google.comvoid 10013260Sgabeblack@google.comResetSensitivity::addToEvent(const ::sc_core::sc_event *e) 10113260Sgabeblack@google.com{ 10213260Sgabeblack@google.com Event::getFromScEvent(e)->addSensitivity(this); 10313260Sgabeblack@google.com} 10413260Sgabeblack@google.com 10513260Sgabeblack@google.comvoid 10613260Sgabeblack@google.comResetSensitivity::delFromEvent(const ::sc_core::sc_event *e) 10713260Sgabeblack@google.com{ 10813260Sgabeblack@google.com Event::getFromScEvent(e)->delSensitivity(this); 10913260Sgabeblack@google.com} 11013260Sgabeblack@google.com 11113207Sgabeblack@google.com 11213207Sgabeblack@google.com/* 11313207Sgabeblack@google.com * Static sensitivities. 11413207Sgabeblack@google.com */ 11513207Sgabeblack@google.com 11613206Sgabeblack@google.comvoid 11713207Sgabeblack@google.comnewStaticSensitivityEvent(Process *p, const sc_core::sc_event *e) 11813206Sgabeblack@google.com{ 11913207Sgabeblack@google.com auto s = new StaticSensitivityEvent(p, e); 12013207Sgabeblack@google.com s->addToEvent(s->event); 12113207Sgabeblack@google.com p->addStatic(s); 12213206Sgabeblack@google.com} 12313206Sgabeblack@google.com 12413206Sgabeblack@google.comvoid 12513207Sgabeblack@google.comnewStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i) 12613206Sgabeblack@google.com{ 12713207Sgabeblack@google.com auto s = new StaticSensitivityInterface(p, i); 12813207Sgabeblack@google.com s->addToEvent(s->event); 12913207Sgabeblack@google.com p->addStatic(s); 13013206Sgabeblack@google.com} 13113206Sgabeblack@google.com 13213206Sgabeblack@google.comvoid 13313207Sgabeblack@google.comnewStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb) 13413206Sgabeblack@google.com{ 13513207Sgabeblack@google.com auto s = new StaticSensitivityPort(p); 13613207Sgabeblack@google.com Port *port = Port::fromPort(pb); 13713207Sgabeblack@google.com port->sensitive(s); 13813207Sgabeblack@google.com p->addStatic(s); 13913206Sgabeblack@google.com} 14013206Sgabeblack@google.com 14113206Sgabeblack@google.comvoid 14213207Sgabeblack@google.comnewStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp) 14313206Sgabeblack@google.com{ 14413207Sgabeblack@google.com auto s = new StaticSensitivityExport(p, exp); 14513207Sgabeblack@google.com s->addToEvent(s->event); 14613207Sgabeblack@google.com p->addStatic(s); 14713206Sgabeblack@google.com} 14813206Sgabeblack@google.com 14913207Sgabeblack@google.comvoid 15013207Sgabeblack@google.comnewStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) 15113207Sgabeblack@google.com{ 15213207Sgabeblack@google.com auto s = new StaticSensitivityFinder(p, f); 15313207Sgabeblack@google.com Port *port = Port::fromPort(f->port()); 15413207Sgabeblack@google.com port->sensitive(s); 15513207Sgabeblack@google.com p->addStatic(s); 15613207Sgabeblack@google.com} 15713207Sgabeblack@google.com 15813207Sgabeblack@google.com 15913207Sgabeblack@google.comStaticSensitivityInterface::StaticSensitivityInterface( 16013207Sgabeblack@google.com Process *p, const sc_core::sc_interface *i) : 16113207Sgabeblack@google.com Sensitivity(p), StaticSensitivity(p), 16213207Sgabeblack@google.com SensitivityEvent(p, &i->default_event()) 16313207Sgabeblack@google.com{} 16413207Sgabeblack@google.com 16513207Sgabeblack@google.comStaticSensitivityExport::StaticSensitivityExport( 16613207Sgabeblack@google.com Process *p, const sc_core::sc_export_base *exp) : 16713207Sgabeblack@google.com Sensitivity(p), StaticSensitivity(p), 16813207Sgabeblack@google.com SensitivityEvent(p, &exp->get_interface()->default_event()) 16913207Sgabeblack@google.com{} 17013207Sgabeblack@google.com 17113207Sgabeblack@google.comconst ::sc_core::sc_event & 17213207Sgabeblack@google.comStaticSensitivityFinder::find(::sc_core::sc_interface *i) 17313207Sgabeblack@google.com{ 17413207Sgabeblack@google.com return finder->find_event(i); 17513207Sgabeblack@google.com} 17613207Sgabeblack@google.com 17713207Sgabeblack@google.com 17813207Sgabeblack@google.com/* 17913207Sgabeblack@google.com * Dynamic sensitivities. 18013207Sgabeblack@google.com */ 18113207Sgabeblack@google.com 18213207Sgabeblack@google.comvoid 18313207Sgabeblack@google.comnewDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e) 18413207Sgabeblack@google.com{ 18513207Sgabeblack@google.com auto s = new DynamicSensitivityEvent(p, e); 18613207Sgabeblack@google.com s->addToEvent(s->event); 18713207Sgabeblack@google.com p->setDynamic(s); 18813207Sgabeblack@google.com} 18913207Sgabeblack@google.com 19013207Sgabeblack@google.comvoid 19113207Sgabeblack@google.comnewDynamicSensitivityEventOrList( 19213207Sgabeblack@google.com Process *p, const sc_core::sc_event_or_list *eol) 19313207Sgabeblack@google.com{ 19413207Sgabeblack@google.com auto s = new DynamicSensitivityEventOrList(p, eol); 19513207Sgabeblack@google.com for (auto event: s->events) 19613207Sgabeblack@google.com s->addToEvent(event); 19713207Sgabeblack@google.com p->setDynamic(s); 19813207Sgabeblack@google.com} 19913207Sgabeblack@google.com 20013207Sgabeblack@google.comvoid newDynamicSensitivityEventAndList( 20113207Sgabeblack@google.com Process *p, const sc_core::sc_event_and_list *eal) 20213207Sgabeblack@google.com{ 20313207Sgabeblack@google.com auto s = new DynamicSensitivityEventAndList(p, eal); 20413207Sgabeblack@google.com for (auto event: s->events) 20513207Sgabeblack@google.com s->addToEvent(event); 20613207Sgabeblack@google.com p->setDynamic(s); 20713207Sgabeblack@google.com} 20813207Sgabeblack@google.com 20913207Sgabeblack@google.com 21013207Sgabeblack@google.comDynamicSensitivityEventOrList::DynamicSensitivityEventOrList( 21113207Sgabeblack@google.com Process *p, const sc_core::sc_event_or_list *eol) : 21213207Sgabeblack@google.com Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eol->events) 21313207Sgabeblack@google.com{} 21413207Sgabeblack@google.com 21513206Sgabeblack@google.combool 21613206Sgabeblack@google.comDynamicSensitivityEventOrList::notifyWork(Event *e) 21713206Sgabeblack@google.com{ 21813206Sgabeblack@google.com events.erase(e->sc_event()); 21913206Sgabeblack@google.com 22013206Sgabeblack@google.com // All the other events need this deleted from their lists since this 22113206Sgabeblack@google.com // sensitivity has been satisfied without them triggering. 22213206Sgabeblack@google.com for (auto le: events) 22313206Sgabeblack@google.com delFromEvent(le); 22413206Sgabeblack@google.com 22513206Sgabeblack@google.com satisfy(); 22613206Sgabeblack@google.com return true; 22713206Sgabeblack@google.com} 22813206Sgabeblack@google.com 22913207Sgabeblack@google.comDynamicSensitivityEventAndList::DynamicSensitivityEventAndList( 23013207Sgabeblack@google.com Process *p, const sc_core::sc_event_and_list *eal) : 23113207Sgabeblack@google.com Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eal->events) 23213206Sgabeblack@google.com{} 23313206Sgabeblack@google.com 23413206Sgabeblack@google.combool 23513206Sgabeblack@google.comDynamicSensitivityEventAndList::notifyWork(Event *e) 23613206Sgabeblack@google.com{ 23713206Sgabeblack@google.com events.erase(e->sc_event()); 23813206Sgabeblack@google.com 23913206Sgabeblack@google.com // This sensitivity is satisfied if all events have triggered. 24013206Sgabeblack@google.com if (events.empty()) 24113206Sgabeblack@google.com satisfy(); 24213206Sgabeblack@google.com 24313206Sgabeblack@google.com return true; 24413206Sgabeblack@google.com} 24513206Sgabeblack@google.com 24613260Sgabeblack@google.com/* 24713260Sgabeblack@google.com * Reset sensitivities. 24813260Sgabeblack@google.com */ 24913260Sgabeblack@google.com 25013260Sgabeblack@google.comvoid 25113260Sgabeblack@google.comnewResetSensitivitySignal( 25213260Sgabeblack@google.com Process *p, const sc_core::sc_signal_in_if<bool> *signal, 25313260Sgabeblack@google.com bool val, bool sync) 25413260Sgabeblack@google.com{ 25513260Sgabeblack@google.com auto s = new ResetSensitivitySignal(p, signal, val, sync); 25613260Sgabeblack@google.com s->addToEvent(s->event); 25713260Sgabeblack@google.com p->addReset(s); 25813260Sgabeblack@google.com} 25913260Sgabeblack@google.com 26013260Sgabeblack@google.comvoid 26113260Sgabeblack@google.comnewResetSensitivityPort(Process *p, const sc_core::sc_in<bool> *port, 26213260Sgabeblack@google.com bool val, bool sync) 26313260Sgabeblack@google.com{ 26413260Sgabeblack@google.com auto s = new ResetSensitivityPort(p, port, val, sync); 26513260Sgabeblack@google.com Port::fromPort(port)->sensitive(s); 26613260Sgabeblack@google.com p->addReset(s); 26713260Sgabeblack@google.com} 26813260Sgabeblack@google.comvoid 26913260Sgabeblack@google.comnewResetSensitivityPort(Process *p, const sc_core::sc_inout<bool> *port, 27013260Sgabeblack@google.com bool val, bool sync) 27113260Sgabeblack@google.com{ 27213260Sgabeblack@google.com auto s = new ResetSensitivityPort(p, port, val, sync); 27313260Sgabeblack@google.com Port::fromPort(port)->sensitive(s); 27413260Sgabeblack@google.com p->addReset(s); 27513260Sgabeblack@google.com} 27613260Sgabeblack@google.comvoid 27713260Sgabeblack@google.comnewResetSensitivityPort(Process *p, const sc_core::sc_out<bool> *port, 27813260Sgabeblack@google.com bool val, bool sync) 27913260Sgabeblack@google.com{ 28013260Sgabeblack@google.com auto s = new ResetSensitivityPort(p, port, val, sync); 28113260Sgabeblack@google.com Port::fromPort(port)->sensitive(s); 28213260Sgabeblack@google.com p->addReset(s); 28313260Sgabeblack@google.com} 28413260Sgabeblack@google.com 28513260Sgabeblack@google.comResetSensitivitySignal::ResetSensitivitySignal( 28613260Sgabeblack@google.com Process *p, const sc_core::sc_signal_in_if<bool> *signal, 28713260Sgabeblack@google.com bool _val, bool _sync) : 28813260Sgabeblack@google.com Sensitivity(p), ResetSensitivity(p, _val, _sync), 28913260Sgabeblack@google.com SensitivityEvent(p, signal ? &signal->value_changed_event() : nullptr), 29013260Sgabeblack@google.com _signal(signal) 29113260Sgabeblack@google.com{ 29213260Sgabeblack@google.com if (signal && signal->read() == val()) 29313260Sgabeblack@google.com process->signalReset(true, sync()); 29413260Sgabeblack@google.com} 29513260Sgabeblack@google.com 29613260Sgabeblack@google.combool 29713260Sgabeblack@google.comResetSensitivitySignal::notifyWork(Event *e) 29813260Sgabeblack@google.com{ 29913260Sgabeblack@google.com process->signalReset(_signal->read() == val(), sync()); 30013260Sgabeblack@google.com return true; 30113260Sgabeblack@google.com} 30213260Sgabeblack@google.com 30313260Sgabeblack@google.comvoid 30413260Sgabeblack@google.comResetSensitivityPort::setSignal(const ::sc_core::sc_signal_in_if<bool> *signal) 30513260Sgabeblack@google.com{ 30613260Sgabeblack@google.com _signal = signal; 30713260Sgabeblack@google.com event = &_signal->value_changed_event(); 30813260Sgabeblack@google.com addToEvent(event); 30913260Sgabeblack@google.com if (signal->read() == val()) 31013260Sgabeblack@google.com process->signalReset(true, sync()); 31113260Sgabeblack@google.com} 31213260Sgabeblack@google.com 31313206Sgabeblack@google.com} // namespace sc_gem5 314