int(long(-sys.maxint-1)) fails on Linux
Christian Tismer
tismer at appliedbiometrics.com
Fri Jul 23 07:31:43 EDT 1999
Chad Netzer wrote:
>
> Here I go, replying to my own posts again...
...
> Here is some assembly of the same region, compiled with the -O1 flag, which DOES
> exhibit the incorrect behavior. Notice that it is quite different from the previous code,
> and I think the bug is that it uses the "LEA" instruction improperly:
>
> <PyLong_AsLong+89>: test %edx,%edx ; x < 0
> <PyLong_AsLong+91>: jge 0x806c22a <PyLong_AsLong+106>
> <PyLong_AsLong+93>: test %ebx,%ebx ; sign > 0
> <PyLong_AsLong+95>: jg 0x806c231 <PyLong_AsLong+113> ; goto overflow
> <PyLong_AsLong+97>: lea 0x0(,%edx,2),%eax ; ?? Where is (x << 1)?
lea doesn't change any flags. It optimizes the shift to an add
which is fine. The implied test of the result is just not done
and this is a false optimization.
Somehing similar happened to me when I hand-optimized assembly
code. It is tempting to replace
add ax, 1
by
inc ax
but beware, that doesn't set flags, and it's likely that you forget
about it when changing tests.
> <PyLong_AsLong+104>: jne 0x806c231 <PyLong_AsLong+113> ; goto overflow
> <PyLong_AsLong+106>: mov %edx,%eax
> <PyLong_AsLong+108>: imul %ebx,%eax
> <PyLong_AsLong+111>: jmp 0x806c246 <PyLong_AsLong+134>
>
> As you can see, the original code had add %eax, %eax instruction to shift
> left by one, the optimized one doesn't. I don't know what the heck it
> was trying to do, and I don't know what condition codes "lea" sets, so
> I can't know what it intended. In any case, I speculate that line +104
> was causing a jump to the overflow handler when it should not.
>
> Anyway, I apologize for cluttering the newsgroup with assembly; clearly the
> problem is with pgcc w/ optimization turned on, which is a Mandrake 6.0 issue.
I can't see any bad about assembly. This is just another data type,
and Python can be a fine tool as a generic,
table driven disassembler ;-)
but that's another project which I will continue next year - chris
--
Christian Tismer :^) <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net
10553 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
we're tired of banana software - shipped green, ripens at home
More information about the Python-list
mailing list