[fpc-devel] Division nodes
J. Gareth Moreton
gareth at moreton-family.com
Mon May 15 19:47:46 CEST 2023
Thank you! I knew it must have been something simple like that!
I just did a quick test with x86 assembly language - this is the code
that used to run for dividing min_int by -1:
MOV EAX, $80000000
EAX contains $80000000 as a result. When using IDIV:
MOV EAX, $80000000
MOV EDX, $FFFFFFFF // Sign extension
MOV ECX, -1
Exception SIGFPE raised.
I understand now. Thanks for pointing out min_int div -1. I'll
experiment a bit more though to see if generating the setup is necessary
in all circumstances (e.g. if an unsigned operand is being expanded into
a larger signed value, it isn't necessary). At the very least, I'll add
a new test for this and also put a comment in the code so it's clear why
-1 needs special treatment (the fact I got no regressions means this
very specific set-up is not tested properly).
On 15/05/2023 17:43, Kirinn via fpc-devel wrote:
> I didn't see a mention of it in this discussion thread, but dividing the
> largest negative integer by -1 does cause an overflow error of some sort,
> because of two's complement.
> Just to make sure, do (min_int div -1) and (min_int mod -1) behave the same
> way before and after this proposed change? And, what min_int is of course
> depends on whether targeting a 32-bit or 64-bit system, so best check both
> On Mon, 15 May 2023 17:21:30 +0100
> "J. Gareth Moreton via fpc-devel" <fpc-devel at lists.freepascal.org> wrote:
>> I made a merge request that removes the comparison against -1.
>> x86_64-win64 and i386-win32 pass without any regressions, so the reason
>> behind the change still eludes me. Maybe my fix for #39646 removes the
>> need for it?
>> On 11/05/2023 23:04, J. Gareth Moreton via fpc-devel wrote:
>>> Fair enough, but I would like an explanation as to why it's necessary,
>>> because the reason for testing -1 in particular is very unclear, and I
>>> wonder if there's a known misbehaviour with a particular division
>>> function with -1.
> fpc-devel maillist - fpc-devel at lists.freepascal.org
More information about the fpc-devel