Example #1
0
    def _op_Iop_Yl2xF64(self, args):
        rm = self._translate_rm(args[0])
        arg2_bv = args[2].to_bv()
        # IEEE754 double looks like this:
        # SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        # thus, we extract the exponent bits, re-bias them, then
        # (signed) convert them back into an FP value for the integer
        # part of the log. then we make the approximation that log2(x)
        # = x - 1 for 1.0 <= x < 2.0 to account for the mantissa.

        # the bias for doubles is 1023
        arg2_exp = (arg2_bv[62:52] - 1023).signed_to_fp(rm, claripy.fp.FSORT_DOUBLE)
        arg2_mantissa = claripy.Concat(claripy.BVV(int('001111111111', 2), 12), arg2_bv[51:0]).raw_to_fp()
        # this is the hacky approximation:
        log2_arg2_mantissa = claripy.fpSub(rm, arg2_mantissa, claripy.FPV(1.0, claripy.fp.FSORT_DOUBLE))
        return claripy.fpMul(rm, args[1].raw_to_fp(), claripy.fpAdd(rm, arg2_exp, log2_arg2_mantissa))
Example #2
0
    def _op_Iop_Yl2xF64(self, args):
        rm = self._translate_rm(args[0])
        arg2_bv = args[2].to_bv()
        # IEEE754 double looks like this:
        # SEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        # thus, we extract the exponent bits, re-bias them, then
        # (signed) convert them back into an FP value for the integer
        # part of the log. then we make the approximation that log2(x)
        # = x - 1 for 1.0 <= x < 2.0 to account for the mantissa.

        # the bias for doubles is 1023
        arg2_exp = (arg2_bv[62:52] - 1023).signed_to_fp(
            rm, claripy.fp.FSORT_DOUBLE)
        arg2_mantissa = claripy.Concat(claripy.BVV(int('001111111111', 2), 12),
                                       arg2_bv[51:0]).raw_to_fp()
        # this is the hacky approximation:
        log2_arg2_mantissa = claripy.fpSub(
            rm, arg2_mantissa, claripy.FPV(1.0, claripy.fp.FSORT_DOUBLE))
        return claripy.fpMul(rm, args[1].raw_to_fp(),
                             claripy.fpAdd(rm, arg2_exp, log2_arg2_mantissa))
Example #3
0
 def pow(rm, arg, n):
     out = claripy.FPV(1.0, arg.sort)
     for _ in range(n):
         out = claripy.fpMul(rm, arg, out)
     return out
Example #4
0
 def pow(rm, arg, n):
     out = claripy.FPV(1.0, arg.sort)
     for _ in xrange(n):
         out = claripy.fpMul(rm, arg, out)
     return out