RubySlicc_Util.hh revision 7832:de7601e6e19d
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 <cassert>
37
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{
139    assert(t1 >= t2);
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__
186