RubySlicc_Util.hh revision 6154
16145Snate@binkert.org
26145Snate@binkert.org/*
36145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
46145Snate@binkert.org * All rights reserved.
56145Snate@binkert.org *
66145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
76145Snate@binkert.org * modification, are permitted provided that the following conditions are
86145Snate@binkert.org * met: redistributions of source code must retain the above copyright
96145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
106145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
116145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
126145Snate@binkert.org * documentation and/or other materials provided with the distribution;
136145Snate@binkert.org * neither the name of the copyright holders nor the names of its
146145Snate@binkert.org * contributors may be used to endorse or promote products derived from
156145Snate@binkert.org * this software without specific prior written permission.
166145Snate@binkert.org *
176145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286145Snate@binkert.org */
296145Snate@binkert.org
306145Snate@binkert.org/*
316145Snate@binkert.org * slicc_util.h
326145Snate@binkert.org *
336145Snate@binkert.org * Description: These are the functions that exported to slicc from ruby.
346145Snate@binkert.org *
356145Snate@binkert.org * $Id$
366145Snate@binkert.org *
376145Snate@binkert.org */
386145Snate@binkert.org
396145Snate@binkert.org#ifndef SLICC_UTIL_H
406145Snate@binkert.org#define SLICC_UTIL_H
416145Snate@binkert.org
426154Snate@binkert.org#include "mem/ruby/common/Global.hh"
436154Snate@binkert.org#include "mem/ruby/common/Address.hh"
446154Snate@binkert.org#include "mem/ruby/system/NodeID.hh"
456154Snate@binkert.org#include "mem/ruby/system/MachineID.hh"
466154Snate@binkert.org#include "mem/ruby/config/RubyConfig.hh"
476154Snate@binkert.org#include "mem/protocol/CacheMsg.hh"
486154Snate@binkert.org#include "mem/protocol/GenericRequestType.hh"
496154Snate@binkert.org#include "mem/protocol/CacheRequestType.hh"
506154Snate@binkert.org#include "mem/protocol/AccessType.hh"
516154Snate@binkert.org#include "mem/protocol/MachineType.hh"
526154Snate@binkert.org#include "mem/protocol/Directory_State.hh"
536154Snate@binkert.org#include "mem/protocol/L1Cache_State.hh"
546154Snate@binkert.org#include "mem/protocol/MessageSizeType.hh"
556154Snate@binkert.org#include "mem/ruby/network/Network.hh"
566154Snate@binkert.org#include "mem/protocol/PrefetchBit.hh"
576145Snate@binkert.org
586154Snate@binkert.org#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh"
596145Snate@binkert.org
606145Snate@binkert.orgclass Set;
616145Snate@binkert.orgclass NetDest;
626145Snate@binkert.org
636145Snate@binkert.orgextern inline int random(int n)
646145Snate@binkert.org{
656145Snate@binkert.org  return random() % n;
666145Snate@binkert.org}
676145Snate@binkert.org
686145Snate@binkert.orgextern inline bool multicast_retry()
696145Snate@binkert.org{
706145Snate@binkert.org  if (RANDOMIZATION) {
716145Snate@binkert.org    return (random() & 0x1);
726145Snate@binkert.org  } else {
736145Snate@binkert.org    return true;
746145Snate@binkert.org  }
756145Snate@binkert.org}
766145Snate@binkert.org
776145Snate@binkert.orgextern inline int cache_state_to_int(L1Cache_State state)
786145Snate@binkert.org{
796145Snate@binkert.org  return state;
806145Snate@binkert.org}
816145Snate@binkert.org
826145Snate@binkert.orgextern inline Time get_time()
836145Snate@binkert.org{
846145Snate@binkert.org  return g_eventQueue_ptr->getTime();
856145Snate@binkert.org}
866145Snate@binkert.org
876145Snate@binkert.orgextern inline Time zero_time()
886145Snate@binkert.org{
896145Snate@binkert.org  return 0;
906145Snate@binkert.org}
916145Snate@binkert.org
926145Snate@binkert.orgextern inline NodeID intToID(int nodenum)
936145Snate@binkert.org{
946145Snate@binkert.org  NodeID id = nodenum;
956145Snate@binkert.org  return id;
966145Snate@binkert.org}
976145Snate@binkert.org
986145Snate@binkert.orgextern inline int IDToInt(NodeID id)
996145Snate@binkert.org{
1006145Snate@binkert.org  int nodenum = id;
1016145Snate@binkert.org  return nodenum;
1026145Snate@binkert.org}
1036145Snate@binkert.org
1046145Snate@binkert.orgextern inline int addressToInt(Address addr)
1056145Snate@binkert.org{
1066145Snate@binkert.org  return (int) addr.getLineAddress();
1076145Snate@binkert.org}
1086145Snate@binkert.org
1096145Snate@binkert.orgextern inline int MessageSizeTypeToInt(MessageSizeType size_type)
1106145Snate@binkert.org{
1116145Snate@binkert.org  return MessageSizeType_to_int(size_type);
1126145Snate@binkert.org}
1136145Snate@binkert.org
1146145Snate@binkert.orgextern inline int numberOfNodes()
1156145Snate@binkert.org{
1166145Snate@binkert.org  return RubyConfig::numberOfChips();
1176145Snate@binkert.org}
1186145Snate@binkert.org
1196145Snate@binkert.orgextern inline int numberOfL1CachePerChip()
1206145Snate@binkert.org{
1216145Snate@binkert.org  return RubyConfig::numberOfL1CachePerChip();
1226145Snate@binkert.org}
1236145Snate@binkert.org
1246145Snate@binkert.orgextern inline bool long_enough_ago(Time event)
1256145Snate@binkert.org{
1266145Snate@binkert.org  return ((get_time() - event) > 200);
1276145Snate@binkert.org}
1286145Snate@binkert.org
1296145Snate@binkert.orgextern inline int getAddThenMod(int addend1, int addend2, int modulus)
1306145Snate@binkert.org{
1316145Snate@binkert.org  return (addend1 + addend2) % modulus;
1326145Snate@binkert.org}
1336145Snate@binkert.org
1346145Snate@binkert.orgextern inline Time getTimeModInt(Time time, int modulus)
1356145Snate@binkert.org{
1366145Snate@binkert.org  return time % modulus;
1376145Snate@binkert.org}
1386145Snate@binkert.org
1396145Snate@binkert.orgextern inline Time getTimePlusInt(Time addend1, int addend2)
1406145Snate@binkert.org{
1416145Snate@binkert.org  return (Time) addend1 + addend2;
1426145Snate@binkert.org}
1436145Snate@binkert.org
1446145Snate@binkert.orgextern inline Time getTimeMinusTime(Time t1, Time t2)
1456145Snate@binkert.org{
1466145Snate@binkert.org  ASSERT(t1 >= t2);
1476145Snate@binkert.org  return t1 - t2;
1486145Snate@binkert.org}
1496145Snate@binkert.org
1506145Snate@binkert.orgextern inline Time getPreviousDelayedCycles(Time t1, Time t2)
1516145Snate@binkert.org{
1526145Snate@binkert.org  if (RANDOMIZATION) {  // when randomizing delayed
1536145Snate@binkert.org    return 0;
1546145Snate@binkert.org  } else {
1556145Snate@binkert.org    return getTimeMinusTime(t1, t2);
1566145Snate@binkert.org  }
1576145Snate@binkert.org}
1586145Snate@binkert.org
1596145Snate@binkert.orgextern inline void WARN_ERROR_TIME(Time time)
1606145Snate@binkert.org{
1616145Snate@binkert.org  WARN_EXPR(time);
1626145Snate@binkert.org}
1636145Snate@binkert.org
1646145Snate@binkert.org// Return type for time_to_int is "Time" and not "int" so we get a 64-bit integer
1656145Snate@binkert.orgextern inline Time time_to_int(Time time)
1666145Snate@binkert.org{
1676145Snate@binkert.org  return time;
1686145Snate@binkert.org}
1696145Snate@binkert.org
1706145Snate@binkert.org
1716145Snate@binkert.orgextern inline bool getFilteringEnabled()
1726145Snate@binkert.org{
1736145Snate@binkert.org  return g_FILTERING_ENABLED;
1746145Snate@binkert.org}
1756145Snate@binkert.org
1766145Snate@binkert.orgextern inline int getRetryThreshold()
1776145Snate@binkert.org{
1786145Snate@binkert.org  return g_RETRY_THRESHOLD;
1796145Snate@binkert.org}
1806145Snate@binkert.org
1816145Snate@binkert.orgextern inline int getFixedTimeoutLatency()
1826145Snate@binkert.org{
1836145Snate@binkert.org  return g_FIXED_TIMEOUT_LATENCY;
1846145Snate@binkert.org}
1856145Snate@binkert.org
1866145Snate@binkert.orgextern inline int N_tokens()
1876145Snate@binkert.org{
1886145Snate@binkert.org  // return N+1 to handle clean writeback
1896145Snate@binkert.org  return g_PROCS_PER_CHIP + 1;
1906145Snate@binkert.org  // return 1;
1916145Snate@binkert.org}
1926145Snate@binkert.org
1936145Snate@binkert.orgextern inline bool distributedPersistentEnabled()
1946145Snate@binkert.org{
1956145Snate@binkert.org  return g_DISTRIBUTED_PERSISTENT_ENABLED;
1966145Snate@binkert.org}
1976145Snate@binkert.org
1986145Snate@binkert.orgextern inline bool getDynamicTimeoutEnabled()
1996145Snate@binkert.org{
2006145Snate@binkert.org  return g_DYNAMIC_TIMEOUT_ENABLED;
2016145Snate@binkert.org}
2026145Snate@binkert.org
2036145Snate@binkert.org// Appends an offset to an address
2046145Snate@binkert.orgextern inline Address setOffset(Address addr, int offset)
2056145Snate@binkert.org{
2066145Snate@binkert.org  Address result = addr;
2076145Snate@binkert.org  result.setOffset(offset);
2086145Snate@binkert.org  return result;
2096145Snate@binkert.org}
2106145Snate@binkert.org
2116145Snate@binkert.org// Makes an address into a line address
2126145Snate@binkert.orgextern inline Address makeLineAddress(Address addr)
2136145Snate@binkert.org{
2146145Snate@binkert.org  Address result = addr;
2156145Snate@binkert.org  result.makeLineAddress();
2166145Snate@binkert.org  return result;
2176145Snate@binkert.org}
2186145Snate@binkert.org
2196145Snate@binkert.org#endif //SLICC_UTIL_H
220