Author: Carl Friedrich Bolz <[email protected]>
Branch:
Changeset: r65039:2fca073afc8e
Date: 2013-06-27 16:44 +0200
http://bitbucket.org/pypy/pypy/changeset/2fca073afc8e/
Log: merge
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -29,12 +29,12 @@
_application_traceback = None
def __init__(self, w_type, w_value, tb=None):
- assert w_type is not None
self.setup(w_type)
self._w_value = w_value
self._application_traceback = tb
def setup(self, w_type):
+ assert w_type is not None
self.w_type = w_type
if not we_are_translated():
self.debug_excs = []
@@ -347,7 +347,6 @@
self.xstrings = strings
for i, _, attr in entries:
setattr(self, attr, args[i])
- assert w_type is not None
def _compute_value(self, space):
lst = [None] * (len(formats) + len(formats) + 1)
@@ -369,6 +368,18 @@
_fmtcache2[formats] = OpErrFmt
return OpErrFmt, strings
+class OpErrFmtNoArgs(OperationError):
+
+ def __init__(self, w_type, value):
+ self.setup(w_type)
+ self._value = value
+
+ def get_w_value(self, space):
+ w_value = self._w_value
+ if w_value is None:
+ self._w_value = w_value = space.wrap(self._value)
+ return w_value
+
def get_operationerr_class(valuefmt):
try:
result = _fmtcache[valuefmt]
@@ -389,6 +400,8 @@
%T - The result of space.type(w_arg).getname(space)
"""
+ if not len(args):
+ return OpErrFmtNoArgs(w_type, valuefmt)
OpErrFmt, strings = get_operationerr_class(valuefmt)
return OpErrFmt(w_type, strings, *args)
operationerrfmt._annspecialcase_ = 'specialize:arg(1)'
diff --git a/pypy/interpreter/test/test_error.py
b/pypy/interpreter/test/test_error.py
--- a/pypy/interpreter/test/test_error.py
+++ b/pypy/interpreter/test/test_error.py
@@ -33,6 +33,14 @@
operr3 = operationerrfmt("w_type2", "a %s b %s c", "bar", "4b")
assert operr3.__class__ is not operr.__class__
+def test_operationerrfmt_noargs(space):
+ operr = operationerrfmt(space.w_AttributeError, "no attribute 'foo'")
+ operr.normalize_exception(space)
+ val = operr.get_w_value(space)
+ assert space.isinstance_w(val, space.w_AttributeError)
+ w_repr = space.repr(val)
+ assert space.str_w(w_repr) == "AttributeError(\"no attribute 'foo'\",)"
+
def test_operationerrfmt_T(space):
operr = operationerrfmt(space.w_AttributeError,
"'%T' object has no attribute '%s'",
diff --git a/pypy/objspace/std/dictmultiobject.py
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -225,8 +225,8 @@
space.raise_key_error(w_key)
def descr_reversed(self, space):
- raise OperationError(space.w_TypeError, space.wrap(
- 'argument to reversed() must be a sequence'))
+ raise operationerrfmt(space.w_TypeError,
+ 'argument to reversed() must be a sequence')
def descr_copy(self, space):
"""D.copy() -> a shallow copy of D"""
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -1222,7 +1222,8 @@
def _safe_find(self, w_list, obj, start, stop):
l = self.unerase(w_list.lstorage)
for i in range(start, min(stop, len(l))):
- if l[i] == obj:
+ val = l[i]
+ if val == obj:
return i
raise ValueError
@@ -1542,18 +1543,6 @@
if reverse:
l.reverse()
- def _safe_find(self, w_list, obj, start, stop):
- from rpython.rlib.rfloat import isnan
- if not isnan(obj):
- return AbstractUnwrappedStrategy._safe_find(self, w_list, obj,
- start, stop)
- # unwrapped nan != nan, finding it requires more effort
- l = self.unerase(w_list.lstorage)
- for i in range(start, min(stop, len(l))):
- if isnan(l[i]):
- return i
- raise ValueError
-
class StringListStrategy(AbstractUnwrappedStrategy, ListStrategy):
_none_value = None
diff --git a/pypy/objspace/std/test/test_listobject.py
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -1314,10 +1314,6 @@
non_list = NonList()
assert [] != non_list
- def test_nan_containment(self):
- nan = float('nan')
- assert nan in [nan]
-
class AppTestForRangeLists(AppTestW_ListObject):
spaceconfig = {"objspace.std.withrangelist": True}
diff --git a/rpython/jit/backend/x86/regalloc.py
b/rpython/jit/backend/x86/regalloc.py
--- a/rpython/jit/backend/x86/regalloc.py
+++ b/rpython/jit/backend/x86/regalloc.py
@@ -3,35 +3,34 @@
"""
import os
-from rpython.jit.metainterp.history import (Box, Const, ConstInt, ConstPtr,
- ConstFloat, BoxInt,
- BoxFloat, INT, REF, FLOAT,
- TargetToken)
-from rpython.jit.backend.x86.regloc import *
-from rpython.rtyper.lltypesystem import lltype, rffi, rstr
-from rpython.rtyper.annlowlevel import cast_instance_to_gcref
-from rpython.rlib.objectmodel import we_are_translated
-from rpython.rlib import rgc
from rpython.jit.backend.llsupport import symbolic
+from rpython.jit.backend.llsupport.descr import (ArrayDescr, CallDescr,
+ unpack_arraydescr, unpack_fielddescr, unpack_interiorfielddescr)
+from rpython.jit.backend.llsupport.gcmap import allocate_gcmap
+from rpython.jit.backend.llsupport.regalloc import (FrameManager, BaseRegalloc,
+ RegisterManager, TempBox, compute_vars_longevity, is_comparison_or_ovf_op)
+from rpython.jit.backend.x86 import rx86
+from rpython.jit.backend.x86.arch import (WORD, JITFRAME_FIXED_SIZE, IS_X86_32,
+ IS_X86_64)
from rpython.jit.backend.x86.jump import remap_frame_layout_mixed
+from rpython.jit.backend.x86.regloc import (FrameLoc, RegLoc, ConstFloatLoc,
+ FloatImmedLoc, ImmedLoc, imm, imm0, imm1, ecx, eax, edx, ebx, esi, edi,
+ ebp, r8, r9, r10, r11, r12, r13, r14, r15, xmm0, xmm1, xmm2, xmm3, xmm4,
+ xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14,
+ X86_64_SCRATCH_REG, X86_64_XMM_SCRATCH_REG)
from rpython.jit.codewriter import longlong
from rpython.jit.codewriter.effectinfo import EffectInfo
+from rpython.jit.metainterp.history import (Box, Const, ConstInt, ConstPtr,
+ ConstFloat, BoxInt, BoxFloat, INT, REF, FLOAT, TargetToken)
from rpython.jit.metainterp.resoperation import rop
-from rpython.jit.backend.llsupport.descr import ArrayDescr
-from rpython.jit.backend.llsupport.descr import CallDescr
-from rpython.jit.backend.llsupport.descr import unpack_arraydescr
-from rpython.jit.backend.llsupport.descr import unpack_fielddescr
-from rpython.jit.backend.llsupport.descr import unpack_interiorfielddescr
-from rpython.jit.backend.llsupport.gcmap import allocate_gcmap
-from rpython.jit.backend.llsupport.regalloc import FrameManager, BaseRegalloc,\
- RegisterManager, TempBox, compute_vars_longevity, is_comparison_or_ovf_op
-from rpython.jit.backend.x86.arch import WORD, JITFRAME_FIXED_SIZE
-from rpython.jit.backend.x86.arch import IS_X86_32, IS_X86_64
-from rpython.jit.backend.x86 import rx86
+from rpython.rlib import rgc
+from rpython.rlib.objectmodel import we_are_translated
from rpython.rlib.rarithmetic import r_longlong, r_uint
+from rpython.rtyper.annlowlevel import cast_instance_to_gcref
+from rpython.rtyper.lltypesystem import lltype, rffi, rstr
+
class X86RegisterManager(RegisterManager):
-
box_types = [INT, REF]
all_regs = [ecx, eax, edx, ebx, esi, edi]
no_lower_byte_regs = [esi, edi]
@@ -886,7 +885,6 @@
gcmap[val // WORD // 8] |= r_uint(1) << (val % (WORD * 8))
return gcmap
-
def consider_setfield_gc(self, op):
ofs, size, _ = unpack_fielddescr(op.getdescr())
ofs_loc = imm(ofs)
@@ -950,7 +948,7 @@
def consider_setarrayitem_gc(self, op):
itemsize, ofs, _ = unpack_arraydescr(op.getdescr())
args = op.getarglist()
- base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), args)
+ base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), args)
if itemsize == 1:
need_lower_byte = True
else:
@@ -1311,7 +1309,6 @@
#if jump_op is not None and jump_op.getdescr() is descr:
# self._compute_hint_frame_locations_from_descr(descr)
-
def consider_keepalive(self, op):
pass
diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py
b/rpython/jit/metainterp/optimizeopt/optimizer.py
--- a/rpython/jit/metainterp/optimizeopt/optimizer.py
+++ b/rpython/jit/metainterp/optimizeopt/optimizer.py
@@ -351,7 +351,8 @@
self.resumedata_memo = resume.ResumeDataLoopMemo(metainterp_sd)
self.bool_boxes = {}
self.producer = {}
- self.pendingfields = []
+ self.pendingfields = None # set temporarily to a list, normally by
+ # heap.py, as we're about to generate a guard
self.quasi_immutable_deps = None
self.opaque_pointers = {}
self.replaces_guard = {}
@@ -546,12 +547,14 @@
self.metainterp_sd.profiler.count(jitprof.Counters.OPT_OPS)
if op.is_guard():
self.metainterp_sd.profiler.count(jitprof.Counters.OPT_GUARDS)
+ pendingfields = self.pendingfields
+ self.pendingfields = None
if self.replaces_guard and op in self.replaces_guard:
self.replace_op(self.replaces_guard[op], op)
del self.replaces_guard[op]
return
else:
- op = self.store_final_boxes_in_guard(op)
+ op = self.store_final_boxes_in_guard(op, pendingfields)
elif op.can_raise():
self.exception_might_have_happened = True
if op.result:
@@ -571,12 +574,13 @@
else:
assert False
- def store_final_boxes_in_guard(self, op):
+ def store_final_boxes_in_guard(self, op, pendingfields):
+ assert pendingfields is not None
descr = op.getdescr()
assert isinstance(descr, compile.ResumeGuardDescr)
modifier = resume.ResumeDataVirtualAdder(descr, self.resumedata_memo)
try:
- newboxes = modifier.finish(self, self.pendingfields)
+ newboxes = modifier.finish(self, pendingfields)
if len(newboxes) > self.metainterp_sd.options.failargs_limit:
raise resume.TagOverflow
except resume.TagOverflow:
diff --git a/rpython/jit/metainterp/optimizeopt/simplify.py
b/rpython/jit/metainterp/optimizeopt/simplify.py
--- a/rpython/jit/metainterp/optimizeopt/simplify.py
+++ b/rpython/jit/metainterp/optimizeopt/simplify.py
@@ -7,7 +7,13 @@
def __init__(self, unroll):
self.last_label_descr = None
self.unroll = unroll
-
+
+ def emit_operation(self, op):
+ if op.is_guard():
+ if self.optimizer.pendingfields is None:
+ self.optimizer.pendingfields = []
+ Optimization.emit_operation(self, op)
+
def optimize_CALL_PURE(self, op):
args = op.getarglist()
self.emit_operation(ResOperation(rop.CALL, args, op.result,
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -27,7 +27,7 @@
snapshot0 = resume.Snapshot(None, [b0])
fdescr.rd_snapshot = resume.Snapshot(snapshot0, [b1])
#
- opt.store_final_boxes_in_guard(op)
+ opt.store_final_boxes_in_guard(op, [])
if op.getfailargs() == [b0, b1]:
assert list(fdescr.rd_numb.nums) == [tag(1, TAGBOX)]
assert list(fdescr.rd_numb.prev.nums) == [tag(0, TAGBOX)]
diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -61,7 +61,7 @@
KARATSUBA_CUTOFF = 19
else:
KARATSUBA_CUTOFF = 38
-
+
KARATSUBA_SQUARE_CUTOFF = 2 * KARATSUBA_CUTOFF
# For exponentiation, use the binary left-to-right algorithm
@@ -85,38 +85,41 @@
def _load_unsigned_digit(x):
return rffi.cast(UNSIGNED_TYPE, x)
-
+
_load_unsigned_digit._always_inline_ = True
NULLDIGIT = _store_digit(0)
-ONEDIGIT = _store_digit(1)
+ONEDIGIT = _store_digit(1)
def _check_digits(l):
for x in l:
assert type(x) is type(NULLDIGIT)
assert UDIGIT_MASK(x) & MASK == UDIGIT_MASK(x)
-
+
class InvalidEndiannessError(Exception):
pass
class InvalidSignednessError(Exception):
pass
+
class Entry(extregistry.ExtRegistryEntry):
_about_ = _check_digits
+
def compute_result_annotation(self, s_list):
from rpython.annotator import model as annmodel
assert isinstance(s_list, annmodel.SomeList)
s_DIGIT = self.bookkeeper.valueoftype(type(NULLDIGIT))
assert s_DIGIT.contains(s_list.listdef.listitem.s_value)
+
def specialize_call(self, hop):
hop.exception_cannot_occur()
+
class rbigint(object):
"""This is a reimplementation of longs using a list of digits."""
_immutable_ = True
_immutable_fields_ = ["_digits"]
-
def __init__(self, digits=[NULLDIGIT], sign=0, size=0):
if not we_are_translated():
@@ -164,7 +167,7 @@
def numdigits(self):
return self.size
numdigits._always_inline_ = True
-
+
@staticmethod
@jit.elidable
def fromint(intval):
@@ -180,15 +183,14 @@
ival = r_uint(intval)
else:
return NULLRBIGINT
-
+
carry = ival >> SHIFT
if carry:
return rbigint([_store_digit(ival & MASK),
_store_digit(carry)], sign, 2)
else:
return rbigint([_store_digit(ival & MASK)], sign, 1)
-
-
+
@staticmethod
@jit.elidable
def frombool(b):
@@ -334,7 +336,7 @@
# Avoid bogus 0's
s = d ^ MASK if self.sign == -1 else d
while s:
- s >>=1
+ s >>= 1
accumbits += 1
else:
accumbits += SHIFT
@@ -355,7 +357,7 @@
if self.sign == -1:
# Add a sign bit
- accum |= (~_widen_digit(0)) << accumbits;
+ accum |= (~_widen_digit(0)) << accumbits
result.append(chr(accum & 0xFF))
@@ -554,15 +556,15 @@
def mul(self, b):
asize = self.numdigits()
bsize = b.numdigits()
-
+
a = self
-
+
if asize > bsize:
a, b, asize, bsize = b, a, bsize, asize
if a.sign == 0 or b.sign == 0:
return NULLRBIGINT
-
+
if asize == 1:
if a._digits[0] == NULLDIGIT:
return NULLRBIGINT
@@ -575,14 +577,14 @@
return rbigint([_store_digit(res & MASK),
_store_digit(carry)], a.sign * b.sign, 2)
else:
return rbigint([_store_digit(res & MASK)], a.sign *
b.sign, 1)
-
- result = _x_mul(a, b, a.digit(0))
+
+ result = _x_mul(a, b, a.digit(0))
elif USE_KARATSUBA:
if a is b:
i = KARATSUBA_SQUARE_CUTOFF
else:
i = KARATSUBA_CUTOFF
-
+
if asize <= i:
result = _x_mul(a, b)
"""elif 2 * asize <= bsize:
@@ -608,13 +610,13 @@
return rbigint(self._digits[:self.size], 1, self.size)
elif digit and digit & (digit - 1) == 0:
return self.rshift(ptwotable[digit])
-
+
div, mod = _divrem(self, other)
if mod.sign * other.sign == -1:
if div.sign == 0:
return ONENEGATIVERBIGINT
div = div.sub(ONERBIGINT)
-
+
return div
@jit.look_inside
@@ -625,7 +627,7 @@
def mod(self, other):
if self.sign == 0:
return NULLRBIGINT
-
+
if other.sign != 0 and other.numdigits() == 1:
digit = other.digit(0)
if digit == 1:
@@ -648,7 +650,7 @@
size -= 1
else:
rem = self.digit(0) % digit
-
+
if rem == 0:
return NULLRBIGINT
mod = rbigint([_store_digit(rem)], -1 if self.sign < 0 else 1,
1)
@@ -699,9 +701,9 @@
"cannot be negative when 3rd argument specified")
# XXX failed to implement
raise ValueError("bigint pow() too negative")
-
+
size_b = b.numdigits()
-
+
if c is not None:
if c.sign == 0:
raise ValueError("pow() 3rd argument cannot be 0")
@@ -717,13 +719,13 @@
# return 0
if c.numdigits() == 1 and c._digits[0] == ONEDIGIT:
return NULLRBIGINT
-
+
# if base < 0:
# base = base % modulus
# Having the base positive just makes things easier.
if a.sign < 0:
a = a.mod(c)
-
+
elif b.sign == 0:
return ONERBIGINT
elif a.sign == 0:
@@ -745,12 +747,12 @@
if a.sign == -1 and not digit % 2:
ret.sign = 1
return ret
-
+
# At this point a, b, and c are guaranteed non-negative UNLESS
# c is NULL, in which case a may be negative. */
z = rbigint([ONEDIGIT], 1, 1)
-
+
# python adaptation: moved macros REDUCE(X) and MULT(X, Y, result)
# into helper function result = _help_mult(x, y, c)
if size_b <= FIVEARY_CUTOFF:
@@ -766,7 +768,7 @@
z = _help_mult(z, a, c)
j >>= 1
size_b -= 1
-
+
else:
# Left-to-right 5-ary exponentiation (HAC Algorithm 14.82)
# This is only useful in the case where c != None.
@@ -799,7 +801,7 @@
# must get the next digit from 'b' in order to complete
if size_b == 0:
break # Done
-
+
size_b -= 1
assert size_b >= 0
bi = b.udigit(size_b)
@@ -813,7 +815,7 @@
z = _help_mult(z, table[index], c)
#
assert j == -5
-
+
if negativeOutput and z.sign != 0:
z = z.sub(c)
return z
@@ -832,12 +834,12 @@
def invert(self): #Implement ~x as -(x + 1)
if self.sign == 0:
return ONENEGATIVERBIGINT
-
+
ret = self.add(ONERBIGINT)
ret.sign = -ret.sign
return ret
-
- @jit.elidable
+
+ @jit.elidable
def lshift(self, int_other):
if int_other < 0:
raise ValueError("negative shift count")
@@ -846,14 +848,14 @@
# wordshift, remshift = divmod(int_other, SHIFT)
wordshift = int_other // SHIFT
- remshift = int_other - wordshift * SHIFT
+ remshift = int_other - wordshift * SHIFT
if not remshift:
# So we can avoid problems with eq, AND avoid the need for
normalize.
if self.sign == 0:
return self
return rbigint([NULLDIGIT] * wordshift + self._digits, self.sign,
self.size + wordshift)
-
+
oldsize = self.numdigits()
newsize = oldsize + wordshift + 1
z = rbigint([NULLDIGIT] * newsize, self.sign, newsize)
@@ -865,7 +867,7 @@
accum >>= SHIFT
wordshift += 1
j += 1
-
+
newsize -= 1
assert newsize >= 0
z.setdigit(newsize, accum)
@@ -873,7 +875,7 @@
z._normalize()
return z
lshift._always_inline_ = True # It's so fast that it's always benefitial.
-
+
@jit.elidable
def lqshift(self, int_other):
" A quicker one with much less checks, int_other is valid and for the
most part constant."
@@ -893,7 +895,7 @@
z._normalize()
return z
lqshift._always_inline_ = True # It's so fast that it's always benefitial.
-
+
@jit.elidable
def rshift(self, int_other, dont_invert=False):
if int_other < 0:
@@ -925,7 +927,7 @@
z._normalize()
return z
rshift._always_inline_ = 'try' # It's so fast that it's always benefitial.
-
+
@jit.elidable
def and_(self, other):
return _bitwise(self, '&', other)
@@ -983,7 +985,7 @@
self._digits = [NULLDIGIT]
_normalize._always_inline_ = True
-
+
@jit.elidable
def bit_length(self):
i = self.numdigits()
@@ -1033,7 +1035,7 @@
# is NULL.
if c is not None:
res = res.mod(c)
-
+
return res
def digits_from_nonneg_long(l):
@@ -1118,7 +1120,7 @@
def _x_sub(a, b):
""" Subtract the absolute values of two integers. """
-
+
size_a = a.numdigits()
size_b = b.numdigits()
sign = 1
@@ -1139,7 +1141,7 @@
sign = -1
a, b = b, a
size_a = size_b = i+1
-
+
z = rbigint([NULLDIGIT] * size_a, sign, size_a)
borrow = UDIGIT_TYPE(0)
i = _load_unsigned_digit(0)
@@ -1157,7 +1159,7 @@
borrow >>= SHIFT
#borrow &= 1
i += 1
-
+
assert borrow == 0
z._normalize()
return z
@@ -1167,7 +1169,7 @@
for x in range(SHIFT-1):
ptwotable[r_longlong(2 << x)] = x+1
ptwotable[r_longlong(-2 << x)] = x+1
-
+
def _x_mul(a, b, digit=0):
"""
Grade school multiplication, ignoring the signs.
@@ -1216,14 +1218,14 @@
i += 1
z._normalize()
return z
-
+
elif digit:
if digit & (digit - 1) == 0:
return b.lqshift(ptwotable[digit])
-
+
# Even if it's not power of two it can still be useful.
return _muladd1(b, digit)
-
+
z = rbigint([NULLDIGIT] * (size_a + size_b), 1)
# gradeschool long mult
i = UDIGIT_TYPE(0)
@@ -1273,7 +1275,7 @@
"""
asize = a.numdigits()
bsize = b.numdigits()
-
+
# (ah*X+al)(bh*X+bl) = ah*bh*X*X + (ah*bl + al*bh)*X + al*bl
# Let k = (ah+al)*(bh+bl) = ah*bl + al*bh + ah*bh + al*bl
# Then the original product is
@@ -1356,7 +1358,7 @@
t2 = _x_add(bh, bl)
t3 = t1.mul(t2)
- assert t3.sign >=0
+ assert t3.sign >= 0
# Add t3. It's not obvious why we can't run out of room here.
# See the (*) comment after this function.
@@ -1436,9 +1438,9 @@
#bslice = rbigint([0] * asize, 1)
# XXX we cannot pre-allocate, see comments below!
# XXX prevent one list from being created.
- bslice = rbigint(sign = 1)
-
- nbdone = 0;
+ bslice = rbigint(sign=1)
+
+ nbdone = 0
while bsize > 0:
nbtouse = min(bsize, asize)
@@ -1487,7 +1489,7 @@
The sign of a is ignored; n should not be zero.
"""
assert n > 0 and n <= MASK
-
+
size = a.numdigits()
z = rbigint([NULLDIGIT] * size, 1, size)
rem = _inplace_divrem1(z, a, n)
@@ -1568,7 +1570,7 @@
""" Shift digit vector a[0:m] d bits left, with 0 <= d < SHIFT. Put
* result in z[0:m], and return the d bits shifted out of the top.
"""
-
+
carry = 0
assert 0 <= d and d < SHIFT
i = 0
@@ -1577,18 +1579,18 @@
z.setdigit(i, acc)
carry = acc >> SHIFT
i += 1
-
+
return carry
def _v_rshift(z, a, m, d):
""" Shift digit vector a[0:m] d bits right, with 0 <= d < PyLong_SHIFT. Put
* result in z[0:m], and return the d bits shifted out of the bottom.
"""
-
+
carry = _widen_digit(0)
acc = _widen_digit(0)
mask = (1 << d) - 1
-
+
assert 0 <= d and d < SHIFT
i = m-1
while i >= 0:
@@ -1596,7 +1598,7 @@
carry = acc & mask
z.setdigit(i, acc >> d)
i -= 1
-
+
return carry
def _x_divrem(v1, w1):
@@ -1604,13 +1606,13 @@
size_v = v1.numdigits()
size_w = w1.numdigits()
assert size_v >= size_w and size_w > 1
-
+
v = rbigint([NULLDIGIT] * (size_v + 1), 1, size_v + 1)
w = rbigint([NULLDIGIT] * size_w, 1, size_w)
-
+
""" normalize: shift w1 left so that its top digit is >= PyLong_BASE/2.
shift v1 left by the same amount. Results go into w and v. """
-
+
d = SHIFT - bits_in_digit(w1.digit(abs(size_w-1)))
carry = _v_lshift(w, w1, size_w, d)
assert carry == 0
@@ -1618,7 +1620,7 @@
if carry != 0 or v.digit(abs(size_v-1)) >= w.digit(abs(size_w-1)):
v.setdigit(size_v, carry)
size_v += 1
-
+
""" Now v->ob_digit[size_v-1] < w->ob_digit[size_w-1], so quotient has
at most (and usually exactly) k = size_v - size_w digits. """
k = size_v - size_w
@@ -1627,10 +1629,10 @@
assert _v_rshift(w, v, size_w, d) == 0
w._normalize()
return rbigint([NULLDIGIT]), w
-
+
assert k > 0
a = rbigint([NULLDIGIT] * k, 1, k)
-
+
wm1 = w.widedigit(abs(size_w-1))
wm2 = w.widedigit(abs(size_w-2))
@@ -1640,7 +1642,7 @@
assert j >= 0
""" inner loop: divide vk[0:size_w+1] by w0[0:size_w], giving
single-digit quotient q, remainder in vk[0:size_w]. """
-
+
# estimate quotient digit q; may overestimate by 1 (rare)
if j >= size_v:
vtop = 0
@@ -1653,9 +1655,9 @@
while wm2 * q > ((r << SHIFT) | v.widedigit(abs(j-2))):
q -= 1
r += wm1
-
+
#assert q <= MASK+1, We need to compare to BASE <=, but ehm, it gives
a buildin long error. So we ignore this.
-
+
# subtract q*w0[0:size_w] from vk[0:size_w+1]
zhi = 0
i = 0
@@ -1664,7 +1666,7 @@
v.setdigit(k+i, z)
zhi = z >> SHIFT
i += 1
-
+
# add w back if q was too large (this branch taken rarely)
if vtop + zhi < 0:
carry = UDIGIT_TYPE(0)
@@ -1675,21 +1677,20 @@
carry >>= SHIFT
i += 1
q -= 1
-
+
# store quotient digit
a.setdigit(k, q)
k -= 1
j -= 1
-
-
+
carry = _v_rshift(w, v, size_w, d)
assert carry == 0
-
+
a._normalize()
w._normalize()
-
+
return a, w
-
+
def _divrem(a, b):
""" Long division with remainder, top-level routine """
size_a = a.numdigits()
@@ -1906,14 +1907,16 @@
da = float(a.digit(a_size))
while True:
a_size -= 1
- if a_size < 0: break
+ if a_size < 0:
+ break
da = da * BASE_AS_FLOAT + a.digit(a_size)
b_size -= 1
db = float(b.digit(b_size))
while True:
b_size -= 1
- if b_size < 0: break
+ if b_size < 0:
+ break
db = db * BASE_AS_FLOAT + b.digit(b_size)
return _truediv_result(da / db, negate)
@@ -2048,7 +2051,6 @@
def _format_int(val, digits):
base = len(digits)
- j = 0
out = []
while val:
out.append(digits[val % base])
@@ -2101,7 +2103,7 @@
if negative:
output.append('-')
output.append(prefix)
- _format_recursive(x,len(pts)-1, output, pts, digits, output.getlength())
+ _format_recursive(x, len(pts)-1, output, pts, digits, output.getlength())
output.append(suffix)
return output.build()
@@ -2171,7 +2173,7 @@
digb = b.digit(i) ^ maskb
else:
digb = maskb
-
+
if op == '&':
z.setdigit(i, diga & digb)
elif op == '|':
@@ -2179,11 +2181,11 @@
elif op == '^':
z.setdigit(i, diga ^ digb)
i += 1
-
+
z._normalize()
if negz == 0:
return z
-
+
return z.invert()
_bitwise._annspecialcase_ = "specialize:arg(1)"
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit