2bit_local.hh revision 2345
112855Sgabeblack@google.com/* 212855Sgabeblack@google.com * Copyright (c) 2004-2006 The Regents of The University of Michigan 312855Sgabeblack@google.com * All rights reserved. 412855Sgabeblack@google.com * 512855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612855Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112855Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412855Sgabeblack@google.com * this software without specific prior written permission. 1512855Sgabeblack@google.com * 1612855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712855Sgabeblack@google.com */ 2812855Sgabeblack@google.com 2912855Sgabeblack@google.com#ifndef __CPU_O3_2BIT_LOCAL_PRED_HH__ 3012855Sgabeblack@google.com#define __CPU_O3_2BIT_LOCAL_PRED_HH__ 3112855Sgabeblack@google.com 3212855Sgabeblack@google.com// For Addr type. 3312855Sgabeblack@google.com#include "arch/isa_traits.hh" 3412855Sgabeblack@google.com#include "cpu/o3/sat_counter.hh" 3512855Sgabeblack@google.com 3612855Sgabeblack@google.com#include <vector> 3712855Sgabeblack@google.com 3812855Sgabeblack@google.com/** 3912855Sgabeblack@google.com * Implements a local predictor that uses the PC to index into a table of 4012855Sgabeblack@google.com * counters. Note that any time a pointer to the bp_history is given, it 4112855Sgabeblack@google.com * should be NULL using this predictor because it does not have any branch 4212855Sgabeblack@google.com * predictor state that needs to be recorded or updated; the update can be 4312855Sgabeblack@google.com * determined solely by the branch being taken or not taken. 4412855Sgabeblack@google.com */ 4512855Sgabeblack@google.comclass LocalBP 4612855Sgabeblack@google.com{ 4712855Sgabeblack@google.com public: 4812855Sgabeblack@google.com /** 4912855Sgabeblack@google.com * Default branch predictor constructor. 5012855Sgabeblack@google.com * @param localPredictorSize Size of the local predictor. 5112855Sgabeblack@google.com * @param localCtrBits Number of bits per counter. 5212855Sgabeblack@google.com * @param instShiftAmt Offset amount for instructions to ignore alignment. 5312855Sgabeblack@google.com */ 5412855Sgabeblack@google.com LocalBP(unsigned localPredictorSize, unsigned localCtrBits, 5512855Sgabeblack@google.com unsigned instShiftAmt); 5612855Sgabeblack@google.com 5712855Sgabeblack@google.com /** 5812855Sgabeblack@google.com * Looks up the given address in the branch predictor and returns 5912855Sgabeblack@google.com * a true/false value as to whether it is taken. 6012855Sgabeblack@google.com * @param branch_addr The address of the branch to look up. 6112855Sgabeblack@google.com * @param bp_history Pointer to any bp history state. 6212855Sgabeblack@google.com * @return Whether or not the branch is taken. 6312855Sgabeblack@google.com */ 6412855Sgabeblack@google.com bool lookup(Addr &branch_addr, void * &bp_history); 6512855Sgabeblack@google.com 6612855Sgabeblack@google.com /** 6712855Sgabeblack@google.com * Updates the branch predictor with the actual result of a branch. 6812855Sgabeblack@google.com * @param branch_addr The address of the branch to update. 6912855Sgabeblack@google.com * @param taken Whether or not the branch was taken. 7012855Sgabeblack@google.com */ 7112855Sgabeblack@google.com void update(Addr &branch_addr, bool taken, void *bp_history); 72 73 void squash(void *bp_history) 74 { assert(bp_history == NULL); } 75 76 void reset(); 77 78 private: 79 /** 80 * Returns the taken/not taken prediction given the value of the 81 * counter. 82 * @param count The value of the counter. 83 * @return The prediction based on the counter value. 84 */ 85 inline bool getPrediction(uint8_t &count); 86 87 /** Calculates the local index based on the PC. */ 88 inline unsigned getLocalIndex(Addr &PC); 89 90 /** Array of counters that make up the local predictor. */ 91 std::vector<SatCounter> localCtrs; 92 93 /** Size of the local predictor. */ 94 unsigned localPredictorSize; 95 96 /** Number of sets. */ 97 unsigned localPredictorSets; 98 99 /** Number of bits of the local predictor's counters. */ 100 unsigned localCtrBits; 101 102 /** Number of bits to shift the PC when calculating index. */ 103 unsigned instShiftAmt; 104 105 /** Mask to get index bits. */ 106 unsigned indexMask; 107}; 108 109#endif // __CPU_O3_2BIT_LOCAL_PRED_HH__ 110