Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #98221

Re: "Lete2�™s Stop Bashing C"

From jacobnavia <jacob@jacob.remcomp.fr>
Newsgroups comp.lang.c
Subject Re: "Lete2�™s Stop Bashing C"
Date 2016-12-07 00:31 +0100
Organization A noiseless patient Spider
Message-ID <o27hmq$frb$1@dont-email.me> (permalink)
References (4 earlier) <o270js$b8g$1@dont-email.me> <o271gi$ejv$1@dont-email.me> <8f359715-238c-42b4-b53f-5c5511725fdb@googlegroups.com> <o279nh$f1b$1@dont-email.me> <52ccfda1-19b5-4996-ae9c-18b98ea6dd4f@googlegroups.com>

Show all headers | View raw


Le 06/12/2016 à 23:16, supercat@casperkitty.com a écrit :
> On Tuesday, December 6, 2016 at 3:15:52 PM UTC-6, jacobnavia wrote:
>> That costs around 4% when I wrote the first version of the software, but
>> can go down to 1-2% when you try to optimize a little bit.
>>
>> We, discussed this here extensively in a thread that I started in
>> comp.std.c and here in Sep 1, 2009.
>
> The problem is that if user code explicitly checks for overflow, then a
> compiler must generate code which detects overflow in all cases where the
> user code checks for it, even in scenarios where the user wouldn't care
> about overflow because it wouldn't interfere with correct computations.
>
> Consider as a simple example, x=(y+z)>>1; on an implementation which
> promises to trap any signed overflows which could result in numerical
> inaccuracy, and documents signed >> as floored power-of-two dovision.  While
> it could be implemented on x86 as
>
>     add esi,edi
>     jo  overflow_occurred
>     asr esi,1
>
> it could be even more efficiently implemented as:
>
>     add esi,edi
>     ror esi,1
>

You think then, that asr is more expensive than ror?

If I eliminate the test for overflow, the first code becomes
 >     add esi,edi
 >     asr esi,1

What is the same thing as your proposed better
 >     add esi,edi
 >     ror esi,1

Arithmetic shift right, and rotate right are the same, I do not think 
there is even a measurable difference after billions of operations...

We are running at 2GHZ at least... Testing the overflow flag is nothing, 
and the difference between asr/ror is not even measurable.

Same with most processors: testing a CPU flag incurs NO I/O, not even a 
register data movement and are extremely fast operations in all processors.

> In the event that the addition of ESI+EDI would overflow, a compiler would
> be entitled to trap, but letting a compiler yield the arithmetically-correct
> result even when not required to do so could yield more efficient code.
>

At the risk of corrupting the results?

Wait... it depends. If the numbers you are calculating are of no great 
importance, why do you calculate them anyway?

I just do not follow very much your logic. There is practically no 
difference between checking or not checking!

> An even more extreme example of that principle would occur in cases where
> a function computes a number of values, some of which will be ignored by
> many callers.  If a caller is going to ignore a value, but its computation
> could result in overflow, a compiler won't be able to optimize out any
> user-written checks for overflow.  If, however, a compiler instead has its
> own support for overflow trapping/reporting, it would only need to check
> for overflows in calculations which are actually used for some purpose.  If
> the result of a calculation isn't used, it should be possible to omit the
> calculation altogether, rendering the question of overflow moot.
>

Contrary to your examples I have a lot of counter examples where an 
overflow should be checked but it wasn't.

In an implementation:

void *calloc(size_t items, size_t itemsize);

There was an implementation of that function that did not test, and with 
specially built arguments would return a small buffer instead of a huge one.

And that is one of the thousands of similar errors. Why this obstination 
with "efficiency" when there is almost none?

What is the efficiency of wrong results? Because you introduce noise in 
the data, and I have the vague feeling sometimes, that MOST OF THE 
CALCULATION RESULTS ARE USED!

I would say even all of them in any serious software. The common case is 
far more important than those fringe cases.
And I think that we can safely forget about the problems of software 
that calculates things for nothing, since the results are no used...

Modern compilers optimize that away. Lcc-win doesn't in many cases but 
gcc/clang/whatever do that kind of stuff.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

