[pypy-commit] extradoc extradoc: a rough draft of some slides for the compiler workshop

2016-06-28 Thread mattip
Author: Matti Picus 
Branch: extradoc
Changeset: r5642:2532bf0a23bd
Date: 2016-06-28 22:53 +0300
http://bitbucket.org/pypy/extradoc/changeset/2532bf0a23bd/

Log:a rough draft of some slides for the compiler workshop

diff --git a/talk/compiler-workshop-2016/pypy.rst 
b/talk/compiler-workshop-2016/pypy.rst
new file mode 100644
--- /dev/null
+++ b/talk/compiler-workshop-2016/pypy.rst
@@ -0,0 +1,29 @@
+PyPy - DRAFT
+
+
+A quick overview of PyPy for other Python-compiler developers
+
+
+What is Our Niche
+-
+
+PyPy is a mature production-ready framework automatically speeding up pure
+python code by factors of 2-5 in commercial settings.
+
+What We Bring to the Table
+--
+
+Our core is based on cutting-edge JIT compiler
+research, written in Python. Being written in Python means we can quickly
+try out (and reject or incorporate) new ideas. For instance, our STM work has
+uncovered subtle bugs in CLANG and GCC, or the fact that we can easily try out
+new register allocation strategies.
+
+What We Need Help With
+--
+
+We seem to be more successful in improving core technologies than creating a
+end-user friendly nicely packaged distribution. We are also extremely
+under-funded. For instance, we could be doing alot more for data science but
+are moving slowly forward on a volunteer basis with C-API compatibility.
+
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy guard-compatible: merge default

2016-06-28 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: guard-compatible
Changeset: r85440:790c399e5c6b
Date: 2016-06-28 18:08 +0200
http://bitbucket.org/pypy/pypy/changeset/790c399e5c6b/

Log:merge default

diff --git a/pypy/doc/config/commandline.txt b/pypy/doc/config/commandline.txt
--- a/pypy/doc/config/commandline.txt
+++ b/pypy/doc/config/commandline.txt
@@ -9,7 +9,7 @@
 PyPy Python interpreter options
 ---
 
-The following options can be used after ``translate.py
+The following options can be used after ``rpython
 targetpypystandalone`` or as options to ``py.py``.
 
 .. GENERATE: objspace
@@ -22,7 +22,7 @@
 General translation options
 ---
 
-The following are options of ``translate.py``.  They must be
+The following are options of ``bin/rpython``.  They must be
 given before the ``targetxxx`` on the command line.
 
 * `--opt -O:`__ set the optimization level `[0, 1, size, mem, 2, 3]`
diff --git a/pypy/doc/config/index.rst b/pypy/doc/config/index.rst
--- a/pypy/doc/config/index.rst
+++ b/pypy/doc/config/index.rst
@@ -15,12 +15,12 @@
 
 ./py.py <`objspace options`_>
 
-and the ``translate.py`` translation entry
+and the ``rpython/bin/rpython`` translation entry
 point which takes arguments of this form:
 
 .. parsed-literal::
 
-./translate.py <`translation options`_> 
+./rpython/bin/rpython <`translation options`_> 
 
 For the common case of  being ``targetpypystandalone.py``,
 you can then pass the `object space options`_ after
@@ -28,7 +28,7 @@
 
 .. parsed-literal::
 
-./translate.py <`translation options`_> targetpypystandalone.py <`objspace 
options`_>
+./rpython/bin/rpython <`translation options`_> targetpypystandalone.py 
<`objspace options`_>
 
 There is an `overview`_ of all command line arguments that can be
 passed in either position.
diff --git a/pypy/doc/config/opt.rst b/pypy/doc/config/opt.rst
--- a/pypy/doc/config/opt.rst
+++ b/pypy/doc/config/opt.rst
@@ -4,8 +4,8 @@
 This meta-option selects a default set of optimization
 settings to use during a translation.  Usage::
 
-translate.py --opt=#
-translate.py -O#
+bin/rpython --opt=#
+bin/rpython -O#
 
 where ``#`` is the desired optimization level.  The valid choices are:
 
diff --git a/pypy/doc/config/translation.dont_write_c_files.txt 
b/pypy/doc/config/translation.dont_write_c_files.txt
--- a/pypy/doc/config/translation.dont_write_c_files.txt
+++ b/pypy/doc/config/translation.dont_write_c_files.txt
@@ -1,4 +1,4 @@
 write the generated C files to ``/dev/null`` instead of to the disk. Useful if
-you want to use translate.py as a benchmark and don't want to access the disk.
+you want to use translation as a benchmark and don't want to access the disk.
 
 .. _`translation documentation`: ../translation.html
diff --git a/pypy/doc/config/translation.fork_before.txt 
b/pypy/doc/config/translation.fork_before.txt
--- a/pypy/doc/config/translation.fork_before.txt
+++ b/pypy/doc/config/translation.fork_before.txt
@@ -1,4 +1,4 @@
 This is an option mostly useful when working on the PyPy toolchain. If you use
-it, translate.py will fork before the specified phase. If the translation
+it, translation will fork before the specified phase. If the translation
 crashes after that fork, you can fix the bug in the toolchain, and continue
 translation at the fork-point.
diff --git a/pypy/doc/cppyy.rst b/pypy/doc/cppyy.rst
--- a/pypy/doc/cppyy.rst
+++ b/pypy/doc/cppyy.rst
@@ -122,7 +122,7 @@
 $ hg up reflex-support # optional
 
 # This example shows python, but using pypy-c is faster and uses less 
memory
-$ python rpython/translator/goal/translate.py --opt=jit 
pypy/goal/targetpypystandalone --withmod-cppyy
+$ python rpython/bin/rpython --opt=jit pypy/goal/targetpypystandalone 
--withmod-cppyy
 
 This will build a ``pypy-c`` that includes the cppyy module, and through that,
 Reflex support.
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -48,3 +48,8 @@
 Bug fix: if ``socket.socket()`` failed, the ``socket.error`` did not show
 the errno of the failing system call, but instead some random previous
 errno.
+
+.. branch: PyTuple_Type-subclass
+
+Refactor PyTupleObject to look like cpython's and allow subclassing 
+PyTuple_Type
diff --git a/pypy/interpreter/astcompiler/tools/asdl_py.py 
b/pypy/interpreter/astcompiler/tools/asdl_py.py
--- a/pypy/interpreter/astcompiler/tools/asdl_py.py
+++ b/pypy/interpreter/astcompiler/tools/asdl_py.py
@@ -400,7 +400,7 @@
 if not (space.isinstance_w(w_obj, space.w_str) or
 space.isinstance_w(w_obj, space.w_unicode)):
 raise oefmt(space.w_TypeError,
-   "AST string must be of type str or unicode")
+"AST string must be of type str or unicode")
 return w_obj
 
 def get_field(space, w_node, name, optional):
diff --git a/pypy/module/cpyext/bufferobject.py 

[pypy-commit] pypy guard-compatible: a comment

2016-06-28 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: guard-compatible
Changeset: r85439:7ed893072cdd
Date: 2016-06-28 18:08 +0200
http://bitbucket.org/pypy/pypy/changeset/7ed893072cdd/

Log:a comment

diff --git a/rpython/jit/metainterp/compile.py 
b/rpython/jit/metainterp/compile.py
--- a/rpython/jit/metainterp/compile.py
+++ b/rpython/jit/metainterp/compile.py
@@ -1138,6 +1138,8 @@
 self.other_compat_conditions.append(compat_cond)
 asminfo = ResumeGuardDescr.compile_and_attach(
 self, metainterp, new_loop, orig_inputargs)
+# note that the backend will not patch the switch at all, so it is
+# vital to *always* do something with asminfo.asmaddr
 if compat_cond:
 compat_cond.jump_target = asminfo.asmaddr
 else:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy guard-compatible: fix tests

2016-06-28 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: guard-compatible
Changeset: r85438:6215fed7ec26
Date: 2016-06-28 17:03 +0200
http://bitbucket.org/pypy/pypy/changeset/6215fed7ec26/

Log:fix tests

diff --git a/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py 
b/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
@@ -30,6 +30,9 @@
 self._last_debug_merge_point = None
 self.quasi_immutable_deps = None
 
+def _can_optimize_call_pure(self, op):
+return True
+
 class BaseTestGenerateGuards(BaseTest):
 def setup_class(self):
 classbox = self.cpu.ts.cls_of_box(InputArgRef(self.nodeaddr))
@@ -490,7 +493,7 @@
 op = ResOperation(
 rop.CALL_PURE_I, [ConstInt(123), ConstPtr(self.quasiptr)],
 descr=self.plaincalldescr)
-copied_op, cond = ccond.prepare_const_arg_call(
+copied_op, cond, result = ccond.prepare_const_arg_call(
 op, optimizer)
 ccond.record_condition(cond, ConstInt(5), optimizer)
 
@@ -504,7 +507,7 @@
 rop.CALL_PURE_I,
 [ConstInt(123), ConstPtr(self.quasiptr), getfield_op],
 descr=self.nonwritedescr)
