From: Georg Bauhaus <bauhaus@futureapps.de>
To: Paul Schlie <schlie@comcast.net>
Cc: Robert Dewar <dewar@adacore.com>, gcc@gcc.gnu.org
Subject: Re: Where does the C standard describe overflow of signed integers?
Date: Fri, 15 Jul 2005 13:20:00 -0000 [thread overview]
Message-ID: <42D7B82B.7010102@futureapps.de> (raw)
In-Reply-To: <BEFC3FA7.AD21%schlie@comcast.net>
Paul Schlie wrote:
>>From: Robert Dewar <dewar@adacore.com>
>>
>>>Paul Schlie wrote:
>>
>>>I don't contest that it may, I simply don't believe it should.
>>
>>you can't seriously mean that with respect to uninitialized
>>variables. this would mean you could not put local variables in
>>registers. the effect on code quality woul be awful!
>
>
> Why would anyone care about the performance of an access to an
> un-initialized variable? [..] although do
> see substantial value in producing compiled code which is strictly
> consistent with the specified program and native target behavior,
> regardless of its portability.
You can have both, correctness and uninitialised local
variables. For an impression of the difference in performance,
and for a way to ensure correctness, I tried this
(switch register/volatile in the declaration lines in comp
and r to see the effects).
#include <stddef.h>
#include <assert.h>
#define BUFFER_SIZE 1000 // must be > 0
#define ITERATIONS 100000 // must be > 0
static inline int comp(const short, const short, const short);
/* pre: a has elements, that is hi > 0. Frequently called */
int r(short a[], size_t hi)
{
//register int x, y, z;
volatile int x=1, y=2, z=3;
assert(hi > 0);
for (size_t c=0; c < hi + 2; ++c) {
if (a[c]) {
jfssoae:
x = c + 3, y = z = a[c];
if (comp(x, y, z)) z = x - y;
}
}
return x + y + z;
}
static inline int comp(const short x, const short y, const short z)
{
//register int result = (x + y) == (x + z);
volatile int result = (x + y) == (x + z);
return result;
}
int main()
{
short buffer[BUFFER_SIZE];
int result;
assert(ITERATIONS > 0);
for (int runs = 0; runs < ITERATIONS; ++runs) {
result = r(buffer, BUFFER_SIZE);
}
return result;
}
next prev parent reply other threads:[~2005-07-15 13:20 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-14 19:09 Paul Schlie
2005-07-14 19:13 ` Robert Dewar
2005-07-14 19:28 ` Paul Schlie
2005-07-14 19:33 ` Robert Dewar
2005-07-14 20:13 ` Paul Schlie
2005-07-15 13:20 ` Georg Bauhaus [this message]
2005-07-15 13:33 ` Georg Bauhaus
2005-07-15 14:31 ` Dave Korn
2005-07-16 12:04 ` Georg Bauhaus
2005-07-16 14:26 ` Paul Schlie
2005-07-15 15:03 ` Paul Schlie
2005-07-16 12:12 ` Georg Bauhaus
2005-07-14 20:35 ` Paul Koning
2005-07-14 21:58 ` Paul Schlie
2005-07-15 7:04 ` Avi Kivity
-- strict thread matches above, loose matches on Subject: below --
2005-07-14 1:10 Paul Schlie
2005-07-14 1:59 ` Robert Dewar
2005-07-14 5:28 ` Paul Schlie
2005-07-14 17:57 ` Matthew Woodcraft
2005-07-14 18:36 ` Paul Koning
2005-07-11 14:58 Nicholas Nethercote
2005-07-11 15:07 ` Dave Korn
2005-07-11 16:07 ` Nicholas Nethercote
2005-07-11 17:04 ` Dave Korn
2005-07-11 15:15 ` Nathan Sidwell
2005-07-11 15:23 ` Dave Korn
2005-07-12 23:13 ` Michael Meissner
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=42D7B82B.7010102@futureapps.de \
--to=bauhaus@futureapps.de \
--cc=dewar@adacore.com \
--cc=gcc@gcc.gnu.org \
--cc=schlie@comcast.net \
/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).