RubySlicc_Util.hh revision 7039
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org */ 286145Snate@binkert.org 296145Snate@binkert.org/* 307039Snate@binkert.org * These are the functions that exported to slicc from ruby. 316145Snate@binkert.org */ 326145Snate@binkert.org 337039Snate@binkert.org#ifndef __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__ 347039Snate@binkert.org#define __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__ 356145Snate@binkert.org 367039Snate@binkert.org#include "mem/protocol/AccessType.hh" 377039Snate@binkert.org#include "mem/protocol/CacheMsg.hh" 387039Snate@binkert.org#include "mem/protocol/CacheRequestType.hh" 397039Snate@binkert.org#include "mem/protocol/Directory_State.hh" 407039Snate@binkert.org#include "mem/protocol/GenericRequestType.hh" 417039Snate@binkert.org#include "mem/protocol/L1Cache_State.hh" 427039Snate@binkert.org#include "mem/protocol/MachineType.hh" 437039Snate@binkert.org#include "mem/protocol/MessageSizeType.hh" 447039Snate@binkert.org#include "mem/protocol/PrefetchBit.hh" 457039Snate@binkert.org#include "mem/ruby/common/Address.hh" 466154Snate@binkert.org#include "mem/ruby/common/Global.hh" 477039Snate@binkert.org#include "mem/ruby/network/Network.hh" 487039Snate@binkert.org#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh" 497039Snate@binkert.org#include "mem/ruby/system/MachineID.hh" 506154Snate@binkert.org#include "mem/ruby/system/NodeID.hh" 516285Snate@binkert.org#include "mem/ruby/system/System.hh" 526145Snate@binkert.org 536145Snate@binkert.orgclass Set; 546145Snate@binkert.orgclass NetDest; 556145Snate@binkert.org 567039Snate@binkert.orginline int 577039Snate@binkert.orgrandom(int n) 586145Snate@binkert.org{ 596145Snate@binkert.org return random() % n; 606145Snate@binkert.org} 616145Snate@binkert.org 627039Snate@binkert.orginline bool 637039Snate@binkert.orgmulticast_retry() 646145Snate@binkert.org{ 657039Snate@binkert.org if (RubySystem::getRandomization()) { 667039Snate@binkert.org return (random() & 0x1); 677039Snate@binkert.org } else { 687039Snate@binkert.org return true; 697039Snate@binkert.org } 706145Snate@binkert.org} 716145Snate@binkert.org 727039Snate@binkert.orginline int 737039Snate@binkert.orgcache_state_to_int(L1Cache_State state) 746145Snate@binkert.org{ 757039Snate@binkert.org return state; 766145Snate@binkert.org} 776145Snate@binkert.org 787039Snate@binkert.orginline Time 797039Snate@binkert.orgget_time() 806145Snate@binkert.org{ 817039Snate@binkert.org return g_eventQueue_ptr->getTime(); 826145Snate@binkert.org} 836145Snate@binkert.org 847039Snate@binkert.orginline Time 857039Snate@binkert.orgzero_time() 866145Snate@binkert.org{ 877039Snate@binkert.org return 0; 886145Snate@binkert.org} 896145Snate@binkert.org 907039Snate@binkert.orginline NodeID 917039Snate@binkert.orgintToID(int nodenum) 926145Snate@binkert.org{ 937039Snate@binkert.org NodeID id = nodenum; 947039Snate@binkert.org return id; 956145Snate@binkert.org} 966145Snate@binkert.org 977039Snate@binkert.orginline int 987039Snate@binkert.orgIDToInt(NodeID id) 996145Snate@binkert.org{ 1007039Snate@binkert.org int nodenum = id; 1017039Snate@binkert.org return nodenum; 1026145Snate@binkert.org} 1036145Snate@binkert.org 1047039Snate@binkert.orginline int 1057039Snate@binkert.orgaddressToInt(Address addr) 1066145Snate@binkert.org{ 1077039Snate@binkert.org return (int)addr.getLineAddress(); 1086145Snate@binkert.org} 1096145Snate@binkert.org 1107039Snate@binkert.orginline bool 1117039Snate@binkert.orglong_enough_ago(Time event) 1126145Snate@binkert.org{ 1137039Snate@binkert.org return ((get_time() - event) > 200); 1146145Snate@binkert.org} 1156145Snate@binkert.org 1167039Snate@binkert.orginline int 1177039Snate@binkert.orggetAddThenMod(int addend1, int addend2, int modulus) 1186145Snate@binkert.org{ 1197039Snate@binkert.org return (addend1 + addend2) % modulus; 1206145Snate@binkert.org} 1216145Snate@binkert.org 1227039Snate@binkert.orginline Time 1237039Snate@binkert.orggetTimeModInt(Time time, int modulus) 1246145Snate@binkert.org{ 1257039Snate@binkert.org return time % modulus; 1266145Snate@binkert.org} 1276145Snate@binkert.org 1287039Snate@binkert.orginline Time 1297039Snate@binkert.orggetTimePlusInt(Time addend1, int addend2) 1306145Snate@binkert.org{ 1317039Snate@binkert.org return (Time) addend1 + addend2; 1326145Snate@binkert.org} 1336145Snate@binkert.org 1347039Snate@binkert.orginline Time 1357039Snate@binkert.orggetTimeMinusTime(Time t1, Time t2) 1366145Snate@binkert.org{ 1377039Snate@binkert.org ASSERT(t1 >= t2); 1387039Snate@binkert.org return t1 - t2; 1396145Snate@binkert.org} 1406145Snate@binkert.org 1417039Snate@binkert.orginline Time 1427039Snate@binkert.orggetPreviousDelayedCycles(Time t1, Time t2) 1436145Snate@binkert.org{ 1447039Snate@binkert.org if (RubySystem::getRandomization()) { // when randomizing delayed 1457039Snate@binkert.org return 0; 1467039Snate@binkert.org } else { 1477039Snate@binkert.org return getTimeMinusTime(t1, t2); 1487039Snate@binkert.org } 1496145Snate@binkert.org} 1506145Snate@binkert.org 1517039Snate@binkert.orginline void 1527039Snate@binkert.orgWARN_ERROR_TIME(Time time) 1536145Snate@binkert.org{ 1547039Snate@binkert.org WARN_EXPR(time); 1556145Snate@binkert.org} 1566145Snate@binkert.org 1577039Snate@binkert.org// Return type for time_to_int is "Time" and not "int" so we get a 1587039Snate@binkert.org// 64-bit integer 1597039Snate@binkert.orginline Time 1607039Snate@binkert.orgtime_to_int(Time time) 1616145Snate@binkert.org{ 1627039Snate@binkert.org return time; 1636145Snate@binkert.org} 1646145Snate@binkert.org 1656145Snate@binkert.org// Appends an offset to an address 1667039Snate@binkert.orginline Address 1677039Snate@binkert.orgsetOffset(Address addr, int offset) 1686145Snate@binkert.org{ 1697039Snate@binkert.org Address result = addr; 1707039Snate@binkert.org result.setOffset(offset); 1717039Snate@binkert.org return result; 1726145Snate@binkert.org} 1736145Snate@binkert.org 1746145Snate@binkert.org// Makes an address into a line address 1757039Snate@binkert.orginline Address 1767039Snate@binkert.orgmakeLineAddress(Address addr) 1776145Snate@binkert.org{ 1787039Snate@binkert.org Address result = addr; 1797039Snate@binkert.org result.makeLineAddress(); 1807039Snate@binkert.org return result; 1816145Snate@binkert.org} 1826145Snate@binkert.org 1837039Snate@binkert.orginline int 1847039Snate@binkert.orgaddressOffset(Address addr) 1856467Sdrh5@cs.wisc.edu{ 1867039Snate@binkert.org return addr.getOffset(); 1876467Sdrh5@cs.wisc.edu} 1886467Sdrh5@cs.wisc.edu 1897039Snate@binkert.org#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__ 190