summaryrefslogtreecommitdiff
path: root/src/arch/arm/insts/static_inst.hh
diff options
context:
space:
mode:
authorGabe Black <gblack@eecs.umich.edu>2010-06-02 12:58:05 -0500
committerGabe Black <gblack@eecs.umich.edu>2010-06-02 12:58:05 -0500
commit62e8487d57796a15887af82034c8283611032ce0 (patch)
treec0b9bd4933daae68b91a9c4e106dec40ebeac1cc /src/arch/arm/insts/static_inst.hh
parenta1253ec6442b217322a6a0104fb9e99f6ab958b1 (diff)
downloadgem5-62e8487d57796a15887af82034c8283611032ce0.tar.xz
ARM: Implement signed saturating add and/or subtract instructions.
Diffstat (limited to 'src/arch/arm/insts/static_inst.hh')
-rw-r--r--src/arch/arm/insts/static_inst.hh17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/arch/arm/insts/static_inst.hh b/src/arch/arm/insts/static_inst.hh
index 485d6997e..634cf0812 100644
--- a/src/arch/arm/insts/static_inst.hh
+++ b/src/arch/arm/insts/static_inst.hh
@@ -60,6 +60,23 @@ class ArmStaticInst : public StaticInst
bool shift_carry_rs(uint32_t base, uint32_t shamt,
uint32_t type, uint32_t cfval) const;
+ template<int width>
+ static bool
+ saturateOp(int32_t &res, int64_t op1, int64_t op2, bool sub=false)
+ {
+ int64_t midRes = sub ? (op1 - op2) : (op1 + op2);
+ if (bits(midRes, width) != bits(midRes, width - 1)) {
+ if (midRes > 0)
+ res = (1LL << (width - 1)) - 1;
+ else
+ res = -(1LL << (width - 1));
+ return true;
+ } else {
+ res = midRes;
+ return false;
+ }
+ }
+
// Constructor
ArmStaticInst(const char *mnem, ExtMachInst _machInst,
OpClass __opClass)