rename_map.hh revision 1763
1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29// Todo: Create destructor. 30// Have it so that there's a more meaningful name given to the variable 31// that marks the beginning of the FP registers. 32 33#ifndef __CPU_O3_CPU_RENAME_MAP_HH__ 34#define __CPU_O3_CPU_RENAME_MAP_HH__ 35 36#include <iostream> 37#include <utility> 38#include <vector> 39 40#include "cpu/o3/free_list.hh" 41 42class SimpleRenameMap 43{ 44 public: 45 /** 46 * Pair of a logical register and a physical register. Tells the 47 * previous mapping of a logical register to a physical register. 48 * Used to roll back the rename map to a previous state. 49 */ 50 typedef std::pair<RegIndex, PhysRegIndex> UnmapInfo; 51 52 /** 53 * Pair of a physical register and a physical register. Used to 54 * return the physical register that a logical register has been 55 * renamed to, and the previous physical register that the same 56 * logical register was previously mapped to. 57 */ 58 typedef std::pair<PhysRegIndex, PhysRegIndex> RenameInfo; 59 60 public: 61 //Constructor 62 SimpleRenameMap(unsigned _numLogicalIntRegs, 63 unsigned _numPhysicalIntRegs, 64 unsigned _numLogicalFloatRegs, 65 unsigned _numPhysicalFloatRegs, 66 unsigned _numMiscRegs, 67 RegIndex _intZeroReg, 68 RegIndex _floatZeroReg); 69 70 /** Destructor. */ 71 ~SimpleRenameMap(); 72 73 void setFreeList(SimpleFreeList *fl_ptr); 74 75 //Tell rename map to get a free physical register for a given 76 //architected register. Not sure it should have a return value, 77 //but perhaps it should have some sort of fault in case there are 78 //no free registers. 79 RenameInfo rename(RegIndex arch_reg); 80 81 PhysRegIndex lookup(RegIndex phys_reg); 82 83 bool isReady(PhysRegIndex arch_reg); 84 85 /** 86 * Marks the given register as ready, meaning that its value has been 87 * calculated and written to the register file. 88 * @param ready_reg The index of the physical register that is now ready. 89 */ 90 void markAsReady(PhysRegIndex ready_reg); 91 92 void setEntry(RegIndex arch_reg, PhysRegIndex renamed_reg); 93 94 void squash(std::vector<RegIndex> freed_regs, 95 std::vector<UnmapInfo> unmaps); 96 97 int numFreeEntries(); 98 99 private: 100 /** Number of logical integer registers. */ 101 int numLogicalIntRegs; 102 103 /** Number of physical integer registers. */ 104 int numPhysicalIntRegs; 105 106 /** Number of logical floating point registers. */ 107 int numLogicalFloatRegs; 108 109 /** Number of physical floating point registers. */ 110 int numPhysicalFloatRegs; 111 112 /** Number of miscellaneous registers. */ 113 int numMiscRegs; 114 115 /** Number of logical integer + float registers. */ 116 int numLogicalRegs; 117 118 /** Number of physical integer + float registers. */ 119 int numPhysicalRegs; 120 121 /** The integer zero register. This implementation assumes it is always 122 * zero and never can be anything else. 123 */ 124 RegIndex intZeroReg; 125 126 /** The floating point zero register. This implementation assumes it is 127 * always zero and never can be anything else. 128 */ 129 RegIndex floatZeroReg; 130 131 class RenameEntry 132 { 133 public: 134 PhysRegIndex physical_reg; 135 bool valid; 136 137 RenameEntry() 138 : physical_reg(0), valid(false) 139 { } 140 }; 141 142 /** Integer rename map. */ 143 RenameEntry *intRenameMap; 144 145 /** Floating point rename map. */ 146 RenameEntry *floatRenameMap; 147 148 /** Free list interface. */ 149 SimpleFreeList *freeList; 150 151 // Might want to make all these scoreboards into one large scoreboard. 152 153 /** Scoreboard of physical integer registers, saying whether or not they 154 * are ready. 155 */ 156 std::vector<bool> intScoreboard; 157 158 /** Scoreboard of physical floating registers, saying whether or not they 159 * are ready. 160 */ 161 std::vector<bool> floatScoreboard; 162 163 /** Scoreboard of miscellaneous registers, saying whether or not they 164 * are ready. 165 */ 166 std::vector<bool> miscScoreboard; 167}; 168 169#endif //__CPU_O3_CPU_RENAME_MAP_HH__ 170