summaryrefslogtreecommitdiff
path: root/src/mem/ruby/common/Address.cc
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/Address.cc
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/Address.cc')
-rw-r--r--src/mem/ruby/common/Address.cc149
1 files changed, 64 insertions, 85 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;
}