SubBlock.cc revision 7055
1545SN/A/* 22512SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 3545SN/A * All rights reserved. 4545SN/A * 5545SN/A * Redistribution and use in source and binary forms, with or without 6545SN/A * modification, are permitted provided that the following conditions are 7545SN/A * met: redistributions of source code must retain the above copyright 8545SN/A * notice, this list of conditions and the following disclaimer; 9545SN/A * redistributions in binary form must reproduce the above copyright 10545SN/A * notice, this list of conditions and the following disclaimer in the 11545SN/A * documentation and/or other materials provided with the distribution; 12545SN/A * neither the name of the copyright holders nor the names of its 13545SN/A * contributors may be used to endorse or promote products derived from 14545SN/A * this software without specific prior written permission. 15545SN/A * 16545SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17545SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18545SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19545SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20545SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21545SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22545SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23545SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24545SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25545SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26545SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu */ 282665Ssaidi@eecs.umich.edu 292665Ssaidi@eecs.umich.edu#include "mem/ruby/common/SubBlock.hh" 30545SN/A 31545SN/ASubBlock::SubBlock(const Address& addr, int size) 323090Sstever@eecs.umich.edu{ 332657Ssaidi@eecs.umich.edu m_address = addr; 34545SN/A setSize(size); 35679SN/A for (int i = 0; i < size; i++) { 362901Ssaidi@eecs.umich.edu setByte(i, 0); 37545SN/A } 382489SN/A} 392901Ssaidi@eecs.umich.edu 402914Ssaidi@eecs.umich.eduvoid 412489SN/ASubBlock::internalMergeFrom(const DataBlock& data) 422489SN/A{ 432489SN/A int size = getSize(); 442489SN/A assert(size > 0); 452630SN/A int offset = m_address.getOffset(); 462489SN/A for (int i = 0; i < size; i++) { 472489SN/A this->setByte(i, data.getByte(offset + i)); 482489SN/A } 492489SN/A} 502489SN/A 512630SN/Avoid 522489SN/ASubBlock::internalMergeTo(DataBlock& data) const 532489SN/A{ 542489SN/A int size = getSize(); 552489SN/A assert(size > 0); 562489SN/A int offset = m_address.getOffset(); 572521SN/A for (int i = 0; i < size; i++) { 582489SN/A // This will detect crossing a cache line boundary 592521SN/A data.setByte(offset + i, this->getByte(i)); 602521SN/A } 612489SN/A} 622489SN/A 632489SN/Avoid 642384SN/ASubBlock::print(std::ostream& out) const 652630SN/A{ 662384SN/A out << "[" << m_address << ", " << getSize() << ", " << m_data << "]"; 672784Ssaidi@eecs.umich.edu} 682846Ssaidi@eecs.umich.edu 692784Ssaidi@eecs.umich.edu 702784Ssaidi@eecs.umich.edu 712784Ssaidi@eecs.umich.edu