]> granicus.if.org Git - python/commit
Replace outdated optimization with clearer code that compiles better.
authorRaymond Hettinger <python@rcn.com>
Tue, 6 Aug 2013 05:24:50 +0000 (22:24 -0700)
committerRaymond Hettinger <python@rcn.com>
Tue, 6 Aug 2013 05:24:50 +0000 (22:24 -0700)
commitc629d4c9a2b6ff92378ee1f2c8ed27f709d2b08e
treeffbed99c17bbf0a9be99ebce96073521f82aea56
parent9e3d27b574bd79b1178fa3c4ca634050eb21b47c
Replace outdated optimization with clearer code that compiles better.

Letting the compiler decide how to optimize the multiply by five
gives it the freedom to make better choices for the best technique
for a given target machine.

For example, GCC on x86_64 produces a little bit better code:

Old-way (3 steps with a data dependency between each step):

    shrq    $5, %r13
    leaq    1(%rbx,%r13), %rax
    leaq    (%rax,%rbx,4), %rbx

New-way (3 steps with no dependency between the first two steps
         which can be run in parallel):

    leaq    (%rbx,%rbx,4), %rax     # i*5
    shrq    $5, %r13                # perturb >>= PERTURB_SHIFT
    leaq    1(%r13,%rax), %rbx      # 1 + perturb + i*5
Objects/setobject.c