[pypy-svn] r68132 - in pypy/trunk/pypy/jit: backend/llsupport metainterp metainterp/test

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Oct 2 23:58:12 CEST 2009


Author: cfbolz
Date: Fri Oct  2 23:58:10 2009
New Revision: 68132

Modified:
   pypy/trunk/pypy/jit/backend/llsupport/gc.py
   pypy/trunk/pypy/jit/metainterp/executor.py
   pypy/trunk/pypy/jit/metainterp/history.py
   pypy/trunk/pypy/jit/metainterp/optimizefindnode.py
   pypy/trunk/pypy/jit/metainterp/optimizeopt.py
   pypy/trunk/pypy/jit/metainterp/pyjitpl.py
   pypy/trunk/pypy/jit/metainterp/resume.py
   pypy/trunk/pypy/jit/metainterp/specnode.py
   pypy/trunk/pypy/jit/metainterp/test/test_history.py
   pypy/trunk/pypy/jit/metainterp/typesystem.py
   pypy/trunk/pypy/jit/metainterp/warmspot.py
Log:
(pedronis awake a bit, cfbolz): prebuild const int values for fun and profit.


Modified: pypy/trunk/pypy/jit/backend/llsupport/gc.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/llsupport/gc.py	(original)
+++ pypy/trunk/pypy/jit/backend/llsupport/gc.py	Fri Oct  2 23:58:10 2009
@@ -4,7 +4,7 @@
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.annlowlevel import llhelper
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.jit.metainterp.history import BoxInt, BoxPtr, ConstInt, ConstPtr
+from pypy.jit.metainterp.history import BoxInt, BoxPtr, constint, ConstInt, ConstPtr
 from pypy.jit.metainterp.resoperation import ResOperation, rop
 from pypy.jit.backend.llsupport import symbolic
 from pypy.jit.backend.llsupport.symbolic import WORD
@@ -334,7 +334,7 @@
         self.HDRPTR = lltype.Ptr(self.GCClass.HDR)
         self.gcheaderbuilder = GCHeaderBuilder(self.HDRPTR.TO)
         self.fielddescr_tid = get_field_descr(self, self.GCClass.HDR, 'tid')
-        self.c_jit_wb_if_flag = ConstInt(self.GCClass.JIT_WB_IF_FLAG)
+        self.c_jit_wb_if_flag = constint(self.GCClass.JIT_WB_IF_FLAG)
         self.calldescr_jit_wb = get_call_descr(self, [llmemory.GCREF,
                                                       llmemory.GCREF],
                                                lltype.Void)
@@ -488,7 +488,7 @@
                     addr = self.gcrefs.get_address_of_gcref(v.value)
                     addr = cpu.cast_adr_to_int(addr)
                     newops.append(ResOperation(rop.GETFIELD_RAW,
-                                               [ConstInt(addr)], box,
+                                               [constint(addr)], box,
                                                self.single_gcref_descr))
                     op.args[i] = box
             # ---------- write barrier for SETFIELD_GC ----------
@@ -519,6 +519,8 @@
         llop1 = self.llop1
         funcptr = llop1.get_write_barrier_failing_case(self.WB_FUNCPTR)
         funcaddr = llmemory.cast_ptr_to_adr(funcptr)
