[pypy-commit] pypy default: (bivab, arigo)
arigo
noreply at buildbot.pypy.org
Tue May 24 10:55:16 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r44397:100b7243a842
Date: 2011-05-24 11:06 +0200
http://bitbucket.org/pypy/pypy/changeset/100b7243a842/
Log: (bivab, arigo)
Check all possible combinations instead of using
itertools.permutations().
diff --git a/pypy/jit/backend/test/calling_convention_test.py b/pypy/jit/backend/test/calling_convention_test.py
--- a/pypy/jit/backend/test/calling_convention_test.py
+++ b/pypy/jit/backend/test/calling_convention_test.py
@@ -1,4 +1,3 @@
-import py, sys, random, os, struct, operator, itertools
from pypy.jit.metainterp.history import (AbstractFailDescr,
AbstractDescr,
BasicFailDescr,
@@ -48,79 +47,46 @@
def func(*args):
- return sum(args)
+ return float(sum(args))
F = lltype.Float
I = lltype.Signed
- base_args = [F, F]
- floats = [0.7, 5.8, 0.1, 0.3, 0.9]
- ints = [7, 11, 23]
- result = sum(floats + ints)
- for p in itertools.permutations([I, I, I, F, F, F]):
- args = base_args + list(p)
+ floats = [0.7, 5.8, 0.1, 0.3, 0.9, -2.34, -3.45, -4.56]
+ ints = [7, 11, 23, 13, -42, 1111, 95, 1]
+ for case in range(256):
+ result = 0.0
+ args = []
+ argslist = []
local_floats = list(floats)
local_ints = list(ints)
+ for i in range(8):
+ if case & (1<<i):
+ args.append(F)
+ arg = local_floats.pop()
+ result += arg
+ argslist.append(boxfloat(arg))
+ else:
+ args.append(I)
+ arg = local_ints.pop()
+ result += arg
+ argslist.append(BoxInt(arg))
FUNC = self.FuncType(args, F)
FPTR = self.Ptr(FUNC)
func_ptr = llhelper(FPTR, func)
calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT)
funcbox = self.get_funcbox(cpu, func_ptr)
- argslist = []
- for x in args:
- if x is F:
- argslist.append(boxfloat(local_floats.pop()))
- else:
- argslist.append(BoxInt(local_ints.pop()))
res = self.execute_operation(rop.CALL,
[funcbox] + argslist,
'float', descr=calldescr)
assert abs(res.getfloat() - result) < 0.0001
- def test_call_alignment_register_args(self):
- from pypy.rlib.libffi import types
- cpu = self.cpu
- if not cpu.supports_floats:
- py.test.skip('requires floats')
-
-
- def func(*args):
- return sum(args)
-
- F = lltype.Float
- I = lltype.Signed
- floats = [0.7, 5.8]
- ints = [7, 11]
- result = sum(floats + ints)
- for args in itertools.permutations([I, I, F, F]):
- local_floats = list(floats)
- local_ints = list(ints)
- FUNC = self.FuncType(args, F)
- FPTR = self.Ptr(FUNC)
- func_ptr = llhelper(FPTR, func)
- calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT)
- funcbox = self.get_funcbox(cpu, func_ptr)
- argslist = []
- for x in args:
- if x is F:
- argslist.append(boxfloat(local_floats.pop()))
- else:
- argslist.append(BoxInt(local_ints.pop()))
-
- res = self.execute_operation(rop.CALL,
- [funcbox] + argslist,
- 'float', descr=calldescr)
- assert abs(res.getfloat() - result) < 0.0001
-
-
def test_call_alignment_call_assembler(self):
from pypy.rlib.libffi import types
cpu = self.cpu
if not cpu.supports_floats:
py.test.skip('requires floats')
- fdescr1 = BasicFailDescr(1)
- fdescr2 = BasicFailDescr(2)
fdescr3 = BasicFailDescr(3)
fdescr4 = BasicFailDescr(4)
@@ -136,35 +102,49 @@
assembler_helper_adr = llmemory.cast_ptr_to_adr(
_assembler_helper_ptr)
- arglist = ['f0', 'f1', 'f2', 'i0', 'f3']
- floats = [0.7, 5.8, 0.1, 0.3]
- ints = [7, 11, 23, 42]
+ floats = [0.7, 5.8, 0.1, 0.3, 0.9, -2.34, -3.45, -4.56]
+ ints = [7, 11, 23, 42, -42, 1111, 95, 1]
def _prepare_args(args):
local_floats = list(floats)
local_ints = list(ints)
+ expected_result = 0.0
for i in range(len(args)):
x = args[i]
if x[0] == 'f':
- t = longlong.getfloatstorage(local_floats.pop())
+ x = local_floats.pop()
+ t = longlong.getfloatstorage(x)
cpu.set_future_value_float(i, t)
else:
- cpu.set_future_value_int(i, (local_ints.pop()))
+ x = local_ints.pop()
+ cpu.set_future_value_int(i, x)
+ expected_result += x
+ return expected_result
- for args in itertools.permutations(arglist):
- args += ('i1', 'i2', 'i3')
+ for case in range(256):
+ float_count = 0
+ int_count = 0
+ args = []
+ called_ops = ''
+ total_index = -1
+ for i in range(8):
+ if case & (1<<i):
+ args.append('f%d' % float_count)
+ else:
+ args.append('i%d' % int_count)
+ called_ops += 'f%d = cast_int_to_float(i%d)\n' % (
+ float_count, int_count)
+ int_count += 1
+ if total_index == -1:
+ total_index = float_count
+ float_count += 1
+ else:
+ called_ops += 'f%d = float_add(f%d, f%d)\n' % (
+ float_count + 1, total_index, float_count)
+ total_index = float_count + 1
+ float_count += 2
arguments = ', '.join(args)
- called_ops = '''
- [%s]
- i4 = int_add(i0, i1)
- i5 = int_add(i4, i2)
- i6 = int_add(i5, i3)
- guard_value(i6, 83, descr=fdescr1) [i4, i5, i6]
- f4 = float_add(f0, f1)
- f5 = float_add(f4, f2)
- f6 = float_add(f5, f3)
- i7 = float_lt(f6, 6.99)
- guard_true(i7, descr=fdescr2) [f4, f5, f6]
- finish(i6, f6, descr=fdescr3)''' % arguments
+ called_ops = '[%s]\n' % arguments + called_ops
+ called_ops += 'finish(f%d, descr=fdescr3)\n' % total_index
# compile called loop
called_loop = parse(called_ops, namespace=locals())
called_looptoken = LoopToken()
@@ -172,15 +152,14 @@
done_number = self.cpu.get_fail_descr_number(called_loop.operations[-1].getdescr())
self.cpu.compile_loop(called_loop.inputargs, called_loop.operations, called_looptoken)
- _prepare_args(args)
+ expected_result = _prepare_args(args)
res = cpu.execute_token(called_looptoken)
assert res.identifier == 3
- assert cpu.get_latest_value_int(0) == 83
- t = longlong.getrealfloat(cpu.get_latest_value_float(1))
- assert abs(t - 6.9) < 0.0001
+ t = longlong.getrealfloat(cpu.get_latest_value_float(0))
+ assert abs(t - expected_result) < 0.0001
ARGS = []
- RES = lltype.Signed
+ RES = lltype.Float
for x in args:
if x[0] == 'f':
ARGS.append(lltype.Float)
@@ -190,13 +169,13 @@
lltype.Ptr(lltype.FuncType(ARGS, RES)), ARGS, RES)
ops = '''
[%s]
- i10 = call_assembler(%s, descr=called_looptoken)
+ f99 = call_assembler(%s, descr=called_looptoken)
guard_not_forced()[]
- finish(i10, descr=fdescr4)
+ finish(f99, descr=fdescr4)
''' % (arguments, arguments)
loop = parse(ops, namespace=locals())
# we want to take the fast path
- self.cpu.done_with_this_frame_int_v = done_number
+ self.cpu.done_with_this_frame_float_v = done_number
try:
othertoken = LoopToken()
self.cpu.compile_loop(loop.inputargs, loop.operations, othertoken)
@@ -204,8 +183,8 @@
# prepare call to called_loop
_prepare_args(args)
res = cpu.execute_token(othertoken)
- x = cpu.get_latest_value_int(0)
+ x = longlong.getrealfloat(cpu.get_latest_value_float(0))
assert res.identifier == 4
- assert x == 83
+ assert abs(x - expected_result) < 0.0001
finally:
- del self.cpu.done_with_this_frame_int_v
+ del self.cpu.done_with_this_frame_float_v
More information about the pypy-commit
mailing list