"Let’s Stop Bashing C" Lynn McGuire <lynnmcguire5@gmail.com> - 2016-12-05 19:57 -0600
  Re: "Let’s Stop Bashing C" Richard Heathfield <rjh@cpax.org.uk> - 2016-12-06 02:34 +0000
    Re: "Let’s Stop Bashing C" BGB <cr88192@hotmail.com> - 2016-12-06 00:13 -0600
      Re: "Let’s Stop Bashing C" BartC <bc@freeuk.com> - 2016-12-06 23:15 +0000
        Re: "Let’s Stop Bashing C" BGB <cr88192@hotmail.com> - 2016-12-06 21:16 -0600
    Re: "Let’s Stop Bashing C" Richard Heathfield <rjh@cpax.org.uk> - 2016-12-06 11:54 +0000
    Re: "Let’s Stop Bashing C" BartC <bc@freeuk.com> - 2016-12-06 12:07 +0000
      Re: "Let’s Stop Bashing C" Richard Heathfield <rjh@cpax.org.uk> - 2016-12-06 12:25 +0000
        Re: "Let’s Stop Bashing C" David Brown <david.brown@hesbynett.no> - 2016-12-06 14:07 +0100
          Re: "Let’s Stop Bashing C" Richard Heathfield <rjh@cpax.org.uk> - 2016-12-06 13:40 +0000
        Re: "Let’s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-06 19:40 +0100
          Re: "Lete2��s Stop Bashing C" Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-06 13:55 -0500
            Re: "Lete2��s Stop Bashing C" Richard Heathfield <rjh@cpax.org.uk> - 2016-12-06 19:13 +0000
              Re: "Lete2��s Stop Bashing C" Keith Thompson <kst-u@mib.org> - 2016-12-06 11:51 -0800
                Re: "Lete2��s Stop Bashing C" supercat@casperkitty.com - 2016-12-06 12:22 -0800
            Re: "Lete2��s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-06 20:16 +0100
            Re: "Lete2�™s Stop Bashing C" supercat@casperkitty.com - 2016-12-06 11:20 -0800
              Re: "Lete2�™s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-06 22:15 +0100
                Re: "Lete2�™s Stop Bashing C" Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-06 16:49 -0500
                Re: "Lete2�™s Stop Bashing C" supercat@casperkitty.com - 2016-12-06 14:24 -0800
                Re: "Lete2�™s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-07 00:07 +0100
                Re: micro-architectural details Noob <root@127.0.0.1> - 2016-12-07 22:04 +0100
                Re: micro-architectural details jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-07 23:44 +0100
                Re: micro-architectural details BartC <bc@freeuk.com> - 2016-12-07 23:02 +0000
                Re: micro-architectural details Keith Thompson <kst-u@mib.org> - 2016-12-07 15:28 -0800
                Re: micro-architectural details Noob <root@127.0.0.1> - 2016-12-08 21:36 +0100
                Re: micro-architectural details supercat@casperkitty.com - 2016-12-08 12:56 -0800
                Re: micro-architectural details Noob <root@127.0.0.1> - 2016-12-08 23:03 +0100
                Re: micro-architectural details supercat@casperkitty.com - 2016-12-08 14:21 -0800
                Re: micro-architectural details Noob <root@127.0.0.1> - 2016-12-08 23:36 +0100
                Re: micro-architectural details BartC <bc@freeuk.com> - 2016-12-08 21:59 +0000
                Re: micro-architectural details Noob <root@127.0.0.1> - 2016-12-08 23:25 +0100
                Re: micro-architectural details supercat@casperkitty.com - 2016-12-08 14:34 -0800
                Re: micro-architectural details Noob <root@127.0.0.1> - 2016-12-08 23:59 +0100
                Re: micro-architectural details Melzzzzz <mel@zzzzz.com> - 2016-12-09 00:18 +0100
                Re: micro-architectural details fir <profesor.fir@gmail.com> - 2016-12-09 00:06 -0800
                Re: micro-architectural details jt@toerring.de (Jens Thoms Toerring) - 2016-12-09 11:35 +0000
                Re: micro-architectural details BartC <bc@freeuk.com> - 2016-12-09 12:12 +0000
                Re: micro-architectural details David Brown <david.brown@hesbynett.no> - 2016-12-09 13:33 +0100
                Re: micro-architectural details Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-09 15:41 -0800
                Re: micro-architectural details Tim Rentsch <txr@alumni.caltech.edu> - 2016-12-10 09:28 -0800
                Re: micro-architectural details supercat@casperkitty.com - 2016-12-10 09:58 -0800
                Re: micro-architectural details Tim Rentsch <txr@alumni.caltech.edu> - 2016-12-14 22:53 -0800
                Re: micro-architectural details Robert Wessel <robertwessel2@yahoo.com> - 2016-12-11 03:10 -0600
                Re: micro-architectural details jt@toerring.de (Jens Thoms Toerring) - 2016-12-11 13:48 +0000
                Re: micro-architectural details BartC <bc@freeuk.com> - 2016-12-11 14:43 +0000
                Re: micro-architectural details Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 16:23 +0000
                Re: micro-architectural details Keith Thompson <kst-u@mib.org> - 2016-12-11 12:53 -0800
                Re: micro-architectural details Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 21:27 +0000
                Re: micro-architectural details supercat@casperkitty.com - 2016-12-11 08:46 -0800
                Re: micro-architectural details Tim Rentsch <txr@alumni.caltech.edu> - 2016-12-14 21:14 -0800
                Re: micro-architectural details supercat@casperkitty.com - 2016-12-15 08:25 -0800
                Re: micro-architectural details Tim Rentsch <txr@alumni.caltech.edu> - 2016-12-14 21:11 -0800
                Re: micro-architectural details BartC <bc@freeuk.com> - 2016-12-15 14:28 +0000
                Re: micro-architectural details David Brown <david.brown@hesbynett.no> - 2016-12-11 18:38 +0100
                Re: micro-architectural details Tim Rentsch <txr@alumni.caltech.edu> - 2016-12-15 00:25 -0800
                Re: micro-architectural details supercat@casperkitty.com - 2016-12-09 07:42 -0800
                Re: micro-architectural details Keith Thompson <kst-u@mib.org> - 2016-12-09 11:54 -0800
                Re: micro-architectural details David Brown <david.brown@hesbynett.no> - 2016-12-09 10:27 +0100
                Re: other missing features (no-brainers) Noob <root@127.0.0.1> - 2016-12-09 17:05 +0100
                Re: micro-architectural details jt@toerring.de (Jens Thoms Toerring) - 2016-12-09 09:51 +0000
                Re: "Lete2�™s Stop Bashing C" Jerry Stuckle <jstucklex@attglobal.net> - 2016-12-06 20:42 -0500
                Re: "Lete2�™s Stop Bashing C" supercat@casperkitty.com - 2016-12-06 14:16 -0800
                Re: "Lete2�™s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-07 00:31 +0100
                Re: "Let's Stop Bashing C" Keith Thompson <kst-u@mib.org> - 2016-12-06 15:55 -0800
                Re: "Let's Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-07 01:01 +0100
                Re: "Lete2�™s Stop Bashing C" supercat@casperkitty.com - 2016-12-06 16:42 -0800
                Re: "Lete2�™s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-07 01:55 +0100
                Re: "Lete2�™s Stop Bashing C" supercat@casperkitty.com - 2016-12-07 07:11 -0800
                Re: "Lete2??s Stop Bashing C" Ike Naar <ike@iceland.freeshell.org> - 2016-12-06 23:05 +0000
                Re: "Lete2??s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-07 00:43 +0100
                Re: "Lete2??s Stop Bashing C" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-07 03:06 +0000
                Re: "Lete2??s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-07 11:47 +0100
                Re: "Lete2??s Stop Bashing C" Thiago Adams <thiago.adams@gmail.com> - 2016-12-07 03:10 -0800
                Re: "Lete2??s Stop Bashing C" Thiago Adams <thiago.adams@gmail.com> - 2016-12-07 03:13 -0800
                Re: "Lete2??s Stop Bashing C" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-07 11:47 +0000
                Re: "Lete2??s Stop Bashing C" Richard Heathfield <rjh@cpax.org.uk> - 2016-12-07 12:08 +0000
                Re: "Lete2??s Stop Bashing C" David Brown <david.brown@hesbynett.no> - 2016-12-07 23:45 +0100
                Re: "Lete2??s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-08 00:22 +0100
                Re: "Lete2??s Stop Bashing C" Keith Thompson <kst-u@mib.org> - 2016-12-07 15:32 -0800
                Re: "Let's Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-08 01:25 +0100
                Re: "Let's Stop Bashing C" supercat@casperkitty.com - 2016-12-07 16:36 -0800
                Re: "Let's Stop Bashing C" Keith Thompson <kst-u@mib.org> - 2016-12-07 17:09 -0800
                Re: "Let's Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-08 10:28 +0100
                Re: "Let's Stop Bashing C" Keith Thompson <kst-u@mib.org> - 2016-12-08 08:34 -0800
                Re: "Let's Stop Bashing C" Gareth Owen <gwowen@gmail.com> - 2016-12-08 20:08 +0000
                Re: "Lete2??s Stop Bashing C" David Brown <david.brown@hesbynett.no> - 2016-12-08 10:24 +0100
                Re: "Lete2??s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-08 15:49 +0100
                Re: "Lete2??s Stop Bashing C" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-08 15:23 +0000
                Re: "Lete2??s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-08 16:58 +0100
                Re: "Lete2??s Stop Bashing C" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-08 18:57 +0000
                Re: "Lete2??s Stop Bashing C" Richard Heathfield <rjh@cpax.org.uk> - 2016-12-08 15:29 +0000
                Re: "Lete2??s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-08 17:09 +0100
                Re: "Lete2??s Stop Bashing C" Richard Heathfield <rjh@cpax.org.uk> - 2016-12-08 16:41 +0000
                Re: "Lete2??s Stop Bashing C" David Brown <david.brown@hesbynett.no> - 2016-12-08 17:04 +0100
                Re: "Lete2??s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-08 17:15 +0100
                Re: "Lete2??s Stop Bashing C" Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-08 11:34 -0500
                Re: "Lete2??s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-08 18:40 +0100
                Re: "Lete2??s Stop Bashing C" supercat@casperkitty.com - 2016-12-08 10:00 -0800
                Re: "Lete2??s Stop Bashing C" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-08 19:05 +0000
                Re: "Lete2??s Stop Bashing C" David Brown <david.brown@hesbynett.no> - 2016-12-08 19:58 +0100
                Re: "Lete2??s Stop Bashing C" supercat@casperkitty.com - 2016-12-08 08:22 -0800
                Re: "Lete2??s Stop Bashing C" David Brown <david.brown@hesbynett.no> - 2016-12-08 20:12 +0100
                Re: "Lete2??s Stop Bashing C" supercat@casperkitty.com - 2016-12-08 11:40 -0800
                Re: "Lete2??s Stop Bashing C" Robert Wessel <robertwessel2@yahoo.com> - 2016-12-10 02:44 -0600
                Re: "Lete2??s Stop Bashing C" Richard Heathfield <rjh@cpax.org.uk> - 2016-12-08 16:22 +0000
                Re: "Lete2??s Stop Bashing C" David Brown <david.brown@hesbynett.no> - 2016-12-08 20:14 +0100
                Re: "Lete2??s Stop Bashing C" Robert Wessel <robertwessel2@yahoo.com> - 2016-12-10 02:19 -0600
                Re: "Lete2??s Stop Bashing C" supercat@casperkitty.com - 2016-12-08 07:44 -0800
                Re: "Lete2??s Stop Bashing C" David Brown <david.brown@hesbynett.no> - 2016-12-08 22:05 +0100
                Re: "Lete2??s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-08 22:14 +0100
                Re: "Lete2??s Stop Bashing C" David Brown <david.brown@hesbynett.no> - 2016-12-09 10:39 +0100
                Re: "Lete2??s Stop Bashing C" supercat@casperkitty.com - 2016-12-08 13:33 -0800
                Re: "Lete2??s Stop Bashing C" David Brown <david.brown@hesbynett.no> - 2016-12-09 11:13 +0100
                Re: "Lete2??s Stop Bashing C" Robert Wessel <robertwessel2@yahoo.com> - 2016-12-07 06:27 -0600
                Re: "Lete2??s Stop Bashing C" supercat@casperkitty.com - 2016-12-07 07:17 -0800
                Re: "Lete2??s Stop Bashing C" Robert Wessel <robertwessel2@yahoo.com> - 2016-12-07 23:43 -0600
                Re: "Lete2??s Stop Bashing C" Ike Naar <ike@iceland.freeshell.org> - 2016-12-07 07:41 +0000
                Re: "Lete2??s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-07 11:45 +0100
                Re: "Lete2??s Stop Bashing C" Keith Thompson <kst-u@mib.org> - 2016-12-07 09:22 -0800
                Re: "Lete2??s Stop Bashing C" jacobnavia <jacob@jacob.remcomp.fr> - 2016-12-07 11:49 +0100
                Re: "Lete2??s Stop Bashing C" Jerry Stuckle <jstucklex@attglobal.net> - 2016-12-07 09:28 -0500
            Re: "Lete2��s Stop Bashing C" "James R. Kuyper" <jameskuyper@verizon.net> - 2016-12-06 14:22 -0500
            Re: Subject field encoding Noob <root@127.0.0.1> - 2016-12-07 21:40 +0100
              Re: Subject field encoding Keith Thompson <kst-u@mib.org> - 2016-12-07 13:01 -0800
              Re: Subject field encoding Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-07 16:02 -0500
            Re: "Lete2�™s Stop Bashing C" asetofsymbols@gmail.com - 2016-12-08 15:50 -0800
          Re: "Let’s Stop Bashing C" Richard Heathfield <rjh@cpax.org.uk> - 2016-12-06 19:07 +0000
    Re: "Let€™s Stop Bashing C" Xcott Craver <nospam@nospam.invalid> - 2016-12-07 16:48 -0500
      Re: "Let's Stop Bashing C" Noob <root@127.0.0.1> - 2016-12-07 23:29 +0100
  Re: "Let’s Stop Bashing C" "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-12-06 12:06 +0800

csiph-web