+        # this is not going to be a small integer, so don't use constint
+        # (bit of a micro-optimization)
         c_func = ConstInt(cpu.cast_adr_to_int(funcaddr))
         args = [v_tid, self.c_jit_wb_if_flag, c_func, v_base, v_value]
         newops.append(ResOperation(rop.COND_CALL_GC_WB, args, None,

Modified: pypy/trunk/pypy/jit/metainterp/executor.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/executor.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/executor.py	Fri Oct  2 23:58:10 2009
@@ -6,7 +6,7 @@
 from pypy.rpython.ootypesystem import ootype
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rlib.rarithmetic import ovfcheck, r_uint, intmask
-from pypy.jit.metainterp.history import BoxInt, ConstInt, check_descr
+from pypy.jit.metainterp.history import BoxInt, constint, check_descr
 from pypy.jit.metainterp.history import INT, REF, ConstFloat
 from pypy.jit.metainterp import resoperation
 from pypy.jit.metainterp.resoperation import rop
@@ -19,86 +19,86 @@
 # ____________________________________________________________
 
 def do_int_add(cpu, box1, box2):
-    return ConstInt(intmask(box1.getint() + box2.getint()))
+    return constint(intmask(box1.getint() + box2.getint()))
 
 def do_int_sub(cpu, box1, box2):
-    return ConstInt(intmask(box1.getint() - box2.getint()))
+    return constint(intmask(box1.getint() - box2.getint()))
 
 def do_int_mul(cpu, box1, box2):
-    return ConstInt(intmask(box1.getint() * box2.getint()))
+    return constint(intmask(box1.getint() * box2.getint()))
 
 def do_int_floordiv(cpu, box1, box2):
     z = llop.int_floordiv(lltype.Signed, box1.getint(), box2.getint())
-    return ConstInt(z)
+    return constint(z)
 
 def do_int_mod(cpu, box1, box2):
     z = llop.int_mod(lltype.Signed, box1.getint(), box2.getint())
-    return ConstInt(z)
+    return constint(z)
 
 def do_int_and(cpu, box1, box2):
-    return ConstInt(box1.getint() & box2.getint())
+    return constint(box1.getint() & box2.getint())
 
 def do_int_or(cpu, box1, box2):
-    return ConstInt(box1.getint() | box2.getint())
+    return constint(box1.getint() | box2.getint())
 
 def do_int_xor(cpu, box1, box2):
-    return ConstInt(box1.getint() ^ box2.getint())
+    return constint(box1.getint() ^ box2.getint())
 
 def do_int_rshift(cpu, box1, box2):
-    return ConstInt(box1.getint() >> box2.getint())
+    return constint(box1.getint() >> box2.getint())
 
 def do_int_lshift(cpu, box1, box2):
-    return ConstInt(intmask(box1.getint() << box2.getint()))
+    return constint(intmask(box1.getint() << box2.getint()))
 
 def do_uint_rshift(cpu, box1, box2):
     v = r_uint(box1.getint()) >> r_uint(box2.getint())
-    return ConstInt(intmask(v))
+    return constint(intmask(v))
 
 # ----------
 
 def do_int_lt(cpu, box1, box2):
-    return ConstInt(box1.getint() < box2.getint())
+    return constint(box1.getint() < box2.getint())
 
 def do_int_le(cpu, box1, box2):
-    return ConstInt(box1.getint() <= box2.getint())
+    return constint(box1.getint() <= box2.getint())
 
 def do_int_eq(cpu, box1, box2):
-    return ConstInt(box1.getint() == box2.getint())
+    return constint(box1.getint() == box2.getint())
 
 def do_int_ne(cpu, box1, box2):
-    return ConstInt(box1.getint() != box2.getint())
+    return constint(box1.getint() != box2.getint())
 
 def do_int_gt(cpu, box1, box2):
-    return ConstInt(box1.getint() > box2.getint())
+    return constint(box1.getint() > box2.getint())
 
 def do_int_ge(cpu, box1, box2):
-    return ConstInt(box1.getint() >= box2.getint())
+    return constint(box1.getint() >= box2.getint())
 
 def do_uint_lt(cpu, box1, box2):
-    return ConstInt(r_uint(box1.getint()) < r_uint(box2.getint()))
+    return constint(r_uint(box1.getint()) < r_uint(box2.getint()))
 
 def do_uint_le(cpu, box1, box2):
-    return ConstInt(r_uint(box1.getint()) <= r_uint(box2.getint()))
+    return constint(r_uint(box1.getint()) <= r_uint(box2.getint()))
 
 def do_uint_gt(cpu, box1, box2):
-    return ConstInt(r_uint(box1.getint()) > r_uint(box2.getint()))
+    return constint(r_uint(box1.getint()) > r_uint(box2.getint()))
 
 def do_uint_ge(cpu, box1, box2):
-    return ConstInt(r_uint(box1.getint()) >= r_uint(box2.getint()))
+    return constint(r_uint(box1.getint()) >= r_uint(box2.getint()))
 
 # ----------
 
 def do_int_is_true(cpu, box1):
-    return ConstInt(bool(box1.getint()))
+    return constint(bool(box1.getint()))
 
 def do_int_neg(cpu, box1):
-    return ConstInt(intmask(-box1.getint()))
+    return constint(intmask(-box1.getint()))
 
 def do_int_invert(cpu, box1):
-    return ConstInt(~box1.getint())
+    return constint(~box1.getint())
 
 def do_bool_not(cpu, box1):
-    return ConstInt(not box1.getint())
+    return constint(not box1.getint())
 
 def do_same_as(cpu, box1):
     return box1
@@ -111,7 +111,7 @@
         x = bool(box1.getref_base())
     else:
         assert False
-    return ConstInt(x)
+    return constint(x)
 
 def do_ooisnull(cpu, box1):
     tp = box1.type
@@ -121,7 +121,7 @@
         x = bool(box1.getref_base())
     else:
         assert False
-    return ConstInt(not x)
+    return constint(not x)
 
 def do_oois(cpu, box1, box2):
     tp = box1.type
@@ -132,7 +132,7 @@
         x = box1.getref_base() == box2.getref_base()
     else:
         assert False
-    return ConstInt(x)
+    return constint(x)
 
 def do_ooisnot(cpu, box1, box2):
     tp = box1.type
@@ -143,14 +143,14 @@
         x = box1.getref_base() != box2.getref_base()
     else:
         assert False
-    return ConstInt(x)
+    return constint(x)
 
 def do_ooidentityhash(cpu, box1):
     obj = box1.getref_base()
-    return ConstInt(cpu.ts.ooidentityhash(obj))
+    return constint(cpu.ts.ooidentityhash(obj))
 
 def do_subclassof(cpu, box1, box2):
-    return ConstInt(cpu.ts.subclassOf(cpu, box1, box2))
+    return constint(cpu.ts.subclassOf(cpu, box1, box2))
 
 # ----------
 
@@ -202,7 +202,7 @@
     return ConstFloat(abs(box1.getfloat()))
 
 def do_float_is_true(cpu, box1):
-    return ConstInt(bool(box1.getfloat()))
+    return constint(bool(box1.getfloat()))
 
 def do_float_add(cpu, box1, box2):
     return ConstFloat(box1.getfloat() + box2.getfloat())
@@ -217,25 +217,25 @@
     return ConstFloat(box1.getfloat() / box2.getfloat())
 
 def do_float_lt(cpu, box1, box2):
-    return ConstInt(box1.getfloat() < box2.getfloat())
+    return constint(box1.getfloat() < box2.getfloat())
 
 def do_float_le(cpu, box1, box2):
-    return ConstInt(box1.getfloat() <= box2.getfloat())
+    return constint(box1.getfloat() <= box2.getfloat())
 
 def do_float_eq(cpu, box1, box2):
-    return ConstInt(box1.getfloat() == box2.getfloat())
+    return constint(box1.getfloat() == box2.getfloat())
 
 def do_float_ne(cpu, box1, box2):
-    return ConstInt(box1.getfloat() != box2.getfloat())
+    return constint(box1.getfloat() != box2.getfloat())
 
 def do_float_gt(cpu, box1, box2):
-    return ConstInt(box1.getfloat() > box2.getfloat())
+    return constint(box1.getfloat() > box2.getfloat())
 
 def do_float_ge(cpu, box1, box2):
-    return ConstInt(box1.getfloat() >= box2.getfloat())
+    return constint(box1.getfloat() >= box2.getfloat())
 
 def do_cast_float_to_int(cpu, box1):
-    return ConstInt(int(box1.getfloat()))
+    return constint(int(box1.getfloat()))
 
 def do_cast_int_to_float(cpu, box1):
     return ConstFloat(float(box1.getint()))

Modified: pypy/trunk/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/history.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/history.py	Fri Oct  2 23:58:10 2009
@@ -160,7 +160,7 @@
                 intval = cpu.cast_adr_to_int(llmemory.cast_ptr_to_adr(x))
             else:
                 intval = lltype.cast_primitive(lltype.Signed, x)
-            return ConstInt(intval)
+            return constint(intval)
         elif kind == "ref":
             return cpu.ts.new_ConstRef(x)
         elif kind == "float":
@@ -244,9 +244,27 @@
 
     def repr_rpython(self):
         return repr_rpython(self, 'ci')
+constint_lower = -5
+constint_upper = 200
+ConstInt.PREBUILT = [ConstInt(i) for i in range(constint_lower, constint_upper)]
+
+def constint(x):
+    from pypy.rlib.rarithmetic import r_uint
+    # use r_uint to perform a single comparison (this whole function
+    # is getting inlined into every caller so keeping the branching
+    # to a minimum is a good idea)
+    if not we_are_translated() and not isinstance(x, int): # e.g. TotalOrderSymbolic
+        return ConstInt(x)
+    index = r_uint(x - constint_lower)
+    if index >= r_uint(constint_upper - constint_lower):
+        const = ConstInt(x) 
+    else:
+        const = ConstInt.PREBUILT[index]
+    return const
 
-CONST_FALSE = ConstInt(0)
-CONST_TRUE  = ConstInt(1)
+
+CONST_0 = CONST_FALSE = constint(0)
+CONST_1 = CONST_TRUE  = constint(1)
 
 class ConstAddr(Const):       # only for constants built before translation
     type = INT
@@ -490,7 +508,7 @@
         return BoxInt(self.value)
 
     def constbox(self):
-        return ConstInt(self.value)
+        return constint(self.value)
 
     def getint(self):
         return self.value

Modified: pypy/trunk/pypy/jit/metainterp/optimizefindnode.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/optimizefindnode.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/optimizefindnode.py	Fri Oct  2 23:58:10 2009
@@ -4,7 +4,7 @@
 from pypy.jit.metainterp.specnode import VirtualInstanceSpecNode
 from pypy.jit.metainterp.specnode import VirtualArraySpecNode
 from pypy.jit.metainterp.specnode import VirtualStructSpecNode
-from pypy.jit.metainterp.history import AbstractValue, ConstInt, Const
+from pypy.jit.metainterp.history import AbstractValue, constint, Const
 from pypy.jit.metainterp.resoperation import rop
 from pypy.jit.metainterp.executor import execute_nonspec
 from pypy.jit.metainterp.optimizeutil import av_newdict, _findall, sort_descrs
@@ -199,7 +199,7 @@
     def find_nodes_ARRAYLEN_GC(self, op):
         arraynode = self.getnode(op.args[0])
         if arraynode.arraydescr is not None:
-            resbox = ConstInt(arraynode.arraysize)
+            resbox = constint(arraynode.arraysize)
             self.set_constant_node(op.result, resbox)
 
     def find_nodes_GUARD_CLASS(self, op):

Modified: pypy/trunk/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/optimizeopt.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/optimizeopt.py	Fri Oct  2 23:58:10 2009
@@ -1,5 +1,6 @@
 from pypy.jit.metainterp.history import Box, BoxInt, LoopToken
-from pypy.jit.metainterp.history import Const, ConstInt, ConstPtr, ConstObj, REF
+from pypy.jit.metainterp.history import Const, constint, ConstInt, ConstPtr, ConstObj, REF
+from pypy.jit.metainterp.history import CONST_0, CONST_1
 from pypy.jit.metainterp.resoperation import rop, ResOperation
 from pypy.jit.metainterp.executor import execute_nonspec
 from pypy.jit.metainterp.specnode import SpecNode, NotSpecNode, ConstantSpecNode
@@ -140,8 +141,6 @@
     def __init__(self, box):
         self.box = box
 
-CONST_0      = ConstInt(0)
-CONST_1      = ConstInt(1)
 CVAL_ZERO    = ConstantValue(CONST_0)
 llhelper.CONST_NULL = ConstPtr(ConstPtr.value)
 llhelper.CVAL_NULLREF = ConstantValue(llhelper.CONST_NULL)
@@ -269,7 +268,7 @@
                 if subvalue is not None:
                     subbox = subvalue.force_box()
                     op = ResOperation(rop.SETARRAYITEM_GC,
-                                      [box, ConstInt(index), subbox], None,
+                                      [box, constint(index), subbox], None,
                                       descr=self.arraydescr)
                     newoperations.append(op)
         return self.box
@@ -410,7 +409,7 @@
         self.make_equal_to(box, ConstantValue(constbox))
 
     def make_constant_int(self, box, intvalue):
-        self.make_constant(box, ConstInt(intvalue))
+        self.make_constant(box, constint(intvalue))
 
     def make_virtual(self, known_class, box, source_op=None):
         vvalue = VirtualValue(self, known_class, box, source_op)

Modified: pypy/trunk/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/pyjitpl.py	Fri Oct  2 23:58:10 2009
@@ -6,7 +6,7 @@
 from pypy.rlib.debug import debug_print
 
 from pypy.jit.metainterp import history, compile, resume
-from pypy.jit.metainterp.history import Const, ConstInt, Box
+from pypy.jit.metainterp.history import Const, constint, Box, CONST_0
 from pypy.jit.metainterp.resoperation import rop
 from pypy.jit.metainterp import codewriter, executor
 from pypy.jit.metainterp.logger import Logger
@@ -351,7 +351,7 @@
     @arguments("orgpc", "box", "descr", "box")
     def opimpl_check_neg_index(self, pc, arraybox, arraydesc, indexbox):
         negbox = self.metainterp.execute_and_record(
-            rop.INT_LT, None, indexbox, ConstInt(0))
+            rop.INT_LT, None, indexbox, CONST_0)
         # xxx inefficient
         negbox = self.implement_guard_value(pc, negbox)
         if negbox.getint():
@@ -391,7 +391,7 @@
     def opimpl_check_resizable_neg_index(self, pc, listbox, lengthdesc,
                                          indexbox):
         negbox = self.metainterp.execute_and_record(
-            rop.INT_LT, None, indexbox, ConstInt(0))
+            rop.INT_LT, None, indexbox, CONST_0)
         # xxx inefficient
         negbox = self.implement_guard_value(pc, negbox)
         if negbox.getint():