-copied_op, cond = ccond.prepare_const_arg_call(
+copied_op, cond, result = ccond.prepare_const_arg_call(
 op, optimizer)
 ccond.record_condition(cond, ConstInt(5), optimizer)
 value = info.PtrInfo()
@@ -532,7 +535,9 @@
 
 def test_virtualstate_guard_compatible(self):
 value1 = self.make_ccond_info()
+ccond1 = value1._compatibility_conditions
 value2 = self.make_ccond_info()
+ccond2 = value2._compatibility_conditions
 
 state1 = not_virtual(self.cpu, 'r', value1)
 state2 = not_virtual(self.cpu, 'r', value2)
@@ -551,6 +556,7 @@
 def test_virtualstate_guard_compatible_make_guards(self):
 value1 = self.make_ccond_info()
 value2 = self.make_ccond_info()
+ccond2 = value2._compatibility_conditions
 
 state1 = not_virtual(self.cpu, 'r', value1)
 state2 = not_virtual(self.cpu, 'r', value2)
@@ -559,7 +565,7 @@
 cond = ccond2.conditions[:]
 ccond2.conditions = [cond[0]]
 box = InputArgRef(self.nodeaddr)
-self.guards(state1, state2)
+self.check_no_guards(state1, state2)
 
 ccond2.conditions = [cond[1]]
 self.check_no_guards(state1, state2)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy guard-compatible: fix the problem

2016-06-28 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: guard-compatible
Changeset: r85437:09617ecb9107
Date: 2016-06-28 16:49 +0200
http://bitbucket.org/pypy/pypy/changeset/09617ecb9107/

Log:fix the problem

when attaching a new bridge to a GuardCompatibleDescr and we cannot
find out whether the new bridge is checking conditions on the same
variable as the GuardCompatibleDescr, the guard needs to henceforth
always jump to that new trace if none of the other traces match.
Otherwise we will keep compiling more and more code.

diff --git a/rpython/jit/metainterp/compile.py 
b/rpython/jit/metainterp/compile.py
--- a/rpython/jit/metainterp/compile.py
+++ b/rpython/jit/metainterp/compile.py
@@ -1091,6 +1091,12 @@
 # list of compatibility conditions about the same variable, with
 # bridges attached to them
 self.other_compat_conditions = []
+# fallback jump target is the one to jump to if the generated bridges
+# do not start with a guard_compatible at all, so we don't have a basis
+# to decide on
+# XXX it would be better to patch the guard properly in the backend,
+# but later
+self.fallback_jump_target = 0
 
 def find_compatible(self, cpu, ref):
 """ callback for the CPU: given a value ref, it returns:
@@ -1108,7 +1114,10 @@
 if _compatibility_conditions.check_compat_and_activate(
 cpu, ref, self.rd_loop_token):
 return _compatibility_conditions.jump_target
-return 0
+# none of the other conditions matched. if we have a
+# fallback_jump_target, go there (otherwise we run the risk of
+# producing arbitrary amounts of code)
+return self.fallback_jump_target
 
 def compile_and_attach(self, metainterp, new_loop, orig_inputargs):
 # if new_loop starts with another guard_compatible on the same argument
@@ -1131,6 +1140,9 @@
 self, metainterp, new_loop, orig_inputargs)
 if compat_cond:
 compat_cond.jump_target = asminfo.asmaddr
+else:
+assert self.fallback_jump_target == 0 # this can never happen twice
+self.fallback_jump_target = asminfo.asmaddr
 return asminfo
 
 def make_a_counter_per_value(self, guard_value_op, index):
diff --git a/rpython/jit/metainterp/test/test_compatible.py 
b/rpython/jit/metainterp/test/test_compatible.py
--- a/rpython/jit/metainterp/test/test_compatible.py
+++ b/rpython/jit/metainterp/test/test_compatible.py
@@ -418,8 +418,7 @@
 
 x = self.meta_interp(main, [])
 
-# trace, two bridges, a finish bridge
-self.check_trace_count(4)
+self.check_trace_count(6)
 
 def test_merge_switch_object(self):
 S = lltype.GcStruct('S', ('x', lltype.Signed))
@@ -611,7 +610,7 @@
 
 x = self.meta_interp(main, [False])
 assert x < 70
-self.check_trace_count(9)
+self.check_trace_count(7)
 self.check_resops(call_i=0)
 
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Internal string->bytes renaming

2016-06-28 Thread rlamy
Author: Ronan Lamy 
Branch: 
Changeset: r85436:4b3a2a0269e2
Date: 2016-06-28 16:37 +0100
http://bitbucket.org/pypy/pypy/changeset/4b3a2a0269e2/

Log:Internal string->bytes renaming

diff --git a/pypy/module/cpyext/bytesobject.py 
b/pypy/module/cpyext/bytesobject.py
--- a/pypy/module/cpyext/bytesobject.py
+++ b/pypy/module/cpyext/bytesobject.py
@@ -11,7 +11,7 @@
 from pypy.objspace.std.bytesobject import W_BytesObject
 
 ##
-## Implementation of PyStringObject
+## Implementation of PyBytesObject
 ## 
 ##
 ## The problem
@@ -29,15 +29,15 @@
 ## Solution
 ## 
 ##
-## PyStringObject contains two additional members: the ob_size and a pointer 
to a
+## PyBytesObject contains two additional members: the ob_size and a pointer to 
a
 ## char ob_sval; it may be NULL.
 ##
-## - A string allocated by pypy will be converted into a PyStringObject with a
+## - A string allocated by pypy will be converted into a PyBytesObject with a
 ##   NULL buffer.  The first time PyString_AsString() is called, memory is
 ##   allocated (with flavor='raw') and content is copied.
 ##
 ## - A string allocated with PyString_FromStringAndSize(NULL, size) will
-##   allocate a PyStringObject structure, and a buffer with the specified
+##   allocate a PyBytesObject structure, and a buffer with the specified
 ##   size+1, but the reference won't be stored in the global map; there is no
 ##   corresponding object in pypy.  When from_ref() or Py_INCREF() is called,
 ##   the pypy string is created, and added to the global map of tracked
@@ -55,58 +55,58 @@
 ##   corresponds to the pypy gc-managed string.
 ##
 
-PyStringObjectStruct = lltype.ForwardReference()
-PyStringObject = lltype.Ptr(PyStringObjectStruct)
-PyStringObjectFields = PyVarObjectFields + \
+PyBytesObjectStruct = lltype.ForwardReference()
+PyBytesObject = lltype.Ptr(PyBytesObjectStruct)
+PyBytesObjectFields = PyVarObjectFields + \
 (("ob_shash", rffi.LONG), ("ob_sstate", rffi.INT), ("ob_sval", 
rffi.CArray(lltype.Char)))
-cpython_struct("PyStringObject", PyStringObjectFields, PyStringObjectStruct)
+cpython_struct("PyStringObject", PyBytesObjectFields, PyBytesObjectStruct)
 
 @bootstrap_function
-def init_stringobject(space):
-"Type description of PyStringObject"
+def init_bytesobject(space):
+"Type description of PyBytesObject"
 make_typedescr(space.w_str.layout.typedef,
-   basestruct=PyStringObject.TO,
-   attach=string_attach,
-   dealloc=string_dealloc,
-   realize=string_realize)
+   basestruct=PyBytesObject.TO,
+   attach=bytes_attach,
+   dealloc=bytes_dealloc,
+   realize=bytes_realize)
 
 PyString_Check, PyString_CheckExact = build_type_checkers("String", "w_str")
 
 def new_empty_str(space, length):
 """
-Allocate a PyStringObject and its ob_sval, but without a corresponding
-interpreter object.  The ob_sval may be mutated, until string_realize() is
+Allocate a PyBytesObject and its ob_sval, but without a corresponding
+interpreter object.  The ob_sval may be mutated, until bytes_realize() is
 called.  Refcount of the result is 1.
 """
 typedescr = get_typedescr(space.w_str.layout.typedef)
 py_obj = typedescr.allocate(space, space.w_str, length)
-py_str = rffi.cast(PyStringObject, py_obj)
+py_str = rffi.cast(PyBytesObject, py_obj)
 py_str.c_ob_shash = -1
 py_str.c_ob_sstate = rffi.cast(rffi.INT, 0) # SSTATE_NOT_INTERNED
 return py_str
 
-def string_attach(space, py_obj, w_obj):
+def bytes_attach(space, py_obj, w_obj):
 """
-Copy RPython string object contents to a PyStringObject. The
+Copy RPython string object contents to a PyBytesObject. The
 c_ob_sval must not be modified.
 """
-py_str = rffi.cast(PyStringObject, py_obj)
+py_str = rffi.cast(PyBytesObject, py_obj)
 s = space.str_w(w_obj)
 if py_str.c_ob_size  < len(s):
 raise oefmt(space.w_ValueError,
-"string_attach called on object with ob_size %d but trying to 
store %d",
-py_str.c_ob_size, len(s)) 
+"bytes_attach called on object with ob_size %d but trying to store 
%d",
+py_str.c_ob_size, len(s))
 rffi.c_memcpy(py_str.c_ob_sval, rffi.str2charp(s), len(s))
 py_str.c_ob_sval[len(s)] = '\0'
 py_str.c_ob_shash = space.hash_w(w_obj)
 py_str.c_ob_sstate = rffi.cast(rffi.INT, 1) # SSTATE_INTERNED_MORTAL
 
-def string_realize(space, py_obj):
+def bytes_realize(space, py_obj):
 """
-Creates the string in the interpreter. The PyStringObject ob_sval must not
+Creates the string in the interpreter. The PyBytesObject ob_sval must not
 be modified after this call.
 """
-py_str = rffi.cast(PyStringObject, py_obj)
+py_str = rffi.cast(PyBytesObject, py_obj)
 s = rffi.charpsize2str(py_str.c_ob_sval, py_str.c_ob_size)
 w_type = 

[pypy-commit] pypy ppc-vsx-support: add the backend functions for vec_int_eq/ne + test,

2016-06-28 Thread plan_rich
Author: Richard Plangger 
Branch: ppc-vsx-support
Changeset: r85435:a404127ebe68
Date: 2016-06-28 17:14 +0200
http://bitbucket.org/pypy/pypy/changeset/a404127ebe68/

Log:add the backend functions for vec_int_eq/ne + test, implement
vec_expand_f, test passes that uses vec_expand_f

diff --git a/rpython/jit/backend/llsupport/rewrite.py 
b/rpython/jit/backend/llsupport/rewrite.py
--- a/rpython/jit/backend/llsupport/rewrite.py
+++ b/rpython/jit/backend/llsupport/rewrite.py
@@ -160,7 +160,7 @@
  factor, offset):
 factor, offset, new_index_box = cpu_simplify_scale(self.cpu, 
index_box, factor, offset)
 if index_box is not new_index_box:
-self.emit_op(index_box)
+self.emit_op(new_index_box)
 return factor, offset, new_index_box
 
 def emit_gc_load_or_indexed(self, op, ptr_box, index_box, itemsize,
diff --git a/rpython/jit/backend/llsupport/vector_ext.py 
b/rpython/jit/backend/llsupport/vector_ext.py
--- a/rpython/jit/backend/llsupport/vector_ext.py
+++ b/rpython/jit/backend/llsupport/vector_ext.py
@@ -1,3 +1,4 @@
+from rpython.jit.backend.llsupport.rewrite import cpu_simplify_scale
 from rpython.jit.backend.llsupport.descr import (unpack_arraydescr,
 unpack_fielddescr, unpack_interiorfielddescr)
 from rpython.rlib.objectmodel import specialize, always_inline
@@ -130,7 +131,7 @@
 if opnum in (rop.SETARRAYITEM_GC, rop.SETARRAYITEM_RAW):
 itemsize, basesize, _ = unpack_arraydescr(op.getdescr())
 index_box = op.getarg(1)
-_, _, changed = cpu_simplify_scale(index_box, itemsize, basesize)
+_, _, changed = cpu_simplify_scale(state.cpu, index_box, itemsize, 
basesize)
 if changed is not index_box:
 state.oplist.append(changed)
 op.setarg(1, changed)
diff --git a/rpython/jit/backend/ppc/vector_ext.py 
b/rpython/jit/backend/ppc/vector_ext.py
--- a/rpython/jit/backend/ppc/vector_ext.py
+++ b/rpython/jit/backend/ppc/vector_ext.py
@@ -16,8 +16,10 @@
 from rpython.jit.backend.ppc.arch import PARAM_SAVE_AREA_OFFSET
 import rpython.jit.backend.ppc.register as r
 import rpython.jit.backend.ppc.condition as c
+import rpython.jit.backend.ppc.locations as l
 from rpython.jit.backend.llsupport.asmmemmgr import MachineDataBlockWrapper
 from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.jit.codewriter import longlong
 
 def not_implemented(msg):
 msg = '[ppc/vector_ext] %s\n' % msg
@@ -441,13 +443,14 @@
 res, l0, l1, sizeloc = arglocs
 size = sizeloc.value
 if size == 1:
-self.vcmpequbx(res.value, l0.value, l1.value)
+self.mc.vcmpequbx(res.value, l0.value, l1.value)
 elif size == 2:
-self.vcmpequhx(res.value, l0.value, l1.value)
+self.mc.vcmpequhx(res.value, l0.value, l1.value)
 elif size == 4:
-self.vcmpequwx(res.value, l0.value, l1.value)
+self.mc.vcmpequwx(res.value, l0.value, l1.value)
 elif size == 8:
-self.vcmpequdx(res.value, l0.value, l1.value)
+self.mc.vcmpequdx(res.value, l0.value, l1.value)
+flush_vec_cc(self, regalloc, c.EQ, op.bytesize, res)
 
 def emit_vec_int_ne(self, op, arglocs, regalloc):
 res, l0, l1, sizeloc = arglocs
@@ -455,62 +458,55 @@
 tmp = regalloc.get_scratch_reg().value
 self.mc.vxor(tmp, tmp, tmp)
 if size == 1:
-self.vcmpequb(res.value, l0.value, l1.value)
-self.vcmpequbx(res.value, res.value, tmp)
+self.mc.vcmpequbx(res.value, res.value, tmp)
 elif size == 2:
-self.vcmpequh(res.value, l0.value, l1.value)
-self.vcmpequhx(res.value, res.value, tmp)
+self.mc.vcmpequhx(res.value, res.value, tmp)
 elif size == 4:
-self.vcmpequw(res.value, l0.value, l1.value)
-self.vcmpequwx(res.value, res.value, tmp)
+self.mc.vcmpequwx(res.value, res.value, tmp)
 elif size == 8:
-self.vcmpequd(res.value, l0.value, l1.value)
-self.vcmpequdx(res.value, res.value, tmp)
+self.mc.vcmpequdx(res.value, res.value, tmp)
+self.mc.vnor(res.value, res.value, res.value)
+flush_vec_cc(self, regalloc, c.NE, op.bytesize, res)
 
-#def genop_vec_cast_float_to_int(self, op, arglocs, regalloc):
-#self.mc.CVTPD2DQ(resloc, arglocs[0])
-#def genop_vec_cast_singlefloat_to_float(self, op, arglocs, regalloc):
-#self.mc.CVTPS2PD(resloc, arglocs[0])
+def emit_vec_expand_f(self, op, arglocs, regalloc):
+resloc, srcloc = arglocs
+size = op.bytesize
+res = resloc.value
+if isinstance(srcloc, l.ConstFloatLoc):
+# they are aligned!
+assert size == 8
+tloc = regalloc.rm.get_scratch_reg()
+self.mc.load_imm(tloc, srcloc.value)
+  

[pypy-commit] pypy ppc-vsx-support: finish the impl. of vec_float_eq/ne + test

2016-06-28 Thread plan_rich
Author: Richard Plangger 
Branch: ppc-vsx-support
Changeset: r85434:780c12936a64
Date: 2016-06-28 16:24 +0200
http://bitbucket.org/pypy/pypy/changeset/780c12936a64/

Log:finish the impl. of vec_float_eq/ne + test

diff --git a/rpython/jit/backend/ppc/codebuilder.py 
b/rpython/jit/backend/ppc/codebuilder.py
--- a/rpython/jit/backend/ppc/codebuilder.py
+++ b/rpython/jit/backend/ppc/codebuilder.py
@@ -683,9 +683,12 @@
 vor = VX(4, XO8=1156)
 veqv = VX(4, XO8=1668)
 vxor = VX(4, XO8=1220)
+vnor = VX(4, XO8=1284)
 
 # vector move register is alias to vector or
 vmr = vor
+# complement is equivalent to vnor
+vnot = vnor
 
 # shift, perm and select
 lvsl = XV(31, XO1=6)
diff --git a/rpython/jit/backend/ppc/runner.py 
b/rpython/jit/backend/ppc/runner.py
--- a/rpython/jit/backend/ppc/runner.py
+++ b/rpython/jit/backend/ppc/runner.py
@@ -52,6 +52,7 @@
 self.vector_ext = AltiVectorExt()
 self.vector_extension = True
 # ??? self.vector_horizontal_operations = True
+self.assembler.setup_once_vector()
 
 @rgc.no_release_gil
 def finish_once(self):
diff --git a/rpython/jit/backend/ppc/vector_ext.py 
b/rpython/jit/backend/ppc/vector_ext.py
--- a/rpython/jit/backend/ppc/vector_ext.py
+++ b/rpython/jit/backend/ppc/vector_ext.py
@@ -16,6 +16,8 @@
 from rpython.jit.backend.ppc.arch import PARAM_SAVE_AREA_OFFSET
 import rpython.jit.backend.ppc.register as r
 import rpython.jit.backend.ppc.condition as c
+from rpython.jit.backend.llsupport.asmmemmgr import MachineDataBlockWrapper
+from rpython.rtyper.lltypesystem import lltype, rffi
 
 def not_implemented(msg):
 msg = '[ppc/vector_ext] %s\n' % msg
@@ -23,12 +25,54 @@
 llop.debug_print(lltype.Void, msg)
 raise NotImplementedError(msg)
 
+def flush_vec_cc(asm, regalloc, condition, size, result_loc):
+# After emitting an instruction that leaves a boolean result in
+# a condition code (cc), call this.  In the common case, result_loc
+# will be set to SPP by the regalloc, which in this case means
+# "propagate it between this operation and the next guard by keeping
+# it in the cc".  In the uncommon case, result_loc is another
+# register, and we emit a load from the cc into this register.
+assert asm.guard_success_cc == c.cond_none
+if result_loc is r.SPP:
+asm.guard_success_cc = condition
+else:
+resval = result_loc.value
+# either doubleword integer 1 (2x) or word integer 1 (4x)
+ones = regalloc.ivrm.get_scratch_reg().value
+zeros = regalloc.ivrm.get_scratch_reg().value
+asm.mc.vxor(zeros, zeros, zeros)
+if size == 4:
+asm.mc.vspltisw(ones, 1)
+else:
+assert size == 8
+tloc = regalloc.rm.get_scratch_reg()
+asm.mc.load_imm(tloc, asm.VEC_DOUBLE_WORD_ONES)
+asm.mc.lvx(ones, 0, tloc.value)
+asm.mc.vsel(resval, zeros, ones, resval)
+
 class AltiVectorExt(VectorExt):
 pass
 
 class VectorAssembler(object):
 _mixin_ = True
 
+VEC_DOUBLE_WORD_ONES = 0
+
+def setup_once_vector(self):
+if IS_BIG_ENDIAN:
+# 2x 64 bit signed integer(1) BE
+data = (b'\x00' * 7 + b'\x01') * 2
+else:
+# 2x 64 bit signed integer(1) LE
+data = (b'\x01' + b'\x00' * 7) * 2
+datablockwrapper = MachineDataBlockWrapper(self.cpu.asmmemmgr, [])
+mem = datablockwrapper.malloc_aligned(len(data), alignment=16)
+datablockwrapper.done()
+addr = rffi.cast(rffi.CArrayPtr(lltype.Char), mem)
+for i in range(len(data)):
+addr[i] = data[i]
+self.VEC_DOUBLE_WORD_ONES = mem
+
 def emit_vec_load_f(self, op, arglocs, regalloc):
 resloc, baseloc, indexloc, size_loc, ofs, integer_loc, aligned_loc = 
arglocs
 #src_addr = addr_add(baseloc, ofs_loc, ofs.value, 0)
@@ -360,6 +404,7 @@
 else:
 notimplemented("[ppc/assembler] float == for size %d" % size)
 self.mc.lvx(resloc.value, off, r.SP.value)
+flush_vec_cc(self, regalloc, c.EQ, op.bytesize, resloc)
 
 def emit_vec_float_ne(self, op, arglocs, regalloc):
 resloc, loc1, loc2, sizeloc = arglocs
@@ -371,15 +416,16 @@
 self.mc.load_imm(offloc, PARAM_SAVE_AREA_OFFSET)
 if size == 4:
 self.mc.xvcmpeqspx(tmp, loc1.value, loc2.value)
-self.mc.xxlandc(tmp, tmp, tmp) # negate
 self.mc.stxvw4x(tmp, off, r.SP.value)
 elif size == 8:
 self.mc.xvcmpeqdpx(tmp, loc1.value, loc2.value)
-self.mc.xxlandc(tmp, tmp, tmp) # negate
 self.mc.stxvd2x(tmp, off, r.SP.value)
 else:
 notimplemented("[ppc/assembler] float == for size %d" % size)
-self.mc.lvx(resloc.value, off, r.SP.value)
+res = resloc.value
+self.mc.lvx(res, off, r.SP.value)
+self.mc.vnor(res, res, 

[pypy-commit] pypy guard-compatible: merge default

2016-06-28 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: guard-compatible
Changeset: r85428:5641802cb054
Date: 2016-06-24 17:33 +0200
http://bitbucket.org/pypy/pypy/changeset/5641802cb054/

Log:merge default

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -1,6 +1,6 @@
-=
+==
 What's new in PyPy2.7 5.3+
-=
+==
 
 .. this is a revision shortly after release-pypy2.7-v5.3
 .. startrev: 873218a739f1
@@ -37,3 +37,14 @@
 
 .. branch: pyfile-tell
 Sync w_file with the c-level FILE* before returning FILE* in PyFile_AsFile
+
+.. branch: rw-PyString_AS_STRING
+Allow rw access to the char* returned from PyString_AS_STRING, also refactor
+PyStringObject to look like cpython's and allow subclassing PyString_Type and
+PyUnicode_Type
+
+.. branch: save_socket_errno
+
+Bug fix: if ``socket.socket()`` failed, the ``socket.error`` did not show
+the errno of the failing system call, but instead some random previous
+errno.
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
@@ -800,6 +800,21 @@
 pypy_debug_catch_fatal_exception()
 assert False
 
+def _restore_gil_state(pygilstate_release, gilstate, gil_release, _gil_auto, 
tid):
+from rpython.rlib import rgil
+# see "Handling of the GIL" above
+assert cpyext_glob_tid_ptr[0] == 0
+if pygilstate_release:
+from pypy.module.cpyext import pystate
+unlock = (gilstate == pystate.PyGILState_UNLOCKED)
+else:
+unlock = gil_release or _gil_auto
+if unlock:
+rgil.release()
+else:
+cpyext_glob_tid_ptr[0] = tid
+
+
 def make_wrapper_second_level(space, argtypesw, restype,
   result_kind, error_value, gil):
 from rpython.rlib import rgil
@@ -827,6 +842,7 @@
 def wrapper_second_level(callable, pname, *args):
 from pypy.module.cpyext.pyobject import make_ref, from_ref, is_pyobj
 from pypy.module.cpyext.pyobject import as_pyobj
+from pypy.module.cpyext import pystate
 # we hope that malloc removal removes the newtuple() that is
 # inserted exactly here by the varargs specializer
 
@@ -839,7 +855,6 @@
 rgil.acquire()
 assert cpyext_glob_tid_ptr[0] == 0
 elif pygilstate_ensure:
-from pypy.module.cpyext import pystate
 if cpyext_glob_tid_ptr[0] == tid:
 cpyext_glob_tid_ptr[0] = 0
 args += (pystate.PyGILState_LOCKED,)
@@ -850,6 +865,10 @@
 if cpyext_glob_tid_ptr[0] != tid:
 no_gil_error(pname)
 cpyext_glob_tid_ptr[0] = 0
+if pygilstate_release:
+gilstate = rffi.cast(lltype.Signed, args[-1])
+else:
+gilstate = pystate.PyGILState_IGNORE
 
 rffi.stackcounter.stacks_counter += 1
 llop.gc_stack_bottom(lltype.Void)   # marker for trackgcroot.py
@@ -919,24 +938,13 @@
 
 except Exception as e:
 unexpected_exception(pname, e, tb)
+_restore_gil_state(pygilstate_release, gilstate, gil_release, 
_gil_auto, tid)
 return fatal_value
 
 assert lltype.typeOf(retval) == restype
 rffi.stackcounter.stacks_counter -= 1
 
-# see "Handling of the GIL" above
-assert cpyext_glob_tid_ptr[0] == 0
-if pygilstate_release:
-from pypy.module.cpyext import pystate
-arg = rffi.cast(lltype.Signed, args[-1])
-unlock = (arg == pystate.PyGILState_UNLOCKED)
-else:
-unlock = gil_release or _gil_auto
-if unlock:
-rgil.release()
-else:
-cpyext_glob_tid_ptr[0] = tid
-
+_restore_gil_state(pygilstate_release, gilstate, gil_release, 
_gil_auto, tid)
 return retval
 
 wrapper_second_level._dont_inline_ = True
@@ -1202,8 +1210,6 @@
 cpyext_type_init = self.cpyext_type_init
 self.cpyext_type_init = None
 for pto, w_type in cpyext_type_init:
-if space.is_w(w_type, space.w_str):
-pto.c_tp_itemsize = 1
 finish_type_1(space, pto)
 finish_type_2(space, pto, w_type)
 
diff --git a/pypy/module/cpyext/bytesobject.py 
b/pypy/module/cpyext/bytesobject.py
--- a/pypy/module/cpyext/bytesobject.py
+++ b/pypy/module/cpyext/bytesobject.py
@@ -6,7 +6,9 @@
 from pypy.module.cpyext.pyerrors import PyErr_BadArgument
 from pypy.module.cpyext.pyobject import (
 PyObject, PyObjectP, Py_DecRef, make_ref, from_ref, track_reference,
-make_typedescr, get_typedescr, as_pyobj, Py_IncRef, get_w_obj_and_decref)
+make_typedescr, get_typedescr, as_pyobj, Py_IncRef, get_w_obj_and_decref,
+pyobj_has_w_obj)
+from pypy.objspace.std.bytesobject import W_BytesObject
 
 ##
 ## Implementation of 

[pypy-commit] pypy guard-compatible: translation fixes

2016-06-28 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: guard-compatible
Changeset: r85427:c1d4078e392b
Date: 2016-06-24 17:31 +0200
http://bitbucket.org/pypy/pypy/changeset/c1d4078e392b/

Log:translation fixes

diff --git a/rpython/jit/metainterp/optimizeopt/unroll.py 
b/rpython/jit/metainterp/optimizeopt/unroll.py
--- a/rpython/jit/metainterp/optimizeopt/unroll.py
+++ b/rpython/jit/metainterp/optimizeopt/unroll.py
@@ -88,6 +88,7 @@
 if preamble_info._compatibility_conditions:
 info_in_loop = op.get_forwarded()
 if info_in_loop is not None:
+assert isinstance(info_in_loop, info.PtrInfo)
 ccond = preamble_info._compatibility_conditions
 ccond = ccond.frozen_copy()
 info_in_loop._compatibility_conditions = ccond
diff --git a/rpython/jit/metainterp/optimizeopt/virtualstate.py 
b/rpython/jit/metainterp/optimizeopt/virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualstate.py
@@ -1,7 +1,7 @@
 from rpython.jit.metainterp.walkvirtual import VirtualVisitor
 from rpython.jit.metainterp.history import ConstInt, ConstPtr, ConstFloat
 from rpython.jit.metainterp.optimizeopt.info import ArrayPtrInfo,\
- ArrayStructInfo, AbstractStructPtrInfo
+ ArrayStructInfo, AbstractStructPtrInfo, PtrInfo
 from rpython.jit.metainterp.optimizeopt.intutils import \
  MININT, MAXINT, IntBound, IntLowerBound
 from rpython.jit.metainterp.resoperation import rop, ResOperation,\
@@ -355,6 +355,7 @@
 if type == 'i':
 return NotVirtualStateInfoInt(cpu, type, info)
 if type == 'r':
+assert isinstance(info, PtrInfo)
 if info is not None and info._compatibility_conditions is not None:
 return NotVirtualStateInfoPtrCompatible(cpu, type, info)
 return NotVirtualStateInfoPtr(cpu, type, info)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy guard-compatible: typo

2016-06-28 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: guard-compatible
Changeset: r85431:3e20ab453a7c
Date: 2016-06-27 14:55 +0200
http://bitbucket.org/pypy/pypy/changeset/3e20ab453a7c/

Log:typo

diff --git a/rpython/jit/metainterp/compatible.py 
b/rpython/jit/metainterp/compatible.py
--- a/rpython/jit/metainterp/compatible.py
+++ b/rpython/jit/metainterp/compatible.py
@@ -293,7 +293,7 @@
 else:
 assert rettype == VOID
 # XXX maybe we should forbid this
-call_op = ResOperation(rop.CALL_PURE_R, args, descr)
+call_op = ResOperation(rop.CALL_PURE_N, args, descr)
 short.append(call_op)
 return
 # add result to call_pure_results
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy guard-compatible: this test shows a problem: we now get 88 bridges(!)

2016-06-28 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: guard-compatible
Changeset: r85433:cedd97e275af
Date: 2016-06-28 14:46 +0200
http://bitbucket.org/pypy/pypy/changeset/cedd97e275af/

Log:this test shows a problem: we now get 88 bridges(!)

diff --git a/rpython/jit/metainterp/test/test_compatible.py 
b/rpython/jit/metainterp/test/test_compatible.py
--- a/rpython/jit/metainterp/test/test_compatible.py
+++ b/rpython/jit/metainterp/test/test_compatible.py
@@ -370,6 +370,12 @@
 p2 = lltype.malloc(S)
 p2.x = 1
 
+p3 = lltype.malloc(S)
+p3.x = 2
+
+p4 = lltype.malloc(S)
+p4.x = 2
+
 driver = jit.JitDriver(greens = [], reds = ['n'])
 
 class A(object):
@@ -402,6 +408,12 @@
 f(1000)
 glob_b.x = p2
 f(1000)
+glob_b.x = p3
+f(1000)
+glob_b.x = p4
+f(1000)
+glob_b.x = p1
+f(1000)
 return c.count
 
 x = self.meta_interp(main, [])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy guard-compatible: nonsense

2016-06-28 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: guard-compatible
Changeset: r85429:eedbe90f19b9
Date: 2016-06-24 18:15 +0200
http://bitbucket.org/pypy/pypy/changeset/eedbe90f19b9/

Log:nonsense

diff --git a/rpython/jit/metainterp/optimizeopt/virtualstate.py 
b/rpython/jit/metainterp/optimizeopt/virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualstate.py
@@ -355,9 +355,10 @@
 if type == 'i':
 return NotVirtualStateInfoInt(cpu, type, info)
 if type == 'r':
-assert isinstance(info, PtrInfo)
-if info is not None and info._compatibility_conditions is not None:
-return NotVirtualStateInfoPtrCompatible(cpu, type, info)
+if info is not None:
+if (isinstance(info, PtrInfo) and
+info._compatibility_conditions is not None):
+return NotVirtualStateInfoPtrCompatible(cpu, type, info)
 return NotVirtualStateInfoPtr(cpu, type, info)
 return NotVirtualStateInfo(cpu, type, info)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy guard-compatible: simply call @elidable_compatible functions where we don't have a result

2016-06-28 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: guard-compatible
Changeset: r85432:f9d5045ab715
Date: 2016-06-27 19:10 +0200
http://bitbucket.org/pypy/pypy/changeset/f9d5045ab715/

Log:simply call @elidable_compatible functions where we don't have a
result (this can only happen when inlining the short preamble into a
bridge)

diff --git a/rpython/jit/metainterp/compatible.py 
b/rpython/jit/metainterp/compatible.py
--- a/rpython/jit/metainterp/compatible.py
+++ b/rpython/jit/metainterp/compatible.py
@@ -78,6 +78,20 @@
 return True
 
 def prepare_const_arg_call(self, op, optimizer):
+copied_op, cond = self._prepare_const_arg_call(op, optimizer)
+if copied_op:
+result = optimizer._can_optimize_call_pure(copied_op)
+if result is None:
+# just call it, we can do that with an @elidable_compatible
+# function
+result = do_call(
+optimizer.cpu, copied_op.getarglist(),
+copied_op.getdescr())
+return copied_op, cond, result
+else:
+return None, None, None
+
+def _prepare_const_arg_call(self, op, optimizer):
 from rpython.jit.metainterp.quasiimmut import QuasiImmutDescr
 # replace further arguments by constants, if the optimizer knows them
 # already
diff --git a/rpython/jit/metainterp/optimizeopt/pure.py 
b/rpython/jit/metainterp/optimizeopt/pure.py
--- a/rpython/jit/metainterp/optimizeopt/pure.py
+++ b/rpython/jit/metainterp/optimizeopt/pure.py
@@ -142,17 +142,15 @@
 ccond = info._compatibility_conditions
 if ccond:
 # it's subject to guard_compatible
-copied_op, cond = ccond.prepare_const_arg_call(
+copied_op, cond, result = ccond.prepare_const_arg_call(
 op, self.optimizer)
 if copied_op:
-result = self._can_optimize_call_pure(copied_op)
-if result is not None:
-recorded = ccond.record_condition(
-cond, result, self.optimizer)
-if recorded:
-self.make_constant(op, result)
-self.last_emitted_operation = REMOVED
-return
+recorded = ccond.record_condition(
+cond, result, self.optimizer)
+if recorded:
+self.make_constant(op, result)
+self.last_emitted_operation = REMOVED
+return
 
 # Step 1: check if all arguments are constant
 for arg in op.getarglist():
diff --git a/rpython/jit/metainterp/test/test_compatible.py 
b/rpython/jit/metainterp/test/test_compatible.py
--- a/rpython/jit/metainterp/test/test_compatible.py
+++ b/rpython/jit/metainterp/test/test_compatible.py
@@ -528,3 +528,78 @@
 self.check_trace_count(7)
 
 
+def test_quasi_immutable_merge_short_preamble(self):
+from rpython.rlib.objectmodel import we_are_translated
+class C(object):
+_immutable_fields_ = ['version?']
+
+class Version(object):
+def __init__(self, cls):
+self.cls = cls
+p1 = C()
+p1.version = Version(p1)
+p1.x = 1
+p2 = C()
+p2.version = Version(p2)
+p2.x = 1
+p3 = C()
+p3.version = Version(p3)
+p3.x = 3
+
+driver = jit.JitDriver(greens = [], reds = ['n'])
+
+class Counter(object):
+pass
+
+c = Counter()
+c.count = 0
+@jit.elidable_compatible()
+def g(cls, v):
+if we_are_translated():
+c.count += 1
+return cls.x
+
+class B(object):
+pass
+
+glob_b = B()
+
+def f(n, x):
+glob_b.x = x
+res = 0
+while n > 0:
+driver.can_enter_jit(n=n)
+driver.jit_merge_point(n=n)
+x = jit.hint(glob_b.x, promote_compatible=True)
+v = x.version
+res = g(x, v)
+n -= res
+if n % 11 == 5:
+n -= 1
+return res
+
+def main(x):
+res = f(100, p1)
+assert res == 1
+res = f(100, p2)
+assert res == 1
+res = f(100, p3)
+assert res == 3
+main(True)
+main(False)
+
+x = self.meta_interp(main, [True])
+assert x < 70
+x = self.meta_interp(main, [True])
+assert x < 70
+x = self.meta_interp(main, [True])
+assert x < 70
+x 

[pypy-commit] pypy guard-compatible: corner case: sometimes the guarded value is really missing from the failargs,

2016-06-28 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: guard-compatible
Changeset: r85430:f8abbe802a80
Date: 2016-06-24 23:39 +0200
http://bitbucket.org/pypy/pypy/changeset/f8abbe802a80/

Log:corner case: sometimes the guarded value is really missing from the
failargs, in which case we are annoyed, but should still not crash.

diff --git a/rpython/jit/metainterp/compile.py 
b/rpython/jit/metainterp/compile.py
--- a/rpython/jit/metainterp/compile.py
+++ b/rpython/jit/metainterp/compile.py
@@ -1114,19 +1114,19 @@
 # if new_loop starts with another guard_compatible on the same argument
 # (which is most of the time) we have to connect the new guard's descr
 # to this descr
-assert self.failarg_index != -1
-arg = new_loop.inputargs[self.failarg_index]
-firstop = new_loop.operations[0]
 compat_cond = None
-if (firstop.getopnum() == rop.GUARD_COMPATIBLE and
-firstop.getarg(0) is arg):
-# a guard_compatible about the same box
-# remove it, it doesn't have to be checked in the bridge
-del new_loop.operations[0]
-newdescr = firstop.getdescr()
-assert isinstance(newdescr, GuardCompatibleDescr)
-compat_cond = newdescr._compatibility_conditions
-self.other_compat_conditions.append(compat_cond)
+if self.failarg_index != -1:
+arg = new_loop.inputargs[self.failarg_index]
+firstop = new_loop.operations[0]
+if (firstop.getopnum() == rop.GUARD_COMPATIBLE and
+firstop.getarg(0) is arg):
+# a guard_compatible about the same box
+# remove it, it doesn't have to be checked in the bridge
+del new_loop.operations[0]
+newdescr = firstop.getdescr()
+assert isinstance(newdescr, GuardCompatibleDescr)
+compat_cond = newdescr._compatibility_conditions
+self.other_compat_conditions.append(compat_cond)
 asminfo = ResumeGuardDescr.compile_and_attach(
 self, metainterp, new_loop, orig_inputargs)
 if compat_cond:
@@ -1134,8 +1134,12 @@
 return asminfo
 
 def make_a_counter_per_value(self, guard_value_op, index):
-self.failarg_index = guard_value_op.getfailargs().index(
-guard_value_op.getarg(0))
+try:
+self.failarg_index = guard_value_op.getfailargs().index(
+guard_value_op.getarg(0))
+except ValueError:
+pass # we don't set the failarg_index, too bad
+
 # this is not actually enabling the counter_per_value logic,
 # which right now gives bad results with a GUARD_COMPATIBLE
 #ResumeGuardDescr.make_a_counter_per_value(self, guard_value_op, index)
diff --git a/rpython/jit/metainterp/test/test_compatible.py 
b/rpython/jit/metainterp/test/test_compatible.py
--- a/rpython/jit/metainterp/test/test_compatible.py
+++ b/rpython/jit/metainterp/test/test_compatible.py
@@ -362,6 +362,53 @@
 # trace, two bridges, a finish bridge
 self.check_trace_count(4)
 
+def test_merge_obj_not_in_failargs(self):
+S = lltype.GcStruct('S', ('x', lltype.Signed))
+p1 = lltype.malloc(S)
+p1.x = 1
+
+p2 = lltype.malloc(S)
+p2.x = 1
+
+driver = jit.JitDriver(greens = [], reds = ['n'])
+
+class A(object):
+pass
+
+c = A()
+c.count = 0
+@jit.elidable_compatible()
+def g(s, ignored):
+c.count += 1
+return s.x
+
+class B(object):
+pass
+
+glob_b = B()
+
+def f(n):
+while n > 0:
+driver.can_enter_jit(n=n)
+driver.jit_merge_point(n=n)
+x = glob_b.x
+n -= g(x, "abc")
+if n & 2:
+n -= 2
+
+def main():
+g(p1, "def") # make annotator not make argument constant
+glob_b.x = p1
+f(1000)
+glob_b.x = p2
+f(1000)
+return c.count
+
+x = self.meta_interp(main, [])
+
+# trace, two bridges, a finish bridge
+self.check_trace_count(4)
+
 def test_merge_switch_object(self):
 S = lltype.GcStruct('S', ('x', lltype.Signed))
 p1 = lltype.malloc(S)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ppc-vsx-support: resolve several issues to run test_vector again

2016-06-28 Thread plan_rich
Author: Richard Plangger 
Branch: ppc-vsx-support
Changeset: r85425:647de5c9a91f
Date: 2016-06-27 16:17 +0200
http://bitbucket.org/pypy/pypy/changeset/647de5c9a91f/

Log:resolve several issues to run test_vector again

diff --git a/rpython/jit/backend/ppc/vector_ext.py 
b/rpython/jit/backend/ppc/vector_ext.py
--- a/rpython/jit/backend/ppc/vector_ext.py
+++ b/rpython/jit/backend/ppc/vector_ext.py
@@ -70,15 +70,11 @@
 genop_discard_vec_setarrayitem_gc = _emit_vec_setitem
 
 def emit_vec_store(self, op, arglocs, regalloc):
-baseloc, ofsloc, valueloc, size_loc, baseofs, \
+baseloc, indexloc, valueloc, sizeloc, baseofs, \
 integer_loc, aligned_loc = arglocs
 #dest_loc = addr_add(base_loc, ofs_loc, baseofs.value, 0)
 assert baseofs.value == 0
-#self._vec_store(baseloc, ofsloc, valueloc, integer_loc.value,
-#size_loc.value, regalloc)
-
-#def _vec_store(self, baseloc, indexloc, valueloc, integer, itemsize, 
regalloc):
-if integer:
+if integer_loc.value:
 Vloloc = regalloc.ivrm.get_scratch_reg()
 Vhiloc = regalloc.ivrm.get_scratch_reg()
 Vploc = regalloc.ivrm.get_scratch_reg()
@@ -117,6 +113,7 @@
 self.mc.stvx(Vlo, indexloc.value, t)
 self.mc.stvx(Vhi, indexloc.value, baseloc.value)
 else:
+itemsize = sizeloc.value
 if itemsize == 4:
 self.mc.stxvw4x(valueloc.value, indexloc.value, baseloc.value)
 elif itemsize == 8:
diff --git a/rpython/jit/metainterp/test/test_vector.py 
b/rpython/jit/metainterp/test/test_vector.py
--- a/rpython/jit/metainterp/test/test_vector.py
+++ b/rpython/jit/metainterp/test/test_vector.py
@@ -161,7 +161,6 @@
 self.meta_interp(f, [l*size, va, vb, vc])
 
 for i in range(l):
-import pdb; pdb.set_trace()
 c = raw_storage_getitem(type,vc,i*size)
 r = func(la[i], lb[i])
 assert isclose(r, c)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ppc-vsx-support: removed & renamed load/store combinations that are rewritten to vec_load/vec_store

2016-06-28 Thread plan_rich
Author: Richard Plangger 
Branch: ppc-vsx-support
Changeset: r85424:c3391ca232ac
Date: 2016-06-27 16:07 +0200
http://bitbucket.org/pypy/pypy/changeset/c3391ca232ac/

Log:removed & renamed load/store combinations that are rewritten to
vec_load/vec_store

diff --git a/rpython/jit/backend/llsupport/rewrite.py 
b/rpython/jit/backend/llsupport/rewrite.py
--- a/rpython/jit/backend/llsupport/rewrite.py
+++ b/rpython/jit/backend/llsupport/rewrite.py
@@ -158,10 +158,10 @@
 
 def _emit_mul_if_factor_offset_not_supported(self, index_box,
  factor, offset):
-factor, offset, index_box = cpu_simplify_scale(self.cpu, indexbox, 
factor, offset)
-if index_box:
+factor, offset, new_index_box = cpu_simplify_scale(self.cpu, 
index_box, factor, offset)
+if index_box is not new_index_box:
 self.emit_op(index_box)
-return factor, offset, index_box
+return factor, offset, new_index_box
 
 def emit_gc_load_or_indexed(self, op, ptr_box, index_box, itemsize,
 factor, offset, sign, type='i'):
diff --git a/rpython/jit/backend/llsupport/vector_ext.py 
b/rpython/jit/backend/llsupport/vector_ext.py
--- a/rpython/jit/backend/llsupport/vector_ext.py
+++ b/rpython/jit/backend/llsupport/vector_ext.py
@@ -3,6 +3,7 @@
 from rpython.rlib.objectmodel import specialize, always_inline
 from rpython.jit.metainterp.history import (VECTOR, FLOAT, INT)
 from rpython.jit.metainterp.resoperation import rop
+from rpython.jit.metainterp.optimizeopt.schedule import forwarded_vecinfo
 
 class TypeRestrict(object):
 ANY_TYPE = '\x00'
diff --git a/rpython/jit/backend/ppc/vector_ext.py 
b/rpython/jit/backend/ppc/vector_ext.py
--- a/rpython/jit/backend/ppc/vector_ext.py
+++ b/rpython/jit/backend/ppc/vector_ext.py
@@ -26,22 +26,7 @@
 class VectorAssembler(object):
 _mixin_ = True
 
-def _emit_getitem(self, op, arglocs, regalloc):
-# prepares item scale (raw_load does not)
-resloc, base_loc, ofs_loc, size_loc, ofs, integer_loc, aligned_loc = 
arglocs
-scale = get_scale(size_loc.value)
-xxx
-src_addr = addr_add(base_loc, ofs_loc, ofs.value, scale)
-self._vec_load(resloc, src_addr, integer_loc.value,
-   size_loc.value, aligned_loc.value)
-
-emit_vec_getarrayitem_raw_i = _emit_getitem
-emit_vec_getarrayitem_raw_f = _emit_getitem
-
-emit_vec_getarrayitem_gc_i = _emit_getitem
-emit_vec_getarrayitem_gc_f = _emit_getitem
-
-def emit_vec_raw_load_f(self, op, arglocs, regalloc):
+def emit_vec_load_f(self, op, arglocs, regalloc):
 resloc, baseloc, indexloc, size_loc, ofs, integer_loc, aligned_loc = 
arglocs
 #src_addr = addr_add(baseloc, ofs_loc, ofs.value, 0)
 assert ofs.value == 0
@@ -51,7 +36,7 @@
 elif itemsize == 8:
 self.mc.lxvd2x(resloc.value, indexloc.value, baseloc.value)
 
-def emit_vec_raw_load_i(self, op, arglocs, regalloc):
+def emit_vec_load_i(self, op, arglocs, regalloc):
 resloc, baseloc, indexloc, size_loc, ofs, \
 Vhiloc, Vloloc, Vploc, tloc = arglocs
 #src_addr = addr_add(base_loc, ofs_loc, ofs.value, 0)
@@ -84,15 +69,15 @@
 genop_discard_vec_setarrayitem_raw = _emit_vec_setitem
 genop_discard_vec_setarrayitem_gc = _emit_vec_setitem
 
-def emit_vec_raw_store(self, op, arglocs, regalloc):
+def emit_vec_store(self, op, arglocs, regalloc):
 baseloc, ofsloc, valueloc, size_loc, baseofs, \
 integer_loc, aligned_loc = arglocs
 #dest_loc = addr_add(base_loc, ofs_loc, baseofs.value, 0)
 assert baseofs.value == 0
-self._vec_store(baseloc, ofsloc, valueloc, integer_loc.value,
-size_loc.value, regalloc)
+#self._vec_store(baseloc, ofsloc, valueloc, integer_loc.value,
+#size_loc.value, regalloc)
 
-def _vec_store(self, baseloc, indexloc, valueloc, integer, itemsize, 
regalloc):
+#def _vec_store(self, baseloc, indexloc, valueloc, integer, itemsize, 
regalloc):
 if integer:
 Vloloc = regalloc.ivrm.get_scratch_reg()
 Vhiloc = regalloc.ivrm.get_scratch_reg()
@@ -137,7 +122,6 @@
 elif itemsize == 8:
 self.mc.stxvd2x(valueloc.value, indexloc.value, baseloc.value)
 
-
 def emit_vec_int_add(self, op, arglocs, regalloc):
 resloc, loc0, loc1, size_loc = arglocs
 size = size_loc.value
@@ -601,12 +585,8 @@
 return [result_loc, base_loc, ofs_loc, imm(itemsize), imm(ofs),
 Vhiloc, Vloloc, Vploc, tloc]
 
-prepare_vec_getarrayitem_raw_i = _prepare_load_i
-prepare_vec_getarrayitem_raw_f = _prepare_load
-prepare_vec_getarrayitem_gc_i = _prepare_load_i
-prepare_vec_getarrayitem_gc_f = _prepare_load
-prepare_vec_raw_load_i = _prepare_load_i
-prepare_vec_raw_load_f = 

[pypy-commit] pypy ppc-vsx-support: add more vector resop implementations (comparison operators)

2016-06-28 Thread plan_rich
Author: Richard Plangger 
Branch: ppc-vsx-support
Changeset: r85426:973d081f4a33
Date: 2016-06-28 14:17 +0200
http://bitbucket.org/pypy/pypy/changeset/973d081f4a33/

Log:add more vector resop implementations (comparison operators)

diff --git a/rpython/jit/backend/ppc/codebuilder.py 
b/rpython/jit/backend/ppc/codebuilder.py
--- a/rpython/jit/backend/ppc/codebuilder.py
+++ b/rpython/jit/backend/ppc/codebuilder.py
@@ -67,6 +67,7 @@
 XX3_2 = Form("fvrT", "fvrA", "fvrB", "OE", "XO11")
 XV = Form("ivrT", "rA", "rB", "XO1")
 VX = Form("ivrT", "ivrA", "ivrB", "XO8")
+VC = Form("ivrT", "ivrA", "ivrB", "XO12", "OE")
 VXI = Form("ivrT", "SIM", "XO8")
 VA = Form("ivrT", "ivrA", "ivrB", "ivrC", "XO10")
 
@@ -629,6 +630,29 @@
 xvabsdp = XX2(60, XO6=473)
 xvabssp = XX2(60, XO6=409)
 
+# conversion from/to
+xvcvsxddp = XX2(60, XO6=504)
+
+# compare greater than unsigned int
+vcmpgtubx = VC(4, XO12=518, OE=1)
+vcmpgtub = VC(4, XO12=518, OE=0)
+vcmpgtuhx = VC(4, XO12=584, OE=1)
+vcmpgtuh = VC(4, XO12=584, OE=0)
+vcmpgtuwx = VC(4, XO12=646, OE=1)
+vcmpgtuw = VC(4, XO12=646, OE=0)
+vcmpgtudx = VC(4, XO12=711, OE=1)
+vcmpgtud = VC(4, XO12=711, OE=0)
+
+# compare equal to unsigned int
+vcmpequbx = VC(4, XO12=6, OE=1)
+vcmpequb = VC(4, XO12=6, OE=0)
+vcmpequhx = VC(4, XO12=70, OE=1)
+vcmpequh = VC(4, XO12=70, OE=0)
+vcmpequwx = VC(4, XO12=134, OE=1)
+vcmpequw = VC(4, XO12=134, OE=0)
+vcmpequdx = VC(4, XO12=199, OE=1)
+vcmpequd = VC(4, XO12=199, OE=0)
+
 # INTEGER
 # ---
 
@@ -658,6 +682,7 @@
 vand = VX(4, XO8=1028)
 vor = VX(4, XO8=1156)
 veqv = VX(4, XO8=1668)
+vxor = VX(4, XO8=1220)
 
 # vector move register is alias to vector or
 vmr = vor
diff --git a/rpython/jit/backend/ppc/ppc_field.py 
b/rpython/jit/backend/ppc/ppc_field.py
--- a/rpython/jit/backend/ppc/ppc_field.py
+++ b/rpython/jit/backend/ppc/ppc_field.py
@@ -65,6 +65,7 @@
 "XO9":(21, 28),
 "XO10":   (26, 31),
 "XO11":   (22, 28),
+"XO12":   (22, 31),
 "LL": ( 9, 10),
 "SIM":(11, 15),
 }
diff --git a/rpython/jit/backend/ppc/vector_ext.py 
b/rpython/jit/backend/ppc/vector_ext.py
--- a/rpython/jit/backend/ppc/vector_ext.py
+++ b/rpython/jit/backend/ppc/vector_ext.py
@@ -13,6 +13,9 @@
 from rpython.jit.backend.ppc.locations import imm
 from rpython.jit.backend.ppc.arch import IS_BIG_ENDIAN
 from rpython.jit.backend.llsupport.vector_ext import VectorExt
+from rpython.jit.backend.ppc.arch import PARAM_SAVE_AREA_OFFSET
+import rpython.jit.backend.ppc.register as r
+import rpython.jit.backend.ppc.condition as c
 
 def not_implemented(msg):
 msg = '[ppc/vector_ext] %s\n' % msg
@@ -146,7 +149,7 @@
 elif size == 8:
 self.mc.vsubudm(resloc.value, loc0.value, loc1.value)
 
-def emit_vec_float_add(self, op, arglocs, resloc):
+def emit_vec_float_add(self, op, arglocs, regalloc):
 resloc, loc0, loc1, itemsize_loc = arglocs
 itemsize = itemsize_loc.value
 if itemsize == 4:
@@ -154,7 +157,7 @@
 elif itemsize == 8:
 self.mc.xvadddp(resloc.value, loc0.value, loc1.value)
 
-def emit_vec_float_sub(self, op, arglocs, resloc):
+def emit_vec_float_sub(self, op, arglocs, regalloc):
 resloc, loc0, loc1, itemsize_loc = arglocs
 itemsize = itemsize_loc.value
 if itemsize == 4:
@@ -162,7 +165,7 @@
 elif itemsize == 8:
 self.mc.xvsubdp(resloc.value, loc0.value, loc1.value)
 
-def emit_vec_float_mul(self, op, arglocs, resloc):
+def emit_vec_float_mul(self, op, arglocs, regalloc):
 resloc, loc0, loc1, itemsize_loc = arglocs
 itemsize = itemsize_loc.value
 if itemsize == 4:
@@ -170,7 +173,7 @@
 elif itemsize == 8:
 self.mc.xvmuldp(resloc.value, loc0.value, loc1.value)
 
-def emit_vec_float_truediv(self, op, arglocs, resloc):
+def emit_vec_float_truediv(self, op, arglocs, regalloc):
 resloc, loc0, loc1, itemsize_loc = arglocs
 itemsize = itemsize_loc.value
 if itemsize == 4:
@@ -178,7 +181,8 @@
 elif itemsize == 8:
 self.mc.xvdivdp(resloc.value, loc0.value, loc1.value)
 
-def emit_vec_int_mul(self, op, arglocs, resloc):
+def emit_vec_int_mul(self, op, arglocs, regalloc):
+raise NotImplementedError
 pass # TODO
 
 def emit_vec_int_and(self, op, arglocs, regalloc):
@@ -198,7 +202,7 @@
 # TODO
 self.regalloc_mov(loc0, resloc)
 
-def emit_vec_float_abs(self, op, arglocs, resloc):
+def emit_vec_float_abs(self, op, arglocs, regalloc):
 resloc, argloc, sizeloc = arglocs
 size = sizeloc.value
 if size == 4:
@@ -208,7 +212,7 @@
 else:
 notimplemented("[ppc/assembler] float abs for size %d" % size)
 
-def emit_vec_float_neg(self, op, arglocs, resloc):
+def emit_vec_float_neg(self, op, arglocs, 

[pypy-commit] pypy reverse-debugger: astcompiler and basic interpreter support for $NUM

2016-06-28 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r85423:0d91eaae941b
Date: 2016-06-28 14:03 +0200
http://bitbucket.org/pypy/pypy/changeset/0d91eaae941b/

Log:astcompiler and basic interpreter support for $NUM

diff --git a/lib-python/2.7/opcode.py b/lib-python/2.7/opcode.py
--- a/lib-python/2.7/opcode.py
+++ b/lib-python/2.7/opcode.py
@@ -194,5 +194,6 @@
 def_op('CALL_METHOD', 202)# #args not including 'self'
 def_op('BUILD_LIST_FROM_ARG', 203)
 jrel_op('JUMP_IF_NOT_DEBUG', 204) # jump over assert statements
+def_op('LOAD_REVDB_VAR', 205) # reverse debugger (syntax example: $5)
 
 del def_op, name_op, jrel_op, jabs_op
diff --git a/pypy/interpreter/astcompiler/assemble.py 
b/pypy/interpreter/astcompiler/assemble.py
--- a/pypy/interpreter/astcompiler/assemble.py
+++ b/pypy/interpreter/astcompiler/assemble.py
@@ -664,6 +664,7 @@
 ops.JUMP_IF_NOT_DEBUG: 0,
 
 ops.BUILD_LIST_FROM_ARG: 1,
+ops.LOAD_REVDB_VAR: 1,
 }
 
 
diff --git a/pypy/interpreter/astcompiler/ast.py 
b/pypy/interpreter/astcompiler/ast.py
--- a/pypy/interpreter/astcompiler/ast.py
+++ b/pypy/interpreter/astcompiler/ast.py
@@ -1534,6 +1534,8 @@
 return Num.from_object(space, w_node)
 if space.isinstance_w(w_node, get(space).w_Str):
 return Str.from_object(space, w_node)
+if space.isinstance_w(w_node, get(space).w_RevDBMetaVar):
+return RevDBMetaVar.from_object(space, w_node)
 if space.isinstance_w(w_node, get(space).w_Attribute):
 return Attribute.from_object(space, w_node)
 if space.isinstance_w(w_node, get(space).w_Subscript):
@@ -2344,6 +2346,41 @@
 State.ast_type('Str', 'expr', ['s'])
 
 
+class RevDBMetaVar(expr):
+
+def __init__(self, metavar, lineno, col_offset):
+self.metavar = metavar
+expr.__init__(self, lineno, col_offset)
+
+def walkabout(self, visitor):
+visitor.visit_RevDBMetaVar(self)
+
+def mutate_over(self, visitor):
+return visitor.visit_RevDBMetaVar(self)
+
+def to_object(self, space):
+w_node = space.call_function(get(space).w_RevDBMetaVar)
+w_metavar = space.wrap(self.metavar)  # int
+space.setattr(w_node, space.wrap('metavar'), w_metavar)
+w_lineno = space.wrap(self.lineno)  # int
+space.setattr(w_node, space.wrap('lineno'), w_lineno)
+w_col_offset = space.wrap(self.col_offset)  # int
+space.setattr(w_node, space.wrap('col_offset'), w_col_offset)
+return w_node
+
+@staticmethod
+def from_object(space, w_node):
+w_metavar = get_field(space, w_node, 'metavar', False)
+w_lineno = get_field(space, w_node, 'lineno', False)
+w_col_offset = get_field(space, w_node, 'col_offset', False)
+_metavar = space.int_w(w_metavar)
+_lineno = space.int_w(w_lineno)
+_col_offset = space.int_w(w_col_offset)
+return RevDBMetaVar(_metavar, _lineno, _col_offset)
+
+State.ast_type('RevDBMetaVar', 'expr', ['metavar'])
+
+
 class Attribute(expr):
 
 def __init__(self, value, attr, ctx, lineno, col_offset):
@@ -3439,6 +3476,8 @@
 return self.default_visitor(node)
 def visit_Str(self, node):
 return self.default_visitor(node)
+def visit_RevDBMetaVar(self, node):
+return self.default_visitor(node)
 def visit_Attribute(self, node):
 return self.default_visitor(node)
 def visit_Subscript(self, node):
@@ -3655,6 +3694,9 @@
 def visit_Str(self, node):
 pass
 
+def visit_RevDBMetaVar(self, node):
+pass
+
 def visit_Attribute(self, node):
 node.value.walkabout(self)
 
diff --git a/pypy/interpreter/astcompiler/astbuilder.py 
b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -1160,6 +1160,11 @@
 elif first_child_type == tokens.BACKQUOTE:
 expr = self.handle_testlist(atom_node.get_child(1))
 return ast.Repr(expr, atom_node.get_lineno(), 
atom_node.get_column())
+elif first_child_type == tokens.REVDBMETAVAR:
+string = atom_node.get_child(0).get_value()
+return ast.RevDBMetaVar(int(string[1:]),
+atom_node.get_lineno(),
+atom_node.get_column())
 else:
 raise AssertionError("unknown atom")
 
diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -1196,6 +1196,14 @@
 sub.value.walkabout(self)
 self._compile_slice(sub.slice, sub.ctx)
 
+def visit_RevDBMetaVar(self, node):
+if self.space.config.translation.reverse_debugger:
+from pypy.interpreter.reverse_debugging import dbstate
+if dbstate.extend_syntax_with_dollar_num:
+  

[pypy-commit] pypy default: ast.py was manually edited (in a non-essential way), fix asdl_py.py to match

2016-06-28 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r85422:00804b502576
Date: 2016-06-28 13:32 +0200
http://bitbucket.org/pypy/pypy/changeset/00804b502576/

Log:ast.py was manually edited (in a non-essential way), fix asdl_py.py
to match

diff --git a/pypy/interpreter/astcompiler/tools/asdl_py.py 
b/pypy/interpreter/astcompiler/tools/asdl_py.py
--- a/pypy/interpreter/astcompiler/tools/asdl_py.py
+++ b/pypy/interpreter/astcompiler/tools/asdl_py.py
@@ -400,7 +400,7 @@
 if not (space.isinstance_w(w_obj, space.w_str) or
 space.isinstance_w(w_obj, space.w_unicode)):
 raise oefmt(space.w_TypeError,
-   "AST string must be of type str or unicode")
+"AST string must be of type str or unicode")
 return w_obj
 
 def get_field(space, w_node, name, optional):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reverse-debugger: started pypy support: recognize in pyparser the syntax of a

2016-06-28 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r85421:91e8176fb344
Date: 2016-06-28 13:23 +0200
http://bitbucket.org/pypy/pypy/changeset/91e8176fb344/

Log:started pypy support: recognize in pyparser the syntax of a dollar
sign followed by a decimal number

diff --git a/pypy/interpreter/pyparser/data/Grammar2.7 
b/pypy/interpreter/pyparser/data/Grammar2.7
--- a/pypy/interpreter/pyparser/data/Grammar2.7
+++ b/pypy/interpreter/pyparser/data/Grammar2.7
@@ -104,7 +104,7 @@
'[' [listmaker] ']' |
'{' [dictorsetmaker] '}' |
'`' testlist1 '`' |
-   NAME | NUMBER | STRING+)
+   NAME | NUMBER | STRING+ | revdb_metavar)
 listmaker: test ( list_for | (',' test)* [','] )
 testlist_comp: test ( comp_for | (',' test)* [','] )
 lambdef: 'lambda' [varargslist] ':' test
@@ -141,3 +141,5 @@
 encoding_decl: NAME
 
 yield_expr: 'yield' [testlist]
+
+revdb_metavar: '$NUM'
diff --git a/pypy/interpreter/pyparser/genpytokenize.py 
b/pypy/interpreter/pyparser/genpytokenize.py
--- a/pypy/interpreter/pyparser/genpytokenize.py
+++ b/pypy/interpreter/pyparser/genpytokenize.py
@@ -140,7 +140,10 @@
 special = group(states,
 makeEOL(),
 groupStr(states, "@:;.,`"))
-funny = group(states, operator, bracket, special)
+revdb_metavar = chain(states,
+  groupStr(states, "$"),
+  atleastonce(states, makeDigits()))
+funny = group(states, operator, bracket, special, revdb_metavar)
 # 
 def makeStrPrefix ():
 return chain(states,
diff --git a/pypy/interpreter/pyparser/pytoken.py 
b/pypy/interpreter/pyparser/pytoken.py
--- a/pypy/interpreter/pyparser/pytoken.py
+++ b/pypy/interpreter/pyparser/pytoken.py
@@ -67,5 +67,6 @@
 # extra PyPy-specific tokens
 _add_tok("COMMENT")
 _add_tok("NL")
+_add_tok("REVDBMETAVAR", "$NUM")
 
 del _add_tok
diff --git a/pypy/interpreter/pyparser/pytokenize.py 
b/pypy/interpreter/pyparser/pytokenize.py
--- a/pypy/interpreter/pyparser/pytokenize.py
+++ b/pypy/interpreter/pyparser/pytokenize.py
@@ -25,37 +25,38 @@
 
 accepts = [True, True, True, True, True, True, True, True,
True, True, False, True, True, True, True, False,
-   False, False, True, False, False, True, False,
-   False, True, False, True, False, True, False,
-   False, True, False, False, True, True, True,
-   False, False, True, False, False, False, True]
+   False, False, False, True, False, False, True,
+   False, False, True, False, True, True, False,
+   True, False, False, True, False, False, True,
+   True, True, False, False, True, False, False,
+   False, True]
 states = [
 # 0
 {'\t': 0, '\n': 13, '\x0c': 0,
- '\r': 14, ' ': 0, '!': 10, '"': 16,
- '#': 18, '%': 12, '&': 12, "'": 15,
- '(': 13, ')': 13, '*': 7, '+': 12,
- ',': 13, '-': 12, '.': 6, '/': 11,
- '0': 4, '1': 5, '2': 5, '3': 5,
- '4': 5, '5': 5, '6': 5, '7': 5,
- '8': 5, '9': 5, ':': 13, ';': 13,
- '<': 9, '=': 12, '>': 8, '@': 13,
- 'A': 1, 'B': 2, 'C': 1, 'D': 1,
- 'E': 1, 'F': 1, 'G': 1, 'H': 1,
- 'I': 1, 'J': 1, 'K': 1, 'L': 1,
- 'M': 1, 'N': 1, 'O': 1, 'P': 1,
- 'Q': 1, 'R': 3, 'S': 1, 'T': 1,
- 'U': 2, 'V': 1, 'W': 1, 'X': 1,
- 'Y': 1, 'Z': 1, '[': 13, '\\': 17,
- ']': 13, '^': 12, '_': 1, '`': 13,
- 'a': 1, 'b': 2, 'c': 1, 'd': 1,
- 'e': 1, 'f': 1, 'g': 1, 'h': 1,
- 'i': 1, 'j': 1, 'k': 1, 'l': 1,
- 'm': 1, 'n': 1, 'o': 1, 'p': 1,
- 'q': 1, 'r': 3, 's': 1, 't': 1,
- 'u': 2, 'v': 1, 'w': 1, 'x': 1,
- 'y': 1, 'z': 1, '{': 13, '|': 12,
- '}': 13, '~': 13},
+ '\r': 14, ' ': 0, '!': 10, '"': 17,
+ '#': 19, '$': 15, '%': 12, '&': 12,
+ "'": 16, '(': 13, ')': 13, '*': 7,
+ '+': 12, ',': 13, '-': 12, '.': 6,
+ '/': 11, '0': 4, '1': 5, '2': 5,
+ '3': 5, '4': 5, '5': 5, '6': 5,
+ '7': 5, '8': 5, '9': 5, ':': 13,
+ ';': 13, '<': 9, '=': 12, '>': 8,
+ '@': 13, 'A': 1, 'B': 2, 'C': 1,
+ 'D': 1, 'E': 1, 'F': 1, 'G': 1,
+ 'H': 1, 'I': 1, 'J': 1, 'K': 1,
+ 'L': 1, 'M': 1, 'N': 1, 'O': 1,
+ 'P': 1, 'Q': 1, 'R': 3, 'S': 1,
+ 'T': 1, 'U': 2, 'V': 1, 'W': 1,
+ 'X': 1, 'Y': 1, 'Z': 1, '[': 13,
+ '\\': 18, ']': 13, '^': 12, '_': 1,
+ '`': 13, 'a': 1, 'b': 2, 'c': 1,
+ 'd': 1, 'e': 1, 'f': 1, 'g': 1,
+ 'h': 1, 'i': 1, 'j': 1, 'k': 1,
+ 'l': 1, 'm': 1, 'n': 1, 'o': 1,
+ 'p': 1, 'q': 1, 'r': 3, 's': 1,
+ 't': 1, 'u': 2, 'v': 1, 'w': 1,
+ 'x': 1, 'y': 1, 'z': 1, '{': 13,
+ '|': 12, '}': 13, '~': 13},
 # 1
 {'0': 1, '1': 1, '2': 1, '3': 1,
  '4': 1, '5': 1, '6': 1, '7': 1,
@@ -74,7 +75,7 @@
  't': 1, 'u': 1, 'v': 1, 'w': 1,
  'x': 1, 'y': 1, 'z': 1},
 # 2
-{'"': 16, "'": 15, '0': 1, '1': 1,
+{'"': 17, "'": 16, '0': 1, '1': 1,
  '2': 1, '3': 1, '4': 

[pypy-commit] pypy reverse-debugger: Bug fix

2016-06-28 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r85420:0cc665a2fb4e
Date: 2016-06-28 11:11 +0200
http://bitbucket.org/pypy/pypy/changeset/0cc665a2fb4e/

Log:Bug fix

diff --git a/rpython/translator/revdb/interact.py 
b/rpython/translator/revdb/interact.py
--- a/rpython/translator/revdb/interact.py
+++ b/rpython/translator/revdb/interact.py
@@ -3,7 +3,7 @@
 import traceback
 from contextlib import contextmanager
 
-from rpython.translator.revdb.process import ReplayProcessGroup, maxint64
+from rpython.translator.revdb.process import ReplayProcessGroup
 from rpython.translator.revdb.process import Breakpoint
 
 r_cmdline = re.compile(r"(\S+)\s*(.*)")
diff --git a/rpython/translator/revdb/process.py 
b/rpython/translator/revdb/process.py
--- a/rpython/translator/revdb/process.py
+++ b/rpython/translator/revdb/process.py
@@ -3,9 +3,6 @@
 from rpython.translator.revdb.message import *
 
 
-maxint64 = int(2**63 - 1)
-
-
 class Breakpoint(Exception):
 def __init__(self, time, num):
 self.time = time
@@ -24,7 +21,9 @@
 self.stack_depth = 0   # breaks if the depth becomes lower than this
 
 def __repr__(self):
-return 'AllBreakpoints(%r, %d)' % (self.num2name, self.stack_depth)
+return 'AllBreakpoints(%r, %r, %r, %d)' % (
+self.num2name, self.watchvalues, self.watchuids,
+self.stack_depth)
 
 def compare(self, other):
 if (self.num2name == other.num2name and
@@ -334,6 +333,8 @@
 if self.all_breakpoints.watchuids:
 uids = set()
 uids.update(*self.all_breakpoints.watchuids.values())
+#print self.all_breakpoints
+#print '\t===>', uids
 self.attach_printed_objects(uids, watch_env=True)
 
 def update_breakpoints(self):
@@ -379,6 +380,7 @@
 if name.startswith('W'):
 _, text = self.check_watchpoint_expr(name[1:])
 if text != self.all_breakpoints.watchvalues[num]:
+#print self.active.pid
 print 'updating watchpoint value: %s => %s' % (
 name[1:], text)
 self.all_breakpoints.watchvalues[num] = text
@@ -454,6 +456,10 @@
 future_uids.sort()
 pack_uids = [struct.pack('q', uid) for uid in future_uids]
 pack_uids = ''.join(pack_uids)
+#print '%d: from %d: CMD_FUTUREIDS %r' % (
+#self.active.pid,
+#self.active.current_time,
+#future_uids)
 self.active.send(Message(CMD_FUTUREIDS, extra=pack_uids))
 self.active.expect_ready()
 self.active.printed_objects = (
@@ -480,6 +486,8 @@
 def attach_printed_objects(self, uids, watch_env):
 for uid in uids:
 nid = self.all_printed_objects[uid]
+#print '%d: %s => %s (watch_env=%d)' % (self.active.pid, nid, uid,
+#   watch_env)
 self.active.send(Message(CMD_ATTACHID, nid, uid, int(watch_env)))
 self.active.expect_ready()
 
diff --git a/rpython/translator/revdb/src-revdb/revdb.c 
b/rpython/translator/revdb/src-revdb/revdb.c
--- a/rpython/translator/revdb/src-revdb/revdb.c
+++ b/rpython/translator/revdb/src-revdb/revdb.c
@@ -1155,7 +1155,7 @@
 rpy_revdb_commands.rp_alloc(uid, new_object);
 unprotect_jmpbuf();
 }
-uid_break = *future_next_id++;
+uid_break = *++future_next_id;
 restore_state();
 rpy_revdb.watch_enabled = watch_enabled;
 return uid;
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reverse-debugger: Clean up the breakpoint system, with a single 'stop_point_break'

2016-06-28 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r85419:9b947e1ab238
Date: 2016-06-28 10:07 +0200
http://bitbucket.org/pypy/pypy/changeset/9b947e1ab238/

Log:Clean up the breakpoint system, with a single 'stop_point_break'
controlled from several internal variables in revdb.c

diff --git a/rpython/translator/revdb/interact.py 
b/rpython/translator/revdb/interact.py
--- a/rpython/translator/revdb/interact.py
+++ b/rpython/translator/revdb/interact.py
@@ -65,6 +65,13 @@
 runner(argument)
 except Exception as e:
 traceback.print_exc()
+print >> sys.stderr
+print >> sys.stderr, 'Something went wrong.  You are now',
+print >> sys.stderr, 'in a pdb; press Ctrl-D to continue.'
+import pdb; pdb.post_mortem(sys.exc_info()[2])
+print >> sys.stderr
+print >> sys.stderr, 'You are back running %s.' % (
+sys.argv[0],)
 
 def command_help(self, argument):
 """Display commands summary"""
diff --git a/rpython/translator/revdb/message.py 
b/rpython/translator/revdb/message.py
--- a/rpython/translator/revdb/message.py
+++ b/rpython/translator/revdb/message.py
@@ -8,6 +8,7 @@
 CMD_QUIT  = -2 # Message(CMD_QUIT)
 CMD_FORWARD   = -3 # Message(CMD_FORWARD, steps, breakpoint_mode)
 CMD_FUTUREIDS = -4 # Message(CMD_FUTUREIDS, extra=list-of-8bytes-uids)
+CMD_PING  = -5 # Message(CMD_PING)
 # extra commands which are not handled by revdb.c, but
 # by revdb.register_debug_command()
 CMD_PRINT   = 1# Message(CMD_PRINT, extra=expression)
diff --git a/rpython/translator/revdb/process.py 
b/rpython/translator/revdb/process.py
--- a/rpython/translator/revdb/process.py
+++ b/rpython/translator/revdb/process.py
@@ -139,6 +139,14 @@
 Returns the Breakpoint or None.
 """
 assert not self.tainted
+
+# 
+currents = self.current_time, self.currently_created_objects
+self.send(Message(CMD_PING))
+self.expect_ready()
+assert currents == (self.current_time, self.currently_created_objects)
+# 
+
 self.send(Message(CMD_FORWARD, steps, ord(breakpoint_mode)))
 #
 # record the first ANSWER_BREAKPOINT, drop the others
@@ -150,7 +158,7 @@
 break
 if bkpt is None:
 bkpt = Breakpoint(msg.arg1, msg.arg3)
-assert msg.cmd == ANSWER_READY
+assert msg.cmd == ANSWER_READY, msg
 self.update_times(msg)
 return bkpt
 
diff --git a/rpython/translator/revdb/src-revdb/revdb.c 
b/rpython/translator/revdb/src-revdb/revdb.c
--- a/rpython/translator/revdb/src-revdb/revdb.c
+++ b/rpython/translator/revdb/src-revdb/revdb.c
@@ -28,6 +28,10 @@
 
 #define ASYNC_FINALIZER_TRIGGER((int16_t)0xff46)
 
+#define FID_REGULAR_MODE   'R'
+#define FID_SAVED_STATE'S'
+#define FID_JMPBUF_PROTECTED   'J'
+
 
 typedef struct {
 Signed version;
@@ -40,7 +44,7 @@
 rpy_revdb_t rpy_revdb;
 static char rpy_rev_buffer[16384];/* max. 32768 */
 static int rpy_rev_fileno = -1;
-static unsigned char flag_io_disabled;
+static char flag_io_disabled = FID_REGULAR_MODE;
 
 
 static void setup_record_mode(int argc, char *argv[]);
@@ -199,6 +203,7 @@
They are only invoked when we call GC_invoke_finalizers(),
which we only do at stop points in the case of revdb. 
 */
+assert(!RPY_RDB_REPLAY);
 assert(rpy_revdb.stop_point_break <= rpy_revdb.stop_point_seen + 1);
 rpy_revdb.stop_point_break = rpy_revdb.stop_point_seen + 1;
 }
@@ -214,26 +219,21 @@
 
 static void record_stop_point(void)
 {
-/* Invoke the finalizers now.  This will call boehm_fq_callback(),
-   which will enqueue the objects in the correct FinalizerQueue.
-   Then, call boehm_fq_trigger(), which calls finalizer_trigger().
-*/
+/* = FINALIZERS =
+
+   When the GC wants to invoke some finalizers, it causes this
+   to be called at the stop point.  The new-style finalizers
+   are only enqueued at this point.  The old-style finalizers
+   run immediately, conceptually just *after* the stop point.
+ */
 int i;
 char *p = rpy_rev_buffer;
 int64_t done;
 
+/* Write an ASYNC_FINALIZER_TRIGGER packet */
 rpy_reverse_db_flush();
+assert(current_packet_size() == 0);
 
-fq_trigger();
-
-/* This should be done without emitting anything to the rdb
-   log.  We check that, and emit just a ASYNC_FINALIZER_TRIGGER.
-*/
-if (current_packet_size() != 0) {
-fprintf(stderr,
-"record_stop_point emitted unexpected data into the rdb 
log\n");
-exit(1);
-}
 *(int16_t *)p = ASYNC_FINALIZER_TRIGGER;
 memcpy(rpy_revdb.buf_p, _revdb.stop_point_seen, sizeof(uint64_t));
 rpy_revdb.buf_p += sizeof(uint64_t);
@@ -251,6 +251,10