[pypy-svn] r51782 - in pypy/branch/unified-rtti/pypy: annotation rpython rpython/lltypesystem rpython/test
arigo at codespeak.net
arigo at codespeak.net
Fri Feb 22 11:48:01 CET 2008
Author: arigo
Date: Fri Feb 22 11:47:59 2008
New Revision: 51782
Modified:
pypy/branch/unified-rtti/pypy/annotation/binaryop.py
pypy/branch/unified-rtti/pypy/rpython/lltypesystem/lloperation.py
pypy/branch/unified-rtti/pypy/rpython/lltypesystem/opimpl.py
pypy/branch/unified-rtti/pypy/rpython/raddress.py
pypy/branch/unified-rtti/pypy/rpython/test/test_rptr.py
Log:
Translation support for adr|int, adr&~int.
Modified: pypy/branch/unified-rtti/pypy/annotation/binaryop.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/annotation/binaryop.py (original)
+++ pypy/branch/unified-rtti/pypy/annotation/binaryop.py Fri Feb 22 11:47:59 2008
@@ -1019,6 +1019,12 @@
def sub((s_addr, s_int)):
return SomeAddress(is_null=False)
+ def or_((s_addr, s_int)):
+ return SomeAddress()
+
+ def and_((s_addr, s_int)):
+ return SomeAddress()
+
class __extend__(pairtype(SomeAddress, SomeImpossibleValue)):
# need to override this specifically to hide the 'raise UnionError'
# of pairtype(SomeAddress, SomeObject).
Modified: pypy/branch/unified-rtti/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/branch/unified-rtti/pypy/rpython/lltypesystem/lloperation.py Fri Feb 22 11:47:59 2008
@@ -374,6 +374,8 @@
'adr_ne': LLOp(canfold=True),
'adr_gt': LLOp(canfold=True),
'adr_ge': LLOp(canfold=True),
+ 'adr_or': LLOp(canfold=True), # to add flags in bits 0,1
+ 'adr_and': LLOp(canfold=True), # to remove these flags
'adr_call': LLOp(canraise=(Exception,)),
'cast_ptr_to_adr': LLOp(sideeffects=False),
'cast_adr_to_ptr': LLOp(canfold=True),
Modified: pypy/branch/unified-rtti/pypy/rpython/lltypesystem/opimpl.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/lltypesystem/opimpl.py (original)
+++ pypy/branch/unified-rtti/pypy/rpython/lltypesystem/opimpl.py Fri Feb 22 11:47:59 2008
@@ -368,6 +368,16 @@
assert lltype.typeOf(offset) is lltype.Signed
return addr - offset
+def op_adr_or(addr, flags):
+ checkadr(addr)
+ assert lltype.typeOf(flags) is lltype.Signed
+ return addr | flags
+
+def op_adr_and(addr, flags):
+ checkadr(addr)
+ assert lltype.typeOf(flags) is lltype.Signed
+ return addr & flags
+
def op_adr_delta(addr1, addr2):
checkadr(addr1)
checkadr(addr2)
Modified: pypy/branch/unified-rtti/pypy/rpython/raddress.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/raddress.py (original)
+++ pypy/branch/unified-rtti/pypy/rpython/raddress.py Fri Feb 22 11:47:59 2008
@@ -99,6 +99,22 @@
return NotImplemented
rtype_inplace_sub = rtype_sub
+ def rtype_or_((r_addr, r_int), hop):
+ if r_int.lowleveltype == lltype.Signed:
+ v_addr, v_flags = hop.inputargs(Address, lltype.Signed)
+ return hop.genop('adr_or', [v_addr, v_flags], resulttype=Address)
+
+ return NotImplemented
+ rtype_inplace_or = rtype_or_
+
+ def rtype_and_((r_addr, r_int), hop):
+ if r_int.lowleveltype == lltype.Signed:
+ v_addr, v_flags = hop.inputargs(Address, lltype.Signed)
+ return hop.genop('adr_and', [v_addr, v_flags], resulttype=Address)
+
+ return NotImplemented
+ rtype_inplace_and = rtype_and_
+
class __extend__(pairtype(AddressRepr, AddressRepr)):
Modified: pypy/branch/unified-rtti/pypy/rpython/test/test_rptr.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/test/test_rptr.py (original)
+++ pypy/branch/unified-rtti/pypy/rpython/test/test_rptr.py Fri Feb 22 11:47:59 2008
@@ -162,6 +162,43 @@
res = interpret(fn, [5])
assert res is True
+def test_flags_in_low_bits():
+ S = GcStruct('S', ('x', Signed))
+ def fn():
+ s = malloc(S)
+ a = llmemory.cast_ptr_to_adr(s)
+ assert llmemory.cast_adr_to_int(a) & 3 == 0
+ assert llmemory.cast_adr_to_int(a | 0) & 3 == 0
+ assert llmemory.cast_adr_to_int(a | 1) & 3 == 1
+ assert llmemory.cast_adr_to_int(a | 2) & 3 == 2
+ assert llmemory.cast_adr_to_int(a | 3) & 3 == 3
+ assert llmemory.cast_adr_to_int(a & ~0) & 3 == 0
+ assert llmemory.cast_adr_to_int(a & ~1) & 3 == 0
+ assert llmemory.cast_adr_to_int(a & ~2) & 3 == 0
+ assert llmemory.cast_adr_to_int(a & ~3) & 3 == 0
+ assert llmemory.cast_adr_to_int((a | 1) & ~0) & 3 == 1
+ assert llmemory.cast_adr_to_int((a | 1) & ~1) & 3 == 0
+ assert llmemory.cast_adr_to_int((a | 1) & ~2) & 3 == 1
+ assert llmemory.cast_adr_to_int((a | 1) & ~3) & 3 == 0
+ assert llmemory.cast_adr_to_int((a | 2) & ~0) & 3 == 2
+ assert llmemory.cast_adr_to_int((a | 2) & ~1) & 3 == 2
+ assert llmemory.cast_adr_to_int((a | 2) & ~2) & 3 == 0
+ assert llmemory.cast_adr_to_int((a | 2) & ~3) & 3 == 0
+ assert llmemory.cast_adr_to_int((a | 3) & ~0) & 3 == 3
+ assert llmemory.cast_adr_to_int((a | 3) & ~1) & 3 == 2
+ assert llmemory.cast_adr_to_int((a | 3) & ~2) & 3 == 1
+ assert llmemory.cast_adr_to_int((a | 3) & ~3) & 3 == 0
+ a |= 1
+ assert a != llmemory.cast_ptr_to_adr(s)
+ a |= 2
+ assert a != llmemory.cast_ptr_to_adr(s)
+ a &= ~1
+ assert a != llmemory.cast_ptr_to_adr(s)
+ a &= ~2
+ assert a == llmemory.cast_ptr_to_adr(s)
+ assert llmemory.cast_adr_to_ptr(a, Ptr(S)) == s
+ interpret(fn, [])
+
def test_flavored_malloc():
T = GcStruct('T', ('y', Signed))
def fn(n):
More information about the Pypy-commit
mailing list