@@ -405,7 +405,7 @@
     @arguments("orgpc", "box")
     def opimpl_check_zerodivisionerror(self, pc, box):
         nonzerobox = self.metainterp.execute_and_record(
-            rop.INT_NE, None, box, ConstInt(0))
+            rop.INT_NE, None, box, CONST_0)
         # xxx inefficient
         nonzerobox = self.implement_guard_value(pc, nonzerobox)
         if nonzerobox.getint():
@@ -419,11 +419,11 @@
         # detect the combination "box1 = -sys.maxint-1, box2 = -1".
         import sys
         tmp1 = self.metainterp.execute_and_record(    # combination to detect:
-            rop.INT_ADD, None, box1, ConstInt(sys.maxint))    # tmp1=-1, box2=-1
+            rop.INT_ADD, None, box1, constint(sys.maxint))    # tmp1=-1, box2=-1
         tmp2 = self.metainterp.execute_and_record(
             rop.INT_AND, None, tmp1, box2)                    # tmp2=-1
         tmp3 = self.metainterp.execute_and_record(
-            rop.INT_EQ, None, tmp2, ConstInt(-1))             # tmp3?
+            rop.INT_EQ, None, tmp2, constint(-1))             # tmp3?
         # xxx inefficient
         tmp4 = self.implement_guard_value(pc, tmp3)       # tmp4?
         if not tmp4.getint():
