regfile.hh revision 9086
11689SN/A/* 21689SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 292665Ssaidi@eecs.umich.edu * Gabe Black 301689SN/A */ 311689SN/A 322292SN/A#ifndef __CPU_O3_REGFILE_HH__ 332292SN/A#define __CPU_O3_REGFILE_HH__ 341060SN/A 356658Snate@binkert.org#include <vector> 366658Snate@binkert.org 372165SN/A#include "arch/isa_traits.hh" 388793Sgblack@eecs.umich.edu#include "arch/kernel_stats.hh" 392669Sktlim@umich.edu#include "arch/types.hh" 401681SN/A#include "base/trace.hh" 416658Snate@binkert.org#include "config/the_isa.hh" 421717SN/A#include "cpu/o3/comm.hh" 438232Snate@binkert.org#include "debug/IEW.hh" 441060SN/A 452292SN/A/** 462292SN/A * Simple physical register file class. 472669Sktlim@umich.edu * Right now this is specific to Alpha until we decide if/how to make things 482669Sktlim@umich.edu * generic enough to support other ISAs. 492292SN/A */ 501061SN/Atemplate <class Impl> 511060SN/Aclass PhysRegFile 521060SN/A{ 532107SN/A protected: 542107SN/A typedef TheISA::IntReg IntReg; 552107SN/A typedef TheISA::FloatReg FloatReg; 562669Sktlim@umich.edu typedef TheISA::FloatRegBits FloatRegBits; 572159SN/A 582669Sktlim@umich.edu typedef union { 592669Sktlim@umich.edu FloatReg d; 602669Sktlim@umich.edu FloatRegBits q; 612669Sktlim@umich.edu } PhysFloatReg; 621060SN/A 632292SN/A // Note that most of the definitions of the IntReg, FloatReg, etc. exist 642292SN/A // within the Impl/ISA class and not within this PhysRegFile class. 651060SN/A 662292SN/A // Will make these registers public for now, but they probably should 672292SN/A // be private eventually with some accessor functions. 681060SN/A public: 692733Sktlim@umich.edu typedef typename Impl::O3CPU O3CPU; 701060SN/A 712292SN/A /** 722292SN/A * Constructs a physical register file with the specified amount of 732292SN/A * integer and floating point registers. 742292SN/A */ 754329Sktlim@umich.edu PhysRegFile(O3CPU *_cpu, unsigned _numPhysicalIntRegs, 761060SN/A unsigned _numPhysicalFloatRegs); 771060SN/A 789086Sandreas.hansson@arm.com /** 799086Sandreas.hansson@arm.com * Destructor to free resources 809086Sandreas.hansson@arm.com */ 819086Sandreas.hansson@arm.com ~PhysRegFile(); 829086Sandreas.hansson@arm.com 831060SN/A //Everything below should be pretty well identical to the normal 841060SN/A //register file that exists within AlphaISA class. 851060SN/A //The duplication is unfortunate but it's better than having 861060SN/A //different ways to access certain registers. 871060SN/A 882292SN/A /** Reads an integer register. */ 891060SN/A uint64_t readIntReg(PhysRegIndex reg_idx) 901060SN/A { 911061SN/A assert(reg_idx < numPhysicalIntRegs); 921061SN/A 931060SN/A DPRINTF(IEW, "RegFile: Access to int register %i, has data " 942690Sktlim@umich.edu "%#x\n", int(reg_idx), intRegFile[reg_idx]); 951060SN/A return intRegFile[reg_idx]; 961060SN/A } 971060SN/A 982292SN/A /** Reads a floating point register (double precision). */ 992455SN/A FloatReg readFloatReg(PhysRegIndex reg_idx) 1001060SN/A { 1011060SN/A // Remove the base Float reg dependency. 1021060SN/A reg_idx = reg_idx - numPhysicalIntRegs; 1031060SN/A 1041062SN/A assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs); 1051061SN/A 1062669Sktlim@umich.edu FloatReg floatReg = floatRegFile[reg_idx].d; 1071060SN/A 1082455SN/A DPRINTF(IEW, "RegFile: Access to float register %i, has " 1092690Sktlim@umich.edu "data %#x\n", int(reg_idx), floatRegFile[reg_idx].q); 1102455SN/A 1112455SN/A return floatReg; 1121060SN/A } 1131060SN/A 1142455SN/A FloatRegBits readFloatRegBits(PhysRegIndex reg_idx) 1152455SN/A { 1162455SN/A // Remove the base Float reg dependency. 1172455SN/A reg_idx = reg_idx - numPhysicalIntRegs; 1182455SN/A 1192455SN/A assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs); 1202455SN/A 1212669Sktlim@umich.edu FloatRegBits floatRegBits = floatRegFile[reg_idx].q; 1222455SN/A 1232455SN/A DPRINTF(IEW, "RegFile: Access to float register %i as int, " 1242690Sktlim@umich.edu "has data %#x\n", int(reg_idx), (uint64_t)floatRegBits); 1252455SN/A 1262455SN/A return floatRegBits; 1271060SN/A } 1281060SN/A 1292292SN/A /** Sets an integer register to the given value. */ 1301060SN/A void setIntReg(PhysRegIndex reg_idx, uint64_t val) 1311060SN/A { 1321061SN/A assert(reg_idx < numPhysicalIntRegs); 1331061SN/A 1342690Sktlim@umich.edu DPRINTF(IEW, "RegFile: Setting int register %i to %#x\n", 1351060SN/A int(reg_idx), val); 1361060SN/A 1372292SN/A if (reg_idx != TheISA::ZeroReg) 1382292SN/A intRegFile[reg_idx] = val; 1391060SN/A } 1401060SN/A 1412292SN/A /** Sets a double precision floating point register to the given value. */ 1422455SN/A void setFloatReg(PhysRegIndex reg_idx, FloatReg val) 1431060SN/A { 1441060SN/A // Remove the base Float reg dependency. 1451060SN/A reg_idx = reg_idx - numPhysicalIntRegs; 1461060SN/A 1474352Sgblack@eecs.umich.edu assert(reg_idx < numPhysicalFloatRegs); 1481061SN/A 1492690Sktlim@umich.edu DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n", 1502690Sktlim@umich.edu int(reg_idx), (uint64_t)val); 1511060SN/A 1524642Sgblack@eecs.umich.edu#if THE_ISA == ALPHA_ISA 1532292SN/A if (reg_idx != TheISA::ZeroReg) 1544642Sgblack@eecs.umich.edu#endif 1552669Sktlim@umich.edu floatRegFile[reg_idx].d = val; 1561060SN/A } 1571060SN/A 1582455SN/A void setFloatRegBits(PhysRegIndex reg_idx, FloatRegBits val) 1592455SN/A { 1602455SN/A // Remove the base Float reg dependency. 1612455SN/A reg_idx = reg_idx - numPhysicalIntRegs; 1622455SN/A 1634352Sgblack@eecs.umich.edu assert(reg_idx < numPhysicalFloatRegs); 1642455SN/A 1652690Sktlim@umich.edu DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n", 1662455SN/A int(reg_idx), (uint64_t)val); 1672455SN/A 1682669Sktlim@umich.edu floatRegFile[reg_idx].q = val; 1691060SN/A } 1701060SN/A 1711060SN/A public: 1721060SN/A /** (signed) integer register file. */ 1732690Sktlim@umich.edu IntReg *intRegFile; 1741060SN/A 1751060SN/A /** Floating point register file. */ 1762690Sktlim@umich.edu PhysFloatReg *floatRegFile; 1771060SN/A 1781060SN/A private: 1795543Ssaidi@eecs.umich.edu int intrflag; // interrupt flag 1801681SN/A 1811681SN/A private: 1822292SN/A /** CPU pointer. */ 1832733Sktlim@umich.edu O3CPU *cpu; 1841681SN/A 1851681SN/A public: 1862292SN/A /** Number of physical integer registers. */ 1871060SN/A unsigned numPhysicalIntRegs; 1882292SN/A /** Number of physical floating point registers. */ 1891060SN/A unsigned numPhysicalFloatRegs; 1901060SN/A}; 1911060SN/A 1921061SN/Atemplate <class Impl> 1934329Sktlim@umich.eduPhysRegFile<Impl>::PhysRegFile(O3CPU *_cpu, unsigned _numPhysicalIntRegs, 1941060SN/A unsigned _numPhysicalFloatRegs) 1954329Sktlim@umich.edu : cpu(_cpu), numPhysicalIntRegs(_numPhysicalIntRegs), 1961060SN/A numPhysicalFloatRegs(_numPhysicalFloatRegs) 1971060SN/A{ 1982690Sktlim@umich.edu intRegFile = new IntReg[numPhysicalIntRegs]; 1992690Sktlim@umich.edu floatRegFile = new PhysFloatReg[numPhysicalFloatRegs]; 2001060SN/A 2012690Sktlim@umich.edu memset(intRegFile, 0, sizeof(IntReg) * numPhysicalIntRegs); 2022690Sktlim@umich.edu memset(floatRegFile, 0, sizeof(PhysFloatReg) * numPhysicalFloatRegs); 2031060SN/A} 2041060SN/A 2059086Sandreas.hansson@arm.comtemplate <class Impl> 2069086Sandreas.hansson@arm.comPhysRegFile<Impl>::~PhysRegFile() 2079086Sandreas.hansson@arm.com{ 2089086Sandreas.hansson@arm.com delete intRegFile; 2099086Sandreas.hansson@arm.com delete floatRegFile; 2109086Sandreas.hansson@arm.com} 2119086Sandreas.hansson@arm.com 2122292SN/A#endif 213