diff options
Diffstat (limited to 'src/arch/arm/insts')
-rw-r--r-- | src/arch/arm/insts/static_inst.hh | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/src/arch/arm/insts/static_inst.hh b/src/arch/arm/insts/static_inst.hh index 3ff1d20cd..2c83ee79c 100644 --- a/src/arch/arm/insts/static_inst.hh +++ b/src/arch/arm/insts/static_inst.hh @@ -67,9 +67,9 @@ class ArmStaticInst : public StaticInst int64_t midRes = sub ? (op1 - op2) : (op1 + op2); if (bits(midRes, width) != bits(midRes, width - 1)) { if (midRes > 0) - res = (1LL << (width - 1)) - 1; + res = (LL(1) << (width - 1)) - 1; else - res = -(1LL << (width - 1)); + res = -(LL(1) << (width - 1)); return true; } else { res = midRes; @@ -77,13 +77,29 @@ class ArmStaticInst : public StaticInst } } + static bool + satInt(int32_t &res, int64_t op, int width) + { + width--; + if (op >= (LL(1) << width)) { + res = (LL(1) << width) - 1; + return true; + } else if (op < -(LL(1) << width)) { + res = -(LL(1) << width); + return true; + } else { + res = op; + return false; + } + } + template<int width> static bool uSaturateOp(uint32_t &res, int64_t op1, int64_t op2, bool sub=false) { int64_t midRes = sub ? (op1 - op2) : (op1 + op2); - if (midRes >= (1 << width)) { - res = (1 << width) - 1; + if (midRes >= (LL(1) << width)) { + res = (LL(1) << width) - 1; return true; } else if (midRes < 0) { res = 0; @@ -94,6 +110,21 @@ class ArmStaticInst : public StaticInst } } + static bool + uSatInt(int32_t &res, int64_t op, int width) + { + if (op >= (LL(1) << width)) { + res = (LL(1) << width) - 1; + return true; + } else if (op < 0) { + res = 0; + return true; + } else { + res = op; + return false; + } + } + // Constructor ArmStaticInst(const char *mnem, ExtMachInst _machInst, OpClass __opClass) |