[pypy-commit] pypy jitdriver-setparam-all: Change set_param API. Now we run set_param(driver-or-None, 'name', value)

2011-11-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: jitdriver-setparam-all
Changeset: r49506:f121b8ac7363
Date: 2011-11-18 11:15 +0200
http://bitbucket.org/pypy/pypy/changeset/f121b8ac7363/

Log:Change set_param API. Now we run set_param(driver-or-None, 'name',
value) instead of driver.set_param(...). This makes it possible to
pass None, which changes the param on all drivers.

diff --git a/pypy/jit/metainterp/test/test_ajit.py 
b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -14,7 +14,7 @@
 from pypy.rlib.jit import (JitDriver, we_are_jitted, hint, dont_look_inside,
 loop_invariant, elidable, promote, jit_debug, assert_green,
 AssertGreenFailed, unroll_safe, current_trace_length, look_inside_iff,
-isconstant, isvirtual, promote_string)
+isconstant, isvirtual, promote_string, set_param)
 from pypy.rlib.rarithmetic import ovfcheck
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.rpython.ootypesystem import ootype
@@ -1256,15 +1256,18 @@
 n -= 1
 x += n
 return x
-def f(n, threshold):
-myjitdriver.set_param('threshold', threshold)
+def f(n, threshold, arg):
+if arg:
+set_param(myjitdriver, 'threshold', threshold)
+else:
+set_param(None, 'threshold', threshold)
 return g(n)
 
-res = self.meta_interp(f, [10, 3])
+res = self.meta_interp(f, [10, 3, 1])
 assert res == 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 0
 self.check_tree_loop_count(2)
 
-res = self.meta_interp(f, [10, 13])
+res = self.meta_interp(f, [10, 13, 0])
 assert res == 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 0
 self.check_tree_loop_count(0)
 
@@ -2328,8 +2331,8 @@
 get_printable_location=get_printable_location)
 bytecode = "0j10jc20a3"
 def f():
-myjitdriver.set_param('threshold', 7)
-myjitdriver.set_param('trace_eagerness', 1)
+set_param(myjitdriver, 'threshold', 7)
+set_param(myjitdriver, 'trace_eagerness', 1)
 i = j = c = a = 1
 while True:
 myjitdriver.jit_merge_point(i=i, j=j, c=c, a=a)
@@ -2607,7 +2610,7 @@
 myjitdriver = JitDriver(greens = [], reds = ['n', 'i', 'sa', 'a'])
 
 def f(n, limit):
-myjitdriver.set_param('retrace_limit', limit)
+set_param(myjitdriver, 'retrace_limit', limit)
 sa = i = a = 0
 while i < n:
 myjitdriver.jit_merge_point(n=n, i=i, sa=sa, a=a)
@@ -2625,8 +2628,8 @@
 myjitdriver = JitDriver(greens = [], reds = ['n', 'i', 'sa', 'a'])
 
 def f(n, limit):
-myjitdriver.set_param('retrace_limit', 3)
-myjitdriver.set_param('max_retrace_guards', limit)
+set_param(myjitdriver, 'retrace_limit', 3)
+set_param(myjitdriver, 'max_retrace_guards', limit)
 sa = i = a = 0
 while i < n:
 myjitdriver.jit_merge_point(n=n, i=i, sa=sa, a=a)
@@ -2645,7 +2648,7 @@
 myjitdriver = JitDriver(greens = [], reds = ['n', 'i', 'sa', 'a',
  'node'])
 def f(n, limit):
-myjitdriver.set_param('retrace_limit', limit)
+set_param(myjitdriver, 'retrace_limit', limit)
 sa = i = a = 0
 node = [1, 2, 3]
 node[1] = n
@@ -2668,10 +2671,10 @@
 myjitdriver = JitDriver(greens = ['pc'], reds = ['n', 'i', 'sa'])
 bytecode = "0+sI0+SI"
 def f(n):
-myjitdriver.set_param('threshold', 3)
-myjitdriver.set_param('trace_eagerness', 1)
-myjitdriver.set_param('retrace_limit', 5)
-myjitdriver.set_param('function_threshold', -1)
+set_param(None, 'threshold', 3)
+set_param(None, 'trace_eagerness', 1)
+set_param(None, 'retrace_limit', 5)
+set_param(None, 'function_threshold', -1)
 pc = sa = i = 0
 while pc < len(bytecode):
 myjitdriver.jit_merge_point(pc=pc, n=n, sa=sa, i=i)
@@ -2728,9 +2731,9 @@
 myjitdriver = JitDriver(greens = ['pc'], reds = ['n', 'a', 'i', 'j', 
'sa'])
 bytecode = "ij+Jj+JI"
 def f(n, a):
-myjitdriver.set_param('threshold', 5)
-myjitdriver.set_param('trace_eagerness', 1)
-myjitdriver.set_param('retrace_limit', 2)
+set_param(None, 'threshold', 5)
+set_param(None, 'trace_eagerness', 1)
+set_param(None, 'retrace_limit', 2)
 pc = sa = i = j = 0
 while pc < len(bytecode):
 myjitdriver.jit_merge_point(pc=pc, n=n, sa=sa, i=i, j=j, a=a)
@@ -2793,8 +2796,8 @@
 return B(self.val + 1)
 myjitdriver = JitD

[pypy-commit] pypy op_malloc_gc: A branch to simplify the backend interface: instead of

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: op_malloc_gc
Changeset: r49507:62ea37257eb5
Date: 2011-11-18 10:13 +0100
http://bitbucket.org/pypy/pypy/changeset/62ea37257eb5/

Log:A branch to simplify the backend interface: instead of the various
new_xxx resoperations, there is only one malloc_gc operation. Can
also be used to do mallocs "in groups", when mallocing several small
structures.

___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy op_malloc_gc: Attempt to collapse several NEW-like operations into a single

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: op_malloc_gc
Changeset: r49508:a85153701bb6
Date: 2011-11-10 21:32 +0100
http://bitbucket.org/pypy/pypy/changeset/a85153701bb6/

Log:Attempt to collapse several NEW-like operations into a single
simpler MALLOC_GC operation: starting...

diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -672,6 +672,7 @@
 self.WB_ARRAY_FUNCPTR = lltype.Ptr(lltype.FuncType(
 [llmemory.Address, lltype.Signed, llmemory.Address], lltype.Void))
 self.write_barrier_descr = WriteBarrierDescr(self)
+self.fielddescr_tid = self.write_barrier_descr.fielddescr_tid
 #
 def malloc_array(itemsize, tid, num_elem):
 type_id = llop.extract_ushort(llgroup.HALFWORD, tid)
@@ -809,17 +810,52 @@
 newops = []
 known_lengths = {}
 # we can only remember one malloc since the next malloc can possibly
-# collect
-last_malloc = None
+# collect; but we can try to collapse several known-size mallocs into
+# one, both for performance and to reduce the number of write
+# barriers.  We do this on each "basic block" of operations, which in
+# this case means between CALLs or unknown-size mallocs.
+op_malloc_gc = None
+v_last_malloc = None
+previous_size = -1
+current_mallocs = {}
+#
 for op in operations:
 if op.getopnum() == rop.DEBUG_MERGE_POINT:
 continue
 # -- record the ConstPtrs --
 self.record_constptrs(op, gcrefs_output_list)
+# -- fold the NEWxxx operations into MALLOC_GC --
 if op.is_malloc():
-last_malloc = op.result
+if op.getopnum() == rop.NEW:
+descr = op.getdescr()
+assert isinstance(descr, BaseSizeDescr)
+if op_malloc_gc is None:
+# it is the first we see: emit MALLOC_GC
+op = ResOperation(rop.MALLOC_GC,
+  [ConstInt(descr.size)],
+  op.result)
+op_malloc_gc = op
+else:
+# already a MALLOC_GC: increment its total size
+total_size = op_malloc_gc.getarg(0).getint()
+total_size += descr.size
+op_malloc_gc.setarg(0, ConstInt(total_size))
+op = ResOperation(rop.INT_ADD,
+  [v_last_malloc,
+   ConstInt(previous_size)],
+  op.result)
+previous_size = descr.size
+v_last_malloc = op.result
+newops.append(op)
+# NEW: add a SETFIELD to initialize the GC header
+op = ResOperation(rop.SETFIELD_GC,
+  [op.result, ConstInt(descr.tid)],
+  None, descr=self.fielddescr_tid)
+newops.append(op)
+continue
+op_last_malloc = op
 elif op.can_malloc():
-last_malloc = None
+op_last_malloc = None
 # -- write barrier for SETFIELD_GC --
 if op.getopnum() == rop.SETFIELD_GC:
 val = op.getarg(0)
diff --git a/pypy/jit/backend/llsupport/test/test_gc.py 
b/pypy/jit/backend/llsupport/test/test_gc.py
--- a/pypy/jit/backend/llsupport/test/test_gc.py
+++ b/pypy/jit/backend/llsupport/test/test_gc.py
@@ -570,6 +570,68 @@
 assert operations[1].getarg(2) == v_value
 assert operations[1].getdescr() == array_descr
 
+def test_rewrite_assembler_new_to_malloc(self):
+self.gc_ll_descr.translate_support_code = False
+try:
+S = lltype.GcStruct('S', ('x', lltype.Signed))
+sdescr = get_size_descr(self.gc_ll_descr, S)
+sdescr.tid = 1234
+finally:
+self.gc_ll_descr.translate_support_code = True
+tiddescr = self.gc_ll_descr.fielddescr_tid
+ops = parse("""
+[p1]
+p0 = new(descr=sdescr)
+jump()
+""", namespace=locals())
+expected = parse("""
+[p1]
+p0 = malloc_gc(%d)
+setfield_gc(p0, 1234, descr=tiddescr)
+jump()
+""" % (sdescr.size,), namespace=locals())
+operations = get_deep_immutable_oplist(ops.operations)
+operations = self.gc_ll_descr.rewrite_assembler(self.fake_cpu,
+operations, [])
+equaloplists(operations, expected.operations)
+
+def test_rewrite_assembler_new3_to

[pypy-commit] pypy op_malloc_gc: In-progress.

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: op_malloc_gc
Changeset: r49509:40d91227555d
Date: 2011-11-17 17:30 +0100
http://bitbucket.org/pypy/pypy/changeset/40d91227555d/

Log:In-progress.

diff --git a/pypy/jit/backend/llsupport/descr.py 
b/pypy/jit/backend/llsupport/descr.py
--- a/pypy/jit/backend/llsupport/descr.py
+++ b/pypy/jit/backend/llsupport/descr.py
@@ -19,6 +19,7 @@
 self._cache_size = {}
 self._cache_field = {}
 self._cache_array = {}
+self._cache_arraylen = {}
 self._cache_call = {}
 self._cache_interiorfield = {}
 
@@ -150,6 +151,18 @@
 cachedict[fieldname] = fielddescr
 return fielddescr
 
