110259SAndrew.Bardsley@arm.com# Copyright (c) 2013-2014 ARM Limited 210259SAndrew.Bardsley@arm.com# All rights reserved. 310259SAndrew.Bardsley@arm.com# 410259SAndrew.Bardsley@arm.com# The license below extends only to copyright in the software and shall 510259SAndrew.Bardsley@arm.com# not be construed as granting a license to any other intellectual 610259SAndrew.Bardsley@arm.com# property including but not limited to intellectual property relating 710259SAndrew.Bardsley@arm.com# to a hardware implementation of the functionality of the software 810259SAndrew.Bardsley@arm.com# licensed hereunder. You may use the software subject to the license 910259SAndrew.Bardsley@arm.com# terms below provided that you ensure that this notice is replicated 1010259SAndrew.Bardsley@arm.com# unmodified and in its entirety in all distributions of the software, 1110259SAndrew.Bardsley@arm.com# modified or unmodified, in source code or in binary form. 1210259SAndrew.Bardsley@arm.com# 1310259SAndrew.Bardsley@arm.com# Redistribution and use in source and binary forms, with or without 1410259SAndrew.Bardsley@arm.com# modification, are permitted provided that the following conditions are 1510259SAndrew.Bardsley@arm.com# met: redistributions of source code must retain the above copyright 1610259SAndrew.Bardsley@arm.com# notice, this list of conditions and the following disclaimer; 1710259SAndrew.Bardsley@arm.com# redistributions in binary form must reproduce the above copyright 1810259SAndrew.Bardsley@arm.com# notice, this list of conditions and the following disclaimer in the 1910259SAndrew.Bardsley@arm.com# documentation and/or other materials provided with the distribution; 2010259SAndrew.Bardsley@arm.com# neither the name of the copyright holders nor the names of its 2110259SAndrew.Bardsley@arm.com# contributors may be used to endorse or promote products derived from 2210259SAndrew.Bardsley@arm.com# this software without specific prior written permission. 2310259SAndrew.Bardsley@arm.com# 2410259SAndrew.Bardsley@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2510259SAndrew.Bardsley@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2610259SAndrew.Bardsley@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2710259SAndrew.Bardsley@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2810259SAndrew.Bardsley@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2910259SAndrew.Bardsley@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3010259SAndrew.Bardsley@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3110259SAndrew.Bardsley@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3210259SAndrew.Bardsley@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3310259SAndrew.Bardsley@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3410259SAndrew.Bardsley@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3510259SAndrew.Bardsley@arm.com# 3610259SAndrew.Bardsley@arm.com# Authors: Andrew Bardsley 3710259SAndrew.Bardsley@arm.com 3810259SAndrew.Bardsley@arm.comfrom m5.params import * 3910259SAndrew.Bardsley@arm.comfrom m5.SimObject import SimObject 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.comclass TimingExpr(SimObject): 4910259SAndrew.Bardsley@arm.com type = 'TimingExpr' 5010259SAndrew.Bardsley@arm.com cxx_header = 'cpu/timing_expr.hh' 5110259SAndrew.Bardsley@arm.com abstract = True; 5210259SAndrew.Bardsley@arm.com 5310259SAndrew.Bardsley@arm.comclass TimingExprLiteral(TimingExpr): 5410259SAndrew.Bardsley@arm.com """Literal 64 bit unsigned value""" 5510259SAndrew.Bardsley@arm.com type = 'TimingExprLiteral' 5610259SAndrew.Bardsley@arm.com cxx_header = 'cpu/timing_expr.hh' 5710259SAndrew.Bardsley@arm.com 5810259SAndrew.Bardsley@arm.com value = Param.UInt64("literal value") 5910259SAndrew.Bardsley@arm.com 6010259SAndrew.Bardsley@arm.com def set_params(self, value): 6110259SAndrew.Bardsley@arm.com self.value = value 6210259SAndrew.Bardsley@arm.com return self 6310259SAndrew.Bardsley@arm.com 6410259SAndrew.Bardsley@arm.comclass TimingExpr0(TimingExprLiteral): 6510259SAndrew.Bardsley@arm.com """Convenient 0""" 6610259SAndrew.Bardsley@arm.com value = 0 6710259SAndrew.Bardsley@arm.com 6810259SAndrew.Bardsley@arm.comclass TimingExprSrcReg(TimingExpr): 6910259SAndrew.Bardsley@arm.com """Find the source register number from the current inst""" 7010259SAndrew.Bardsley@arm.com type = 'TimingExprSrcReg' 7110259SAndrew.Bardsley@arm.com cxx_header = 'cpu/timing_expr.hh' 7210259SAndrew.Bardsley@arm.com 7310259SAndrew.Bardsley@arm.com # index = Param.Unsigned("index into inst src regs") 7410259SAndrew.Bardsley@arm.com index = Param.Unsigned("index into inst src regs") 7510259SAndrew.Bardsley@arm.com 7610259SAndrew.Bardsley@arm.com def set_params(self, index): 7710259SAndrew.Bardsley@arm.com self.index = index 7810259SAndrew.Bardsley@arm.com return self 7910259SAndrew.Bardsley@arm.com 8010259SAndrew.Bardsley@arm.comclass TimingExprReadIntReg(TimingExpr): 8110259SAndrew.Bardsley@arm.com """Read an architectural register""" 8210259SAndrew.Bardsley@arm.com type = 'TimingExprReadIntReg' 8310259SAndrew.Bardsley@arm.com cxx_header = 'cpu/timing_expr.hh' 8410259SAndrew.Bardsley@arm.com 8510259SAndrew.Bardsley@arm.com reg = Param.TimingExpr("register raw index to read") 8610259SAndrew.Bardsley@arm.com 8710259SAndrew.Bardsley@arm.com def set_params(self, reg): 8810259SAndrew.Bardsley@arm.com self.reg = reg 8910259SAndrew.Bardsley@arm.com return self 9010259SAndrew.Bardsley@arm.com 9110259SAndrew.Bardsley@arm.comclass TimingExprLet(TimingExpr): 9210259SAndrew.Bardsley@arm.com """Block of declarations""" 9310259SAndrew.Bardsley@arm.com type = 'TimingExprLet' 9410259SAndrew.Bardsley@arm.com cxx_header = 'cpu/timing_expr.hh' 9510259SAndrew.Bardsley@arm.com 9610259SAndrew.Bardsley@arm.com defns = VectorParam.TimingExpr("expressions for bindings") 9710259SAndrew.Bardsley@arm.com expr = Param.TimingExpr("body expression") 9810259SAndrew.Bardsley@arm.com 9910259SAndrew.Bardsley@arm.com def set_params(self, defns, expr): 10010259SAndrew.Bardsley@arm.com self.defns = defns 10110259SAndrew.Bardsley@arm.com self.expr = expr 10210259SAndrew.Bardsley@arm.com return self 10310259SAndrew.Bardsley@arm.com 10410259SAndrew.Bardsley@arm.comclass TimingExprRef(TimingExpr): 10510259SAndrew.Bardsley@arm.com """Value of a bound sub-expression""" 10610259SAndrew.Bardsley@arm.com type = 'TimingExprRef' 10710259SAndrew.Bardsley@arm.com cxx_header = 'cpu/timing_expr.hh' 10810259SAndrew.Bardsley@arm.com 10910259SAndrew.Bardsley@arm.com index = Param.Unsigned("expression index") 11010259SAndrew.Bardsley@arm.com 11110259SAndrew.Bardsley@arm.com def set_params(self, index): 11210259SAndrew.Bardsley@arm.com self.index = index 11310259SAndrew.Bardsley@arm.com return self 11410259SAndrew.Bardsley@arm.com 11510259SAndrew.Bardsley@arm.comclass TimingExprOp(Enum): 11610259SAndrew.Bardsley@arm.com vals = [ 11710259SAndrew.Bardsley@arm.com 'timingExprAdd', 'timingExprSub', 11810259SAndrew.Bardsley@arm.com 'timingExprUMul', 'timingExprUDiv', 11910259SAndrew.Bardsley@arm.com 'timingExprSMul', 'timingExprSDiv', 12010259SAndrew.Bardsley@arm.com 'timingExprUCeilDiv', # Unsigned divide rounding up 12110259SAndrew.Bardsley@arm.com 'timingExprEqual', 'timingExprNotEqual', 12210259SAndrew.Bardsley@arm.com 'timingExprULessThan', 12310259SAndrew.Bardsley@arm.com 'timingExprUGreaterThan', 12410259SAndrew.Bardsley@arm.com 'timingExprSLessThan', 12510259SAndrew.Bardsley@arm.com 'timingExprSGreaterThan', 12610259SAndrew.Bardsley@arm.com 'timingExprInvert', 12710259SAndrew.Bardsley@arm.com 'timingExprNot', 12810259SAndrew.Bardsley@arm.com 'timingExprAnd', 12910259SAndrew.Bardsley@arm.com 'timingExprOr', 13010259SAndrew.Bardsley@arm.com 'timingExprSizeInBits', 13110259SAndrew.Bardsley@arm.com 'timingExprSignExtend32To64', 13210259SAndrew.Bardsley@arm.com 'timingExprAbs' 13310259SAndrew.Bardsley@arm.com ] 13410259SAndrew.Bardsley@arm.com 13510259SAndrew.Bardsley@arm.comclass TimingExprUn(TimingExpr): 13610259SAndrew.Bardsley@arm.com """Unary operator""" 13710259SAndrew.Bardsley@arm.com type = 'TimingExprUn' 13810259SAndrew.Bardsley@arm.com cxx_header = 'cpu/timing_expr.hh' 13910259SAndrew.Bardsley@arm.com 14010259SAndrew.Bardsley@arm.com op = Param.TimingExprOp("operator") 14110259SAndrew.Bardsley@arm.com arg = Param.TimingExpr("expression") 14210259SAndrew.Bardsley@arm.com 14310259SAndrew.Bardsley@arm.com def set_params(self, op, arg): 14410259SAndrew.Bardsley@arm.com self.op = op 14510259SAndrew.Bardsley@arm.com self.arg = arg 14610259SAndrew.Bardsley@arm.com return self 14710259SAndrew.Bardsley@arm.com 14810259SAndrew.Bardsley@arm.comclass TimingExprBin(TimingExpr): 14910259SAndrew.Bardsley@arm.com """Binary operator""" 15010259SAndrew.Bardsley@arm.com type = 'TimingExprBin' 15110259SAndrew.Bardsley@arm.com cxx_header = 'cpu/timing_expr.hh' 15210259SAndrew.Bardsley@arm.com 15310259SAndrew.Bardsley@arm.com op = Param.TimingExprOp("operator") 15410259SAndrew.Bardsley@arm.com left = Param.TimingExpr("LHS expression") 15510259SAndrew.Bardsley@arm.com right = Param.TimingExpr("RHS expression") 15610259SAndrew.Bardsley@arm.com 15710259SAndrew.Bardsley@arm.com def set_params(self, op, left, right): 15810259SAndrew.Bardsley@arm.com self.op = op 15910259SAndrew.Bardsley@arm.com self.left = left 16010259SAndrew.Bardsley@arm.com self.right = right 16110259SAndrew.Bardsley@arm.com return self 16210259SAndrew.Bardsley@arm.com 16310259SAndrew.Bardsley@arm.comclass TimingExprIf(TimingExpr): 16410259SAndrew.Bardsley@arm.com """If-then-else operator""" 16510259SAndrew.Bardsley@arm.com type = 'TimingExprIf' 16610259SAndrew.Bardsley@arm.com cxx_header = 'cpu/timing_expr.hh' 16710259SAndrew.Bardsley@arm.com 16810259SAndrew.Bardsley@arm.com cond = Param.TimingExpr("condition expression") 16910259SAndrew.Bardsley@arm.com trueExpr = Param.TimingExpr("true expression") 17010259SAndrew.Bardsley@arm.com falseExpr = Param.TimingExpr("false expression") 17110259SAndrew.Bardsley@arm.com 17210259SAndrew.Bardsley@arm.com def set_params(self, cond, trueExpr, falseExpr): 17310259SAndrew.Bardsley@arm.com self.cond = cond 17410259SAndrew.Bardsley@arm.com self.trueExpr = trueExpr 17510259SAndrew.Bardsley@arm.com self.falseExpr = falseExpr 17610259SAndrew.Bardsley@arm.com return self 177