5f076673a29596cbfadcbe6ce6e2691287192c8c
2 * Copyright (c) 2004-2006 The Regents of The University of Michigan
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.
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.
29 #include "cpu/pred/2bit_local.hh"
31 #include "base/intmath.hh"
32 #include "base/logging.hh"
33 #include "base/trace.hh"
34 #include "debug/Fetch.hh"
36 LocalBP::LocalBP(const LocalBPParams
¶ms
)
38 localPredictorSize(params
.localPredictorSize
),
39 localCtrBits(params
.localCtrBits
),
40 localPredictorSets(localPredictorSize
/ localCtrBits
),
41 localCtrs(localPredictorSets
, SatCounter(localCtrBits
)),
42 indexMask(localPredictorSets
- 1)
44 if (!isPowerOf2(localPredictorSize
)) {
45 fatal("Invalid local predictor size!\n");
48 if (!isPowerOf2(localPredictorSets
)) {
49 fatal("Invalid number of local predictor sets! Check localCtrBits.\n");
52 DPRINTF(Fetch
, "index mask: %#x\n", indexMask
);
54 DPRINTF(Fetch
, "local predictor size: %i\n",
57 DPRINTF(Fetch
, "local counter bits: %i\n", localCtrBits
);
59 DPRINTF(Fetch
, "instruction shift amount: %i\n",
64 LocalBP::btbUpdate(ThreadID tid
, Addr branch_addr
, void * &bp_history
)
66 // Place holder for a function that is called to update predictor history when
67 // a BTB entry is invalid or not found.
72 LocalBP::lookup(ThreadID tid
, Addr branch_addr
, void * &bp_history
)
75 unsigned local_predictor_idx
= getLocalIndex(branch_addr
);
77 DPRINTF(Fetch
, "Looking up index %#x\n",
80 uint8_t counter_val
= localCtrs
[local_predictor_idx
];
82 DPRINTF(Fetch
, "prediction is %i.\n",
85 taken
= getPrediction(counter_val
);
91 LocalBP::update(ThreadID tid
, Addr branch_addr
, bool taken
, void *bp_history
,
92 bool squashed
, const StaticInstPtr
& inst
, Addr corrTarget
)
94 assert(bp_history
== NULL
);
95 unsigned local_predictor_idx
;
97 // No state to restore, and we do not update on the wrong
103 // Update the local predictor.
104 local_predictor_idx
= getLocalIndex(branch_addr
);
106 DPRINTF(Fetch
, "Looking up index %#x\n", local_predictor_idx
);
109 DPRINTF(Fetch
, "Branch updated as taken.\n");
110 localCtrs
[local_predictor_idx
]++;
112 DPRINTF(Fetch
, "Branch updated as not taken.\n");
113 localCtrs
[local_predictor_idx
]--;
119 LocalBP::getPrediction(uint8_t &count
)
121 // Get the MSB of the count
122 return (count
>> (localCtrBits
- 1));
127 LocalBP::getLocalIndex(Addr
&branch_addr
)
129 return (branch_addr
>> instShiftAmt
) & indexMask
;
133 LocalBP::uncondBranch(ThreadID tid
, Addr pc
, void *&bp_history
)
138 LocalBPParams::create() const
140 return new LocalBP(*this);