110259SAndrew.Bardsley@arm.com/* 210259SAndrew.Bardsley@arm.com * Copyright (c) 2013-2014 ARM Limited 310259SAndrew.Bardsley@arm.com * All rights reserved. 410259SAndrew.Bardsley@arm.com * 510259SAndrew.Bardsley@arm.com * The license below extends only to copyright in the software and shall 610259SAndrew.Bardsley@arm.com * not be construed as granting a license to any other intellectual 710259SAndrew.Bardsley@arm.com * property including but not limited to intellectual property relating 810259SAndrew.Bardsley@arm.com * to a hardware implementation of the functionality of the software 910259SAndrew.Bardsley@arm.com * licensed hereunder. You may use the software subject to the license 1010259SAndrew.Bardsley@arm.com * terms below provided that you ensure that this notice is replicated 1110259SAndrew.Bardsley@arm.com * unmodified and in its entirety in all distributions of the software, 1210259SAndrew.Bardsley@arm.com * modified or unmodified, in source code or in binary form. 1310259SAndrew.Bardsley@arm.com * 1410259SAndrew.Bardsley@arm.com * Redistribution and use in source and binary forms, with or without 1510259SAndrew.Bardsley@arm.com * modification, are permitted provided that the following conditions are 1610259SAndrew.Bardsley@arm.com * met: redistributions of source code must retain the above copyright 1710259SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer; 1810259SAndrew.Bardsley@arm.com * redistributions in binary form must reproduce the above copyright 1910259SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer in the 2010259SAndrew.Bardsley@arm.com * documentation and/or other materials provided with the distribution; 2110259SAndrew.Bardsley@arm.com * neither the name of the copyright holders nor the names of its 2210259SAndrew.Bardsley@arm.com * contributors may be used to endorse or promote products derived from 2310259SAndrew.Bardsley@arm.com * this software without specific prior written permission. 2410259SAndrew.Bardsley@arm.com * 2510259SAndrew.Bardsley@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2610259SAndrew.Bardsley@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2710259SAndrew.Bardsley@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2810259SAndrew.Bardsley@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2910259SAndrew.Bardsley@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3010259SAndrew.Bardsley@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3110259SAndrew.Bardsley@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3210259SAndrew.Bardsley@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3310259SAndrew.Bardsley@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3410259SAndrew.Bardsley@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3510259SAndrew.Bardsley@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3610259SAndrew.Bardsley@arm.com * 3710259SAndrew.Bardsley@arm.com * Authors: Andrew Bardsley 3810259SAndrew.Bardsley@arm.com */ 3910259SAndrew.Bardsley@arm.com 4010259SAndrew.Bardsley@arm.com/* 4110259SAndrew.Bardsley@arm.com * These classes define an expression language over uint64_t with only 4210259SAndrew.Bardsley@arm.com * a few operators. This can be used to form expressions for the extra 4310259SAndrew.Bardsley@arm.com * delay required in variable execution time instructions. 4410259SAndrew.Bardsley@arm.com * 4510259SAndrew.Bardsley@arm.com * Expressions, in evaluation, will have access to the ThreadContext and 4610259SAndrew.Bardsley@arm.com * a StaticInst. 4710259SAndrew.Bardsley@arm.com */ 4810259SAndrew.Bardsley@arm.com 4910259SAndrew.Bardsley@arm.com#ifndef __CPU_TIMING_EXPR_HH__ 5010259SAndrew.Bardsley@arm.com#define __CPU_TIMING_EXPR_HH__ 5110259SAndrew.Bardsley@arm.com 5210259SAndrew.Bardsley@arm.com#include "cpu/static_inst.hh" 5310259SAndrew.Bardsley@arm.com#include "cpu/thread_context.hh" 5410259SAndrew.Bardsley@arm.com#include "enums/TimingExprOp.hh" 5510259SAndrew.Bardsley@arm.com#include "params/TimingExpr.hh" 5610259SAndrew.Bardsley@arm.com#include "params/TimingExprBin.hh" 5710259SAndrew.Bardsley@arm.com#include "params/TimingExprIf.hh" 5810259SAndrew.Bardsley@arm.com#include "params/TimingExprLet.hh" 5910259SAndrew.Bardsley@arm.com#include "params/TimingExprLiteral.hh" 6010259SAndrew.Bardsley@arm.com#include "params/TimingExprReadIntReg.hh" 6110259SAndrew.Bardsley@arm.com#include "params/TimingExprRef.hh" 6210259SAndrew.Bardsley@arm.com#include "params/TimingExprSrcReg.hh" 6310259SAndrew.Bardsley@arm.com#include "params/TimingExprUn.hh" 6410259SAndrew.Bardsley@arm.com#include "sim/sim_object.hh" 6510259SAndrew.Bardsley@arm.com 6610259SAndrew.Bardsley@arm.com/** These classes are just the C++ counterparts for those in Expr.py and 6710259SAndrew.Bardsley@arm.com * are, therefore, documented there */ 6810259SAndrew.Bardsley@arm.com 6910259SAndrew.Bardsley@arm.comclass TimingExprLet; 7010259SAndrew.Bardsley@arm.com 7110259SAndrew.Bardsley@arm.com/** Object to gather the visible context for evaluation */ 7210259SAndrew.Bardsley@arm.comclass TimingExprEvalContext 7310259SAndrew.Bardsley@arm.com{ 7410259SAndrew.Bardsley@arm.com public: 7510259SAndrew.Bardsley@arm.com /** Special visible context */ 7610417Sandreas.hansson@arm.com const StaticInstPtr &inst; 7710259SAndrew.Bardsley@arm.com ThreadContext *thread; 7810259SAndrew.Bardsley@arm.com 7910259SAndrew.Bardsley@arm.com /** Context visible as sub expressions. results will hold the results 8010259SAndrew.Bardsley@arm.com * of (lazily) evaluating let's expressions. resultAvailable elements 8110259SAndrew.Bardsley@arm.com * are true when a result has actually been evaluated */ 8210259SAndrew.Bardsley@arm.com TimingExprLet *let; 8310259SAndrew.Bardsley@arm.com std::vector<uint64_t> results; 8410259SAndrew.Bardsley@arm.com std::vector<bool > resultAvailable; 8510259SAndrew.Bardsley@arm.com 8610417Sandreas.hansson@arm.com TimingExprEvalContext(const StaticInstPtr &inst_, 8710259SAndrew.Bardsley@arm.com ThreadContext *thread_, TimingExprLet *let_); 8810259SAndrew.Bardsley@arm.com}; 8910259SAndrew.Bardsley@arm.com 9010259SAndrew.Bardsley@arm.comclass TimingExpr : public SimObject 9110259SAndrew.Bardsley@arm.com{ 9210259SAndrew.Bardsley@arm.com public: 9310259SAndrew.Bardsley@arm.com TimingExpr(const TimingExprParams *params) : 9410259SAndrew.Bardsley@arm.com SimObject(params) 9510259SAndrew.Bardsley@arm.com { } 9610259SAndrew.Bardsley@arm.com 9710259SAndrew.Bardsley@arm.com virtual uint64_t eval(TimingExprEvalContext &context) = 0; 9810259SAndrew.Bardsley@arm.com}; 9910259SAndrew.Bardsley@arm.com 10010259SAndrew.Bardsley@arm.comclass TimingExprLiteral : public TimingExpr 10110259SAndrew.Bardsley@arm.com{ 10210259SAndrew.Bardsley@arm.com public: 10310259SAndrew.Bardsley@arm.com uint64_t value; 10410259SAndrew.Bardsley@arm.com 10510259SAndrew.Bardsley@arm.com TimingExprLiteral(const TimingExprLiteralParams *params) : 10610259SAndrew.Bardsley@arm.com TimingExpr(params), 10710259SAndrew.Bardsley@arm.com value(params->value) 10810259SAndrew.Bardsley@arm.com { } 10910259SAndrew.Bardsley@arm.com 11010259SAndrew.Bardsley@arm.com uint64_t eval(TimingExprEvalContext &context) { return value; } 11110259SAndrew.Bardsley@arm.com}; 11210259SAndrew.Bardsley@arm.com 11310259SAndrew.Bardsley@arm.comclass TimingExprSrcReg : public TimingExpr 11410259SAndrew.Bardsley@arm.com{ 11510259SAndrew.Bardsley@arm.com public: 11610259SAndrew.Bardsley@arm.com unsigned int index; 11710259SAndrew.Bardsley@arm.com 11810259SAndrew.Bardsley@arm.com TimingExprSrcReg(const TimingExprSrcRegParams *params) : 11910259SAndrew.Bardsley@arm.com TimingExpr(params), 12010259SAndrew.Bardsley@arm.com index(params->index) 12110259SAndrew.Bardsley@arm.com { } 12210259SAndrew.Bardsley@arm.com 12310259SAndrew.Bardsley@arm.com uint64_t eval(TimingExprEvalContext &context); 12410259SAndrew.Bardsley@arm.com}; 12510259SAndrew.Bardsley@arm.com 12610259SAndrew.Bardsley@arm.comclass TimingExprReadIntReg : public TimingExpr 12710259SAndrew.Bardsley@arm.com{ 12810259SAndrew.Bardsley@arm.com public: 12910259SAndrew.Bardsley@arm.com TimingExpr *reg; 13010259SAndrew.Bardsley@arm.com 13110259SAndrew.Bardsley@arm.com TimingExprReadIntReg(const TimingExprReadIntRegParams *params) : 13210259SAndrew.Bardsley@arm.com TimingExpr(params), 13310259SAndrew.Bardsley@arm.com reg(params->reg) 13410259SAndrew.Bardsley@arm.com { } 13510259SAndrew.Bardsley@arm.com 13610259SAndrew.Bardsley@arm.com uint64_t eval(TimingExprEvalContext &context); 13710259SAndrew.Bardsley@arm.com}; 13810259SAndrew.Bardsley@arm.com 13910259SAndrew.Bardsley@arm.comclass TimingExprLet : public TimingExpr 14010259SAndrew.Bardsley@arm.com{ 14110259SAndrew.Bardsley@arm.com public: 14210259SAndrew.Bardsley@arm.com std::vector<TimingExpr *> defns; 14310259SAndrew.Bardsley@arm.com TimingExpr *expr; 14410259SAndrew.Bardsley@arm.com 14510259SAndrew.Bardsley@arm.com TimingExprLet(const TimingExprLetParams *params) : 14610259SAndrew.Bardsley@arm.com TimingExpr(params), 14710259SAndrew.Bardsley@arm.com defns(params->defns), 14810259SAndrew.Bardsley@arm.com expr(params->expr) 14910259SAndrew.Bardsley@arm.com { } 15010259SAndrew.Bardsley@arm.com 15110259SAndrew.Bardsley@arm.com uint64_t eval(TimingExprEvalContext &context); 15210259SAndrew.Bardsley@arm.com}; 15310259SAndrew.Bardsley@arm.com 15410259SAndrew.Bardsley@arm.comclass TimingExprRef : public TimingExpr 15510259SAndrew.Bardsley@arm.com{ 15610259SAndrew.Bardsley@arm.com public: 15710259SAndrew.Bardsley@arm.com unsigned int index; 15810259SAndrew.Bardsley@arm.com 15910259SAndrew.Bardsley@arm.com TimingExprRef(const TimingExprRefParams *params) : 16010259SAndrew.Bardsley@arm.com TimingExpr(params), 16110259SAndrew.Bardsley@arm.com index(params->index) 16210259SAndrew.Bardsley@arm.com { } 16310259SAndrew.Bardsley@arm.com 16410259SAndrew.Bardsley@arm.com uint64_t eval(TimingExprEvalContext &context); 16510259SAndrew.Bardsley@arm.com}; 16610259SAndrew.Bardsley@arm.com 16710259SAndrew.Bardsley@arm.comclass TimingExprUn : public TimingExpr 16810259SAndrew.Bardsley@arm.com{ 16910259SAndrew.Bardsley@arm.com public: 17010259SAndrew.Bardsley@arm.com Enums::TimingExprOp op; 17110259SAndrew.Bardsley@arm.com TimingExpr *arg; 17210259SAndrew.Bardsley@arm.com 17310259SAndrew.Bardsley@arm.com TimingExprUn(const TimingExprUnParams *params) : 17410259SAndrew.Bardsley@arm.com TimingExpr(params), 17510259SAndrew.Bardsley@arm.com op(params->op), 17610259SAndrew.Bardsley@arm.com arg(params->arg) 17710259SAndrew.Bardsley@arm.com { } 17810259SAndrew.Bardsley@arm.com 17910259SAndrew.Bardsley@arm.com uint64_t eval(TimingExprEvalContext &context); 18010259SAndrew.Bardsley@arm.com}; 18110259SAndrew.Bardsley@arm.com 18210259SAndrew.Bardsley@arm.comclass TimingExprBin : public TimingExpr 18310259SAndrew.Bardsley@arm.com{ 18410259SAndrew.Bardsley@arm.com public: 18510259SAndrew.Bardsley@arm.com Enums::TimingExprOp op; 18610259SAndrew.Bardsley@arm.com TimingExpr *left; 18710259SAndrew.Bardsley@arm.com TimingExpr *right; 18810259SAndrew.Bardsley@arm.com 18910259SAndrew.Bardsley@arm.com TimingExprBin(const TimingExprBinParams *params) : 19010259SAndrew.Bardsley@arm.com TimingExpr(params), 19110259SAndrew.Bardsley@arm.com op(params->op), 19210259SAndrew.Bardsley@arm.com left(params->left), 19310259SAndrew.Bardsley@arm.com right(params->right) 19410259SAndrew.Bardsley@arm.com { } 19510259SAndrew.Bardsley@arm.com 19610259SAndrew.Bardsley@arm.com uint64_t eval(TimingExprEvalContext &context); 19710259SAndrew.Bardsley@arm.com}; 19810259SAndrew.Bardsley@arm.com 19910259SAndrew.Bardsley@arm.comclass TimingExprIf : public TimingExpr 20010259SAndrew.Bardsley@arm.com{ 20110259SAndrew.Bardsley@arm.com public: 20210259SAndrew.Bardsley@arm.com TimingExpr *cond; 20310259SAndrew.Bardsley@arm.com TimingExpr *trueExpr; 20410259SAndrew.Bardsley@arm.com TimingExpr *falseExpr; 20510259SAndrew.Bardsley@arm.com 20610259SAndrew.Bardsley@arm.com TimingExprIf(const TimingExprIfParams *params) : 20710259SAndrew.Bardsley@arm.com TimingExpr(params), 20810259SAndrew.Bardsley@arm.com cond(params->cond), 20910259SAndrew.Bardsley@arm.com trueExpr(params->trueExpr), 21010259SAndrew.Bardsley@arm.com falseExpr(params->falseExpr) 21110259SAndrew.Bardsley@arm.com { } 21210259SAndrew.Bardsley@arm.com 21310259SAndrew.Bardsley@arm.com uint64_t eval(TimingExprEvalContext &context); 21410259SAndrew.Bardsley@arm.com}; 21510259SAndrew.Bardsley@arm.com 21610259SAndrew.Bardsley@arm.com#endif 217