[pypy-dev] Spurious dict lookups in my JIT loops

Boris boris2010 at boristhebrave.com
Wed Sep 21 00:00:03 CEST 2011

> Alternatively, there is a way to display where the operations come from,
but only during testing.

I did this; which was good advice, as it generated several errors that the
ordinary compiler doesn't flag.

After fixing those up, I get the following (paraphrased):

pop__AccessDirect_None:46 setarrayitem_gc(p30, Const(0), Const(* None),
descr=<Descr "4, 'r'">)
pop__AccessDirect_None:46 setarrayitem_gc(p30, Const(1), Const(* None),
descr=<Descr "4, 'r'">)
compare__AccessDirect_None:34 i138 = uint_lt(i137, Const(10000))
compare__AccessDirect_None:38 guard_true(i138, ...
ll_contains__dicttablePtr_Signed:10 i139 = call(Const(<AddressAsInt * fn
ll_dict_lookup__dicttablePtr_Signed_Signed>), Const(*dicttable), Const(21),
Const(21), descr=<Descr "0, 'i', E">)
ll_contains__dicttablePtr_Signed:10 guard_no_exception(...
ll_contains__dicttablePtr_Signed:14 i40 = int_and(i139, Const(-2147483684))
ll_contains__dicttablePtr_Signed:17 141 = int_is_true(140)

followed by much more dicttable stuff. So that doesn't really help me
pinpoint the problem, unless *dicttable is some magic constant? What do the
offsets reference - they don't correspond to line numbers.

Here's my compare function for what it's worth. Note that there is an
implicit downcast in order to get intValue. In the above loop, the klass's
of both objects is Int, which the JIT is able to deduce.

class Frame:
    # ...
    def compare(self, a, b):
        """ Compares two values using the builting comparison operator.
Returns -1, 0, 1 or -99, where -99 means NaN comparison, otherwise such that
(a op b) iff (result op 0)"""
        import math
        if a.klass == Int and b.klass == Int:
            if a.intValue < b.intValue:
                return -1
            elif a.intValue > b.intValue:
                return 1
                return 0
        #elif a.klass in (Int, Uint, Number) and b.klass in (Int, Uint,
        #    aValue = self.space.toNumber(a)
        #    bValue = self.space.toNumber(b)
        #    if math.isnan(aValue):
        #        return -99
        #    if math.isnan(bValue):
        #        return -99
        #    if aValue < bValue:
        #        return -1
        #    elif aValue > bValue:
        #        return 1
        #    else:
        #        return 0

        raise StandardError("Not implemented")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20110920/3f553ec5/attachment-0001.html>

More information about the pypy-dev mailing list