regfile.hh revision 12106
11689SN/A/* 21689SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 39915Ssteve.reinhardt@amd.com * Copyright (c) 2013 Advanced Micro Devices, Inc. 41689SN/A * All rights reserved. 51689SN/A * 61689SN/A * Redistribution and use in source and binary forms, with or without 71689SN/A * modification, are permitted provided that the following conditions are 81689SN/A * met: redistributions of source code must retain the above copyright 91689SN/A * notice, this list of conditions and the following disclaimer; 101689SN/A * redistributions in binary form must reproduce the above copyright 111689SN/A * notice, this list of conditions and the following disclaimer in the 121689SN/A * documentation and/or other materials provided with the distribution; 131689SN/A * neither the name of the copyright holders nor the names of its 141689SN/A * contributors may be used to endorse or promote products derived from 151689SN/A * this software without specific prior written permission. 161689SN/A * 171689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 181689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 191689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 201689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 211689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 221689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 231689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 241689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 251689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 261689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 271689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu * 292665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 302665Ssaidi@eecs.umich.edu * Gabe Black 311689SN/A */ 321689SN/A 332292SN/A#ifndef __CPU_O3_REGFILE_HH__ 342292SN/A#define __CPU_O3_REGFILE_HH__ 351060SN/A 366658Snate@binkert.org#include <vector> 376658Snate@binkert.org 382165SN/A#include "arch/isa_traits.hh" 398793Sgblack@eecs.umich.edu#include "arch/kernel_stats.hh" 402669Sktlim@umich.edu#include "arch/types.hh" 411681SN/A#include "base/trace.hh" 426658Snate@binkert.org#include "config/the_isa.hh" 431717SN/A#include "cpu/o3/comm.hh" 448232Snate@binkert.org#include "debug/IEW.hh" 451060SN/A 469919Ssteve.reinhardt@amd.comclass UnifiedFreeList; 479919Ssteve.reinhardt@amd.com 482292SN/A/** 492292SN/A * Simple physical register file class. 502292SN/A */ 511060SN/Aclass PhysRegFile 521060SN/A{ 539915Ssteve.reinhardt@amd.com private: 549915Ssteve.reinhardt@amd.com 552107SN/A typedef TheISA::IntReg IntReg; 562107SN/A typedef TheISA::FloatReg FloatReg; 572669Sktlim@umich.edu typedef TheISA::FloatRegBits FloatRegBits; 589920Syasuko.eckert@amd.com typedef TheISA::CCReg CCReg; 592159SN/A 602669Sktlim@umich.edu typedef union { 612669Sktlim@umich.edu FloatReg d; 622669Sktlim@umich.edu FloatRegBits q; 632669Sktlim@umich.edu } PhysFloatReg; 641060SN/A 659915Ssteve.reinhardt@amd.com /** Integer register file. */ 669919Ssteve.reinhardt@amd.com std::vector<IntReg> intRegFile; 6712105Snathanael.premillieu@arm.com std::vector<PhysRegId> intRegIds; 681060SN/A 699915Ssteve.reinhardt@amd.com /** Floating point register file. */ 709919Ssteve.reinhardt@amd.com std::vector<PhysFloatReg> floatRegFile; 7112105Snathanael.premillieu@arm.com std::vector<PhysRegId> floatRegIds; 729915Ssteve.reinhardt@amd.com 739920Syasuko.eckert@amd.com /** Condition-code register file. */ 749920Syasuko.eckert@amd.com std::vector<CCReg> ccRegFile; 7512105Snathanael.premillieu@arm.com std::vector<PhysRegId> ccRegIds; 7612105Snathanael.premillieu@arm.com 7712105Snathanael.premillieu@arm.com /** Misc Reg Ids */ 7812105Snathanael.premillieu@arm.com std::vector<PhysRegId> miscRegIds; 799920Syasuko.eckert@amd.com 809915Ssteve.reinhardt@amd.com /** 8112105Snathanael.premillieu@arm.com * Number of physical general purpose registers 829915Ssteve.reinhardt@amd.com */ 8312105Snathanael.premillieu@arm.com unsigned numPhysicalIntRegs; 849915Ssteve.reinhardt@amd.com 859920Syasuko.eckert@amd.com /** 8612105Snathanael.premillieu@arm.com * Number of physical general purpose registers 879920Syasuko.eckert@amd.com */ 8812105Snathanael.premillieu@arm.com unsigned numPhysicalFloatRegs; 8912105Snathanael.premillieu@arm.com 9012105Snathanael.premillieu@arm.com /** 9112105Snathanael.premillieu@arm.com * Number of physical general purpose registers 9212105Snathanael.premillieu@arm.com */ 9312105Snathanael.premillieu@arm.com unsigned numPhysicalCCRegs; 949920Syasuko.eckert@amd.com 959915Ssteve.reinhardt@amd.com /** Total number of physical registers. */ 969915Ssteve.reinhardt@amd.com unsigned totalNumRegs; 979915Ssteve.reinhardt@amd.com 981060SN/A public: 992292SN/A /** 1002292SN/A * Constructs a physical register file with the specified amount of 1012292SN/A * integer and floating point registers. 1022292SN/A */ 1039915Ssteve.reinhardt@amd.com PhysRegFile(unsigned _numPhysicalIntRegs, 1049920Syasuko.eckert@amd.com unsigned _numPhysicalFloatRegs, 10510935Snilay@cs.wisc.edu unsigned _numPhysicalCCRegs); 1061060SN/A 1079086Sandreas.hansson@arm.com /** 1089086Sandreas.hansson@arm.com * Destructor to free resources 1099086Sandreas.hansson@arm.com */ 1109919Ssteve.reinhardt@amd.com ~PhysRegFile() {} 1119919Ssteve.reinhardt@amd.com 1129919Ssteve.reinhardt@amd.com /** Initialize the free list */ 1139919Ssteve.reinhardt@amd.com void initFreeList(UnifiedFreeList *freeList); 1149086Sandreas.hansson@arm.com 1159915Ssteve.reinhardt@amd.com /** @return the number of integer physical registers. */ 11612105Snathanael.premillieu@arm.com unsigned numIntPhysRegs() const { return numPhysicalIntRegs; } 1179915Ssteve.reinhardt@amd.com 1189915Ssteve.reinhardt@amd.com /** @return the number of floating-point physical registers. */ 11912105Snathanael.premillieu@arm.com unsigned numFloatPhysRegs() const { return numPhysicalFloatRegs; } 1209920Syasuko.eckert@amd.com 1219920Syasuko.eckert@amd.com /** @return the number of condition-code physical registers. */ 12212105Snathanael.premillieu@arm.com unsigned numCCPhysRegs() const { return numPhysicalCCRegs; } 1239915Ssteve.reinhardt@amd.com 1249915Ssteve.reinhardt@amd.com /** @return the total number of physical registers. */ 1259915Ssteve.reinhardt@amd.com unsigned totalNumPhysRegs() const { return totalNumRegs; } 1269915Ssteve.reinhardt@amd.com 12712105Snathanael.premillieu@arm.com /** Gets a misc register PhysRegIdPtr. */ 12812105Snathanael.premillieu@arm.com PhysRegIdPtr getMiscRegId(RegIndex reg_idx) { 12912105Snathanael.premillieu@arm.com return &miscRegIds[reg_idx]; 1309915Ssteve.reinhardt@amd.com } 1311060SN/A 1322292SN/A /** Reads an integer register. */ 13312105Snathanael.premillieu@arm.com uint64_t readIntReg(PhysRegIdPtr phys_reg) const 1341060SN/A { 13512105Snathanael.premillieu@arm.com assert(phys_reg->isIntPhysReg()); 1361061SN/A 1371060SN/A DPRINTF(IEW, "RegFile: Access to int register %i, has data " 13812106SRekai.GonzalezAlberquilla@arm.com "%#x\n", phys_reg->index(), intRegFile[phys_reg->index()]); 13912106SRekai.GonzalezAlberquilla@arm.com return intRegFile[phys_reg->index()]; 1401060SN/A } 1411060SN/A 1422292SN/A /** Reads a floating point register (double precision). */ 14312105Snathanael.premillieu@arm.com FloatReg readFloatReg(PhysRegIdPtr phys_reg) const 1441060SN/A { 14512105Snathanael.premillieu@arm.com assert(phys_reg->isFloatPhysReg()); 1461060SN/A 1472455SN/A DPRINTF(IEW, "RegFile: Access to float register %i, has " 14812106SRekai.GonzalezAlberquilla@arm.com "data %#x\n", phys_reg->index(), 14912106SRekai.GonzalezAlberquilla@arm.com floatRegFile[phys_reg->index()].q); 1502455SN/A 15112106SRekai.GonzalezAlberquilla@arm.com return floatRegFile[phys_reg->index()].d; 1521060SN/A } 1531060SN/A 15412105Snathanael.premillieu@arm.com FloatRegBits readFloatRegBits(PhysRegIdPtr phys_reg) const 1552455SN/A { 15612105Snathanael.premillieu@arm.com assert(phys_reg->isFloatPhysReg()); 1579915Ssteve.reinhardt@amd.com 15812106SRekai.GonzalezAlberquilla@arm.com FloatRegBits floatRegBits = floatRegFile[phys_reg->index()].q; 1592455SN/A 1602455SN/A DPRINTF(IEW, "RegFile: Access to float register %i as int, " 16112106SRekai.GonzalezAlberquilla@arm.com "has data %#x\n", phys_reg->index(), 16212105Snathanael.premillieu@arm.com (uint64_t)floatRegBits); 1632455SN/A 1642455SN/A return floatRegBits; 1651060SN/A } 1661060SN/A 1679920Syasuko.eckert@amd.com /** Reads a condition-code register. */ 16812105Snathanael.premillieu@arm.com CCReg readCCReg(PhysRegIdPtr phys_reg) 1699920Syasuko.eckert@amd.com { 17012105Snathanael.premillieu@arm.com assert(phys_reg->isCCPhysReg()); 1719920Syasuko.eckert@amd.com 1729920Syasuko.eckert@amd.com DPRINTF(IEW, "RegFile: Access to cc register %i, has " 17312106SRekai.GonzalezAlberquilla@arm.com "data %#x\n", phys_reg->index(), 17412106SRekai.GonzalezAlberquilla@arm.com ccRegFile[phys_reg->index()]); 1759920Syasuko.eckert@amd.com 17612106SRekai.GonzalezAlberquilla@arm.com return ccRegFile[phys_reg->index()]; 1779920Syasuko.eckert@amd.com } 1789920Syasuko.eckert@amd.com 1792292SN/A /** Sets an integer register to the given value. */ 18012105Snathanael.premillieu@arm.com void setIntReg(PhysRegIdPtr phys_reg, uint64_t val) 1811060SN/A { 18212105Snathanael.premillieu@arm.com assert(phys_reg->isIntPhysReg()); 1831061SN/A 1842690Sktlim@umich.edu DPRINTF(IEW, "RegFile: Setting int register %i to %#x\n", 18512106SRekai.GonzalezAlberquilla@arm.com phys_reg->index(), val); 1861060SN/A 18712105Snathanael.premillieu@arm.com if (!phys_reg->isZeroReg()) 18812106SRekai.GonzalezAlberquilla@arm.com intRegFile[phys_reg->index()] = val; 1891060SN/A } 1901060SN/A 1912292SN/A /** Sets a double precision floating point register to the given value. */ 19212105Snathanael.premillieu@arm.com void setFloatReg(PhysRegIdPtr phys_reg, FloatReg val) 1931060SN/A { 19412105Snathanael.premillieu@arm.com assert(phys_reg->isFloatPhysReg()); 1951061SN/A 1962690Sktlim@umich.edu DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n", 19712106SRekai.GonzalezAlberquilla@arm.com phys_reg->index(), (uint64_t)val); 1981060SN/A 19912105Snathanael.premillieu@arm.com if (!phys_reg->isZeroReg()) 20012106SRekai.GonzalezAlberquilla@arm.com floatRegFile[phys_reg->index()].d = val; 2011060SN/A } 2021060SN/A 20312105Snathanael.premillieu@arm.com void setFloatRegBits(PhysRegIdPtr phys_reg, FloatRegBits val) 2042455SN/A { 20512105Snathanael.premillieu@arm.com assert(phys_reg->isFloatPhysReg()); 2062455SN/A 2072690Sktlim@umich.edu DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n", 20812106SRekai.GonzalezAlberquilla@arm.com phys_reg->index(), (uint64_t)val); 2092455SN/A 21012106SRekai.GonzalezAlberquilla@arm.com floatRegFile[phys_reg->index()].q = val; 2111060SN/A } 2121060SN/A 2139920Syasuko.eckert@amd.com /** Sets a condition-code register to the given value. */ 21412105Snathanael.premillieu@arm.com void setCCReg(PhysRegIdPtr phys_reg, CCReg val) 2159920Syasuko.eckert@amd.com { 21612105Snathanael.premillieu@arm.com assert(phys_reg->isCCPhysReg()); 2179920Syasuko.eckert@amd.com 2189920Syasuko.eckert@amd.com DPRINTF(IEW, "RegFile: Setting cc register %i to %#x\n", 21912106SRekai.GonzalezAlberquilla@arm.com phys_reg->index(), (uint64_t)val); 2209920Syasuko.eckert@amd.com 22112106SRekai.GonzalezAlberquilla@arm.com ccRegFile[phys_reg->index()] = val; 2229920Syasuko.eckert@amd.com } 2231060SN/A}; 2241060SN/A 2259915Ssteve.reinhardt@amd.com 2269915Ssteve.reinhardt@amd.com#endif //__CPU_O3_REGFILE_HH__ 227