------- Comment #11 from tkoenig at gcc dot gnu dot org  2009-11-23 21:48 
-------
Created an attachment (id=19104)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19104&action=view)
another proposed patch

Here's another proposed patch, but there is a problem with it.

If we calculate (m2 - m1 + m3)/m3 with signed types, then this will overflow,
for example, for

do i=-huge(i),huge(i),2

The current implementation gets around that by doing the addition and division
unsigned, then dividing unsigned as well.  For this, there have to be two
cases, one for m3>0 and one for m3<0, which is what we generate
at the moment.

Possible solutions:

- get rid of the loop counter altogether

- perform the intermediate calculation with increased precision, if
  available

- Multiply everything by the sign of m3 before doing the unsigned
  math (which is what we do now, except that we hide this behind an
  if)

- Trust two's complement arithmetic and hope that overflows don't trap
  (not, in general, a good idea)

Any tricks I have missed?


-- 

tkoenig at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #19076|0                           |1
        is obsolete|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42131

Reply via email to