+def get_field_arraylen_descr(gccache, ARRAY):
+cache = gccache._cache_arraylen
+try:
+return cache[ARRAY]
+except KeyError:
+tsc = gccache.translate_support_code
+(_, _, ofs) = symbolic.get_array_token(ARRAY, tsc)
+SignedFieldDescr = getFieldDescrClass(lltype.Signed)
+result = SignedFieldDescr("len", ofs)
+cache[ARRAY] = result
+return result
+
 # 
 # ArrayDescrs
 
@@ -270,6 +283,8 @@
 else:
 assert isinstance(ARRAY, lltype.GcArray)
 arraydescr = getArrayDescrClass(ARRAY)()
+arraydescr.field_arraylen_descr = get_field_arraylen_descr(
+gccache, ARRAY)
 # verify basic assumption that all arrays' basesize and ofslength
 # are equal
 basesize, itemsize, ofslength = symbolic.get_array_token(ARRAY, False)
diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -17,6 +17,7 @@
 from pypy.jit.backend.llsupport.descr import GcCache, get_field_descr
 from pypy.jit.backend.llsupport.descr import GcPtrFieldDescr
 from pypy.jit.backend.llsupport.descr import get_call_descr
+from pypy.jit.backend.llsupport.descr import get_field_arraylen_descr
 from pypy.rpython.memory.gctransform import asmgcroot
 
 # 
@@ -34,8 +35,6 @@
 pass
 def do_write_barrier(self, gcref_struct, gcref_newptr):
 pass
-def rewrite_assembler(self, cpu, operations, gcrefs_output_list):
-return operations
 def can_inline_malloc(self, descr):
 return False
 def can_inline_malloc_varsize(self, descr, num_elem):
@@ -61,6 +60,13 @@
 rgc._make_sure_does_not_move(p)
 gcrefs_output_list.append(p)
 
+def rewrite_assembler(self, cpu, operations, gcrefs_output_list):
+# record all GCREFs, because the GC (or Boehm) cannot see them and
+# keep them alive if they end up as constants in the assembler
+for op in operations:
+self.record_constptrs(op, gcrefs_output_list)
+return operations
+
 # 
 
 class GcLLDescr_boehm(GcLLDescription):
@@ -178,15 +184,6 @@
 def get_funcptr_for_new(self):
 return self.funcptr_for_new
 
-def rewrite_assembler(self, cpu, operations, gcrefs_output_list):
-# record all GCREFs too, because Boehm cannot see them and keep them
-# alive if they end up as constants in the assembler
-for op in operations:
-self.record_constptrs(op, gcrefs_output_list)
-return GcLLDescription.rewrite_assembler(self, cpu, operations,
- gcrefs_output_list)
-
-
 # 
 # All code below is for the hybrid or minimark GC
 
@@ -800,114 +797,10 @@
 llmemory.cast_ptr_to_adr(gcref_newptr))
 
 def rewrite_assembler(self, cpu, operations, gcrefs_output_list):
-# Perform two kinds of rewrites in parallel:
-#
-# - Add COND_CALLs to the write barrier before SETFIELD_GC and
-#   SETARRAYITEM_GC operations.
-#
-# - Record the ConstPtrs from the assembler.
-#
-newops = []
-known_lengths = {}
-# we can only remember one malloc since the next malloc can possibly
-# collect; but we can try to collapse several known-size mallocs into
-# one, both for performance and to reduce the number of write
-# barriers.  We do this on each "basic block" of operations, which in
-# this case means between CALLs or unknown-size mallocs.
-op_malloc_gc = None
-v_last_malloc = None
-previous_size = -1
-current_mallocs = {}
-#
-for op in operations:
-if op.getopnum() == rop.DEBUG_MERGE_POINT:
-continue
-# -- record the ConstPtrs --
-self.record_constptrs(op, gcrefs_output_list)
-# -- fold the NEWxxx operations into MALLOC_GC --
-if op.is_malloc()

[pypy-commit] pypy op_malloc_gc: Clean up the tests.

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: op_malloc_gc
Changeset: r49511:b5fdf3f1574e
Date: 2011-11-17 17:59 +0100
http://bitbucket.org/pypy/pypy/changeset/b5fdf3f1574e/

Log:Clean up the tests.

diff --git a/pypy/jit/backend/llsupport/test/test_gc.py 
b/pypy/jit/backend/llsupport/test/test_gc.py
--- a/pypy/jit/backend/llsupport/test/test_gc.py
+++ b/pypy/jit/backend/llsupport/test/test_gc.py
@@ -547,95 +547,96 @@
 assert operations[1].getarg(2) == v_value
 assert operations[1].getdescr() == array_descr
 
-def test_rewrite_assembler_new_to_malloc(self):
+def check_rewrite(self, frm_operations, to_operations):
 self.gc_ll_descr.translate_support_code = False
 try:
 S = lltype.GcStruct('S', ('x', lltype.Signed))
 sdescr = get_size_descr(self.gc_ll_descr, S)
 sdescr.tid = 1234
-finally:
-self.gc_ll_descr.translate_support_code = True
-tiddescr = self.gc_ll_descr.fielddescr_tid
-ops = parse("""
-[p1]
-p0 = new(descr=sdescr)
-jump()
-""", namespace=locals())
-expected = parse("""
-[p1]
-p0 = malloc_gc(%d)
-setfield_gc(p0, 1234, descr=tiddescr)
-jump()
-""" % (sdescr.size,), namespace=locals())
-operations = get_deep_immutable_oplist(ops.operations)
-operations = self.gc_ll_descr.rewrite_assembler(self.fake_cpu,
-operations, [])
-equaloplists(operations, expected.operations)
-
-def test_rewrite_assembler_new3_to_malloc(self):
-self.gc_ll_descr.translate_support_code = False
-try:
-S = lltype.GcStruct('S', ('x', lltype.Signed))
-sdescr = get_size_descr(self.gc_ll_descr, S)
-sdescr.tid = 1234
+#
 T = lltype.GcStruct('T', ('y', lltype.Signed),
  ('z', lltype.Signed))
 tdescr = get_size_descr(self.gc_ll_descr, T)
 tdescr.tid = 5678
+#
+A = lltype.GcArray(lltype.Signed)
+adescr = get_array_descr(self.gc_ll_descr, A)
+adescr.tid = 4321
+alendescr = get_field_arraylen_descr(self.gc_ll_descr, A)
+#
+tiddescr = self.gc_ll_descr.fielddescr_tid
+#
+ops = parse(frm_operations, namespace=locals())
+expected = parse(to_operations % Evaluator(locals()),
+ namespace=locals())
+operations = get_deep_immutable_oplist(ops.operations)
+operations = self.gc_ll_descr.rewrite_assembler(self.fake_cpu,
+operations, [])
 finally:
 self.gc_ll_descr.translate_support_code = True
-tiddescr = self.gc_ll_descr.fielddescr_tid
-ops = parse("""
-[]
-p0 = new(descr=sdescr)
-p1 = new(descr=tdescr)
-p2 = new(descr=sdescr)
-jump()
-""", namespace=locals())
-expected = parse("""
-[]
-p0 = malloc_gc(%d)
-setfield_gc(p0, 1234, descr=tiddescr)
-p1 = int_add(p0, %d)
-setfield_gc(p1, 5678, descr=tiddescr)
-p2 = int_add(p1, %d)
-setfield_gc(p2, 1234, descr=tiddescr)
-jump()
-""" % (sdescr.size + tdescr.size + sdescr.size,
-   sdescr.size,
-   tdescr.size), namespace=locals())
-operations = get_deep_immutable_oplist(ops.operations)
-operations = self.gc_ll_descr.rewrite_assembler(self.fake_cpu,
-operations, [])
 equaloplists(operations, expected.operations)
 
+def test_rewrite_assembler_new_to_malloc(self):
+self.check_rewrite("""
+[p1]
+p0 = new(descr=sdescr)
+jump()
+""", """
+[p1]
+p0 = malloc_gc(%(sdescr.size)d)
+setfield_gc(p0, 1234, descr=tiddescr)
+jump()
+""")
+
+def test_rewrite_assembler_new3_to_malloc(self):
+self.check_rewrite("""
+[]
+p0 = new(descr=sdescr)
+p1 = new(descr=tdescr)
+p2 = new(descr=sdescr)
+jump()
+""", """
+[]
+p0 = malloc_gc(%(sdescr.size + tdescr.size + sdescr.size)d)
+setfield_gc(p0, 1234, descr=tiddescr)
+p1 = int_add(p0, %(sdescr.size)d)
+setfield_gc(p1, 5678, descr=tiddescr)
+p2 = int_add(p1, %(tdescr.size)d)
+setfield_gc(p2, 1234, descr=tiddescr)
+jump()
+""")
+
 def test_rewrite_assembler_new_array_fixed_to_malloc(self):
-self.gc_ll_descr.translate_support_code = False
-try:
-A = lltype.GcArray(lltype.Signed)
-adescr = get_array_descr(self.gc_ll_descr, A)
-adescr.tid = 1234
-

[pypy-commit] pypy op_malloc_gc: Fix some tests.

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: op_malloc_gc
Changeset: r49510:8b49822025c6
Date: 2011-11-17 17:40 +0100
http://bitbucket.org/pypy/pypy/changeset/8b49822025c6/

Log:Fix some tests.

diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -839,22 +839,24 @@
 # - Add COND_CALLs to the write barrier before SETFIELD_GC and
 #   SETARRAYITEM_GC operations.
 
+_v_last_malloc = None
+_previous_size = -1
+
 def __init__(self, gc_ll_descr, cpu):
 self.gc_ll_descr = gc_ll_descr
 self.cpu = cpu
 self.tsc = self.gc_ll_descr.translate_support_code
+self.newops = []
+self.known_lengths = {}
+self.op_malloc_gc = None
+self.current_mallocs = {} # set of variables
 
 def rewrite(self, operations):
-self.newops = []
-self.known_lengths = {}
 # we can only remember one malloc since the next malloc can possibly
 # collect; but we can try to collapse several known-size mallocs into
 # one, both for performance and to reduce the number of write
 # barriers.  We do this on each "basic block" of operations, which in
 # this case means between CALLs or unknown-size mallocs.
-self.op_malloc_gc = None
-self.v_last_malloc = None
-self.previous_size = -1
 #
 for op in operations:
 if op.getopnum() == rop.DEBUG_MERGE_POINT:
@@ -885,11 +887,12 @@
 
 elif op.can_malloc():
 self.op_malloc_gc = None
+self.current_mallocs.clear()
 # -- write barrier for SETFIELD_GC --
 if op.getopnum() == rop.SETFIELD_GC:
 val = op.getarg(0)
 # no need for a write barrier in the case of previous malloc
-if val is not last_malloc:
+if val not in self.current_mallocs:
 v = op.getarg(1)
 if isinstance(v, BoxPtr) or (isinstance(v, ConstPtr) and
 bool(v.value)): # store a non-NULL
@@ -899,7 +902,7 @@
 if op.getopnum() == rop.SETARRAYITEM_GC:
 val = op.getarg(0)
 # no need for a write barrier in the case of previous malloc
