summaryrefslogtreecommitdiff
path: root/src/mem/ruby/common
diff options
context:
space:
mode:
authorNilay Vaish <nilay@cs.wisc.edu>2015-08-14 12:04:51 -0500
committerNilay Vaish <nilay@cs.wisc.edu>2015-08-14 12:04:51 -0500
commit91a84c5b3cfb888794ac0245c066a4724b9a0871 (patch)
tree79a8b41aff56655dbd187934d2709fdd7488c6ed /src/mem/ruby/common
parent9ea5d9cad9381e05004de28ef25309ebe94c3a79 (diff)
downloadgem5-91a84c5b3cfb888794ac0245c066a4724b9a0871.tar.xz
ruby: replace Address by Addr
This patch eliminates the type Address defined by the ruby memory system. This memory system would now use the type Addr that is in use by the rest of the system.
Diffstat (limited to 'src/mem/ruby/common')
-rw-r--r--src/mem/ruby/common/Address.cc149
-rw-r--r--src/mem/ruby/common/Address.hh195
-rw-r--r--src/mem/ruby/common/SubBlock.cc6
-rw-r--r--src/mem/ruby/common/SubBlock.hh8
-rw-r--r--src/mem/ruby/common/TypeDefines.hh2
5 files changed, 81 insertions, 279 deletions
diff --git a/src/mem/ruby/common/Address.cc b/src/mem/ruby/common/Address.cc
index 5d9fa49e5..8d8800501 100644
--- a/src/mem/ruby/common/Address.cc
+++ b/src/mem/ruby/common/Address.cc
@@ -29,115 +29,94 @@
#include "mem/ruby/common/Address.hh"
#include "mem/ruby/system/System.hh"
-physical_address_t
-Address::getLineAddress() const
+Addr
+bitSelect(Addr addr, unsigned int small, unsigned int big)
{
- return bitSelect(RubySystem::getBlockSizeBits(), ADDRESS_WIDTH);
-}
+ assert(big >= small);
-physical_address_t
-Address::getOffset() const
-{
- return bitSelect(0, RubySystem::getBlockSizeBits() - 1);
+ if (big >= ADDRESS_WIDTH - 1) {
+ return (addr >> small);
+ } else {
+ Addr mask = ~((Addr)~0 << (big + 1));
+ // FIXME - this is slow to manipulate a 64-bit number using 32-bits
+ Addr partial = (addr & mask);
+ return (partial >> small);
+ }
}
-void
-Address::makeLineAddress()
+Addr
+bitRemove(Addr addr, unsigned int small, unsigned int big)
{
- m_address = maskLowOrderBits(RubySystem::getBlockSizeBits());
-}
+ assert(big >= small);
-// returns the next stride address based on line address
-void
-Address::makeNextStrideAddress(int stride)
-{
- m_address = maskLowOrderBits(RubySystem::getBlockSizeBits())
- + RubySystem::getBlockSizeBytes()*stride;
+ if (small >= ADDRESS_WIDTH - 1) {
+ return addr;
+ } else if (big >= ADDRESS_WIDTH - 1) {
+ Addr mask = (Addr)~0 >> small;
+ return (addr & mask);
+ } else if (small == 0) {
+ Addr mask = (Addr)~0 << big;
+ return (addr & mask);
+ } else {
+ Addr mask = ~((Addr)~0 << small);
+ Addr lower_bits = addr & mask;
+ mask = (Addr)~0 << (big + 1);
+ Addr higher_bits = addr & mask;
+
+ // Shift the valid high bits over the removed section
+ higher_bits = higher_bits >> (big - small + 1);
+ return (higher_bits | lower_bits);
+ }
}
-int64
-Address::memoryModuleIndex() const
+Addr
+maskLowOrderBits(Addr addr, unsigned int number)
{
- int64 index =
- bitSelect(RubySystem::getBlockSizeBits() +
- RubySystem::getMemorySizeBits(), ADDRESS_WIDTH);
- assert (index >= 0);
- return index;
+ Addr mask;
- // int64 indexHighPortion =
- // address.bitSelect(MEMORY_SIZE_BITS - 1,
- // PAGE_SIZE_BITS + NUMBER_OF_MEMORY_MODULE_BITS);
- // int64 indexLowPortion =
- // address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS - 1);
- //
- // int64 index = indexLowPortion |
- // (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS));
-
- /*
- Round-robin mapping of addresses, at page size granularity
-
-ADDRESS_WIDTH MEMORY_SIZE_BITS PAGE_SIZE_BITS DATA_BLOCK_BITS
- | | | |
- \ / \ / \ / \ / 0
- -----------------------------------------------------------------------
- | unused |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
- | |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
- -----------------------------------------------------------------------
- indexHighPortion indexLowPortion
- <------->
- NUMBER_OF_MEMORY_MODULE_BITS
- */
+ if (number >= ADDRESS_WIDTH - 1) {
+ mask = ~0;
+ } else {
+ mask = (Addr)~0 << number;
+ }
+ return (addr & mask);
}
-void
-Address::print(std::ostream& out) const
+Addr
+maskHighOrderBits(Addr addr, unsigned int number)
{
- using namespace std;
- out << "[" << hex << "0x" << m_address << "," << " line 0x"
- << maskLowOrderBits(RubySystem::getBlockSizeBits()) << dec << "]"
- << flush;
-}
+ Addr mask;
-void
-Address::output(std::ostream& out) const
-{
- // Note: this outputs addresses in the form "ffff", not "0xffff".
- // This code should always be able to write out addresses in a
- // format that can be read in by the below input() method. Please
- // don't change this without talking to Milo first.
- out << std::hex << m_address << std::dec;
+ if (number >= ADDRESS_WIDTH - 1) {
+ mask = ~0;
+ } else {
+ mask = (Addr)~0 >> number;
+ }
+ return (addr & mask);
}
-void
-Address::input(std::istream& in)
+Addr
+shiftLowOrderBits(Addr addr, unsigned int number)
{
- // Note: this only works with addresses in the form "ffff", not
- // "0xffff". This code should always be able to read in addresses
- // written out by the above output() method. Please don't change
- // this without talking to Milo first.
- in >> std::hex >> m_address >> std::dec;
+ return (addr >> number);
}
-Address::Address(const Address& obj)
+Addr
+getOffset(Addr addr)
{
- m_address = obj.m_address;
+ return bitSelect(addr, 0, RubySystem::getBlockSizeBits() - 1);
}
-Address&
-Address::operator=(const Address& obj)
+Addr
+makeLineAddress(Addr addr)
{
- if (this == &obj) {
- // assert(false);
- } else {
- m_address = obj.m_address;
- }
- return *this;
+ return maskLowOrderBits(addr, RubySystem::getBlockSizeBits());
}
-Address
-next_stride_address(const Address& addr, int stride)
+// returns the next stride address based on line address
+Addr
+makeNextStrideAddress(Addr addr, int stride)
{
- Address temp = addr;
- temp.makeNextStrideAddress(stride);
- return temp;
+ return maskLowOrderBits(addr, RubySystem::getBlockSizeBits())
+ + RubySystem::getBlockSizeBytes() * stride;
}
diff --git a/src/mem/ruby/common/Address.hh b/src/mem/ruby/common/Address.hh
index d47ff9ac5..6210baa5c 100644
--- a/src/mem/ruby/common/Address.hh
+++ b/src/mem/ruby/common/Address.hh
@@ -34,193 +34,18 @@
#include <iostream>
#include "base/hashmap.hh"
-#include "mem/ruby/common/TypeDefines.hh"
+#include "base/types.hh"
const uint32_t ADDRESS_WIDTH = 64; // address width in bytes
-class Address;
-typedef Address PhysAddress;
-typedef Address VirtAddress;
-
-class Address
-{
- public:
- Address()
- : m_address(0)
- { }
-
- explicit
- Address(physical_address_t address)
- : m_address(address)
- { }
-
- Address(const Address& obj);
- Address& operator=(const Address& obj);
-
- void setAddress(physical_address_t address) { m_address = address; }
- physical_address_t getAddress() const {return m_address;}
- // selects bits inclusive
- physical_address_t bitSelect(unsigned int small, unsigned int big) const;
- physical_address_t bitRemove(unsigned int small, unsigned int big) const;
- physical_address_t maskLowOrderBits(unsigned int number) const;
- physical_address_t maskHighOrderBits(unsigned int number) const;
- physical_address_t shiftLowOrderBits(unsigned int number) const;
-
- physical_address_t getLineAddress() const;
- physical_address_t getOffset() const;
- void makeLineAddress();
- void makeNextStrideAddress(int stride);
-
- int64 memoryModuleIndex() const;
-
- void print(std::ostream& out) const;
- void output(std::ostream& out) const;
- void input(std::istream& in);
-
- void
- setOffset(int offset)
- {
- // first, zero out the offset bits
- makeLineAddress();
- m_address |= (physical_address_t) offset;
- }
-
- private:
- physical_address_t m_address;
-};
-
-inline Address
-line_address(const Address& addr)
-{
- Address temp(addr);
- temp.makeLineAddress();
- return temp;
-}
-
-inline bool
-operator<(const Address& obj1, const Address& obj2)
-{
- return obj1.getAddress() < obj2.getAddress();
-}
-
-inline std::ostream&
-operator<<(std::ostream& out, const Address& obj)
-{
- obj.print(out);
- out << std::flush;
- return out;
-}
-
-inline bool
-operator==(const Address& obj1, const Address& obj2)
-{
- return (obj1.getAddress() == obj2.getAddress());
-}
-
-inline bool
-operator!=(const Address& obj1, const Address& obj2)
-{
- return (obj1.getAddress() != obj2.getAddress());
-}
-
-// rips bits inclusive
-inline physical_address_t
-Address::bitSelect(unsigned int small, unsigned int big) const
-{
- physical_address_t mask;
- assert(big >= small);
-
- if (big >= ADDRESS_WIDTH - 1) {
- return (m_address >> small);
- } else {
- mask = ~((physical_address_t)~0 << (big + 1));
- // FIXME - this is slow to manipulate a 64-bit number using 32-bits
- physical_address_t partial = (m_address & mask);
- return (partial >> small);
- }
-}
-
-// removes bits inclusive
-inline physical_address_t
-Address::bitRemove(unsigned int small, unsigned int big) const
-{
- physical_address_t mask;
- assert(big >= small);
-
- if (small >= ADDRESS_WIDTH - 1) {
- return m_address;
- } else if (big >= ADDRESS_WIDTH - 1) {
- mask = (physical_address_t)~0 >> small;
- return (m_address & mask);
- } else if (small == 0) {
- mask = (physical_address_t)~0 << big;
- return (m_address & mask);
- } else {
- mask = ~((physical_address_t)~0 << small);
- physical_address_t lower_bits = m_address & mask;
- mask = (physical_address_t)~0 << (big + 1);
- physical_address_t higher_bits = m_address & mask;
-
- // Shift the valid high bits over the removed section
- higher_bits = higher_bits >> (big - small + 1);
- return (higher_bits | lower_bits);
- }
-}
-
-inline physical_address_t
-Address::maskLowOrderBits(unsigned int number) const
-{
- physical_address_t mask;
-
- if (number >= ADDRESS_WIDTH - 1) {
- mask = ~0;
- } else {
- mask = (physical_address_t)~0 << number;
- }
- return (m_address & mask);
-}
-
-inline physical_address_t
-Address::maskHighOrderBits(unsigned int number) const
-{
- physical_address_t mask;
-
- if (number >= ADDRESS_WIDTH - 1) {
- mask = ~0;
- } else {
- mask = (physical_address_t)~0 >> number;
- }
- return (m_address & mask);
-}
-
-inline physical_address_t
-Address::shiftLowOrderBits(unsigned int number) const
-{
- return (m_address >> number);
-}
-
-Address next_stride_address(const Address& addr, int stride);
-
-__hash_namespace_begin
-template <> struct hash<Address>
-{
- size_t
- operator()(const Address &s) const
- {
- return (size_t)s.getAddress();
- }
-};
-__hash_namespace_end
-
-namespace std {
-template <> struct equal_to<Address>
-{
- bool
- operator()(const Address& s1, const Address& s2) const
- {
- return s1 == s2;
- }
-};
-} // namespace std
+// selects bits inclusive
+Addr bitSelect(Addr addr, unsigned int small, unsigned int big);
+Addr bitRemove(Addr addr, unsigned int small, unsigned int big);
+Addr maskLowOrderBits(Addr addr, unsigned int number);
+Addr maskHighOrderBits(Addr addr, unsigned int number);
+Addr shiftLowOrderBits(Addr addr, unsigned int number);
+Addr getOffset(Addr addr);
+Addr makeLineAddress(Addr addr);
+Addr makeNextStrideAddress(Addr addr, int stride);
#endif // __MEM_RUBY_COMMON_ADDRESS_HH__
diff --git a/src/mem/ruby/common/SubBlock.cc b/src/mem/ruby/common/SubBlock.cc
index 48485bf8b..5175cb950 100644
--- a/src/mem/ruby/common/SubBlock.cc
+++ b/src/mem/ruby/common/SubBlock.cc
@@ -31,7 +31,7 @@
using m5::stl_helpers::operator<<;
-SubBlock::SubBlock(const Address& addr, int size)
+SubBlock::SubBlock(Addr addr, int size)
{
m_address = addr;
resize(size);
@@ -45,7 +45,7 @@ SubBlock::internalMergeFrom(const DataBlock& data)
{
int size = getSize();
assert(size > 0);
- int offset = m_address.getOffset();
+ int offset = getOffset(m_address);
for (int i = 0; i < size; i++) {
this->setByte(i, data.getByte(offset + i));
}
@@ -56,7 +56,7 @@ SubBlock::internalMergeTo(DataBlock& data) const
{
int size = getSize();
assert(size > 0);
- int offset = m_address.getOffset();
+ int offset = getOffset(m_address);
for (int i = 0; i < size; i++) {
// This will detect crossing a cache line boundary
data.setByte(offset + i, this->getByte(i));
diff --git a/src/mem/ruby/common/SubBlock.hh b/src/mem/ruby/common/SubBlock.hh
index 35e99b956..ad1d68ae1 100644
--- a/src/mem/ruby/common/SubBlock.hh
+++ b/src/mem/ruby/common/SubBlock.hh
@@ -39,11 +39,11 @@ class SubBlock
{
public:
SubBlock() { }
- SubBlock(const Address& addr, int size);
+ SubBlock(Addr addr, int size);
~SubBlock() { }
- const Address& getAddress() const { return m_address; }
- void setAddress(const Address& addr) { m_address = addr; }
+ Addr getAddress() const { return m_address; }
+ void setAddress(Addr addr) { m_address = addr; }
int getSize() const { return m_data.size(); }
void resize(int size) { m_data.resize(size); }
@@ -66,7 +66,7 @@ class SubBlock
void internalMergeFrom(const DataBlock& data);
// Data Members (m_ prefix)
- Address m_address;
+ Addr m_address;
std::vector<uint8_t> m_data;
};
diff --git a/src/mem/ruby/common/TypeDefines.hh b/src/mem/ruby/common/TypeDefines.hh
index 17b30f4b3..203b63779 100644
--- a/src/mem/ruby/common/TypeDefines.hh
+++ b/src/mem/ruby/common/TypeDefines.hh
@@ -33,8 +33,6 @@
typedef unsigned long long uint64;
typedef long long int64;
-typedef uint64 physical_address_t;
-
typedef unsigned int LinkID;
typedef unsigned int NodeID;
typedef unsigned int SwitchID;