Author: Armin Rigo <ar...@tunes.org>
Branch: remove-raisingops
Changeset: r83983:f61ef2f172af
Date: 2016-04-27 15:50 +0200
http://bitbucket.org/pypy/pypy/changeset/f61ef2f172af/

Log:    a remaining direct usage of int_add_ovf

diff --git a/rpython/rtyper/lltypesystem/rtagged.py 
b/rpython/rtyper/lltypesystem/rtagged.py
--- a/rpython/rtyper/lltypesystem/rtagged.py
+++ b/rpython/rtyper/lltypesystem/rtagged.py
@@ -3,6 +3,7 @@
     InstanceRepr, CLASSTYPE, ll_inst_type, MissingRTypeAttribute,
     ll_issubclass_const, getclassrepr, getinstancerepr, get_type_repr)
 from rpython.rtyper.rmodel import TyperError, inputconst
+from rpython.rlib.rarithmetic import r_uint, intmask
 
 
 class TaggedInstanceRepr(InstanceRepr):
@@ -40,12 +41,8 @@
             raise TyperError("must instantiate %r with a simple class call" % (
                 self.classdef,))
         v_value = hop.inputarg(lltype.Signed, arg=1)
-        c_one = hop.inputconst(lltype.Signed, 1)
         hop.exception_is_here()
-        v2 = hop.genop('int_add_ovf', [v_value, v_value],
-                       resulttype = lltype.Signed)
-        v2p1 = hop.genop('int_add', [v2, c_one],
-                         resulttype = lltype.Signed)
+        v2p1 = hop.gendirectcall(ll_times_two_plus_one, v_value)
         v_instance =  hop.genop('cast_int_to_ptr', [v2p1],
                                 resulttype = self.lowleveltype)
         return v_instance, False   # don't call __init__
@@ -140,6 +137,11 @@
         return hop.gendirectcall(ll_unboxed_isinstance_const, v_obj,
                                  minid, maxid, c_answer_if_unboxed)
 
+def ll_times_two_plus_one(x):
+    r = intmask(r_uint(x) << 1)
+    if r^x < 0:
+        raise OverflowError("integer addition")
+    return r + 1
 
 def ll_int_to_unboxed(PTRTYPE, value):
     return lltype.cast_int_to_ptr(PTRTYPE, value*2+1)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to