sensitivity.hh 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#ifndef __SYSTEMC_CORE_SENSITIVITY_HH__ 3113206Sgabeblack@google.com#define __SYSTEMC_CORE_SENSITIVITY_HH__ 3213206Sgabeblack@google.com 3313206Sgabeblack@google.com#include <set> 3413206Sgabeblack@google.com#include <vector> 3513206Sgabeblack@google.com 3613206Sgabeblack@google.com#include "sim/eventq.hh" 3713206Sgabeblack@google.com#include "systemc/core/sched_event.hh" 3813206Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh" 3913260Sgabeblack@google.com#include "systemc/ext/core/sc_port.hh" 4013206Sgabeblack@google.com 4113206Sgabeblack@google.comnamespace sc_core 4213206Sgabeblack@google.com{ 4313206Sgabeblack@google.com 4413206Sgabeblack@google.comclass sc_event; 4513206Sgabeblack@google.comclass sc_event_and_list; 4613206Sgabeblack@google.comclass sc_event_or_list; 4713206Sgabeblack@google.comclass sc_event_finder; 4813206Sgabeblack@google.comclass sc_export_base; 4913206Sgabeblack@google.comclass sc_interface; 5013206Sgabeblack@google.comclass sc_port_base; 5113206Sgabeblack@google.com 5213206Sgabeblack@google.com} // namespace sc_core 5313206Sgabeblack@google.com 5413206Sgabeblack@google.comnamespace sc_gem5 5513206Sgabeblack@google.com{ 5613206Sgabeblack@google.com 5713206Sgabeblack@google.comclass Process; 5813206Sgabeblack@google.comclass Event; 5913206Sgabeblack@google.com 6013206Sgabeblack@google.com/* 6113206Sgabeblack@google.com * Common sensitivity interface. 6213206Sgabeblack@google.com */ 6313206Sgabeblack@google.com 6413206Sgabeblack@google.comclass Sensitivity 6513206Sgabeblack@google.com{ 6613206Sgabeblack@google.com protected: 6713206Sgabeblack@google.com Process *process; 6813206Sgabeblack@google.com 6913206Sgabeblack@google.com Sensitivity(Process *p) : process(p) {} 7013206Sgabeblack@google.com virtual ~Sensitivity() {} 7113206Sgabeblack@google.com 7213206Sgabeblack@google.com virtual void addToEvent(const ::sc_core::sc_event *e) = 0; 7313206Sgabeblack@google.com virtual void delFromEvent(const ::sc_core::sc_event *e) = 0; 7413206Sgabeblack@google.com 7513206Sgabeblack@google.com virtual bool 7613206Sgabeblack@google.com notifyWork(Event *e) 7713206Sgabeblack@google.com { 7813206Sgabeblack@google.com satisfy(); 7913206Sgabeblack@google.com return true; 8013206Sgabeblack@google.com } 8113206Sgabeblack@google.com 8213206Sgabeblack@google.com public: 8313206Sgabeblack@google.com virtual void clear() = 0; 8413206Sgabeblack@google.com 8513206Sgabeblack@google.com void satisfy(); 8613206Sgabeblack@google.com bool notify(Event *e); 8713206Sgabeblack@google.com 8813260Sgabeblack@google.com enum Category 8913260Sgabeblack@google.com { 9013260Sgabeblack@google.com Static, 9113260Sgabeblack@google.com Dynamic, 9213260Sgabeblack@google.com Reset 9313260Sgabeblack@google.com }; 9413260Sgabeblack@google.com 9513260Sgabeblack@google.com virtual Category category() = 0; 9613208Sgabeblack@google.com 9713208Sgabeblack@google.com bool ofMethod(); 9813206Sgabeblack@google.com}; 9913206Sgabeblack@google.com 10013206Sgabeblack@google.com 10113206Sgabeblack@google.com/* 10213260Sgabeblack@google.com * Dynamic vs. static vs. reset sensitivity. 10313206Sgabeblack@google.com */ 10413206Sgabeblack@google.com 10513206Sgabeblack@google.comclass DynamicSensitivity : virtual public Sensitivity 10613206Sgabeblack@google.com{ 10713206Sgabeblack@google.com protected: 10813206Sgabeblack@google.com DynamicSensitivity(Process *p) : Sensitivity(p) {} 10913206Sgabeblack@google.com 11013206Sgabeblack@google.com void addToEvent(const ::sc_core::sc_event *e) override; 11113206Sgabeblack@google.com void delFromEvent(const ::sc_core::sc_event *e) override; 11213206Sgabeblack@google.com 11313206Sgabeblack@google.com public: 11413260Sgabeblack@google.com Category category() override { return Dynamic; } 11513206Sgabeblack@google.com}; 11613206Sgabeblack@google.com 11713206Sgabeblack@google.comtypedef std::vector<DynamicSensitivity *> DynamicSensitivities; 11813206Sgabeblack@google.com 11913206Sgabeblack@google.com 12013206Sgabeblack@google.comclass StaticSensitivity : virtual public Sensitivity 12113206Sgabeblack@google.com{ 12213206Sgabeblack@google.com protected: 12313206Sgabeblack@google.com StaticSensitivity(Process *p) : Sensitivity(p) {} 12413206Sgabeblack@google.com 12513206Sgabeblack@google.com void addToEvent(const ::sc_core::sc_event *e) override; 12613206Sgabeblack@google.com void delFromEvent(const ::sc_core::sc_event *e) override; 12713206Sgabeblack@google.com 12813206Sgabeblack@google.com public: 12913260Sgabeblack@google.com Category category() override { return Static; } 13013206Sgabeblack@google.com}; 13113206Sgabeblack@google.com 13213206Sgabeblack@google.comtypedef std::vector<StaticSensitivity *> StaticSensitivities; 13313206Sgabeblack@google.com 13413260Sgabeblack@google.comclass ResetSensitivity : virtual public Sensitivity 13513260Sgabeblack@google.com{ 13613260Sgabeblack@google.com private: 13713260Sgabeblack@google.com bool _val; 13813260Sgabeblack@google.com bool _sync; 13913260Sgabeblack@google.com 14013260Sgabeblack@google.com protected: 14113260Sgabeblack@google.com ResetSensitivity(Process *p, bool _val, bool _sync) : 14213260Sgabeblack@google.com Sensitivity(p), _val(_val), _sync(_sync) 14313260Sgabeblack@google.com {} 14413260Sgabeblack@google.com 14513260Sgabeblack@google.com void addToEvent(const ::sc_core::sc_event *e) override; 14613260Sgabeblack@google.com void delFromEvent(const ::sc_core::sc_event *e) override; 14713260Sgabeblack@google.com 14813260Sgabeblack@google.com bool val() { return _val; } 14913260Sgabeblack@google.com bool sync() { return _sync; } 15013260Sgabeblack@google.com 15113260Sgabeblack@google.com public: 15213260Sgabeblack@google.com Category category() override { return Reset; } 15313260Sgabeblack@google.com}; 15413260Sgabeblack@google.com 15513260Sgabeblack@google.comtypedef std::vector<ResetSensitivity *> ResetSensitivities; 15613260Sgabeblack@google.com 15713206Sgabeblack@google.com 15813206Sgabeblack@google.com/* 15913207Sgabeblack@google.com * Sensitivity to an event or events, which can be static or dynamic. 16013206Sgabeblack@google.com */ 16113206Sgabeblack@google.com 16213206Sgabeblack@google.comclass SensitivityEvent : virtual public Sensitivity 16313206Sgabeblack@google.com{ 16413206Sgabeblack@google.com protected: 16513206Sgabeblack@google.com const ::sc_core::sc_event *event; 16613206Sgabeblack@google.com 16713206Sgabeblack@google.com SensitivityEvent(Process *p, const ::sc_core::sc_event *e=nullptr) : 16813206Sgabeblack@google.com Sensitivity(p), event(e) 16913206Sgabeblack@google.com {} 17013206Sgabeblack@google.com 17113206Sgabeblack@google.com public: 17213206Sgabeblack@google.com void clear() override { delFromEvent(event); } 17313206Sgabeblack@google.com}; 17413206Sgabeblack@google.com 17513207Sgabeblack@google.comclass SensitivityEvents : virtual public Sensitivity 17613207Sgabeblack@google.com{ 17713207Sgabeblack@google.com protected: 17813207Sgabeblack@google.com std::set<const ::sc_core::sc_event *> events; 17913207Sgabeblack@google.com 18013207Sgabeblack@google.com SensitivityEvents(Process *p) : Sensitivity(p) {} 18113207Sgabeblack@google.com SensitivityEvents( 18213207Sgabeblack@google.com Process *p, const std::set<const ::sc_core::sc_event *> &s) : 18313207Sgabeblack@google.com Sensitivity(p), events(s) 18413207Sgabeblack@google.com {} 18513207Sgabeblack@google.com 18613207Sgabeblack@google.com public: 18713207Sgabeblack@google.com void 18813207Sgabeblack@google.com clear() override 18913207Sgabeblack@google.com { 19013207Sgabeblack@google.com for (auto event: events) 19113207Sgabeblack@google.com delFromEvent(event); 19213207Sgabeblack@google.com } 19313207Sgabeblack@google.com 19413207Sgabeblack@google.com void 19513207Sgabeblack@google.com addEvent(const ::sc_core::sc_event *event) 19613207Sgabeblack@google.com { 19713207Sgabeblack@google.com events.insert(event); 19813207Sgabeblack@google.com addToEvent(event); 19913207Sgabeblack@google.com } 20013207Sgabeblack@google.com}; 20113207Sgabeblack@google.com 20213206Sgabeblack@google.com 20313206Sgabeblack@google.com/* 20413206Sgabeblack@google.com * Static sensitivities. 20513206Sgabeblack@google.com */ 20613206Sgabeblack@google.com 20713207Sgabeblack@google.comvoid newStaticSensitivityEvent(Process *p, const sc_core::sc_event *e); 20813207Sgabeblack@google.comvoid newStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i); 20913207Sgabeblack@google.comvoid newStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb); 21013207Sgabeblack@google.comvoid newStaticSensitivityExport( 21113207Sgabeblack@google.com Process *p, const sc_core::sc_export_base *exp); 21213207Sgabeblack@google.comvoid newStaticSensitivityFinder( 21313207Sgabeblack@google.com Process *p, const sc_core::sc_event_finder *f); 21413207Sgabeblack@google.com 21513207Sgabeblack@google.com 21613206Sgabeblack@google.comclass StaticSensitivityEvent : 21713206Sgabeblack@google.com public StaticSensitivity, public SensitivityEvent 21813206Sgabeblack@google.com{ 21913207Sgabeblack@google.com friend void newStaticSensitivityEvent( 22013207Sgabeblack@google.com Process *p, const sc_core::sc_event *e); 22113207Sgabeblack@google.com 22213207Sgabeblack@google.com protected: 22313206Sgabeblack@google.com StaticSensitivityEvent(Process *p, const sc_core::sc_event *e) : 22413206Sgabeblack@google.com Sensitivity(p), StaticSensitivity(p), SensitivityEvent(p, e) 22513206Sgabeblack@google.com {} 22613206Sgabeblack@google.com}; 22713206Sgabeblack@google.com 22813206Sgabeblack@google.comclass StaticSensitivityInterface : 22913206Sgabeblack@google.com public StaticSensitivity, public SensitivityEvent 23013206Sgabeblack@google.com{ 23113207Sgabeblack@google.com friend void newStaticSensitivityInterface( 23213207Sgabeblack@google.com Process *p, const sc_core::sc_interface *i); 23313207Sgabeblack@google.com protected: 23413207Sgabeblack@google.com StaticSensitivityInterface(Process *p, const sc_core::sc_interface *i); 23513206Sgabeblack@google.com}; 23613206Sgabeblack@google.com 23713207Sgabeblack@google.comclass StaticSensitivityPort : 23813207Sgabeblack@google.com public StaticSensitivity, public SensitivityEvents 23913206Sgabeblack@google.com{ 24013207Sgabeblack@google.com friend void newStaticSensitivityPort( 24113207Sgabeblack@google.com Process *p, const sc_core::sc_port_base *pb); 24213206Sgabeblack@google.com 24313207Sgabeblack@google.com protected: 24413207Sgabeblack@google.com StaticSensitivityPort(Process *p) : 24513207Sgabeblack@google.com Sensitivity(p), StaticSensitivity(p), SensitivityEvents(p) 24613206Sgabeblack@google.com {} 24713206Sgabeblack@google.com}; 24813206Sgabeblack@google.com 24913206Sgabeblack@google.comclass StaticSensitivityExport : 25013206Sgabeblack@google.com public StaticSensitivity, public SensitivityEvent 25113206Sgabeblack@google.com{ 25213206Sgabeblack@google.com private: 25313207Sgabeblack@google.com friend void newStaticSensitivityExport( 25413207Sgabeblack@google.com Process *p, const sc_core::sc_export_base *exp); 25513207Sgabeblack@google.com 25613207Sgabeblack@google.com StaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp); 25713207Sgabeblack@google.com}; 25813207Sgabeblack@google.com 25913207Sgabeblack@google.com 26013207Sgabeblack@google.comclass StaticSensitivityFinder : 26113207Sgabeblack@google.com public StaticSensitivity, public SensitivityEvents 26213207Sgabeblack@google.com{ 26313207Sgabeblack@google.com private: 26413207Sgabeblack@google.com const sc_core::sc_event_finder *finder; 26513207Sgabeblack@google.com 26613207Sgabeblack@google.com friend void newStaticSensitivityFinder( 26713207Sgabeblack@google.com Process *p, const sc_core::sc_event_finder *f); 26813207Sgabeblack@google.com 26913207Sgabeblack@google.com StaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) : 27013207Sgabeblack@google.com Sensitivity(p), StaticSensitivity(p), SensitivityEvents(p), finder(f) 27113207Sgabeblack@google.com {} 27213206Sgabeblack@google.com 27313206Sgabeblack@google.com public: 27413207Sgabeblack@google.com const ::sc_core::sc_event &find(::sc_core::sc_interface *i); 27513206Sgabeblack@google.com}; 27613206Sgabeblack@google.com 27713206Sgabeblack@google.com 27813206Sgabeblack@google.com/* 27913206Sgabeblack@google.com * Dynamic sensitivities. 28013206Sgabeblack@google.com */ 28113206Sgabeblack@google.com 28213207Sgabeblack@google.comvoid newDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e); 28313207Sgabeblack@google.comvoid newDynamicSensitivityEventOrList( 28413207Sgabeblack@google.com Process *p, const sc_core::sc_event_or_list *eol); 28513207Sgabeblack@google.comvoid newDynamicSensitivityEventAndList( 28613207Sgabeblack@google.com Process *p, const sc_core::sc_event_and_list *eal); 28713207Sgabeblack@google.com 28813206Sgabeblack@google.comclass DynamicSensitivityEvent : 28913206Sgabeblack@google.com public DynamicSensitivity, public SensitivityEvent 29013206Sgabeblack@google.com{ 29113207Sgabeblack@google.com private: 29213207Sgabeblack@google.com friend void newDynamicSensitivityEvent( 29313207Sgabeblack@google.com Process *p, const sc_core::sc_event *e); 29413207Sgabeblack@google.com 29513206Sgabeblack@google.com DynamicSensitivityEvent(Process *p, const sc_core::sc_event *e) : 29613206Sgabeblack@google.com Sensitivity(p), DynamicSensitivity(p), SensitivityEvent(p, e) 29713206Sgabeblack@google.com {} 29813206Sgabeblack@google.com}; 29913206Sgabeblack@google.com 30013207Sgabeblack@google.comclass DynamicSensitivityEventOrList : 30113207Sgabeblack@google.com public DynamicSensitivity, public SensitivityEvents 30213206Sgabeblack@google.com{ 30313206Sgabeblack@google.com private: 30413207Sgabeblack@google.com friend void newDynamicSensitivityEventOrList( 30513207Sgabeblack@google.com Process *p, const sc_core::sc_event_or_list *eol); 30613206Sgabeblack@google.com 30713206Sgabeblack@google.com DynamicSensitivityEventOrList( 30813206Sgabeblack@google.com Process *p, const sc_core::sc_event_or_list *eol); 30913206Sgabeblack@google.com 31013207Sgabeblack@google.com bool notifyWork(Event *e) override; 31113206Sgabeblack@google.com}; 31213206Sgabeblack@google.com 31313206Sgabeblack@google.com//XXX This sensitivity can't be reused. To reset it, it has to be deleted and 31413206Sgabeblack@google.com//recreated. That works for dynamic sensitivities, but not for static. 31513206Sgabeblack@google.com//Fortunately processes can't be statically sensitive to sc_event_and_lists. 31613207Sgabeblack@google.comclass DynamicSensitivityEventAndList : 31713207Sgabeblack@google.com public DynamicSensitivity, public SensitivityEvents 31813206Sgabeblack@google.com{ 31913206Sgabeblack@google.com private: 32013207Sgabeblack@google.com friend void newDynamicSensitivityEventAndList( 32113207Sgabeblack@google.com Process *p, const sc_core::sc_event_and_list *eal); 32213206Sgabeblack@google.com 32313206Sgabeblack@google.com DynamicSensitivityEventAndList( 32413206Sgabeblack@google.com Process *p, const sc_core::sc_event_and_list *eal); 32513206Sgabeblack@google.com 32613207Sgabeblack@google.com bool notifyWork(Event *e) override; 32713206Sgabeblack@google.com}; 32813206Sgabeblack@google.com 32913260Sgabeblack@google.com/* 33013260Sgabeblack@google.com * Reset sensitivities. 33113260Sgabeblack@google.com */ 33213260Sgabeblack@google.com 33313260Sgabeblack@google.comvoid newResetSensitivitySignal( 33413260Sgabeblack@google.com Process *p, const sc_core::sc_signal_in_if<bool> *signal, 33513260Sgabeblack@google.com bool val, bool sync); 33613260Sgabeblack@google.com 33713260Sgabeblack@google.comvoid newResetSensitivityPort( 33813260Sgabeblack@google.com Process *p, const sc_core::sc_in<bool> *port, bool val, bool sync); 33913260Sgabeblack@google.comvoid newResetSensitivityPort( 34013260Sgabeblack@google.com Process *p, const sc_core::sc_inout<bool> *port, bool val, bool sync); 34113260Sgabeblack@google.comvoid newResetSensitivityPort( 34213260Sgabeblack@google.com Process *p, const sc_core::sc_out<bool> *port, bool val, bool sync); 34313260Sgabeblack@google.com 34413260Sgabeblack@google.comclass ResetSensitivitySignal : 34513260Sgabeblack@google.com public ResetSensitivity, public SensitivityEvent 34613260Sgabeblack@google.com{ 34713260Sgabeblack@google.com protected: 34813260Sgabeblack@google.com const sc_core::sc_signal_in_if<bool> *_signal; 34913260Sgabeblack@google.com 35013260Sgabeblack@google.com friend void newResetSensitivitySignal( 35113260Sgabeblack@google.com Process *p, const sc_core::sc_signal_in_if<bool> *signal, 35213260Sgabeblack@google.com bool val, bool sync); 35313260Sgabeblack@google.com 35413260Sgabeblack@google.com ResetSensitivitySignal( 35513260Sgabeblack@google.com Process *p, const sc_core::sc_signal_in_if<bool> *signal, 35613260Sgabeblack@google.com bool _val, bool _sync); 35713260Sgabeblack@google.com 35813260Sgabeblack@google.com bool notifyWork(Event *e) override; 35913260Sgabeblack@google.com}; 36013260Sgabeblack@google.com 36113260Sgabeblack@google.comclass ResetSensitivityPort : public ResetSensitivitySignal 36213260Sgabeblack@google.com{ 36313260Sgabeblack@google.com private: 36413260Sgabeblack@google.com friend void newResetSensitivityPort( 36513260Sgabeblack@google.com Process *p, const sc_core::sc_in<bool> *port, bool val, bool sync); 36613260Sgabeblack@google.com friend void newResetSensitivityPort( 36713260Sgabeblack@google.com Process *p, const sc_core::sc_inout<bool> *port, 36813260Sgabeblack@google.com bool val, bool sync); 36913260Sgabeblack@google.com friend void newResetSensitivityPort( 37013260Sgabeblack@google.com Process *p, const sc_core::sc_out<bool> *port, 37113260Sgabeblack@google.com bool val, bool sync); 37213260Sgabeblack@google.com 37313260Sgabeblack@google.com ResetSensitivityPort( 37413260Sgabeblack@google.com Process *p, const sc_core::sc_port_base *port, 37513260Sgabeblack@google.com bool _val, bool _sync) : 37613260Sgabeblack@google.com Sensitivity(p), ResetSensitivitySignal(p, nullptr, _val, _sync) 37713260Sgabeblack@google.com {} 37813260Sgabeblack@google.com 37913260Sgabeblack@google.com public: 38013260Sgabeblack@google.com void setSignal(const ::sc_core::sc_signal_in_if<bool> *signal); 38113260Sgabeblack@google.com}; 38213260Sgabeblack@google.com 38313206Sgabeblack@google.com} // namespace sc_gem5 38413206Sgabeblack@google.com 38513206Sgabeblack@google.com#endif //__SYSTEMC_CORE_SENSITIVITY_HH__ 386