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


Groups > comp.arch.embedded > #21625 > unrolled thread

Slightly OT: speed of operation on a PC

Started byTim Wescott <seemywebsite@myfooter.really>
First post2015-08-04 12:59 -0500
Last post2015-08-06 12:56 +1000
Articles 20 on this page of 43 — 17 participants

Back to article view | Back to comp.arch.embedded


Contents

  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

Page 2 of 3 — ← Prev page 1 [2] 3  Next page →


#21651

Fromglen herrmannsfeldt <gah@ugcs.caltech.edu>
Date2015-08-05 05:43 +0000
Message-ID<mps7p4$irk$1@speranza.aioe.org>
In reply to#21645
Don Y <this@is.not.me.com> wrote:

(snip, I wrote)
>> The 7447 has nice high current 15 volt OC drivers.
>> Usual OC gates have 5V transistors.
 
> The HV output wasn't required.  The silliness was the effort
> to save a package of *gates* (or an AOI, etc.) -- at the expense
> of puzzling anyone who had to look at the circuit thereafter
> (Can you rattle off the decoding functions of any particular
> 7seg decoder, "off the top of your head"?  e.g., does 6 have a
> tail?  9?  

This one I still remember from years ago. The 7447 does not have
tails, the 74247 does.

> how are the non-decimal codes handled?  etc.  By
> contrast, some *gates* wired together would be incredibly
> obvious to damn near anyone looking at the schematic!)

-- glen

[toc] | [prev] | [next] | [standalone]


#21655

