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


Groups > comp.arch.embedded > #21660

Re: Slightly OT: speed of operation on a PC

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.arch.embedded
Subject Re: Slightly OT: speed of operation on a PC
Date 2015-08-05 12:59 +0200
Organization A noiseless patient Spider
Message-ID <mpsq7l$pi6$1@dont-email.me> (permalink)
References <juKdnf5uzZr0YF3InZ2dnUU7-YOdnZ2d@giganews.com> <4%9wx.82891$Ec3.82302@fx24.am4> <mpsoav$id3$1@dont-email.me>

Show all headers | View raw


On 05/08/15 12:25, Simon Clubley wrote:
> On 2015-08-04, Tom Gardner <spamjunk@blueyonder.co.uk> wrote:
>> On 04/08/15 18:59, Tim Wescott wrote:
>>> Which do you think is quicker on a PC, with the latest gnu compiler:
>>>
>>> double a = something;
>>> double b = something else;
>>>
>>> if (a >= 0.0 && b < 0.0)
>>>
>>>>> or <<
>>>
>>> if (a * b <= 0)
>>>
>>> Thank you for your time.
>>
>> With many of these questions, the answer may depend on the
>> surrounding context and the compiler optimisation level,
>> and what is/isn't in the cache.
>>
>> And may change with the next compiler release. Or with
>> a "trivial" change to the context.
>>
> 
> You have no idea just how true that is. :-( :-(
> 
> Still annoyed about this one because it's just happened to me (last
> night) and I sunk quite some time into it because I wrongly thought
> initially I had done something stupid to my code while changing it.
> 
> MIPS gcc cross-compiler, targeting a M4K core, -Os in effect.
> 
> Made a change to a routine (called from lots of places) which _reduced_
> the amount of code in the routine. End result: final binary _grew_ from
> 3520 bytes to 4844 bytes and hence smashed through the 4K SRAM limit
> available for the code to execute in.
> 
> Even though -Os was in use, it appears gcc decided to inline my new
> smaller routine; I guess the final binary size wasn't considered by gcc
> for some reason.
> 
> -fno-inline fixed the problem. (As did -O1 :-))
> 

Or use __attribute__((noinline)) on the function in question.

gcc uses a number of heuristics and hints to decide whether or not a
function should be inlined.  These include optimisation options (such as
-Os, -O2 or -O3), knowledge about the code usage (a single-use static
function is almost always inlined with modern gcc), and estimations
about how the total code size will change by inline the code.  It is
often not clear whether inlining will cause code to grow or shrink,
since inlining eliminates function call overhead (which can be large in
some cases), and can allow for many other optimisations (keeping data in
registers before and after the call, constant propagation, etc.).

gcc usually does a reasonable job, but certainly not always - it
sometimes gets things wrong due to bugs (suboptimal code generation is
still correct code generation, and so such issues are harder to spot and
lower priority for fixing), limited functionality (such as overly
simplistic models of code size), or simply because the balancing
heuristics about when a function is "too big to inline" or "small enough
to always inline, even with -Os" don't match your particular requirements.

More recent versions of gcc generally have better tuning (and fewer
bugs) than older ones, but it can never be right for everyone.  You can
fiddle with many of the heuristic parameters manually, but usually the
best method is a few "noinline" or "always_inline" (or even "flatten")
attributes in critical functions.


Look at it this way - it is one of the many little quirks that keep our
jobs from getting boring!



