RubySlicc_Util.hh revision 8485:7a9a7f2a3d46
16657Snate@binkert.org/*
26657Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36657Snate@binkert.org * All rights reserved.
46657Snate@binkert.org *
56657Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66657Snate@binkert.org * modification, are permitted provided that the following conditions are
76657Snate@binkert.org * met: redistributions of source code must retain the above copyright
86657Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96657Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106657Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116657Snate@binkert.org * documentation and/or other materials provided with the distribution;
126657Snate@binkert.org * neither the name of the copyright holders nor the names of its
136657Snate@binkert.org * contributors may be used to endorse or promote products derived from
146657Snate@binkert.org * this software without specific prior written permission.
156657Snate@binkert.org *
166657Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176657Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186657Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196657Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206657Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216657Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226657Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236657Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246657Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256657Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266657Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276657Snate@binkert.org */
2813672Sandreas.sandberg@arm.com
296657Snate@binkert.org/*
306657Snate@binkert.org * These are the functions that exported to slicc from ruby.
316657Snate@binkert.org */
329302Snilay@cs.wisc.edu
336657Snate@binkert.org#ifndef __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
3411117Snilay@cs.wisc.edu#define __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
3511117Snilay@cs.wisc.edu
3611117Snilay@cs.wisc.edu#include <cassert>
3711117Snilay@cs.wisc.edu
3811117Snilay@cs.wisc.edu#include "mem/protocol/AccessType.hh"
396657Snate@binkert.org#include "mem/protocol/GenericRequestType.hh"
406657Snate@binkert.org#include "mem/protocol/MachineType.hh"
416657Snate@binkert.org#include "mem/protocol/MessageSizeType.hh"
426657Snate@binkert.org#include "mem/protocol/PrefetchBit.hh"
436657Snate@binkert.org#include "mem/ruby/common/Address.hh"
446657Snate@binkert.org#include "mem/ruby/common/Global.hh"
4511283Santhony.gutierrez@amd.com#include "mem/ruby/network/Network.hh"
466657Snate@binkert.org#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh"
476657Snate@binkert.org#include "mem/ruby/system/MachineID.hh"
486657Snate@binkert.org#include "mem/ruby/system/NodeID.hh"
496657Snate@binkert.org#include "mem/ruby/system/System.hh"
506657Snate@binkert.org
516882SBrad.Beckmann@amd.comclass Set;
526657Snate@binkert.orgclass NetDest;
536657Snate@binkert.org
546657Snate@binkert.orginline int
556657Snate@binkert.orgrandom(int n)
566657Snate@binkert.org{
576657Snate@binkert.org  return random() % n;
586657Snate@binkert.org}
596657Snate@binkert.org
606657Snate@binkert.orginline bool
616657Snate@binkert.orgmulticast_retry()
626657Snate@binkert.org{
636657Snate@binkert.org    if (RubySystem::getRandomization()) {
646657Snate@binkert.org        return (random() & 0x1);
6510895Snilay@cs.wisc.edu    } else {
666657Snate@binkert.org        return true;
676657Snate@binkert.org    }
686657Snate@binkert.org}
6910228Snilay@cs.wisc.edu
706657Snate@binkert.orginline Time
716657Snate@binkert.orgget_time()
7210228Snilay@cs.wisc.edu{
736657Snate@binkert.org    return g_eventQueue_ptr->getTime();
746657Snate@binkert.org}
756657Snate@binkert.org
766657Snate@binkert.orginline Time
776657Snate@binkert.orgzero_time()
786657Snate@binkert.org{
796657Snate@binkert.org    return 0;
806657Snate@binkert.org}
816657Snate@binkert.org
826657Snate@binkert.orginline NodeID
836657Snate@binkert.orgintToID(int nodenum)
846657Snate@binkert.org{
856657Snate@binkert.org    NodeID id = nodenum;
866657Snate@binkert.org    return id;
876657Snate@binkert.org}
886657Snate@binkert.org
898086SBrad.Beckmann@amd.cominline int
908086SBrad.Beckmann@amd.comIDToInt(NodeID id)
918086SBrad.Beckmann@amd.com{
9213672Sandreas.sandberg@arm.com    int nodenum = id;
936657Snate@binkert.org    return nodenum;
9413672Sandreas.sandberg@arm.com}
956657Snate@binkert.org
966657Snate@binkert.orginline int
976657Snate@binkert.orgaddressToInt(Address addr)
986657Snate@binkert.org{
9910895Snilay@cs.wisc.edu    return (int)addr.getLineAddress();
1006657Snate@binkert.org}
1016657Snate@binkert.org
1026657Snate@binkert.orginline bool
1036657Snate@binkert.orglong_enough_ago(Time event)
1046657Snate@binkert.org{
1056657Snate@binkert.org    return ((get_time() - event) > 200);
1066657Snate@binkert.org}
1076657Snate@binkert.org
1086657Snate@binkert.orginline int
1096657Snate@binkert.orggetAddThenMod(int addend1, int addend2, int modulus)
1106657Snate@binkert.org{
1116657Snate@binkert.org    return (addend1 + addend2) % modulus;
1126657Snate@binkert.org}
1136657Snate@binkert.org
1146657Snate@binkert.orginline Time
1156657Snate@binkert.orggetTimeModInt(Time time, int modulus)
1166657Snate@binkert.org{
1176657Snate@binkert.org    return time % modulus;
1186657Snate@binkert.org}
1196657Snate@binkert.org
1206657Snate@binkert.orginline Time
1216657Snate@binkert.orggetTimePlusInt(Time addend1, int addend2)
1226657Snate@binkert.org{
1236657Snate@binkert.org    return (Time) addend1 + addend2;
1246657Snate@binkert.org}
1256657Snate@binkert.org
1269298Snilay@cs.wisc.eduinline Time
1276657Snate@binkert.orggetTimeMinusTime(Time t1, Time t2)
1286657Snate@binkert.org{
1296657Snate@binkert.org    assert(t1 >= t2);
13011117Snilay@cs.wisc.edu    return t1 - t2;
13111117Snilay@cs.wisc.edu}
13211117Snilay@cs.wisc.edu
1336657Snate@binkert.orginline Time
13411117Snilay@cs.wisc.edugetPreviousDelayedCycles(Time t1, Time t2)
1356657Snate@binkert.org{
1366657Snate@binkert.org    if (RubySystem::getRandomization()) {  // when randomizing delayed
1376657Snate@binkert.org        return 0;
1386657Snate@binkert.org    } else {
1396657Snate@binkert.org        return getTimeMinusTime(t1, t2);
1406657Snate@binkert.org    }
1416657Snate@binkert.org}
1426657Snate@binkert.org
1436882SBrad.Beckmann@amd.com// Return type for time_to_int is "Time" and not "int" so we get a
1446882SBrad.Beckmann@amd.com// 64-bit integer
1456882SBrad.Beckmann@amd.cominline Time
1468086SBrad.Beckmann@amd.comtime_to_int(Time time)
1478086SBrad.Beckmann@amd.com{
1488086SBrad.Beckmann@amd.com    return time;
14910307Snilay@cs.wisc.edu}
15010307Snilay@cs.wisc.edu
1516657Snate@binkert.org// Appends an offset to an address
1526657Snate@binkert.orginline Address
1536657Snate@binkert.orgsetOffset(Address addr, int offset)
15410307Snilay@cs.wisc.edu{
1559298Snilay@cs.wisc.edu    Address result = addr;
1569298Snilay@cs.wisc.edu    result.setOffset(offset);
1579298Snilay@cs.wisc.edu    return result;
1586657Snate@binkert.org}
1596657Snate@binkert.org
1606657Snate@binkert.org// Makes an address into a line address
1616657Snate@binkert.orginline Address
1626657Snate@binkert.orgmakeLineAddress(Address addr)
1636657Snate@binkert.org{
1646657Snate@binkert.org    Address result = addr;
1656657Snate@binkert.org    result.makeLineAddress();
1666657Snate@binkert.org    return result;
1676657Snate@binkert.org}
1686657Snate@binkert.org
16911283Santhony.gutierrez@amd.cominline int
17011283Santhony.gutierrez@amd.comaddressOffset(Address addr)
17111283Santhony.gutierrez@amd.com{
17211283Santhony.gutierrez@amd.com    return addr.getOffset();
17311283Santhony.gutierrez@amd.com}
17411283Santhony.gutierrez@amd.com
17511283Santhony.gutierrez@amd.cominline int
17611283Santhony.gutierrez@amd.commod(int val, int mod)
1779219Spower.jg@gmail.com{
1786657Snate@binkert.org    return val % mod;
1796657Snate@binkert.org}
1806657Snate@binkert.org
1816657Snate@binkert.org#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
1826657Snate@binkert.org