RubySlicc_Util.hh revision 8174:e21f6e70169e
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/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{
137    assert(t1 >= t2);
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
183inline int
184mod(int val, int mod)
185{
186    return val % mod;
187}
188
189#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
190