scoreboard.cc revision 7699:addb847910d2
1/*
2 * Copyright (c) 2005-2006 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 * Authors: Korey Sewell
29 *          Kevin Lim
30 */
31
32#include "config/the_isa.hh"
33#include "cpu/o3/scoreboard.hh"
34
35Scoreboard::Scoreboard(unsigned activeThreads,
36                       unsigned _numLogicalIntRegs,
37                       unsigned _numPhysicalIntRegs,
38                       unsigned _numLogicalFloatRegs,
39                       unsigned _numPhysicalFloatRegs,
40                       unsigned _numMiscRegs,
41                       unsigned _zeroRegIdx)
42    : numLogicalIntRegs(_numLogicalIntRegs),
43      numPhysicalIntRegs(_numPhysicalIntRegs),
44      numLogicalFloatRegs(_numLogicalFloatRegs),
45      numPhysicalFloatRegs(_numPhysicalFloatRegs),
46      numMiscRegs(_numMiscRegs),
47      zeroRegIdx(_zeroRegIdx)
48{
49    //Get Register Sizes
50    numLogicalRegs = numLogicalIntRegs  + numLogicalFloatRegs;
51    numPhysicalRegs = numPhysicalIntRegs  + numPhysicalFloatRegs;
52
53    //Resize scoreboard appropriately
54    resize(numPhysicalRegs + (numMiscRegs * activeThreads));
55
56    //Initialize values
57    for (int i=0; i < numLogicalIntRegs * activeThreads; i++) {
58        assert(indexInBounds(i));
59        regScoreBoard[i] = 1;
60    }
61
62    for (int i= numPhysicalIntRegs;
63         i < numPhysicalIntRegs + (numLogicalFloatRegs * activeThreads);
64         i++) {
65        assert(indexInBounds(i));
66        regScoreBoard[i] = 1;
67    }
68
69    for (int i = numPhysicalRegs;
70         i < numPhysicalRegs + (numMiscRegs * activeThreads);
71         i++) {
72        assert(indexInBounds(i));
73        regScoreBoard[i] = 1;
74    }
75}
76
77std::string
78Scoreboard::name() const
79{
80    return "cpu.scoreboard";
81}
82
83bool
84Scoreboard::getReg(PhysRegIndex phys_reg)
85{
86#if THE_ISA == ALPHA_ISA
87    // Always ready if int or fp zero reg.
88    if (phys_reg == zeroRegIdx ||
89        phys_reg == (zeroRegIdx + numPhysicalIntRegs)) {
90        return 1;
91    }
92#else
93    // Always ready if int zero reg.
94    if (phys_reg == zeroRegIdx) {
95        return 1;
96    }
97#endif
98
99    assert(indexInBounds(phys_reg));
100    return regScoreBoard[phys_reg];
101}
102
103void
104Scoreboard::setReg(PhysRegIndex phys_reg)
105{
106    DPRINTF(Scoreboard, "Setting reg %i as ready\n", phys_reg);
107
108    assert(indexInBounds(phys_reg));
109    regScoreBoard[phys_reg] = 1;
110}
111
112void
113Scoreboard::unsetReg(PhysRegIndex ready_reg)
114{
115#if THE_ISA == ALPHA_ISA
116    if (ready_reg == zeroRegIdx ||
117        ready_reg == (zeroRegIdx + numPhysicalIntRegs)) {
118        // Don't do anything if int or fp zero reg.
119        return;
120    }
121#else
122    if (ready_reg == zeroRegIdx) {
123        // Don't do anything if int zero reg.
124        return;
125    }
126#endif
127
128    assert(indexInBounds(ready_reg));
129    regScoreBoard[ready_reg] = 0;
130}
131