dynamic_instruction.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "dynamic_instruction.h"
  2. #include "instruction.h"
  3. #include "allocator.h"
  4. #include "core.h"
  5. #include "branch_predictor.h"
  6. #include "performance_model.h"
  7. Allocator* DynamicInstruction::createAllocator()
  8. {
  9. return new TypedAllocator<DynamicInstruction, 1024>();
  10. }
  11. DynamicInstruction::~DynamicInstruction()
  12. {
  13. if (instruction->isPseudo())
  14. delete instruction;
  15. }
  16. SubsecondTime DynamicInstruction::getCost(Core *core)
  17. {
  18. if (isBranch())
  19. return getBranchCost(core);
  20. else
  21. return instruction->getCost(core);
  22. }
  23. SubsecondTime DynamicInstruction::getBranchCost(Core *core, bool *p_is_mispredict)
  24. {
  25. PerformanceModel *perf = core->getPerformanceModel();
  26. BranchPredictor *bp = perf->getBranchPredictor();
  27. const ComponentPeriod *period = core->getDvfsDomain();
  28. bool is_mispredict = core->accessBranchPredictor(eip, branch_info.taken, branch_info.target);
  29. UInt64 cost = is_mispredict ? bp->getMispredictPenalty() : 1;
  30. if (p_is_mispredict)
  31. *p_is_mispredict = is_mispredict;
  32. return static_cast<SubsecondTime>(*period) * cost;
  33. }
  34. void DynamicInstruction::accessMemory(Core *core)
  35. {
  36. for(UInt8 idx = 0; idx < num_memory; ++idx)
  37. {
  38. if (memory_info[idx].executed && memory_info[idx].hit_where == HitWhere::UNKNOWN)
  39. {
  40. MemoryResult res = core->accessMemory(
  41. /*instruction.isAtomic()
  42. ? (info->type == DynamicInstructionInfo::MEMORY_READ ? Core::LOCK : Core::UNLOCK)
  43. :*/ Core::NONE, // Just as in pin/lite/memory_modeling.cc, make the second part of an atomic update implicit
  44. memory_info[idx].dir == Operand::READ ? (instruction->isAtomic() ? Core::READ_EX : Core::READ) : Core::WRITE,
  45. memory_info[idx].addr,
  46. NULL,
  47. memory_info[idx].size,
  48. Core::MEM_MODELED_RETURN,
  49. instruction->getAddress()
  50. );
  51. memory_info[idx].latency = res.latency;
  52. memory_info[idx].hit_where = res.hit_where;
  53. }
  54. else
  55. {
  56. memory_info[idx].latency = 1 * core->getDvfsDomain()->getPeriod(); // 1 cycle latency
  57. memory_info[idx].hit_where = HitWhere::PREDICATE_FALSE;
  58. }
  59. }
  60. }