RubySlicc_Util.hh revision 6467
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/protocol/CacheMsg.hh" 476154Snate@binkert.org#include "mem/protocol/GenericRequestType.hh" 486154Snate@binkert.org#include "mem/protocol/CacheRequestType.hh" 496154Snate@binkert.org#include "mem/protocol/AccessType.hh" 506154Snate@binkert.org#include "mem/protocol/MachineType.hh" 516154Snate@binkert.org#include "mem/protocol/Directory_State.hh" 526154Snate@binkert.org#include "mem/protocol/L1Cache_State.hh" 536154Snate@binkert.org#include "mem/protocol/MessageSizeType.hh" 546154Snate@binkert.org#include "mem/ruby/network/Network.hh" 556154Snate@binkert.org#include "mem/protocol/PrefetchBit.hh" 566285Snate@binkert.org#include "mem/ruby/system/System.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{ 706285Snate@binkert.org if (RubySystem::getRandomization()) { 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 bool long_enough_ago(Time event) 1156145Snate@binkert.org{ 1166145Snate@binkert.org return ((get_time() - event) > 200); 1176145Snate@binkert.org} 1186145Snate@binkert.org 1196145Snate@binkert.orgextern inline int getAddThenMod(int addend1, int addend2, int modulus) 1206145Snate@binkert.org{ 1216145Snate@binkert.org return (addend1 + addend2) % modulus; 1226145Snate@binkert.org} 1236145Snate@binkert.org 1246145Snate@binkert.orgextern inline Time getTimeModInt(Time time, int modulus) 1256145Snate@binkert.org{ 1266145Snate@binkert.org return time % modulus; 1276145Snate@binkert.org} 1286145Snate@binkert.org 1296145Snate@binkert.orgextern inline Time getTimePlusInt(Time addend1, int addend2) 1306145Snate@binkert.org{ 1316145Snate@binkert.org return (Time) addend1 + addend2; 1326145Snate@binkert.org} 1336145Snate@binkert.org 1346145Snate@binkert.orgextern inline Time getTimeMinusTime(Time t1, Time t2) 1356145Snate@binkert.org{ 1366145Snate@binkert.org ASSERT(t1 >= t2); 1376145Snate@binkert.org return t1 - t2; 1386145Snate@binkert.org} 1396145Snate@binkert.org 1406145Snate@binkert.orgextern inline Time getPreviousDelayedCycles(Time t1, Time t2) 1416145Snate@binkert.org{ 1426285Snate@binkert.org if (RubySystem::getRandomization()) { // when randomizing delayed 1436145Snate@binkert.org return 0; 1446145Snate@binkert.org } else { 1456145Snate@binkert.org return getTimeMinusTime(t1, t2); 1466145Snate@binkert.org } 1476145Snate@binkert.org} 1486145Snate@binkert.org 1496145Snate@binkert.orgextern inline void WARN_ERROR_TIME(Time time) 1506145Snate@binkert.org{ 1516145Snate@binkert.org WARN_EXPR(time); 1526145Snate@binkert.org} 1536145Snate@binkert.org 1546145Snate@binkert.org// Return type for time_to_int is "Time" and not "int" so we get a 64-bit integer 1556145Snate@binkert.orgextern inline Time time_to_int(Time time) 1566145Snate@binkert.org{ 1576145Snate@binkert.org return time; 1586145Snate@binkert.org} 1596145Snate@binkert.org 1606145Snate@binkert.org// Appends an offset to an address 1616145Snate@binkert.orgextern inline Address setOffset(Address addr, int offset) 1626145Snate@binkert.org{ 1636145Snate@binkert.org Address result = addr; 1646145Snate@binkert.org result.setOffset(offset); 1656145Snate@binkert.org return result; 1666145Snate@binkert.org} 1676145Snate@binkert.org 1686145Snate@binkert.org// Makes an address into a line address 1696145Snate@binkert.orgextern inline Address makeLineAddress(Address addr) 1706145Snate@binkert.org{ 1716145Snate@binkert.org Address result = addr; 1726145Snate@binkert.org result.makeLineAddress(); 1736145Snate@binkert.org return result; 1746145Snate@binkert.org} 1756145Snate@binkert.org 1766467Sdrh5@cs.wisc.eduextern inline int addressOffset(Address addr) 1776467Sdrh5@cs.wisc.edu{ 1786467Sdrh5@cs.wisc.edu return addr.getOffset(); 1796467Sdrh5@cs.wisc.edu} 1806467Sdrh5@cs.wisc.edu 1816145Snate@binkert.org#endif //SLICC_UTIL_H 182