@@ -439,7 +439,7 @@
     @arguments("orgpc", "box")
     def opimpl_int_abs(self, pc, box):
         nonneg = self.metainterp.execute_and_record(
-            rop.INT_GE, None, box, ConstInt(0))
+            rop.INT_GE, None, box, CONST_0)
         # xxx inefficient
         nonneg = self.implement_guard_value(pc, nonneg)
         if nonneg.getint():
@@ -585,7 +585,7 @@
         virtualizable_box = self.metainterp.virtualizable_boxes[-1]
         virtualizable = vinfo.unwrap_virtualizable_box(virtualizable_box)
         result = vinfo.get_array_length(virtualizable, arrayindex)
-        self.make_result_box(ConstInt(result))
+        self.make_result_box(constint(result))
 
     def perform_call(self, jitcode, varargs):
         if (self.metainterp.is_blackholing() and
@@ -1725,7 +1725,7 @@
                 descr = vinfo.array_descrs[k]
                 for j in range(vinfo.get_array_length(virtualizable, k)):
                     itembox = self.execute_and_record(rop.GETARRAYITEM_GC,
-                                                      descr, abox, ConstInt(j))
+                                                      descr, abox, constint(j))
                     self.virtualizable_boxes[i] = itembox
                     i += 1
             assert i + 1 == len(self.virtualizable_boxes)
