RubySlicc_Util.hh (9484:e96ff45795bc) RubySlicc_Util.hh (9499:b03b556a8fbb)
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 "debug/RubySlicc.hh"
39#include "mem/ruby/common/Address.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 "debug/RubySlicc.hh"
39#include "mem/ruby/common/Address.hh"
40#include "mem/ruby/common/Global.hh"
41#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh"
40#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh"
42#include "mem/ruby/system/System.hh"
41#include "mem/packet.hh"
43
44inline int
45random(int n)
46{
47 return random() % n;
48}
49
50inline Time
51zero_time()
52{
53 return 0;
54}
55
42
43inline int
44random(int n)
45{
46 return random() % n;
47}
48
49inline Time
50zero_time()
51{
52 return 0;
53}
54
55inline Cycles TimeToCycles(Time t) { return Cycles(t); }
56
56inline NodeID
57intToID(int nodenum)
58{
59 NodeID id = nodenum;
60 return id;
61}
62
63inline int
64IDToInt(NodeID id)
65{
66 int nodenum = id;
67 return nodenum;
68}
69
70inline Time
71getTimeModInt(Time time, int modulus)
72{
73 return time % modulus;
74}
75
76inline Time
77getTimePlusInt(Time addend1, int addend2)
78{
79 return (Time) addend1 + addend2;
80}
81
82inline Time
83getTimeMinusTime(Time t1, Time t2)
84{
85 assert(t1 >= t2);
86 return t1 - t2;
87}
88
89// Return type for time_to_int is "Time" and not "int" so we get a
90// 64-bit integer
91inline Time
92time_to_int(Time time)
93{
94 return time;
95}
96
97// Appends an offset to an address
98inline Address
99setOffset(Address addr, int offset)
100{
101 Address result = addr;
102 result.setOffset(offset);
103 return result;
104}
105
106// Makes an address into a line address
107inline Address
108makeLineAddress(Address addr)
109{
110 Address result = addr;
111 result.makeLineAddress();
112 return result;
113}
114
115inline int
116addressOffset(Address addr)
117{
118 return addr.getOffset();
119}
120
121inline int
122mod(int val, int mod)
123{
124 return val % mod;
125}
126
127inline int max_tokens()
128{
129 return 1024;
130}
131
132/**
133 * This function accepts an address, a data block and a packet. If the address
134 * range for the data block contains the address which the packet needs to
135 * read, then the data from the data block is written to the packet. True is
136 * returned if the data block was read, otherwise false is returned.
137 */
138inline bool
139testAndRead(Address addr, DataBlock& blk, Packet *pkt)
140{
141 Address pktLineAddr(pkt->getAddr());
142 pktLineAddr.makeLineAddress();
143
144 Address lineAddr = addr;
145 lineAddr.makeLineAddress();
146
147 if (pktLineAddr == lineAddr) {
148 uint8_t *data = pkt->getPtr<uint8_t>(true);
149 unsigned int size_in_bytes = pkt->getSize();
150 unsigned startByte = pkt->getAddr() - lineAddr.getAddress();
151
152 for (unsigned i = 0; i < size_in_bytes; ++i) {
153 data[i] = blk.getByte(i + startByte);
154 }
155 return true;
156 }
157 return false;
158}
159
160/**
161 * This function accepts an address, a data block and a packet. If the address
162 * range for the data block contains the address which the packet needs to
163 * write, then the data from the packet is written to the data block. True is
164 * returned if the data block was written, otherwise false is returned.
165 */
166inline bool
167testAndWrite(Address addr, DataBlock& blk, Packet *pkt)
168{
169 Address pktLineAddr(pkt->getAddr());
170 pktLineAddr.makeLineAddress();
171
172 Address lineAddr = addr;
173 lineAddr.makeLineAddress();
174
175 if (pktLineAddr == lineAddr) {
176 uint8_t *data = pkt->getPtr<uint8_t>(true);
177 unsigned int size_in_bytes = pkt->getSize();
178 unsigned startByte = pkt->getAddr() - lineAddr.getAddress();
179
180 for (unsigned i = 0; i < size_in_bytes; ++i) {
181 blk.setByte(i + startByte, data[i]);
182 }
183 return true;
184 }
185 return false;
186}
187
188#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
57inline NodeID
58intToID(int nodenum)
59{
60 NodeID id = nodenum;
61 return id;
62}
63
64inline int
65IDToInt(NodeID id)
66{
67 int nodenum = id;
68 return nodenum;
69}
70
71inline Time
72getTimeModInt(Time time, int modulus)
73{
74 return time % modulus;
75}
76
77inline Time
78getTimePlusInt(Time addend1, int addend2)
79{
80 return (Time) addend1 + addend2;
81}
82
83inline Time
84getTimeMinusTime(Time t1, Time t2)
85{
86 assert(t1 >= t2);
87 return t1 - t2;
88}
89
90// Return type for time_to_int is "Time" and not "int" so we get a
91// 64-bit integer
92inline Time
93time_to_int(Time time)
94{
95 return time;
96}
97
98// Appends an offset to an address
99inline Address
100setOffset(Address addr, int offset)
101{
102 Address result = addr;
103 result.setOffset(offset);
104 return result;
105}
106
107// Makes an address into a line address
108inline Address
109makeLineAddress(Address addr)
110{
111 Address result = addr;
112 result.makeLineAddress();
113 return result;
114}
115
116inline int
117addressOffset(Address addr)
118{
119 return addr.getOffset();
120}
121
122inline int
123mod(int val, int mod)
124{
125 return val % mod;
126}
127
128inline int max_tokens()
129{
130 return 1024;
131}
132
133/**
134 * This function accepts an address, a data block and a packet. If the address
135 * range for the data block contains the address which the packet needs to
136 * read, then the data from the data block is written to the packet. True is
137 * returned if the data block was read, otherwise false is returned.
138 */
139inline bool
140testAndRead(Address addr, DataBlock& blk, Packet *pkt)
141{
142 Address pktLineAddr(pkt->getAddr());
143 pktLineAddr.makeLineAddress();
144
145 Address lineAddr = addr;
146 lineAddr.makeLineAddress();
147
148 if (pktLineAddr == lineAddr) {
149 uint8_t *data = pkt->getPtr<uint8_t>(true);
150 unsigned int size_in_bytes = pkt->getSize();
151 unsigned startByte = pkt->getAddr() - lineAddr.getAddress();
152
153 for (unsigned i = 0; i < size_in_bytes; ++i) {
154 data[i] = blk.getByte(i + startByte);
155 }
156 return true;
157 }
158 return false;
159}
160
161/**
162 * This function accepts an address, a data block and a packet. If the address
163 * range for the data block contains the address which the packet needs to
164 * write, then the data from the packet is written to the data block. True is
165 * returned if the data block was written, otherwise false is returned.
166 */
167inline bool
168testAndWrite(Address addr, DataBlock& blk, Packet *pkt)
169{
170 Address pktLineAddr(pkt->getAddr());
171 pktLineAddr.makeLineAddress();
172
173 Address lineAddr = addr;
174 lineAddr.makeLineAddress();
175
176 if (pktLineAddr == lineAddr) {
177 uint8_t *data = pkt->getPtr<uint8_t>(true);
178 unsigned int size_in_bytes = pkt->getSize();
179 unsigned startByte = pkt->getAddr() - lineAddr.getAddress();
180
181 for (unsigned i = 0; i < size_in_bytes; ++i) {
182 blk.setByte(i + startByte, data[i]);
183 }
184 return true;
185 }
186 return false;
187}
188
189#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__