RubySlicc_Util.hh revision 8131
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 367832Snate@binkert.org#include <cassert> 377832Snate@binkert.org 387039Snate@binkert.org#include "mem/protocol/AccessType.hh" 397039Snate@binkert.org#include "mem/protocol/CacheMsg.hh" 407039Snate@binkert.org#include "mem/protocol/CacheRequestType.hh" 417039Snate@binkert.org#include "mem/protocol/Directory_State.hh" 427039Snate@binkert.org#include "mem/protocol/GenericRequestType.hh" 437039Snate@binkert.org#include "mem/protocol/L1Cache_State.hh" 447039Snate@binkert.org#include "mem/protocol/MachineType.hh" 457039Snate@binkert.org#include "mem/protocol/MessageSizeType.hh" 467039Snate@binkert.org#include "mem/protocol/PrefetchBit.hh" 477039Snate@binkert.org#include "mem/ruby/common/Address.hh" 486154Snate@binkert.org#include "mem/ruby/common/Global.hh" 497039Snate@binkert.org#include "mem/ruby/network/Network.hh" 507039Snate@binkert.org#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh" 517039Snate@binkert.org#include "mem/ruby/system/MachineID.hh" 526154Snate@binkert.org#include "mem/ruby/system/NodeID.hh" 536285Snate@binkert.org#include "mem/ruby/system/System.hh" 546145Snate@binkert.org 556145Snate@binkert.orgclass Set; 566145Snate@binkert.orgclass NetDest; 576145Snate@binkert.org 587039Snate@binkert.orginline int 597039Snate@binkert.orgrandom(int n) 606145Snate@binkert.org{ 616145Snate@binkert.org return random() % n; 626145Snate@binkert.org} 636145Snate@binkert.org 647039Snate@binkert.orginline bool 657039Snate@binkert.orgmulticast_retry() 666145Snate@binkert.org{ 677039Snate@binkert.org if (RubySystem::getRandomization()) { 687039Snate@binkert.org return (random() & 0x1); 697039Snate@binkert.org } else { 707039Snate@binkert.org return true; 717039Snate@binkert.org } 726145Snate@binkert.org} 736145Snate@binkert.org 747039Snate@binkert.orginline int 757039Snate@binkert.orgcache_state_to_int(L1Cache_State state) 766145Snate@binkert.org{ 777039Snate@binkert.org return state; 786145Snate@binkert.org} 796145Snate@binkert.org 807039Snate@binkert.orginline Time 817039Snate@binkert.orgget_time() 826145Snate@binkert.org{ 837039Snate@binkert.org return g_eventQueue_ptr->getTime(); 846145Snate@binkert.org} 856145Snate@binkert.org 867039Snate@binkert.orginline Time 877039Snate@binkert.orgzero_time() 886145Snate@binkert.org{ 897039Snate@binkert.org return 0; 906145Snate@binkert.org} 916145Snate@binkert.org 927039Snate@binkert.orginline NodeID 937039Snate@binkert.orgintToID(int nodenum) 946145Snate@binkert.org{ 957039Snate@binkert.org NodeID id = nodenum; 967039Snate@binkert.org return id; 976145Snate@binkert.org} 986145Snate@binkert.org 997039Snate@binkert.orginline int 1007039Snate@binkert.orgIDToInt(NodeID id) 1016145Snate@binkert.org{ 1027039Snate@binkert.org int nodenum = id; 1037039Snate@binkert.org return nodenum; 1046145Snate@binkert.org} 1056145Snate@binkert.org 1067039Snate@binkert.orginline int 1077039Snate@binkert.orgaddressToInt(Address addr) 1086145Snate@binkert.org{ 1097039Snate@binkert.org return (int)addr.getLineAddress(); 1106145Snate@binkert.org} 1116145Snate@binkert.org 1127039Snate@binkert.orginline bool 1137039Snate@binkert.orglong_enough_ago(Time event) 1146145Snate@binkert.org{ 1157039Snate@binkert.org return ((get_time() - event) > 200); 1166145Snate@binkert.org} 1176145Snate@binkert.org 1187039Snate@binkert.orginline int 1197039Snate@binkert.orggetAddThenMod(int addend1, int addend2, int modulus) 1206145Snate@binkert.org{ 1217039Snate@binkert.org return (addend1 + addend2) % modulus; 1226145Snate@binkert.org} 1236145Snate@binkert.org 1247039Snate@binkert.orginline Time 1257039Snate@binkert.orggetTimeModInt(Time time, int modulus) 1266145Snate@binkert.org{ 1277039Snate@binkert.org return time % modulus; 1286145Snate@binkert.org} 1296145Snate@binkert.org 1307039Snate@binkert.orginline Time 1317039Snate@binkert.orggetTimePlusInt(Time addend1, int addend2) 1326145Snate@binkert.org{ 1337039Snate@binkert.org return (Time) addend1 + addend2; 1346145Snate@binkert.org} 1356145Snate@binkert.org 1367039Snate@binkert.orginline Time 1377039Snate@binkert.orggetTimeMinusTime(Time t1, Time t2) 1386145Snate@binkert.org{ 1397832Snate@binkert.org assert(t1 >= t2); 1407039Snate@binkert.org return t1 - t2; 1416145Snate@binkert.org} 1426145Snate@binkert.org 1437039Snate@binkert.orginline Time 1447039Snate@binkert.orggetPreviousDelayedCycles(Time t1, Time t2) 1456145Snate@binkert.org{ 1467039Snate@binkert.org if (RubySystem::getRandomization()) { // when randomizing delayed 1477039Snate@binkert.org return 0; 1487039Snate@binkert.org } else { 1497039Snate@binkert.org return getTimeMinusTime(t1, t2); 1507039Snate@binkert.org } 1516145Snate@binkert.org} 1526145Snate@binkert.org 1537039Snate@binkert.org// Return type for time_to_int is "Time" and not "int" so we get a 1547039Snate@binkert.org// 64-bit integer 1557039Snate@binkert.orginline Time 1567039Snate@binkert.orgtime_to_int(Time time) 1576145Snate@binkert.org{ 1587039Snate@binkert.org return time; 1596145Snate@binkert.org} 1606145Snate@binkert.org 1616145Snate@binkert.org// Appends an offset to an address 1627039Snate@binkert.orginline Address 1637039Snate@binkert.orgsetOffset(Address addr, int offset) 1646145Snate@binkert.org{ 1657039Snate@binkert.org Address result = addr; 1667039Snate@binkert.org result.setOffset(offset); 1677039Snate@binkert.org return result; 1686145Snate@binkert.org} 1696145Snate@binkert.org 1706145Snate@binkert.org// Makes an address into a line address 1717039Snate@binkert.orginline Address 1727039Snate@binkert.orgmakeLineAddress(Address addr) 1736145Snate@binkert.org{ 1747039Snate@binkert.org Address result = addr; 1757039Snate@binkert.org result.makeLineAddress(); 1767039Snate@binkert.org return result; 1776145Snate@binkert.org} 1786145Snate@binkert.org 1797039Snate@binkert.orginline int 1807039Snate@binkert.orgaddressOffset(Address addr) 1816467Sdrh5@cs.wisc.edu{ 1827039Snate@binkert.org return addr.getOffset(); 1836467Sdrh5@cs.wisc.edu} 1846467Sdrh5@cs.wisc.edu 1858131SLisa.Hsu@amd.cominline int 1868131SLisa.Hsu@amd.commod(int val, int mod) 1878131SLisa.Hsu@amd.com{ 1888131SLisa.Hsu@amd.com return val % mod; 1898131SLisa.Hsu@amd.com} 1908131SLisa.Hsu@amd.com 1917039Snate@binkert.org#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__ 192