@@ -1749,7 +1749,7 @@
                     itembox = self.virtualizable_boxes[i]
                     i += 1
                     self.execute_and_record(rop.SETARRAYITEM_GC, descr,
-                                            abox, ConstInt(j), itembox)
+                                            abox, constint(j), itembox)
             assert i + 1 == len(self.virtualizable_boxes)
 
     def gen_store_back_in_virtualizable_no_perform(self):
@@ -1770,7 +1770,7 @@
                 itembox = self.virtualizable_boxes[i]
                 i += 1
                 self.history.record(rop.SETARRAYITEM_GC,
-                                    [abox, ConstInt(j), itembox],
+                                    [abox, constint(j), itembox],
                                     None,
                                     descr=vinfo.array_descrs[k])
         assert i + 1 == len(self.virtualizable_boxes)

Modified: pypy/trunk/pypy/jit/metainterp/resume.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/resume.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/resume.py	Fri Oct  2 23:58:10 2009
@@ -1,5 +1,5 @@
 import sys
-from pypy.jit.metainterp.history import Box, Const, ConstInt
+from pypy.jit.metainterp.history import Box, Const, constint
 from pypy.jit.metainterp.resoperation import rop
 
 # Logic to encode the chain of frames and the state of the boxes at a
@@ -251,14 +251,14 @@
         length = len(self.fieldnums)
         return metainterp.execute_and_record(rop.NEW_ARRAY,
                                              self.arraydescr,
-                                             ConstInt(length))
+                                             constint(length))
 
     def setfields(self, metainterp, box, fn_decode_box):
         for i in range(len(self.fieldnums)):
             itembox = fn_decode_box(self.fieldnums[i])
             metainterp.execute_and_record(rop.SETARRAYITEM_GC,
                                           self.arraydescr,
-                                          box, ConstInt(i), itembox)
+                                          box, constint(i), itembox)
 
     def repr_rpython(self):
         return 'VArrayInfo("%s", %s)' % (self.arraydescr,

Modified: pypy/trunk/pypy/jit/metainterp/specnode.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/specnode.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/specnode.py	Fri Oct  2 23:58:10 2009
@@ -97,7 +97,7 @@
         for i in range(len(self.items)):
             itembox = executor.execute(cpu, resoperation.rop.GETARRAYITEM_GC,
                                        self.arraydescr,
-                                       valuebox, history.ConstInt(i))
+                                       valuebox, history.constint(i))
             subspecnode = self.items[i]
             subspecnode.extract_runtime_data(cpu, itembox, resultlist)
 

