public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Theodore Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr>
To: Mark Mitchell <mark@codesourcery.com>
Cc: Joe Buck <Joe.Buck@synopsys.COM>,
	Michael Veksler <VEKSLER@il.ibm.com>,
	Paul Koning <pkoning@equallogic.com>,
	gcc@gcc.gnu.org, gdr@integrable-solutions.net,
	nathan@codesourcery.com
Subject: Re: Do C++ signed types have modulo semantics?
Date: Tue, 28 Jun 2005 17:46:00 -0000	[thread overview]
Message-ID: <1119980590.23191.16.camel@mururoa> (raw)
In-Reply-To: <42C182A0.7000207@codesourcery.com>

On Tue, 2005-06-28 at 10:02 -0700, Mark Mitchell wrote:
> Joe Buck wrote:

> > 
> > int blah(int);
> > 
> > int func(int a, int b) {
> >     if (b >= 0) {
> > 	int c = a + b;
> > 	int count = 0;
> > 	for (int i = a; i <= c; i++)
> > 	    count++;
> > 	blah(count);
> >     }
> > }
> 
> Yes, I understand.
> 
> I just didn't imagine that these kinds of opportunities came up very 
> often.  (Perhaps that's because I routinely write code that can't be 
> compiled well, and so don't think about this situation.  In particular, 
> I often use unsigned types when the underlying quantity really is always 
> non-negative, and I'm saddened to learn that doing that would result in 
> inferior code.)

The real question is how often anyone is writing a loop (with an
unsigned of signed index) that is designed to wrap....

So maybe at the end of this lengthy discussion, one decision to make is
introduce a flag -floop-index-may-wrap and assume by default that loop
indices never, ever go outside of the range of values allowed by the
underlying type (or the opposite if backward compatibility is judged
more important).

A few months ago, problems with integers that may possibly wrap was
found to be a major penalty for STL vectors because loops over iterators
were never unrolled (because the increment on pointers is 4 and the
unroller was not able to decide the finiteness of a loop in such a
case). Zdenek (I hope my memory does not misattribute the work)
corrected that for increments that are powers of 2 (in which case it is
easier to decide whether the loop is finite or not). The fact remains
that the loop unroller currently must be pessimist in many cases
assuming that the loop induction variable may wrap ending up in an
infinite loop....

  parent reply	other threads:[~2005-06-28 17:46 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-27  5:09 Michael Veksler
2005-06-27 13:02 ` Nathan Sidwell
2005-06-27 14:10   ` Gabriel Dos Reis
2005-06-27 14:36     ` Nathan Sidwell
2005-06-27 14:47       ` Paul Koning
2005-06-27 15:21         ` Michael Veksler
2005-06-28  3:06           ` Mark Mitchell
2005-06-28  3:49             ` Gabriel Dos Reis
2005-06-28 10:08             ` Robert Dewar
2005-06-28 11:19               ` Steven Bosscher
2005-06-28 12:03                 ` Ulrich Weigand
2005-06-28 12:09                   ` Steven Bosscher
2005-06-29 16:46                     ` Steven Bosscher
2005-06-29 18:01                       ` Daniel Berlin
2005-06-29 18:32                         ` Steven Bosscher
2005-06-29 18:45                           ` Robert Dewar
2005-06-29 19:13                         ` Nicholas Nethercote
2005-06-28 12:16                 ` Paul Koning
2005-06-28 12:30                   ` Steven Bosscher
2005-06-28 12:35                     ` Michael Veksler
2005-06-28 12:38                       ` Steven Bosscher
2005-06-28 16:54             ` Joe Buck
2005-06-28 17:02               ` Mark Mitchell
2005-06-28 17:08                 ` Daniel Berlin
2005-06-28 18:12                   ` Mark Mitchell
2005-06-28 17:46                 ` Theodore Papadopoulo [this message]
2005-06-27 15:17       ` Gabriel Dos Reis
2005-06-30 20:53         ` Kai Henningsen
2005-06-27 14:39 Morten Welinder
2005-06-27 15:21 ` Gabriel Dos Reis
     [not found] <OF0E4366CA.5D54868B-ON4325702E.0036D351-4325702E.003973C5@il.ibm.com>
     [not found] ` <m3k6keeibo.fsf@uniton.integrable-solutions.net>
2005-06-28 13:29   ` Nathan Sidwell
2005-06-28 13:59     ` Gabriel Dos Reis
2005-06-28 14:05       ` Nathan Sidwell
2005-06-28 14:05       ` Andrew Pinski
2005-06-28 14:13         ` Gabriel Dos Reis
2005-06-28 15:30           ` Michael Veksler
2005-06-28 15:49             ` Nathan Sidwell
2005-06-28 15:58               ` Michael Veksler
2005-06-28 16:07                 ` Andrew Pinski
2005-06-28 16:39                 ` Gabriel Dos Reis
2005-06-28 15:55             ` Gabriel Dos Reis
2005-06-28 16:47               ` Joseph S. Myers
2005-06-28 17:58                 ` Gabriel Dos Reis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1119980590.23191.16.camel@mururoa \
    --to=theodore.papadopoulo@sophia.inria.fr \
    --cc=Joe.Buck@synopsys.COM \
    --cc=VEKSLER@il.ibm.com \
    --cc=gcc@gcc.gnu.org \
    --cc=gdr@integrable-solutions.net \
    --cc=mark@codesourcery.com \
    --cc=nathan@codesourcery.com \
    --cc=pkoning@equallogic.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).