FromDon Y <this@is.not.me.com>
Date2015-08-05 00:44 -0700
Message-ID<mpsesi$1jj$1@speranza.aioe.org>
In reply to#21651
On 8/4/2015 10:43 PM, glen herrmannsfeldt wrote:
> Don Y <this@is.not.me.com> wrote:
>
> (snip, I wrote)
>>> The 7447 has nice high current 15 volt OC drivers.
>>> Usual OC gates have 5V transistors.
>
>> The HV output wasn't required.  The silliness was the effort
>> to save a package of *gates* (or an AOI, etc.) -- at the expense
>> of puzzling anyone who had to look at the circuit thereafter
>> (Can you rattle off the decoding functions of any particular
>> 7seg decoder, "off the top of your head"?  e.g., does 6 have a
>> tail?  9?
>
> This one I still remember from years ago. The 7447 does not have
> tails, the 74247 does.

Your memory is far better than mine!  That was the *one* instance where I used
a TTL 7segment decoder in my career.  The only other times were CMOS devices
(e.g., 14543, 4511, etc.) driving non-muxed LCD or PGD displays.

Any other "display interfaces" had the decoding done in software lookup
tables (i.e., direct control of each segment so you could make "special
characters")

[toc] | [prev] | [next] | [standalone]


#21657

FromClifford Heath <no.spam@please.net>
Date2015-08-05 19:14 +1000
Message-ID<Zskwx.63869$Ry5.40018@fx22.iad>
In reply to#21655
On 05/08/15 17:44, Don Y wrote:
> On 8/4/2015 10:43 PM, glen herrmannsfeldt wrote:
>> Don Y <this@is.not.me.com> wrote:
>>
>> (snip, I wrote)
>>>> The 7447 has nice high current 15 volt OC drivers.
>>>> Usual OC gates have 5V transistors.
>>
>>> The HV output wasn't required.  The silliness was the effort
>>> to save a package of *gates* (or an AOI, etc.) -- at the expense
>>> of puzzling anyone who had to look at the circuit thereafter
>>> (Can you rattle off the decoding functions of any particular
>>> 7seg decoder, "off the top of your head"?  e.g., does 6 have a
>>> tail?  9?
>>
>> This one I still remember from years ago. The 7447 does not have
>> tails, the 74247 does.
>
> Your memory is far better than mine!  That was the *one* instance where
> I used a TTL 7segment decoder in my career.

The 7447 was the first IC I ever bought, with a single digit display.
It absorbed my pocket money saved for a month, so you can imagine my
dismay when I found I'd bought a common-cathode display that wouldn't
work with the 7447 - and the supplier wouldn't take either of them back.
That was after fretting for a while about how to get 5V, when batteries 
only came in 1.5v increments. I really needed a mentor or a book.

I never did end up building the digital dice (die?) circuit I had 
designed, but I did design and build a lot of other stuff.

[toc] | [prev] | [next] | [standalone]


#21666

FromDon Y <this@is.not.me.com>
Date2015-08-05 08:04 -0700
Message-ID<mpt8kv$ka$1@speranza.aioe.org>
In reply to#21657
On 8/5/2015 2:14 AM, Clifford Heath wrote:
> On 05/08/15 17:44, Don Y wrote:
>> On 8/4/2015 10:43 PM, glen herrmannsfeldt wrote:
>>> Don Y <this@is.not.me.com> wrote:
>>>
>>> (snip, I wrote)
>>>>> The 7447 has nice high current 15 volt OC drivers.
>>>>> Usual OC gates have 5V transistors.
>>>
>>>> The HV output wasn't required.  The silliness was the effort
>>>> to save a package of *gates* (or an AOI, etc.) -- at the expense
>>>> of puzzling anyone who had to look at the circuit thereafter
>>>> (Can you rattle off the decoding functions of any particular
>>>> 7seg decoder, "off the top of your head"?  e.g., does 6 have a
>>>> tail?  9?
>>>
>>> This one I still remember from years ago. The 7447 does not have
>>> tails, the 74247 does.
>>
>> Your memory is far better than mine!  That was the *one* instance where
>> I used a TTL 7segment decoder in my career.
>
> The 7447 was the first IC I ever bought, with a single digit display.
> It absorbed my pocket money saved for a month, so you can imagine my
> dismay when I found I'd bought a common-cathode display that wouldn't
> work with the 7447 - and the supplier wouldn't take either of them back.
> That was after fretting for a while about how to get 5V, when batteries only
> came in 1.5v increments. I really needed a mentor or a book.

Mine would probably have been a `138 (ubiquitous "address decoder" for
small systems; or, `74 and `157's (DRAM controller)

> I never did end up building the digital dice (die?) circuit I had designed, but
> I did design and build a lot of other stuff.

Most of my "discrete" logic designs were specialty CPU's.  So, any "junk
logic" was typically implemented in bipolar ROMs (e.g., microcode store).

[toc] | [prev] | [next] | [standalone]


#21654

FromClifford Heath <no.spam@please.net>
Date2015-08-05 17:28 +1000
Message-ID<lViwx.77281$XZ5.25782@fx19.iad>
In reply to#21632
On 05/08/15 04:28, Tim Wescott wrote:
> On Tue, 04 Aug 2015 11:07:49 -0700, Don Y wrote:
>
>> On 8/4/2015 10:59 AM, 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.
>>
>> Do you really need to micro-optimize like this?
>
> Uh -- fun?
>
>> Why not just have the code *say* what you are trying to *do*?
>
> Where's the job security in that?

The first thing we do when we find someone has that attitude is to 
revert their clever codez, and the second one is to fire them. So in 
this case, your "job security" has a negative value.

[toc] | [prev] | [next] | [standalone]


#21629

FromPaul Rubin <no.email@nospam.invalid>
Date2015-08-04 11:13 -0700
Message-ID<877fpakjlt.fsf@jester.gateway.sonic.net>
In reply to#21625
Tim Wescott <seemywebsite@myfooter.really> writes:
> Which do you think is quicker on a PC, with the latest gnu compiler:
> if (a >= 0.0 && b < 0.0)
>>> or <<
> if (a * b <= 0)

It depends partly on the hardware.  You have to actually benchmark on
your target cpu.

[toc] | [prev] | [next] | [standalone]


#21630

From"Bill Davy" <Bill@SynectixLtd.com>
Date2015-08-04 19:19 +0100
Message-ID<d2ce2fFeg84U1@mid.individual.net>
In reply to#21625
"Tim Wescott" <seemywebsite@myfooter.really> wrote in message 
news:juKdnf5uzZr0YF3InZ2dnUU7-YOdnZ2d@giganews.com...
> 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.
>
> -- 
>
> Tim Wescott
> Wescott Design Services
> http://www.wescottdesign.com

if a==1 and b==0, first expression is false, second expression is true so 
they are not equivalent.
Border conditions are such a bother.  I could proivide a similar expresion 
which is even faster but laso not right (0, for example).
Sometimes the use of the sgn() function is even quicker.
Rules of optimsiation:
1) Never
2) Later
3) Measure 

[toc] | [prev] | [next] | [standalone]


#21636

FromTom Gardner <spamjunk@blueyonder.co.uk>
Date2015-08-04 22:18 +0100
Message-ID<4%9wx.82891$Ec3.82302@fx24.am4>
In reply to#21625
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.

Unless the answer is *critical*, it is usually better to
write clear simple code using the "best" algorithm,
and let the compiler (hopefully correctly) optimise it.
Since you ask the question, clearly you haven't determined
that this is the most important optimisation.

[toc] | [prev] | [next] | [standalone]


#21658

FromSimon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP>
Date2015-08-05 10:25 +0000
Message-ID<mpsoav$id3$1@dont-email.me>
In reply to#21636
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 :-))

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.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world

[toc] | [prev] | [next] | [standalone]


#21659

FromTom Gardner <spamjunk@blueyonder.co.uk>
Date2015-08-05 11:42 +0100
Message-ID<MMlwx.132929$cf5.32544@fx08.am4>
In reply to#21658
On 05/08/15 11: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 :-))
>
> 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". :-))

Yes indeed.

That kind of "nonsense" is one reason why the best /general purpose/
language/environment is Java. HotSpot optimises what is /actually/
executing as opposed to what the compiler can /safely guess/ what
/might/ be executing. GP = in the absence of other constraints such
as might be found in embedded systems.

HP's Dynamo C compiler from the 1990s is a remarkable demonstration
of that kind of thing:
   - take a processor X, and emulate that processor on that processor
   - take optimised CPU-bound C (Oc) running in the emulator to discover
     what code is actually executing
   - change the binary to optimise what is actually executing (Oe)
   - measure performance of original C (Oc) running in X => Px
   - measure performance of the changed binary (Oe) running in the
     emulator of X running in processor X => Pe
   - now Px = +- Pe

So, C slows down code as much as emulating a processor!
Quite Remarkable, and one reason why Java isn't as slow as
naive oldies assume.

[toc] | [prev] | [next] | [standalone]


#21661

FromAnders.Montonen@kapsi.spam.stop.fi.invalid
Date2015-08-05 11:23 +0000
Message-ID<mpsrmo$ep$1@speranza.aioe.org>
In reply to#21659
Tom Gardner <spamjunk@blueyonder.co.uk> wrote:
> HP's Dynamo C compiler from the 1990s is a remarkable demonstration
> of that kind of thing:
<snip>
Many modern C/C++ compilers (eg. GCC, Visual Studio, Clang, ICC) have 
similar features, usually called "profile guided optimization." Having 
to generate and export the execution profile however means it's not 
usually an option for smaller embedded systems.

-a

[toc] | [prev] | [next] | [standalone]


#21662

FromDavid Brown <david.brown@hesbynett.no>
Date2015-08-05 13:58 +0200
Message-ID<mpstn3$7fq$1@dont-email.me>
In reply to#21661
On 05/08/15 13:23, Anders.Montonen@kapsi.spam.stop.fi.invalid wrote:
> Tom Gardner <spamjunk@blueyonder.co.uk> wrote:
>> HP's Dynamo C compiler from the 1990s is a remarkable demonstration
>> of that kind of thing:
> <snip>
> Many modern C/C++ compilers (eg. GCC, Visual Studio, Clang, ICC) have 
> similar features, usually called "profile guided optimization." Having 
> to generate and export the execution profile however means it's not 
> usually an option for smaller embedded systems.
> 

There is an additional problem with profile-guided optimisation.  It is
based on the idea that you measure how often functions (and to a lesser
extent, loops) are executed - and thus where the optimisation effort
should be concentrated.  This plays badly with modern compiler
optimisation techniques such as inlining, function cloning, partial
inlining, hot/cold partitioning, link-time optimisation, which all blur
the concept of separate functions and the match between source-code
functions and object-code functions.

[toc] | [prev] | [next] | [standalone]


#21689

FromRobert Wessel <robertwessel2@yahoo.com>
Date2015-08-06 00:24 -0500
Message-ID<bjr5sathdqsd41i9i91qa1toce4rl2rrr3@4ax.com>
In reply to#21661
On Wed, 5 Aug 2015 11:23:06 +0000 (UTC),
Anders.Montonen@kapsi.spam.stop.fi.invalid wrote:

>Tom Gardner <spamjunk@blueyonder.co.uk> wrote:
>> HP's Dynamo C compiler from the 1990s is a remarkable demonstration
>> of that kind of thing:
><snip>
>Many modern C/C++ compilers (eg. GCC, Visual Studio, Clang, ICC) have 
>similar features, usually called "profile guided optimization." Having 
>to generate and export the execution profile however means it's not 
>usually an option for smaller embedded systems.


A fundamental difference is that PGO requires a training run, and
after that the code is static.  A more dynamic system, like Dynamo,
will rebuild the code as usage changes.  Somewhat similar to
rebuilding with PGO with a new training dataset, but on the fly.

[toc] | [prev] | [next] | [standalone]


#21660

FromDavid Brown <david.brown@hesbynett.no>
Date2015-08-05 12:59 +0200
Message-ID<mpsq7l$pi6$1@dont-email.me>
In reply to#21658
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.
> 

[toc] | [prev] | [next] | [standalone]


#21638

FromHans-Bernhard Bröker <HBBroeker@t-online.de>
Date2015-08-04 23:30 +0200
Message-ID<d2cp87Fhcd0U1@mid.dfncis.de>
In reply to#21625
Am 04.08.2015 um 19:59 schrieb Tim Wescott:
> 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)

That's rather beside the point, I'm afraid.  Those two expressions don't 
even compute the same condition, so who cares which of them might be 
quicker?

[toc] | [prev] | [next] | [standalone]


#21725

FromPhilipp Klaus Krause <pkk@spth.de>
Date2015-08-11 11:19 +0200
Message-ID<mqcemr$dfs$1@solani.org>
In reply to#21638
On 04.08.2015 23:30, Hans-Bernhard Bröker wrote:
> Am 04.08.2015 um 19:59 schrieb Tim Wescott:
>> 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)
> 
> That's rather beside the point, I'm afraid.  Those two expressions don't
> even compute the same condition, so who cares which of them might be
> quicker?

They might be equivalent for the OP. The OP might have additional
knowledge on the values of a and b.

Philipp

[toc] | [prev] | [next] | [standalone]


#21652

FromDavid Brown <david.brown@hesbynett.no>
Date2015-08-05 08:32 +0200
Message-ID<mpsajk$1oc$1@dont-email.me>
In reply to#21625
On 04/08/15 19: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.
> 

If you are looking at the general principle, rather than this particular
example (since the two versions don't do the same thing), then the
answer is ... it depends :-)

These sorts of things often depend on the code before and after the
tests, the number of tests, the hardware, the compiler, and the
optimisation flags.  Testing the sign of a floating point number is just
a single bit test - in theory, the compiler could do this by loading a
and b (or the appropriate byte from them) into integer registers,
xor'ing it, then doing a test for that single bit (assuming normal
floating point, rather than NaNs, etc.).

Code before or after this section may affect the speed - perhaps the
compiler already knows something about a and b, or can make use of parts
of the calculation at a later state.  Perhaps /you/ know something, such
as that it is likely for a to be non-negative - and by telling the
compiler about it in the conditional, you'll get the likeliest path
executed fastest.

Some processors are good at handling conditional jumps (or conditional
instructions) smoothly, and have no problem with a series of tests.
Others are better with a single multiply and a single jump.

Different compilers may handle the ordering differently.  One thing to
be sure of is to use good optimisation (typically -Os or -O2), make sure
you target the actual hardware (-march=native, if that's not the
default), and use "-ffast-math" to tell gcc not to be painfully pedantic
about IEEE rules for re-arranging and optimising floating point.

[toc] | [prev] | [next] | [standalone]


#21674

FromStefan Reuther <stefan.news@arcor.de>
Date2015-08-05 18:43 +0200
Message-ID<mptlgi.2ss.1@stefan.msgid.phost.de>
In reply to#21625
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)

I cannot get my compilers to generate anything else than two branches
for the first case, which would mean the second one is faster on average
(except if a were >= 0.0 in the vast majority of cases).

If I had to process these values in bulk, and didn't have to care for
things like NaNs, I'd probably try to play some tricks with (integer)
SIMD instructions.


  Stefan

[toc] | [prev] | [next] | [standalone]


#21675

Fromedward.ming.lee@gmail.com
Date2015-08-05 10:31 -0700
Message-ID<006ed9bc-bbaa-4b4f-b532-4c2508c36efe@googlegroups.com>
In reply to#21625
On Tuesday, August 4, 2015 at 10:59:08 AM UTC-7, 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.

I just wrote a test program.  The first statement is 10% faster than the second.  You can argue all you want, but nothing beat benchmarking.

[toc] | [prev] | [next] | [standalone]


#21678

FromHans-Bernhard Bröker <HBBroeker@t-online.de>
Date2015-08-05 20:11 +0200
Message-ID<d2f1v1F42h7U1@mid.dfncis.de>
In reply to#21675
Am 05.08.2015 um 19:31 schrieb edward.ming.lee@gmail.com:

> I just wrote a test program.  The first statement is 10% faster than
> the second.  You can argue all you want, but nothing beat
> benchmarking.

That's easy to believe, but still wrong.  Benchmarking a 
micro-optimization like that, particularly if done in any other context 
than the actual project, is clearly pointless.  _Any_ difference between 
the benchmark platform and the actual one will render the benchmark 
result useless.  A 10% difference like that can easily be inverted by 
just about any unrelated change to the surrounding source code, or any 
change to the tools and their settings.

The old truth still holds: premature optimization _is_ the root of all evil.

[toc] | [prev] | [next] | [standalone]


Page 2 of 3 — ← Prev page 1 [2] 3  Next page →

Back to top | Article view | comp.arch.embedded


csiph-web