RubySlicc_Util.hh (8485:7a9a7f2a3d46) RubySlicc_Util.hh (8608:02d7ac5fb855)
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/GenericRequestType.hh"
40#include "mem/protocol/MachineType.hh"
41#include "mem/protocol/MessageSizeType.hh"
42#include "mem/protocol/PrefetchBit.hh"
43#include "mem/ruby/common/Address.hh"
44#include "mem/ruby/common/Global.hh"
45#include "mem/ruby/network/Network.hh"
46#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh"
47#include "mem/ruby/system/MachineID.hh"
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/GenericRequestType.hh"
40#include "mem/protocol/MachineType.hh"
41#include "mem/protocol/MessageSizeType.hh"
42#include "mem/protocol/PrefetchBit.hh"
43#include "mem/ruby/common/Address.hh"
44#include "mem/ruby/common/Global.hh"
45#include "mem/ruby/network/Network.hh"
46#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh"
47#include "mem/ruby/system/MachineID.hh"
48#include "mem/ruby/system/NodeID.hh"
49#include "mem/ruby/system/System.hh"
50
51class Set;
52class NetDest;
53
54inline int
55random(int n)
56{
57 return random() % n;
58}
59
60inline bool
61multicast_retry()
62{
63 if (RubySystem::getRandomization()) {
64 return (random() & 0x1);
65 } else {
66 return true;
67 }
68}
69
70inline Time
71get_time()
72{
73 return g_eventQueue_ptr->getTime();
74}
75
76inline Time
77zero_time()
78{
79 return 0;
80}
81
82inline NodeID
83intToID(int nodenum)
84{
85 NodeID id = nodenum;
86 return id;
87}
88
89inline int
90IDToInt(NodeID id)
91{
92 int nodenum = id;
93 return nodenum;
94}
95
96inline int
97addressToInt(Address addr)
98{
99 return (int)addr.getLineAddress();
100}
101
102inline bool
103long_enough_ago(Time event)
104{
105 return ((get_time() - event) > 200);
106}
107
108inline int
109getAddThenMod(int addend1, int addend2, int modulus)
110{
111 return (addend1 + addend2) % modulus;
112}
113
114inline Time
115getTimeModInt(Time time, int modulus)
116{
117 return time % modulus;
118}
119
120inline Time
121getTimePlusInt(Time addend1, int addend2)
122{
123 return (Time) addend1 + addend2;
124}
125
126inline Time
127getTimeMinusTime(Time t1, Time t2)
128{
129 assert(t1 >= t2);
130 return t1 - t2;
131}
132
133inline Time
134getPreviousDelayedCycles(Time t1, Time t2)
135{
136 if (RubySystem::getRandomization()) { // when randomizing delayed
137 return 0;
138 } else {
139 return getTimeMinusTime(t1, t2);
140 }
141}
142
143// Return type for time_to_int is "Time" and not "int" so we get a
144// 64-bit integer
145inline Time
146time_to_int(Time time)
147{
148 return time;
149}
150
151// Appends an offset to an address
152inline Address
153setOffset(Address addr, int offset)
154{
155 Address result = addr;
156 result.setOffset(offset);
157 return result;
158}
159
160// Makes an address into a line address
161inline Address
162makeLineAddress(Address addr)
163{
164 Address result = addr;
165 result.makeLineAddress();
166 return result;
167}
168
169inline int
170addressOffset(Address addr)
171{
172 return addr.getOffset();
173}
174
175inline int
176mod(int val, int mod)
177{
178 return val % mod;
179}
180
181#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
48#include "mem/ruby/system/System.hh"
49
50class Set;
51class NetDest;
52
53inline int
54random(int n)
55{
56 return random() % n;
57}
58
59inline bool
60multicast_retry()
61{
62 if (RubySystem::getRandomization()) {
63 return (random() & 0x1);
64 } else {
65 return true;
66 }
67}
68
69inline Time
70get_time()
71{
72 return g_eventQueue_ptr->getTime();
73}
74
75inline Time
76zero_time()
77{
78 return 0;
79}
80
81inline NodeID
82intToID(int nodenum)
83{
84 NodeID id = nodenum;
85 return id;
86}
87
88inline int
89IDToInt(NodeID id)
90{
91 int nodenum = id;
92 return nodenum;
93}
94
95inline int
96addressToInt(Address addr)
97{
98 return (int)addr.getLineAddress();
99}
100
101inline bool
102long_enough_ago(Time event)
103{
104 return ((get_time() - event) > 200);
105}
106
107inline int
108getAddThenMod(int addend1, int addend2, int modulus)
109{
110 return (addend1 + addend2) % modulus;
111}
112
113inline Time
114getTimeModInt(Time time, int modulus)
115{
116 return time % modulus;
117}
118
119inline Time
120getTimePlusInt(Time addend1, int addend2)
121{
122 return (Time) addend1 + addend2;
123}
124
125inline Time
126getTimeMinusTime(Time t1, Time t2)
127{
128 assert(t1 >= t2);
129 return t1 - t2;
130}
131
132inline Time
133getPreviousDelayedCycles(Time t1, Time t2)
134{
135 if (RubySystem::getRandomization()) { // when randomizing delayed
136 return 0;
137 } else {
138 return getTimeMinusTime(t1, t2);
139 }
140}
141
142// Return type for time_to_int is "Time" and not "int" so we get a
143// 64-bit integer
144inline Time
145time_to_int(Time time)
146{
147 return time;
148}
149
150// Appends an offset to an address
151inline Address
152setOffset(Address addr, int offset)
153{
154 Address result = addr;
155 result.setOffset(offset);
156 return result;
157}
158
159// Makes an address into a line address
160inline Address
161makeLineAddress(Address addr)
162{
163 Address result = addr;
164 result.makeLineAddress();
165 return result;
166}
167
168inline int
169addressOffset(Address addr)
170{
171 return addr.getOffset();
172}
173
174inline int
175mod(int val, int mod)
176{
177 return val % mod;
178}
179
180#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__