RubySlicc_Util.hh revision 9171
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36145Snate@binkert.org * All rights reserved.
46145Snate@binkert.org *
56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66145Snate@binkert.org * modification, are permitted provided that the following conditions are
76145Snate@binkert.org * met: redistributions of source code must retain the above copyright
86145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116145Snate@binkert.org * documentation and/or other materials provided with the distribution;
126145Snate@binkert.org * neither the name of the copyright holders nor the names of its
136145Snate@binkert.org * contributors may be used to endorse or promote products derived from
146145Snate@binkert.org * this software without specific prior written permission.
156145Snate@binkert.org *
166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145Snate@binkert.org */
286145Snate@binkert.org
296145Snate@binkert.org/*
307039Snate@binkert.org * These are the functions that exported to slicc from ruby.
316145Snate@binkert.org */
326145Snate@binkert.org
337039Snate@binkert.org#ifndef __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
347039Snate@binkert.org#define __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
356145Snate@binkert.org
367832Snate@binkert.org#include <cassert>
377832Snate@binkert.org
387039Snate@binkert.org#include "mem/ruby/common/Address.hh"
396154Snate@binkert.org#include "mem/ruby/common/Global.hh"
407039Snate@binkert.org#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh"
416285Snate@binkert.org#include "mem/ruby/system/System.hh"
426145Snate@binkert.org
437039Snate@binkert.orginline int
447039Snate@binkert.orgrandom(int n)
456145Snate@binkert.org{
466145Snate@binkert.org  return random() % n;
476145Snate@binkert.org}
486145Snate@binkert.org
497039Snate@binkert.orginline Time
507039Snate@binkert.orgget_time()
516145Snate@binkert.org{
529171Snilay@cs.wisc.edu    return g_system_ptr->getTime();
536145Snate@binkert.org}
546145Snate@binkert.org
557039Snate@binkert.orginline Time
567039Snate@binkert.orgzero_time()
576145Snate@binkert.org{
587039Snate@binkert.org    return 0;
596145Snate@binkert.org}
606145Snate@binkert.org
617039Snate@binkert.orginline NodeID
627039Snate@binkert.orgintToID(int nodenum)
636145Snate@binkert.org{
647039Snate@binkert.org    NodeID id = nodenum;
657039Snate@binkert.org    return id;
666145Snate@binkert.org}
676145Snate@binkert.org
687039Snate@binkert.orginline int
697039Snate@binkert.orgIDToInt(NodeID id)
706145Snate@binkert.org{
717039Snate@binkert.org    int nodenum = id;
727039Snate@binkert.org    return nodenum;
736145Snate@binkert.org}
746145Snate@binkert.org
757039Snate@binkert.orginline Time
767039Snate@binkert.orggetTimeModInt(Time time, int modulus)
776145Snate@binkert.org{
787039Snate@binkert.org    return time % modulus;
796145Snate@binkert.org}
806145Snate@binkert.org
817039Snate@binkert.orginline Time
827039Snate@binkert.orggetTimePlusInt(Time addend1, int addend2)
836145Snate@binkert.org{
847039Snate@binkert.org    return (Time) addend1 + addend2;
856145Snate@binkert.org}
866145Snate@binkert.org
877039Snate@binkert.orginline Time
887039Snate@binkert.orggetTimeMinusTime(Time t1, Time t2)
896145Snate@binkert.org{
907832Snate@binkert.org    assert(t1 >= t2);
917039Snate@binkert.org    return t1 - t2;
926145Snate@binkert.org}
936145Snate@binkert.org
947039Snate@binkert.org// Return type for time_to_int is "Time" and not "int" so we get a
957039Snate@binkert.org// 64-bit integer
967039Snate@binkert.orginline Time
977039Snate@binkert.orgtime_to_int(Time time)
986145Snate@binkert.org{
997039Snate@binkert.org    return time;
1006145Snate@binkert.org}
1016145Snate@binkert.org
1026145Snate@binkert.org// Appends an offset to an address
1037039Snate@binkert.orginline Address
1047039Snate@binkert.orgsetOffset(Address addr, int offset)
1056145Snate@binkert.org{
1067039Snate@binkert.org    Address result = addr;
1077039Snate@binkert.org    result.setOffset(offset);
1087039Snate@binkert.org    return result;
1096145Snate@binkert.org}
1106145Snate@binkert.org
1116145Snate@binkert.org// Makes an address into a line address
1127039Snate@binkert.orginline Address
1137039Snate@binkert.orgmakeLineAddress(Address addr)
1146145Snate@binkert.org{
1157039Snate@binkert.org    Address result = addr;
1167039Snate@binkert.org    result.makeLineAddress();
1177039Snate@binkert.org    return result;
1186145Snate@binkert.org}
1196145Snate@binkert.org
1207039Snate@binkert.orginline int
1217039Snate@binkert.orgaddressOffset(Address addr)
1226467Sdrh5@cs.wisc.edu{
1237039Snate@binkert.org    return addr.getOffset();
1246467Sdrh5@cs.wisc.edu}
1256467Sdrh5@cs.wisc.edu
1268131SLisa.Hsu@amd.cominline int
1278131SLisa.Hsu@amd.commod(int val, int mod)
1288131SLisa.Hsu@amd.com{
1298131SLisa.Hsu@amd.com    return val % mod;
1308131SLisa.Hsu@amd.com}
1318131SLisa.Hsu@amd.com
1327039Snate@binkert.org#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
133