ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
Timing.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
6
7#include "etiss/Timing.h"
8#include "etiss/Instruction.h"
9
10namespace etiss
11{
12
13void DataSheetAccurateTiming::addRule(std::function<bool(uint32_t /*mode*/)> matchesMode,
14 std::function<bool(unsigned /*width*/)> matchesWidth,
15 std::function<bool(etiss::instr::Instruction & /*instr*/)> matchesInstr,
16 std::function<void(etiss::instr::Instruction & /*match*/)> handleMatch)
17{
18
19 if (!handleMatch) // return if there is no handler
20 return;
21
22 if (!matchesMode)
23 {
24 etiss::log(etiss::WARNING, "etiss::DataSheetAccurateTiming::addRule called without a matcher function for the "
25 "mode. using default match all rule.");
26 matchesMode = [](uint32_t) { return true; };
27 }
28
29 if (!matchesWidth)
30 {
31 etiss::log(etiss::WARNING, "etiss::DataSheetAccurateTiming::addRule called without a matcher function for the "
32 "width. using default match all rule.");
33 matchesWidth = [](unsigned) { return true; };
34 }
35
36 if (!matchesInstr)
37 {
38 etiss::log(etiss::WARNING, "etiss::DataSheetAccurateTiming::addRule called without a matcher function for a "
39 "instruction. using default match all rule.");
40 matchesInstr = [](etiss::instr::Instruction &) { return true; };
41 }
42
43 Rule *rule = new Rule();
44 rule->mode = matchesMode;
45 rule->width = matchesWidth;
46 rule->instr = matchesInstr;
47 rule->handler = handleMatch;
48 rules_.push_back(rule);
49}
50
52 const std::tuple<uint32_t, unsigned, const char *, std::function<void(etiss::instr::Instruction & /*match*/)>>
53 &tuple)
54{
55 uint32_t refmode = std::get<0>(tuple);
56 unsigned refwidth = std::get<1>(tuple);
57 std::string refname = std::get<2>(tuple);
58
59 addRule([refmode](uint32_t mode) { return refmode == mode; },
60 [refwidth](unsigned width) { return refwidth == width; },
61 [refname](etiss::instr::Instruction &instr) { return refname == instr.name_; }, std::get<3>(tuple));
62}
63
65 const std::tuple<std::regex, std::regex, std::regex, std::function<void(etiss::instr::Instruction & /*match*/)>>
66 &tuple)
67{
68 std::regex refmode = std::get<0>(tuple);
69 std::regex refwidth = std::get<1>(tuple);
70 std::regex refname = std::get<2>(tuple);
71
72 addRule([refmode](uint32_t mode) { return std::regex_match(etiss::toString(mode), refmode); },
73 [refwidth](unsigned width) { return std::regex_match(etiss::toString(width), refwidth); },
74 [refname](etiss::instr::Instruction &instr) { return std::regex_match(instr.name_, refname); },
75 std::get<3>(tuple));
76}
77
79{
80 for (auto iter = rules_.begin(); iter != rules_.end(); ++iter)
81 {
82 delete *iter;
83 }
84 rules_.clear();
85}
86
88{
89 bool verifyCompleteness = true;
90
91 std::set<etiss::instr::Instruction *> found;
92 std::set<etiss::instr::Instruction *> matched;
93 if (verifyCompleteness)
94 { // create a list of all instructions
95 mis.foreach (
97 {
98 vis.foreach ([&found](etiss::instr::InstructionSet &is)
99 { is.foreach ([&found](etiss::instr::Instruction &instr) { found.insert(&instr); }); });
100 });
101 }
102
103 for (auto iter = rules_.begin(); iter != rules_.end(); ++iter)
104 {
105 Rule *rule = *iter;
106 if (rule)
107 {
108 mis.foreach (
109 [&matched, rule](etiss::instr::VariableInstructionSet &vis)
110 {
111 uint32_t mode =
112 vis.parent_.getMode(vis);
113 if (rule->mode(mode))
114 { // match mode
115 vis.foreach (
116 [&matched, rule](etiss::instr::InstructionSet &is)
117 {
118 unsigned width = is.width_;
119 if (rule->width(width))
120 { // match width
121 is.foreach (
122 [&matched, rule](etiss::instr::Instruction &instr)
123 {
124 if (rule->instr(instr))
125 { // match instruction
126 matched.insert(&instr); // store instruction as matched
127 rule->handler(instr); // handle instruction
128 }
129 });
130 }
131 });
132 }
133 });
134 }
135 }
136
137 if (verifyCompleteness)
138 {
139 for (auto iter = matched.begin(); iter != matched.end(); ++iter)
140 {
141 found.erase(*iter);
142 }
143 for (auto iter = found.begin(); iter != found.end(); ++iter)
144 {
145 etiss::log(etiss::WARNING, std::string("DataSheetAccurateTiming instance [") +
146 ((DataSheetAccurateTiming *)this)->_getPluginName() +
147 "] ignored instruction " + (*iter)->toString());
148 }
149 }
150}
151
152} // namespace etiss
contains container classes to store instruction definitions + translation functions and build a trans...
static __inline__ uint32_t
Definition arm_cde.h:25
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:87
std::list< Rule * > rules_
Definition Timing.h:129
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:13
holds etiss::instr::Instruction instances and handles automatic instruction tree creation.
void foreach(std::function< void(Instruction &)> func)
holds information and translation callbacks for an instruction.
holds etiss::instr::VariableInstructionSet instances for different modes.
uint32_t getMode(VariableInstructionSet *vis)
void foreach(std::function< void(VariableInstructionSet &)> call)
holds etiss::instr::InstructionSet instances with different bit widths.
void foreach(std::function< void(InstructionSet &)> func)
forwards: include/jit/*
Definition Benchmark.h:17
std::string toString(const T &val)
conversion of type T to std::string.
Definition Misc.h:133
@ WARNING
Definition Misc.h:86
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:94
std::function< void(etiss::instr::Instruction &)> handler
Definition Timing.h:36
std::function< bool(etiss::instr::Instruction &)> instr
Definition Timing.h:35
std::function< bool(unsigned)> width
Definition Timing.h:34
std::function< bool(uint32_t)> mode
Definition Timing.h:33