ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
Timing.h
Go to the documentation of this file.
1 
53 #ifndef ETISS_TIMING_H
54 #define ETISS_TIMING_H
55 
56 #include "etiss/Instruction.h"
57 #include "etiss/Misc.h"
58 #include "etiss/Plugin.h"
59 
60 #include <functional>
61 #include <regex>
62 
63 namespace etiss
64 {
65 
67 {
68  private:
69  struct Rule
70  {
71  std::function<bool(uint32_t /*mode*/)> mode;
72  std::function<bool(unsigned /*width*/)> width;
73  std::function<bool(etiss::instr::Instruction & /*instr*/)> instr;
74  std::function<void(etiss::instr::Instruction &)> handler;
75  };
76 
77  public:
83  void addRule(std::function<bool(uint32_t /*mode*/)> matchesMode,
84  std::function<bool(unsigned /*width*/)> matchesWidth,
85  std::function<bool(etiss::instr::Instruction & /*instr*/)> matchesInstr,
86  std::function<void(etiss::instr::Instruction & /*match*/)> handleMatch);
90  void addRule(const std::tuple<uint32_t, unsigned, const char *,
91  std::function<void(etiss::instr::Instruction & /*match*/)>> &tuple);
95  void addRule(const std::tuple<std::regex, std::regex, std::regex,
96  std::function<void(etiss::instr::Instruction & /*match*/)>> &tuple);
97  inline void addRule(
98  const std::tuple<std::regex, std::regex, std::regex, void (*)(etiss::instr::Instruction & /*match*/)> &tuple)
99  {
100  addRule(make_tuple(std::get<0>(tuple), std::get<1>(tuple), std::get<2>(tuple),
101  std::function<void(etiss::instr::Instruction &)>(std::get<3>(tuple))));
102  }
103 
104  template <unsigned cycles, bool isNotAdditionalTime = true>
111  {
112  static_assert((cycles > 0) || (!isNotAdditionalTime),
113  "etiss::DataSheetAccurateTiming::handleMatch_cycles may not be used with cycle = 0 and "
114  "isNoteAdditionalTime = false");
115  std::string code;
116  if (cycles == 1)
117  {
118  code = "cpu->cpuTime_ps += cpu->cpuCycleTime_ps; //DataSheetAccurateTiming\n";
119  }
120  else
121  {
122  code = std::string("cpu->cpuTime_ps += ") + etiss::toString(cycles) +
123  " * cpu->cpuCycleTime_ps; //DataSheetAccurateTiming\n";
124  }
125  instr.addCallback(
128  cp.getAffectedRegisters().add("cpuTime_ps", 64);
129  cp.code() = code;
130 
131  return true;
132  },
133  isNotAdditionalTime ? ((uint32_t)etiss::instr::Instruction::BUILTINGROUP::CPUTIMEUPDATE) : 0);
134  }
135 
136  private:
138  inline void ctor_hlpr() {}
139  template <typename A, typename... T>
141  void ctor_hlpr(const A &arg, const T &... rules)
142  {
143  addRule(arg); // store current element
144  ctor_hlpr(rules...);
145  }
146 
147  public:
148  const std::string name_;
149  template <typename... T>
150  DataSheetAccurateTiming(const std::string &name, const T &... rules) : name_(name)
151  {
152  ctor_hlpr(rules...);
153  }
154  virtual ~DataSheetAccurateTiming();
155 
160  virtual void initInstrSet(etiss::instr::ModedInstructionSet &) const;
161 
162  protected:
163  inline std::string _getPluginName() const { return name_; }
164 
165  private:
166  std::list<Rule *> rules_;
167 };
168 
169 } // namespace etiss
170 
171 #endif // ETISS_TIMING_H
#define static_assert(x, y)
Definition: Fault.cpp:60
contains container classes to store instruction definitions + translation functions and build a trans...
general configuration and logging
plugins for extensions to code translation and instruction execution
static __inline__ uint32_t
Definition: arm_cde.h:25
Contains a small code snipped.
Definition: CodePart.h:386
std::string & code()
Definition: CodePart.h:416
RegisterSet & getAffectedRegisters()
Definition: CodePart.h:414
A set of CodeParts.
Definition: CodePart.h:437
CodePart & prepend(CodePart::TYPE type)
Definition: CodePart.h:503
void ctor_hlpr(const A &arg, const T &... rules)
handles the argument list passed to the template constructor
Definition: Timing.h:141
const std::string name_
Definition: Timing.h:148
void addRule(const std::tuple< std::regex, std::regex, std::regex, void(*)(etiss::instr::Instruction &)> &tuple)
Definition: Timing.h:97
std::string _getPluginName() const
Definition: Timing.h:163
static void handleMatch_cycles(etiss::instr::Instruction &instr)
simple template function that adds the given number of cycles to the cpu time if the related rule mat...
Definition: Timing.h:110
virtual void initInstrSet(etiss::instr::ModedInstructionSet &) const
performs lookups for instructions that are in the modded instruction set to add timing code (e....
Definition: Timing.cpp:122
std::list< Rule * > rules_
Definition: Timing.h:166
void ctor_hlpr()
terminates recursion
Definition: Timing.h:138
DataSheetAccurateTiming(const std::string &name, const T &... rules)
Definition: Timing.h:150
void addRule(std::function< bool(uint32_t)> matchesMode, std::function< bool(unsigned)> matchesWidth, std::function< bool(etiss::instr::Instruction &)> matchesInstr, std::function< void(etiss::instr::Instruction &)> handleMatch)
this is the main add rule function.
Definition: Timing.cpp:48
allows to add code to the translation of instructions
Definition: Plugin.h:262
stores a bit vector
Definition: Instruction.h:161
this class contains parameters that persist in between instruction lookpus/translation within a trans...
Definition: Instruction.h:337
holds information and translation callbacks for an instruction.
Definition: Instruction.h:393
bool addCallback(std::function< bool(BitArray &, etiss::CodeSet &, InstructionContext &)> callback, uint32_t builtinGroups, const std::set< uint32_t > &groups=std::set< uint32_t >())
holds etiss::instr::VariableInstructionSet instances for different modes.
Definition: Instruction.h:562
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition: Benchmark.h:53
std::string toString(const T &val)
conversion of type T to std::string.
Definition: Misc.h:174
#define bool
Definition: stdbool.h:15
std::function< void(etiss::instr::Instruction &)> handler
Definition: Timing.h:74
std::function< bool(etiss::instr::Instruction &)> instr
Definition: Timing.h:73
std::function< bool(unsigned)> width
Definition: Timing.h:72
std::function< bool(uint32_t)> mode
Definition: Timing.h:71