[pypy-svn] r37385 - in pypy/dist/pypy/jit/codegen: . i386/demo
arigo at codespeak.net
arigo at codespeak.net
Fri Jan 26 14:25:39 CET 2007
Author: arigo
Date: Fri Jan 26 14:25:36 2007
New Revision: 37385
Modified:
pypy/dist/pypy/jit/codegen/graph2rgenop.py
pypy/dist/pypy/jit/codegen/i386/demo/conftest.py
pypy/dist/pypy/jit/codegen/i386/demo/support.py
pypy/dist/pypy/jit/codegen/i386/demo/test_factorial.py
Log:
A big random automatically-generated function doing loads of nonsense.
Could be useful to stress-test the backend. Skipped, as indeed it
crashes the backend :-)
Modified: pypy/dist/pypy/jit/codegen/graph2rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/graph2rgenop.py (original)
+++ pypy/dist/pypy/jit/codegen/graph2rgenop.py Fri Jan 26 14:25:36 2007
@@ -9,9 +9,12 @@
def rcompile(rgenop, entrypoint, argtypes, random_seed=0):
from pypy.translator.translator import TranslationContext
+ from pypy.annotation.policy import AnnotatorPolicy
from pypy import conftest
t = TranslationContext()
- t.buildannotator().build_types(entrypoint, argtypes)
+ policy = AnnotatorPolicy()
+ policy.allow_someobjects = False
+ t.buildannotator(policy=policy).build_types(entrypoint, argtypes)
t.buildrtyper().specialize()
#from pypy.translator.backendopt.all import backend_optimizations
Modified: pypy/dist/pypy/jit/codegen/i386/demo/conftest.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/demo/conftest.py (original)
+++ pypy/dist/pypy/jit/codegen/i386/demo/conftest.py Fri Jan 26 14:25:36 2007
@@ -3,7 +3,7 @@
Option = py.test.config.Option
option = py.test.config.addoptions("demo options",
- Option('--seed', action="store_true",
+ Option('--seed', action="store", type="int",
default=random.randrange(0, 10000),
dest="randomseed",
help="choose a fixed random seed"),
Modified: pypy/dist/pypy/jit/codegen/i386/demo/support.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/demo/support.py (original)
+++ pypy/dist/pypy/jit/codegen/i386/demo/support.py Fri Jan 26 14:25:36 2007
@@ -12,6 +12,15 @@
from pypy.jit.codegen.i386.demo import conftest as demo_conftest
+def Random():
+ import random
+ seed = demo_conftest.option.randomseed
+ print
+ print 'Random seed value is %d.' % (seed,)
+ print
+ return random.Random(seed)
+
+
def rundemo(entrypoint, *args):
view = conftest.option.view
seed = demo_conftest.option.randomseed
Modified: pypy/dist/pypy/jit/codegen/i386/demo/test_factorial.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/demo/test_factorial.py (original)
+++ pypy/dist/pypy/jit/codegen/i386/demo/test_factorial.py Fri Jan 26 14:25:36 2007
@@ -1,4 +1,6 @@
-from pypy.jit.codegen.i386.demo.support import rundemo
+import py
+from pypy.rlib.rarithmetic import intmask
+from pypy.jit.codegen.i386.demo.support import rundemo, Random
# try running this with the following py.test options:
#
@@ -30,3 +32,100 @@
n -= 1
return result
rundemo(pseudofact, 10)
+
+def test_f1():
+ def f1(n):
+ "Arbitrary test function."
+ i = 0
+ x = 1
+ while i<n:
+ j = 0
+ while j<=i:
+ j = j + 1
+ x = x + (i&j)
+ i = i + 1
+ return x
+ #rundemo(f1, 2117)
+ rundemo(f1, 217)
+
+def test_random_function():
+ py.test.skip("in-progress (e.g. --seed=225 shows a backend crash)")
+ from pypy.rlib.unroll import SpecTag
+ blocklabels = range(15)
+ r = Random()
+ vars = list("abcdefghijklmnopqrstuvwxyz")
+ varlist = ', '.join(vars)
+ magicsum = '+'.join(['%s^%d' % (v, hash(v)) for v in vars])
+ operations = ['%s + %s',
+ '%s + %s',
+ '%s - %s',
+ '%s - %s',
+ '%s * %s',
+ '%s & %s',
+ '%s | %s',
+ '%s ^ %s',
+ '%s << abs(%s)',
+ '%s >> abs(%s)',
+ 'abs(%s)',
+ '-%s',
+ '~%s',
+ '%s // ((%s & 0xfffff) + 1)',
+ '%s // (-((%s & 0xfffff) + 1))',
+ '%s %% ((%s & 0xfffff) + 1)',
+ '%s %% (-((%s & 0xfffff) + 1))',
+ '!%s or %s',
+ '!%s and %s',
+ '!not %s',
+ '!bool(%s)',
+ '!%s < %s',
+ '!%s <= %s',
+ '!%s == %s',
+ '!%s != %s',
+ '!%s > %s',
+ '!%s >= %s',
+ ]
+ lines = ["def dummyfn(%(varlist)s):" % locals(),
+ " goto = blocktag0",
+ " counter = 10000",
+ " while counter > 0:",
+ " counter -= 1"]
+ for i in blocklabels:
+ lines.append(" if goto is blocktag%d:" % i)
+ for j in range(r.randrange(0, 20)):
+ v1 = r.choice(vars)
+ constbytes = r.randrange(-15, 5)
+ if constbytes <= 0:
+ v2 = r.choice(vars)
+ op = r.choice(operations)
+ if op.count('%s') == 1:
+ op = op % (v2,)
+ else:
+ v3 = r.choice(vars)
+ op = op % (v2, v3)
+ if op.startswith('!'):
+ op = op[1:]
+ else:
+ op = 'intmask(%s)' % op
+ lines.append(" %s = %s" % (v1, op))
+ else:
+ constant = r.randrange(-128, 128)
+ for i in range(1, constbytes):
+ constant = constant << 8 | r.randrange(0, 256)
+ lines.append(" %s = %d" % (v1, constant))
+ v1 = r.choice(vars)
+ lines.append(" if %s: goto = blocktag%d" %
+ (v1, r.choice(blocklabels)))
+ lines.append(" else: goto = blocktag%d" %
+ (r.choice(blocklabels),))
+ lines.append(" del goto")
+ lines.append(" return intmask(%(magicsum)s)" % locals())
+
+ miniglobals = {'intmask': intmask}
+ for i in blocklabels:
+ miniglobals['blocktag%d' % i] = SpecTag()
+ src = py.code.Source('\n'.join(lines))
+ exec src.compile() in miniglobals
+ dummyfn = miniglobals['dummyfn']
+
+ args = [r.randrange(-99, 100) for v1 in vars]
+ rundemo(dummyfn, *args)
More information about the Pypy-commit
mailing list