public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* signed is undefined and has been since 1992 (in GCC)
@ 2005-06-28  4:08 Andrew Pinski
  2005-06-28  4:20 ` Michael Veksler
  2005-06-28  4:34 ` Gabriel Dos Reis
  0 siblings, 2 replies; 119+ messages in thread
From: Andrew Pinski @ 2005-06-28  4:08 UTC (permalink / raw)
  To: gcc mailing list

The first change in GCC which changed signed overflow/wrapping to be 
undefined
was added back in 1992 in loop.c.  The next change was in 1999 with the
addition of simplify-rtx.c.  Why are we talking about this now, instead 
of back
when they were added?  (note both of these changes were before fwrapv 
can into
play).

-- Pinski

^ permalink raw reply	[flat|nested] 119+ messages in thread
* Re: signed is undefined and has been since 1992 (in GCC)
@ 2005-06-28 16:59 Morten Welinder
  2005-06-28 17:23 ` Olivier Galibert
  2005-06-28 18:44 ` Michael Veksler
  0 siblings, 2 replies; 119+ messages in thread
From: Morten Welinder @ 2005-06-28 16:59 UTC (permalink / raw)
  To: galibert; +Cc: gcc

> In particular, a very large number of C and C++ programs are written
> with the assumptions:

>- signed and unsigned types are modulo, except in loop induction
> variables where it's bad taste

Well, as demonstrated by INT_MIN/-1, gcc has NEVER fulfilled such assumptions
on i86 and, quite likely, neither has or will any other compiler.   The runtime
penalty would be too big and hurt performance numbers.

What I believe you can find examples of is that the more restricted claim of
"addition and perhaps subtraction of signed numbers is modulo" is being
assumed.  That's cheap since (for 2-complement) signed addition is the same
operation as unsigned addition.

Morten

^ permalink raw reply	[flat|nested] 119+ messages in thread
* Re: signed is undefined and has been since 1992 (in GCC)
@ 2005-06-28 17:41 Paul Schlie
  0 siblings, 0 replies; 119+ messages in thread
From: Paul Schlie @ 2005-06-28 17:41 UTC (permalink / raw)
  To: Gabriel Dos Reis, Steven Bosscher, Robert Dewar, Andrew Pinski
  Cc: GCC Development

Gabriel Dos Reis writes:
> Steven Bosscher <stevenb@suse.de> writes:
>| On Tuesday 28 June 2005 07:12, Gabriel Dos Reis wrote:
>| > For the concrete case at issue, if the hardware I'm writing the C/C++
>| > programs for consistently displays modulo arithmetics for signed
>| > integer type, Andrew can you tell me why GCC should deny me access
>| > to that functionally where it actually can?
>| 
>| Because it disallows compiler transformations?  E.g. suddenly a
>| loop with a signed variable as the loop counter may wrap around,
>| which that means some transformations that are safe now would
>| no longer be safe.
>
> You have to define "safe".  Obviously, if you make the assumption that
> with signed overflow, all bets are off then you can go to
> tansformations predicated by that assumption.  If you take the
> assumption that signed overflow is defined and supported, you can go
> transformations predicated by that assumption.  In either case, "safe"
> is with respect to the semantics chosen.

Yes.

Overall the problem/conflict seems to revolve around the differentiation
between what's allowed vs. should be done; where "should" is of course
subjective, so it may be worth first attempting to define philosophically
what an idealized implementation "should" do, and then strive to follow this
guideline in cases where the compiler has the freedom to do so.

For what it's worth, a compiler "should":

- Strictly implement all mandated language semantics by default; although
  may enable these semantics to be extended and/or altered, if believed to
  be "Most Likely Beneficial", only by explicit request to do so.

- Define and correspondingly strictly implement the "Most Likely Beneficial"
  semantics which are not mandated by the standard as if they were, and
  emit a warning for every such behavior which is known to likely to express
  itself. (i.e. a shift by a value known to have a range which may exceed
  the size of it's shifted operand, or a the dereference of a pointer which
  is known to potentially be NULL, for example.)

