dynamic_instruction.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef __DYNAMIC_INSTRUCTION_H
  2. #define __DYNAMIC_INSTRUCTION_H
  3. #include "operand.h"
  4. #include "subsecond_time.h"
  5. #include "hit_where.h"
  6. #include "allocator.h"
  7. class Core;
  8. class Instruction;
  9. class DynamicInstruction
  10. {
  11. private:
  12. // Private constructor: alloc() should be used
  13. DynamicInstruction(Instruction *ins, IntPtr _eip)
  14. {
  15. instruction = ins;
  16. eip = _eip;
  17. branch_info.is_branch = false;
  18. num_memory = 0;
  19. }
  20. public:
  21. struct BranchInfo
  22. {
  23. bool is_branch;
  24. bool taken;
  25. IntPtr target;
  26. };
  27. struct MemoryInfo {
  28. bool executed; // For CMOV: true if executed
  29. Operand::Direction dir;
  30. IntPtr addr;
  31. UInt32 size;
  32. UInt32 num_misses;
  33. SubsecondTime latency;
  34. HitWhere::where_t hit_where;
  35. };
  36. static const UInt8 MAX_MEMORY = 2;
  37. Instruction* instruction;
  38. IntPtr eip; // Can be physical address, so different from instruction->getAddress() which is always virtual
  39. BranchInfo branch_info;
  40. UInt8 num_memory;
  41. MemoryInfo memory_info[MAX_MEMORY];
  42. static Allocator* createAllocator();
  43. ~DynamicInstruction();
  44. static DynamicInstruction* alloc(Allocator *alloc, Instruction *ins, IntPtr eip)
  45. {
  46. void *ptr = alloc->alloc(sizeof(DynamicInstruction));
  47. DynamicInstruction *i = new(ptr) DynamicInstruction(ins, eip);
  48. return i;
  49. }
  50. static void operator delete(void* ptr) { Allocator::dealloc(ptr); }
  51. SubsecondTime getCost(Core *core);
  52. bool isBranch() const { return branch_info.is_branch; }
  53. bool isMemory() const { return num_memory > 0; }
  54. void addMemory(bool e, SubsecondTime l, IntPtr a, UInt32 s, Operand::Direction dir, UInt32 num_misses, HitWhere::where_t hit_where)
  55. {
  56. LOG_ASSERT_ERROR(num_memory < MAX_MEMORY, "Got more than MAX_MEMORY(%d) memory operands", MAX_MEMORY);
  57. memory_info[num_memory].dir = dir;
  58. memory_info[num_memory].executed = e;
  59. memory_info[num_memory].latency = l;
  60. memory_info[num_memory].addr = a;
  61. memory_info[num_memory].size = s;
  62. memory_info[num_memory].num_misses = num_misses;
  63. memory_info[num_memory].hit_where = hit_where;
  64. num_memory++;
  65. }
  66. void addBranch(bool taken, IntPtr target)
  67. {
  68. branch_info.is_branch = true;
  69. branch_info.taken = taken;
  70. branch_info.target = target;
  71. }
  72. SubsecondTime getBranchCost(Core *core, bool *p_is_mispredict = NULL);
  73. void accessMemory(Core *core);
  74. };
  75. #endif // __DYNAMIC_INSTRUCTION_H