Address.hh revision 8091
16145Snate@binkert.org/* 26239Snate@binkert.org * Copyright (c) 1999 Mark D. Hill and David A. Wood 36239Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56239Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66239Snate@binkert.org * modification, are permitted provided that the following conditions are 76239Snate@binkert.org * met: redistributions of source code must retain the above copyright 86239Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96239Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106239Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116239Snate@binkert.org * documentation and/or other materials provided with the distribution; 126239Snate@binkert.org * neither the name of the copyright holders nor the names of its 136239Snate@binkert.org * contributors may be used to endorse or promote products derived from 146239Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166239Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176239Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186239Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196239Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206239Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216239Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226239Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236239Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246239Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256239Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266239Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org */ 286145Snate@binkert.org 297039Snate@binkert.org#ifndef __MEM_RUBY_COMMON_ADDRESS_HH__ 307039Snate@binkert.org#define __MEM_RUBY_COMMON_ADDRESS_HH__ 316145Snate@binkert.org 328091Snilay@cs.wisc.edu#include <cassert> 336145Snate@binkert.org#include <iomanip> 347002Snate@binkert.org 357002Snate@binkert.org#include "base/hashmap.hh" 366154Snate@binkert.org#include "mem/ruby/common/Global.hh" 377039Snate@binkert.org#include "mem/ruby/system/MachineID.hh" 387039Snate@binkert.org#include "mem/ruby/system/NodeID.hh" 396145Snate@binkert.org 406145Snate@binkert.orgconst int ADDRESS_WIDTH = 64; // address width in bytes 416145Snate@binkert.org 426145Snate@binkert.orgclass Address; 436145Snate@binkert.orgtypedef Address PhysAddress; 446145Snate@binkert.orgtypedef Address VirtAddress; 456145Snate@binkert.org 467039Snate@binkert.orgclass Address 477039Snate@binkert.org{ 487039Snate@binkert.org public: 497039Snate@binkert.org Address() 507039Snate@binkert.org : m_address(0) 517039Snate@binkert.org { } 526145Snate@binkert.org 537039Snate@binkert.org explicit 547039Snate@binkert.org Address(physical_address_t address) 557039Snate@binkert.org : m_address(address) 567039Snate@binkert.org { } 576145Snate@binkert.org 587039Snate@binkert.org Address(const Address& obj); 597039Snate@binkert.org Address& operator=(const Address& obj); 606145Snate@binkert.org 617039Snate@binkert.org void setAddress(physical_address_t address) { m_address = address; } 627039Snate@binkert.org physical_address_t getAddress() const {return m_address;} 637039Snate@binkert.org // selects bits inclusive 647039Snate@binkert.org physical_address_t bitSelect(int small, int big) const; 657039Snate@binkert.org physical_address_t bitRemove(int small, int big) const; 667039Snate@binkert.org physical_address_t maskLowOrderBits(int number) const; 677039Snate@binkert.org physical_address_t maskHighOrderBits(int number) const; 687039Snate@binkert.org physical_address_t shiftLowOrderBits(int number) const; 696145Snate@binkert.org 708091Snilay@cs.wisc.edu physical_address_t getLineAddress() const; 718091Snilay@cs.wisc.edu physical_address_t getOffset() const; 728091Snilay@cs.wisc.edu void makeLineAddress(); 738091Snilay@cs.wisc.edu void makeNextStrideAddress(int stride); 746145Snate@binkert.org 757039Snate@binkert.org int getBankSetNum() const; 767039Snate@binkert.org int getBankSetDist() const; 776145Snate@binkert.org 787039Snate@binkert.org Index memoryModuleIndex() const; 796145Snate@binkert.org 807055Snate@binkert.org void print(std::ostream& out) const; 817055Snate@binkert.org void output(std::ostream& out) const; 827055Snate@binkert.org void input(std::istream& in); 836145Snate@binkert.org 847039Snate@binkert.org void 857039Snate@binkert.org setOffset(int offset) 867039Snate@binkert.org { 877039Snate@binkert.org // first, zero out the offset bits 887039Snate@binkert.org makeLineAddress(); 897039Snate@binkert.org m_address |= (physical_address_t) offset; 907039Snate@binkert.org } 917039Snate@binkert.org 927039Snate@binkert.org private: 937039Snate@binkert.org physical_address_t m_address; 946145Snate@binkert.org}; 956145Snate@binkert.org 967039Snate@binkert.orginline Address 977039Snate@binkert.orgline_address(const Address& addr) 986145Snate@binkert.org{ 997039Snate@binkert.org Address temp(addr); 1007039Snate@binkert.org temp.makeLineAddress(); 1017039Snate@binkert.org return temp; 1026145Snate@binkert.org} 1036145Snate@binkert.org 1047039Snate@binkert.orginline bool 1057039Snate@binkert.orgoperator<(const Address& obj1, const Address& obj2) 1066145Snate@binkert.org{ 1077039Snate@binkert.org return obj1.getAddress() < obj2.getAddress(); 1086145Snate@binkert.org} 1096145Snate@binkert.org 1107055Snate@binkert.orginline std::ostream& 1117055Snate@binkert.orgoperator<<(std::ostream& out, const Address& obj) 1126145Snate@binkert.org{ 1137039Snate@binkert.org obj.print(out); 1147055Snate@binkert.org out << std::flush; 1157039Snate@binkert.org return out; 1166145Snate@binkert.org} 1176145Snate@binkert.org 1187039Snate@binkert.orginline bool 1197039Snate@binkert.orgoperator==(const Address& obj1, const Address& obj2) 1206145Snate@binkert.org{ 1217039Snate@binkert.org return (obj1.getAddress() == obj2.getAddress()); 1226145Snate@binkert.org} 1236145Snate@binkert.org 1247039Snate@binkert.orginline bool 1257039Snate@binkert.orgoperator!=(const Address& obj1, const Address& obj2) 1266145Snate@binkert.org{ 1277039Snate@binkert.org return (obj1.getAddress() != obj2.getAddress()); 1287039Snate@binkert.org} 1296145Snate@binkert.org 1307039Snate@binkert.org// rips bits inclusive 1317039Snate@binkert.orginline physical_address_t 1327039Snate@binkert.orgAddress::bitSelect(int small, int big) const 1337039Snate@binkert.org{ 1347039Snate@binkert.org physical_address_t mask; 1357039Snate@binkert.org assert((unsigned)big >= (unsigned)small); 1367039Snate@binkert.org 1377039Snate@binkert.org if (big >= ADDRESS_WIDTH - 1) { 1387039Snate@binkert.org return (m_address >> small); 1397039Snate@binkert.org } else { 1407039Snate@binkert.org mask = ~((physical_address_t)~0 << (big + 1)); 1417039Snate@binkert.org // FIXME - this is slow to manipulate a 64-bit number using 32-bits 1427039Snate@binkert.org physical_address_t partial = (m_address & mask); 1437039Snate@binkert.org return (partial >> small); 1447039Snate@binkert.org } 1456145Snate@binkert.org} 1466145Snate@binkert.org 1477027SBrad.Beckmann@amd.com// removes bits inclusive 1487039Snate@binkert.orginline physical_address_t 1497039Snate@binkert.orgAddress::bitRemove(int small, int big) const 1507027SBrad.Beckmann@amd.com{ 1517027SBrad.Beckmann@amd.com physical_address_t mask; 1527027SBrad.Beckmann@amd.com assert((unsigned)big >= (unsigned)small); 1537054Snate@binkert.org 1547027SBrad.Beckmann@amd.com if (small >= ADDRESS_WIDTH - 1) { 1557027SBrad.Beckmann@amd.com return m_address; 1567027SBrad.Beckmann@amd.com } else if (big >= ADDRESS_WIDTH - 1) { 1577027SBrad.Beckmann@amd.com mask = (physical_address_t)~0 >> small; 1587027SBrad.Beckmann@amd.com return (m_address & mask); 1597027SBrad.Beckmann@amd.com } else if (small == 0) { 1607027SBrad.Beckmann@amd.com mask = (physical_address_t)~0 << big; 1617027SBrad.Beckmann@amd.com return (m_address & mask); 1627027SBrad.Beckmann@amd.com } else { 1637027SBrad.Beckmann@amd.com mask = ~((physical_address_t)~0 << small); 1647027SBrad.Beckmann@amd.com physical_address_t lower_bits = m_address & mask; 1657027SBrad.Beckmann@amd.com mask = (physical_address_t)~0 << (big + 1); 1667027SBrad.Beckmann@amd.com physical_address_t higher_bits = m_address & mask; 1677027SBrad.Beckmann@amd.com 1687027SBrad.Beckmann@amd.com // Shift the valid high bits over the removed section 1697563SBrad.Beckmann@amd.com higher_bits = higher_bits >> (big - small + 1); 1707027SBrad.Beckmann@amd.com return (higher_bits | lower_bits); 1717027SBrad.Beckmann@amd.com } 1727027SBrad.Beckmann@amd.com} 1737027SBrad.Beckmann@amd.com 1747039Snate@binkert.orginline physical_address_t 1757039Snate@binkert.orgAddress::maskLowOrderBits(int number) const 1766145Snate@binkert.org{ 1776145Snate@binkert.org physical_address_t mask; 1786145Snate@binkert.org 1796145Snate@binkert.org if (number >= ADDRESS_WIDTH - 1) { 1807039Snate@binkert.org mask = ~0; 1816145Snate@binkert.org } else { 1827039Snate@binkert.org mask = (physical_address_t)~0 << number; 1836145Snate@binkert.org } 1846145Snate@binkert.org return (m_address & mask); 1856145Snate@binkert.org} 1866145Snate@binkert.org 1877039Snate@binkert.orginline physical_address_t 1887039Snate@binkert.orgAddress::maskHighOrderBits(int number) const 1896145Snate@binkert.org{ 1907039Snate@binkert.org physical_address_t mask; 1916145Snate@binkert.org 1927039Snate@binkert.org if (number >= ADDRESS_WIDTH - 1) { 1937039Snate@binkert.org mask = ~0; 1947039Snate@binkert.org } else { 1957039Snate@binkert.org mask = (physical_address_t)~0 >> number; 1967039Snate@binkert.org } 1977039Snate@binkert.org return (m_address & mask); 1986145Snate@binkert.org} 1996145Snate@binkert.org 2007039Snate@binkert.orginline physical_address_t 2017039Snate@binkert.orgAddress::shiftLowOrderBits(int number) const 2026145Snate@binkert.org{ 2037039Snate@binkert.org return (m_address >> number); 2046145Snate@binkert.org} 2056145Snate@binkert.org 2066145Snate@binkert.orgclass Address; 2077002Snate@binkert.orgnamespace __hash_namespace { 2087039Snate@binkert.orgtemplate <> struct hash<Address> 2097039Snate@binkert.org{ 2107039Snate@binkert.org size_t 2117039Snate@binkert.org operator()(const Address &s) const 2127039Snate@binkert.org { 2137039Snate@binkert.org return (size_t)s.getAddress(); 2147039Snate@binkert.org } 2157039Snate@binkert.org}; 2167811Ssteve.reinhardt@amd.com} // namespace __hash_namespace 2177039Snate@binkert.org 2186145Snate@binkert.orgnamespace std { 2197039Snate@binkert.orgtemplate <> struct equal_to<Address> 2207039Snate@binkert.org{ 2217039Snate@binkert.org bool 2227039Snate@binkert.org operator()(const Address& s1, const Address& s2) const 2237039Snate@binkert.org { 2247039Snate@binkert.org return s1 == s2; 2257039Snate@binkert.org } 2267039Snate@binkert.org}; 2277811Ssteve.reinhardt@amd.com} // namespace std 2286145Snate@binkert.org 2297039Snate@binkert.org#endif // __MEM_RUBY_COMMON_ADDRESS_HH__ 230