> This was with the MIPS sourced version of the compiler which is quite
> old by now (gcc 4.4.6 IIRC) so I don't know if it's a problem on current
> gcc versions.
> 
> The message for Tim is that you need to see the generated code in the
> final binary at the optimisation level you are _actually_ using before
> you can decide which one is best. (And don't assume higher optimisation
> level equals "better". :-))
> 
> Simon.
> 

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Slightly OT: speed of operation on a PC Tim Wescott <seemywebsite@myfooter.really> - 2015-08-04 12:59 -0500
  Re: Slightly OT: speed of operation on a PC rickman <gnuarm@gmail.com> - 2015-08-04 14:06 -0400
  Re: Slightly OT: speed of operation on a PC Lanarcam <lanarcam1@yahoo.fr> - 2015-08-04 20:06 +0200
    Re: Slightly OT: speed of operation on a PC Tim Wescott <seemywebsite@myfooter.really> - 2015-08-04 13:27 -0500
      Re: Slightly OT: speed of operation on a PC Lanarcam <lanarcam1@yahoo.fr> - 2015-08-04 20:33 +0200
      Re: Slightly OT: speed of operation on a PC rickman <gnuarm@gmail.com> - 2015-08-04 17:05 -0400
        Re: Slightly OT: speed of operation on a PC Tim Wescott <seemywebsite@myfooter.really> - 2015-08-04 18:54 -0500
          Re: Slightly OT: speed of operation on a PC glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-05 00:09 +0000
            Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-04 17:32 -0700
          Re: Slightly OT: speed of operation on a PC Clifford Heath <no.spam@please.net> - 2015-08-05 17:25 +1000
            Re: Slightly OT: speed of operation on a PC Anders.Montonen@kapsi.spam.stop.fi.invalid - 2015-08-05 08:34 +0000
    Re: Slightly OT: speed of operation on a PC Philipp Klaus Krause <pkk@spth.de> - 2015-08-11 11:04 +0200
  Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-04 11:07 -0700
    Re: Slightly OT: speed of operation on a PC Tim Wescott <seemywebsite@myfooter.really> - 2015-08-04 13:28 -0500
      Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-04 11:37 -0700
        Re: Slightly OT: speed of operation on a PC Tom Gardner <spamjunk@blueyonder.co.uk> - 2015-08-04 22:20 +0100
        Re: Slightly OT: speed of operation on a PC glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-04 21:45 +0000
          Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-04 15:34 -0700
            Re: Slightly OT: speed of operation on a PC glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-05 00:00 +0000
              Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-04 17:36 -0700
                Re: Slightly OT: speed of operation on a PC glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-05 05:43 +0000
                Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-05 00:44 -0700
                Re: Slightly OT: speed of operation on a PC Clifford Heath <no.spam@please.net> - 2015-08-05 19:14 +1000
                Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-05 08:04 -0700
      Re: Slightly OT: speed of operation on a PC Clifford Heath <no.spam@please.net> - 2015-08-05 17:28 +1000
  Re: Slightly OT: speed of operation on a PC Paul Rubin <no.email@nospam.invalid> - 2015-08-04 11:13 -0700
  Re: Slightly OT: speed of operation on a PC "Bill Davy" <Bill@SynectixLtd.com> - 2015-08-04 19:19 +0100
  Re: Slightly OT: speed of operation on a PC Tom Gardner <spamjunk@blueyonder.co.uk> - 2015-08-04 22:18 +0100
    Re: Slightly OT: speed of operation on a PC Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2015-08-05 10:25 +0000
      Re: Slightly OT: speed of operation on a PC Tom Gardner <spamjunk@blueyonder.co.uk> - 2015-08-05 11:42 +0100
        Re: Slightly OT: speed of operation on a PC Anders.Montonen@kapsi.spam.stop.fi.invalid - 2015-08-05 11:23 +0000
          Re: Slightly OT: speed of operation on a PC David Brown <david.brown@hesbynett.no> - 2015-08-05 13:58 +0200
          Re: Slightly OT: speed of operation on a PC Robert Wessel <robertwessel2@yahoo.com> - 2015-08-06 00:24 -0500
      Re: Slightly OT: speed of operation on a PC David Brown <david.brown@hesbynett.no> - 2015-08-05 12:59 +0200
  Re: Slightly OT: speed of operation on a PC Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2015-08-04 23:30 +0200
    Re: Slightly OT: speed of operation on a PC Philipp Klaus Krause <pkk@spth.de> - 2015-08-11 11:19 +0200
  Re: Slightly OT: speed of operation on a PC David Brown <david.brown@hesbynett.no> - 2015-08-05 08:32 +0200
  Re: Slightly OT: speed of operation on a PC Stefan Reuther <stefan.news@arcor.de> - 2015-08-05 18:43 +0200
  Re: Slightly OT: speed of operation on a PC edward.ming.lee@gmail.com - 2015-08-05 10:31 -0700
    Re: Slightly OT: speed of operation on a PC Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2015-08-05 20:11 +0200
    Re: Slightly OT: speed of operation on a PC rickman <gnuarm@gmail.com> - 2015-08-05 20:19 -0400
      Re: Slightly OT: speed of operation on a PC edward.ming.lee@gmail.com - 2015-08-05 19:45 -0700
        Re: Slightly OT: speed of operation on a PC Clifford Heath <no.spam@please.net> - 2015-08-06 12:56 +1000

csiph-web