RubySlicc_Util.hh revision 6154:6bb54dcb940e
12810Srdreslin@umich.edu
212719Snikos.nikoleris@arm.com/*
38702Sandreas.hansson@arm.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
48702Sandreas.hansson@arm.com * All rights reserved.
58702Sandreas.hansson@arm.com *
68702Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without
78702Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are
88702Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright
98702Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer;
108702Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright
118702Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the
128702Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution;
138702Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its
142810Srdreslin@umich.edu * contributors may be used to endorse or promote products derived from
152810Srdreslin@umich.edu * this software without specific prior written permission.
162810Srdreslin@umich.edu *
172810Srdreslin@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182810Srdreslin@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192810Srdreslin@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202810Srdreslin@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212810Srdreslin@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222810Srdreslin@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232810Srdreslin@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242810Srdreslin@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252810Srdreslin@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262810Srdreslin@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272810Srdreslin@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282810Srdreslin@umich.edu */
292810Srdreslin@umich.edu
302810Srdreslin@umich.edu/*
312810Srdreslin@umich.edu * slicc_util.h
322810Srdreslin@umich.edu *
332810Srdreslin@umich.edu * Description: These are the functions that exported to slicc from ruby.
342810Srdreslin@umich.edu *
352810Srdreslin@umich.edu * $Id$
362810Srdreslin@umich.edu *
372810Srdreslin@umich.edu */
382810Srdreslin@umich.edu
392810Srdreslin@umich.edu#ifndef SLICC_UTIL_H
402810Srdreslin@umich.edu#define SLICC_UTIL_H
412810Srdreslin@umich.edu
422810Srdreslin@umich.edu#include "mem/ruby/common/Global.hh"
434458Sstever@eecs.umich.edu#include "mem/ruby/common/Address.hh"
448856Sandreas.hansson@arm.com#include "mem/ruby/system/NodeID.hh"
452810Srdreslin@umich.edu#include "mem/ruby/system/MachineID.hh"
462810Srdreslin@umich.edu#include "mem/ruby/config/RubyConfig.hh"
472810Srdreslin@umich.edu#include "mem/protocol/CacheMsg.hh"
482810Srdreslin@umich.edu#include "mem/protocol/GenericRequestType.hh"
492810Srdreslin@umich.edu#include "mem/protocol/CacheRequestType.hh"
502810Srdreslin@umich.edu#include "mem/protocol/AccessType.hh"
512810Srdreslin@umich.edu#include "mem/protocol/MachineType.hh"
5211051Sandreas.hansson@arm.com#include "mem/protocol/Directory_State.hh"
5311051Sandreas.hansson@arm.com#include "mem/protocol/L1Cache_State.hh"
542810Srdreslin@umich.edu#include "mem/protocol/MessageSizeType.hh"
5511859Sandreas.hansson@arm.com#include "mem/ruby/network/Network.hh"
5611859Sandreas.hansson@arm.com#include "mem/protocol/PrefetchBit.hh"
5712334Sgabeblack@google.com
5811197Sandreas.hansson@arm.com#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh"
595338Sstever@gmail.com
605338Sstever@gmail.comclass Set;
615338Sstever@gmail.comclass NetDest;
6210815Sdavid.guillen@arm.com
6311053Sandreas.hansson@arm.comextern inline int random(int n)
644458Sstever@eecs.umich.edu{
654458Sstever@eecs.umich.edu  return random() % n;
662813Srdreslin@umich.edu}
673861Sstever@eecs.umich.edu
682810Srdreslin@umich.eduextern inline bool multicast_retry()
692810Srdreslin@umich.edu{
702810Srdreslin@umich.edu  if (RANDOMIZATION) {
712810Srdreslin@umich.edu    return (random() & 0x1);
729264Sdjordje.kovacevic@arm.com  } else {
732810Srdreslin@umich.edu    return true;
742810Srdreslin@umich.edu  }
752810Srdreslin@umich.edu}
762810Srdreslin@umich.edu
772810Srdreslin@umich.eduextern inline int cache_state_to_int(L1Cache_State state)
788856Sandreas.hansson@arm.com{
798856Sandreas.hansson@arm.com  return state;
808856Sandreas.hansson@arm.com}
818856Sandreas.hansson@arm.com
828856Sandreas.hansson@arm.comextern inline Time get_time()
833738Sstever@eecs.umich.edu{
848856Sandreas.hansson@arm.com  return g_eventQueue_ptr->getTime();
853738Sstever@eecs.umich.edu}
868856Sandreas.hansson@arm.com
8710815Sdavid.guillen@arm.comextern inline Time zero_time()
883738Sstever@eecs.umich.edu{
898856Sandreas.hansson@arm.com  return 0;
904478Sstever@eecs.umich.edu}
918975Sandreas.hansson@arm.com
928948Sandreas.hansson@arm.comextern inline NodeID intToID(int nodenum)
9312343Snikos.nikoleris@arm.com{
9412343Snikos.nikoleris@arm.com  NodeID id = nodenum;
958975Sandreas.hansson@arm.com  return id;
963738Sstever@eecs.umich.edu}
973738Sstever@eecs.umich.edu
983738Sstever@eecs.umich.eduextern inline int IDToInt(NodeID id)
993738Sstever@eecs.umich.edu{
1008856Sandreas.hansson@arm.com  int nodenum = id;
1019090Sandreas.hansson@arm.com  return nodenum;
1028856Sandreas.hansson@arm.com}
1038856Sandreas.hansson@arm.com
1048856Sandreas.hansson@arm.comextern inline int addressToInt(Address addr)
10510815Sdavid.guillen@arm.com{
1068856Sandreas.hansson@arm.com  return (int) addr.getLineAddress();
1078856Sandreas.hansson@arm.com}
1083738Sstever@eecs.umich.edu
1093738Sstever@eecs.umich.eduextern inline int MessageSizeTypeToInt(MessageSizeType size_type)
1108856Sandreas.hansson@arm.com{
1118914Sandreas.hansson@arm.com  return MessageSizeType_to_int(size_type);
1128914Sandreas.hansson@arm.com}
1138914Sandreas.hansson@arm.com
1148914Sandreas.hansson@arm.comextern inline int numberOfNodes()
1158914Sandreas.hansson@arm.com{
11610713Sandreas.hansson@arm.com  return RubyConfig::numberOfChips();
1178914Sandreas.hansson@arm.com}
1188914Sandreas.hansson@arm.com
1198914Sandreas.hansson@arm.comextern inline int numberOfL1CachePerChip()
1208914Sandreas.hansson@arm.com{
12110815Sdavid.guillen@arm.com  return RubyConfig::numberOfL1CachePerChip();
12210713Sandreas.hansson@arm.com}
1238914Sandreas.hansson@arm.com
1248914Sandreas.hansson@arm.comextern inline bool long_enough_ago(Time event)
1258914Sandreas.hansson@arm.com{
12610815Sdavid.guillen@arm.com  return ((get_time() - event) > 200);
12710713Sandreas.hansson@arm.com}
12810713Sandreas.hansson@arm.com
12910713Sandreas.hansson@arm.comextern inline int getAddThenMod(int addend1, int addend2, int modulus)
13010713Sandreas.hansson@arm.com{
1318914Sandreas.hansson@arm.com  return (addend1 + addend2) % modulus;
1328914Sandreas.hansson@arm.com}
1338914Sandreas.hansson@arm.com
1348914Sandreas.hansson@arm.comextern inline Time getTimeModInt(Time time, int modulus)
1358914Sandreas.hansson@arm.com{
1368914Sandreas.hansson@arm.com  return time % modulus;
1378914Sandreas.hansson@arm.com}
1388914Sandreas.hansson@arm.com
13911375Sandreas.hansson@arm.comextern inline Time getTimePlusInt(Time addend1, int addend2)
14011375Sandreas.hansson@arm.com{
14111375Sandreas.hansson@arm.com  return (Time) addend1 + addend2;
14211375Sandreas.hansson@arm.com}
14311375Sandreas.hansson@arm.com
14411375Sandreas.hansson@arm.comextern inline Time getTimeMinusTime(Time t1, Time t2)
14511375Sandreas.hansson@arm.com{
14611375Sandreas.hansson@arm.com  ASSERT(t1 >= t2);
14711375Sandreas.hansson@arm.com  return t1 - t2;
14811375Sandreas.hansson@arm.com}
14911375Sandreas.hansson@arm.com
15011375Sandreas.hansson@arm.comextern inline Time getPreviousDelayedCycles(Time t1, Time t2)
15111375Sandreas.hansson@arm.com{
15211375Sandreas.hansson@arm.com  if (RANDOMIZATION) {  // when randomizing delayed
15311375Sandreas.hansson@arm.com    return 0;
15411375Sandreas.hansson@arm.com  } else {
15511375Sandreas.hansson@arm.com    return getTimeMinusTime(t1, t2);
1568914Sandreas.hansson@arm.com  }
1578914Sandreas.hansson@arm.com}
1588914Sandreas.hansson@arm.com
1598856Sandreas.hansson@arm.comextern inline void WARN_ERROR_TIME(Time time)
1608856Sandreas.hansson@arm.com{
1618856Sandreas.hansson@arm.com  WARN_EXPR(time);
1628856Sandreas.hansson@arm.com}
1633738Sstever@eecs.umich.edu
1648856Sandreas.hansson@arm.com// Return type for time_to_int is "Time" and not "int" so we get a 64-bit integer
1653738Sstever@eecs.umich.eduextern inline Time time_to_int(Time time)
1668914Sandreas.hansson@arm.com{
16710713Sandreas.hansson@arm.com  return time;
16810713Sandreas.hansson@arm.com}
16910713Sandreas.hansson@arm.com
1708914Sandreas.hansson@arm.com
1718856Sandreas.hansson@arm.comextern inline bool getFilteringEnabled()
17210815Sdavid.guillen@arm.com{
1733738Sstever@eecs.umich.edu  return g_FILTERING_ENABLED;
1748856Sandreas.hansson@arm.com}
1754478Sstever@eecs.umich.edu
1768975Sandreas.hansson@arm.comextern inline int getRetryThreshold()
1778948Sandreas.hansson@arm.com{
1788975Sandreas.hansson@arm.com  return g_RETRY_THRESHOLD;
1793738Sstever@eecs.umich.edu}
1808948Sandreas.hansson@arm.com
1813738Sstever@eecs.umich.eduextern inline int getFixedTimeoutLatency()
1828948Sandreas.hansson@arm.com{
1834458Sstever@eecs.umich.edu  return g_FIXED_TIMEOUT_LATENCY;
1848856Sandreas.hansson@arm.com}
1858856Sandreas.hansson@arm.com
18610815Sdavid.guillen@arm.comextern inline int N_tokens()
1878856Sandreas.hansson@arm.com{
1883738Sstever@eecs.umich.edu  // return N+1 to handle clean writeback
1893738Sstever@eecs.umich.edu  return g_PROCS_PER_CHIP + 1;
1902810Srdreslin@umich.edu  // return 1;
19110815Sdavid.guillen@arm.com}
1924626Sstever@eecs.umich.edu
1932810Srdreslin@umich.eduextern inline bool distributedPersistentEnabled()
1943861Sstever@eecs.umich.edu{
1952810Srdreslin@umich.edu  return g_DISTRIBUTED_PERSISTENT_ENABLED;
1964671Sstever@eecs.umich.edu}
19710815Sdavid.guillen@arm.com
1984671Sstever@eecs.umich.eduextern inline bool getDynamicTimeoutEnabled()
1992810Srdreslin@umich.edu{
2005707Shsul@eecs.umich.edu  return g_DYNAMIC_TIMEOUT_ENABLED;
2013860Sstever@eecs.umich.edu}
2023860Sstever@eecs.umich.edu
2033860Sstever@eecs.umich.edu// Appends an offset to an address
2045875Ssteve.reinhardt@amd.comextern inline Address setOffset(Address addr, int offset)
20510345SCurtis.Dunham@arm.com{
20610345SCurtis.Dunham@arm.com  Address result = addr;
20710345SCurtis.Dunham@arm.com  result.setOffset(offset);
20810345SCurtis.Dunham@arm.com  return result;
20910345SCurtis.Dunham@arm.com}
2105875Ssteve.reinhardt@amd.com
2115875Ssteve.reinhardt@amd.com// Makes an address into a line address
2125875Ssteve.reinhardt@amd.comextern inline Address makeLineAddress(Address addr)
2133860Sstever@eecs.umich.edu{
21411197Sandreas.hansson@arm.com  Address result = addr;
21511197Sandreas.hansson@arm.com  result.makeLineAddress();
21611197Sandreas.hansson@arm.com  return result;
21711197Sandreas.hansson@arm.com}
21811197Sandreas.hansson@arm.com
21911197Sandreas.hansson@arm.com#endif //SLICC_UTIL_H
22011197Sandreas.hansson@arm.com