ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Timing.cpp
Go to the documentation of this file.
1/*
2
3 @copyright
4
5 <pre>
6
7 Copyright 2018 Infineon Technologies AG
8
9 This file is part of ETISS tool, see <https://github.com/tum-ei-eda/etiss>.
10
11 The initial version of this software has been created with the funding support by the German Federal
12 Ministry of Education and Research (BMBF) in the project EffektiV under grant 01IS13022.
13
14 Redistribution and use in source and binary forms, with or without modification, are permitted
15 provided that the following conditions are met:
16
17 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
18 the following disclaimer.
19
20 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
21 and the following disclaimer in the documentation and/or other materials provided with the distribution.
22
23 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
24 or promote products derived from this software without specific prior written permission.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
27 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
28 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
29 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 POSSIBILITY OF SUCH DAMAGE.
34
35 </pre>
36
37 @author Chair of Electronic Design Automation, TUM
38
39 @version 0.1
40
41*/
42
43#include "etiss/Timing.h"
44
45namespace etiss
46{
47
48void DataSheetAccurateTiming::addRule(std::function<bool(uint32_t /*mode*/)> matchesMode,
49 std::function<bool(unsigned /*width*/)> matchesWidth,
50 std::function<bool(etiss::instr::Instruction & /*instr*/)> matchesInstr,
51 std::function<void(etiss::instr::Instruction & /*match*/)> handleMatch)
52{
53
54 if (!handleMatch) // return if there is no handler
55 return;
56
57 if (!matchesMode)
58 {
59 etiss::log(etiss::WARNING, "etiss::DataSheetAccurateTiming::addRule called without a matcher function for the "
60 "mode. using default match all rule.");
61 matchesMode = [](uint32_t) { return true; };
62 }
63
64 if (!matchesWidth)
65 {
66 etiss::log(etiss::WARNING, "etiss::DataSheetAccurateTiming::addRule called without a matcher function for the "
67 "width. using default match all rule.");
68 matchesWidth = [](unsigned) { return true; };
69 }
70
71 if (!matchesInstr)
72 {
73 etiss::log(etiss::WARNING, "etiss::DataSheetAccurateTiming::addRule called without a matcher function for a "
74 "instruction. using default match all rule.");
75 matchesInstr = [](etiss::instr::Instruction &) { return true; };
76 }
77
78 Rule *rule = new Rule();
79 rule->mode = matchesMode;
80 rule->width = matchesWidth;
81 rule->instr = matchesInstr;
82 rule->handler = handleMatch;
83 rules_.push_back(rule);
84}
85
87 const std::tuple<uint32_t, unsigned, const char *, std::function<void(etiss::instr::Instruction & /*match*/)>>
88 &tuple)
89{
90 uint32_t refmode = std::get<0>(tuple);
91 unsigned refwidth = std::get<1>(tuple);
92 std::string refname = std::get<2>(tuple);
93
94 addRule([refmode](uint32_t mode) { return refmode == mode; },
95 [refwidth](unsigned width) { return refwidth == width; },
96 [refname](etiss::instr::Instruction &instr) { return refname == instr.name_; }, std::get<3>(tuple));
97}
98
100 const std::tuple<std::regex, std::regex, std::regex, std::function<void(etiss::instr::Instruction & /*match*/)>>
101 &tuple)
102{
103 std::regex refmode = std::get<0>(tuple);
104 std::regex refwidth = std::get<1>(tuple);
105 std::regex refname = std::get<2>(tuple);
106
107 addRule([refmode](uint32_t mode) { return std::regex_match(etiss::toString(mode), refmode); },
108 [refwidth](unsigned width) { return std::regex_match(etiss::toString(width), refwidth); },
109 [refname](etiss::instr::Instruction &instr) { return std::regex_match(instr.name_, refname); },
110 std::get<3>(tuple));
111}
112
114{
115 for (auto iter = rules_.begin(); iter != rules_.end(); ++iter)
116 {
117 delete *iter;
118 }
119 rules_.clear();
120}
121
123{
124 bool verifyCompleteness = true;
125
126 std::set<etiss::instr::Instruction *> found;
127 std::set<etiss::instr::Instruction *> matched;
128 if (verifyCompleteness)
129 { // create a list of all instructions
131 vis.foreach ([&found](etiss::instr::InstructionSet &is) {
132 is.foreach ([&found](etiss::instr::Instruction &instr) { found.insert(&instr); });
133 });
134 });
135 }
136
137 for (auto iter = rules_.begin(); iter != rules_.end(); ++iter)
138 {
139 Rule *rule = *iter;
140 if (rule)
141 {
142 mis.foreach ([&matched, rule](etiss::instr::VariableInstructionSet &vis) {
143 uint32_t mode = vis.parent_.getMode(vis);
144 if (rule->mode(mode))
145 { // match mode
146 vis.foreach ([&matched, rule](etiss::instr::InstructionSet &is) {
147 unsigned width = is.width_;
148 if (rule->width(width))
149 { // match width
150 is.foreach ([&matched, rule](etiss::instr::Instruction &instr) {
151 if (rule->instr(instr))
152 { // match instruction
153 matched.insert(&instr); // store instruction as matched
154 rule->handler(instr); // handle instruction
155 }
156 });
157 }
158 });
159 }
160 });
161 }
162 }
163
164 if (verifyCompleteness)
165 {
166 for (auto iter = matched.begin(); iter != matched.end(); ++iter)
167 {
168 found.erase(*iter);
169 }
170 for (auto iter = found.begin(); iter != found.end(); ++iter)
171 {
172 etiss::log(etiss::WARNING, std::string("DataSheetAccurateTiming instance [") +
173 ((DataSheetAccurateTiming *)this)->_getPluginName() +
174 "] ignored instruction " + (*iter)->toString());
175 }
176 }
177}
178
179} // namespace etiss
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:122
std::list< Rule * > rules_
Definition Timing.h:166
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
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)
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
@ WARNING
Definition Misc.h:128
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:125
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