-if val is not last_malloc:
+if val not in self.current_mallocs:
 v = op.getarg(2)
 if isinstance(v, BoxPtr) or (isinstance(v, ConstPtr) and
 bool(v.value)): # store a non-NULL
@@ -923,11 +926,12 @@
 total_size += size
 self.op_malloc_gc.setarg(0, ConstInt(total_size))
 op = ResOperation(rop.INT_ADD,
-  [self.v_last_malloc,
-   ConstInt(self.previous_size)],
+  [self._v_last_malloc,
+   ConstInt(self._previous_size)],
   v_result)
-self.previous_size = size
-self.v_last_malloc = v_result
+self._previous_size = size
+self._v_last_malloc = v_result
+self.current_mallocs[v_result] = None
 self.newops.append(op)
 
 def gen_initialize_tid(self, v_newgcobj, tid):
@@ -945,9 +949,10 @@
 self.newops.append(op)
 
 def gen_write_barrier(self, v_base, v_value):
+write_barrier_descr = self.gc_ll_descr.write_barrier_descr
 args = [v_base, v_value]
 self.newops.append(ResOperation(rop.COND_CALL_GC_WB, args, None,
-descr=self.write_barrier_descr))
+descr=write_barrier_descr))
 
 def gen_write_barrier_array(self, v_base, v_index, v_value):
 write_barrier_descr = self.gc_ll_descr.write_barrier_descr
diff --git a/pypy/jit/backend/llsupport/test/test_gc.py 
b/pypy/jit/backend/llsupport/test/test_gc.py
--- a/pypy/jit/backend/llsupport/test/test_gc.py
+++ b/pypy/jit/backend/llsupport/test/test_gc.py
@@ -404,10 +404,11 @@
 gc_ll_descr = self.gc_ll_descr
 llop1 = self.llop1
 #
-newops = []
+rewriter = GcRewriterAssembler(gc_ll_descr, None)
+newops = rewriter.newops
 v_base = BoxPtr()
 v_value = BoxPtr()
-gc_ll_descr._gen_write_barrier(newops, v_base, v_value)
+rewriter.gen_write_barrier(v_base, v_value)
 assert llop1.record == []
 assert len(newops) == 1
 assert newops[0].getopnum() == rop.COND_CALL_GC_WB
@@ -482,7 +483,7 @@
 
 def test_rewrite_assembler_3(self):
 # check write barriers before SETARRAYITEM_GC
-for v_new_length in (None, ConstInt(5), ConstInt(5000), BoxInt()):
+for new_length in (-1, 5, 5000):
 v_base = BoxPtr()
 v_index = BoxInt()
 v_value =

[pypy-commit] pypy op_malloc_gc: Missing rounding up: tests and fix.

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: op_malloc_gc
Changeset: r49512:c4bcb5c2b12f
Date: 2011-11-17 18:11 +0100
http://bitbucket.org/pypy/pypy/changeset/c4bcb5c2b12f/

Log:Missing rounding up: tests and fix.

diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -4,7 +4,7 @@
 from pypy.rlib.debug import fatalerror
 from pypy.rlib.rarithmetic import ovfcheck
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi, rclass, rstr
-from pypy.rpython.lltypesystem import llgroup
+from pypy.rpython.lltypesystem import llgroup, llarena
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.annlowlevel import llhelper
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
@@ -879,6 +879,7 @@
 basesize = descr.get_base_size(self.tsc)
 itemsize = descr.get_item_size(self.tsc)
 fullsize = basesize + newlength * itemsize
+fullsize = self.round_up_for_allocation(fullsize)
 self.gen_malloc_const(fullsize, op.result)
 self.gen_initialize_tid(op.result, descr.tid)
 self.gen_initialize_len(op.result, v_newlength, descr)
@@ -972,6 +973,16 @@
 # fall-back case: produce a write_barrier
 self.gen_write_barrier(v_base, v_value)
 
+def round_up_for_allocation(self, size):
+if self.tsc:
+return llarena.round_up_for_allocation(
+size, self.gc_ll_descr.minimal_size_in_nursery)
+else:
+# non-translated: do it manually
+# assume that "self.gc_ll_descr.minimal_size_in_nursery" is 2 WORDs
+size = max(size, 2 * WORD)
+return (size + WORD-1) & ~(WORD-1) # round up
+
 # 
 
 def get_ll_description(gcdescr, translator=None, rtyper=None):
diff --git a/pypy/jit/backend/llsupport/test/test_gc.py 
b/pypy/jit/backend/llsupport/test/test_gc.py
--- a/pypy/jit/backend/llsupport/test/test_gc.py
+++ b/pypy/jit/backend/llsupport/test/test_gc.py
@@ -564,6 +564,11 @@
 adescr.tid = 4321
 alendescr = get_field_arraylen_descr(self.gc_ll_descr, A)
 #
+B = lltype.GcArray(lltype.Char)
+bdescr = get_array_descr(self.gc_ll_descr, B)
+bdescr.tid = 8765
+blendescr = get_field_arraylen_descr(self.gc_ll_descr, B)
+#
 tiddescr = self.gc_ll_descr.fielddescr_tid
 #
 ops = parse(frm_operations, namespace=locals())
@@ -638,6 +643,44 @@
 jump()
 """)
 
+def test_rewrite_assembler_round_up(self):
+self.check_rewrite("""
+[]
+p0 = new_array(6, descr=bdescr)
+jump()
+""", """
+[]
+p0 = malloc_gc(%(adescr.get_base_size(False) + 8)d)
+setfield_gc(p0, 8765, descr=tiddescr)
+setfield_gc(p0, 6, descr=blendescr)
+jump()
+""")
+
+def test_rewrite_assembler_round_up_always(self):
+self.check_rewrite("""
+[]
+p0 = new_array(5, descr=bdescr)
+p1 = new_array(5, descr=bdescr)
+p2 = new_array(5, descr=bdescr)
+p3 = new_array(5, descr=bdescr)
+jump()
+""", """
+[]
+p0 = malloc_gc(%(4 * (adescr.get_base_size(False) + 8))d)
+setfield_gc(p0, 8765, descr=tiddescr)
+setfield_gc(p0, 5, descr=blendescr)
+p1 = int_add(p0, %(adescr.get_base_size(False) + 8)d)
+setfield_gc(p1, 8765, descr=tiddescr)
+setfield_gc(p1, 5, descr=blendescr)
+p2 = int_add(p1, %(adescr.get_base_size(False) + 8)d)
+setfield_gc(p2, 8765, descr=tiddescr)
+setfield_gc(p2, 5, descr=blendescr)
+p3 = int_add(p2, %(adescr.get_base_size(False) + 8)d)
+setfield_gc(p3, 8765, descr=tiddescr)
+setfield_gc(p3, 5, descr=blendescr)
+jump()
+""")
+
 def test_rewrite_assembler_initialization_store(self):
 S = lltype.GcStruct('S', ('parent', OBJECT),
 ('x', lltype.Signed))
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy op_malloc_gc: Test and fix for allocating tiny structures --- they are smaller

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: op_malloc_gc
Changeset: r49513:454b0eb8af85
Date: 2011-11-17 18:15 +0100
http://bitbucket.org/pypy/pypy/changeset/454b0eb8af85/

Log:Test and fix for allocating tiny structures --- they are smaller
than the minimal_size_in_nursery.

diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -879,7 +879,6 @@
 basesize = descr.get_base_size(self.tsc)
 itemsize = descr.get_item_size(self.tsc)
 fullsize = basesize + newlength * itemsize
-fullsize = self.round_up_for_allocation(fullsize)
 self.gen_malloc_const(fullsize, op.result)
 self.gen_initialize_tid(op.result, descr.tid)
 self.gen_initialize_len(op.result, v_newlength, descr)
@@ -915,6 +914,7 @@
 return self.newops
 
 def gen_malloc_const(self, size, v_result):
+size = self.round_up_for_allocation(size)
 if self.op_malloc_gc is None:
 # it is the first we see: emit MALLOC_GC
 op = ResOperation(rop.MALLOC_GC,
diff --git a/pypy/jit/backend/llsupport/test/test_gc.py 
b/pypy/jit/backend/llsupport/test/test_gc.py
--- a/pypy/jit/backend/llsupport/test/test_gc.py
+++ b/pypy/jit/backend/llsupport/test/test_gc.py
@@ -550,12 +550,14 @@
 def check_rewrite(self, frm_operations, to_operations):
 self.gc_ll_descr.translate_support_code = False
 try:
-S = lltype.GcStruct('S', ('x', lltype.Signed))
+S = lltype.GcStruct('S', ('x', lltype.Signed),
+ ('y', lltype.Signed))
 sdescr = get_size_descr(self.gc_ll_descr, S)
 sdescr.tid = 1234
 #
 T = lltype.GcStruct('T', ('y', lltype.Signed),
- ('z', lltype.Signed))
+ ('z', lltype.Signed),
+ ('t', lltype.Signed))
 tdescr = get_size_descr(self.gc_ll_descr, T)
 tdescr.tid = 5678
 #
@@ -569,7 +571,12 @@
 bdescr.tid = 8765
 blendescr = get_field_arraylen_descr(self.gc_ll_descr, B)
 #
+E = lltype.GcStruct('Empty')
+edescr = get_size_descr(self.gc_ll_descr, E)
+edescr.tid = 9000
+#
 tiddescr = self.gc_ll_descr.fielddescr_tid
+WORD = globals()['WORD']
 #
 ops = parse(frm_operations, namespace=locals())
 expected = parse(to_operations % Evaluator(locals()),
@@ -681,6 +688,21 @@
 jump()
 """)
 
+def test_rewrite_assembler_minimal_size(self):
+self.check_rewrite("""
+[]
+p0 = new(descr=edescr)
+p1 = new(descr=edescr)
+jump()
+""", """
+[]
+p0 = malloc_gc(%(4*WORD)d)
+setfield_gc(p0, 9000, descr=tiddescr)
+p1 = int_add(p0, %(2*WORD)d)
+setfield_gc(p1, 9000, descr=tiddescr)
+jump()
+""")
+
 def test_rewrite_assembler_initialization_store(self):
 S = lltype.GcStruct('S', ('parent', OBJECT),
 ('x', lltype.Signed))
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy op_malloc_gc: Kill unused attribute.

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: op_malloc_gc
Changeset: r49514:cf80cbdf1c65
Date: 2011-11-18 10:09 +0100
http://bitbucket.org/pypy/pypy/changeset/cf80cbdf1c65/

Log:Kill unused attribute.

diff --git a/pypy/jit/backend/llsupport/descr.py 
b/pypy/jit/backend/llsupport/descr.py
--- a/pypy/jit/backend/llsupport/descr.py
+++ b/pypy/jit/backend/llsupport/descr.py
@@ -43,8 +43,6 @@
 
 class SizeDescr(AbstractDescr):
 size = 0  # help translation
-is_immutable = False
-
 tid = llop.combine_ushort(lltype.Signed, 0, 0)
 
 def __init__(self, size, count_fields_if_immut=-1):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: rename numpy -> numpypy

2011-11-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r49515:f732c0996244
Date: 2011-11-18 11:26 +0200
http://bitbucket.org/pypy/pypy/changeset/f732c0996244/

Log:rename numpy -> numpypy

diff --git a/pypy/module/micronumpy/__init__.py 
b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -2,7 +2,7 @@
 
 
 class Module(MixedModule):
-applevel_name = 'numpy'
+applevel_name = 'numpypy'
 
 interpleveldefs = {
 'array': 'interp_numarray.SingleDimArray',
diff --git a/pypy/module/micronumpy/app_numpy.py 
b/pypy/module/micronumpy/app_numpy.py
--- a/pypy/module/micronumpy/app_numpy.py
+++ b/pypy/module/micronumpy/app_numpy.py
@@ -1,6 +1,6 @@
 import math
 
-import numpy
+import numpypy
 
 
 inf = float("inf")
@@ -13,5 +13,5 @@
 
 def mean(a):
 if not hasattr(a, "mean"):
-a = numpy.array(a)
+a = numpypy.array(a)
 return a.mean()
diff --git a/pypy/module/micronumpy/bench/add.py 
b/pypy/module/micronumpy/bench/add.py
--- a/pypy/module/micronumpy/bench/add.py
+++ b/pypy/module/micronumpy/bench/add.py
@@ -1,5 +1,8 @@
 
-import numpy
+try:
+import numpypy as numpy
+except:
+import numpy
 
 def f():
 a = numpy.zeros(1000)
diff --git a/pypy/module/micronumpy/bench/iterate.py 
b/pypy/module/micronumpy/bench/iterate.py
--- a/pypy/module/micronumpy/bench/iterate.py
+++ b/pypy/module/micronumpy/bench/iterate.py
@@ -1,5 +1,8 @@
 
-import numpy
+try:
+import numpypy as numpy
+except:
+import numpy
 
 def f():
 sum = 0
diff --git a/pypy/module/micronumpy/test/test_dtypes.py 
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -3,7 +3,7 @@
 
 class AppTestDtypes(BaseNumpyAppTest):
 def test_dtype(self):
-from numpy import dtype
+from numpypy import dtype
 
 d = dtype('?')
 assert d.num == 0
@@ -14,7 +14,7 @@
 raises(TypeError, dtype, 1042)
 
 def test_dtype_with_types(self):
-from numpy import dtype
+from numpypy import dtype
 
 assert dtype(bool).num == 0
 assert dtype(int).num == 7
@@ -22,13 +22,13 @@
 assert dtype(float).num == 12
 
 def test_array_dtype_attr(self):
-from numpy import array, dtype
+from numpypy import array, dtype
 
 a = array(range(5), long)
 assert a.dtype is dtype(long)
 
 def test_repr_str(self):
-from numpy import dtype
+from numpypy import dtype
 
 assert repr(dtype) == ""
 d = dtype('?')
@@ -36,57 +36,57 @@
 assert str(d) == "bool"
 
 def test_bool_array(self):
-import numpy
+from numpypy import array, False_, True_
 
-a = numpy.array([0, 1, 2, 2.5], dtype='?')
-assert a[0] is numpy.False_
+a = array([0, 1, 2, 2.5], dtype='?')
+assert a[0] is False_
 for i in xrange(1, 4):
-assert a[i] is numpy.True_
+assert a[i] is True_
 
 def test_copy_array_with_dtype(self):
-import numpy
+from numpypy import array, False_, True_
 
-a = numpy.array([0, 1, 2, 3], dtype=long)
+a = array([0, 1, 2, 3], dtype=long)
 # int on 64-bit, long in 32-bit
 assert isinstance(a[0], (int, long))
 b = a.copy()
 assert isinstance(b[0], (int, long))
 
-a = numpy.array([0, 1, 2, 3], dtype=bool)
-assert a[0] is numpy.False_
+a = array([0, 1, 2, 3], dtype=bool)
+assert a[0] is False_
 b = a.copy()
-assert b[0] is numpy.False_
+assert b[0] is False_
 
 def test_zeros_bool(self):
-import numpy
+from numpypy import zeros, False_
 
-a = numpy.zeros(10, dtype=bool)
+a = zeros(10, dtype=bool)
 for i in range(10):
-assert a[i] is numpy.False_
+assert a[i] is False_
 
 def test_ones_bool(self):
-import numpy
+from numpypy import ones, True_
 
-a = numpy.ones(10, dtype=bool)
+a = ones(10, dtype=bool)
 for i in range(10):
-assert a[i] is numpy.True_
+assert a[i] is True_
 
 def test_zeros_long(self):
-from numpy import zeros
+from numpypy import zeros
 a = zeros(10, dtype=long)
 for i in range(10):
 assert isinstance(a[i], (int, long))
 assert a[1] == 0
 
 def test_ones_long(self):
-from numpy import ones
+from numpypy import ones
 a = ones(10, dtype=long)
 for i in range(10):
 assert isinstance(a[i], (int, long))
 assert a[1] == 1
 
 def test_overflow(self):
-from numpy import array, dtype
+from numpypy import array, dtype
 assert array([128], 'b')[0] == -128
 assert array([256], 'B')[0] == 0
 assert array([32768], 'h')[0] == -32768
@@ -98,7 +98,7 @@

[pypy-commit] pypy jitdriver-setparam-all: Re-add an assert that was lost.

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: jitdriver-setparam-all
Changeset: r49516:73172e1ee46c
Date: 2011-11-18 10:43 +0100
http://bitbucket.org/pypy/pypy/changeset/73172e1ee46c/

Log:Re-add an assert that was lost.

diff --git a/pypy/jit/metainterp/warmspot.py b/pypy/jit/metainterp/warmspot.py
--- a/pypy/jit/metainterp/warmspot.py
+++ b/pypy/jit/metainterp/warmspot.py
@@ -873,6 +873,8 @@
 for jd in self.jitdrivers_sd:
 if jd.jitdriver is op.args[1].value:
 break
+else:
+assert 0, "jitdriver of set_param() not found"
 else:
 jd = None
 funcname = op.args[2].value
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jitdriver-setparam-all: close about to be merged branch

2011-11-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: jitdriver-setparam-all
Changeset: r49517:310e106460c0
Date: 2011-11-18 11:50 +0200
http://bitbucket.org/pypy/pypy/changeset/310e106460c0/

Log:close about to be merged branch

___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Merge jitdriver-setparam-all branch that allows setting parameters to all

2011-11-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r49518:42d55fa4ac69
Date: 2011-11-18 11:50 +0200
http://bitbucket.org/pypy/pypy/changeset/42d55fa4ac69/

Log:Merge jitdriver-setparam-all branch that allows setting parameters
to all jitdrivers.

diff --git a/pypy/jit/metainterp/test/test_ajit.py 
b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -14,7 +14,7 @@
 from pypy.rlib.jit import (JitDriver, we_are_jitted, hint, dont_look_inside,
 loop_invariant, elidable, promote, jit_debug, assert_green,
 AssertGreenFailed, unroll_safe, current_trace_length, look_inside_iff,
-isconstant, isvirtual, promote_string)
+isconstant, isvirtual, promote_string, set_param)
 from pypy.rlib.rarithmetic import ovfcheck
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.rpython.ootypesystem import ootype
@@ -1256,15 +1256,18 @@
 n -= 1
 x += n
 return x
-def f(n, threshold):
-myjitdriver.set_param('threshold', threshold)
+def f(n, threshold, arg):
+if arg:
+set_param(myjitdriver, 'threshold', threshold)
+else:
+set_param(None, 'threshold', threshold)
 return g(n)
 
-res = self.meta_interp(f, [10, 3])
+res = self.meta_interp(f, [10, 3, 1])
 assert res == 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 0
 self.check_tree_loop_count(2)
 
-res = self.meta_interp(f, [10, 13])
+res = self.meta_interp(f, [10, 13, 0])
 assert res == 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 0
 self.check_tree_loop_count(0)
 
@@ -2328,8 +2331,8 @@
 get_printable_location=get_printable_location)
 bytecode = "0j10jc20a3"
 def f():
-myjitdriver.set_param('threshold', 7)
-myjitdriver.set_param('trace_eagerness', 1)
+set_param(myjitdriver, 'threshold', 7)
+set_param(myjitdriver, 'trace_eagerness', 1)
 i = j = c = a = 1
 while True:
 myjitdriver.jit_merge_point(i=i, j=j, c=c, a=a)
@@ -2607,7 +2610,7 @@
 myjitdriver = JitDriver(greens = [], reds = ['n', 'i', 'sa', 'a'])
 
 def f(n, limit):
-myjitdriver.set_param('retrace_limit', limit)
+set_param(myjitdriver, 'retrace_limit', limit)
 sa = i = a = 0
 while i < n:
 myjitdriver.jit_merge_point(n=n, i=i, sa=sa, a=a)
@@ -2625,8 +2628,8 @@
 myjitdriver = JitDriver(greens = [], reds = ['n', 'i', 'sa', 'a'])
 
 def f(n, limit):
-myjitdriver.set_param('retrace_limit', 3)
-myjitdriver.set_param('max_retrace_guards', limit)
+set_param(myjitdriver, 'retrace_limit', 3)
+set_param(myjitdriver, 'max_retrace_guards', limit)
 sa = i = a = 0
 while i < n:
 myjitdriver.jit_merge_point(n=n, i=i, sa=sa, a=a)
@@ -2645,7 +2648,7 @@
 myjitdriver = JitDriver(greens = [], reds = ['n', 'i', 'sa', 'a',
  'node'])
 def f(n, limit):
-myjitdriver.set_param('retrace_limit', limit)
+set_param(myjitdriver, 'retrace_limit', limit)
 sa = i = a = 0
 node = [1, 2, 3]
 node[1] = n
@@ -2668,10 +2671,10 @@
 myjitdriver = JitDriver(greens = ['pc'], reds = ['n', 'i', 'sa'])
 bytecode = "0+sI0+SI"
 def f(n):
-myjitdriver.set_param('threshold', 3)
-myjitdriver.set_param('trace_eagerness', 1)
-myjitdriver.set_param('retrace_limit', 5)
-myjitdriver.set_param('function_threshold', -1)
+set_param(None, 'threshold', 3)
+set_param(None, 'trace_eagerness', 1)
+set_param(None, 'retrace_limit', 5)
+set_param(None, 'function_threshold', -1)
 pc = sa = i = 0
 while pc < len(bytecode):
 myjitdriver.jit_merge_point(pc=pc, n=n, sa=sa, i=i)
@@ -2728,9 +2731,9 @@
 myjitdriver = JitDriver(greens = ['pc'], reds = ['n', 'a', 'i', 'j', 
'sa'])
 bytecode = "ij+Jj+JI"
 def f(n, a):
-myjitdriver.set_param('threshold', 5)
-myjitdriver.set_param('trace_eagerness', 1)
-myjitdriver.set_param('retrace_limit', 2)
+set_param(None, 'threshold', 5)
+set_param(None, 'trace_eagerness', 1)
+set_param(None, 'retrace_limit', 2)
 pc = sa = i = j = 0
 while pc < len(bytecode):
 myjitdriver.jit_merge_point(pc=pc, n=n, sa=sa, i=i, j=j, a=a)
