2bit_local.cc (13626:d6a6358aa6db) 2bit_local.cc (13959:ea907b02c800)
1/*
2 * Copyright (c) 2004-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;

--- 24 unchanged lines hidden (view full) ---

33#include "base/intmath.hh"
34#include "base/logging.hh"
35#include "base/trace.hh"
36#include "debug/Fetch.hh"
37
38LocalBP::LocalBP(const LocalBPParams *params)
39 : BPredUnit(params),
40 localPredictorSize(params->localPredictorSize),
1/*
2 * Copyright (c) 2004-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;

--- 24 unchanged lines hidden (view full) ---

33#include "base/intmath.hh"
34#include "base/logging.hh"
35#include "base/trace.hh"
36#include "debug/Fetch.hh"
37
38LocalBP::LocalBP(const LocalBPParams *params)
39 : BPredUnit(params),
40 localPredictorSize(params->localPredictorSize),
41 localCtrBits(params->localCtrBits)
41 localCtrBits(params->localCtrBits),
42 localPredictorSets(localPredictorSize / localCtrBits),
43 localCtrs(localPredictorSets, SatCounter(localCtrBits)),
44 indexMask(localPredictorSets - 1)
42{
43 if (!isPowerOf2(localPredictorSize)) {
44 fatal("Invalid local predictor size!\n");
45 }
46
45{
46 if (!isPowerOf2(localPredictorSize)) {
47 fatal("Invalid local predictor size!\n");
48 }
49
47 localPredictorSets = localPredictorSize / localCtrBits;
48
49 if (!isPowerOf2(localPredictorSets)) {
50 fatal("Invalid number of local predictor sets! Check localCtrBits.\n");
51 }
52
50 if (!isPowerOf2(localPredictorSets)) {
51 fatal("Invalid number of local predictor sets! Check localCtrBits.\n");
52 }
53
53 // Setup the index mask.
54 indexMask = localPredictorSets - 1;
55
56 DPRINTF(Fetch, "index mask: %#x\n", indexMask);
57
54 DPRINTF(Fetch, "index mask: %#x\n", indexMask);
55
58 // Setup the array of counters for the local predictor.
59 localCtrs.resize(localPredictorSets);
60
61 for (unsigned i = 0; i < localPredictorSets; ++i)
62 localCtrs[i].setBits(localCtrBits);
63
64 DPRINTF(Fetch, "local predictor size: %i\n",
65 localPredictorSize);
66
67 DPRINTF(Fetch, "local counter bits: %i\n", localCtrBits);
68
69 DPRINTF(Fetch, "instruction shift amount: %i\n",
70 instShiftAmt);
71}
72
73void
56 DPRINTF(Fetch, "local predictor size: %i\n",
57 localPredictorSize);
58
59 DPRINTF(Fetch, "local counter bits: %i\n", localCtrBits);
60
61 DPRINTF(Fetch, "instruction shift amount: %i\n",
62 instShiftAmt);
63}
64
65void
74LocalBP::reset()
75{
76 for (unsigned i = 0; i < localPredictorSets; ++i) {
77 localCtrs[i].reset();
78 }
79}
80
81void
82LocalBP::btbUpdate(ThreadID tid, Addr branch_addr, void * &bp_history)
83{
84// Place holder for a function that is called to update predictor history when
85// a BTB entry is invalid or not found.
86}
87
88
89bool
90LocalBP::lookup(ThreadID tid, Addr branch_addr, void * &bp_history)
91{
92 bool taken;
66LocalBP::btbUpdate(ThreadID tid, Addr branch_addr, void * &bp_history)
67{
68// Place holder for a function that is called to update predictor history when
69// a BTB entry is invalid or not found.
70}
71
72
73bool
74LocalBP::lookup(ThreadID tid, Addr branch_addr, void * &bp_history)
75{
76 bool taken;
93 uint8_t counter_val;
94 unsigned local_predictor_idx = getLocalIndex(branch_addr);
95
96 DPRINTF(Fetch, "Looking up index %#x\n",
97 local_predictor_idx);
98
77 unsigned local_predictor_idx = getLocalIndex(branch_addr);
78
79 DPRINTF(Fetch, "Looking up index %#x\n",
80 local_predictor_idx);
81
99 counter_val = localCtrs[local_predictor_idx].read();
82 uint8_t counter_val = localCtrs[local_predictor_idx];
100
101 DPRINTF(Fetch, "prediction is %i.\n",
102 (int)counter_val);
103
104 taken = getPrediction(counter_val);
105
106#if 0
107 // Speculative update.
108 if (taken) {
109 DPRINTF(Fetch, "Branch updated as taken.\n");
83
84 DPRINTF(Fetch, "prediction is %i.\n",
85 (int)counter_val);
86
87 taken = getPrediction(counter_val);
88
89#if 0
90 // Speculative update.
91 if (taken) {
92 DPRINTF(Fetch, "Branch updated as taken.\n");
110 localCtrs[local_predictor_idx].increment();
93 localCtrs[local_predictor_idx]++;
111 } else {
112 DPRINTF(Fetch, "Branch updated as not taken.\n");
94 } else {
95 DPRINTF(Fetch, "Branch updated as not taken.\n");
113 localCtrs[local_predictor_idx].decrement();
96 localCtrs[local_predictor_idx]--;
114 }
115#endif
116
117 return taken;
118}
119
120void
121LocalBP::update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history,

--- 10 unchanged lines hidden (view full) ---

132
133 // Update the local predictor.
134 local_predictor_idx = getLocalIndex(branch_addr);
135
136 DPRINTF(Fetch, "Looking up index %#x\n", local_predictor_idx);
137
138 if (taken) {
139 DPRINTF(Fetch, "Branch updated as taken.\n");
97 }
98#endif
99
100 return taken;
101}
102
103void
104LocalBP::update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history,

--- 10 unchanged lines hidden (view full) ---

115
116 // Update the local predictor.
117 local_predictor_idx = getLocalIndex(branch_addr);
118
119 DPRINTF(Fetch, "Looking up index %#x\n", local_predictor_idx);
120
121 if (taken) {
122 DPRINTF(Fetch, "Branch updated as taken.\n");
140 localCtrs[local_predictor_idx].increment();
123 localCtrs[local_predictor_idx]++;
141 } else {
142 DPRINTF(Fetch, "Branch updated as not taken.\n");
124 } else {
125 DPRINTF(Fetch, "Branch updated as not taken.\n");
143 localCtrs[local_predictor_idx].decrement();
126 localCtrs[local_predictor_idx]--;
144 }
145}
146
147inline
148bool
149LocalBP::getPrediction(uint8_t &count)
150{
151 // Get the MSB of the count

--- 20 unchanged lines hidden ---
127 }
128}
129
130inline
131bool
132LocalBP::getPrediction(uint8_t &count)
133{
134 // Get the MSB of the count

--- 20 unchanged lines hidden ---