rename_map.cc revision 13600
13170Sstever@eecs.umich.edu/* 25254Sksewell@umich.edu * Copyright (c) 2016 ARM Limited 35254Sksewell@umich.edu * All rights reserved 43170Sstever@eecs.umich.edu * 55254Sksewell@umich.edu * The license below extends only to copyright in the software and shall 65254Sksewell@umich.edu * not be construed as granting a license to any other intellectual 75254Sksewell@umich.edu * property including but not limited to intellectual property relating 85254Sksewell@umich.edu * to a hardware implementation of the functionality of the software 95254Sksewell@umich.edu * licensed hereunder. You may use the software subject to the license 105254Sksewell@umich.edu * terms below provided that you ensure that this notice is replicated 115254Sksewell@umich.edu * unmodified and in its entirety in all distributions of the software, 125254Sksewell@umich.edu * modified or unmodified, in source code or in binary form. 135254Sksewell@umich.edu * 145254Sksewell@umich.edu * Copyright (c) 2004-2005 The Regents of The University of Michigan 153170Sstever@eecs.umich.edu * Copyright (c) 2013 Advanced Micro Devices, Inc. 165254Sksewell@umich.edu * All rights reserved. 175254Sksewell@umich.edu * 185254Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 195254Sksewell@umich.edu * modification, are permitted provided that the following conditions are 205254Sksewell@umich.edu * met: redistributions of source code must retain the above copyright 215254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer; 225254Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright 235254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 245254Sksewell@umich.edu * documentation and/or other materials provided with the distribution; 255254Sksewell@umich.edu * neither the name of the copyright holders nor the names of its 265254Sksewell@umich.edu * contributors may be used to endorse or promote products derived from 273170Sstever@eecs.umich.edu * this software without specific prior written permission. 285254Sksewell@umich.edu * 293170Sstever@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 303170Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 313170Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 323170Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 333170Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 343170Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 353170Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 363170Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 373170Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 383170Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 393170Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 406329Sgblack@eecs.umich.edu * 414661Sksewell@umich.edu * Authors: Kevin Lim 424661Sksewell@umich.edu */ 433170Sstever@eecs.umich.edu 443170Sstever@eecs.umich.edu#include "cpu/o3/rename_map.hh" 453170Sstever@eecs.umich.edu 463170Sstever@eecs.umich.edu#include <vector> 473170Sstever@eecs.umich.edu 483170Sstever@eecs.umich.edu#include "cpu/reg_class.hh" 493170Sstever@eecs.umich.edu#include "debug/Rename.hh" 503170Sstever@eecs.umich.edu 513170Sstever@eecs.umich.eduusing namespace std; 525596Sgblack@eecs.umich.edu 535596Sgblack@eecs.umich.edu/**** SimpleRenameMap methods ****/ 544661Sksewell@umich.edu 555715Shsul@eecs.umich.eduSimpleRenameMap::SimpleRenameMap() 563170Sstever@eecs.umich.edu : freeList(NULL), zeroReg(IntRegClass,0) 573170Sstever@eecs.umich.edu{ 583170Sstever@eecs.umich.edu} 593170Sstever@eecs.umich.edu 603170Sstever@eecs.umich.edu 613170Sstever@eecs.umich.eduvoid 623170Sstever@eecs.umich.eduSimpleRenameMap::init(unsigned size, SimpleFreeList *_freeList, 634661Sksewell@umich.edu RegIndex _zeroReg) 644661Sksewell@umich.edu{ 654661Sksewell@umich.edu assert(freeList == NULL); 664661Sksewell@umich.edu assert(map.empty()); 674661Sksewell@umich.edu 684661Sksewell@umich.edu map.resize(size); 695596Sgblack@eecs.umich.edu freeList = _freeList; 705596Sgblack@eecs.umich.edu zeroReg = RegId(IntRegClass, _zeroReg); 714661Sksewell@umich.edu} 724661Sksewell@umich.edu 734661Sksewell@umich.eduSimpleRenameMap::RenameInfo 744661Sksewell@umich.eduSimpleRenameMap::rename(const RegId& arch_reg) 754661Sksewell@umich.edu{ 765596Sgblack@eecs.umich.edu PhysRegIdPtr renamed_reg; 774661Sksewell@umich.edu // Record the current physical register that is renamed to the 784661Sksewell@umich.edu // requested architected register. 794661Sksewell@umich.edu PhysRegIdPtr prev_reg = map[arch_reg.flatIndex()]; 804661Sksewell@umich.edu 814661Sksewell@umich.edu // If it's not referencing the zero register, then rename the 824661Sksewell@umich.edu // register. 834661Sksewell@umich.edu if (arch_reg != zeroReg) { 844661Sksewell@umich.edu renamed_reg = freeList->getReg(); 854661Sksewell@umich.edu 865714Shsul@eecs.umich.edu map[arch_reg.flatIndex()] = renamed_reg; 874661Sksewell@umich.edu } else { 885714Shsul@eecs.umich.edu // Otherwise return the zero register so nothing bad happens. 894661Sksewell@umich.edu assert(prev_reg->isZeroReg()); 904661Sksewell@umich.edu renamed_reg = prev_reg; 914661Sksewell@umich.edu } 924661Sksewell@umich.edu 934661Sksewell@umich.edu DPRINTF(Rename, "Renamed reg %d to physical reg %d (%d) old mapping was" 944661Sksewell@umich.edu " %d (%d)\n", 954661Sksewell@umich.edu arch_reg, renamed_reg->flatIndex(), renamed_reg->flatIndex(), 964661Sksewell@umich.edu prev_reg->flatIndex(), prev_reg->flatIndex()); 975715Shsul@eecs.umich.edu 984661Sksewell@umich.edu return RenameInfo(renamed_reg, prev_reg); 994661Sksewell@umich.edu} 1005715Shsul@eecs.umich.edu 1014661Sksewell@umich.edu 1024661Sksewell@umich.edu/**** UnifiedRenameMap methods ****/ 1034661Sksewell@umich.edu 1044661Sksewell@umich.eduvoid 1054661Sksewell@umich.eduUnifiedRenameMap::init(PhysRegFile *_regFile, 1064661Sksewell@umich.edu RegIndex _intZeroReg, 1073170Sstever@eecs.umich.edu RegIndex _floatZeroReg, 1083170Sstever@eecs.umich.edu UnifiedFreeList *freeList, 1093170Sstever@eecs.umich.edu VecMode _mode) 1103170Sstever@eecs.umich.edu{ 1113170Sstever@eecs.umich.edu regFile = _regFile; 1123170Sstever@eecs.umich.edu vecMode = _mode; 1133170Sstever@eecs.umich.edu 114 intMap.init(TheISA::NumIntRegs, &(freeList->intList), _intZeroReg); 115 116 floatMap.init(TheISA::NumFloatRegs, &(freeList->floatList), _floatZeroReg); 117 118 vecMap.init(TheISA::NumVecRegs, &(freeList->vecList), (RegIndex)-1); 119 120 vecElemMap.init(TheISA::NumVecRegs * NVecElems, 121 &(freeList->vecElemList), (RegIndex)-1); 122 123 ccMap.init(TheISA::NumCCRegs, &(freeList->ccList), (RegIndex)-1); 124 125} 126 127void 128UnifiedRenameMap::switchMode(VecMode newVecMode, UnifiedFreeList* freeList) 129{ 130 if (newVecMode == Enums::Elem && vecMode == Enums::Full) { 131 /* Switch to vector element rename mode. */ 132 /* The free list should currently be tracking full registers. */ 133 panic_if(freeList->hasFreeVecElems(), 134 "The free list is already tracking Vec elems"); 135 panic_if(freeList->numFreeVecRegs() != 136 regFile->numVecPhysRegs() - TheISA::NumVecRegs, 137 "The free list has lost vector registers"); 138 /* Split the mapping of each arch reg. */ 139 int reg = 0; 140 for (auto &e: vecMap) { 141 PhysRegFile::IdRange range = this->regFile->getRegElemIds(e); 142 uint32_t i; 143 for (i = 0; range.first != range.second; i++, range.first++) { 144 vecElemMap.setEntry(RegId(VecElemClass, reg, i), 145 &(*range.first)); 146 } 147 panic_if(i != NVecElems, 148 "Wrong name of elems: expecting %u, got %d\n", 149 TheISA::NumVecElemPerVecReg, i); 150 reg++; 151 } 152 /* Split the free regs. */ 153 while (freeList->hasFreeVecRegs()) { 154 auto vr = freeList->getVecReg(); 155 auto range = this->regFile->getRegElemIds(vr); 156 freeList->addRegs(range.first, range.second); 157 } 158 vecMode = Enums::Elem; 159 } else if (newVecMode == Enums::Full && vecMode == Enums::Elem) { 160 /* Switch to full vector register rename mode. */ 161 /* The free list should currently be tracking register elems. */ 162 panic_if(freeList->hasFreeVecRegs(), 163 "The free list is already tracking full Vec"); 164 panic_if(freeList->numFreeVecElems() != 165 regFile->numVecElemPhysRegs() - TheISA::NumFloatRegs, 166 "The free list has lost vector register elements"); 167 /* To rebuild the arch regs we take the easy road: 168 * 1.- Stitch the elems together into vectors. 169 * 2.- Replace the contents of the register file with the vectors 170 * 3.- Set the remaining registers as free 171 */ 172 TheISA::VecRegContainer new_RF[TheISA::NumVecRegs]; 173 for (uint32_t i = 0; i < TheISA::NumVecRegs; i++) { 174 VecReg dst = new_RF[i].as<TheISA::VecElem>(); 175 for (uint32_t l = 0; l < NVecElems; l++) { 176 RegId s_rid(VecElemClass, i, l); 177 PhysRegIdPtr s_prid = vecElemMap.lookup(s_rid); 178 dst[l] = regFile->readVecElem(s_prid); 179 } 180 } 181 182 for (uint32_t i = 0; i < TheISA::NumVecRegs; i++) { 183 PhysRegId pregId(VecRegClass, i, 0); 184 regFile->setVecReg(regFile->getTrueId(&pregId), new_RF[i]); 185 } 186 187 auto range = regFile->getRegIds(VecRegClass); 188 freeList->addRegs(range.first + TheISA::NumVecRegs, range.second); 189 190 /* We remove the elems from the free list. */ 191 while (freeList->hasFreeVecElems()) 192 freeList->getVecElem(); 193 vecMode = Enums::Full; 194 } 195} 196