@@ -2793,8 +2796,8 @@
 return B(self.val + 1)
 myjitdriver = JitDriver(greens = [], reds = ['sa', 'a'])
 def f():
-myjitdriver.set_param('threshold', 3)
-myjitdri

[pypy-commit] pypy default: what I remember that goes into the release

2011-11-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r49520:7c06e045a439
Date: 2011-11-18 12:22 +0200
http://bitbucket.org/pypy/pypy/changeset/7c06e045a439/

Log:what I remember that goes into the release

diff --git a/pypy/doc/release-1.7.0.rst b/pypy/doc/release-1.7.0.rst
new file mode 100644
--- /dev/null
+++ b/pypy/doc/release-1.7.0.rst
@@ -0,0 +1,44 @@
+=
+PyPy 1.7
+=
+
+Highlights
+==
+
+* numerous performance improvements, PyPy 1.7 is xxx faster than 1.6
+
+* numerous bugfixes, compatibility fixes
+
+* windows fixes
+
+* stackless and JIT integration
+
+* numpy progress - dtypes, numpy -> numpypy renaming
+
+* brand new JSON encoder
+
+* improved memory footprint on heavy users of C APIs example - tornado
+
+* cpyext progress
+
+Things that didn't make it, expect in 1.8 soon
+==
+
+* list strategies
+
+* multi-dimensional arrays for numpy
+
+* ARM backend
+
+* PPC backend
+
+Things we're working on with unclear ETA
+
+
+* windows 64 (?)
+
+* Py3k
+
+* SSE for numpy
+
+* specialized objects
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy set-strategies: uh? this test is clearly dict order dependent

2011-11-18 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: set-strategies
Changeset: r49521:617ce44795c0
Date: 2011-11-18 13:40 +0100
http://bitbucket.org/pypy/pypy/changeset/617ce44795c0/

Log:uh? this test is clearly dict order dependent

diff --git a/pypy/objspace/std/test/test_setobject.py 
b/pypy/objspace/std/test/test_setobject.py
--- a/pypy/objspace/std/test/test_setobject.py
+++ b/pypy/objspace/std/test/test_setobject.py
@@ -791,11 +791,13 @@
 raises(TypeError, s.discard, set([1]))
 
 def test_create_set_from_set(self):
+# no sharing
 x = set([1,2,3])
 y = set(x)
-x.pop()
-assert x == set([2,3])
+a = x.pop()
 assert y == set([1,2,3])
+assert len(x) == 2
+assert x.union(set([a])) == y
 
 def test_never_change_frozenset(self):
 a = frozenset([1,2])
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy type-specialized-instances: introduced IntAttribute

2011-11-18 Thread l . diekmann
Author: Lukas Diekmann 
Branch: type-specialized-instances
Changeset: r49522:b16fead0c3f3
Date: 2011-11-16 18:24 +0100
http://bitbucket.org/pypy/pypy/changeset/b16fead0c3f3/

Log:introduced IntAttribute

diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -125,15 +125,15 @@
 return None
 
 @jit.elidable
-def _get_new_attr(self, name, index):
-selector = name, index
+def _get_new_attr(self, name, index, attrclass):
+key = name, index, attrclass
 cache = self.cache_attrs
 if cache is None:
 cache = self.cache_attrs = {}
-attr = cache.get(selector, None)
+attr = cache.get(key, None)
 if attr is None:
-attr = PlainAttribute(selector, self)
-cache[selector] = attr
+attr = attrclass(key, self)
+cache[key] = attr
 return attr
 
 @jit.look_inside_iff(lambda self, obj, selector, w_value:
@@ -141,8 +141,9 @@
 jit.isconstant(selector[0]) and
 jit.isconstant(selector[1]))
 def add_attr(self, obj, selector, w_value):
+attrclass = get_attrclass_from_value(self.space, w_value)
 # grumble, jit needs this