Modified: pypy/trunk/pypy/jit/metainterp/test/test_history.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_history.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_history.py	Fri Oct  2 23:58:10 2009
@@ -9,3 +9,13 @@
     s = lltype.cast_pointer(lltype.Ptr(S), t)
     const = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s))
     assert const._getrepr_() == "*T"
+
+def test_constint_sharing():
+    for val in [-1, 0, 1, 5, 99]:
+        c1 = constint(val)
+        c2 = constint(val)
+        assert c1 is c2
+    for val in [100000, -10000]:
+        c1 = constint(val)
+        c2 = constint(val)
+        assert c1 is not c2

Modified: pypy/trunk/pypy/jit/metainterp/typesystem.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/typesystem.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/typesystem.py	Fri Oct  2 23:58:10 2009
@@ -77,7 +77,7 @@
     def cls_of_box(self, cpu, box):
         obj = box.getref(lltype.Ptr(rclass.OBJECT))
         cls = llmemory.cast_ptr_to_adr(obj.typeptr)
-        return history.ConstInt(cpu.cast_adr_to_int(cls))
+        return history.constint(cpu.cast_adr_to_int(cls))
 
     def subclassOf(self, cpu, clsbox1, clsbox2):
         adr = clsbox2.getaddr(cpu)
@@ -87,7 +87,7 @@
         return rclass.ll_issubclass(real_class, bounding_class)
 
     def get_exception_box(self, etype):
-        return history.ConstInt(etype)
+        return history.constint(etype)
 
     def get_exc_value_box(self, evalue):
         return history.BoxPtr(evalue)

Modified: pypy/trunk/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/warmspot.py	Fri Oct  2 23:58:10 2009
@@ -637,7 +637,7 @@
     else:
         value = intmask(value)
     if in_const_box:
-        return history.ConstInt(value)
+        return history.constint(value)
     else:
         return history.BoxInt(value)
 wrap._annspecialcase_ = 'specialize:ll'



More information about the Pypy-commit mailing list