[pypy-svn] r68266 - in pypy/branch/gc-compress/pypy: rpython/lltypesystem rpython/lltypesystem/test translator/c translator/c/src

arigo at codespeak.net arigo at codespeak.net
Fri Oct 9 11:56:08 CEST 2009


Author: arigo
Date: Fri Oct  9 11:56:07 2009
New Revision: 68266

Modified:
   pypy/branch/gc-compress/pypy/rpython/lltypesystem/llgroup.py
   pypy/branch/gc-compress/pypy/rpython/lltypesystem/lloperation.py
   pypy/branch/gc-compress/pypy/rpython/lltypesystem/opimpl.py
   pypy/branch/gc-compress/pypy/rpython/lltypesystem/test/test_llgroup.py
   pypy/branch/gc-compress/pypy/translator/c/primitive.py
   pypy/branch/gc-compress/pypy/translator/c/src/llgroup.h
Log:
Yet Another Symbolic type, to combine a USHORT and some flags into a
single Signed value.


Modified: pypy/branch/gc-compress/pypy/rpython/lltypesystem/llgroup.py
==============================================================================
--- pypy/branch/gc-compress/pypy/rpython/lltypesystem/llgroup.py	(original)
+++ pypy/branch/gc-compress/pypy/rpython/lltypesystem/llgroup.py	Fri Oct  9 11:56:07 2009
@@ -69,3 +69,26 @@
         assert skipoffset.TYPE == lltype.typeOf(self.member).TO
         assert skipoffset.repeat == 1
         return self.grpptr._as_obj().members[self.index + 1]._as_ptr()
+
+
+class CombinedSymbolic(llmemory.Symbolic):
+    """A general-purpose Signed symbolic that combines a USHORT and the
+    rest of the word (typically flags).  Only supports extracting the USHORT
+    with 'llop.extract_ushort', and extracting the rest of the word with
+    '&~0xFFFF' or with a direct masking like '&0x10000'.
+    """
+    def annotation(self):
+        from pypy.annotation import model
+        return model.SomeInteger()
+
+    def lltype(self):
+        return lltype.Signed
+
+    def __init__(self, lowpart, rest):
+        assert (rest & 0xFFFF) == 0
+        self.lowpart = lowpart
+        self.rest = rest
+
+    def __and__(self, other):
+        assert (other & 0xFFFF) == 0
+        return self.rest & other

Modified: pypy/branch/gc-compress/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/gc-compress/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/branch/gc-compress/pypy/rpython/lltypesystem/lloperation.py	Fri Oct  9 11:56:07 2009
@@ -413,6 +413,7 @@
     'get_group_member':     LLOp(canfold=True),
     'get_next_group_member':LLOp(canfold=True),
     'is_group_member_zero': LLOp(canfold=True),
+    'extract_ushort':       LLOp(canfold=True),
 
     # __________ used by the JIT ________
 

Modified: pypy/branch/gc-compress/pypy/rpython/lltypesystem/opimpl.py
==============================================================================
--- pypy/branch/gc-compress/pypy/rpython/lltypesystem/opimpl.py	(original)
+++ pypy/branch/gc-compress/pypy/rpython/lltypesystem/opimpl.py	Fri Oct  9 11:56:07 2009
@@ -175,6 +175,13 @@
     assert isinstance(y, (int, llmemory.AddressOffset))
     return intmask(x + y)
 
+def op_int_and(x, y):
+    if not isinstance(x, int):
+        from pypy.rpython.lltypesystem import llgroup
+        assert isinstance(x, llgroup.CombinedSymbolic)
+    assert isinstance(y, int)
+    return x & y
+
 def op_int_mul(x, y):
     assert isinstance(x, (int, llmemory.AddressOffset))
     assert isinstance(y, (int, llmemory.AddressOffset))
@@ -410,6 +417,11 @@
         assert isinstance(memberoffset, int)
         return memberoffset == 0
 
+def op_extract_ushort(combinedoffset):
+    from pypy.rpython.lltypesystem import llgroup
+    assert isinstance(combinedoffset, llgroup.CombinedSymbolic)
+    return combinedoffset.lowpart
+
 # ____________________________________________________________
 
 def get_op_impl(opname):

Modified: pypy/branch/gc-compress/pypy/rpython/lltypesystem/test/test_llgroup.py
==============================================================================
--- pypy/branch/gc-compress/pypy/rpython/lltypesystem/test/test_llgroup.py	(original)
+++ pypy/branch/gc-compress/pypy/rpython/lltypesystem/test/test_llgroup.py	Fri Oct  9 11:56:07 2009
@@ -67,6 +67,12 @@
     test.build()
     grpptr = test.grpptr
     g1x = [test.g1a, test.g1b]
+    cs1 = CombinedSymbolic(test.g1b, 0x450000)
+    cs2 = CombinedSymbolic(test.g1b, 0x410000)
+    assert llop.extract_ushort(rffi.USHORT, cs1) is test.g1b
+    assert cs1 & ~0xFFFF == 0x450000
+    cslist = [cs1, cs2]
+    #
     def f():
         p = llop.get_group_member(lltype.Ptr(test.S1), grpptr, test.g1a)
         assert p == test.p1a
@@ -92,5 +98,12 @@
             p = llop.get_group_member(lltype.Ptr(test.S1), grpptr, g1x[i])
             assert p.x == expected[i]
         #
+        for i in range(2):
+            s = llop.extract_ushort(rffi.USHORT, cslist[i])
+            p = llop.get_group_member(lltype.Ptr(test.S1), grpptr, s)
+            assert p == test.p1b
+        assert cslist[0] & ~0xFFFF == 0x450000
+        assert cslist[1] & ~0xFFFF == 0x410000
+        #
         return 42
     return f

Modified: pypy/branch/gc-compress/pypy/translator/c/primitive.py
==============================================================================
--- pypy/branch/gc-compress/pypy/translator/c/primitive.py	(original)
+++ pypy/branch/gc-compress/pypy/translator/c/primitive.py	Fri Oct  9 11:56:07 2009
@@ -57,6 +57,8 @@
             return str(value.expr)
         elif isinstance(value, ComputedIntSymbolic):
             value = value.compute_fn()
+        elif isinstance(value, llgroup.CombinedSymbolic):
+            return '(%s|%dL)' % (name_ushort(value.lowpart, db), value.rest)
         else:
             raise Exception("unimplemented symbolic %r"%value)
     if value is None:

Modified: pypy/branch/gc-compress/pypy/translator/c/src/llgroup.h
==============================================================================
--- pypy/branch/gc-compress/pypy/translator/c/src/llgroup.h	(original)
+++ pypy/branch/gc-compress/pypy/translator/c/src/llgroup.h	Fri Oct  9 11:56:07 2009
@@ -14,6 +14,9 @@
 #define OP_IS_GROUP_MEMBER_ZERO(compactoffset, r) \
   r = (compactoffset == 0)
 
+#define OP_EXTRACT_USHORT(value, r) \
+  r = (unsigned short)value
+
 /* A macro to crash at compile-time if sizeof(group) is too large.
    Uses a hack that I've found on some random forum.  Haaaaaaaaaackish. */
 #define PYPY_GROUP_CHECK_SIZE(groupname)                              \



More information about the Pypy-commit mailing list