def test_float_hf_call_mixed(self):
        if not self.cpu.supports_floats:
            py.test.skip("requires floats")
        cpu = self.cpu
        callargs = []

        def func(f0, f1, f2, f3, f4, f5, f6, i0, f7, i1, f8, f9):
            callargs.append(zip(range(12), [f0, f1, f2, f3, f4, f5, f6, i0, f7, i1, f8, f9]))
            return f0 + f1 + f2 + f3 + f4 + f5 + f6 + float(i0 + i1) + f7 + f8 + f9

        F = lltype.Float
        I = lltype.Signed
        FUNC = self.FuncType([F] * 7 + [I] + [F] + [I] + [F] * 2, F)
        FPTR = self.Ptr(FUNC)
        func_ptr = llhelper(FPTR, func)
        calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo.MOST_GENERAL)
        funcbox = self.get_funcbox(cpu, func_ptr)
        args = [boxfloat(0.1) for i in range(7)] + [BoxInt(1), boxfloat(0.2), BoxInt(2), boxfloat(0.3), boxfloat(0.4)]
        res = self.execute_operation(rop.CALL, [funcbox] + args, "float", descr=calldescr)
        for i, j in enumerate(callargs[0]):
            box = args[i]
            if box.type == "f":
                assert (i, args[i].getfloat()) == j
            else:
                assert (i, args[i].getint()) == j
        assert abs(res.getfloat() - 4.6) < 0.0001
 def test_float_hf_call_mixed(self):
     if not self.cpu.supports_floats:
         py.test.skip("requires floats")
     cpu = self.cpu
     callargs = []
     def func(f0, f1, f2, f3, f4, f5, f6, i0, f7, i1, f8, f9):
         callargs.append(zip(range(12),
                     [f0, f1, f2, f3, f4, f5, f6, i0, f7, i1, f8, f9]))
         return f0 + f1 + f2 + f3 + f4 + f5 + f6 + float(i0 + i1) + f7 + f8 + f9
     F = lltype.Float
     I = lltype.Signed
     FUNC = self.FuncType([F] * 7 + [I] + [F] + [I] + [F]* 2, F)
     FPTR = self.Ptr(FUNC)
     func_ptr = llhelper(FPTR, func)
     calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
                                 EffectInfo.MOST_GENERAL)
     funcbox = self.get_funcbox(cpu, func_ptr)
     args = ([boxfloat(.1) for i in range(7)] +
             [BoxInt(1), boxfloat(.2), BoxInt(2), boxfloat(.3),
              boxfloat(.4)])
     res = self.execute_operation(rop.CALL,
                                  [funcbox] + args,
                                  'float', descr=calldescr)
     for i,j in enumerate(callargs[0]):
         box = args[i]
         if box.type == 'f':
             assert (i, args[i].getfloat()) == j
         else:
             assert (i, args[i].getint()) == j
     assert abs(res.getfloat() - 4.6) < 0.0001
Example #3
0
    def test_float_hf_call_float(self):
        if not self.cpu.supports_floats:
            py.test.skip("requires floats")
        cpu = self.cpu
        callargs = []

        def func(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9):
            callargs.append(
                zip(range(10), [f0, f1, f2, f3, f4, f5, f6, f7, f8, f9]))
            return f0 + f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9

        F = lltype.Float
        FUNC = self.FuncType([F] * 10, F)
        FPTR = self.Ptr(FUNC)
        func_ptr = llhelper(FPTR, func)
        calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
                                    EffectInfo.MOST_GENERAL)
        funcbox = self.get_funcbox(cpu, func_ptr)
        args = ([boxfloat(.1) for i in range(10)])
        res = self.execute_operation(rop.CALL_F, [funcbox] + args,
                                     'float',
                                     descr=calldescr)
        for i, j in enumerate(callargs[0]):
            assert (i, 0.1) == j
        assert abs(res.getfloat() - 1) < 0.0001
    def test_float_hf_call_float(self):
        if not self.cpu.supports_floats:
            py.test.skip("requires floats")
        cpu = self.cpu
        callargs = []

        def func(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9):
            callargs.append(zip(range(10), [f0, f1, f2, f3, f4, f5, f6, f7, f8, f9]))
            return f0 + f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9

        F = lltype.Float
        FUNC = self.FuncType([F] * 10, F)
        FPTR = self.Ptr(FUNC)
        func_ptr = llhelper(FPTR, func)
        calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo.MOST_GENERAL)
        funcbox = self.get_funcbox(cpu, func_ptr)
        args = [boxfloat(0.1) for i in range(10)]
        res = self.execute_operation(rop.CALL, [funcbox] + args, "float", descr=calldescr)
        for i, j in enumerate(callargs[0]):
            assert (i, 0.1) == j
        assert abs(res.getfloat() - 1) < 0.0001