[pypy-svn] pypy jit-lsprofile: Start supporting both 32-bit and 64-bit. Type differences:

arigo commits-noreply at bitbucket.org
Wed Mar 16 20:15:08 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: jit-lsprofile
Changeset: r42728:5009a0570c3a
Date: 2011-03-16 14:07 -0400
http://bitbucket.org/pypy/pypy/changeset/5009a0570c3a/

Log:	Start supporting both 32-bit and 64-bit. Type differences:
	BoxFloats store floats on 64-bit but longlongs on 32-bit, and
	read_timestamp() returns an int on 64-bit but a r_longlong on
	32-bit.

diff --git a/pypy/rlib/rtimer.py b/pypy/rlib/rtimer.py
--- a/pypy/rlib/rtimer.py
+++ b/pypy/rlib/rtimer.py
@@ -1,14 +1,21 @@
 import time
 
-from pypy.rlib.rarithmetic import r_longlong, r_ulonglong
+from pypy.rlib.rarithmetic import r_longlong, r_ulonglong, r_uint
+from pypy.rlib.rarithmetic import intmask, longlongmask
 from pypy.rpython.extregistry import ExtRegistryEntry
-from pypy.rpython.lltypesystem import rffi
+from pypy.rpython.lltypesystem import lltype, rffi
+
+_is_64_bit = r_uint.BITS > 32
 
 
 def read_timestamp():
-    # returns a longlong.  When running on top of python, build
-    # the result a bit arbitrarily.
-    return r_longlong(r_ulonglong(long(time.time() * 500000000)))
+    # Returns a longlong on 32-bit, and a regular int on 64-bit.
+    # When running on top of python, build the result a bit arbitrarily.
+    x = long(time.time() * 500000000)
+    if _is_64_bit:
+        return intmask(x)
+    else:
+        return longlongmask(x)
 
 
 class ReadTimestampEntry(ExtRegistryEntry):
@@ -16,8 +23,15 @@
 
     def compute_result_annotation(self):
         from pypy.annotation.model import SomeInteger
-        return SomeInteger(knowntype=r_longlong)
+        if _is_64_bit:
+            return SomeInteger()
+        else:
+            return SomeInteger(knowntype=r_longlong)
 
     def specialize_call(self, hop):
         hop.exception_cannot_occur()
-        return hop.genop("ll_read_timestamp", [], resulttype=rffi.LONGLONG)
+        if _is_64_bit:
+            resulttype = lltype.Signed
+        else:
+            resulttype = rffi.LONGLONG
+        return hop.genop("ll_read_timestamp", [], resulttype=resulttype)

diff --git a/pypy/jit/codewriter/longlong.py b/pypy/jit/codewriter/longlong.py
--- a/pypy/jit/codewriter/longlong.py
+++ b/pypy/jit/codewriter/longlong.py
@@ -16,6 +16,7 @@
 
     from pypy.rlib.objectmodel import compute_hash
 
+    is_64_bit = True
     supports_longlong = False
     r_float_storage = float
     FLOATSTORAGE = lltype.Float
@@ -32,6 +33,7 @@
 
     from pypy.rlib import rarithmetic, longlong2float
 
+    is_64_bit = False
     supports_longlong = True
     r_float_storage = rarithmetic.r_longlong
     FLOATSTORAGE = lltype.SignedLongLong

diff --git a/pypy/jit/backend/llgraph/llimpl.py b/pypy/jit/backend/llgraph/llimpl.py
--- a/pypy/jit/backend/llgraph/llimpl.py
+++ b/pypy/jit/backend/llgraph/llimpl.py
@@ -25,7 +25,7 @@
 from pypy.rlib.objectmodel import ComputedIntSymbolic, we_are_translated
 from pypy.rlib.rarithmetic import ovfcheck
 from pypy.rlib.rarithmetic import r_longlong, r_ulonglong, r_uint
-from pypy.rlib.rtimer import c_read_timestamp
+from pypy.rlib.rtimer import read_timestamp
 
 import py
 from pypy.tool.ansi_print import ansi_log
@@ -858,7 +858,7 @@
         return llmemory.cast_ptr_to_adr(opaque_frame)
 
     def op_read_timestamp(self, descr):
-        return c_read_timestamp()
+        return read_timestamp()
 
     def op_call_may_force(self, calldescr, func, *args):
         assert not self._forced

diff --git a/pypy/jit/metainterp/executor.py b/pypy/jit/metainterp/executor.py
--- a/pypy/jit/metainterp/executor.py
+++ b/pypy/jit/metainterp/executor.py
@@ -5,8 +5,8 @@
 from pypy.rpython.lltypesystem import lltype, llmemory, rstr
 from pypy.rpython.ootypesystem import ootype
 from pypy.rpython.lltypesystem.lloperation import llop
-from pypy.rlib.rarithmetic import ovfcheck, r_uint, intmask
-from pypy.rlib.rtimer import c_read_timestamp
+from pypy.rlib.rarithmetic import ovfcheck, r_uint, intmask, r_longlong
+from pypy.rlib.rtimer import read_timestamp
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.jit.metainterp.history import BoxInt, BoxPtr, BoxFloat, check_descr
 from pypy.jit.metainterp.history import INT, REF, FLOAT, VOID, AbstractDescr
@@ -229,7 +229,13 @@
     rstr.copy_unicode_contents(src, dst, srcstart, dststart, length)
 
 def do_read_timestamp(cpu, _):
-    return BoxFloat(c_read_timestamp())
+    x = read_timestamp()
+    if longlong.is_64_bit:
+        assert isinstance(x, int)         # 64-bit
+        return BoxInt(x)
+    else:
+        assert isinstance(x, r_longlong)  # 32-bit
+        return BoxFloat(x)
 
 # ____________________________________________________________
 

diff --git a/pypy/jit/metainterp/blackhole.py b/pypy/jit/metainterp/blackhole.py
--- a/pypy/jit/metainterp/blackhole.py
+++ b/pypy/jit/metainterp/blackhole.py
@@ -1,5 +1,5 @@
 from pypy.rlib.unroll import unrolling_iterable
-from pypy.rlib.rtimer import c_read_timestamp
+from pypy.rlib.rtimer import read_timestamp
 from pypy.rlib.rarithmetic import intmask, LONG_BIT, r_uint, ovfcheck
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.rlib.debug import debug_start, debug_stop
@@ -1206,9 +1206,9 @@
     def bhimpl_unicodesetitem(cpu, unicode, index, newchr):
         cpu.bh_unicodesetitem(unicode, index, newchr)
 
-    @arguments(returns="f")
+    @arguments(returns=(longlong.is_64_bit and "i" or "f"))
     def bhimpl_ll_read_timestamp():
-        return c_read_timestamp()
+        return read_timestamp()
 
     # ----------
     # helpers to resume running in blackhole mode when a guard failed


More information about the Pypy-commit mailing list