-attr = self._get_new_attr(selector[0], selector[1])
+attr = self._get_new_attr(selector[0], selector[1], attrclass)
 oldattr = obj._get_mapdict_map()
 if not jit.we_are_jitted():
 size_est = (oldattr._size_estimate + attr.size_estimate()
@@ -264,8 +265,10 @@
 terminator = terminator.devolved_dict_terminator
 return Terminator.set_terminator(self, obj, terminator)
 
-class PlainAttribute(AbstractAttribute):
+class AbstractStoredAttribute(AbstractAttribute):
+
 _immutable_fields_ = ['selector', 'position', 'back']
+
 def __init__(self, selector, back):
 AbstractAttribute.__init__(self, back.space, back.terminator)
 self.selector = selector
@@ -277,17 +280,6 @@
 w_value = self.read(obj, self.selector)
 new_obj._get_mapdict_map().add_attr(new_obj, self.selector, w_value)
 
-def read_attr(self, obj):
-# XXX do the unerasing (and wrapping) here
-erased = obj._mapdict_read_storage(self.position)
-w_value = unerase_item(erased)
-return w_value
-
-def write_attr(self, obj, w_value):
-# XXX do the unerasing (and unwrapping) here
-erased = erase_item(w_value)
-obj._mapdict_write_storage(self.position, erased)
-
 def delete(self, obj, selector):
 if selector == self.selector:
 # ok, attribute is deleted
@@ -333,6 +325,41 @@
 def __repr__(self):
 return "" % (self.selector, self.position, 
self.back)
 
+class PlainAttribute(AbstractStoredAttribute):
+
+erase_item, unerase_item = rerased.new_erasing_pair("mapdict storage 
object item")
+erase_item = staticmethod(erase_item)
+unerase_item = staticmethod(unerase_item)
+
+def read_attr(self, obj):
+erased = obj._mapdict_read_storage(self.position)
+w_value = self.unerase_item(erased)
+return w_value
+
+def write_attr(self, obj, w_value):
+erased = self.erase_item(w_value)
+obj._mapdict_write_storage(self.position, erased)
+
+class IntAttribute(AbstractStoredAttribute):
+
+erase_item, unerase_item = rerased.erase_int, rerased.unerase_int
+erase_item = staticmethod(erase_item)
+unerase_item = staticmethod(unerase_item)
+
+def read_attr(self, obj):
+erased = obj._mapdict_read_storage(self.position)
+value = self.unerase_item(erased)
+return self.space.wrap(value)
+
+def write_attr(self, obj, w_value):
+erased = self.erase_item(self.space.int_w(w_value))
+obj._mapdict_write_storage(self.position, erased)
+
+def get_attrclass_from_value(space, w_value):
+if space.is_w(space.type(w_value), space.w_int):
+return IntAttribute
+return PlainAttribute
+
 def _become(w_obj, new_obj):
 # this is like the _become method, really, but we cannot use that due to
 # RPython reasons
@@ -524,7 +551,6 @@
 memo_get_subclass_of_correct_size._annspecialcase_ = "specialize:memo"
 _subclass_cache = {}
 
-erase_item, unerase_item = rerased.new_erasing_pair("mapdict storage item")
 erase_list, unerase_list = rerased.new_erasing_pair("mapdict storage list")
 
 def _make_subclass_size_n(supercls, n):
diff --git a/pypy/objspace/std/test/test_mapdict.py 
b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -5,12 +5,14 @@
 space = FakeSpace()
 
 class Class(object):
-def __init__(self, hasdict=True):
+def __init__(self, hasdict=True, sp=None):
 self.hasdict = True
+if sp is None:
+sp = space
 if hasdict:
-self.terminator = DictTerminator(space, self)
+ 

[pypy-commit] pypy type-specialized-instances: fix: former PlainAttribute is now AbstractStoredAttribute

2011-11-18 Thread l . diekmann
Author: Lukas Diekmann 
Branch: type-specialized-instances
Changeset: r49524:51f420b3af95
Date: 2011-11-16 20:40 +0100
http://bitbucket.org/pypy/pypy/changeset/51f420b3af95/

Log:fix: former PlainAttribute is now AbstractStoredAttribute

diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -99,7 +99,7 @@
 return attr
 
 def _findmap(self, selector):
-while isinstance(self, PlainAttribute):
+while isinstance(self, AbstractStoredAttribute):
 if selector == self.selector:
 return self
 self = self.back
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy type-specialized-instances: removed some old prints

2011-11-18 Thread l . diekmann
Author: Lukas Diekmann 
Branch: type-specialized-instances
Changeset: r49523:26d4cedd131b
Date: 2011-11-16 20:39 +0100
http://bitbucket.org/pypy/pypy/changeset/26d4cedd131b/

Log:removed some old prints

diff --git a/pypy/objspace/std/test/test_mapdict.py 
b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -311,12 +311,12 @@
 cls = Class(sp=space)
 obj1 = cls.instantiate()
 obj1.setdictvalue(space, "x", space.wrap(1))
-#assert space.eq_w(obj1.getdictvalue(space, "x"), space.wrap(1))
+assert space.eq_w(obj1.getdictvalue(space, "x"), space.wrap(1))
 
 obj2 = cls.instantiate()
 w_str = space.wrap("string")
 obj2.setdictvalue(space, "x", w_str)
-#assert space.eq_w(obj1.getdictvalue(space, "x"), w_str)
+assert space.eq_w(obj2.getdictvalue(space, "x"), w_str)
 
 assert obj1.map is not obj2.map
 assert isinstance(obj1.map, IntAttribute)
@@ -501,9 +501,7 @@
 a.x = 42
 
 assert a.x == 42
-print "read once"
 assert a.x == 42
-print "read twice"
 
 def test_simple(self):
 class A(object):
@@ -727,7 +725,6 @@
 INVALID_CACHE_ENTRY.failure_counter = 0
 #
 w_res = space.call_function(w_func)
-print w_res
 assert space.eq_w(w_res, space.wrap(42))
 #
 entry = w_code._mapdict_caches[nameindex]
@@ -758,14 +755,9 @@
 def f():
 return a.x
 #
-print "1"
 assert a.x == 42
-print "2"
 assert a.x == 42
-print "3"
-print "first check"
 res = self.check(f, 'x')
-print "second check"
 assert res == (1, 0, 0)
 res = self.check(f, 'x')
 assert res == (0, 1, 0)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy type-specialized-instances: fixed read with new selector (still not sure if this is the right fix)

2011-11-18 Thread l . diekmann
Author: Lukas Diekmann 
Branch: type-specialized-instances
Changeset: r49525:ca3e806187f6
Date: 2011-11-18 14:41 +0100
http://bitbucket.org/pypy/pypy/changeset/ca3e806187f6/

Log:fixed read with new selector (still not sure if this is the right
fix)

diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -100,7 +100,8 @@
 
 def _findmap(self, selector):
 while isinstance(self, AbstractStoredAttribute):
-if selector == self.selector:
+# XXX is this the right fix?
+if selector == self.selector[:2]:
 return self
 self = self.back
 return None
@@ -277,11 +278,12 @@
 self._size_estimate = self.length() * NUM_DIGITS_POW2
 
 def _copy_attr(self, obj, new_obj):
-w_value = self.read(obj, self.selector)
+#XXX this the right fix?
+w_value = self.read(obj, self.selector[:2])
 new_obj._get_mapdict_map().add_attr(new_obj, self.selector, w_value)
 
 def delete(self, obj, selector):
-if selector == self.selector:
+if selector == self.selector[:2]:
 # ok, attribute is deleted
 return self.back.copy(obj)
 new_obj = self.back.delete(obj, selector)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy type-specialized-instances: started fixing tests to work with new selector

2011-11-18 Thread l . diekmann
Author: Lukas Diekmann 
Branch: type-specialized-instances
Changeset: r49526:6f9cd7e5bdeb
Date: 2011-11-18 14:42 +0100
http://bitbucket.org/pypy/pypy/changeset/6f9cd7e5bdeb/

Log:started fixing tests to work with new selector

diff --git a/pypy/objspace/std/test/test_mapdict.py 
b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -28,14 +28,14 @@
 def erase_storage_items(items):
 return [IntAttribute.erase_item(item) for item in items]
 
-def unerase_storage_items(storage):
-return [IntAttribute.unerase_item(item) for item in storage]
+def unerase_storage_items(storage, uneraser=IntAttribute):
+return [uneraser.unerase_item(item) for item in storage]
 
 def test_plain_attribute():
 
 w_cls = "class"
-aa = PlainAttribute(("b", DICT),
-PlainAttribute(("a", DICT),
+aa = IntAttribute(("b", DICT, IntAttribute),
+IntAttribute(("a", DICT, IntAttribute),
Terminator(space, w_cls)))
 assert aa.space is space
 assert aa.terminator.w_cls is w_cls
@@ -115,8 +115,10 @@
 obj.setdictvalue(space, "a", 50)
 obj.setdictvalue(space, "b", 60)
 obj.setdictvalue(space, "c", 70)
+print obj.storage
 assert unerase_storage_items(obj.storage) == [50, 60, 70]
 res = obj.deldictvalue(space, dattr)
+print obj.storage
 assert res
 s = [50, 60, 70]
 del s[i]
@@ -159,7 +161,8 @@
 assert obj.getdictvalue(space, "a") == 50
 assert obj.getdictvalue(space, "b") == 60
 assert obj.getdictvalue(space, "c") == 70
-assert unerase_storage_items(obj.storage) == [50, 60, 70, lifeline1]
+assert unerase_storage_items(obj.storage[:-1], IntAttribute) == [50, 60, 
70]
+assert unerase_storage_items(obj.storage[-1:], PlainAttribute) == 
[lifeline1]
 assert obj.getweakref() is lifeline1
 
 obj2 = c.instantiate()
@@ -323,6 +326,7 @@
 
 obj3 = cls.instantiate()
 obj3.setdictvalue(space, "x", space.wrap(5))
+assert space.eq_w(obj3.getdictvalue(space, "x"), space.wrap(5))
 
 assert obj1.map is obj3.map
 
@@ -336,15 +340,27 @@
 obj1 = cls.instantiate()
 obj1.setdictvalue(space, "x", space.wrap(1))
 obj1.setdictvalue(space, "y", space.wrap(2))
+assert space.eq_w(obj1.getdictvalue(space, "x"), space.wrap(1))
+assert space.eq_w(obj1.getdictvalue(space, "y"), space.wrap(2))
+
+obj2 = cls.instantiate()
+obj2.setdictvalue(space, "x", space.wrap(5)) # this is shared
+obj2.setdictvalue(space, "y", space.wrap("str")) # this not
+assert space.eq_w(obj2.getdictvalue(space, "x"), space.wrap(5))
+assert space.eq_w(obj2.getdictvalue(space, "y"), space.wrap("str"))
 
 def test_switch_attribute_types(self):
 space = self.space
 cls = Class(sp=space)
 obj1 = cls.instantiate()
+
 obj1.setdictvalue(space, "x", space.wrap(1))
 assert isinstance(obj1.map, IntAttribute)
+assert space.eq_w(obj1.getdictvalue(space, "x"), space.wrap(1))
+
 obj1.setdictvalue(space, "y", space.wrap("str"))
 assert isinstance(obj1.map, PlainAttribute)
+assert space.eq_w(obj1.getdictvalue(space, "y"), space.wrap("str"))
 
 # ___
 # dict tests
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy type-specialized-instances: removed some old debug prints

2011-11-18 Thread l . diekmann
Author: Lukas Diekmann 
Branch: type-specialized-instances
Changeset: r49527:c76cccda3d75
Date: 2011-11-18 14:43 +0100
http://bitbucket.org/pypy/pypy/changeset/c76cccda3d75/

Log:removed some old debug prints

diff --git a/pypy/objspace/std/test/test_mapdict.py 
b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -115,10 +115,8 @@
 obj.setdictvalue(space, "a", 50)
 obj.setdictvalue(space, "b", 60)
 obj.setdictvalue(space, "c", 70)
-print obj.storage
 assert unerase_storage_items(obj.storage) == [50, 60, 70]
 res = obj.deldictvalue(space, dattr)
-print obj.storage
 assert res
 s = [50, 60, 70]
 del s[i]
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Fix for 612f7784a228.

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r49530:5269f0ee1ed2
Date: 2011-11-18 16:48 +0100
http://bitbucket.org/pypy/pypy/changeset/5269f0ee1ed2/

Log:Fix for 612f7784a228.

diff --git a/pypy/rpython/lltypesystem/rbuilder.py 
b/pypy/rpython/lltypesystem/rbuilder.py
--- a/pypy/rpython/lltypesystem/rbuilder.py
+++ b/pypy/rpython/lltypesystem/rbuilder.py
@@ -123,9 +123,10 @@
 def ll_build(ll_builder):
 final_size = ll_builder.used
 assert final_size >= 0
-if final_size == ll_builder.allocated:
-return ll_builder.buf
-return rgc.ll_shrink_array(ll_builder.buf, final_size)
+if final_size < ll_builder.allocated:
+ll_builder.allocated = final_size
+ll_builder.buf = rgc.ll_shrink_array(ll_builder.buf, final_size)
+return ll_builder.buf
 
 @classmethod
 def ll_is_true(cls, ll_builder):
diff --git a/pypy/translator/c/test/test_newgc.py 
b/pypy/translator/c/test/test_newgc.py
--- a/pypy/translator/c/test/test_newgc.py
+++ b/pypy/translator/c/test/test_newgc.py
@@ -1324,15 +1324,15 @@
 s = StringBuilder(4)
 got = []
 for i in range(50):
-s.append(chr(i))
+s.append(chr(33+i))
 got.append(s.build())
 gc.collect()
-return '/'.join(got)
+return ' '.join(got)
 return fn
 
 def test_string_builder_multiple_builds(self):
 res = self.run('string_builder_multiple_builds')
-assert res == '/'.join([''.join(map(chr, range(length)))
+assert res == ' '.join([''.join(map(chr, range(33, 33+length)))
 for length in range(1, 51)])
 
 def define_nursery_hash_base(cls):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy op_malloc_gc: Plan which tests are still needed (and the corresponding code).

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: op_malloc_gc
Changeset: r49528:211a72d5b8b8
Date: 2011-11-18 14:28 +0100
http://bitbucket.org/pypy/pypy/changeset/211a72d5b8b8/

Log:Plan which tests are still needed (and the corresponding code).

diff --git a/pypy/jit/backend/llsupport/test/test_gc.py 
b/pypy/jit/backend/llsupport/test/test_gc.py
--- a/pypy/jit/backend/llsupport/test/test_gc.py
+++ b/pypy/jit/backend/llsupport/test/test_gc.py
@@ -703,6 +703,28 @@
 jump()
 """)
 
+def test_rewrite_assembler_maximal_size(self):
+xxx
+
+def test_rewrite_assembler_variable_size(self):
+xxx
+
+def test_rewrite_assembler_new_with_vtable(self):
+self.check_rewrite("""
+[p1]
+p0 = new_with_vtable(descr=vdescr)
+jump()
+""", """
+[p1]
+p0 = malloc_gc(%(vdescr.size)d)
+setfield_gc(p0, 1234, descr=tiddescr)
+...
+jump()
+""")
+
+def test_rewrite_assembler_newstr_newunicode(self):
+xxx
+
 def test_rewrite_assembler_initialization_store(self):
 S = lltype.GcStruct('S', ('parent', OBJECT),
 ('x', lltype.Signed))
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Test for crashes when we call StringBuilder.build() several times over a growing

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r49529:612f7784a228
Date: 2011-11-18 16:43 +0100
http://bitbucket.org/pypy/pypy/changeset/612f7784a228/

Log:Test for crashes when we call StringBuilder.build() several times
over a growing builder, like W_StringBufferObject does.

diff --git a/pypy/translator/c/test/test_newgc.py 
b/pypy/translator/c/test/test_newgc.py
--- a/pypy/translator/c/test/test_newgc.py
+++ b/pypy/translator/c/test/test_newgc.py
@@ -1318,6 +1318,23 @@
 res = self.run('string_builder_over_allocation')
 assert res[1000] == 'y'
 
+def definestr_string_builder_multiple_builds(cls):
+import gc
+def fn(_):
+s = StringBuilder(4)
+got = []
+for i in range(50):
+s.append(chr(i))
+got.append(s.build())
+gc.collect()
+return '/'.join(got)
+return fn
+
+def test_string_builder_multiple_builds(self):
+res = self.run('string_builder_multiple_builds')
+assert res == '/'.join([''.join(map(chr, range(length)))
+for length in range(1, 51)])
+
 def define_nursery_hash_base(cls):
 from pypy.rlib.objectmodel import compute_identity_hash
 class A:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Python 2.5 compatibility.

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r49531:5019a28f7e6a
Date: 2011-11-18 16:51 +0100
http://bitbucket.org/pypy/pypy/changeset/5019a28f7e6a/

Log:Python 2.5 compatibility.

diff --git a/pypy/rpython/test/test_rbuilder.py 
b/pypy/rpython/test/test_rbuilder.py
--- a/pypy/rpython/test/test_rbuilder.py
+++ b/pypy/rpython/test/test_rbuilder.py
@@ -1,3 +1,4 @@
+from __future__ import with_statement
 import py
 
 from pypy.rlib.rstring import StringBuilder, UnicodeBuilder
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge

2011-11-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r49533:54e972f7c8ba
Date: 2011-11-18 18:26 +0200
http://bitbucket.org/pypy/pypy/changeset/54e972f7c8ba/

Log:merge

diff --git a/pypy/rpython/lltypesystem/rbuilder.py 
b/pypy/rpython/lltypesystem/rbuilder.py
--- a/pypy/rpython/lltypesystem/rbuilder.py
+++ b/pypy/rpython/lltypesystem/rbuilder.py
@@ -123,9 +123,10 @@
 def ll_build(ll_builder):
 final_size = ll_builder.used
 assert final_size >= 0
-if final_size == ll_builder.allocated:
-return ll_builder.buf
-return rgc.ll_shrink_array(ll_builder.buf, final_size)
+if final_size < ll_builder.allocated:
+ll_builder.allocated = final_size
+ll_builder.buf = rgc.ll_shrink_array(ll_builder.buf, final_size)
+return ll_builder.buf
 
 @classmethod
 def ll_is_true(cls, ll_builder):
diff --git a/pypy/rpython/test/test_rbuilder.py 
b/pypy/rpython/test/test_rbuilder.py
--- a/pypy/rpython/test/test_rbuilder.py
+++ b/pypy/rpython/test/test_rbuilder.py
@@ -1,3 +1,4 @@
+from __future__ import with_statement
 import py
 
 from pypy.rlib.rstring import StringBuilder, UnicodeBuilder
diff --git a/pypy/translator/c/test/test_newgc.py 
b/pypy/translator/c/test/test_newgc.py
--- a/pypy/translator/c/test/test_newgc.py
+++ b/pypy/translator/c/test/test_newgc.py
@@ -1318,6 +1318,23 @@
 res = self.run('string_builder_over_allocation')
 assert res[1000] == 'y'
 
+def definestr_string_builder_multiple_builds(cls):
+import gc
+def fn(_):
+s = StringBuilder(4)
+got = []
+for i in range(50):
+s.append(chr(33+i))
+got.append(s.build())
+gc.collect()
+return ' '.join(got)
+return fn
+
+def test_string_builder_multiple_builds(self):
+res = self.run('string_builder_multiple_builds')
+assert res == ' '.join([''.join(map(chr, range(33, 33+length)))
+for length in range(1, 51)])
+
 def define_nursery_hash_base(cls):
 from pypy.rlib.objectmodel import compute_identity_hash
 class A:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: move test_zll_random to llsupport

2011-11-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r49534:81dcafabbba9
Date: 2011-11-18 18:29 +0200
http://bitbucket.org/pypy/pypy/changeset/81dcafabbba9/

Log:move test_zll_random to llsupport

diff --git a/pypy/jit/backend/x86/test/test_zll_random.py 
b/pypy/jit/backend/llsupport/test/test_zll_random.py
rename from pypy/jit/backend/x86/test/test_zll_random.py
rename to pypy/jit/backend/llsupport/test/test_zll_random.py
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: use autodetect if you don't want to run llgraph

2011-11-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r49532:cb316be6a96f
Date: 2011-11-18 18:25 +0200
http://bitbucket.org/pypy/pypy/changeset/cb316be6a96f/

Log:use autodetect if you don't want to run llgraph

diff --git a/pypy/jit/backend/conftest.py b/pypy/jit/backend/conftest.py
--- a/pypy/jit/backend/conftest.py
+++ b/pypy/jit/backend/conftest.py
@@ -12,7 +12,7 @@
 help="choose a fixed random seed")
 group.addoption('--backend', action="store",
 default='llgraph',
-choices=['llgraph', 'x86'],
+choices=['llgraph', 'cpu'],
 dest="backend",
 help="select the backend to run the functions with")
 group.addoption('--block-length', action="store", type="int",
diff --git a/pypy/jit/backend/test/test_random.py 
b/pypy/jit/backend/test/test_random.py
--- a/pypy/jit/backend/test/test_random.py
+++ b/pypy/jit/backend/test/test_random.py
@@ -495,9 +495,9 @@
 if pytest.config.option.backend == 'llgraph':
 from pypy.jit.backend.llgraph.runner import LLtypeCPU
 return LLtypeCPU(None)
-elif pytest.config.option.backend == 'x86':
-from pypy.jit.backend.x86.runner import CPU386
-return CPU386(None, None)
+elif pytest.config.option.backend == 'cpu':
+from pypy.jit.backend.detect_cpu import getcpuclass
+return getcpuclass()(None, None)
 else:
 assert 0, "unknown backend %r" % pytest.config.option.backend
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Move the stress test directly to backend/test and rename it

2011-11-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r49535:dcc33426aadc
Date: 2011-11-18 18:48 +0200
http://bitbucket.org/pypy/pypy/changeset/dcc33426aadc/

Log:Move the stress test directly to backend/test and rename it

diff --git a/pypy/jit/backend/llsupport/test/test_zll_random.py 
b/pypy/jit/backend/test/test_zll_stress.py
rename from pypy/jit/backend/llsupport/test/test_zll_random.py
rename to pypy/jit/backend/test/test_zll_stress.py
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy op_malloc_gc: The interface that I really want.

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: op_malloc_gc
Changeset: r49537:f84b61015be5
Date: 2011-11-18 19:02 +0100
http://bitbucket.org/pypy/pypy/changeset/f84b61015be5/

Log:The interface that I really want.

diff --git a/pypy/jit/metainterp/resoperation.py 
b/pypy/jit/metainterp/resoperation.py
--- a/pypy/jit/metainterp/resoperation.py
+++ b/pypy/jit/metainterp/resoperation.py
@@ -470,7 +470,8 @@
 'NEW_ARRAY/1d',
 'NEWSTR/1',
 'NEWUNICODE/1',
-'MALLOC_GC/1',# added by llsupport/gc: GC malloc of ConstInt bytes
+'MALLOC_GC/3',   # added by llsupport/gc: malloc of C1+N*C2 bytes
+'MALLOC_NURSERY/1',  # added by llsupport/gc: nursery malloc, const bytes
 '_MALLOC_LAST',
 'FORCE_TOKEN/0',
 'VIRTUAL_REF/2', # removed before it's passed to the backend
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy op_malloc_gc: Move the new tests to their own file.

2011-11-18 Thread arigo
Author: Armin Rigo 
Branch: op_malloc_gc
Changeset: r49536:feae28c11d92
Date: 2011-11-18 19:02 +0100
http://bitbucket.org/pypy/pypy/changeset/feae28c11d92/

Log:Move the new tests to their own file.

diff --git a/pypy/jit/backend/llsupport/test/test_gc.py 
b/pypy/jit/backend/llsupport/test/test_gc.py
--- a/pypy/jit/backend/llsupport/test/test_gc.py
+++ b/pypy/jit/backend/llsupport/test/test_gc.py
@@ -547,184 +547,6 @@
 assert operations[1].getarg(2) == v_value
 assert operations[1].getdescr() == array_descr
 
-def check_rewrite(self, frm_operations, to_operations):
-self.gc_ll_descr.translate_support_code = False
-try:
-S = lltype.GcStruct('S', ('x', lltype.Signed),
- ('y', lltype.Signed))
-sdescr = get_size_descr(self.gc_ll_descr, S)
-sdescr.tid = 1234
-#
-T = lltype.GcStruct('T', ('y', lltype.Signed),
- ('z', lltype.Signed),
- ('t', lltype.Signed))
-tdescr = get_size_descr(self.gc_ll_descr, T)
-tdescr.tid = 5678
-#
-A = lltype.GcArray(lltype.Signed)
-adescr = get_array_descr(self.gc_ll_descr, A)
-adescr.tid = 4321
-alendescr = get_field_arraylen_descr(self.gc_ll_descr, A)
-#
-B = lltype.GcArray(lltype.Char)
-bdescr = get_array_descr(self.gc_ll_descr, B)
-bdescr.tid = 8765
-blendescr = get_field_arraylen_descr(self.gc_ll_descr, B)
-#
-E = lltype.GcStruct('Empty')
-edescr = get_size_descr(self.gc_ll_descr, E)
-edescr.tid = 9000
-#
-tiddescr = self.gc_ll_descr.fielddescr_tid
-WORD = globals()['WORD']
-#
-ops = parse(frm_operations, namespace=locals())
-expected = parse(to_operations % Evaluator(locals()),
- namespace=locals())
-operations = get_deep_immutable_oplist(ops.operations)
-operations = self.gc_ll_descr.rewrite_assembler(self.fake_cpu,
-operations, [])
-finally:
-self.gc_ll_descr.translate_support_code = True
-equaloplists(operations, expected.operations)
-
-def test_rewrite_assembler_new_to_malloc(self):
-self.check_rewrite("""
-[p1]
-p0 = new(descr=sdescr)
-jump()
-""", """
-[p1]
-p0 = malloc_gc(%(sdescr.size)d)
-setfield_gc(p0, 1234, descr=tiddescr)
-jump()
-""")
-
-def test_rewrite_assembler_new3_to_malloc(self):
-self.check_rewrite("""
-[]
-p0 = new(descr=sdescr)
-p1 = new(descr=tdescr)
-p2 = new(descr=sdescr)
-jump()
-""", """
-[]
-p0 = malloc_gc(%(sdescr.size + tdescr.size + sdescr.size)d)
-setfield_gc(p0, 1234, descr=tiddescr)
-p1 = int_add(p0, %(sdescr.size)d)
-setfield_gc(p1, 5678, descr=tiddescr)
-p2 = int_add(p1, %(tdescr.size)d)
-setfield_gc(p2, 1234, descr=tiddescr)
-jump()
-""")
-
-def test_rewrite_assembler_new_array_fixed_to_malloc(self):
-self.check_rewrite("""
-[]
-p0 = new_array(10, descr=adescr)
-jump()
-""", """
-[]
-p0 = malloc_gc(%(adescr.get_base_size(False) +\
- 10 * adescr.get_item_size(False))d)
-setfield_gc(p0, 4321, descr=tiddescr)
-setfield_gc(p0, 10, descr=alendescr)
-jump()
-""")
-
-def test_rewrite_assembler_new_and_new_array_fixed_to_malloc(self):
-self.check_rewrite("""
-[]
-p0 = new(descr=sdescr)
-p1 = new_array(10, descr=adescr)
-jump()
-""", """
-[]
-p0 = malloc_gc(%(sdescr.size +\
- adescr.get_base_size(False) +\
- 10 * adescr.get_item_size(False))d)
-setfield_gc(p0, 1234, descr=tiddescr)
-p1 = int_add(p0, %(sdescr.size)d)
-setfield_gc(p1, 4321, descr=tiddescr)
-setfield_gc(p1, 10, descr=alendescr)
-jump()
-""")
-
-def test_rewrite_assembler_round_up(self):
-self.check_rewrite("""
-[]
-p0 = new_array(6, descr=bdescr)
-jump()
-""", """
-[]
-p0 = malloc_gc(%(adescr.get_base_size(False) + 8)d)
-setfield_gc(p0, 8765, descr=tiddescr)
-setfield_gc(p0, 6, descr=blendescr)
-jump()
-""")
-
-def test_rewrite_assembler_round_up_always(self):
-   

[pypy-commit] pypy numpy-multidim-shards: remove unused parameter

2011-11-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: numpy-multidim-shards
Changeset: r49538:ad7839a7ff62
Date: 2011-11-18 21:00 +0200
http://bitbucket.org/pypy/pypy/changeset/ad7839a7ff62/

Log:remove unused parameter

diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -360,7 +360,6 @@
 res = StringBuilder()
 res.append("array(")
 concrete = self.get_concrete()
-start = True
 dtype = concrete.find_dtype()
 if not concrete.find_size():
 res.append('[]')
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: made the assembler sources compile so far

2011-11-18 Thread ctismer
Author: Christian Tismer 
Branch: 
Changeset: r49539:7d9e78a91dce
Date: 2011-11-18 23:12 +0100
http://bitbucket.org/pypy/pypy/changeset/7d9e78a91dce/

Log:made the assembler sources compile so far

diff --git a/pypy/rlib/_rffi_stacklet.py b/pypy/rlib/_rffi_stacklet.py
--- a/pypy/rlib/_rffi_stacklet.py
+++ b/pypy/rlib/_rffi_stacklet.py
@@ -3,16 +3,22 @@
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from pypy.rpython.tool import rffi_platform
+import sys
 
 
 cdir = py.path.local(pypydir) / 'translator' / 'c'
 
-
+_sep_mods = []
+if sys.platform == 'win32':
+_sep_mods = [cdir / "src/stacklet/switch_x86_msvc.asm"]
+
 eci = ExternalCompilationInfo(
 include_dirs = [cdir],
 includes = ['src/stacklet/stacklet.h'],
 separate_module_sources = ['#include "src/stacklet/stacklet.c"\n'],
+separate_module_files = _sep_mods
 )
+
 rffi_platform.verify_eci(eci.convert_sources_to_files())
 
 def llexternal(name, args, result, **kwds):
diff --git a/pypy/translator/platform/__init__.py 
b/pypy/translator/platform/__init__.py
--- a/pypy/translator/platform/__init__.py
+++ b/pypy/translator/platform/__init__.py
@@ -59,7 +59,11 @@
 compile_args = self._compile_args_from_eci(eci, standalone)
 ofiles = []
 for cfile in cfiles:
-ofiles.append(self._compile_c_file(self.cc, cfile, compile_args))
+# Windows hack: use masm for files ending in .asm
+if str(cfile).lower().endswith('.asm'):
+ofiles.append(self._compile_c_file(self.masm, cfile, []))
+else:
+ofiles.append(self._compile_c_file(self.cc, cfile, 
compile_args))
 return ofiles
 
 def execute(self, executable, args=None, env=None, compilation_info=None):
diff --git a/pypy/translator/platform/windows.py 
b/pypy/translator/platform/windows.py
--- a/pypy/translator/platform/windows.py
+++ b/pypy/translator/platform/windows.py
@@ -165,7 +165,7 @@
 
 def _compile_c_file(self, cc, cfile, compile_args):
 oname = cfile.new(ext='obj')
-args = ['/nologo', '/c'] + compile_args + [str(cfile), '/Fo%s' % 
(oname,)]
+args = ['/nologo', '/c'] + compile_args + ['/Fo%s' % (oname,), 
str(cfile)]
 self._execute_c_compiler(cc, args, oname)
 return oname
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: maybe wrong merge or wrong update. Anyway, fixed

2011-11-18 Thread ctismer
Author: Christian Tismer 
Branch: 
Changeset: r49541:7a0e4c3ee81a
Date: 2011-11-19 01:51 +0100
http://bitbucket.org/pypy/pypy/changeset/7a0e4c3ee81a/

Log:maybe wrong merge or wrong update. Anyway, fixed

diff --git a/pypy/jit/codewriter/codewriter.py 
b/pypy/jit/codewriter/codewriter.py
--- a/pypy/jit/codewriter/codewriter.py
+++ b/pypy/jit/codewriter/codewriter.py
@@ -104,6 +104,8 @@
 else:
 name = 'unnamed' % id(ssarepr)
 i = 1
+# escape  names for windows
+#name = name.replace('', '_(lambda)_')
 extra = ''
 while name+extra in self._seen_files:
 i += 1
diff --git a/pypy/translator/platform/windows.py 
b/pypy/translator/platform/windows.py
--- a/pypy/translator/platform/windows.py
+++ b/pypy/translator/platform/windows.py
@@ -80,7 +80,7 @@
 shared_only = ()
 environ = None
 
-def __init__(self, cc=None):
+def __init__(self, cc=None, x64=False):
 Platform.__init__(self, 'cl.exe')
 if msvc_compiler_environ:
 self.c_environ = os.environ.copy()
@@ -103,9 +103,16 @@
  env=self.c_environ)
 r = re.search('Macro Assembler', stderr)
 if r is None and os.path.exists('c:/masm32/bin/ml.exe'):
-self.masm = 'c:/masm32/bin/ml.exe'
+masm32 = 'c:/masm32/bin/ml.exe'
+masm64 = 'c:/masm64/bin/ml64.exe'
 else:
-self.masm = 'ml.exe'
+masm32 = 'ml.exe'
+masm64 = 'ml64.exe'
+
+if x64:
+self.masm = masm64
+else:
+self.masm = masm32
 
 # Install debug options only when interpreter is in debug mode
 if sys.executable.lower().endswith('_d.exe'):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: escape '' for windows

2011-11-18 Thread ctismer
Author: Christian Tismer 
Branch: 
Changeset: r49542:11f0c5fd62bd
Date: 2011-11-19 02:01 +0100
http://bitbucket.org/pypy/pypy/changeset/11f0c5fd62bd/

Log:escape '' for windows

diff --git a/pypy/jit/codewriter/codewriter.py 
b/pypy/jit/codewriter/codewriter.py
--- a/pypy/jit/codewriter/codewriter.py
+++ b/pypy/jit/codewriter/codewriter.py
@@ -105,7 +105,7 @@
 name = 'unnamed' % id(ssarepr)
 i = 1
 # escape  names for windows
-#name = name.replace('', '_(lambda)_')
+name = name.replace('', '_(lambda)_')
 extra = ''
 while name+extra in self._seen_files:
 i += 1
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy release-1.7.x: fix the test

2011-11-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: release-1.7.x
Changeset: r49544:ff4af8f31882
Date: 2011-11-19 09:44 +0200
http://bitbucket.org/pypy/pypy/changeset/ff4af8f31882/

Log:fix the test

diff --git a/pypy/jit/backend/x86/test/test_ztranslation.py 
b/pypy/jit/backend/x86/test/test_ztranslation.py
--- a/pypy/jit/backend/x86/test/test_ztranslation.py
+++ b/pypy/jit/backend/x86/test/test_ztranslation.py
@@ -1,6 +1,6 @@
 import py, os, sys
 from pypy.tool.udir import udir
-from pypy.rlib.jit import JitDriver, unroll_parameters
+from pypy.rlib.jit import JitDriver, unroll_parameters, set_param
 from pypy.rlib.jit import PARAMETERS, dont_look_inside
 from pypy.rlib.jit import promote
 from pypy.jit.metainterp.jitprof import Profiler
@@ -47,9 +47,9 @@
 def f(i, j):
 for param, _ in unroll_parameters:
 defl = PARAMETERS[param]
-jitdriver.set_param(param, defl)
-jitdriver.set_param("threshold", 3)
-jitdriver.set_param("trace_eagerness", 2)
+set_param(jitdriver, param, defl)
+set_param(jitdriver, "threshold", 3)
+set_param(jitdriver, "trace_eagerness", 2)
 total = 0
 frame = Frame(i)
 while frame.i > 3:
@@ -213,8 +213,8 @@
 else:
 return Base()
 def myportal(i):
-jitdriver.set_param("threshold", 3)
-jitdriver.set_param("trace_eagerness", 2)
+set_param(jitdriver, "threshold", 3)
+set_param(jitdriver, "trace_eagerness", 2)
 total = 0
 n = i
 while True:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix the test

2011-11-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r49543:a12c7868cd94
Date: 2011-11-19 09:44 +0200
http://bitbucket.org/pypy/pypy/changeset/a12c7868cd94/

Log:fix the test

diff --git a/pypy/jit/backend/x86/test/test_ztranslation.py 
b/pypy/jit/backend/x86/test/test_ztranslation.py
--- a/pypy/jit/backend/x86/test/test_ztranslation.py
+++ b/pypy/jit/backend/x86/test/test_ztranslation.py
@@ -1,6 +1,6 @@
 import py, os, sys
 from pypy.tool.udir import udir
-from pypy.rlib.jit import JitDriver, unroll_parameters
+from pypy.rlib.jit import JitDriver, unroll_parameters, set_param
 from pypy.rlib.jit import PARAMETERS, dont_look_inside
 from pypy.rlib.jit import promote
 from pypy.jit.metainterp.jitprof import Profiler
@@ -47,9 +47,9 @@
 def f(i, j):
 for param, _ in unroll_parameters:
 defl = PARAMETERS[param]
-jitdriver.set_param(param, defl)
-jitdriver.set_param("threshold", 3)
-jitdriver.set_param("trace_eagerness", 2)
+set_param(jitdriver, param, defl)
+set_param(jitdriver, "threshold", 3)
+set_param(jitdriver, "trace_eagerness", 2)
 total = 0
 frame = Frame(i)
 while frame.i > 3:
@@ -213,8 +213,8 @@
 else:
 return Base()
 def myportal(i):
-jitdriver.set_param("threshold", 3)
-jitdriver.set_param("trace_eagerness", 2)
+set_param(jitdriver, "threshold", 3)
+set_param(jitdriver, "trace_eagerness", 2)
 total = 0
 n = i
 while True:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge

2011-11-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r49545:c2d0f2933d2f
Date: 2011-11-19 09:51 +0200
http://bitbucket.org/pypy/pypy/changeset/c2d0f2933d2f/

Log:merge

diff --git a/pypy/jit/backend/x86/test/test_ztranslation.py 
b/pypy/jit/backend/x86/test/test_ztranslation.py
--- a/pypy/jit/backend/x86/test/test_ztranslation.py
+++ b/pypy/jit/backend/x86/test/test_ztranslation.py
@@ -1,6 +1,6 @@
 import py, os, sys
 from pypy.tool.udir import udir
-from pypy.rlib.jit import JitDriver, unroll_parameters
+from pypy.rlib.jit import JitDriver, unroll_parameters, set_param
 from pypy.rlib.jit import PARAMETERS, dont_look_inside
 from pypy.rlib.jit import promote
 from pypy.jit.metainterp.jitprof import Profiler
@@ -47,9 +47,9 @@
 def f(i, j):
 for param, _ in unroll_parameters:
 defl = PARAMETERS[param]
-jitdriver.set_param(param, defl)
-jitdriver.set_param("threshold", 3)
-jitdriver.set_param("trace_eagerness", 2)
+set_param(jitdriver, param, defl)
+set_param(jitdriver, "threshold", 3)
+set_param(jitdriver, "trace_eagerness", 2)
 total = 0
 frame = Frame(i)
 while frame.i > 3:
@@ -213,8 +213,8 @@
 else:
 return Base()
 def myportal(i):
-jitdriver.set_param("threshold", 3)
-jitdriver.set_param("trace_eagerness", 2)
+set_param(jitdriver, "threshold", 3)
+set_param(jitdriver, "trace_eagerness", 2)
 total = 0
 n = i
 while True:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit