rename_map.hh revision 2980:eab855f06b79
14202Sbinkertn@umich.edu/*
24202Sbinkertn@umich.edu * Copyright (c) 2004-2005 The Regents of The University of Michigan
34202Sbinkertn@umich.edu * All rights reserved.
44202Sbinkertn@umich.edu *
54202Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without
64202Sbinkertn@umich.edu * modification, are permitted provided that the following conditions are
74202Sbinkertn@umich.edu * met: redistributions of source code must retain the above copyright
84202Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer;
94202Sbinkertn@umich.edu * redistributions in binary form must reproduce the above copyright
104202Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer in the
114202Sbinkertn@umich.edu * documentation and/or other materials provided with the distribution;
124202Sbinkertn@umich.edu * neither the name of the copyright holders nor the names of its
134202Sbinkertn@umich.edu * contributors may be used to endorse or promote products derived from
144202Sbinkertn@umich.edu * this software without specific prior written permission.
154202Sbinkertn@umich.edu *
164202Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
174202Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
184202Sbinkertn@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
194202Sbinkertn@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
204202Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
214202Sbinkertn@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
224202Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234202Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
244202Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254202Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
264202Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274202Sbinkertn@umich.edu *
284202Sbinkertn@umich.edu * Authors: Kevin Lim
294202Sbinkertn@umich.edu */
304202Sbinkertn@umich.edu
314202Sbinkertn@umich.edu// Todo:  Create destructor.
324202Sbinkertn@umich.edu// Have it so that there's a more meaningful name given to the variable
334202Sbinkertn@umich.edu// that marks the beginning of the FP registers.
34
35#ifndef __CPU_O3_RENAME_MAP_HH__
36#define __CPU_O3_RENAME_MAP_HH__
37
38#include <iostream>
39#include <utility>
40#include <vector>
41
42#include "cpu/o3/free_list.hh"
43#include "arch/types.hh"
44
45class SimpleRenameMap
46{
47  protected:
48    typedef TheISA::RegIndex RegIndex;
49  public:
50    /**
51     * Pair of a logical register and a physical register.  Tells the
52     * previous mapping of a logical register to a physical register.
53     * Used to roll back the rename map to a previous state.
54     */
55    typedef std::pair<RegIndex, PhysRegIndex> UnmapInfo;
56
57    /**
58     * Pair of a physical register and a physical register.  Used to
59     * return the physical register that a logical register has been
60     * renamed to, and the previous physical register that the same
61     * logical register was previously mapped to.
62     */
63    typedef std::pair<PhysRegIndex, PhysRegIndex> RenameInfo;
64
65  public:
66    /** Default constructor.  init() must be called prior to use. */
67    SimpleRenameMap() {};
68
69    /** Destructor. */
70    ~SimpleRenameMap();
71
72    /** Initializes rename map with given parameters. */
73    void init(unsigned _numLogicalIntRegs,
74              unsigned _numPhysicalIntRegs,
75              PhysRegIndex &_int_reg_start,
76
77              unsigned _numLogicalFloatRegs,
78              unsigned _numPhysicalFloatRegs,
79              PhysRegIndex &_float_reg_start,
80
81              unsigned _numMiscRegs,
82
83              RegIndex _intZeroReg,
84              RegIndex _floatZeroReg,
85
86              int id,
87              bool bindRegs);
88
89    /** Sets the free list used with this rename map. */
90    void setFreeList(SimpleFreeList *fl_ptr);
91
92    //Tell rename map to get a free physical register for a given
93    //architected register.  Not sure it should have a return value,
94    //but perhaps it should have some sort of fault in case there are
95    //no free registers.
96    RenameInfo rename(RegIndex arch_reg);
97
98    PhysRegIndex lookup(RegIndex phys_reg);
99
100    /**
101     * Marks the given register as ready, meaning that its value has been
102     * calculated and written to the register file.
103     * @param ready_reg The index of the physical register that is now ready.
104     */
105    void setEntry(RegIndex arch_reg, PhysRegIndex renamed_reg);
106
107    int numFreeEntries();
108
109  private:
110    /** Rename Map ID  */
111    int id;
112
113    /** Number of logical integer registers. */
114    int numLogicalIntRegs;
115
116    /** Number of physical integer registers. */
117    int numPhysicalIntRegs;
118
119    /** Number of logical floating point registers. */
120    int numLogicalFloatRegs;
121
122    /** Number of physical floating point registers. */
123    int numPhysicalFloatRegs;
124
125    /** Number of miscellaneous registers. */
126    int numMiscRegs;
127
128    /** Number of logical integer + float registers. */
129    int numLogicalRegs;
130
131    /** Number of physical integer + float registers. */
132    int numPhysicalRegs;
133
134    /** The integer zero register.  This implementation assumes it is always
135     *  zero and never can be anything else.
136     */
137    RegIndex intZeroReg;
138
139    /** The floating point zero register.  This implementation assumes it is
140     *  always zero and never can be anything else.
141     */
142    RegIndex floatZeroReg;
143
144    class RenameEntry
145    {
146      public:
147        PhysRegIndex physical_reg;
148        bool valid;
149
150        RenameEntry()
151            : physical_reg(0), valid(false)
152        { }
153    };
154
155  private:
156    /** Integer rename map. */
157    std::vector<RenameEntry> intRenameMap;
158
159    /** Floating point rename map. */
160    std::vector<RenameEntry> floatRenameMap;
161
162  private:
163    /** Free list interface. */
164    SimpleFreeList *freeList;
165};
166
167#endif //__CPU_O3_RENAME_MAP_HH__
168