gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Address.cc
Go to the documentation of this file.
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;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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 
30 
32 
33 Addr
34 bitSelect(Addr addr, unsigned int small, unsigned int big)
35 {
36  assert(big >= small);
37 
38  if (big >= ADDRESS_WIDTH - 1) {
39  return (addr >> small);
40  } else {
41  Addr mask = ~((Addr)~0 << (big + 1));
42  // FIXME - this is slow to manipulate a 64-bit number using 32-bits
43  Addr partial = (addr & mask);
44  return (partial >> small);
45  }
46 }
47 
48 Addr
49 bitRemove(Addr addr, unsigned int small, unsigned int big)
50 {
51  assert(big >= small);
52 
53  if (small >= ADDRESS_WIDTH - 1) {
54  return addr;
55  } else if (big >= ADDRESS_WIDTH - 1) {
56  Addr mask = (Addr)~0 >> small;
57  return (addr & mask);
58  } else if (small == 0) {
59  Addr mask = (Addr)~0 << big;
60  return (addr & mask);
61  } else {
62  Addr mask = ~((Addr)~0 << small);
63  Addr lower_bits = addr & mask;
64  mask = (Addr)~0 << (big + 1);
65  Addr higher_bits = addr & mask;
66 
67  // Shift the valid high bits over the removed section
68  higher_bits = higher_bits >> (big - small + 1);
69  return (higher_bits | lower_bits);
70  }
71 }
72 
73 Addr
74 maskLowOrderBits(Addr addr, unsigned int number)
75 {
76  Addr mask;
77 
78  if (number >= ADDRESS_WIDTH - 1) {
79  mask = ~0;
80  } else {
81  mask = (Addr)~0 << number;
82  }
83  return (addr & mask);
84 }
85 
86 Addr
87 maskHighOrderBits(Addr addr, unsigned int number)
88 {
89  Addr mask;
90 
91  if (number >= ADDRESS_WIDTH - 1) {
92  mask = ~0;
93  } else {
94  mask = (Addr)~0 >> number;
95  }
96  return (addr & mask);
97 }
98 
99 Addr
100 shiftLowOrderBits(Addr addr, unsigned int number)
101 {
102  return (addr >> number);
103 }
104 
105 Addr
107 {
108  return bitSelect(addr, 0, RubySystem::getBlockSizeBits() - 1);
109 }
110 
111 Addr
113 {
115 }
116 
117 // returns the next stride address based on line address
118 Addr
120 {
123 }
124 
125 std::string
127 {
128  std::stringstream out;
129  out << "[" << std::hex << "0x" << addr << "," << " line 0x"
131  << std::dec << "]";
132  return out.str();
133 }
Addr bitSelect(Addr addr, unsigned int small, unsigned int big)
Definition: Address.cc:34
const uint32_t ADDRESS_WIDTH
Definition: Address.hh:38
Addr maskHighOrderBits(Addr addr, unsigned int number)
Definition: Address.cc:87
Bitfield< 21, 20 > stride
Definition: miscregs.hh:1627
Addr bitRemove(Addr addr, unsigned int small, unsigned int big)
Definition: Address.cc:49
ip6_addr_t addr
Definition: inet.hh:335
Addr getOffset(Addr addr)
Definition: Address.cc:106
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Addr makeLineAddress(Addr addr)
Definition: Address.cc:112
Addr shiftLowOrderBits(Addr addr, unsigned int number)
Definition: Address.cc:100
std::string printAddress(Addr addr)
Definition: Address.cc:126
Bitfield< 3, 0 > mask
Definition: types.hh:64
Addr makeNextStrideAddress(Addr addr, int stride)
Definition: Address.cc:119
static uint32_t getBlockSizeBits()
Definition: RubySystem.hh:75
static uint32_t getBlockSizeBytes()
Definition: RubySystem.hh:74
Addr maskLowOrderBits(Addr addr, unsigned int number)
Definition: Address.cc:74

Generated on Fri Jun 9 2017 13:03:49 for gem5 by doxygen 1.8.6