RubySlicc_Util.hh revision 9116:9171e26543fa
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/ruby/common/Address.hh"
39#include "mem/ruby/common/Global.hh"
40#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh"
41#include "mem/ruby/system/System.hh"
42
43inline int
44random(int n)
45{
46  return random() % n;
47}
48
49inline Time
50get_time()
51{
52    return g_eventQueue_ptr->getTime();
53}
54
55inline Time
56zero_time()
57{
58    return 0;
59}
60
61inline NodeID
62intToID(int nodenum)
63{
64    NodeID id = nodenum;
65    return id;
66}
67
68inline int
69IDToInt(NodeID id)
70{
71    int nodenum = id;
72    return nodenum;
73}
74
75inline Time
76getTimeModInt(Time time, int modulus)
77{
78    return time % modulus;
79}
80
81inline Time
82getTimePlusInt(Time addend1, int addend2)
83{
84    return (Time) addend1 + addend2;
85}
86
87inline Time
88getTimeMinusTime(Time t1, Time t2)
89{
90    assert(t1 >= t2);
91    return t1 - t2;
92}
93
94// Return type for time_to_int is "Time" and not "int" so we get a
95// 64-bit integer
96inline Time
97time_to_int(Time time)
98{
99    return time;
100}
101
102// Appends an offset to an address
103inline Address
104setOffset(Address addr, int offset)
105{
106    Address result = addr;
107    result.setOffset(offset);
108    return result;
109}
110
111// Makes an address into a line address
112inline Address
113makeLineAddress(Address addr)
114{
115    Address result = addr;
116    result.makeLineAddress();
117    return result;
118}
119
120inline int
121addressOffset(Address addr)
122{
123    return addr.getOffset();
124}
125
126inline int
127mod(int val, int mod)
128{
129    return val % mod;
130}
131
132#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
133