ras.cc revision 6226
16184SN/A/*
26184SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
36184SN/A * All rights reserved.
46184SN/A *
56184SN/A * Redistribution and use in source and binary forms, with or without
66184SN/A * modification, are permitted provided that the following conditions are
76184SN/A * met: redistributions of source code must retain the above copyright
86184SN/A * notice, this list of conditions and the following disclaimer;
96184SN/A * redistributions in binary form must reproduce the above copyright
106184SN/A * notice, this list of conditions and the following disclaimer in the
116184SN/A * documentation and/or other materials provided with the distribution;
126184SN/A * neither the name of the copyright holders nor the names of its
136184SN/A * contributors may be used to endorse or promote products derived from
146184SN/A * this software without specific prior written permission.
156184SN/A *
166184SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176184SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186184SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196184SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206184SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216184SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226184SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236184SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246184SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256184SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266184SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276184SN/A *
286184SN/A * Authors: Kevin Lim
296184SN/A */
306184SN/A
316226Snate@binkert.org#include "cpu/pred/ras.hh"
326184SN/A
336184SN/Avoid
346184SN/AReturnAddrStack::init(unsigned _numEntries)
356184SN/A{
366184SN/A     numEntries  = _numEntries;
376184SN/A     usedEntries = 0;
386184SN/A     tos = 0;
396184SN/A
406184SN/A     addrStack.resize(numEntries);
416184SN/A
426184SN/A     for (int i = 0; i < numEntries; ++i)
436184SN/A         addrStack[i] = 0;
446184SN/A}
456184SN/A
466184SN/Avoid
476184SN/AReturnAddrStack::reset()
486184SN/A{
496184SN/A    usedEntries = 0;
506184SN/A    tos = 0;
516184SN/A    for (int i = 0; i < numEntries; ++i)
526184SN/A        addrStack[i] = 0;
536184SN/A}
546184SN/A
556184SN/Avoid
566184SN/AReturnAddrStack::push(const Addr &return_addr)
576184SN/A{
586184SN/A    incrTos();
596184SN/A
606184SN/A    addrStack[tos] = return_addr;
616184SN/A
626184SN/A    if (usedEntries != numEntries) {
636184SN/A        ++usedEntries;
646184SN/A    }
656184SN/A}
666184SN/A
676184SN/Avoid
686184SN/AReturnAddrStack::pop()
696184SN/A{
706184SN/A    if (usedEntries > 0) {
716184SN/A        --usedEntries;
726184SN/A    }
736184SN/A
746184SN/A    decrTos();
756184SN/A}
766184SN/A
776184SN/Avoid
786184SN/AReturnAddrStack::restore(unsigned top_entry_idx,
796184SN/A                         const Addr &restored_target)
806184SN/A{
816184SN/A    tos = top_entry_idx;
826184SN/A
836184SN/A    addrStack[tos] = restored_target;
846184SN/A}
85