RubySlicc_Util.hh (6284:a63d1dc4c820) RubySlicc_Util.hh (6285:ce086eca1ede)
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/ruby/config/RubyConfig.hh"
47#include "mem/protocol/CacheMsg.hh"
48#include "mem/protocol/GenericRequestType.hh"
49#include "mem/protocol/CacheRequestType.hh"
50#include "mem/protocol/AccessType.hh"
51#include "mem/protocol/MachineType.hh"
52#include "mem/protocol/Directory_State.hh"
53#include "mem/protocol/L1Cache_State.hh"
54#include "mem/protocol/MessageSizeType.hh"
55#include "mem/ruby/network/Network.hh"
56#include "mem/protocol/PrefetchBit.hh"
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/ruby/config/RubyConfig.hh"
47#include "mem/protocol/CacheMsg.hh"
48#include "mem/protocol/GenericRequestType.hh"
49#include "mem/protocol/CacheRequestType.hh"
50#include "mem/protocol/AccessType.hh"
51#include "mem/protocol/MachineType.hh"
52#include "mem/protocol/Directory_State.hh"
53#include "mem/protocol/L1Cache_State.hh"
54#include "mem/protocol/MessageSizeType.hh"
55#include "mem/ruby/network/Network.hh"
56#include "mem/protocol/PrefetchBit.hh"
57#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{
58
59#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh"
60
61class Set;
62class NetDest;
63
64extern inline int random(int n)
65{
66 return random() % n;
67}
68
69extern inline bool multicast_retry()
70{
70 if (RANDOMIZATION) {
71 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 int MessageSizeTypeToInt(MessageSizeType size_type)
110{
111 return MessageSizeType_to_int(size_type);
112}
113
72 return (random() & 0x1);
73 } else {
74 return true;
75 }
76}
77
78extern inline int cache_state_to_int(L1Cache_State state)
79{
80 return state;
81}
82
83extern inline Time get_time()
84{
85 return g_eventQueue_ptr->getTime();
86}
87
88extern inline Time zero_time()
89{
90 return 0;
91}
92
93extern inline NodeID intToID(int nodenum)
94{
95 NodeID id = nodenum;
96 return id;
97}
98
99extern inline int IDToInt(NodeID id)
100{
101 int nodenum = id;
102 return nodenum;
103}
104
105extern inline int addressToInt(Address addr)
106{
107 return (int) addr.getLineAddress();
108}
109
110extern inline int MessageSizeTypeToInt(MessageSizeType size_type)
111{
112 return MessageSizeType_to_int(size_type);
113}
114
115/*
114extern inline int numberOfNodes()
115{
116 return RubyConfig::numberOfChips();
117}
116extern inline int numberOfNodes()
117{
118 return RubyConfig::numberOfChips();
119}
118
120*/
121/*
119extern inline int numberOfL1CachePerChip()
120{
122extern inline int numberOfL1CachePerChip()
123{
121 return RubyConfig::numberOfL1CachePerChip();
124 return RubyConfig::getNumberOfCachesPerLevelPerChip(1,0);
122}
125}
126*/
123
124extern inline bool long_enough_ago(Time event)
125{
126 return ((get_time() - event) > 200);
127}
128
129extern inline int getAddThenMod(int addend1, int addend2, int modulus)
130{
131 return (addend1 + addend2) % modulus;
132}
133
134extern inline Time getTimeModInt(Time time, int modulus)
135{
136 return time % modulus;
137}
138
139extern inline Time getTimePlusInt(Time addend1, int addend2)
140{
141 return (Time) addend1 + addend2;
142}
143
144extern inline Time getTimeMinusTime(Time t1, Time t2)
145{
146 ASSERT(t1 >= t2);
147 return t1 - t2;
148}
149
150extern inline Time getPreviousDelayedCycles(Time t1, Time t2)
151{
127
128extern inline bool long_enough_ago(Time event)
129{
130 return ((get_time() - event) > 200);
131}
132
133extern inline int getAddThenMod(int addend1, int addend2, int modulus)
134{
135 return (addend1 + addend2) % modulus;
136}
137
138extern inline Time getTimeModInt(Time time, int modulus)
139{
140 return time % modulus;
141}
142
143extern inline Time getTimePlusInt(Time addend1, int addend2)
144{
145 return (Time) addend1 + addend2;
146}
147
148extern inline Time getTimeMinusTime(Time t1, Time t2)
149{
150 ASSERT(t1 >= t2);
151 return t1 - t2;
152}
153
154extern inline Time getPreviousDelayedCycles(Time t1, Time t2)
155{
152 if (RANDOMIZATION) { // when randomizing delayed
156 if (RubySystem::getRandomization()) { // when randomizing delayed
153 return 0;
154 } else {
155 return getTimeMinusTime(t1, t2);
156 }
157}
158
159extern inline void WARN_ERROR_TIME(Time time)
160{
161 WARN_EXPR(time);
162}
163
164// Return type for time_to_int is "Time" and not "int" so we get a 64-bit integer
165extern inline Time time_to_int(Time time)
166{
167 return time;
168}
169
157 return 0;
158 } else {
159 return getTimeMinusTime(t1, t2);
160 }
161}
162
163extern inline void WARN_ERROR_TIME(Time time)
164{
165 WARN_EXPR(time);
166}
167
168// Return type for time_to_int is "Time" and not "int" so we get a 64-bit integer
169extern inline Time time_to_int(Time time)
170{
171 return time;
172}
173
170
174/*
171extern inline bool getFilteringEnabled()
172{
175extern inline bool getFilteringEnabled()
176{
173 return g_FILTERING_ENABLED;
177 return RubyConfig::getFilteringEnabled();
174}
175
178}
179
180
176extern inline int getRetryThreshold()
177{
181extern inline int getRetryThreshold()
182{
178 return g_RETRY_THRESHOLD;
183 return RubyConfig::getRetryThreshold();
179}
180
181extern inline int getFixedTimeoutLatency()
182{
184}
185
186extern inline int getFixedTimeoutLatency()
187{
183 return g_FIXED_TIMEOUT_LATENCY;
188 return RubyConfig::getFixedTimeoutLatency();
184}
185
186extern inline int N_tokens()
187{
188 // return N+1 to handle clean writeback
189}
190
191extern inline int N_tokens()
192{
193 // return N+1 to handle clean writeback
189 return g_PROCS_PER_CHIP + 1;
194 return RubyConfig::getProcsPerChip() + 1;
190 // return 1;
191}
192
193extern inline bool distributedPersistentEnabled()
194{
195 // return 1;
196}
197
198extern inline bool distributedPersistentEnabled()
199{
195 return g_DISTRIBUTED_PERSISTENT_ENABLED;
200 return RubyConfig::getDistributedPersistentEnabled();
196}
197
198extern inline bool getDynamicTimeoutEnabled()
199{
201}
202
203extern inline bool getDynamicTimeoutEnabled()
204{
200 return g_DYNAMIC_TIMEOUT_ENABLED;
205 return RubyConfig::getDynamicTimeoutEnabled();
201}
206}
202
207*/
203// Appends an offset to an address
204extern inline Address setOffset(Address addr, int offset)
205{
206 Address result = addr;
207 result.setOffset(offset);
208 return result;
209}
210
211// Makes an address into a line address
212extern inline Address makeLineAddress(Address addr)
213{
214 Address result = addr;
215 result.makeLineAddress();
216 return result;
217}
218
219#endif //SLICC_UTIL_H
208// Appends an offset to an address
209extern inline Address setOffset(Address addr, int offset)
210{
211 Address result = addr;
212 result.setOffset(offset);
213 return result;
214}
215
216// Makes an address into a line address
217extern inline Address makeLineAddress(Address addr)
218{
219 Address result = addr;
220 result.makeLineAddress();
221 return result;
222}
223
224#endif //SLICC_UTIL_H