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