8#include "sparta/statistics/ExpressionNode.hpp"
12 class StatisticInstance;
14 namespace statistics {
15 namespace expression {
30 std::vector<std::unique_ptr<ExpressionNode>>
operands_;
149 bool supports_compression =
true;
151 supports_compression &= op->supportsCompression();
153 return supports_compression;
160 return operands_.at(0)->supportsCompression();
169 virtual void start()
override {
174 virtual void end()
override {
180 virtual void dump(std::ostream& o,
181 bool show_range=
true,
182 bool resolve_subexprs=
true)
const override {
186 operands_.at(0)->dump(o, show_range, resolve_subexprs);
187 o <<
"" << (char)(
type_ & 0xff);
188 operands_.at(1)->dump(o, show_range, resolve_subexprs);
191 if((uint32_t)
type_ > 255){
192 o <<
"op" <<
type_ <<
"(" ;
194 o <<
"op" << (char)(
type_ & 0xff) <<
"(" ;
202 op->dump(o, show_range, resolve_subexprs);
209 virtual void getClocks(std::vector<const Clock*>& clocks)
const override {
211 op->getClocks(clocks);
217 virtual uint32_t getStats_(std::vector<const StatisticInstance*>& results)
const override {
220 added += op->getStats(results);
254 virtual void start()
override {
257 virtual void end()
override {
260 virtual void dump(std::ostream& o,
261 bool show_range=
true,
262 bool resolve_subexprs=
true)
const override {
264 (void) resolve_subexprs;
268 virtual void getClocks(std::vector<const Clock*>& clocks)
const override {
275 virtual uint32_t getStats_(std::vector<const StatisticInstance*>& results)
const override {
285template <
typename RetT=
double,
typename ArgT=
double,
typename fxn_t = RetT (* const)(ArgT)>
332 "operand of unary function \"" << name <<
"\" cannot be nullptr");
356 virtual void start()
override {
360 virtual void end()
override {
364 virtual void dump(std::ostream& o,
365 bool show_range=
true,
366 bool resolve_subexprs=
true)
const override {
368 operand_->dump(o, show_range, resolve_subexprs);
372 virtual void getClocks(std::vector<const Clock*>& clocks)
const override {
378 virtual uint32_t getStats_(std::vector<const StatisticInstance*>& results)
const override {
390template <
typename RetT=
double,
typename ArgT=
double>
396 using fxn_t =
typename std::conditional<
397 std::is_class<RetT>::value,
399 RetT(*
const)(ArgT, ArgT)>::type;
455 "operand 1 of binary function \"" << name <<
"\" cannot be nullptr");
457 "operand 2 of binary function \"" << name <<
"\" cannot be nullptr");
472 return (
double)
fxn_(x, y);
483 virtual void start()
override {
488 virtual void end()
override {
493 virtual void dump(std::ostream& o,
494 bool show_range=
true,
495 bool resolve_subexprs=
true)
const override {
497 operand_1_->dump(o, show_range, resolve_subexprs);
499 operand_2_->dump(o, show_range, resolve_subexprs);
503 virtual void getClocks(std::vector<const Clock*>& clocks)
const override {
510 virtual uint32_t getStats_(std::vector<const StatisticInstance*>& results)
const override {
522template <
typename RetT=
double,
typename ArgT=
double>
528 typedef RetT(*
const fxn_t)(ArgT, ArgT, ArgT);
593 "operand 1 of ternary function \"" << name <<
"\" cannot be nullptr");
595 "operand 2 of ternary function \"" << name <<
"\" cannot be nullptr");
597 "operand 3 of ternary function \"" << name <<
"\" cannot be nullptr");
621 virtual void start()
override {
627 virtual void end()
override {
633 virtual void dump(std::ostream& o,
634 bool show_range=
true,
635 bool resolve_subexprs=
true)
const override {
637 operand_1_->dump(o, show_range, resolve_subexprs);
639 operand_2_->dump(o, show_range, resolve_subexprs);
641 operand_3_->dump(o, show_range, resolve_subexprs);
645 virtual void getClocks(std::vector<const Clock*>& clocks)
const override {
653 virtual uint32_t getStats_(std::vector<const StatisticInstance*>& results)
const override {
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Abstract interface class for an item in an expression. Subclasses can contain other ExpressionNodes.
operation_t
Types of operations supported.
@ OP_FORWARD
Forwarding: (x)
@ OP_PROMOTE
Promotion: +x.
Macros for handling exponential backoff.
Represents a Binary function node.
std::unique_ptr< ExpressionNode > operand_2_
Operand 2 of the unary function fxn_.
virtual BinaryFunction * clone_() const override
Deep copy of the content of this item.
typename std::conditional< std::is_class< RetT >::value, RetT, RetT(*const)(ArgT, ArgT)>::type fxn_t
Function evaluation handler type.
std::unique_ptr< ExpressionNode > operand_1_
Operand 1 of the unary function fxn_.
const fxn_t fxn_
Binary function to invoke.
virtual bool supportsCompression() const override
virtual void dump(std::ostream &o, bool show_range=true, bool resolve_subexprs=true) const override
Dump the content of this expression item.
virtual double evaluate_() const override
Compute value of this item in simulation.
BinaryFunction(const std::string &name, fxn_t fxn, ExpressionNode *op1, ExpressionNode *op2)
BinaryFunction & operator=(const BinaryFunction &)=delete
Non-assignable.
BinaryFunction()=delete
No default construction.
const std::string name_
Name of this binary function.
virtual void getClocks(std::vector< const Clock * > &clocks) const override
Populates a vector with the clocks found in this subexpression node.
virtual bool supportsCompression() const override
Constants are always good candidates for compression.
virtual void dump(std::ostream &o, bool show_range=true, bool resolve_subexprs=true) const override
Dump the content of this expression item.
virtual double evaluate_() const override
Compute value of this item in simulation.
virtual void getClocks(std::vector< const Clock * > &clocks) const override
Populates a vector with the clocks found in this subexpression node.
virtual Constant * clone_() const override
Deep copy of the content of this item.
Operation Node (e.g. +,-,*,/)
Operation(const Operation &rhp)
Copy constructor. Deep copies the operands of the operation.
std::vector< std::unique_ptr< ExpressionNode > > operands_
All operands (subexpressions) in this node.
virtual bool supportsCompression() const override
virtual double evaluate_() const override
Compute value of this item in simulation.
virtual Operation * clone_() const override
Deep copy of the content of this item.
void addOperand(ExpressionNode *op)
Manually add an operand.
virtual void dump(std::ostream &o, bool show_range=true, bool resolve_subexprs=true) const override
Dump the content of this expression item.
operation_t type_
Type of operation to perform.
Operation()
Default constructor with null operations and no type.
Operation(operation_t type, ExpressionNode *op1, ExpressionNode *op2=nullptr, ExpressionNode *op3=nullptr)
Contruct with operation type and operands.
virtual void getClocks(std::vector< const Clock * > &clocks) const override
Populates a vector with the clocks found in this subexpression node.
Represents a Ternary function node.
TernaryFunction(const std::string &name, fxn_t fxn, ExpressionNode *op1, ExpressionNode *op2, ExpressionNode *op3)
TernaryFunction & operator=(const TernaryFunction &)=delete
Non-assignable.
RetT(*const fxn_t)(ArgT, ArgT, ArgT)
Function evaluation handler type.
std::unique_ptr< ExpressionNode > operand_3_
Operand 2 of the unary function fxn_.
virtual TernaryFunction * clone_() const override
Deep copy of the content of this item.
TernaryFunction()=delete
No default construction.
std::unique_ptr< ExpressionNode > operand_2_
Operand 2 of the unary function fxn_.
virtual void getClocks(std::vector< const Clock * > &clocks) const override
Populates a vector with the clocks found in this subexpression node.
std::unique_ptr< ExpressionNode > operand_1_
Operand 1 of the unary function fxn_.
const fxn_t fxn_
Ternary function to invoke.
virtual void dump(std::ostream &o, bool show_range=true, bool resolve_subexprs=true) const override
Dump the content of this expression item.
const std::string name_
Name of this ternary function.
virtual bool supportsCompression() const override
virtual double evaluate_() const override
Compute value of this item in simulation.
Represents a Unary function node.
std::unique_ptr< ExpressionNode > operand_
Operand of the unary function fxn_.
UnaryFunction & operator=(const UnaryFunction &)=delete
Non-assignable.
virtual void dump(std::ostream &o, bool show_range=true, bool resolve_subexprs=true) const override
Dump the content of this expression item.
virtual void getClocks(std::vector< const Clock * > &clocks) const override
Populates a vector with the clocks found in this subexpression node.
const std::string name_
Name of this unary function.
virtual UnaryFunction * clone_() const override
Deep copy of the content of this item.
virtual double evaluate_() const override
Compute value of this item in simulation.
virtual bool supportsCompression() const override
UnaryFunction()=delete
No default construction.
const fxn_t fxn_
Unary function to invoke.
UnaryFunction(const std::string &name, fxn_t fxn, ExpressionNode *op)