This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Bug in divmodhi4(), plus poor inperformant code
- From: Paul Koning <paulkoning at comcast dot net>
- To: Stefan Kanthak <stefan dot kanthak at nexgo dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 5 Dec 2018 09:28:58 -0500
- Subject: Re: Bug in divmodhi4(), plus poor inperformant code
- References: <08C1AE242031402FA1206D72CB9AD084@W340> <E9204D74-DF3F-4D0F-AA5D-197B0758DDDC@comcast.net> <58F21FB4419D43EEBBBF13235B24E9C6@W340>
> On Dec 4, 2018, at 8:19 PM, Stefan Kanthak <stefan.kanthak@nexgo.de> wrote:
>
> "Paul Koning" <paulkoning@comcast.net> wrote:
>
>> Yes, that's a rather nasty cut & paste error I made.
>
> I suspected that.
> Replacing
> !(den & (1L<<31))
> with
> (signed short) den >= 0
> avoids this type of error: there's no need for a constant here!
>
> JFTR: of course the 1L should be just a 1, without suffix.
>
>> But if the 31 is changed to a 15, is the code correct?
>> I would think so.
>
> Almost. It's the standard algorithm, and it's correct except
> for den == 0, where the current implementation returns 0 as
> quotient or the numerator as remainder, while my fix yields an
> endless loop (as could be expected for "undefined behaviour").
I submitted a patch that just changes that one line. This file is a copy of udivmodsi4.c so I figured I'd aim for the same logic except for the word length changes, and the 31 instead of 15 was a missed edit for that.
The other changes could be left for later, or a handwritten assembly routine used instead as some other targets do.
Thanks!
paul