1/* 2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29/* 30 * These are the functions that exported to slicc from ruby. 31 */ 32 33#ifndef __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__ 34#define __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__ 35
| 1/* 2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29/* 30 * These are the functions that exported to slicc from ruby. 31 */ 32 33#ifndef __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__ 34#define __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__ 35
|
36#include "mem/protocol/AccessType.hh" 37#include "mem/protocol/CacheMsg.hh" 38#include "mem/protocol/CacheRequestType.hh" 39#include "mem/protocol/Directory_State.hh" 40#include "mem/protocol/GenericRequestType.hh" 41#include "mem/protocol/L1Cache_State.hh" 42#include "mem/protocol/MachineType.hh" 43#include "mem/protocol/MessageSizeType.hh" 44#include "mem/protocol/PrefetchBit.hh" 45#include "mem/ruby/common/Address.hh" 46#include "mem/ruby/common/Global.hh" 47#include "mem/ruby/network/Network.hh" 48#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh" 49#include "mem/ruby/system/MachineID.hh" 50#include "mem/ruby/system/NodeID.hh" 51#include "mem/ruby/system/System.hh" 52 53class Set; 54class NetDest; 55 56inline int 57random(int n) 58{ 59 return random() % n; 60} 61 62inline bool 63multicast_retry() 64{ 65 if (RubySystem::getRandomization()) { 66 return (random() & 0x1); 67 } else { 68 return true; 69 } 70} 71 72inline int 73cache_state_to_int(L1Cache_State state) 74{ 75 return state; 76} 77 78inline Time 79get_time() 80{ 81 return g_eventQueue_ptr->getTime(); 82} 83 84inline Time 85zero_time() 86{ 87 return 0; 88} 89 90inline NodeID 91intToID(int nodenum) 92{ 93 NodeID id = nodenum; 94 return id; 95} 96 97inline int 98IDToInt(NodeID id) 99{ 100 int nodenum = id; 101 return nodenum; 102} 103 104inline int 105addressToInt(Address addr) 106{ 107 return (int)addr.getLineAddress(); 108} 109 110inline bool 111long_enough_ago(Time event) 112{ 113 return ((get_time() - event) > 200); 114} 115 116inline int 117getAddThenMod(int addend1, int addend2, int modulus) 118{ 119 return (addend1 + addend2) % modulus; 120} 121 122inline Time 123getTimeModInt(Time time, int modulus) 124{ 125 return time % modulus; 126} 127 128inline Time 129getTimePlusInt(Time addend1, int addend2) 130{ 131 return (Time) addend1 + addend2; 132} 133 134inline Time 135getTimeMinusTime(Time t1, Time t2) 136{
| 38#include "mem/protocol/AccessType.hh" 39#include "mem/protocol/CacheMsg.hh" 40#include "mem/protocol/CacheRequestType.hh" 41#include "mem/protocol/Directory_State.hh" 42#include "mem/protocol/GenericRequestType.hh" 43#include "mem/protocol/L1Cache_State.hh" 44#include "mem/protocol/MachineType.hh" 45#include "mem/protocol/MessageSizeType.hh" 46#include "mem/protocol/PrefetchBit.hh" 47#include "mem/ruby/common/Address.hh" 48#include "mem/ruby/common/Global.hh" 49#include "mem/ruby/network/Network.hh" 50#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh" 51#include "mem/ruby/system/MachineID.hh" 52#include "mem/ruby/system/NodeID.hh" 53#include "mem/ruby/system/System.hh" 54 55class Set; 56class NetDest; 57 58inline int 59random(int n) 60{ 61 return random() % n; 62} 63 64inline bool 65multicast_retry() 66{ 67 if (RubySystem::getRandomization()) { 68 return (random() & 0x1); 69 } else { 70 return true; 71 } 72} 73 74inline int 75cache_state_to_int(L1Cache_State state) 76{ 77 return state; 78} 79 80inline Time 81get_time() 82{ 83 return g_eventQueue_ptr->getTime(); 84} 85 86inline Time 87zero_time() 88{ 89 return 0; 90} 91 92inline NodeID 93intToID(int nodenum) 94{ 95 NodeID id = nodenum; 96 return id; 97} 98 99inline int 100IDToInt(NodeID id) 101{ 102 int nodenum = id; 103 return nodenum; 104} 105 106inline int 107addressToInt(Address addr) 108{ 109 return (int)addr.getLineAddress(); 110} 111 112inline bool 113long_enough_ago(Time event) 114{ 115 return ((get_time() - event) > 200); 116} 117 118inline int 119getAddThenMod(int addend1, int addend2, int modulus) 120{ 121 return (addend1 + addend2) % modulus; 122} 123 124inline Time 125getTimeModInt(Time time, int modulus) 126{ 127 return time % modulus; 128} 129 130inline Time 131getTimePlusInt(Time addend1, int addend2) 132{ 133 return (Time) addend1 + addend2; 134} 135 136inline Time 137getTimeMinusTime(Time t1, Time t2) 138{
|
138 return t1 - t2; 139} 140 141inline Time 142getPreviousDelayedCycles(Time t1, Time t2) 143{ 144 if (RubySystem::getRandomization()) { // when randomizing delayed 145 return 0; 146 } else { 147 return getTimeMinusTime(t1, t2); 148 } 149} 150 151// Return type for time_to_int is "Time" and not "int" so we get a 152// 64-bit integer 153inline Time 154time_to_int(Time time) 155{ 156 return time; 157} 158 159// Appends an offset to an address 160inline Address 161setOffset(Address addr, int offset) 162{ 163 Address result = addr; 164 result.setOffset(offset); 165 return result; 166} 167 168// Makes an address into a line address 169inline Address 170makeLineAddress(Address addr) 171{ 172 Address result = addr; 173 result.makeLineAddress(); 174 return result; 175} 176 177inline int 178addressOffset(Address addr) 179{ 180 return addr.getOffset(); 181} 182 183#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
| 140 return t1 - t2; 141} 142 143inline Time 144getPreviousDelayedCycles(Time t1, Time t2) 145{ 146 if (RubySystem::getRandomization()) { // when randomizing delayed 147 return 0; 148 } else { 149 return getTimeMinusTime(t1, t2); 150 } 151} 152 153// Return type for time_to_int is "Time" and not "int" so we get a 154// 64-bit integer 155inline Time 156time_to_int(Time time) 157{ 158 return time; 159} 160 161// Appends an offset to an address 162inline Address 163setOffset(Address addr, int offset) 164{ 165 Address result = addr; 166 result.setOffset(offset); 167 return result; 168} 169 170// Makes an address into a line address 171inline Address 172makeLineAddress(Address addr) 173{ 174 Address result = addr; 175 result.makeLineAddress(); 176 return result; 177} 178 179inline int 180addressOffset(Address addr) 181{ 182 return addr.getOffset(); 183} 184 185#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
|