regfile.hh revision 13611
112855Sgabeblack@google.com/* 212855Sgabeblack@google.com * Copyright (c) 2016-2017 ARM Limited 312855Sgabeblack@google.com * All rights reserved 412855Sgabeblack@google.com * 512855Sgabeblack@google.com * The license below extends only to copyright in the software and shall 612855Sgabeblack@google.com * not be construed as granting a license to any other intellectual 712855Sgabeblack@google.com * property including but not limited to intellectual property relating 812855Sgabeblack@google.com * to a hardware implementation of the functionality of the software 912855Sgabeblack@google.com * licensed hereunder. You may use the software subject to the license 1012855Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated 1112855Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software, 1212855Sgabeblack@google.com * modified or unmodified, in source code or in binary form. 1312855Sgabeblack@google.com * 1412855Sgabeblack@google.com * Copyright (c) 2004-2005 The Regents of The University of Michigan 1512855Sgabeblack@google.com * Copyright (c) 2013 Advanced Micro Devices, Inc. 1612855Sgabeblack@google.com * All rights reserved. 1712855Sgabeblack@google.com * 1812855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 1912855Sgabeblack@google.com * modification, are permitted provided that the following conditions are 2012855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 2112855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 2212855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 2312855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 2412855Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 2512855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 2612855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 2712855Sgabeblack@google.com * this software without specific prior written permission. 2812855Sgabeblack@google.com * 2912855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3012855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3112855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3212855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3312855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3412855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3512855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3612855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3712855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3812855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3912855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4012855Sgabeblack@google.com * 4112855Sgabeblack@google.com * Authors: Kevin Lim 4212855Sgabeblack@google.com * Gabe Black 4312855Sgabeblack@google.com */ 4412855Sgabeblack@google.com 4512855Sgabeblack@google.com#ifndef __CPU_O3_REGFILE_HH__ 4612855Sgabeblack@google.com#define __CPU_O3_REGFILE_HH__ 4712855Sgabeblack@google.com 4812855Sgabeblack@google.com#include <vector> 4912855Sgabeblack@google.com 5012855Sgabeblack@google.com#include "arch/isa_traits.hh" 5112855Sgabeblack@google.com#include "arch/kernel_stats.hh" 5212855Sgabeblack@google.com#include "arch/types.hh" 5312855Sgabeblack@google.com#include "base/trace.hh" 5412855Sgabeblack@google.com#include "config/the_isa.hh" 5512855Sgabeblack@google.com#include "cpu/o3/comm.hh" 5612855Sgabeblack@google.com#include "debug/IEW.hh" 5712855Sgabeblack@google.com#include "enums/VecRegRenameMode.hh" 5812855Sgabeblack@google.com 5912855Sgabeblack@google.comclass UnifiedFreeList; 6012855Sgabeblack@google.com 6112855Sgabeblack@google.com/** 6212855Sgabeblack@google.com * Simple physical register file class. 6312855Sgabeblack@google.com */ 6412855Sgabeblack@google.comclass PhysRegFile 6512855Sgabeblack@google.com{ 6612855Sgabeblack@google.com private: 6712855Sgabeblack@google.com 6812855Sgabeblack@google.com typedef TheISA::CCReg CCReg; 6912855Sgabeblack@google.com using VecElem = TheISA::VecElem; 7012855Sgabeblack@google.com using VecRegContainer = TheISA::VecRegContainer; 7112855Sgabeblack@google.com using PhysIds = std::vector<PhysRegId>; 7212855Sgabeblack@google.com using VecMode = Enums::VecRegRenameMode; 7312855Sgabeblack@google.com using VecPredRegContainer = TheISA::VecPredRegContainer; 7412855Sgabeblack@google.com public: 7512855Sgabeblack@google.com using IdRange = std::pair<PhysIds::const_iterator, 7612855Sgabeblack@google.com PhysIds::const_iterator>; 7712855Sgabeblack@google.com private: 7812855Sgabeblack@google.com static constexpr auto NumVecElemPerVecReg = TheISA::NumVecElemPerVecReg; 79 80 /** Integer register file. */ 81 std::vector<RegVal> intRegFile; 82 std::vector<PhysRegId> intRegIds; 83 84 /** Floating point register file. */ 85 std::vector<RegVal> floatRegFile; 86 std::vector<PhysRegId> floatRegIds; 87 88 /** Vector register file. */ 89 std::vector<VecRegContainer> vectorRegFile; 90 std::vector<PhysRegId> vecRegIds; 91 std::vector<PhysRegId> vecElemIds; 92 93 /** Predicate register file. */ 94 std::vector<VecPredRegContainer> vecPredRegFile; 95 std::vector<PhysRegId> vecPredRegIds; 96 97 /** Condition-code register file. */ 98 std::vector<CCReg> ccRegFile; 99 std::vector<PhysRegId> ccRegIds; 100 101 /** Misc Reg Ids */ 102 std::vector<PhysRegId> miscRegIds; 103 104 /** 105 * Number of physical general purpose registers 106 */ 107 unsigned numPhysicalIntRegs; 108 109 /** 110 * Number of physical floating point registers 111 */ 112 unsigned numPhysicalFloatRegs; 113 114 /** 115 * Number of physical vector registers 116 */ 117 unsigned numPhysicalVecRegs; 118 119 /** 120 * Number of physical vector element registers 121 */ 122 unsigned numPhysicalVecElemRegs; 123 124 /** 125 * Number of physical predicate registers 126 */ 127 unsigned numPhysicalVecPredRegs; 128 129 /** 130 * Number of physical CC registers 131 */ 132 unsigned numPhysicalCCRegs; 133 134 /** Total number of physical registers. */ 135 unsigned totalNumRegs; 136 137 /** Mode in which vector registers are addressed. */ 138 VecMode vecMode; 139 140 public: 141 /** 142 * Constructs a physical register file with the specified amount of 143 * integer and floating point registers. 144 */ 145 PhysRegFile(unsigned _numPhysicalIntRegs, 146 unsigned _numPhysicalFloatRegs, 147 unsigned _numPhysicalVecRegs, 148 unsigned _numPhysicalVecPredRegs, 149 unsigned _numPhysicalCCRegs, 150 VecMode vmode 151 ); 152 153 /** 154 * Destructor to free resources 155 */ 156 ~PhysRegFile() {} 157 158 /** Initialize the free list */ 159 void initFreeList(UnifiedFreeList *freeList); 160 161 /** @return the number of integer physical registers. */ 162 unsigned numIntPhysRegs() const { return numPhysicalIntRegs; } 163 164 /** @return the number of floating-point physical registers. */ 165 unsigned numFloatPhysRegs() const { return numPhysicalFloatRegs; } 166 /** @return the number of vector physical registers. */ 167 unsigned numVecPhysRegs() const { return numPhysicalVecRegs; } 168 /** @return the number of predicate physical registers. */ 169 unsigned numPredPhysRegs() const { return numPhysicalVecPredRegs; } 170 171 /** @return the number of vector physical registers. */ 172 unsigned numVecElemPhysRegs() const { return numPhysicalVecElemRegs; } 173 174 /** @return the number of condition-code physical registers. */ 175 unsigned numCCPhysRegs() const { return numPhysicalCCRegs; } 176 177 /** @return the total number of physical registers. */ 178 unsigned totalNumPhysRegs() const { return totalNumRegs; } 179 180 /** Gets a misc register PhysRegIdPtr. */ 181 PhysRegIdPtr getMiscRegId(RegIndex reg_idx) { 182 return &miscRegIds[reg_idx]; 183 } 184 185 /** Reads an integer register. */ 186 RegVal 187 readIntReg(PhysRegIdPtr phys_reg) const 188 { 189 assert(phys_reg->isIntPhysReg()); 190 191 DPRINTF(IEW, "RegFile: Access to int register %i, has data " 192 "%#x\n", phys_reg->index(), intRegFile[phys_reg->index()]); 193 return intRegFile[phys_reg->index()]; 194 } 195 196 RegVal 197 readFloatReg(PhysRegIdPtr phys_reg) const 198 { 199 assert(phys_reg->isFloatPhysReg()); 200 201 RegVal floatRegBits = floatRegFile[phys_reg->index()]; 202 203 DPRINTF(IEW, "RegFile: Access to float register %i as int, " 204 "has data %#x\n", phys_reg->index(), floatRegBits); 205 206 return floatRegBits; 207 } 208 209 /** Reads a vector register. */ 210 const VecRegContainer & 211 readVecReg(PhysRegIdPtr phys_reg) const 212 { 213 assert(phys_reg->isVectorPhysReg()); 214 215 DPRINTF(IEW, "RegFile: Access to vector register %i, has " 216 "data %s\n", int(phys_reg->index()), 217 vectorRegFile[phys_reg->index()].print()); 218 219 return vectorRegFile[phys_reg->index()]; 220 } 221 222 /** Reads a vector register for modification. */ 223 VecRegContainer & 224 getWritableVecReg(PhysRegIdPtr phys_reg) 225 { 226 /* const_cast for not duplicating code above. */ 227 return const_cast<VecRegContainer&>(readVecReg(phys_reg)); 228 } 229 230 /** Reads a vector register lane. */ 231 template <typename VecElem, int LaneIdx> 232 VecLaneT<VecElem, true> 233 readVecLane(PhysRegIdPtr phys_reg) const 234 { 235 return readVecReg(phys_reg).laneView<VecElem, LaneIdx>(); 236 } 237 238 /** Reads a vector register lane. */ 239 template <typename VecElem> 240 VecLaneT<VecElem, true> 241 readVecLane(PhysRegIdPtr phys_reg) const 242 { 243 return readVecReg(phys_reg).laneView<VecElem>(phys_reg->elemIndex()); 244 } 245 246 /** Get a vector register lane for modification. */ 247 template <typename LD> 248 void 249 setVecLane(PhysRegIdPtr phys_reg, const LD& val) 250 { 251 assert(phys_reg->isVectorPhysReg()); 252 253 DPRINTF(IEW, "RegFile: Setting vector register %i[%d] to %lx\n", 254 int(phys_reg->index()), phys_reg->elemIndex(), val); 255 256 vectorRegFile[phys_reg->index()].laneView<typename LD::UnderlyingType>( 257 phys_reg->elemIndex()) = val; 258 } 259 260 /** Reads a vector element. */ 261 const VecElem & 262 readVecElem(PhysRegIdPtr phys_reg) const 263 { 264 assert(phys_reg->isVectorPhysElem()); 265 auto ret = vectorRegFile[phys_reg->index()].as<VecElem>(); 266 const VecElem& val = ret[phys_reg->elemIndex()]; 267 DPRINTF(IEW, "RegFile: Access to element %d of vector register %i," 268 " has data %#x\n", phys_reg->elemIndex(), 269 int(phys_reg->index()), val); 270 271 return val; 272 } 273 274 /** Reads a predicate register. */ 275 const VecPredRegContainer& readVecPredReg(PhysRegIdPtr phys_reg) const 276 { 277 assert(phys_reg->isVecPredPhysReg()); 278 279 DPRINTF(IEW, "RegFile: Access to predicate register %i, has " 280 "data %s\n", int(phys_reg->index()), 281 vecPredRegFile[phys_reg->index()].print()); 282 283 return vecPredRegFile[phys_reg->index()]; 284 } 285 286 VecPredRegContainer& getWritableVecPredReg(PhysRegIdPtr phys_reg) 287 { 288 /* const_cast for not duplicating code above. */ 289 return const_cast<VecPredRegContainer&>(readVecPredReg(phys_reg)); 290 } 291 292 /** Reads a condition-code register. */ 293 CCReg 294 readCCReg(PhysRegIdPtr phys_reg) 295 { 296 assert(phys_reg->isCCPhysReg()); 297 298 DPRINTF(IEW, "RegFile: Access to cc register %i, has " 299 "data %#x\n", phys_reg->index(), 300 ccRegFile[phys_reg->index()]); 301 302 return ccRegFile[phys_reg->index()]; 303 } 304 305 /** Sets an integer register to the given value. */ 306 void 307 setIntReg(PhysRegIdPtr phys_reg, RegVal val) 308 { 309 assert(phys_reg->isIntPhysReg()); 310 311 DPRINTF(IEW, "RegFile: Setting int register %i to %#x\n", 312 phys_reg->index(), val); 313 314 if (!phys_reg->isZeroReg()) 315 intRegFile[phys_reg->index()] = val; 316 } 317 318 void 319 setFloatReg(PhysRegIdPtr phys_reg, RegVal val) 320 { 321 assert(phys_reg->isFloatPhysReg()); 322 323 DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n", 324 phys_reg->index(), (uint64_t)val); 325 326 if (!phys_reg->isZeroReg()) 327 floatRegFile[phys_reg->index()] = val; 328 } 329 330 /** Sets a vector register to the given value. */ 331 void 332 setVecReg(PhysRegIdPtr phys_reg, const VecRegContainer& val) 333 { 334 assert(phys_reg->isVectorPhysReg()); 335 336 DPRINTF(IEW, "RegFile: Setting vector register %i to %s\n", 337 int(phys_reg->index()), val.print()); 338 339 vectorRegFile[phys_reg->index()] = val; 340 } 341 342 /** Sets a vector register to the given value. */ 343 void 344 setVecElem(PhysRegIdPtr phys_reg, const VecElem val) 345 { 346 assert(phys_reg->isVectorPhysElem()); 347 348 DPRINTF(IEW, "RegFile: Setting element %d of vector register %i to" 349 " %#x\n", phys_reg->elemIndex(), int(phys_reg->index()), val); 350 351 vectorRegFile[phys_reg->index()].as<VecElem>()[phys_reg->elemIndex()] = 352 val; 353 } 354 355 /** Sets a predicate register to the given value. */ 356 void setVecPredReg(PhysRegIdPtr phys_reg, const VecPredRegContainer& val) 357 { 358 assert(phys_reg->isVecPredPhysReg()); 359 360 DPRINTF(IEW, "RegFile: Setting predicate register %i to %s\n", 361 int(phys_reg->index()), val.print()); 362 363 vecPredRegFile[phys_reg->index()] = val; 364 } 365 366 /** Sets a condition-code register to the given value. */ 367 void 368 setCCReg(PhysRegIdPtr phys_reg, CCReg val) 369 { 370 assert(phys_reg->isCCPhysReg()); 371 372 DPRINTF(IEW, "RegFile: Setting cc register %i to %#x\n", 373 phys_reg->index(), (uint64_t)val); 374 375 ccRegFile[phys_reg->index()] = val; 376 } 377 378 /** Get the PhysRegIds of the elems of a vector register. 379 * Auxiliary function to transition from Full vector mode to Elem mode. 380 */ 381 IdRange getRegElemIds(PhysRegIdPtr reg); 382 383 /** 384 * Get the PhysRegIds of the elems of all vector registers. 385 * Auxiliary function to transition from Full vector mode to Elem mode 386 * and to initialise the rename map. 387 */ 388 IdRange getRegIds(RegClass cls); 389 390 /** 391 * Get the true physical register id. 392 * As many parts work with PhysRegIdPtr, we need to be able to produce 393 * the pointer out of just class and register idx. 394 */ 395 PhysRegIdPtr getTrueId(PhysRegIdPtr reg); 396}; 397 398 399#endif //__CPU_O3_REGFILE_HH__ 400