lrusecurity_ExistHitPrevUDomain.cpp 2.07 KB
Newer Older
1 2 3 4 5 6 7 8
#include "ExistHitPrevUDomain.h"

using namespace otawa;

namespace lrusecurity
{

ExistHitPrevUDomain::ExistHitPrevUDomain(
9 10 11 12 13 14 15
        const icat3::LBlockCollection& coll,
        int set,
        const t *init):
    _n(coll[set].count()),
    _bot(_n),
    _top(_n, Address(0x0)), //TO CHANGE
    _set(set),
16
	_coll(coll),
17 18 19
    _A(coll.A()),
    _init(init ? *init : _top),
    _tmp(_n)
20 21 22 23 24 25 26 27 28 29
{
}

bool ExistHitPrevUDomain::equals(const t& acss, const t& bcss) const
{
  for (int i = 0; i < _n; i++)
    if (acss[i] != bcss[i])
      return false;
  return true;
}
30 31

void ExistHitPrevUDomain::join(t& dcss, const t& scss, icat3::ACS d_eh, icat3::ACS s_eh)
32
{
33 34
  for (int i = 0; i < _n; i++) {
    if (s_eh[i] < d_eh[i] || (d_eh[i] == -1 && s_eh[i] != -1)) {
35
      dcss[i] = scss[i];
36 37 38 39 40 41 42 43
    } else if (s_eh[i] == d_eh[i]) {
      int fullsize = (dcss[i]).size() + (scss[i]).size();
      Bag <Address> tmp = Bag <Address> (fullsize);
      for (int j = 0; j < fullsize; j++) {
        if (j < (dcss[i]).size())
          tmp[j] = dcss[i][j];
        else
          tmp[j] = scss[i][j - dcss[i].size()];
44 45 46 47
      }
      dcss[i] = tmp;
    }
  }
48
}
49 50

void ExistHitPrevUDomain::fetch(t& acss, const icache::Access& access, lrupreanalysis::eh_em:: ACSManager & ehManager)
51 52 53 54 55
{
  icat3::LBlock *lb = icat3::LBLOCK(access);
  int b = lb->index();
  for (int i = 0; i < _n; i++){
    if (i == b){
56 57 58
      Address smol[] = {access.address()};
      acss[i] = Bag<Address>(1, smol);
    } else if (ehManager.existHitAge(_coll[_set][i]) == _A)
59 60 61 62
      acss[i] = Bag<Address>();
  }
}

Valentin Touzeau's avatar
Valentin Touzeau committed
63
void ExistHitPrevUDomain::update(const icache::Access& access, t& a, lrupreanalysis::eh_em::ACSManager& ehManager)
64
{
65
  switch(access.kind()) {
66

67 68 69 70
  case icache::FETCH:
    if(_coll.cache()->set(access.address()) == _set)
      fetch(a, access, ehManager);
      break;
71

72 73 74 75 76 77 78
  case icache::PREFETCH:
    if(_coll.cache()->set(access.address()) == _set) {
      copy(_tmp, a);
      fetch(a, access, ehManager);
      join(a, _tmp, icat3::ACS(), icat3::ACS());
    }
    break;
79

80 81
  case icache::NONE:
    break;
82

83 84 85
  default:
    ASSERT(false);
  }
86 87 88
}

} // namespace lrusecurity