Address.cc (10466:73b7549d979e) Address.cc (11025:4872dbdea907)
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 15 unchanged lines hidden (view full) ---

24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "mem/ruby/common/Address.hh"
30#include "mem/ruby/system/System.hh"
31
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 15 unchanged lines hidden (view full) ---

24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "mem/ruby/common/Address.hh"
30#include "mem/ruby/system/System.hh"
31
32physical_address_t
33Address::getLineAddress() const
32Addr
33bitSelect(Addr addr, unsigned int small, unsigned int big)
34{
34{
35 return bitSelect(RubySystem::getBlockSizeBits(), ADDRESS_WIDTH);
36}
35 assert(big >= small);
37
36
38physical_address_t
39Address::getOffset() const
40{
41 return bitSelect(0, RubySystem::getBlockSizeBits() - 1);
37 if (big >= ADDRESS_WIDTH - 1) {
38 return (addr >> small);
39 } else {
40 Addr mask = ~((Addr)~0 << (big + 1));
41 // FIXME - this is slow to manipulate a 64-bit number using 32-bits
42 Addr partial = (addr & mask);
43 return (partial >> small);
44 }
42}
43
45}
46
44void
45Address::makeLineAddress()
47Addr
48bitRemove(Addr addr, unsigned int small, unsigned int big)
46{
49{
47 m_address = maskLowOrderBits(RubySystem::getBlockSizeBits());
48}
50 assert(big >= small);
49
51
50// returns the next stride address based on line address
51void
52Address::makeNextStrideAddress(int stride)
53{
54 m_address = maskLowOrderBits(RubySystem::getBlockSizeBits())
55 + RubySystem::getBlockSizeBytes()*stride;
52 if (small >= ADDRESS_WIDTH - 1) {
53 return addr;
54 } else if (big >= ADDRESS_WIDTH - 1) {
55 Addr mask = (Addr)~0 >> small;
56 return (addr & mask);
57 } else if (small == 0) {
58 Addr mask = (Addr)~0 << big;
59 return (addr & mask);
60 } else {
61 Addr mask = ~((Addr)~0 << small);
62 Addr lower_bits = addr & mask;
63 mask = (Addr)~0 << (big + 1);
64 Addr higher_bits = addr & mask;
65
66 // Shift the valid high bits over the removed section
67 higher_bits = higher_bits >> (big - small + 1);
68 return (higher_bits | lower_bits);
69 }
56}
57
70}
71
58int64
59Address::memoryModuleIndex() const
72Addr
73maskLowOrderBits(Addr addr, unsigned int number)
60{
74{
61 int64 index =
62 bitSelect(RubySystem::getBlockSizeBits() +
63 RubySystem::getMemorySizeBits(), ADDRESS_WIDTH);
64 assert (index >= 0);
65 return index;
75 Addr mask;
66
76
67 // int64 indexHighPortion =
68 // address.bitSelect(MEMORY_SIZE_BITS - 1,
69 // PAGE_SIZE_BITS + NUMBER_OF_MEMORY_MODULE_BITS);
70 // int64 indexLowPortion =
71 // address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS - 1);
72 //
73 // int64 index = indexLowPortion |
74 // (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS));
75
76 /*
77 Round-robin mapping of addresses, at page size granularity
78
79ADDRESS_WIDTH MEMORY_SIZE_BITS PAGE_SIZE_BITS DATA_BLOCK_BITS
80 | | | |
81 \ / \ / \ / \ / 0
82 -----------------------------------------------------------------------
83 | unused |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
84 | |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
85 -----------------------------------------------------------------------
86 indexHighPortion indexLowPortion
87 <------->
88 NUMBER_OF_MEMORY_MODULE_BITS
89 */
77 if (number >= ADDRESS_WIDTH - 1) {
78 mask = ~0;
79 } else {
80 mask = (Addr)~0 << number;
81 }
82 return (addr & mask);
90}
91
83}
84
92void
93Address::print(std::ostream& out) const
85Addr
86maskHighOrderBits(Addr addr, unsigned int number)
94{
87{
95 using namespace std;
96 out << "[" << hex << "0x" << m_address << "," << " line 0x"
97 << maskLowOrderBits(RubySystem::getBlockSizeBits()) << dec << "]"
98 << flush;
99}
88 Addr mask;
100
89
101void
102Address::output(std::ostream& out) const
103{
104 // Note: this outputs addresses in the form "ffff", not "0xffff".
105 // This code should always be able to write out addresses in a
106 // format that can be read in by the below input() method. Please
107 // don't change this without talking to Milo first.
108 out << std::hex << m_address << std::dec;
90 if (number >= ADDRESS_WIDTH - 1) {
91 mask = ~0;
92 } else {
93 mask = (Addr)~0 >> number;
94 }
95 return (addr & mask);
109}
110
96}
97
111void
112Address::input(std::istream& in)
98Addr
99shiftLowOrderBits(Addr addr, unsigned int number)
113{
100{
114 // Note: this only works with addresses in the form "ffff", not
115 // "0xffff". This code should always be able to read in addresses
116 // written out by the above output() method. Please don't change
117 // this without talking to Milo first.
118 in >> std::hex >> m_address >> std::dec;
101 return (addr >> number);
119}
120
102}
103
121Address::Address(const Address& obj)
104Addr
105getOffset(Addr addr)
122{
106{
123 m_address = obj.m_address;
107 return bitSelect(addr, 0, RubySystem::getBlockSizeBits() - 1);
124}
125
108}
109
126Address&
127Address::operator=(const Address& obj)
110Addr
111makeLineAddress(Addr addr)
128{
112{
129 if (this == &obj) {
130 // assert(false);
131 } else {
132 m_address = obj.m_address;
133 }
134 return *this;
113 return maskLowOrderBits(addr, RubySystem::getBlockSizeBits());
135}
136
114}
115
137Address
138next_stride_address(const Address& addr, int stride)
116// returns the next stride address based on line address
117Addr
118makeNextStrideAddress(Addr addr, int stride)
139{
119{
140 Address temp = addr;
141 temp.makeNextStrideAddress(stride);
142 return temp;
120 return maskLowOrderBits(addr, RubySystem::getBlockSizeBits())
121 + RubySystem::getBlockSizeBytes() * stride;
143}
122}