Address.cc revision 11025
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org */ 286145Snate@binkert.org 296154Snate@binkert.org#include "mem/ruby/common/Address.hh" 308091Snilay@cs.wisc.edu#include "mem/ruby/system/System.hh" 318091Snilay@cs.wisc.edu 3211025Snilay@cs.wisc.eduAddr 3311025Snilay@cs.wisc.edubitSelect(Addr addr, unsigned int small, unsigned int big) 348091Snilay@cs.wisc.edu{ 3511025Snilay@cs.wisc.edu assert(big >= small); 3611025Snilay@cs.wisc.edu 3711025Snilay@cs.wisc.edu if (big >= ADDRESS_WIDTH - 1) { 3811025Snilay@cs.wisc.edu return (addr >> small); 3911025Snilay@cs.wisc.edu } else { 4011025Snilay@cs.wisc.edu Addr mask = ~((Addr)~0 << (big + 1)); 4111025Snilay@cs.wisc.edu // FIXME - this is slow to manipulate a 64-bit number using 32-bits 4211025Snilay@cs.wisc.edu Addr partial = (addr & mask); 4311025Snilay@cs.wisc.edu return (partial >> small); 4411025Snilay@cs.wisc.edu } 458091Snilay@cs.wisc.edu} 468091Snilay@cs.wisc.edu 4711025Snilay@cs.wisc.eduAddr 4811025Snilay@cs.wisc.edubitRemove(Addr addr, unsigned int small, unsigned int big) 498091Snilay@cs.wisc.edu{ 5011025Snilay@cs.wisc.edu assert(big >= small); 5111025Snilay@cs.wisc.edu 5211025Snilay@cs.wisc.edu if (small >= ADDRESS_WIDTH - 1) { 5311025Snilay@cs.wisc.edu return addr; 5411025Snilay@cs.wisc.edu } else if (big >= ADDRESS_WIDTH - 1) { 5511025Snilay@cs.wisc.edu Addr mask = (Addr)~0 >> small; 5611025Snilay@cs.wisc.edu return (addr & mask); 5711025Snilay@cs.wisc.edu } else if (small == 0) { 5811025Snilay@cs.wisc.edu Addr mask = (Addr)~0 << big; 5911025Snilay@cs.wisc.edu return (addr & mask); 6011025Snilay@cs.wisc.edu } else { 6111025Snilay@cs.wisc.edu Addr mask = ~((Addr)~0 << small); 6211025Snilay@cs.wisc.edu Addr lower_bits = addr & mask; 6311025Snilay@cs.wisc.edu mask = (Addr)~0 << (big + 1); 6411025Snilay@cs.wisc.edu Addr higher_bits = addr & mask; 6511025Snilay@cs.wisc.edu 6611025Snilay@cs.wisc.edu // Shift the valid high bits over the removed section 6711025Snilay@cs.wisc.edu higher_bits = higher_bits >> (big - small + 1); 6811025Snilay@cs.wisc.edu return (higher_bits | lower_bits); 6911025Snilay@cs.wisc.edu } 708091Snilay@cs.wisc.edu} 718091Snilay@cs.wisc.edu 7211025Snilay@cs.wisc.eduAddr 7311025Snilay@cs.wisc.edumaskLowOrderBits(Addr addr, unsigned int number) 748091Snilay@cs.wisc.edu{ 7511025Snilay@cs.wisc.edu Addr mask; 7611025Snilay@cs.wisc.edu 7711025Snilay@cs.wisc.edu if (number >= ADDRESS_WIDTH - 1) { 7811025Snilay@cs.wisc.edu mask = ~0; 7911025Snilay@cs.wisc.edu } else { 8011025Snilay@cs.wisc.edu mask = (Addr)~0 << number; 8111025Snilay@cs.wisc.edu } 8211025Snilay@cs.wisc.edu return (addr & mask); 8311025Snilay@cs.wisc.edu} 8411025Snilay@cs.wisc.edu 8511025Snilay@cs.wisc.eduAddr 8611025Snilay@cs.wisc.edumaskHighOrderBits(Addr addr, unsigned int number) 8711025Snilay@cs.wisc.edu{ 8811025Snilay@cs.wisc.edu Addr mask; 8911025Snilay@cs.wisc.edu 9011025Snilay@cs.wisc.edu if (number >= ADDRESS_WIDTH - 1) { 9111025Snilay@cs.wisc.edu mask = ~0; 9211025Snilay@cs.wisc.edu } else { 9311025Snilay@cs.wisc.edu mask = (Addr)~0 >> number; 9411025Snilay@cs.wisc.edu } 9511025Snilay@cs.wisc.edu return (addr & mask); 9611025Snilay@cs.wisc.edu} 9711025Snilay@cs.wisc.edu 9811025Snilay@cs.wisc.eduAddr 9911025Snilay@cs.wisc.edushiftLowOrderBits(Addr addr, unsigned int number) 10011025Snilay@cs.wisc.edu{ 10111025Snilay@cs.wisc.edu return (addr >> number); 10211025Snilay@cs.wisc.edu} 10311025Snilay@cs.wisc.edu 10411025Snilay@cs.wisc.eduAddr 10511025Snilay@cs.wisc.edugetOffset(Addr addr) 10611025Snilay@cs.wisc.edu{ 10711025Snilay@cs.wisc.edu return bitSelect(addr, 0, RubySystem::getBlockSizeBits() - 1); 10811025Snilay@cs.wisc.edu} 10911025Snilay@cs.wisc.edu 11011025Snilay@cs.wisc.eduAddr 11111025Snilay@cs.wisc.edumakeLineAddress(Addr addr) 11211025Snilay@cs.wisc.edu{ 11311025Snilay@cs.wisc.edu return maskLowOrderBits(addr, RubySystem::getBlockSizeBits()); 1148091Snilay@cs.wisc.edu} 1158091Snilay@cs.wisc.edu 1168091Snilay@cs.wisc.edu// returns the next stride address based on line address 11711025Snilay@cs.wisc.eduAddr 11811025Snilay@cs.wisc.edumakeNextStrideAddress(Addr addr, int stride) 1198091Snilay@cs.wisc.edu{ 12011025Snilay@cs.wisc.edu return maskLowOrderBits(addr, RubySystem::getBlockSizeBits()) 12111025Snilay@cs.wisc.edu + RubySystem::getBlockSizeBytes() * stride; 1228091Snilay@cs.wisc.edu} 123