- Where the "Most likely Beneficial" semantics are those which most likely:
  - improve the expressiveness and/or consistency of the language.
  - improve the determinism of the language and resulting executable.
  - improve the efficiency of the language and resulting executable by
    adopting and basing optimizations on the target's native semantics
    when not in conflict with the above.

Thereby it's never "Most likely Beneficial" to base optimizations on a
presumed undefined behavior, as no such behaviors should exist; therefore
such optimizations will only likely yield inconsistent and/or potentially
non-deterministic results, which is most likely not beneficial toward the
goals of producing an efficient deterministic program.

(The key to an efficient, consistent, and deterministic compiled program is
leveraging the natural behavior of the target where it is not in conflict
with the language's or implementation's otherwise defined semantics.)


^ permalink raw reply	[flat|nested] 119+ messages in thread
[parent not found: <2382433.1119938227627.JavaMail.root@dtm1eusosrv72.dtm.ops.eu.uu.net>]

end of thread, other threads:[~2005-07-14  7:21 UTC | newest]

Thread overview: 119+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-28  4:08 signed is undefined and has been since 1992 (in GCC) Andrew Pinski
2005-06-28  4:20 ` Michael Veksler
2005-06-28  9:49   ` Robert Dewar
2005-06-28  4:34 ` Gabriel Dos Reis
2005-06-28  4:50   ` Andrew Pinski
2005-06-28  5:13     ` Gabriel Dos Reis
2005-06-28  5:34       ` Andrew Pinski
2005-06-28  6:01         ` Gabriel Dos Reis
2005-06-28  9:18           ` Robert Dewar
2005-06-28 11:50             ` Gabriel Dos Reis
2005-06-28 12:07               ` Robert Dewar
2005-06-28 12:33                 ` Gabriel Dos Reis
2005-06-28 12:57                   ` Robert Dewar
2005-06-28 13:19                     ` Gabriel Dos Reis
2005-06-28 22:58                       ` Georg Bauhaus
2005-06-28 23:53                         ` Gabriel Dos Reis
2005-06-29  0:27                           ` Robert Dewar
2005-06-29  0:43                             ` Gabriel Dos Reis
2005-06-29  0:48                               ` Robert Dewar
2005-06-29  1:14                                 ` Gabriel Dos Reis
2005-06-29  1:21                                   ` Diego Novillo
2005-06-29  2:19                                     ` Marcin Dalecki
2005-06-29  3:13                                       ` Scott Robert Ladd
2005-06-28 14:24                     ` Olivier Galibert
2005-06-28 14:28                       ` Jonathan Wilson
2005-06-28 14:42                         ` Olivier Galibert
2005-06-28 14:39                       ` Dave Korn
2005-06-28 14:52                         ` Olivier Galibert
2005-06-28 15:01                           ` Robert Dewar
2005-06-28 15:04                           ` Andrew Haley
2005-06-28 17:18                             ` Olivier Galibert
2005-06-28 17:36                               ` Dave Korn
2005-06-28 18:02                                 ` Olivier Galibert
2005-06-28 18:36                                   ` Dave Korn
2005-06-28 18:56                                     ` Gabriel Dos Reis
2005-06-28 19:10                                     ` Olivier Galibert
2005-06-28 19:13                                       ` Andrew Pinski
2005-06-28 19:20                                         ` Robert Dewar
2005-06-28 21:48                                           ` Joe Buck
2005-06-28 19:25                                         ` Gabriel Dos Reis
2005-06-28 19:32                                           ` Robert Dewar
2005-06-28 19:48                                             ` Gabriel Dos Reis
2005-06-28 20:37                                               ` Robert Dewar
2005-06-28 20:58                                                 ` Gabriel Dos Reis
2005-06-28 21:57                                                   ` Robert Dewar
2005-06-28 21:44                                             ` Joe Buck
2005-06-28 21:50                                               ` Olivier Galibert
2005-06-28 21:59                                               ` Robert Dewar
2005-06-28 18:52                                   ` Robert Dewar
2005-06-28 19:17                                     ` Olivier Galibert
2005-06-28 19:21                                       ` Robert Dewar
2005-06-28 20:18                                         ` Paul Koning
2005-06-28 20:24                                           ` Robert Dewar
2005-06-28 21:41                                             ` Joe Buck
2005-06-28 21:53                                         ` Michael Veksler
2005-06-28 23:05                                           ` Michael Veksler
2005-07-02 17:15                                         ` Florian Weimer
2005-07-02 18:59                                           ` Gabriel Dos Reis
2005-07-02 23:20                                             ` Robert Dewar
2005-07-03  0:07                                               ` Gabriel Dos Reis
2005-07-03  9:49                                                 ` Robert Dewar
2005-07-02 23:12                                           ` Nicholas Nethercote
2005-07-02 23:20                                           ` Robert Dewar
2005-07-03  0:13                                             ` Gabriel Dos Reis
2005-07-03  9:54                                               ` Robert Dewar
2005-07-03 10:02                                                 ` Florian Weimer
2005-07-03 10:10                                                   ` Robert Dewar
2005-07-03 12:01                                                 ` Gabriel Dos Reis
2005-07-14  7:21                                           ` Marc Espie
2005-07-02 17:06                                 ` Florian Weimer
2005-06-28 17:51                               ` Joe Buck
2005-06-28 18:21                                 ` Gabriel Dos Reis
2005-06-28 18:53                                   ` Robert Dewar
2005-06-28 18:28                                 ` Olivier Galibert
2005-06-28 18:38                                   ` Dave Korn
2005-06-28 18:50                               ` Robert Dewar
2005-06-28 19:02                                 ` Gabriel Dos Reis
2005-06-28 19:17                                   ` Robert Dewar
2005-06-28 19:43                                     ` Gabriel Dos Reis
2005-06-28 20:31                                       ` Robert Dewar
2005-06-28 20:51                                         ` Gabriel Dos Reis
2005-06-28 20:59                                           ` Robert Dewar
2005-06-28 21:20                                             ` Gabriel Dos Reis
2005-06-28 21:27                                               ` Paul Koning
2005-06-28 21:39                                                 ` Andreas Schwab
2005-06-28 21:35                                               ` Joe Buck
2005-06-28 22:09                                     ` Joseph S. Myers
2005-06-28 22:16                                       ` Falk Hueffner
2005-06-29  6:59                                         ` Eric Botcazou
2005-06-28 22:19                                       ` Robert Dewar
2005-06-28 16:42                         ` Joe Buck
2005-06-28 17:10                           ` Dave Korn
2005-06-28 17:21                             ` Joe Buck
2005-06-28 22:41                               ` Georg Bauhaus
2005-06-28 14:47                       ` Gabriel Dos Reis
2005-06-28 16:38                     ` Joe Buck
2005-06-28 21:59                     ` Mike Stump
2005-06-28 13:47                   ` Gabriel Paubert
2005-06-28 13:52                     ` Andrew Pinski
2005-06-28 14:33                     ` Robert Dewar
2005-06-28 12:08               ` Robert Dewar
2005-06-28 12:34                 ` Gabriel Dos Reis
2005-06-28  7:25         ` Michael Veksler
2005-06-28 16:32           ` Joe Buck
2005-06-28 16:56             ` Joe Buck
2005-06-28 17:03             ` Gabriel Dos Reis
2005-06-28 17:34               ` Joe Buck
2005-06-28 18:09                 ` Gabriel Dos Reis
2005-06-28 17:35               ` Diego Novillo
2005-06-28  6:55       ` Steven Bosscher
2005-06-28  7:20         ` Michael Veksler
2005-06-28  7:39           ` Falk Hueffner
2005-06-28 12:08             ` Gabriel Dos Reis
2005-06-28 12:01         ` Gabriel Dos Reis
2005-06-28 16:59 Morten Welinder
2005-06-28 17:23 ` Olivier Galibert
2005-06-28 18:44 ` Michael Veksler
2005-06-28 17:41 Paul Schlie
     [not found] <2382433.1119938227627.JavaMail.root@dtm1eusosrv72.dtm.ops.eu.uu.net>
2005-06-28 19:44 ` Toon Moene

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).