RubySlicc_Util.hh revision 6285
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/* 316284Snate@binkert.org * slicc_util.hh 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" 576285Snate@binkert.org#include "mem/ruby/system/System.hh" 586145Snate@binkert.org 596154Snate@binkert.org#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh" 606145Snate@binkert.org 616145Snate@binkert.orgclass Set; 626145Snate@binkert.orgclass NetDest; 636145Snate@binkert.org 646145Snate@binkert.orgextern inline int random(int n) 656145Snate@binkert.org{ 666145Snate@binkert.org return random() % n; 676145Snate@binkert.org} 686145Snate@binkert.org 696145Snate@binkert.orgextern inline bool multicast_retry() 706145Snate@binkert.org{ 716285Snate@binkert.org if (RubySystem::getRandomization()) { 726145Snate@binkert.org return (random() & 0x1); 736145Snate@binkert.org } else { 746145Snate@binkert.org return true; 756145Snate@binkert.org } 766145Snate@binkert.org} 776145Snate@binkert.org 786145Snate@binkert.orgextern inline int cache_state_to_int(L1Cache_State state) 796145Snate@binkert.org{ 806145Snate@binkert.org return state; 816145Snate@binkert.org} 826145Snate@binkert.org 836145Snate@binkert.orgextern inline Time get_time() 846145Snate@binkert.org{ 856145Snate@binkert.org return g_eventQueue_ptr->getTime(); 866145Snate@binkert.org} 876145Snate@binkert.org 886145Snate@binkert.orgextern inline Time zero_time() 896145Snate@binkert.org{ 906145Snate@binkert.org return 0; 916145Snate@binkert.org} 926145Snate@binkert.org 936145Snate@binkert.orgextern inline NodeID intToID(int nodenum) 946145Snate@binkert.org{ 956145Snate@binkert.org NodeID id = nodenum; 966145Snate@binkert.org return id; 976145Snate@binkert.org} 986145Snate@binkert.org 996145Snate@binkert.orgextern inline int IDToInt(NodeID id) 1006145Snate@binkert.org{ 1016145Snate@binkert.org int nodenum = id; 1026145Snate@binkert.org return nodenum; 1036145Snate@binkert.org} 1046145Snate@binkert.org 1056145Snate@binkert.orgextern inline int addressToInt(Address addr) 1066145Snate@binkert.org{ 1076145Snate@binkert.org return (int) addr.getLineAddress(); 1086145Snate@binkert.org} 1096145Snate@binkert.org 1106145Snate@binkert.orgextern inline int MessageSizeTypeToInt(MessageSizeType size_type) 1116145Snate@binkert.org{ 1126145Snate@binkert.org return MessageSizeType_to_int(size_type); 1136145Snate@binkert.org} 1146145Snate@binkert.org 1156285Snate@binkert.org/* 1166145Snate@binkert.orgextern inline int numberOfNodes() 1176145Snate@binkert.org{ 1186145Snate@binkert.org return RubyConfig::numberOfChips(); 1196145Snate@binkert.org} 1206285Snate@binkert.org*/ 1216285Snate@binkert.org/* 1226145Snate@binkert.orgextern inline int numberOfL1CachePerChip() 1236145Snate@binkert.org{ 1246285Snate@binkert.org return RubyConfig::getNumberOfCachesPerLevelPerChip(1,0); 1256145Snate@binkert.org} 1266285Snate@binkert.org*/ 1276145Snate@binkert.org 1286145Snate@binkert.orgextern inline bool long_enough_ago(Time event) 1296145Snate@binkert.org{ 1306145Snate@binkert.org return ((get_time() - event) > 200); 1316145Snate@binkert.org} 1326145Snate@binkert.org 1336145Snate@binkert.orgextern inline int getAddThenMod(int addend1, int addend2, int modulus) 1346145Snate@binkert.org{ 1356145Snate@binkert.org return (addend1 + addend2) % modulus; 1366145Snate@binkert.org} 1376145Snate@binkert.org 1386145Snate@binkert.orgextern inline Time getTimeModInt(Time time, int modulus) 1396145Snate@binkert.org{ 1406145Snate@binkert.org return time % modulus; 1416145Snate@binkert.org} 1426145Snate@binkert.org 1436145Snate@binkert.orgextern inline Time getTimePlusInt(Time addend1, int addend2) 1446145Snate@binkert.org{ 1456145Snate@binkert.org return (Time) addend1 + addend2; 1466145Snate@binkert.org} 1476145Snate@binkert.org 1486145Snate@binkert.orgextern inline Time getTimeMinusTime(Time t1, Time t2) 1496145Snate@binkert.org{ 1506145Snate@binkert.org ASSERT(t1 >= t2); 1516145Snate@binkert.org return t1 - t2; 1526145Snate@binkert.org} 1536145Snate@binkert.org 1546145Snate@binkert.orgextern inline Time getPreviousDelayedCycles(Time t1, Time t2) 1556145Snate@binkert.org{ 1566285Snate@binkert.org if (RubySystem::getRandomization()) { // when randomizing delayed 1576145Snate@binkert.org return 0; 1586145Snate@binkert.org } else { 1596145Snate@binkert.org return getTimeMinusTime(t1, t2); 1606145Snate@binkert.org } 1616145Snate@binkert.org} 1626145Snate@binkert.org 1636145Snate@binkert.orgextern inline void WARN_ERROR_TIME(Time time) 1646145Snate@binkert.org{ 1656145Snate@binkert.org WARN_EXPR(time); 1666145Snate@binkert.org} 1676145Snate@binkert.org 1686145Snate@binkert.org// Return type for time_to_int is "Time" and not "int" so we get a 64-bit integer 1696145Snate@binkert.orgextern inline Time time_to_int(Time time) 1706145Snate@binkert.org{ 1716145Snate@binkert.org return time; 1726145Snate@binkert.org} 1736145Snate@binkert.org 1746285Snate@binkert.org/* 1756145Snate@binkert.orgextern inline bool getFilteringEnabled() 1766145Snate@binkert.org{ 1776285Snate@binkert.org return RubyConfig::getFilteringEnabled(); 1786145Snate@binkert.org} 1796145Snate@binkert.org 1806285Snate@binkert.org 1816145Snate@binkert.orgextern inline int getRetryThreshold() 1826145Snate@binkert.org{ 1836285Snate@binkert.org return RubyConfig::getRetryThreshold(); 1846145Snate@binkert.org} 1856145Snate@binkert.org 1866145Snate@binkert.orgextern inline int getFixedTimeoutLatency() 1876145Snate@binkert.org{ 1886285Snate@binkert.org return RubyConfig::getFixedTimeoutLatency(); 1896145Snate@binkert.org} 1906145Snate@binkert.org 1916145Snate@binkert.orgextern inline int N_tokens() 1926145Snate@binkert.org{ 1936145Snate@binkert.org // return N+1 to handle clean writeback 1946285Snate@binkert.org return RubyConfig::getProcsPerChip() + 1; 1956145Snate@binkert.org // return 1; 1966145Snate@binkert.org} 1976145Snate@binkert.org 1986145Snate@binkert.orgextern inline bool distributedPersistentEnabled() 1996145Snate@binkert.org{ 2006285Snate@binkert.org return RubyConfig::getDistributedPersistentEnabled(); 2016145Snate@binkert.org} 2026145Snate@binkert.org 2036145Snate@binkert.orgextern inline bool getDynamicTimeoutEnabled() 2046145Snate@binkert.org{ 2056285Snate@binkert.org return RubyConfig::getDynamicTimeoutEnabled(); 2066145Snate@binkert.org} 2076285Snate@binkert.org*/ 2086145Snate@binkert.org// Appends an offset to an address 2096145Snate@binkert.orgextern inline Address setOffset(Address addr, int offset) 2106145Snate@binkert.org{ 2116145Snate@binkert.org Address result = addr; 2126145Snate@binkert.org result.setOffset(offset); 2136145Snate@binkert.org return result; 2146145Snate@binkert.org} 2156145Snate@binkert.org 2166145Snate@binkert.org// Makes an address into a line address 2176145Snate@binkert.orgextern inline Address makeLineAddress(Address addr) 2186145Snate@binkert.org{ 2196145Snate@binkert.org Address result = addr; 2206145Snate@binkert.org result.makeLineAddress(); 2216145Snate@binkert.org return result; 2226145Snate@binkert.org} 2236145Snate@binkert.org 2246145Snate@binkert.org#endif //SLICC_UTIL_H 225