sensitivity.cc revision 13207
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"
3413206Sgabeblack@google.com#include "systemc/core/scheduler.hh"
3513206Sgabeblack@google.com#include "systemc/ext/core/sc_export.hh"
3613206Sgabeblack@google.com#include "systemc/ext/core/sc_interface.hh"
3713206Sgabeblack@google.com#include "systemc/ext/core/sc_port.hh"
3813206Sgabeblack@google.com
3913206Sgabeblack@google.comnamespace sc_gem5
4013206Sgabeblack@google.com{
4113206Sgabeblack@google.com
4213207Sgabeblack@google.com/*
4313207Sgabeblack@google.com * Common sensitivity interface.
4413207Sgabeblack@google.com */
4513207Sgabeblack@google.com
4613206Sgabeblack@google.comvoid
4713206Sgabeblack@google.comSensitivity::satisfy()
4813206Sgabeblack@google.com{
4913206Sgabeblack@google.com    process->satisfySensitivity(this);
5013206Sgabeblack@google.com}
5113206Sgabeblack@google.com
5213206Sgabeblack@google.combool
5313206Sgabeblack@google.comSensitivity::notify(Event *e)
5413206Sgabeblack@google.com{
5513206Sgabeblack@google.com    if (process->disabled())
5613206Sgabeblack@google.com        return false;
5713206Sgabeblack@google.com    return notifyWork(e);
5813206Sgabeblack@google.com}
5913206Sgabeblack@google.com
6013206Sgabeblack@google.com
6113207Sgabeblack@google.com/*
6213207Sgabeblack@google.com * Dynamic vs. static sensitivity.
6313207Sgabeblack@google.com */
6413207Sgabeblack@google.com
6513206Sgabeblack@google.comvoid
6613206Sgabeblack@google.comDynamicSensitivity::addToEvent(const ::sc_core::sc_event *e)
6713206Sgabeblack@google.com{
6813206Sgabeblack@google.com    Event::getFromScEvent(e)->addSensitivity(this);
6913206Sgabeblack@google.com}
7013206Sgabeblack@google.com
7113206Sgabeblack@google.comvoid
7213206Sgabeblack@google.comDynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e)
7313206Sgabeblack@google.com{
7413206Sgabeblack@google.com    Event::getFromScEvent(e)->delSensitivity(this);
7513206Sgabeblack@google.com}
7613206Sgabeblack@google.com
7713206Sgabeblack@google.comvoid
7813206Sgabeblack@google.comStaticSensitivity::addToEvent(const ::sc_core::sc_event *e)
7913206Sgabeblack@google.com{
8013206Sgabeblack@google.com    Event::getFromScEvent(e)->addSensitivity(this);
8113206Sgabeblack@google.com}
8213206Sgabeblack@google.com
8313206Sgabeblack@google.comvoid
8413206Sgabeblack@google.comStaticSensitivity::delFromEvent(const ::sc_core::sc_event *e)
8513206Sgabeblack@google.com{
8613206Sgabeblack@google.com    Event::getFromScEvent(e)->delSensitivity(this);
8713206Sgabeblack@google.com}
8813206Sgabeblack@google.com
8913207Sgabeblack@google.com
9013207Sgabeblack@google.com/*
9113207Sgabeblack@google.com * Static sensitivities.
9213207Sgabeblack@google.com */
9313207Sgabeblack@google.com
9413206Sgabeblack@google.comvoid
9513207Sgabeblack@google.comnewStaticSensitivityEvent(Process *p, const sc_core::sc_event *e)
9613206Sgabeblack@google.com{
9713207Sgabeblack@google.com    auto s = new StaticSensitivityEvent(p, e);
9813207Sgabeblack@google.com    s->addToEvent(s->event);
9913207Sgabeblack@google.com    p->addStatic(s);
10013206Sgabeblack@google.com}
10113206Sgabeblack@google.com
10213206Sgabeblack@google.comvoid
10313207Sgabeblack@google.comnewStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i)
10413206Sgabeblack@google.com{
10513207Sgabeblack@google.com    auto s = new StaticSensitivityInterface(p, i);
10613207Sgabeblack@google.com    s->addToEvent(s->event);
10713207Sgabeblack@google.com    p->addStatic(s);
10813206Sgabeblack@google.com}
10913206Sgabeblack@google.com
11013206Sgabeblack@google.comvoid
11113207Sgabeblack@google.comnewStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb)
11213206Sgabeblack@google.com{
11313207Sgabeblack@google.com    auto s = new StaticSensitivityPort(p);
11413207Sgabeblack@google.com    Port *port = Port::fromPort(pb);
11513207Sgabeblack@google.com    port->sensitive(s);
11613207Sgabeblack@google.com    p->addStatic(s);
11713206Sgabeblack@google.com}
11813206Sgabeblack@google.com
11913206Sgabeblack@google.comvoid
12013207Sgabeblack@google.comnewStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp)
12113206Sgabeblack@google.com{
12213207Sgabeblack@google.com    auto s = new StaticSensitivityExport(p, exp);
12313207Sgabeblack@google.com    s->addToEvent(s->event);
12413207Sgabeblack@google.com    p->addStatic(s);
12513206Sgabeblack@google.com}
12613206Sgabeblack@google.com
12713207Sgabeblack@google.comvoid
12813207Sgabeblack@google.comnewStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f)
12913207Sgabeblack@google.com{
13013207Sgabeblack@google.com    auto s = new StaticSensitivityFinder(p, f);
13113207Sgabeblack@google.com    Port *port = Port::fromPort(f->port());
13213207Sgabeblack@google.com    port->sensitive(s);
13313207Sgabeblack@google.com    p->addStatic(s);
13413207Sgabeblack@google.com}
13513207Sgabeblack@google.com
13613207Sgabeblack@google.com
13713207Sgabeblack@google.comStaticSensitivityInterface::StaticSensitivityInterface(
13813207Sgabeblack@google.com        Process *p, const sc_core::sc_interface *i) :
13913207Sgabeblack@google.com    Sensitivity(p), StaticSensitivity(p),
14013207Sgabeblack@google.com    SensitivityEvent(p, &i->default_event())
14113207Sgabeblack@google.com{}
14213207Sgabeblack@google.com
14313207Sgabeblack@google.comStaticSensitivityExport::StaticSensitivityExport(
14413207Sgabeblack@google.com        Process *p, const sc_core::sc_export_base *exp) :
14513207Sgabeblack@google.com    Sensitivity(p), StaticSensitivity(p),
14613207Sgabeblack@google.com    SensitivityEvent(p, &exp->get_interface()->default_event())
14713207Sgabeblack@google.com{}
14813207Sgabeblack@google.com
14913207Sgabeblack@google.comconst ::sc_core::sc_event &
15013207Sgabeblack@google.comStaticSensitivityFinder::find(::sc_core::sc_interface *i)
15113207Sgabeblack@google.com{
15213207Sgabeblack@google.com    return finder->find_event(i);
15313207Sgabeblack@google.com}
15413207Sgabeblack@google.com
15513207Sgabeblack@google.com
15613207Sgabeblack@google.com/*
15713207Sgabeblack@google.com * Dynamic sensitivities.
15813207Sgabeblack@google.com */
15913207Sgabeblack@google.com
16013207Sgabeblack@google.comvoid
16113207Sgabeblack@google.comnewDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e)
16213207Sgabeblack@google.com{
16313207Sgabeblack@google.com    auto s = new DynamicSensitivityEvent(p, e);
16413207Sgabeblack@google.com    s->addToEvent(s->event);
16513207Sgabeblack@google.com    p->setDynamic(s);
16613207Sgabeblack@google.com}
16713207Sgabeblack@google.com
16813207Sgabeblack@google.comvoid
16913207Sgabeblack@google.comnewDynamicSensitivityEventOrList(
17013207Sgabeblack@google.com        Process *p, const sc_core::sc_event_or_list *eol)
17113207Sgabeblack@google.com{
17213207Sgabeblack@google.com    auto s = new DynamicSensitivityEventOrList(p, eol);
17313207Sgabeblack@google.com    for (auto event: s->events)
17413207Sgabeblack@google.com        s->addToEvent(event);
17513207Sgabeblack@google.com    p->setDynamic(s);
17613207Sgabeblack@google.com}
17713207Sgabeblack@google.com
17813207Sgabeblack@google.comvoid newDynamicSensitivityEventAndList(
17913207Sgabeblack@google.com        Process *p, const sc_core::sc_event_and_list *eal)
18013207Sgabeblack@google.com{
18113207Sgabeblack@google.com    auto s = new DynamicSensitivityEventAndList(p, eal);
18213207Sgabeblack@google.com    for (auto event: s->events)
18313207Sgabeblack@google.com        s->addToEvent(event);
18413207Sgabeblack@google.com    p->setDynamic(s);
18513207Sgabeblack@google.com}
18613207Sgabeblack@google.com
18713207Sgabeblack@google.com
18813207Sgabeblack@google.comDynamicSensitivityEventOrList::DynamicSensitivityEventOrList(
18913207Sgabeblack@google.com        Process *p, const sc_core::sc_event_or_list *eol) :
19013207Sgabeblack@google.com    Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eol->events)
19113207Sgabeblack@google.com{}
19213207Sgabeblack@google.com
19313206Sgabeblack@google.combool
19413206Sgabeblack@google.comDynamicSensitivityEventOrList::notifyWork(Event *e)
19513206Sgabeblack@google.com{
19613206Sgabeblack@google.com    events.erase(e->sc_event());
19713206Sgabeblack@google.com
19813206Sgabeblack@google.com    // All the other events need this deleted from their lists since this
19913206Sgabeblack@google.com    // sensitivity has been satisfied without them triggering.
20013206Sgabeblack@google.com    for (auto le: events)
20113206Sgabeblack@google.com        delFromEvent(le);
20213206Sgabeblack@google.com
20313206Sgabeblack@google.com    satisfy();
20413206Sgabeblack@google.com    return true;
20513206Sgabeblack@google.com}
20613206Sgabeblack@google.com
20713207Sgabeblack@google.comDynamicSensitivityEventAndList::DynamicSensitivityEventAndList(
20813207Sgabeblack@google.com        Process *p, const sc_core::sc_event_and_list *eal) :
20913207Sgabeblack@google.com    Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eal->events)
21013206Sgabeblack@google.com{}
21113206Sgabeblack@google.com
21213206Sgabeblack@google.combool
21313206Sgabeblack@google.comDynamicSensitivityEventAndList::notifyWork(Event *e)
21413206Sgabeblack@google.com{
21513206Sgabeblack@google.com    events.erase(e->sc_event());
21613206Sgabeblack@google.com
21713206Sgabeblack@google.com    // This sensitivity is satisfied if all events have triggered.
21813206Sgabeblack@google.com    if (events.empty())
21913206Sgabeblack@google.com        satisfy();
22013206Sgabeblack@google.com
22113206Sgabeblack@google.com    return true;
22213206Sgabeblack@google.com}
22313206Sgabeblack@google.com
22413206Sgabeblack@google.com} // namespace sc_gem5
225