[pypy-commit] pypy counter-decay: Merge default again, but keeping the pieces that I want to keep.
Author: Armin Rigo ar...@tunes.org Branch: counter-decay Changeset: r50745:b3d18c96013e Date: 2011-12-20 09:19 +0100 http://bitbucket.org/pypy/pypy/changeset/b3d18c96013e/ Log:Merge default again, but keeping the pieces that I want to keep. The idea is to keep some mecanism to clean-up jitcell dicts, and to re- add some minimal form of decaying. diff --git a/pypy/jit/metainterp/memmgr.py b/pypy/jit/metainterp/memmgr.py --- a/pypy/jit/metainterp/memmgr.py +++ b/pypy/jit/metainterp/memmgr.py @@ -1,5 +1,5 @@ import math -from pypy.rlib.rarithmetic import r_int64, r_uint +from pypy.rlib.rarithmetic import r_int64 from pypy.rlib.debug import debug_start, debug_print, debug_stop from pypy.rlib.objectmodel import we_are_translated @@ -21,7 +21,6 @@ # class MemoryManager(object): -NO_NEXT_CHECK = r_int64(2 ** 63 - 1) def __init__(self): self.check_frequency = -1 @@ -37,13 +36,12 @@ # According to my estimates it's about 5e9 years given 1000 loops # per second self.current_generation = r_int64(1) -self.next_check = self.NO_NEXT_CHECK +self.next_check = r_int64(-1) self.alive_loops = {} -self._cleanup_jitcell_dicts = lambda: None def set_max_age(self, max_age, check_frequency=0): if max_age = 0: -self.next_check = self.NO_NEXT_CHECK +self.next_check = r_int64(-1) else: self.max_age = max_age if check_frequency = 0: @@ -51,11 +49,10 @@ self.check_frequency = check_frequency self.next_check = self.current_generation + 1 -def next_generation(self, do_cleanups_now=True): +def next_generation(self): self.current_generation += 1 -if do_cleanups_now and self.current_generation = self.next_check: +if self.current_generation == self.next_check: self._kill_old_loops_now() -self._cleanup_jitcell_dicts() self.next_check = self.current_generation + self.check_frequency def keep_loop_alive(self, looptoken): @@ -84,22 +81,3 @@ # a single one is not enough for all tests :-( rgc.collect(); rgc.collect(); rgc.collect() debug_stop(jit-mem-collect) - -def get_current_generation_uint(self): -Return the current generation, possibly truncated to a uint. -To use only as an approximation for decaying counters. -return r_uint(self.current_generation) - -def record_jitcell_dict(self, callback): -NOT_RPYTHON. The given jitcell_dict is a dict that needs -occasional clean-ups of old cells. A cell is old if it never -reached the threshold, and its counter decayed to a tiny value. -# note that the various jitcell_dicts have different RPython types, -# so we have to make a different function for each one. These -# functions are chained to each other: each calls the previous one. -def cleanup_dict(): -callback() -cleanup_previous() -# -cleanup_previous = self._cleanup_jitcell_dicts -self._cleanup_jitcell_dicts = cleanup_dict 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 @@ -2910,27 +2910,6 @@ res = self.meta_interp(f, [32]) assert res == f(32) -def test_decay_counters(self): -myjitdriver = JitDriver(greens = ['m'], reds = ['n']) -def f(m, n): -while n 0: -myjitdriver.jit_merge_point(m=m, n=n) -n += m -n -= m -n -= 1 -def main(): -f(5, 7) # run 7x with m=5 counter[m=5] = 7 -f(15, 10)# compiles one loop counter[m=5] = 3 (automatic decay) -f(5, 5) # run 5x times with m=5 counter[m=5] = 8 -# -self.meta_interp(main, [], decay_halflife=1, - function_threshold=0, threshold=9, trace_eagerness=99) -self.check_trace_count(1) -# -self.meta_interp(main, [], decay_halflife=1, - function_threshold=0, threshold=8, trace_eagerness=99) -self.check_trace_count(2) - class TestOOtype(BasicTests, OOJitMixin): diff --git a/pypy/jit/metainterp/test/test_warmstate.py b/pypy/jit/metainterp/test/test_warmstate.py --- a/pypy/jit/metainterp/test/test_warmstate.py +++ b/pypy/jit/metainterp/test/test_warmstate.py @@ -1,4 +1,3 @@ -import math from pypy.rpython.test.test_llinterp import interpret from pypy.rpython.lltypesystem import lltype, llmemory, rstr, rffi from pypy.rpython.ootypesystem import ootype @@ -9,7 +8,7 @@ from pypy.jit.metainterp.history import BoxInt, BoxFloat, BoxPtr from pypy.jit.metainterp.history import ConstInt, ConstFloat, ConstPtr from pypy.jit.codewriter import
[pypy-commit] pypy counter-decay: Simplify and stand-alone-ize the clean-up of old jitcells from
Author: Armin Rigo ar...@tunes.org Branch: counter-decay Changeset: r50746:5f38cbc2c7f7 Date: 2011-12-20 09:30 +0100 http://bitbucket.org/pypy/pypy/changeset/5f38cbc2c7f7/ Log:Simplify and stand-alone-ize the clean-up of old jitcells from the jitcell dict. diff --git a/pypy/jit/metainterp/test/test_warmstate.py b/pypy/jit/metainterp/test/test_warmstate.py --- a/pypy/jit/metainterp/test/test_warmstate.py +++ b/pypy/jit/metainterp/test/test_warmstate.py @@ -277,65 +277,50 @@ assert res is True def test_cleanup_jitcell_dict(): -from pypy.jit.metainterp.memmgr import MemoryManager -class FakeWarmRunnerDesc: -memory_manager = MemoryManager() -class cpu: -pass class FakeJitDriverSD: _green_args_spec = [lltype.Signed] # # Test creating tons of jitcells that remain at 0 -warmstate = WarmEnterState(FakeWarmRunnerDesc(), FakeJitDriverSD()) +warmstate = WarmEnterState(None, FakeJitDriverSD()) get_jitcell = warmstate._make_jitcell_getter_default() cell1 = get_jitcell(True, -1) assert len(warmstate._jitcell_dict) == 1 -assert FakeWarmRunnerDesc.memory_manager.current_generation == 1 # for i in range(1, 20005): get_jitcell(True, i) # should trigger a clean-up at 20001 assert len(warmstate._jitcell_dict) == (i % 2) + 1 -assert FakeWarmRunnerDesc.memory_manager.current_generation == 2 # # Same test, with one jitcell that has a counter of BASE instead of 0 -warmstate = WarmEnterState(FakeWarmRunnerDesc(), FakeJitDriverSD()) -warmstate.set_param_decay_halflife(2) -warmstate.set_param_threshold(5) -warmstate.set_param_function_threshold(0) +warmstate = WarmEnterState(None, FakeJitDriverSD()) get_jitcell = warmstate._make_jitcell_getter_default() cell2 = get_jitcell(True, -2) -cell2.counter = BASE = warmstate.increment_threshold * 3 +cell2.counter = BASE = warmstate.THRESHOLD_LIMIT // 2# 50% # for i in range(0, 20005): get_jitcell(True, i) assert len(warmstate._jitcell_dict) == (i % 1) + 2 # assert cell2 in warmstate._jitcell_dict.values() -assert cell2.counter == int(BASE * math.sqrt(0.5)) # decayed once -assert FakeWarmRunnerDesc.memory_manager.current_generation == 3 +assert cell2.counter == int(BASE * 0.92) # decayed once # -# Same test, with jitcells that are compiled and free by the memmgr -warmstate = WarmEnterState(FakeWarmRunnerDesc(), FakeJitDriverSD()) +# Same test, with jitcells that are compiled and freed by the memmgr +warmstate = WarmEnterState(None, FakeJitDriverSD()) get_jitcell = warmstate._make_jitcell_getter_default() get_jitcell(True, -1) -assert FakeWarmRunnerDesc.memory_manager.current_generation == 3 # for i in range(1, 20005): cell = get_jitcell(True, i) cell.counter = -1 cell.wref_procedure_token = None# or a dead weakref, equivalently assert len(warmstate._jitcell_dict) == (i % 2) + 1 -assert FakeWarmRunnerDesc.memory_manager.current_generation == 4 # # Same test, with counter == -2 (rare case, kept alive) -warmstate = WarmEnterState(FakeWarmRunnerDesc(), FakeJitDriverSD()) +warmstate = WarmEnterState(None, FakeJitDriverSD()) get_jitcell = warmstate._make_jitcell_getter_default() cell = get_jitcell(True, -1) cell.counter = -2 -assert FakeWarmRunnerDesc.memory_manager.current_generation == 4 # for i in range(1, 20005): cell = get_jitcell(True, i) cell.counter = -2 assert len(warmstate._jitcell_dict) == i + 1 -assert FakeWarmRunnerDesc.memory_manager.current_generation == 5 diff --git a/pypy/jit/metainterp/warmstate.py b/pypy/jit/metainterp/warmstate.py --- a/pypy/jit/metainterp/warmstate.py +++ b/pypy/jit/metainterp/warmstate.py @@ -446,44 +446,32 @@ except AttributeError: pass # -memmgr = self.warmrunnerdesc and self.warmrunnerdesc.memory_manager -if memmgr: -def _cleanup_dict(): -minimum = sys.maxint -if self.increment_threshold 0: -minimum = min(minimum, self.increment_threshold) -if self.increment_function_threshold 0: -minimum = min(minimum, self.increment_function_threshold) -currentgen = memmgr.get_current_generation_uint() -killme = [] -for key, cell in jitcell_dict.iteritems(): -if cell.counter = 0: -cell.adjust_counter(currentgen, self.log_decay_factor) -if cell.counter minimum: -killme.append(key) -elif (cell.counter == -1 - and cell.get_procedure_token() is None): +def _cleanup_dict(): +minimum =
[pypy-commit] pypy default: Un-merge counter-decay, which was definitely not really good.
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r50744:a2b9604a9859 Date: 2011-12-20 08:57 +0100 http://bitbucket.org/pypy/pypy/changeset/a2b9604a9859/ Log:Un-merge counter-decay, which was definitely not really good. More work should be going on in the branch. This cancels 5309a1389556, e790db7af776 and 15811e23d71a. diff --git a/pypy/jit/metainterp/memmgr.py b/pypy/jit/metainterp/memmgr.py --- a/pypy/jit/metainterp/memmgr.py +++ b/pypy/jit/metainterp/memmgr.py @@ -1,5 +1,5 @@ import math -from pypy.rlib.rarithmetic import r_int64, r_uint +from pypy.rlib.rarithmetic import r_int64 from pypy.rlib.debug import debug_start, debug_print, debug_stop from pypy.rlib.objectmodel import we_are_translated @@ -21,7 +21,6 @@ # class MemoryManager(object): -NO_NEXT_CHECK = r_int64(2 ** 63 - 1) def __init__(self): self.check_frequency = -1 @@ -37,13 +36,12 @@ # According to my estimates it's about 5e9 years given 1000 loops # per second self.current_generation = r_int64(1) -self.next_check = self.NO_NEXT_CHECK +self.next_check = r_int64(-1) self.alive_loops = {} -self._cleanup_jitcell_dicts = lambda: None def set_max_age(self, max_age, check_frequency=0): if max_age = 0: -self.next_check = self.NO_NEXT_CHECK +self.next_check = r_int64(-1) else: self.max_age = max_age if check_frequency = 0: @@ -51,11 +49,10 @@ self.check_frequency = check_frequency self.next_check = self.current_generation + 1 -def next_generation(self, do_cleanups_now=True): +def next_generation(self): self.current_generation += 1 -if do_cleanups_now and self.current_generation = self.next_check: +if self.current_generation == self.next_check: self._kill_old_loops_now() -self._cleanup_jitcell_dicts() self.next_check = self.current_generation + self.check_frequency def keep_loop_alive(self, looptoken): @@ -84,22 +81,3 @@ # a single one is not enough for all tests :-( rgc.collect(); rgc.collect(); rgc.collect() debug_stop(jit-mem-collect) - -def get_current_generation_uint(self): -Return the current generation, possibly truncated to a uint. -To use only as an approximation for decaying counters. -return r_uint(self.current_generation) - -def record_jitcell_dict(self, callback): -NOT_RPYTHON. The given jitcell_dict is a dict that needs -occasional clean-ups of old cells. A cell is old if it never -reached the threshold, and its counter decayed to a tiny value. -# note that the various jitcell_dicts have different RPython types, -# so we have to make a different function for each one. These -# functions are chained to each other: each calls the previous one. -def cleanup_dict(): -callback() -cleanup_previous() -# -cleanup_previous = self._cleanup_jitcell_dicts -self._cleanup_jitcell_dicts = cleanup_dict 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 @@ -2910,27 +2910,6 @@ res = self.meta_interp(f, [32]) assert res == f(32) -def test_decay_counters(self): -myjitdriver = JitDriver(greens = ['m'], reds = ['n']) -def f(m, n): -while n 0: -myjitdriver.jit_merge_point(m=m, n=n) -n += m -n -= m -n -= 1 -def main(): -f(5, 7) # run 7x with m=5 counter[m=5] = 7 -f(15, 10)# compiles one loop counter[m=5] = 3 (automatic decay) -f(5, 5) # run 5x times with m=5 counter[m=5] = 8 -# -self.meta_interp(main, [], decay_halflife=1, - function_threshold=0, threshold=9, trace_eagerness=99) -self.check_trace_count(1) -# -self.meta_interp(main, [], decay_halflife=1, - function_threshold=0, threshold=8, trace_eagerness=99) -self.check_trace_count(2) - class TestOOtype(BasicTests, OOJitMixin): diff --git a/pypy/jit/metainterp/test/test_warmstate.py b/pypy/jit/metainterp/test/test_warmstate.py --- a/pypy/jit/metainterp/test/test_warmstate.py +++ b/pypy/jit/metainterp/test/test_warmstate.py @@ -1,4 +1,3 @@ -import math from pypy.rpython.test.test_llinterp import interpret from pypy.rpython.lltypesystem import lltype, llmemory, rstr, rffi from pypy.rpython.ootypesystem import ootype @@ -9,7 +8,7 @@ from pypy.jit.metainterp.history import BoxInt, BoxFloat, BoxPtr from pypy.jit.metainterp.history import ConstInt, ConstFloat, ConstPtr from pypy.jit.codewriter import longlong -from
[pypy-commit] pypy default: Python 2.5 compat
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r50747:2eaaedd0fe70 Date: 2011-12-20 09:39 +0100 http://bitbucket.org/pypy/pypy/changeset/2eaaedd0fe70/ Log:Python 2.5 compat diff --git a/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py b/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py --- a/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py @@ -1,3 +1,4 @@ +from __future__ import with_statement from pypy.jit.metainterp.optimizeopt.test.test_util import ( LLtypeMixin, BaseTest, Storage, _sortboxes, FakeDescrWithSnapshot) from pypy.jit.metainterp.history import TreeLoop, JitCellToken, TargetToken ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy counter-decay: A minimal version of counter decaying.
Author: Armin Rigo ar...@tunes.org Branch: counter-decay Changeset: r50748:85efaef762fb Date: 2011-12-20 09:41 +0100 http://bitbucket.org/pypy/pypy/changeset/85efaef762fb/ Log:A minimal version of counter decaying. diff --git a/pypy/jit/metainterp/warmstate.py b/pypy/jit/metainterp/warmstate.py --- a/pypy/jit/metainterp/warmstate.py +++ b/pypy/jit/metainterp/warmstate.py @@ -151,6 +151,7 @@ # counter == -2: tracing is currently going on for this cell counter = 0 dont_trace_here = False +extra_delay = chr(0) wref_procedure_token = None def get_procedure_token(self): @@ -315,6 +316,36 @@ # assert 0, should have raised +def bound_reached(cell, *args): +# bound reached, but we do a last check: if it is the first +# time we reach the bound, or if another loop or bridge was +# compiled since the last time we reached it, then decrease +# the counter by a few percents instead. It should avoid +# sudden bursts of JIT-compilation, and also corner cases +# where we suddenly compile more than one loop because all +# counters reach the bound at the same time, but where +# compiling all but the first one is pointless. +curgen = warmrunnerdesc.memory_manager.current_generation +curgen = chr(intmask(curgen) 0xFF)# only use 8 bits +if we_are_translated() and curgen != cell.extra_delay: +cell.counter = int(self.THRESHOLD_LIMIT * 0.98) +cell.extra_delay = curgen +return +# +if not confirm_enter_jit(*args): +cell.counter = 0 +return +# start tracing +from pypy.jit.metainterp.pyjitpl import MetaInterp +metainterp = MetaInterp(metainterp_sd, jitdriver_sd) +# set counter to -2, to mean tracing in effect +cell.counter = -2 +try: +metainterp.compile_and_run_once(jitdriver_sd, *args) +finally: +if cell.counter == -2: +cell.counter = 0 + def maybe_compile_and_run(threshold, *args): Entry point to the JIT. Called at the point with the can_enter_jit() hint. @@ -329,19 +360,9 @@ if n = self.THRESHOLD_LIMIT: # bound not reached cell.counter = n return -if not confirm_enter_jit(*args): -cell.counter = 0 +else: +bound_reached(cell, *args) return -# bound reached; start tracing -from pypy.jit.metainterp.pyjitpl import MetaInterp -metainterp = MetaInterp(metainterp_sd, jitdriver_sd) -# set counter to -2, to mean tracing in effect -cell.counter = -2 -try: -metainterp.compile_and_run_once(jitdriver_sd, *args) -finally: -if cell.counter == -2: -cell.counter = 0 else: if cell.counter != -1: assert cell.counter == -2 ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Fix the repr of CallDescrs to not include a , because
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r50749:db66545368fd Date: 2011-12-20 10:13 + http://bitbucket.org/pypy/pypy/changeset/db66545368fd/ Log:Fix the repr of CallDescrs to not include a , because that confuses the jitlogparser to no end... 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 @@ -425,7 +425,7 @@ self.arg_classes.count('L')) == len(args_f or ()) def repr_of_descr(self): -return 'CallDescr(%s,%s)' % (self.arg_classes, self.result_type) +return 'CallDescr(%s/%s)' % (self.arg_classes, self.result_type) def map_type_to_argclass(ARG, accept_void=False): diff --git a/pypy/jit/backend/llsupport/test/test_descr.py b/pypy/jit/backend/llsupport/test/test_descr.py --- a/pypy/jit/backend/llsupport/test/test_descr.py +++ b/pypy/jit/backend/llsupport/test/test_descr.py @@ -313,6 +313,10 @@ def test_repr_of_descr(): +def repr_of_descr(descr): +s = descr.repr_of_descr() +assert ',' not in s # makes the life easier for pypy.tool.jitlogparser +return s c0 = GcCache(False) T = lltype.GcStruct('T') S = lltype.GcStruct('S', ('x', lltype.Char), @@ -320,34 +324,34 @@ ('z', lltype.Ptr(T))) descr1 = get_size_descr(c0, S) s = symbolic.get_size(S, False) -assert descr1.repr_of_descr() == 'SizeDescr %d' % s +assert repr_of_descr(descr1) == 'SizeDescr %d' % s # descr2 = get_field_descr(c0, S, 'y') o, _ = symbolic.get_field_token(S, 'y', False) -assert descr2.repr_of_descr() == 'FieldP S.y %d' % o +assert repr_of_descr(descr2) == 'FieldP S.y %d' % o # descr2i = get_field_descr(c0, S, 'x') o, _ = symbolic.get_field_token(S, 'x', False) -assert descr2i.repr_of_descr() == 'FieldU S.x %d' % o +assert repr_of_descr(descr2i) == 'FieldU S.x %d' % o # descr3 = get_array_descr(c0, lltype.GcArray(lltype.Ptr(S))) o = symbolic.get_size(lltype.Ptr(S), False) -assert descr3.repr_of_descr() == 'ArrayP %d' % o +assert repr_of_descr(descr3) == 'ArrayP %d' % o # descr3i = get_array_descr(c0, lltype.GcArray(lltype.Char)) -assert descr3i.repr_of_descr() == 'ArrayU 1' +assert repr_of_descr(descr3i) == 'ArrayU 1' # descr4 = get_call_descr(c0, [lltype.Char, lltype.Ptr(S)], lltype.Ptr(S)) -assert descr4.repr_of_descr() == 'CallDescr(ir,r)' +assert repr_of_descr(descr4) == 'CallDescr(ir/r)' # descr4i = get_call_descr(c0, [lltype.Char, lltype.Ptr(S)], lltype.Char) -assert descr4i.repr_of_descr() == 'CallDescr(ir,i)' +assert repr_of_descr(descr4i) == 'CallDescr(ir/i)' # descr4f = get_call_descr(c0, [lltype.Char, lltype.Ptr(S)], lltype.Float) -assert descr4f.repr_of_descr() == 'CallDescr(ir,f)' +assert repr_of_descr(descr4f) == 'CallDescr(ir/f)' # descr5f = get_call_descr(c0, [lltype.Char], lltype.SingleFloat) -assert descr5f.repr_of_descr() == 'CallDescr(i,S)' +assert repr_of_descr(descr5f) == 'CallDescr(i/S)' def test_call_stubs_1(): c0 = GcCache(False) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy set-strategies: merged set- with liststrategies. when initializing a set with lists they can copy the storage and strategy from that list without wrapping the storages content
Author: Lukas Diekmann lukas.diekm...@uni-duesseldorf.de Branch: set-strategies Changeset: r50751:b0d872ae3261 Date: 2011-12-20 13:42 +0100 http://bitbucket.org/pypy/pypy/changeset/b0d872ae3261/ Log:merged set- with liststrategies. when initializing a set with lists they can copy the storage and strategy from that list without wrapping the storages content diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py --- a/pypy/objspace/std/listobject.py +++ b/pypy/objspace/std/listobject.py @@ -508,6 +508,11 @@ def getitems_copy(self, w_list): return self._getitems_range(w_list, True) +getitems_wrapped = getitems_copy + +def getitems_unwrapped(self, w_list): +return self._getitems_range(w_list, False) + def getstorage_copy(self, w_list): # tuple is unmutable return w_list.lstorage @@ -698,6 +703,11 @@ def getitems_copy(self, w_list): return [self.wrap(item) for item in self.unerase(w_list.lstorage)] +getitems_wrapped = getitems_copy + +def getitems_unwrapped(self, w_list): +return self.unerase(w_list.lstorage) + @jit.unroll_safe def getitems_unroll(self, w_list): return [self.wrap(item) for item in self.unerase(w_list.lstorage)] @@ -926,6 +936,8 @@ def getitems(self, w_list): return self.unerase(w_list.lstorage) +getitems_wrapped = getitems + class IntegerListStrategy(AbstractUnwrappedStrategy, ListStrategy): _none_value = 0 _applevel_repr = int diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py --- a/pypy/objspace/std/setobject.py +++ b/pypy/objspace/std/setobject.py @@ -13,6 +13,8 @@ from pypy.objspace.std.listobject import W_ListObject from pypy.objspace.std.intobject import W_IntObject from pypy.objspace.std.stringobject import W_StringObject +from pypy.objspace.std.listobject import IntegerListStrategy, StringListStrategy,\ +EmptyListStrategy, RangeListStrategy, ObjectListStrategy, FloatListStrategy class W_BaseSetObject(W_Object): typedef = None @@ -280,6 +282,9 @@ def get_empty_storage(self): return self.erase(None) +def get_storage_from_w_list(self, w_list): +return self.get_empty_storage() + def is_correct_type(self, w_key): return False @@ -384,6 +389,14 @@ setdata[self.unwrap(w_item)] = None return self.erase(setdata) +def get_storage_from_w_list(self, w_list): +items = w_list.strategy.getitems_unwrapped(w_list) + +setdata = self.get_empty_dict() +for item in items: +setdata[item] = None +return self.erase(setdata) + def length(self, w_set): return len(self.unerase(w_set.sstorage)) @@ -746,6 +759,14 @@ def get_empty_storage(self): return self.erase(self.get_empty_dict()) +def get_storage_from_w_list(self, w_list): +items = w_list.strategy.getitems_wrapped(w_list) + +setdata = self.get_empty_dict() +for item in items: +setdata[item] = None +return self.erase(setdata) + def get_empty_dict(self): return newset(self.space) @@ -883,6 +904,22 @@ def newset(space): return r_dict(space.eq_w, space.hash_w, force_non_null=True) +_strategy_map = { +EmptyListStrategy: EmptySetStrategy, +IntegerListStrategy: IntegerSetStrategy, +RangeListStrategy: IntegerSetStrategy, +StringListStrategy: StringSetStrategy, +FloatListStrategy: ObjectSetStrategy, +ObjectListStrategy: ObjectSetStrategy +} + +def set_strategy_and_setdata_from_listobject(space, w_set, w_list): +strategy_class = _strategy_map[w_list.strategy.__class__] +strategy = space.fromcache(strategy_class) + +w_set.sstorage = strategy.get_storage_from_w_list(w_list) +w_set.strategy = strategy + def set_strategy_and_setdata(space, w_set, w_iterable): from pypy.objspace.std.intobject import W_IntObject if w_iterable is None : @@ -895,6 +932,10 @@ w_set.sstorage = w_iterable.get_storage_copy() return +if isinstance(w_iterable, W_ListObject): +set_strategy_and_setdata_from_listobject(space, w_set, w_iterable) +return + iterable_w = space.listview(w_iterable) if len(iterable_w) == 0: 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 @@ -8,7 +8,7 @@ is not too wrong. import py.test -from pypy.objspace.std.setobject import W_SetObject, W_FrozensetObject +from pypy.objspace.std.setobject import W_SetObject, W_FrozensetObject, IntegerSetStrategy from pypy.objspace.std.setobject import _initialize_set from pypy.objspace.std.setobject import newset from pypy.objspace.std.setobject import and__Set_Set @@ -83,6 +83,45 @@ result = set_intersection__Set(space, a, [d,c,b])
[pypy-commit] pypy ppc-jit-backend: merge
Author: hager sven.ha...@uni-duesseldorf.de Branch: ppc-jit-backend Changeset: r50756:4b2b09579148 Date: 2011-12-20 15:37 +0100 http://bitbucket.org/pypy/pypy/changeset/4b2b09579148/ Log:merge 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 @@ -561,26 +561,34 @@ self.fielddescr_tid = get_field_descr(gc_ll_descr, GCClass.HDR, 'tid') # self.jit_wb_if_flag = GCClass.JIT_WB_IF_FLAG -self.jit_wb_if_flag_byteofs, self.jit_wb_if_flag_singlebyte = ( +(self.jit_wb_if_flag_byteofs, + self.jit_wb_if_flag_singlebyte, + self.jit_wb_if_flag_bitpos) = ( self.extract_flag_byte(self.jit_wb_if_flag)) # if hasattr(GCClass, 'JIT_WB_CARDS_SET'): self.jit_wb_cards_set = GCClass.JIT_WB_CARDS_SET self.jit_wb_card_page_shift = GCClass.JIT_WB_CARD_PAGE_SHIFT -self.jit_wb_cards_set_byteofs, self.jit_wb_cards_set_singlebyte = ( +(self.jit_wb_cards_set_byteofs, + self.jit_wb_cards_set_singlebyte, + self.jit_wb_cards_set_bitpos) = ( self.extract_flag_byte(self.jit_wb_cards_set)) else: self.jit_wb_cards_set = 0 def extract_flag_byte(self, flag_word): # if convenient for the backend, we compute the info about -# the flag as (byte-offset, single-byte-flag). +# the flag as (byte-offset, single-byte-flag, bit-position-in-word). +# Note that flag_word == 1 bit_position_in_word. import struct value = struct.pack(l, flag_word) assert value.count('\x00') == len(value) - 1# only one byte is != 0 i = 0 while value[i] == '\x00': i += 1 -return (i, struct.unpack('b', value[i])[0]) +bitpos = 0 +while flag_word (1 bitpos): bitpos += 1 +assert flag_word == (1 bitpos) +return (i, struct.unpack('b', value[i])[0], bitpos) def get_write_barrier_fn(self, cpu): llop1 = self.llop1 diff --git a/pypy/jit/backend/ppc/ppcgen/opassembler.py b/pypy/jit/backend/ppc/ppcgen/opassembler.py --- a/pypy/jit/backend/ppc/ppcgen/opassembler.py +++ b/pypy/jit/backend/ppc/ppcgen/opassembler.py @@ -898,22 +898,14 @@ else: self.mc.ld(r.SCRATCH.value, loc_base.value, 0) -# offset to the byte we are interested in -byte_offset = descr.jit_wb_if_flag_byteofs -single_byte = descr.jit_wb_if_flag_singlebyte - -# examine which bit in the byte is set -for i in range(8): -if 1 i == single_byte: -n = i -break +# get the position of the bit we want to test +bitpos = descr.jit_wb_if_flag_bitpos if IS_PPC_32: -# compute the position of the bit we want to test -bitpos = (3 - byte_offset) * 8 + n -# ^^^ due to endianess # put this bit to the rightmost bitposition of r0 -self.mc.rlwinm(r.SCRATCH.value, r.SCRATCH.value, 32 - bitpos, 31, 31) +if bitpos 0: +self.mc.rlwinm(r.SCRATCH.value, r.SCRATCH.value, + 32 - bitpos, 31, 31) # test whether this bit is set self.mc.cmpwi(0, r.SCRATCH.value, 1) else: diff --git a/pypy/jit/backend/test/runner_test.py b/pypy/jit/backend/test/runner_test.py --- a/pypy/jit/backend/test/runner_test.py +++ b/pypy/jit/backend/test/runner_test.py @@ -1961,6 +1961,7 @@ jit_wb_if_flag = 4096 jit_wb_if_flag_byteofs = struct.pack(i, 4096).index('\x10') jit_wb_if_flag_singlebyte = 0x10 +jit_wb_if_flag_bitpos = 12 def get_write_barrier_fn(self, cpu): return funcbox.getint() # @@ -1998,6 +1999,7 @@ jit_wb_if_flag = 4096 jit_wb_if_flag_byteofs = struct.pack(i, 4096).index('\x10') jit_wb_if_flag_singlebyte = 0x10 +jit_wb_if_flag_bitpos = 12 jit_wb_cards_set = 0 def get_write_barrier_from_array_fn(self, cpu): return funcbox.getint() @@ -2044,9 +2046,11 @@ jit_wb_if_flag = 4096 jit_wb_if_flag_byteofs = struct.pack(i, 4096).index('\x10') jit_wb_if_flag_singlebyte = 0x10 +jit_wb_if_flag_bitpos = 12 jit_wb_cards_set = 8192 jit_wb_cards_set_byteofs = struct.pack(i, 8192).index('\x20') jit_wb_cards_set_singlebyte = 0x20 +jit_wb_cards_set_bitpos = 13 jit_wb_card_page_shift = 7 def get_write_barrier_from_array_fn(self, cpu): return funcbox.getint() ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ppc-jit-backend: add emit_force_token
Author: hager sven.ha...@uni-duesseldorf.de Branch: ppc-jit-backend Changeset: r50752:b3404ddd47d9 Date: 2011-12-15 18:26 +0100 http://bitbucket.org/pypy/pypy/changeset/b3404ddd47d9/ Log:add emit_force_token diff --git a/pypy/jit/backend/ppc/ppcgen/opassembler.py b/pypy/jit/backend/ppc/ppcgen/opassembler.py --- a/pypy/jit/backend/ppc/ppcgen/opassembler.py +++ b/pypy/jit/backend/ppc/ppcgen/opassembler.py @@ -948,6 +948,10 @@ class ForceOpAssembler(object): _mixin_ = True + +def emit_force_token(self, op, arglocs, regalloc): +res_loc = arglocs[0] +self.mc.mr(res_loc.value, r.SPP.value) # from: ../x86/assembler.py:1668 # XXX Split into some helper methods ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ppc-jit-backend: add convenience function for conditional absolute branches
Author: hager sven.ha...@uni-duesseldorf.de Branch: ppc-jit-backend Changeset: r50754:981b61e0d09a Date: 2011-12-20 15:31 +0100 http://bitbucket.org/pypy/pypy/changeset/981b61e0d09a/ Log:add convenience function for conditional absolute branches diff --git a/pypy/jit/backend/ppc/ppcgen/codebuilder.py b/pypy/jit/backend/ppc/ppcgen/codebuilder.py --- a/pypy/jit/backend/ppc/ppcgen/codebuilder.py +++ b/pypy/jit/backend/ppc/ppcgen/codebuilder.py @@ -1007,6 +1007,13 @@ target_ofs = offset - pos self.bc(condition, 2, target_ofs) +def b_cond_abs(self, addr, condition): +assert condition in (c.EQ, c.NE) +self.alloc_scratch_reg(addr) +self.mtctr(r.SCRATCH.value) +self.free_scratch_reg() +self.bcctr(condition, 2) + def b_abs(self, address, trap=False): self.alloc_scratch_reg(address) self.mtctr(r.r0.value) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ppc-jit-backend: begin of exceptopn handling during memory allocation
Author: hager sven.ha...@uni-duesseldorf.de Branch: ppc-jit-backend Changeset: r50755:81c255a5fb96 Date: 2011-12-20 15:36 +0100 http://bitbucket.org/pypy/pypy/changeset/81c255a5fb96/ Log:begin of exceptopn handling during memory allocation diff --git a/pypy/jit/backend/ppc/ppcgen/opassembler.py b/pypy/jit/backend/ppc/ppcgen/opassembler.py --- a/pypy/jit/backend/ppc/ppcgen/opassembler.py +++ b/pypy/jit/backend/ppc/ppcgen/opassembler.py @@ -838,7 +838,7 @@ self.mc.std(r.r0.value, r.r3.value, self.cpu.vtable_offset) def emit_new_array(self, op, arglocs, regalloc): -# XXX handle memory errors +self.propagate_memoryerror_if_r3_is_null() if len(arglocs) 0: value_loc, base_loc, ofs_length = arglocs if IS_PPC_32: diff --git a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py --- a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py +++ b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py @@ -102,6 +102,7 @@ self.current_clt = None self._regalloc = None self.max_stack_params = 0 +self.propagate_exception_path = 0 def _save_nonvolatiles(self): save nonvolatile GPRs in GPR SAVE AREA @@ -290,6 +291,21 @@ locs.append(loc) return locs +def _build_propagate_exception_path(self): +if self.cpu.propagate_exception_v 0: +return + +mc = PPCBuilder() +with Saved_Volatiles(mc): +addr = self.cpu.get_on_leave_jitted_int(save_exception=True) +mc.bl_abs(addr) +#mc.alloc_scratch_reg(self.cpu.propagate_exception_v) +#mc.mr(r.RES.value, r.SCRATCH.value) +#mc.free_scratch_reg() +mc.load_imm(r.RES, self.cpu.propagate_exception_v) +mc.prepare_insts_blocks() +self.propagate_exception_path = mc.materialize(self.cpu.asmmemmgr, []) + def _gen_leave_jitted_hook_code(self, save_exc=False): mc = PPCBuilder() @@ -328,7 +344,7 @@ # load parameters into parameter registers if IS_PPC_32: mc.lwz(r.r3.value, r.SPP.value, self.ENCODING_AREA) # address of state encoding -else: +else: mc.ld(r.r3.value, r.SPP.value, self.ENCODING_AREA) mc.mr(r.r4.value, r.SP.value) # load stack pointer mc.mr(r.r5.value, r.SPP.value) # load spilling pointer @@ -495,6 +511,7 @@ gc_ll_descr.initialize() ll_new = gc_ll_descr.get_funcptr_for_new() self.malloc_func_addr = rffi.cast(lltype.Signed, ll_new) +self._build_propagate_exception_path() if gc_ll_descr.get_funcptr_for_newarray is not None: ll_new_array = gc_ll_descr.get_funcptr_for_newarray() self.malloc_array_func_addr = rffi.cast(lltype.Signed, @@ -955,6 +972,10 @@ assert gcrootmap.is_shadow_stack gcrootmap.write_callshape(mark, force_index) +def propagate_memoryerror_if_r3_is_null(self): +self.mc.cmp_op(0, r.RES.value, 0, imm=True) +self.mc.b_cond_abs(self.propagate_exception_path, c.EQ) + def write_new_force_index(self): # for shadowstack only: get a new, unused force_index number and # write it to FORCE_INDEX_OFS. Used to record the call shape ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Change again the repr of CallDescrs, this time to standardize the format
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r50757:b3fc00ecbb30 Date: 2011-12-20 13:55 + http://bitbucket.org/pypy/pypy/changeset/b3fc00ecbb30/ Log:Change again the repr of CallDescrs, this time to standardize the format with the other Descrs and to include more information. 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 @@ -425,7 +425,15 @@ self.arg_classes.count('L')) == len(args_f or ()) def repr_of_descr(self): -return 'CallDescr(%s/%s)' % (self.arg_classes, self.result_type) +res = 'Call%s %d' % (self.result_type, self.result_size) +if self.arg_classes: +res += ' ' + self.arg_classes +if self.extrainfo: +res += ' EF=%d' % self.extrainfo.extraeffect +oopspecindex = self.extrainfo.oopspecindex +if oopspecindex: +res += ' OS=%d' % oopspecindex +return '%s' % res def map_type_to_argclass(ARG, accept_void=False): diff --git a/pypy/jit/backend/llsupport/test/test_descr.py b/pypy/jit/backend/llsupport/test/test_descr.py --- a/pypy/jit/backend/llsupport/test/test_descr.py +++ b/pypy/jit/backend/llsupport/test/test_descr.py @@ -342,16 +342,16 @@ assert repr_of_descr(descr3i) == 'ArrayU 1' # descr4 = get_call_descr(c0, [lltype.Char, lltype.Ptr(S)], lltype.Ptr(S)) -assert repr_of_descr(descr4) == 'CallDescr(ir/r)' +assert repr_of_descr(descr4) == 'Callr %d ir' % o # descr4i = get_call_descr(c0, [lltype.Char, lltype.Ptr(S)], lltype.Char) -assert repr_of_descr(descr4i) == 'CallDescr(ir/i)' +assert repr_of_descr(descr4i) == 'Calli 1 ir' # descr4f = get_call_descr(c0, [lltype.Char, lltype.Ptr(S)], lltype.Float) -assert repr_of_descr(descr4f) == 'CallDescr(ir/f)' +assert repr_of_descr(descr4f) == 'Callf 8 ir' # descr5f = get_call_descr(c0, [lltype.Char], lltype.SingleFloat) -assert repr_of_descr(descr5f) == 'CallDescr(i/S)' +assert repr_of_descr(descr5f) == 'CallS 4 i' def test_call_stubs_1(): c0 = GcCache(False) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: - fix the tests to expect the new format of descrs.
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r50758:85a5e1fe1ad8 Date: 2011-12-20 14:53 + http://bitbucket.org/pypy/pypy/changeset/85a5e1fe1ad8/ Log:- fix the tests to expect the new format of descrs. - fix match() to always raise InvalidMatch if the match fails because I found that at least one test was not doing assert match(..) but just match(..) which always passes... - test_generator still fails, but that should be fixed on the new version of the 'counter-decay' branch. diff --git a/pypy/module/pypyjit/test_pypy_c/model.py b/pypy/module/pypyjit/test_pypy_c/model.py --- a/pypy/module/pypyjit/test_pypy_c/model.py +++ b/pypy/module/pypyjit/test_pypy_c/model.py @@ -311,7 +311,7 @@ # to repeat it every time ticker_check = guard_not_invalidated? -ticker0 = getfield_raw(ticker_address, descr=SignedFieldDescr pypysig_long_struct.c_value .*) +ticker0 = getfield_raw(ticker_address, descr=FieldS pypysig_long_struct.c_value .*) ticker_cond0 = int_lt(ticker0, 0) guard_false(ticker_cond0, descr=...) @@ -320,9 +320,9 @@ # this is the ticker check generated if we have threads thread_ticker_check = guard_not_invalidated? -ticker0 = getfield_raw(ticker_address, descr=SignedFieldDescr pypysig_long_struct.c_value .*) +ticker0 = getfield_raw(ticker_address, descr=FieldS pypysig_long_struct.c_value .*) ticker1 = int_sub(ticker0, _) -setfield_raw(ticker_address, ticker1, descr=SignedFieldDescr pypysig_long_struct.c_value .*) +setfield_raw(ticker_address, ticker1, descr=FieldS pypysig_long_struct.c_value .*) ticker_cond0 = int_lt(ticker1, 0) guard_false(ticker_cond0, descr=...) @@ -330,7 +330,7 @@ # # this is the ticker check generated in PyFrame.handle_operation_error exc_ticker_check = -ticker2 = getfield_raw(ticker_address, descr=SignedFieldDescr pypysig_long_struct.c_value .*) +ticker2 = getfield_raw(ticker_address, descr=FieldS pypysig_long_struct.c_value .*) ticker_cond1 = int_lt(ticker2, 0) guard_false(ticker_cond1, descr=...) @@ -451,7 +451,6 @@ try: self.match_loop(expected_ops, ignore_ops) except InvalidMatch, e: -#raise # uncomment this and use py.test --pdb for better debugging print '@' * 40 print Loops don't match print = @@ -464,7 +463,7 @@ print print Expected: print format(expected_src) -return False +raise # always propagate the exception in case of mismatch else: return True diff --git a/pypy/module/pypyjit/test_pypy_c/test_00_model.py b/pypy/module/pypyjit/test_pypy_c/test_00_model.py --- a/pypy/module/pypyjit/test_pypy_c/test_00_model.py +++ b/pypy/module/pypyjit/test_pypy_c/test_00_model.py @@ -7,8 +7,9 @@ from pypy.tool.udir import udir from pypy.tool import logparser from pypy.jit.tool.jitoutput import parse_prof -from pypy.module.pypyjit.test_pypy_c.model import Log, find_ids_range, find_ids, \ -TraceWithIds, OpMatcher +from pypy.module.pypyjit.test_pypy_c.model import (Log, find_ids_range, + find_ids, TraceWithIds, + OpMatcher, InvalidMatch) class BaseTestPyPyC(object): def setup_class(cls): @@ -115,13 +116,18 @@ assert opcodes_names == ['LOAD_FAST', 'LOAD_CONST', 'BINARY_ADD', 'STORE_FAST'] -class TestOpMatcher(object): +class TestOpMatcher_(object): def match(self, src1, src2, **kwds): from pypy.tool.jitlogparser.parser import SimpleParser loop = SimpleParser.parse_from_input(src1) matcher = OpMatcher(loop.operations) -return matcher.match(src2, **kwds) +try: +res = matcher.match(src2, **kwds) +assert res is True +return True +except InvalidMatch: +return False def test_match_var(self): match_var = OpMatcher([]).match_var @@ -447,7 +453,7 @@ jump(p0, p1, p2, p3, i8, descr=...) ) # -assert not loop.match( +py.test.raises(InvalidMatch, loop.match, i6 = int_lt(i4, 1003) guard_true(i6) i8 = int_add(i5, 1) # variable mismatch @@ -492,9 +498,8 @@ guard_no_exception(descr=...) ) # -assert not loop.match_by_id('ntohs', +py.test.raises(InvalidMatch, loop.match_by_id, 'ntohs', guard_not_invalidated(descr=...) p12 = call(ConstClass(foobar), 1, descr=...) guard_no_exception(descr=...) ) - diff --git
[pypy-commit] pypy counter-decay: hg merge default
Author: Armin Rigo ar...@tunes.org Branch: counter-decay Changeset: r50759:5330b853e079 Date: 2011-12-20 14:54 + http://bitbucket.org/pypy/pypy/changeset/5330b853e079/ Log:hg merge default 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 @@ -425,7 +425,15 @@ self.arg_classes.count('L')) == len(args_f or ()) def repr_of_descr(self): -return 'CallDescr(%s,%s)' % (self.arg_classes, self.result_type) +res = 'Call%s %d' % (self.result_type, self.result_size) +if self.arg_classes: +res += ' ' + self.arg_classes +if self.extrainfo: +res += ' EF=%d' % self.extrainfo.extraeffect +oopspecindex = self.extrainfo.oopspecindex +if oopspecindex: +res += ' OS=%d' % oopspecindex +return '%s' % res def map_type_to_argclass(ARG, accept_void=False): diff --git a/pypy/jit/backend/llsupport/test/test_descr.py b/pypy/jit/backend/llsupport/test/test_descr.py --- a/pypy/jit/backend/llsupport/test/test_descr.py +++ b/pypy/jit/backend/llsupport/test/test_descr.py @@ -313,6 +313,10 @@ def test_repr_of_descr(): +def repr_of_descr(descr): +s = descr.repr_of_descr() +assert ',' not in s # makes the life easier for pypy.tool.jitlogparser +return s c0 = GcCache(False) T = lltype.GcStruct('T') S = lltype.GcStruct('S', ('x', lltype.Char), @@ -320,34 +324,34 @@ ('z', lltype.Ptr(T))) descr1 = get_size_descr(c0, S) s = symbolic.get_size(S, False) -assert descr1.repr_of_descr() == 'SizeDescr %d' % s +assert repr_of_descr(descr1) == 'SizeDescr %d' % s # descr2 = get_field_descr(c0, S, 'y') o, _ = symbolic.get_field_token(S, 'y', False) -assert descr2.repr_of_descr() == 'FieldP S.y %d' % o +assert repr_of_descr(descr2) == 'FieldP S.y %d' % o # descr2i = get_field_descr(c0, S, 'x') o, _ = symbolic.get_field_token(S, 'x', False) -assert descr2i.repr_of_descr() == 'FieldU S.x %d' % o +assert repr_of_descr(descr2i) == 'FieldU S.x %d' % o # descr3 = get_array_descr(c0, lltype.GcArray(lltype.Ptr(S))) o = symbolic.get_size(lltype.Ptr(S), False) -assert descr3.repr_of_descr() == 'ArrayP %d' % o +assert repr_of_descr(descr3) == 'ArrayP %d' % o # descr3i = get_array_descr(c0, lltype.GcArray(lltype.Char)) -assert descr3i.repr_of_descr() == 'ArrayU 1' +assert repr_of_descr(descr3i) == 'ArrayU 1' # descr4 = get_call_descr(c0, [lltype.Char, lltype.Ptr(S)], lltype.Ptr(S)) -assert descr4.repr_of_descr() == 'CallDescr(ir,r)' +assert repr_of_descr(descr4) == 'Callr %d ir' % o # descr4i = get_call_descr(c0, [lltype.Char, lltype.Ptr(S)], lltype.Char) -assert descr4i.repr_of_descr() == 'CallDescr(ir,i)' +assert repr_of_descr(descr4i) == 'Calli 1 ir' # descr4f = get_call_descr(c0, [lltype.Char, lltype.Ptr(S)], lltype.Float) -assert descr4f.repr_of_descr() == 'CallDescr(ir,f)' +assert repr_of_descr(descr4f) == 'Callf 8 ir' # descr5f = get_call_descr(c0, [lltype.Char], lltype.SingleFloat) -assert descr5f.repr_of_descr() == 'CallDescr(i,S)' +assert repr_of_descr(descr5f) == 'CallS 4 i' def test_call_stubs_1(): c0 = GcCache(False) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py b/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py --- a/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py @@ -1,3 +1,4 @@ +from __future__ import with_statement from pypy.jit.metainterp.optimizeopt.test.test_util import ( LLtypeMixin, BaseTest, Storage, _sortboxes, FakeDescrWithSnapshot) from pypy.jit.metainterp.history import TreeLoop, JitCellToken, TargetToken diff --git a/pypy/module/pypyjit/test_pypy_c/model.py b/pypy/module/pypyjit/test_pypy_c/model.py --- a/pypy/module/pypyjit/test_pypy_c/model.py +++ b/pypy/module/pypyjit/test_pypy_c/model.py @@ -311,7 +311,7 @@ # to repeat it every time ticker_check = guard_not_invalidated? -ticker0 = getfield_raw(ticker_address, descr=SignedFieldDescr pypysig_long_struct.c_value .*) +ticker0 = getfield_raw(ticker_address, descr=FieldS pypysig_long_struct.c_value .*) ticker_cond0 = int_lt(ticker0, 0) guard_false(ticker_cond0, descr=...) @@ -320,9 +320,9 @@ # this is the ticker check generated if we have threads thread_ticker_check = guard_not_invalidated? -ticker0 = getfield_raw(ticker_address, descr=SignedFieldDescr pypysig_long_struct.c_value .*) +ticker0 = getfield_raw(ticker_address, descr=FieldS pypysig_long_struct.c_value .*) ticker1 = int_sub(ticker0, _) -
[pypy-commit] pypy set-strategies: better approach for merging sets with lists
Author: Lukas Diekmann lukas.diekm...@uni-duesseldorf.de Branch: set-strategies Changeset: r50760:01dbcc06249a Date: 2011-12-20 16:19 +0100 http://bitbucket.org/pypy/pypy/changeset/01dbcc06249a/ Log:better approach for merging sets with lists diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py --- a/pypy/objspace/std/listobject.py +++ b/pypy/objspace/std/listobject.py @@ -193,6 +193,11 @@ Return the items in the list as unwrapped strings. If the list does not use the list strategy, return None. return self.strategy.getitems_str(self) + +def getitems_int(self): + Return the items in the list as unwrapped strings. If the list does +not use the list strategy, return None. +return self.strategy.getitems_int(self) # ___ @@ -292,6 +297,9 @@ def getitems_str(self, w_list): return None +def getitems_int(self, w_list): +return None + def getstorage_copy(self, w_list): raise NotImplementedError @@ -502,17 +510,15 @@ raise IndexError return start + i * step +def getitems_int(self, w_list): +return self._getitems_range(w_list, False) + def getitem(self, w_list, i): return self.wrap(self._getitem_unwrapped(w_list, i)) def getitems_copy(self, w_list): return self._getitems_range(w_list, True) -getitems_wrapped = getitems_copy - -def getitems_unwrapped(self, w_list): -return self._getitems_range(w_list, False) - def getstorage_copy(self, w_list): # tuple is unmutable return w_list.lstorage @@ -703,11 +709,6 @@ def getitems_copy(self, w_list): return [self.wrap(item) for item in self.unerase(w_list.lstorage)] -getitems_wrapped = getitems_copy - -def getitems_unwrapped(self, w_list): -return self.unerase(w_list.lstorage) - @jit.unroll_safe def getitems_unroll(self, w_list): return [self.wrap(item) for item in self.unerase(w_list.lstorage)] @@ -936,8 +937,6 @@ def getitems(self, w_list): return self.unerase(w_list.lstorage) -getitems_wrapped = getitems - class IntegerListStrategy(AbstractUnwrappedStrategy, ListStrategy): _none_value = 0 _applevel_repr = int @@ -965,6 +964,9 @@ if reverse: l.reverse() +def getitems_int(self, w_list): +return self.unerase(w_list.lstorage) + class FloatListStrategy(AbstractUnwrappedStrategy, ListStrategy): _none_value = 0.0 _applevel_repr = float @@ -1022,7 +1024,6 @@ def getitems_str(self, w_list): return self.unerase(w_list.lstorage) - # ___ init_signature = Signature(['sequence'], None, None) diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py --- a/pypy/objspace/std/objspace.py +++ b/pypy/objspace/std/objspace.py @@ -440,6 +440,11 @@ return w_obj.getitems_str() return None +def listview_int(self, w_obj): +if isinstance(w_obj, W_ListObject): +return w_obj.getitems_int() +return None + def sliceindices(self, w_slice, w_length): if isinstance(w_slice, W_SliceObject): a, b, c = w_slice.indices3(self, self.int_w(w_length)) diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py --- a/pypy/objspace/std/setobject.py +++ b/pypy/objspace/std/setobject.py @@ -13,8 +13,6 @@ from pypy.objspace.std.listobject import W_ListObject from pypy.objspace.std.intobject import W_IntObject from pypy.objspace.std.stringobject import W_StringObject -from pypy.objspace.std.listobject import IntegerListStrategy, StringListStrategy,\ -EmptyListStrategy, RangeListStrategy, ObjectListStrategy, FloatListStrategy class W_BaseSetObject(W_Object): typedef = None @@ -282,9 +280,6 @@ def get_empty_storage(self): return self.erase(None) -def get_storage_from_w_list(self, w_list): -return self.get_empty_storage() - def is_correct_type(self, w_key): return False @@ -389,9 +384,7 @@ setdata[self.unwrap(w_item)] = None return self.erase(setdata) -def get_storage_from_w_list(self, w_list): -items = w_list.strategy.getitems_unwrapped(w_list) - +def get_storage_from_unwrapped_list(self, items): setdata = self.get_empty_dict() for item in items: setdata[item] = None @@ -759,14 +752,6 @@ def get_empty_storage(self): return self.erase(self.get_empty_dict()) -def get_storage_from_w_list(self, w_list): -items = w_list.strategy.getitems_wrapped(w_list) - -setdata = self.get_empty_dict() -for item in items: -setdata[item] = None -return self.erase(setdata) - def get_empty_dict(self): return newset(self.space) @@
[pypy-commit] pypy counter-decay: Fix the test.
Author: Armin Rigo ar...@tunes.org Branch: counter-decay Changeset: r50761:083617e059dd Date: 2011-12-20 16:13 + http://bitbucket.org/pypy/pypy/changeset/083617e059dd/ Log:Fix the test. diff --git a/pypy/module/pypyjit/test_pypy_c/test_generators.py b/pypy/module/pypyjit/test_pypy_c/test_generators.py --- a/pypy/module/pypyjit/test_pypy_c/test_generators.py +++ b/pypy/module/pypyjit/test_pypy_c/test_generators.py @@ -21,9 +21,9 @@ assert loop.match_by_id(generator, i16 = force_token() p45 = new_with_vtable(ConstClass(W_IntObject)) -setfield_gc(p45, i29, descr=SignedFieldDescr .*) -setarrayitem_gc(p8, 0, p45, descr=GcPtrArrayDescr) -i47 = arraylen_gc(p8, descr=GcPtrArrayDescr) # Should be removed by backend +setfield_gc(p45, i29, descr=FieldS .*) +setarrayitem_gc(p8, 0, p45, descr=ArrayP .) +i47 = arraylen_gc(p8, descr=ArrayP .) # Should be removed by backend jump(..., descr=...) ) assert loop.match_by_id(subtract, ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy counter-decay: The basic threshold is now larger by 2% than it used to be.
Author: Armin Rigo ar...@tunes.org Branch: counter-decay Changeset: r50762:91ce4e8c26be Date: 2011-12-20 16:15 + http://bitbucket.org/pypy/pypy/changeset/91ce4e8c26be/ Log:The basic threshold is now larger by 2% than it used to be. diff --git a/pypy/module/pypyjit/test_pypy_c/test_misc.py b/pypy/module/pypyjit/test_pypy_c/test_misc.py --- a/pypy/module/pypyjit/test_pypy_c/test_misc.py +++ b/pypy/module/pypyjit/test_pypy_c/test_misc.py @@ -46,7 +46,7 @@ r *= n n -= 1 return r -log = self.run(fact, [7], threshold=5) +log = self.run(fact, [7], threshold=4) assert log.result == 5040 loop, = log.loops_by_filename(self.filepath) assert loop.match( diff --git a/pypy/module/pypyjit/test_pypy_c/test_string.py b/pypy/module/pypyjit/test_pypy_c/test_string.py --- a/pypy/module/pypyjit/test_pypy_c/test_string.py +++ b/pypy/module/pypyjit/test_pypy_c/test_string.py @@ -55,8 +55,8 @@ i += int(long(string.digits[i % len(string.digits)], 16)) return i -log = self.run(main, [1000]) -assert log.result == main(1000) +log = self.run(main, [1100]) +assert log.result == main(1100) loop, = log.loops_by_filename(self.filepath) assert loop.match( i11 = int_lt(i6, i7) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ppc-jit-backend: (arigo, hager): Remove unnecessary argument from decoding function
Author: hager sven.ha...@uni-duesseldorf.de Branch: ppc-jit-backend Changeset: r50763:fa0b1ce8e088 Date: 2011-12-20 16:18 +0100 http://bitbucket.org/pypy/pypy/changeset/fa0b1ce8e088/ Log:(arigo, hager): Remove unnecessary argument from decoding function diff --git a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py --- a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py +++ b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py @@ -177,35 +177,28 @@ def setup_failure_recovery(self): @rgc.no_collect -def failure_recovery_func(mem_loc, stack_pointer, spilling_pointer): +def failure_recovery_func(mem_loc, spilling_pointer): mem_loc is a structure in memory describing where the values for the failargs are stored. - -stack_pointer is the address of top of the stack. spilling_pointer is the address of the FORCE_INDEX. -return self.decode_registers_and_descr(mem_loc, stack_pointer, -spilling_pointer) +return self.decode_registers_and_descr(mem_loc, spilling_pointer) self.failure_recovery_func = failure_recovery_func recovery_func_sign = lltype.Ptr(lltype.FuncType([lltype.Signed, -lltype.Signed, lltype.Signed], lltype.Signed)) +lltype.Signed], lltype.Signed)) @rgc.no_collect -def decode_registers_and_descr(self, mem_loc, stack_loc, spp_loc): +def decode_registers_and_descr(self, mem_loc, spp_loc): ''' mem_loc : pointer to encoded state -stack_loc : pointer to top of the stack spp_loc : pointer to begin of the spilling area ''' enc = rffi.cast(rffi.CCHARP, mem_loc) managed_size = WORD * len(r.MANAGED_REGS) - -assert spp_loc stack_loc - regs = rffi.cast(rffi.CCHARP, spp_loc) i = -1 fail_index = -1 @@ -346,8 +339,7 @@ mc.lwz(r.r3.value, r.SPP.value, self.ENCODING_AREA) # address of state encoding else: mc.ld(r.r3.value, r.SPP.value, self.ENCODING_AREA) -mc.mr(r.r4.value, r.SP.value) # load stack pointer -mc.mr(r.r5.value, r.SPP.value) # load spilling pointer +mc.mr(r.r4.value, r.SPP.value) # load spilling pointer # # load address of decoding function into SCRATCH mc.alloc_scratch_reg(addr) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge counter-decay again: simplified version, just requiring 2%
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r50767:a21cab6475c1 Date: 2011-12-20 19:09 +0100 http://bitbucket.org/pypy/pypy/changeset/a21cab6475c1/ Log:merge counter-decay again: simplified version, just requiring 2% extra counts on loops if a piece of assembler has been produced in the meantime. See included explanations for motivation. diff --git a/pypy/jit/metainterp/test/test_warmstate.py b/pypy/jit/metainterp/test/test_warmstate.py --- a/pypy/jit/metainterp/test/test_warmstate.py +++ b/pypy/jit/metainterp/test/test_warmstate.py @@ -275,3 +275,52 @@ state.make_jitdriver_callbacks() res = state.can_never_inline(5, 42.5) assert res is True + +def test_cleanup_jitcell_dict(): +class FakeJitDriverSD: +_green_args_spec = [lltype.Signed] +# +# Test creating tons of jitcells that remain at 0 +warmstate = WarmEnterState(None, FakeJitDriverSD()) +get_jitcell = warmstate._make_jitcell_getter_default() +cell1 = get_jitcell(True, -1) +assert len(warmstate._jitcell_dict) == 1 +# +for i in range(1, 20005): +get_jitcell(True, i) # should trigger a clean-up at 20001 +assert len(warmstate._jitcell_dict) == (i % 2) + 1 +# +# Same test, with one jitcell that has a counter of BASE instead of 0 +warmstate = WarmEnterState(None, FakeJitDriverSD()) +get_jitcell = warmstate._make_jitcell_getter_default() +cell2 = get_jitcell(True, -2) +cell2.counter = BASE = warmstate.THRESHOLD_LIMIT // 2# 50% +# +for i in range(0, 20005): +get_jitcell(True, i) +assert len(warmstate._jitcell_dict) == (i % 1) + 2 +# +assert cell2 in warmstate._jitcell_dict.values() +assert cell2.counter == int(BASE * 0.92) # decayed once +# +# Same test, with jitcells that are compiled and freed by the memmgr +warmstate = WarmEnterState(None, FakeJitDriverSD()) +get_jitcell = warmstate._make_jitcell_getter_default() +get_jitcell(True, -1) +# +for i in range(1, 20005): +cell = get_jitcell(True, i) +cell.counter = -1 +cell.wref_procedure_token = None# or a dead weakref, equivalently +assert len(warmstate._jitcell_dict) == (i % 2) + 1 +# +# Same test, with counter == -2 (rare case, kept alive) +warmstate = WarmEnterState(None, FakeJitDriverSD()) +get_jitcell = warmstate._make_jitcell_getter_default() +cell = get_jitcell(True, -1) +cell.counter = -2 +# +for i in range(1, 20005): +cell = get_jitcell(True, i) +cell.counter = -2 +assert len(warmstate._jitcell_dict) == i + 1 diff --git a/pypy/jit/metainterp/warmstate.py b/pypy/jit/metainterp/warmstate.py --- a/pypy/jit/metainterp/warmstate.py +++ b/pypy/jit/metainterp/warmstate.py @@ -151,6 +151,7 @@ # counter == -2: tracing is currently going on for this cell counter = 0 dont_trace_here = False +extra_delay = chr(0) wref_procedure_token = None def get_procedure_token(self): @@ -172,7 +173,6 @@ class WarmEnterState(object): THRESHOLD_LIMIT = sys.maxint // 2 -default_jitcell_dict = None def __init__(self, warmrunnerdesc, jitdriver_sd): NOT_RPYTHON @@ -316,6 +316,36 @@ # assert 0, should have raised +def bound_reached(cell, *args): +# bound reached, but we do a last check: if it is the first +# time we reach the bound, or if another loop or bridge was +# compiled since the last time we reached it, then decrease +# the counter by a few percents instead. It should avoid +# sudden bursts of JIT-compilation, and also corner cases +# where we suddenly compile more than one loop because all +# counters reach the bound at the same time, but where +# compiling all but the first one is pointless. +curgen = warmrunnerdesc.memory_manager.current_generation +curgen = chr(intmask(curgen) 0xFF)# only use 8 bits +if we_are_translated() and curgen != cell.extra_delay: +cell.counter = int(self.THRESHOLD_LIMIT * 0.98) +cell.extra_delay = curgen +return +# +if not confirm_enter_jit(*args): +cell.counter = 0 +return +# start tracing +from pypy.jit.metainterp.pyjitpl import MetaInterp +metainterp = MetaInterp(metainterp_sd, jitdriver_sd) +# set counter to -2, to mean tracing in effect +cell.counter = -2 +try: +metainterp.compile_and_run_once(jitdriver_sd, *args) +finally: +if cell.counter == -2: +cell.counter = 0 + def maybe_compile_and_run(threshold, *args): Entry point to the JIT. Called at the point with the can_enter_jit()
[pypy-commit] pypy refactor-signature: call create_sig instead of array_sig, for symmetry mostly
Author: Maciej Fijalkowski fij...@gmail.com Branch: refactor-signature Changeset: r50768:a9d8fe792078 Date: 2011-12-20 21:12 +0200 http://bitbucket.org/pypy/pypy/changeset/a9d8fe792078/ Log:call create_sig instead of array_sig, for symmetry mostly diff --git a/pypy/module/micronumpy/REVIEW.txt b/pypy/module/micronumpy/REVIEW.txt --- a/pypy/module/micronumpy/REVIEW.txt +++ b/pypy/module/micronumpy/REVIEW.txt @@ -1,8 +1,6 @@ REVIEW NOTES -* Scalar.reshape should turn the value into an array correct for an input of - ``1`` or ``(1,)``. * VirtualSlice vs. W_NDimSlice? * Call{1, 2}.create_sig, should it call forced_result.create_sig(), instead of array_sig()? If not, why not? 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 @@ -753,7 +753,7 @@ def create_sig(self, res_shape): if self.forced_result is not None: -return self.forced_result.array_sig(res_shape) +return self.forced_result.create_sig(res_shape) return signature.Call1(self.ufunc, self.name, self.values.create_sig(res_shape)) @@ -777,7 +777,7 @@ def create_sig(self, res_shape): if self.forced_result is not None: -return self.forced_result.array_sig(res_shape) +return self.forced_result.create_sig(res_shape) return signature.Call2(self.ufunc, self.name, self.calc_dtype, self.left.create_sig(res_shape), self.right.create_sig(res_shape)) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-signature: call directly parent class init
Author: Maciej Fijalkowski fij...@gmail.com Branch: refactor-signature Changeset: r50769:26c22a795ee9 Date: 2011-12-20 21:14 +0200 http://bitbucket.org/pypy/pypy/changeset/26c22a795ee9/ Log:call directly parent class init diff --git a/pypy/module/micronumpy/REVIEW.txt b/pypy/module/micronumpy/REVIEW.txt --- a/pypy/module/micronumpy/REVIEW.txt +++ b/pypy/module/micronumpy/REVIEW.txt @@ -2,8 +2,6 @@ * VirtualSlice vs. W_NDimSlice? -* Call{1, 2}.create_sig, should it call forced_result.create_sig(), instead of - array_sig()? If not, why not? * W_NDimSlice.__init__ calls ConcreteArray.__init__ instead of ViewArray.__init__, W_FlatIterator as well. * Better names for sigeq and sigeq2, sighash doesn't say if numberings are 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 @@ -970,7 +970,7 @@ size *= sh self.strides = strides self.backstrides = backstrides -ConcreteArray.__init__(self, size, shape, parent.dtype, parent.order, +ViewArray.__init__(self, size, shape, parent.dtype, parent.order, parent) self.start = start @@ -1224,7 +1224,7 @@ size *= sh self.strides = [arr.strides[-1]] self.backstrides = [arr.backstrides[-1]] -ConcreteArray.__init__(self, size, [size], arr.dtype, arr.order, +ViewArray.__init__(self, size, [size], arr.dtype, arr.order, arr) self.shapelen = len(arr.shape) self.iter = OneDimIterator(arr.start, self.strides[0], ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-signature: improve names a bit
Author: Maciej Fijalkowski fij...@gmail.com Branch: refactor-signature Changeset: r50770:034b7e34339e Date: 2011-12-20 21:16 +0200 http://bitbucket.org/pypy/pypy/changeset/034b7e34339e/ Log:improve names a bit diff --git a/pypy/module/micronumpy/REVIEW.txt b/pypy/module/micronumpy/REVIEW.txt --- a/pypy/module/micronumpy/REVIEW.txt +++ b/pypy/module/micronumpy/REVIEW.txt @@ -4,8 +4,6 @@ * VirtualSlice vs. W_NDimSlice? * W_NDimSlice.__init__ calls ConcreteArray.__init__ instead of ViewArray.__init__, W_FlatIterator as well. -* Better names for sigeq and sigeq2, sighash doesn't say if numberings are - included in the hash. * Cleanup of the iterator and array caching/numbering. It's a mess right now: * _creater_iter updates the arraylist * Why do Scalars need an iterator at all? diff --git a/pypy/module/micronumpy/signature.py b/pypy/module/micronumpy/signature.py --- a/pypy/module/micronumpy/signature.py +++ b/pypy/module/micronumpy/signature.py @@ -8,7 +8,9 @@ def sigeq(one, two): return one.eq(two) -def sigeq2(one, two): +def sigeq_numbering(one, two): + Cache for iterator numbering should not compare array numbers + return one.eq(two, compare_array_no=False) def sighash(sig): @@ -71,7 +73,7 @@ iter_no = 0 def invent_numbering(self): -cache = r_dict(sigeq2, sighash) +cache = r_dict(sigeq_numbering, sighash) allnumbers = [] self._invent_numbering(cache, allnumbers) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ppc-jit-backend: factored out some distinctions of cases between PPC32 and PPC64
Author: hager sven.ha...@uni-duesseldorf.de Branch: ppc-jit-backend Changeset: r50771:17e99f1ed45a Date: 2011-12-20 20:30 +0100 http://bitbucket.org/pypy/pypy/changeset/17e99f1ed45a/ Log:factored out some distinctions of cases between PPC32 and PPC64 diff --git a/pypy/jit/backend/ppc/ppcgen/codebuilder.py b/pypy/jit/backend/ppc/ppcgen/codebuilder.py --- a/pypy/jit/backend/ppc/ppcgen/codebuilder.py +++ b/pypy/jit/backend/ppc/ppcgen/codebuilder.py @@ -1033,6 +1033,30 @@ self.free_scratch_reg() self.bctrl() +def load(self, target_reg, base_reg, offset): +if IS_PPC_32: +self.lwz(target_reg, base_reg, offset) +else: +self.ld(target_reg, base_reg, offset) + +def loadx(self, target_reg, base_reg, offset_reg): +if IS_PPC_32: +self.lwzx(target_reg, base_reg, offset_reg) +else: +self.ldx(target_reg, base_reg. offset_reg) + +def store(self, from_reg, base_reg, offset): +if IS_PPC_32: +self.stw(from_reg, base_reg, offset) +else: +self.std(from_reg, base_reg, offset) + +def storex(self, from_reg, base_reg, offset_reg): +if IS_PPC_32: +self.stwx(from_reg, base_reg, offset_reg) +else: +self.stdx(from_reg, base_reg, offset_reg) + def prepare_insts_blocks(self, show=False): self.assemble(show) insts = self.insts diff --git a/pypy/jit/backend/ppc/ppcgen/opassembler.py b/pypy/jit/backend/ppc/ppcgen/opassembler.py --- a/pypy/jit/backend/ppc/ppcgen/opassembler.py +++ b/pypy/jit/backend/ppc/ppcgen/opassembler.py @@ -191,35 +191,28 @@ def emit_guard_true(self, op, arglocs, regalloc): l0 = arglocs[0] failargs = arglocs[1:] -if IS_PPC_32: -self.mc.cmpwi(l0.value, 0) -else: -self.mc.cmpdi(l0.value, 0) +self.mc.cmp_op(0, l0.value, 0, imm=True) self._emit_guard(op, failargs, c.EQ) ## If this condition is met, ## then the guard fails. def emit_guard_false(self, op, arglocs, regalloc): -l0 = arglocs[0] -failargs = arglocs[1:] -if IS_PPC_32: -self.mc.cmpwi(l0.value, 0) -else: -self.mc.cmpdi(l0.value, 0) -self._emit_guard(op, failargs, c.NE) +l0 = arglocs[0] +failargs = arglocs[1:] +self.mc.cmp_op(0, l0.value, 0, imm=True) +self._emit_guard(op, failargs, c.NE) # TODO - Evaluate whether this can be done with #SO bit instead of OV bit = usage of CR #instead of XER could be more efficient def _emit_ovf_guard(self, op, arglocs, cond): # move content of XER to GPR -self.mc.mfspr(r.r0.value, 1) +self.mc.alloc_scratch_reg() +self.mc.mfspr(r.SCRATCH.value, 1) # shift and mask to get comparison result -self.mc.rlwinm(r.r0.value, r.r0.value, 1, 0, 0) -if IS_PPC_32: -self.mc.cmpwi(r.r0.value, 0) -else: -self.mc.cmpdi(r.r0.value, 0) +self.mc.rlwinm(r.SCRATCH.value, r.SCRATCH.value, 1, 0, 0) +self.mc.cmp_op(0, r.SCRATCH.value, 0, imm=True) +self.mc.free_scratch_reg() self._emit_guard(op, arglocs, cond) def emit_guard_no_overflow(self, op, arglocs, regalloc): @@ -235,15 +228,9 @@ if l0.is_reg(): if l1.is_imm(): -if IS_PPC_32: -self.mc.cmpwi(l0.value, l1.getint()) -else: -self.mc.cmpdi(l0.value, l1.getint()) +self.mc.cmp_op(0, l0.value, l1.getint(), imm=True) else: -if IS_PPC_32: -self.mc.cmpw(l0.value, l1.value) -else: -self.mc.cmpd(l0.value, l1.value) +self.mc.cmp_op(0, l0.value, l1.value) else: assert 0, not implemented yet self._emit_guard(op, failargs, c.NE) @@ -254,17 +241,13 @@ def _cmp_guard_class(self, op, locs, regalloc): offset = locs[2] if offset is not None: +self.mc.alloc_scratch_reg() if offset.is_imm(): -if IS_PPC_32: -self.mc.lwz(r.r0.value, locs[0].value, offset.value) -else: -self.mc.ld(r.r0.value, locs[0].value, offset.value) +self.mc.load(r.SCRATCH.value, locs[0].value, offset.value) else: -if IS_PPC_32: -self.mc.lwzx(r.r0.value, locs[0].value, offset.value) -else: -self.mc.ldx(r.r0.value, locs[0].value, offset.value) -self.mc.cmp(r.r0.value, locs[1].value) +self.mc.loadx(r.SCRATCH.value, locs[0].value, offset.value) +self.mc.cmp_op(0, r.SCRATCH.value,
[pypy-commit] pypy windows-no-err-dlg: prevent windows testrunner from opening system error dialog boxes
Author: mattip Branch: windows-no-err-dlg Changeset: r50772:f01058ed1577 Date: 2011-12-20 21:59 +0200 http://bitbucket.org/pypy/pypy/changeset/f01058ed1577/ Log:prevent windows testrunner from opening system error dialog boxes diff --git a/testrunner/runner.py b/testrunner/runner.py --- a/testrunner/runner.py +++ b/testrunner/runner.py @@ -21,7 +21,17 @@ win32api.CloseHandle(proch) except pywintypes.error, e: pass - +#Try to avoid opeing a dialog box if one of the tests causes a system error +import ctypes +winapi = ctypes.windll.kernel32 +SEM_FAILCRITICALERRORS = 1 +SEM_NOGPFAULTERRORBOX = 2 +SEM_NOOPENFILEERRORBOX = 0x8000 +flags = SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX +#Since there is no GetErrorMode, do a double Set +old_mode = winapi.SetErrorMode(flags) +winapi.SetErrorMode(old_mode | flags) + SIGKILL = SIGTERM = 0 READ_MODE = 'rU' WRITE_MODE = 'wb' ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: prevent system error dialog on windows
Author: mattip Branch: Changeset: r50774:b16fca1fa6ec Date: 2011-12-20 22:39 +0200 http://bitbucket.org/pypy/pypy/changeset/b16fca1fa6ec/ Log:prevent system error dialog on windows diff --git a/testrunner/runner.py b/testrunner/runner.py --- a/testrunner/runner.py +++ b/testrunner/runner.py @@ -21,6 +21,16 @@ win32api.CloseHandle(proch) except pywintypes.error, e: pass +#Try to avoid opeing a dialog box if one of the tests causes a system error +import ctypes +winapi = ctypes.windll.kernel32 +SEM_FAILCRITICALERRORS = 1 +SEM_NOGPFAULTERRORBOX = 2 +SEM_NOOPENFILEERRORBOX = 0x8000 +flags = SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX +#Since there is no GetErrorMode, do a double Set +old_mode = winapi.SetErrorMode(flags) +winapi.SetErrorMode(old_mode | flags) SIGKILL = SIGTERM = 0 READ_MODE = 'rU' ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy better-jit-hooks: add a test I wrote one day
Author: Maciej Fijalkowski fij...@gmail.com Branch: better-jit-hooks Changeset: r50776:97c31fd53d0e Date: 2011-12-20 22:57 +0200 http://bitbucket.org/pypy/pypy/changeset/97c31fd53d0e/ Log:add a test I wrote one day diff --git a/pypy/jit/metainterp/test/test_jitportal.py b/pypy/jit/metainterp/test/test_jitportal.py new file mode 100644 --- /dev/null +++ b/pypy/jit/metainterp/test/test_jitportal.py @@ -0,0 +1,34 @@ + +from pypy.rlib.jit import JitDriver, JitPortal +from pypy.jit.metainterp.test.support import LLJitMixin +from pypy.jit.codewriter.policy import PortalPolicy + +class TestJitPortal(LLJitMixin): +def test_abort_quasi_immut(self): +class MyJitPortal(JitPortal): +def abort(self, *args): + + +portal = MyJitPortal() + +myjitdriver = JitDriver(greens=['foo'], reds=['x', 'total']) + +class Foo: +_immutable_fields_ = ['a?'] +def __init__(self, a): +self.a = a +def f(a, x): +foo = Foo(a) +total = 0 +while x 0: +myjitdriver.jit_merge_point(foo=foo, x=x, total=total) +# read a quasi-immutable field out of a Constant +total += foo.a +foo.a += 1 +x -= 1 +return total +# +assert f(100, 7) == 721 +res = self.meta_interp(f, [100, 7], policy=PortalPolicy(portal)) +assert res == 721 + ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-signature: better name
Author: Alex Gaynor alex.gay...@gmail.com Branch: refactor-signature Changeset: r50778:3ad573e7d40c Date: 2011-12-20 15:02 -0600 http://bitbucket.org/pypy/pypy/changeset/3ad573e7d40c/ Log:better name diff --git a/pypy/module/micronumpy/signature.py b/pypy/module/micronumpy/signature.py --- a/pypy/module/micronumpy/signature.py +++ b/pypy/module/micronumpy/signature.py @@ -8,7 +8,7 @@ def sigeq(one, two): return one.eq(two) -def sigeq_numbering(one, two): +def sigeq_no_numbering(one, two): Cache for iterator numbering should not compare array numbers return one.eq(two, compare_array_no=False) @@ -73,7 +73,7 @@ iter_no = 0 def invent_numbering(self): -cache = r_dict(sigeq_numbering, sighash) +cache = r_dict(sigeq_no_numbering, sighash) allnumbers = [] self._invent_numbering(cache, allnumbers) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-signature: dead code
Author: Alex Gaynor alex.gay...@gmail.com Branch: refactor-signature Changeset: r50779:970ab217c79f Date: 2011-12-20 15:23 -0600 http://bitbucket.org/pypy/pypy/changeset/970ab217c79f/ Log:dead code 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 @@ -658,9 +658,6 @@ return self -def get_storage(self, space): -raise OperationError(space.w_TypeError, space.wrap(Cannot get array interface on scalars in pypy)) - class VirtualArray(BaseArray): Class for representing virtual arrays, such as binary ops or ufuncs @@ -1051,13 +1048,6 @@ self.invalidated() self.dtype.setitem(self.storage, item, value) -def start_iter(self, res_shape=None): -if self.order == 'C': -if res_shape is not None and res_shape != self.shape: -return BroadcastIterator(self, res_shape) -return ArrayIterator(self.size) -raise NotImplementedError # use ViewIterator simply, test it - def setshape(self, space, new_shape): self.shape = new_shape self.calc_strides(new_shape) @@ -1065,9 +1055,6 @@ def create_sig(self, res_shape): return self.array_sig(res_shape) -def get_storage(self, space): -return self.storage - def __del__(self): lltype.free(self.storage, flavor='raw', track_allocation=False) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-signature: oops actually fix the test
Author: Maciej Fijalkowski fij...@gmail.com Branch: refactor-signature Changeset: r50782:114830fb70f1 Date: 2011-12-21 00:06 +0200 http://bitbucket.org/pypy/pypy/changeset/114830fb70f1/ Log:oops actually fix the test diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py --- a/pypy/module/micronumpy/test/test_numarray.py +++ b/pypy/module/micronumpy/test/test_numarray.py @@ -911,10 +911,10 @@ d = c[::2][::2] assert d[1] == 8 b = a + a -c = c[::2] +c = b[::2] c[:] = 3 assert b[0] == 3 -assert b[1] == 4 +assert b[1] == 2 def test_tolist_scalar(self): from numpypy import int32, bool_ ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-signature: kill some dead code and a failing test
Author: Maciej Fijalkowski fij...@gmail.com Branch: refactor-signature Changeset: r50781:5bb7c7ef1481 Date: 2011-12-21 00:05 +0200 http://bitbucket.org/pypy/pypy/changeset/5bb7c7ef1481/ Log:kill some dead code and a failing test 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 @@ -468,9 +468,6 @@ def descr_getitem(self, space, w_idx): if self._single_item_result(space, w_idx): concrete = self.get_concrete() -if len(concrete.shape) 1: -raise OperationError(space.w_IndexError, space.wrap( -0-d arrays can't be indexed)) item = concrete._index_of_single_item(space, w_idx) return concrete.getitem(item) chunks = self._prepare_slice_args(space, w_idx) @@ -480,9 +477,6 @@ self.invalidated() if self._single_item_result(space, w_idx): concrete = self.get_concrete() -if len(concrete.shape) 1: -raise OperationError(space.w_IndexError, space.wrap( -0-d arrays can't be indexed)) item = concrete._index_of_single_item(space, w_idx) dtype = concrete.find_dtype() concrete.setitem(item, dtype.coerce(space, w_value)) @@ -642,9 +636,6 @@ def find_dtype(self): return self.dtype -def getitem(self, item): -raise NotImplementedError - def to_str(self, space, comma, builder, indent=' ', use_ellipsis=False): builder.append(self.dtype.itemtype.str_format(self.value)) @@ -657,10 +648,6 @@ def get_concrete_or_scalar(self): return self - -def get_storage(self, space): -raise OperationError(space.w_TypeError, space.wrap(Cannot get array interface on scalars in pypy)) - class VirtualArray(BaseArray): Class for representing virtual arrays, such as binary ops or ufuncs @@ -1065,9 +1052,6 @@ def create_sig(self, res_shape): return self.array_sig(res_shape) -def get_storage(self, space): -return self.storage - def __del__(self): lltype.free(self.storage, flavor='raw', track_allocation=False) diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py --- a/pypy/module/micronumpy/test/test_numarray.py +++ b/pypy/module/micronumpy/test/test_numarray.py @@ -910,6 +910,11 @@ c = (a + a) d = c[::2][::2] assert d[1] == 8 +b = a + a +c = c[::2] +c[:] = 3 +assert b[0] == 3 +assert b[1] == 4 def test_tolist_scalar(self): from numpypy import int32, bool_ ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy pyarg-parsetuple-s-star-buffer: merge
Author: Maciej Fijalkowski fij...@gmail.com Branch: pyarg-parsetuple-s-star-buffer Changeset: r50785:650faf80d8d2 Date: 2011-12-20 23:11 +0100 http://bitbucket.org/pypy/pypy/changeset/650faf80d8d2/ Log:merge diff --git a/pypy/module/cpyext/bufferobject.py b/pypy/module/cpyext/bufferobject.py --- a/pypy/module/cpyext/bufferobject.py +++ b/pypy/module/cpyext/bufferobject.py @@ -2,7 +2,7 @@ from pypy.module.cpyext.api import ( cpython_api, Py_ssize_t, cpython_struct, bootstrap_function, PyObjectFields, PyObject) -from pypy.module.cpyext.pyobject import make_typedescr +from pypy.module.cpyext.pyobject import make_typedescr, Py_DecRef from pypy.interpreter.buffer import Buffer, StringBuffer, SubBuffer @@ -25,7 +25,7 @@ make_typedescr(space.gettypefor(Buffer).instancetypedef, basestruct=PyBufferObject.TO, attach=buffer_attach, - # dealloc=buffer_dealloc, + dealloc=buffer_dealloc, realize=buffer_realize) def buffer_attach(space, py_obj, w_obj): @@ -57,6 +57,10 @@ -# @cpython_api([PyObject], lltype.Void, external=False) -# def buffer_dealloc(space, py_obj): - +@cpython_api([PyObject], lltype.Void, external=False) +def buffer_dealloc(space, py_obj): +py_buf = rffi.cast(PyBufferObject, py_obj) +Py_DecRef(space, py_buf.c_b_base) +rffi.free_charp(py_buf.c_b_ptr) +from pypy.module.cpyext.object import PyObject_dealloc +PyObject_dealloc(space, py_obj) diff --git a/pypy/module/cpyext/test/test_getargs.py b/pypy/module/cpyext/test/test_getargs.py --- a/pypy/module/cpyext/test/test_getargs.py +++ b/pypy/module/cpyext/test/test_getargs.py @@ -137,13 +137,11 @@ if (!PyArg_ParseTuple(args, s*, buf)) { return NULL; } -printf(OH NO %s %d\\n, buf.buf, buf.len); -fflush(stdout); result = PyString_FromStringAndSize(buf.buf, buf.len); PyBuffer_Release(buf); return result; ''') -assert buffer('foo\0bar\0baz') == pybuffer(buffer('foo\0bar\0baz')) +assert 'foo\0bar\0baz' == pybuffer(buffer('foo\0bar\0baz')) def test_pyarg_parse_charbuf_and_length(self): diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py --- a/pypy/module/cpyext/typeobject.py +++ b/pypy/module/cpyext/typeobject.py @@ -28,6 +28,7 @@ PyNumberMethods, PyMappingMethods, PySequenceMethods, PyBufferProcs) from pypy.module.cpyext.slotdefs import ( slotdefs_for_tp_slots, slotdefs_for_wrappers, get_slot_tp_function) +from pypy.interpreter.buffer import Buffer from pypy.interpreter.error import OperationError from pypy.rlib.rstring import rsplit from pypy.rlib.objectmodel import specialize @@ -418,8 +419,20 @@ Py_DecRef(space, pyref) return space.len_w(w_str) +@cpython_api([PyObject, Py_ssize_t, rffi.VOIDPP], lltype.Signed, + external=False, error=-1) +def buf_getreadbuffer(space, pyref, segment, ref): +from pypy.module.cpyext.bufferobject import PyBufferObject +if segment != 0: +raise OperationError(space.w_SystemError, space.wrap + (accessing non-existent string segment)) +py_buf = rffi.cast(PyBufferObject, pyref) +ref[0] = py_buf.c_b_ptr +#Py_DecRef(space, pyref) +return py_buf.c_b_size + def setup_string_buffer_procs(space, pto): -c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True) +c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True, immortal=True) c_buf.c_bf_getsegcount = llhelper(str_segcount.api_func.functype, str_segcount.api_func.get_wrapper(space)) c_buf.c_bf_getreadbuffer = llhelper(str_getreadbuffer.api_func.functype, @@ -429,6 +442,14 @@ pto.c_tp_as_buffer = c_buf pto.c_tp_flags |= Py_TPFLAGS_HAVE_GETCHARBUFFER +def setup_buffer_buffer_procs(space, pto): +c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True, immortal=True) +c_buf.c_bf_getsegcount = llhelper(str_segcount.api_func.functype, + str_segcount.api_func.get_wrapper(space)) +c_buf.c_bf_getreadbuffer = llhelper(buf_getreadbuffer.api_func.functype, + buf_getreadbuffer.api_func.get_wrapper(space)) +pto.c_tp_as_buffer = c_buf + @cpython_api([PyObject], lltype.Void, external=False) def type_dealloc(space, obj): from pypy.module.cpyext.object import PyObject_dealloc @@ -484,6 +505,8 @@ # buffer protocol if space.is_w(w_type, space.w_str): setup_string_buffer_procs(space, pto) +if space.is_w(w_type, space.gettypefor(Buffer)): +setup_buffer_buffer_procs(space, pto) pto.c_tp_free = llhelper(PyObject_Del.api_func.functype, PyObject_Del.api_func.get_wrapper(space)) ___ pypy-commit mailing list
[pypy-commit] pypy pyarg-parsetuple-s-star-buffer: I hope this pdb is not necessary
Author: Maciej Fijalkowski fij...@gmail.com Branch: pyarg-parsetuple-s-star-buffer Changeset: r50784:3599bd6c07dc Date: 2011-12-20 23:08 +0100 http://bitbucket.org/pypy/pypy/changeset/3599bd6c07dc/ Log:I hope this pdb is not necessary diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py --- a/pypy/module/cpyext/pyobject.py +++ b/pypy/module/cpyext/pyobject.py @@ -113,8 +113,6 @@ @specialize.memo() def _get_typedescr_1(typedef): -if typedef.name == buffer: -import pdb; pdb.set_trace() try: return typedescr_cache[typedef] except KeyError: ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy pyarg-parsetuple-s-star-buffer: Fix translation
Author: Amaury Forgeot d'Arc amaur...@gmail.com Branch: pyarg-parsetuple-s-star-buffer Changeset: r50786:ffdf30e6ad7b Date: 2011-12-20 23:13 +0100 http://bitbucket.org/pypy/pypy/changeset/ffdf30e6ad7b/ Log:Fix translation diff --git a/pypy/module/cpyext/bufferobject.py b/pypy/module/cpyext/bufferobject.py --- a/pypy/module/cpyext/bufferobject.py +++ b/pypy/module/cpyext/bufferobject.py @@ -61,6 +61,6 @@ def buffer_dealloc(space, py_obj): py_buf = rffi.cast(PyBufferObject, py_obj) Py_DecRef(space, py_buf.c_b_base) -rffi.free_charp(py_buf.c_b_ptr) +rffi.free_charp(rffi.cast(rffi.CCHARP, py_buf.c_b_ptr)) from pypy.module.cpyext.object import PyObject_dealloc PyObject_dealloc(space, py_obj) diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py --- a/pypy/module/cpyext/typeobject.py +++ b/pypy/module/cpyext/typeobject.py @@ -432,7 +432,8 @@ return py_buf.c_b_size def setup_string_buffer_procs(space, pto): -c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True, immortal=True) +c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True) +lltype.render_immortal(c_buf) c_buf.c_bf_getsegcount = llhelper(str_segcount.api_func.functype, str_segcount.api_func.get_wrapper(space)) c_buf.c_bf_getreadbuffer = llhelper(str_getreadbuffer.api_func.functype, @@ -443,7 +444,8 @@ pto.c_tp_flags |= Py_TPFLAGS_HAVE_GETCHARBUFFER def setup_buffer_buffer_procs(space, pto): -c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True, immortal=True) +c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True) +lltype.render_immortal(c_buf) c_buf.c_bf_getsegcount = llhelper(str_segcount.api_func.functype, str_segcount.api_func.get_wrapper(space)) c_buf.c_bf_getreadbuffer = llhelper(buf_getreadbuffer.api_func.functype, ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy pyarg-parsetuple-s-star-buffer: Close branch about to be merged
Author: Amaury Forgeot d'Arc amaur...@gmail.com Branch: pyarg-parsetuple-s-star-buffer Changeset: r50787:7359951c27a7 Date: 2011-12-20 23:16 +0100 http://bitbucket.org/pypy/pypy/changeset/7359951c27a7/ Log:Close branch about to be merged ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Merge branch pyarg-parsetuple-s-star-buffer:
Author: Amaury Forgeot d'Arc amaur...@gmail.com Branch: Changeset: r50788:5d4dfac3c59a Date: 2011-12-20 23:18 +0100 http://bitbucket.org/pypy/pypy/changeset/5d4dfac3c59a/ Log:Merge branch pyarg-parsetuple-s-star-buffer: (exarkun) Add support for buffer() objects in cpyext. They also implement the C buffer interface. diff --git a/pypy/module/cpyext/__init__.py b/pypy/module/cpyext/__init__.py --- a/pypy/module/cpyext/__init__.py +++ b/pypy/module/cpyext/__init__.py @@ -45,6 +45,8 @@ import pypy.module.cpyext.longobject import pypy.module.cpyext.listobject import pypy.module.cpyext.sequence +import pypy.module.cpyext.buffer +import pypy.module.cpyext.bufferobject import pypy.module.cpyext.eval import pypy.module.cpyext.import_ import pypy.module.cpyext.mapping diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -317,6 +317,10 @@ INTERPLEVEL_API = {} FUNCTIONS = {} + +# These are C symbols which cpyext will export, but which are defined in .c +# files somewhere in the implementation of cpyext (rather than being defined in +# RPython). SYMBOLS_C = [ 'Py_FatalError', 'PyOS_snprintf', 'PyOS_vsnprintf', 'PyArg_Parse', 'PyArg_ParseTuple', 'PyArg_UnpackTuple', 'PyArg_ParseTupleAndKeywords', diff --git a/pypy/module/cpyext/buffer.py b/pypy/module/cpyext/buffer.py new file mode 100644 --- /dev/null +++ b/pypy/module/cpyext/buffer.py @@ -0,0 +1,11 @@ +from pypy.rpython.lltypesystem import rffi, lltype +from pypy.module.cpyext.api import ( +cpython_api, CANNOT_FAIL, Py_buffer) + +@cpython_api([lltype.Ptr(Py_buffer), lltype.Char], rffi.INT_real, error=CANNOT_FAIL) +def PyBuffer_IsContiguous(space, view, fortran): +Return 1 if the memory defined by the view is C-style (fortran is +'C') or Fortran-style (fortran is 'F') contiguous or either one +(fortran is 'A'). Return 0 otherwise. +# PyPy only supports contiguous Py_buffers for now. +return space.wrap(1) diff --git a/pypy/module/cpyext/bufferobject.py b/pypy/module/cpyext/bufferobject.py new file mode 100644 --- /dev/null +++ b/pypy/module/cpyext/bufferobject.py @@ -0,0 +1,66 @@ +from pypy.rpython.lltypesystem import rffi, lltype +from pypy.module.cpyext.api import ( +cpython_api, Py_ssize_t, cpython_struct, bootstrap_function, +PyObjectFields, PyObject) +from pypy.module.cpyext.pyobject import make_typedescr, Py_DecRef +from pypy.interpreter.buffer import Buffer, StringBuffer, SubBuffer + + +PyBufferObjectStruct = lltype.ForwardReference() +PyBufferObject = lltype.Ptr(PyBufferObjectStruct) +PyBufferObjectFields = PyObjectFields + ( +(b_base, PyObject), +(b_ptr, rffi.VOIDP), +(b_size, Py_ssize_t), +(b_offset, Py_ssize_t), +(b_readonly, rffi.INT), +(b_hash, rffi.LONG), +) + +cpython_struct(PyBufferObject, PyBufferObjectFields, PyBufferObjectStruct) + +@bootstrap_function +def init_bufferobject(space): +Type description of PyBufferObject +make_typedescr(space.gettypefor(Buffer).instancetypedef, + basestruct=PyBufferObject.TO, + attach=buffer_attach, + dealloc=buffer_dealloc, + realize=buffer_realize) + +def buffer_attach(space, py_obj, w_obj): + +Fills a newly allocated PyBufferObject with the given (str) buffer object. + +py_buf = rffi.cast(PyBufferObject, py_obj) +py_buf.c_b_offset = 0 +rffi.setintfield(py_buf, 'c_b_readonly', 1) +rffi.setintfield(py_buf, 'c_b_hash', -1) + +if isinstance(w_obj, SubBuffer): +py_buf.c_b_offset = w_obj.offset +w_obj = w_obj.buffer + +if isinstance(w_obj, StringBuffer): +py_buf.c_b_base = rffi.cast(PyObject, 0) # space.wrap(w_obj.value) +py_buf.c_b_ptr = rffi.cast(rffi.VOIDP, rffi.str2charp(w_obj.as_str())) +py_buf.c_b_size = w_obj.getlength() +else: +raise Exception(Fail fail fail fail fail) + + +def buffer_realize(space, py_obj): + +Creates the buffer in the PyPy interpreter from a cpyext representation. + +raise Exception(realize fail fail fail) + + + +@cpython_api([PyObject], lltype.Void, external=False) +def buffer_dealloc(space, py_obj): +py_buf = rffi.cast(PyBufferObject, py_obj) +Py_DecRef(space, py_buf.c_b_base) +rffi.free_charp(rffi.cast(rffi.CCHARP, py_buf.c_b_ptr)) +from pypy.module.cpyext.object import PyObject_dealloc +PyObject_dealloc(space, py_obj) diff --git a/pypy/module/cpyext/include/bufferobject.h b/pypy/module/cpyext/include/bufferobject.h --- a/pypy/module/cpyext/include/bufferobject.h +++ b/pypy/module/cpyext/include/bufferobject.h @@ -9,6 +9,17 @@ extern C { #endif +typedef struct { + PyObject_HEAD + PyObject *b_base; + void *b_ptr; + Py_ssize_t b_size; + Py_ssize_t b_offset; + int b_readonly; + long b_hash; +} PyBufferObject; + + PyAPI_DATA(PyTypeObject) PyBuffer_Type; #define
[pypy-commit] pypy refactor-signature: some more dead code
Author: Maciej Fijalkowski fij...@gmail.com Branch: refactor-signature Changeset: r50789:44f6ff290792 Date: 2011-12-21 00:22 +0200 http://bitbucket.org/pypy/pypy/changeset/44f6ff290792/ Log:some more dead code 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 @@ -736,9 +736,6 @@ def _del_sources(self): self.values = None -def _find_dtype(self): -return self.res_dtype - def create_sig(self, res_shape): if self.forced_result is not None: return self.forced_result.create_sig(res_shape) @@ -1029,12 +1026,6 @@ ) return array -def descr_len(self, space): -if len(self.shape): -return space.wrap(self.shape[0]) -raise OperationError(space.w_TypeError, space.wrap( -len() of unsized object)) - def setitem(self, item, value): self.invalidated() self.dtype.setitem(self.storage, item, value) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-signature: close to be merged branch
Author: Maciej Fijalkowski fij...@gmail.com Branch: refactor-signature Changeset: r50790:ad20782034b9 Date: 2011-12-21 00:25 +0200 http://bitbucket.org/pypy/pypy/changeset/ad20782034b9/ Log:close to be merged branch ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: kill review file
Author: Alex Gaynor alex.gay...@gmail.com Branch: Changeset: r50792:862207881328 Date: 2011-12-20 16:28 -0600 http://bitbucket.org/pypy/pypy/changeset/862207881328/ Log:kill review file diff --git a/pypy/module/micronumpy/REVIEW.txt b/pypy/module/micronumpy/REVIEW.txt deleted file mode 100644 --- a/pypy/module/micronumpy/REVIEW.txt +++ /dev/null @@ -1,10 +0,0 @@ -REVIEW NOTES - - -* VirtualSlice vs. W_NDimSlice? -* W_NDimSlice.__init__ calls ConcreteArray.__init__ instead of - ViewArray.__init__, W_FlatIterator as well. -* Cleanup of the iterator and array caching/numbering. It's a mess right now: - * _creater_iter updates the arraylist - * Why do Scalars need an iterator at all? - * Do views share storage with concrete arrays or other views? ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix backwards logic
Author: Alex Gaynor alex.gay...@gmail.com Branch: Changeset: r50794:d84a162addff Date: 2011-12-20 22:54 -0600 http://bitbucket.org/pypy/pypy/changeset/d84a162addff/ Log:fix backwards logic diff --git a/pypy/objspace/std/stringobject.py b/pypy/objspace/std/stringobject.py --- a/pypy/objspace/std/stringobject.py +++ b/pypy/objspace/std/stringobject.py @@ -524,7 +524,8 @@ result_size = ovfcheck(upper * len(by)) result_size = ovfcheck(result_size + upper) result_size = ovfcheck(result_size + len(by)) -result_size = ovfcheck(result_size + upper - len(input)) +remaining_size = len(input) - upper +result_size = ovfcheck(result_size + remaining_size) except OverflowError: raise OperationError(space.w_OverflowError, space.wrap(replace string is too long) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit