gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
timing_expr.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ARM Limited
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  * Authors: Andrew Bardsley
38  */
39 
40 #include "cpu/timing_expr.hh"
41 
42 #include "base/intmath.hh"
43 
45  ThreadContext *thread_,
46  TimingExprLet *let_) :
47  inst(inst_), thread(thread_), let(let_)
48 {
49  /* Reserve space to hold the results of evaluating the
50  * let expressions */
51  if (let) {
52  unsigned int num_defns = let->defns.size();
53 
54  results.resize(num_defns, 0);
55  resultAvailable.resize(num_defns, false);
56  }
57 }
58 
60 {
61  return context.inst->srcRegIdx(index);
62 }
63 
65 {
66  return context.thread->readIntReg(reg->eval(context));
67 }
68 
70 {
71  TimingExprEvalContext new_context(context.inst,
72  context.thread, this);
73 
74  return expr->eval(new_context);
75 }
76 
78 {
79  /* Lookup the result, evaluating if necessary. @todo, this
80  * should have more error checking */
81  if (!context.resultAvailable[index]) {
82  context.results[index] = context.let->defns[index]->eval(context);
83  context.resultAvailable[index] = true;
84  }
85 
86  return context.results[index];
87 }
88 
90 {
91  uint64_t arg_value = arg->eval(context);
92  uint64_t ret = 0;
93 
94  switch (op) {
95  case Enums::timingExprSizeInBits:
96  if (arg_value == 0)
97  ret = 0;
98  else
99  ret = ceilLog2(arg_value);
100  break;
101  case Enums::timingExprNot:
102  ret = arg_value != 0;
103  break;
104  case Enums::timingExprInvert:
105  ret = ~arg_value;
106  break;
107  case Enums::timingExprSignExtend32To64:
108  ret = static_cast<int64_t>(
109  static_cast<int32_t>(arg_value));
110  break;
111  case Enums::timingExprAbs:
112  if (static_cast<int64_t>(arg_value) < 0)
113  ret = -arg_value;
114  else
115  ret = arg_value;
116  break;
117  default:
118  break;
119  }
120 
121  return ret;
122 }
123 
125 {
126  uint64_t left_value = left->eval(context);
127  uint64_t right_value = right->eval(context);
128  uint64_t ret = 0;
129 
130  switch (op) {
131  case Enums::timingExprAdd:
132  ret = left_value + right_value;
133  break;
134  case Enums::timingExprSub:
135  ret = left_value - right_value;
136  break;
137  case Enums::timingExprUMul:
138  ret = left_value * right_value;
139  break;
140  case Enums::timingExprUDiv:
141  if (right_value != 0) {
142  ret = left_value / right_value;
143  }
144  break;
145  case Enums::timingExprUCeilDiv:
146  if (right_value != 0) {
147  ret = (left_value + (right_value - 1)) / right_value;
148  }
149  break;
150  case Enums::timingExprSMul:
151  ret = static_cast<int64_t>(left_value) *
152  static_cast<int64_t>(right_value);
153  break;
154  case Enums::timingExprSDiv:
155  if (right_value != 0) {
156  ret = static_cast<int64_t>(left_value) /
157  static_cast<int64_t>(right_value);
158  }
159  break;
160  case Enums::timingExprEqual:
161  ret = left_value == right_value;
162  break;
163  case Enums::timingExprNotEqual:
164  ret = left_value != right_value;
165  break;
166  case Enums::timingExprULessThan:
167  ret = left_value < right_value;
168  break;
169  case Enums::timingExprUGreaterThan:
170  ret = left_value > right_value;
171  break;
172  case Enums::timingExprSLessThan:
173  ret = static_cast<int64_t>(left_value) <
174  static_cast<int64_t>(right_value);
175  break;
176  case Enums::timingExprSGreaterThan:
177  ret = static_cast<int64_t>(left_value) >
178  static_cast<int64_t>(right_value);
179  break;
180  case Enums::timingExprAnd:
181  ret = (left_value != 0) && (right_value != 0);
182  break;
183  case Enums::timingExprOr:
184  ret = (left_value != 0) || (right_value != 0);
185  break;
186  default:
187  break;
188  }
189 
190  return ret;
191 }
192 
194 {
195  uint64_t cond_value = cond->eval(context);
196 
197  if (cond_value != 0)
198  return trueExpr->eval(context);
199  else
200  return falseExpr->eval(context);
201 }
202 
204 TimingExprLiteralParams::create()
205 {
206  return new TimingExprLiteral(this);
207 }
208 
210 TimingExprSrcRegParams::create()
211 {
212  return new TimingExprSrcReg(this);
213 }
214 
216 TimingExprReadIntRegParams::create()
217 {
218  return new TimingExprReadIntReg(this);
219 }
220 
222 TimingExprLetParams::create()
223 {
224  return new TimingExprLet(this);
225 }
226 
228 TimingExprRefParams::create()
229 {
230  return new TimingExprRef(this);
231 }
232 
233 TimingExprUn *
234 TimingExprUnParams::create()
235 {
236  return new TimingExprUn(this);
237 }
238 
240 TimingExprBinParams::create()
241 {
242  return new TimingExprBin(this);
243 }
244 
245 TimingExprIf *
246 TimingExprIfParams::create()
247 {
248  return new TimingExprIf(this);
249 }
Enums::TimingExprOp op
Definition: timing_expr.hh:185
TimingExpr * expr
Definition: timing_expr.hh:143
TimingExprEvalContext(const StaticInstPtr &inst_, ThreadContext *thread_, TimingExprLet *let_)
Definition: timing_expr.cc:44
TimingExpr * arg
Definition: timing_expr.hh:171
uint64_t eval(TimingExprEvalContext &context)
Definition: timing_expr.cc:124
Object to gather the visible context for evaluation.
Definition: timing_expr.hh:72
TimingExpr * right
Definition: timing_expr.hh:187
int ceilLog2(const T &n)
Definition: intmath.hh:174
uint64_t eval(TimingExprEvalContext &context)
Definition: timing_expr.cc:59
uint64_t eval(TimingExprEvalContext &context)
Definition: timing_expr.cc:89
TimingExpr * cond
Definition: timing_expr.hh:202
ThreadContext is the external interface to all thread state for anything outside of the CPU...
uint64_t eval(TimingExprEvalContext &context)
Definition: timing_expr.cc:64
std::vector< uint64_t > results
Definition: timing_expr.hh:83
TimingExprLet * let
Context visible as sub expressions.
Definition: timing_expr.hh:82
unsigned int index
Definition: timing_expr.hh:116
virtual uint64_t readIntReg(int reg_idx)=0
std::vector< bool > resultAvailable
Definition: timing_expr.hh:84
TimingExpr * left
Definition: timing_expr.hh:186
TimingExpr * trueExpr
Definition: timing_expr.hh:203
const StaticInstPtr & inst
Special visible context.
Definition: timing_expr.hh:76
uint64_t eval(TimingExprEvalContext &context)
Definition: timing_expr.cc:69
unsigned int index
Definition: timing_expr.hh:157
RegIndex srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
Definition: static_inst.hh:192
uint64_t eval(TimingExprEvalContext &context)
Definition: timing_expr.cc:193
ThreadContext * thread
Definition: timing_expr.hh:77
Enums::TimingExprOp op
Definition: timing_expr.hh:170
uint64_t eval(TimingExprEvalContext &context)
Definition: timing_expr.cc:77
virtual uint64_t eval(TimingExprEvalContext &context)=0
std::vector< TimingExpr * > defns
Definition: timing_expr.hh:142
TimingExpr * falseExpr
Definition: timing_expr.hh:204

Generated on Fri Jun 9 2017 13:03:44 for gem5 by doxygen 1.8.6