rename_map.cc revision 12109
11689SN/A/* 212109SRekai.GonzalezAlberquilla@arm.com * Copyright (c) 2016 ARM Limited 312109SRekai.GonzalezAlberquilla@arm.com * All rights reserved 412109SRekai.GonzalezAlberquilla@arm.com * 512109SRekai.GonzalezAlberquilla@arm.com * The license below extends only to copyright in the software and shall 612109SRekai.GonzalezAlberquilla@arm.com * not be construed as granting a license to any other intellectual 712109SRekai.GonzalezAlberquilla@arm.com * property including but not limited to intellectual property relating 812109SRekai.GonzalezAlberquilla@arm.com * to a hardware implementation of the functionality of the software 912109SRekai.GonzalezAlberquilla@arm.com * licensed hereunder. You may use the software subject to the license 1012109SRekai.GonzalezAlberquilla@arm.com * terms below provided that you ensure that this notice is replicated 1112109SRekai.GonzalezAlberquilla@arm.com * unmodified and in its entirety in all distributions of the software, 1212109SRekai.GonzalezAlberquilla@arm.com * modified or unmodified, in source code or in binary form. 1312109SRekai.GonzalezAlberquilla@arm.com * 141689SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 159919Ssteve.reinhardt@amd.com * Copyright (c) 2013 Advanced Micro Devices, Inc. 161689SN/A * All rights reserved. 171689SN/A * 181689SN/A * Redistribution and use in source and binary forms, with or without 191689SN/A * modification, are permitted provided that the following conditions are 201689SN/A * met: redistributions of source code must retain the above copyright 211689SN/A * notice, this list of conditions and the following disclaimer; 221689SN/A * redistributions in binary form must reproduce the above copyright 231689SN/A * notice, this list of conditions and the following disclaimer in the 241689SN/A * documentation and/or other materials provided with the distribution; 251689SN/A * neither the name of the copyright holders nor the names of its 261689SN/A * contributors may be used to endorse or promote products derived from 271689SN/A * this software without specific prior written permission. 281689SN/A * 291689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 301689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 311689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 321689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 331689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 341689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 351689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 361689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 371689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 381689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 391689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665Ssaidi@eecs.umich.edu * 412665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 421689SN/A */ 431464SN/A 4411793Sbrandon.potter@amd.com#include "cpu/o3/rename_map.hh" 4511793Sbrandon.potter@amd.com 461464SN/A#include <vector> 471060SN/A 4812106SRekai.GonzalezAlberquilla@arm.com#include "cpu/reg_class_impl.hh" 498232Snate@binkert.org#include "debug/Rename.hh" 501060SN/A 511464SN/Ausing namespace std; 521464SN/A 539919Ssteve.reinhardt@amd.com/**** SimpleRenameMap methods ****/ 541060SN/A 559919Ssteve.reinhardt@amd.comSimpleRenameMap::SimpleRenameMap() 5612106SRekai.GonzalezAlberquilla@arm.com : freeList(NULL), zeroReg(IntRegClass,0) 571060SN/A{ 582292SN/A} 592292SN/A 601061SN/A 611060SN/Avoid 629919Ssteve.reinhardt@amd.comSimpleRenameMap::init(unsigned size, SimpleFreeList *_freeList, 639919Ssteve.reinhardt@amd.com RegIndex _zeroReg) 641060SN/A{ 659919Ssteve.reinhardt@amd.com assert(freeList == NULL); 669919Ssteve.reinhardt@amd.com assert(map.empty()); 679919Ssteve.reinhardt@amd.com 689919Ssteve.reinhardt@amd.com map.resize(size); 699919Ssteve.reinhardt@amd.com freeList = _freeList; 7012106SRekai.GonzalezAlberquilla@arm.com zeroReg = RegId(IntRegClass, _zeroReg); 711060SN/A} 721060SN/A 731060SN/ASimpleRenameMap::RenameInfo 7412106SRekai.GonzalezAlberquilla@arm.comSimpleRenameMap::rename(const RegId& arch_reg) 751060SN/A{ 7612105Snathanael.premillieu@arm.com PhysRegIdPtr renamed_reg; 779919Ssteve.reinhardt@amd.com // Record the current physical register that is renamed to the 789919Ssteve.reinhardt@amd.com // requested architected register. 7912106SRekai.GonzalezAlberquilla@arm.com PhysRegIdPtr prev_reg = map[arch_reg.index()]; 801060SN/A 819919Ssteve.reinhardt@amd.com // If it's not referencing the zero register, then rename the 829919Ssteve.reinhardt@amd.com // register. 839919Ssteve.reinhardt@amd.com if (arch_reg != zeroReg) { 849919Ssteve.reinhardt@amd.com renamed_reg = freeList->getReg(); 851060SN/A 8612106SRekai.GonzalezAlberquilla@arm.com map[arch_reg.index()] = renamed_reg; 871060SN/A } else { 889919Ssteve.reinhardt@amd.com // Otherwise return the zero register so nothing bad happens. 8912105Snathanael.premillieu@arm.com assert(prev_reg->isZeroReg()); 9012105Snathanael.premillieu@arm.com renamed_reg = prev_reg; 911060SN/A } 921060SN/A 9312105Snathanael.premillieu@arm.com DPRINTF(Rename, "Renamed reg %d to physical reg %d (%d) old mapping was" 9412105Snathanael.premillieu@arm.com " %d (%d)\n", 9512106SRekai.GonzalezAlberquilla@arm.com arch_reg, renamed_reg->index(), renamed_reg->flatIndex(), 9612106SRekai.GonzalezAlberquilla@arm.com prev_reg->index(), prev_reg->flatIndex()); 973867Sbinkertn@umich.edu 981060SN/A return RenameInfo(renamed_reg, prev_reg); 991060SN/A} 1001060SN/A 1019919Ssteve.reinhardt@amd.com 1029919Ssteve.reinhardt@amd.com/**** UnifiedRenameMap methods ****/ 1039919Ssteve.reinhardt@amd.com 1049919Ssteve.reinhardt@amd.comvoid 1059919Ssteve.reinhardt@amd.comUnifiedRenameMap::init(PhysRegFile *_regFile, 1069919Ssteve.reinhardt@amd.com RegIndex _intZeroReg, 1079919Ssteve.reinhardt@amd.com RegIndex _floatZeroReg, 10812109SRekai.GonzalezAlberquilla@arm.com UnifiedFreeList *freeList, 10912109SRekai.GonzalezAlberquilla@arm.com VecMode _mode) 1109919Ssteve.reinhardt@amd.com{ 1119919Ssteve.reinhardt@amd.com regFile = _regFile; 11212109SRekai.GonzalezAlberquilla@arm.com vecMode = _mode; 1139919Ssteve.reinhardt@amd.com 1149919Ssteve.reinhardt@amd.com intMap.init(TheISA::NumIntRegs, &(freeList->intList), _intZeroReg); 1159919Ssteve.reinhardt@amd.com 1169919Ssteve.reinhardt@amd.com floatMap.init(TheISA::NumFloatRegs, &(freeList->floatList), _floatZeroReg); 1179920Syasuko.eckert@amd.com 11812109SRekai.GonzalezAlberquilla@arm.com vecMap.init(TheISA::NumVecRegs, &(freeList->vecList), (RegIndex)-1); 11912109SRekai.GonzalezAlberquilla@arm.com 12012109SRekai.GonzalezAlberquilla@arm.com vecElemMap.init(TheISA::NumVecRegs * NVecElems, 12112109SRekai.GonzalezAlberquilla@arm.com &(freeList->vecElemList), (RegIndex)-1); 12212109SRekai.GonzalezAlberquilla@arm.com 12310897Snilay@cs.wisc.edu ccMap.init(TheISA::NumCCRegs, &(freeList->ccList), (RegIndex)-1); 12412105Snathanael.premillieu@arm.com 1259919Ssteve.reinhardt@amd.com} 1269919Ssteve.reinhardt@amd.com 12712109SRekai.GonzalezAlberquilla@arm.comvoid 12812109SRekai.GonzalezAlberquilla@arm.comUnifiedRenameMap::switchMode(VecMode newVecMode, UnifiedFreeList* freeList) 12912109SRekai.GonzalezAlberquilla@arm.com{ 13012109SRekai.GonzalezAlberquilla@arm.com if (newVecMode == Enums::Elem && vecMode == Enums::Full) { 13112109SRekai.GonzalezAlberquilla@arm.com /* Switch to vector element rename mode. */ 13212109SRekai.GonzalezAlberquilla@arm.com /* The free list should currently be tracking full registers. */ 13312109SRekai.GonzalezAlberquilla@arm.com panic_if(freeList->hasFreeVecElems(), 13412109SRekai.GonzalezAlberquilla@arm.com "The free list is already tracking Vec elems"); 13512109SRekai.GonzalezAlberquilla@arm.com panic_if(freeList->numFreeVecRegs() != 13612109SRekai.GonzalezAlberquilla@arm.com regFile->numVecPhysRegs() - TheISA::NumVecRegs, 13712109SRekai.GonzalezAlberquilla@arm.com "The free list has lost vector registers"); 13812109SRekai.GonzalezAlberquilla@arm.com /* Split the mapping of each arch reg. */ 13912109SRekai.GonzalezAlberquilla@arm.com int reg = 0; 14012109SRekai.GonzalezAlberquilla@arm.com for (auto &e: vecMap) { 14112109SRekai.GonzalezAlberquilla@arm.com PhysRegFile::IdRange range = this->regFile->getRegElemIds(e); 14212109SRekai.GonzalezAlberquilla@arm.com uint32_t i; 14312109SRekai.GonzalezAlberquilla@arm.com for (i = 0; range.first != range.second; i++, range.first++) { 14412109SRekai.GonzalezAlberquilla@arm.com vecElemMap.setEntry(RegId(VecElemClass, reg, i), 14512109SRekai.GonzalezAlberquilla@arm.com &(*range.first)); 14612109SRekai.GonzalezAlberquilla@arm.com } 14712109SRekai.GonzalezAlberquilla@arm.com panic_if(i != NVecElems, 14812109SRekai.GonzalezAlberquilla@arm.com "Wrong name of elems: expecting %u, got %d\n", 14912109SRekai.GonzalezAlberquilla@arm.com TheISA::NumVecElemPerVecReg, i); 15012109SRekai.GonzalezAlberquilla@arm.com reg++; 15112109SRekai.GonzalezAlberquilla@arm.com } 15212109SRekai.GonzalezAlberquilla@arm.com /* Split the free regs. */ 15312109SRekai.GonzalezAlberquilla@arm.com while (freeList->hasFreeVecRegs()) { 15412109SRekai.GonzalezAlberquilla@arm.com auto vr = freeList->getVecReg(); 15512109SRekai.GonzalezAlberquilla@arm.com auto range = this->regFile->getRegElemIds(vr); 15612109SRekai.GonzalezAlberquilla@arm.com freeList->addRegs(range.first, range.second); 15712109SRekai.GonzalezAlberquilla@arm.com } 15812109SRekai.GonzalezAlberquilla@arm.com vecMode = Enums::Elem; 15912109SRekai.GonzalezAlberquilla@arm.com } else if (newVecMode == Enums::Full && vecMode == Enums::Elem) { 16012109SRekai.GonzalezAlberquilla@arm.com /* Switch to full vector register rename mode. */ 16112109SRekai.GonzalezAlberquilla@arm.com /* The free list should currently be tracking register elems. */ 16212109SRekai.GonzalezAlberquilla@arm.com panic_if(freeList->hasFreeVecRegs(), 16312109SRekai.GonzalezAlberquilla@arm.com "The free list is already tracking full Vec"); 16412109SRekai.GonzalezAlberquilla@arm.com panic_if(freeList->numFreeVecRegs() != 16512109SRekai.GonzalezAlberquilla@arm.com regFile->numVecElemPhysRegs() - TheISA::NumFloatRegs, 16612109SRekai.GonzalezAlberquilla@arm.com "The free list has lost vector register elements"); 16712109SRekai.GonzalezAlberquilla@arm.com /* To rebuild the arch regs we take the easy road: 16812109SRekai.GonzalezAlberquilla@arm.com * 1.- Stitch the elems together into vectors. 16912109SRekai.GonzalezAlberquilla@arm.com * 2.- Replace the contents of the register file with the vectors 17012109SRekai.GonzalezAlberquilla@arm.com * 3.- Set the remaining registers as free 17112109SRekai.GonzalezAlberquilla@arm.com */ 17212109SRekai.GonzalezAlberquilla@arm.com TheISA::VecRegContainer new_RF[TheISA::NumVecRegs]; 17312109SRekai.GonzalezAlberquilla@arm.com for (uint32_t i = 0; i < TheISA::NumVecRegs; i++) { 17412109SRekai.GonzalezAlberquilla@arm.com VecReg dst = new_RF[i].as<TheISA::VecElem>(); 17512109SRekai.GonzalezAlberquilla@arm.com for (uint32_t l = 0; l < NVecElems; l++) { 17612109SRekai.GonzalezAlberquilla@arm.com RegId s_rid(VecElemClass, i, l); 17712109SRekai.GonzalezAlberquilla@arm.com PhysRegIdPtr s_prid = vecElemMap.lookup(s_rid); 17812109SRekai.GonzalezAlberquilla@arm.com dst[l] = regFile->readVecElem(s_prid); 17912109SRekai.GonzalezAlberquilla@arm.com } 18012109SRekai.GonzalezAlberquilla@arm.com } 18112109SRekai.GonzalezAlberquilla@arm.com 18212109SRekai.GonzalezAlberquilla@arm.com for (uint32_t i = 0; i < TheISA::NumVecRegs; i++) { 18312109SRekai.GonzalezAlberquilla@arm.com PhysRegId pregId(VecRegClass, i, 0); 18412109SRekai.GonzalezAlberquilla@arm.com regFile->setVecReg(regFile->getTrueId(&pregId), new_RF[i]); 18512109SRekai.GonzalezAlberquilla@arm.com } 18612109SRekai.GonzalezAlberquilla@arm.com 18712109SRekai.GonzalezAlberquilla@arm.com auto range = regFile->getRegIds(VecRegClass); 18812109SRekai.GonzalezAlberquilla@arm.com freeList->addRegs(range.first + TheISA::NumVecRegs, range.second); 18912109SRekai.GonzalezAlberquilla@arm.com 19012109SRekai.GonzalezAlberquilla@arm.com /* We remove the elems from the free list. */ 19112109SRekai.GonzalezAlberquilla@arm.com while (freeList->hasFreeVecElems()) 19212109SRekai.GonzalezAlberquilla@arm.com freeList->getVecElem(); 19312109SRekai.GonzalezAlberquilla@arm.com vecMode = Enums::Full; 19412109SRekai.GonzalezAlberquilla@arm.com } 19512109SRekai.GonzalezAlberquilla@arm.com} 19612109SRekai.GonzalezAlberquilla@arm.com 197