Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | "BartC" <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| References | (4 earlier) <m5947m$i1k$1@dont-email.me> <2VYdw.15675$zz2.11112@fx06.am4> <m59rgr$rkh$1@dont-email.me> <22%dw.11896$He3.4668@fx15.am4> <m5a455$tf3$1@dont-email.me> |
| Subject | Re: harder case for optimization |
| Message-ID | <342ew.15978$WR7.12711@fx04.am4> (permalink) |
| Organization | virginmedia.com |
| Date | 2014-11-28 17:14 +0000 |
"David Brown" <david.brown@hesbynett.no> wrote in message
news:m5a455$tf3$1@dont-email.me...
> On 28/11/14 14:46, BartC wrote:
>> No, gcc -O3 is the equivalent of viewing code through rose-tinted
>> specs.
> I really don't understand your problem here.
OK, so would you approach the issues the OP is having?
If that involves finding out what is taking the most time, or experimenting
with different approaches, then gcc -O0 is a tool that will let you measure
the differences, and not produce distorted, unrealistic results.
For example, you have this sequence of code:
A;
B;
C;
Which part takes the most time? Well, you might try commenting out one
section at a time:
A;
B;
//C;
This is much faster (the same example I gave earlier), but with -O3, it
might be that B does something that is only relevant to C, so the the
compiler doesn't do B either. Or you duplicate one bit of code to see how
much slower it becomes:
A;
B;
B;
C;
(assuming this doesn't affect the working). Now again, -O3 might decide the
first B doesn't do anything useful and suppress it. Not exactly useful:
instead of concerning itself with localised optimisations, -O3 is doing much
more, but you don't know exactly what.
(BTW what is the -O0 option actually for?)
> It doesn't matter how
> "optimal" the source code is, if the generated result is the same thanks
> to the compiler's optimiser. I want to write my source code in the
> clearest way I can,
> code. If I were writing a code generator, I would want to generate the
> most convenient code using the simplest algorithms and let the C
> compiler turn it into great object code - what is the point in spending
> time and effort writing (and testing and debugging) a complex code
> generator to produce neat or elegant C code, when I could rely on the
> tried and tested optimisation from gcc?
(In my case, so that I have the satisfaction that if my code performs well,
then it will be largely thanks to my efforts than because of the C compiler.
In fact I now generate x64 code directly. This also means that if:
a = f*x+f*y;
isn't automatically optimised to a = (x+y)*f, then I would be forced to make
that change myself, which makes the code more readable *and* faster. But
using gcc -O3, there would be no incentive, as that change is done
internally; the code is just as fast, but is not as readable.)
> To take a very simple example, suppose I want a function that divides an
> integer by 13 - and I want that code to run as fast as possible. The
> simple, clear way is this:
>
> int foo(int x) { return x / 13; }
>
> Maybe I would want to allow for some future flexibility:
>
> static const int fooDiv = 13;
> int foo(int x) { return x / fooDiv; }
<snip>.
> The division is now handled by much faster instructions (a multiply and
> some shifts).
>
> It is completely and utterly pointless to spend time and effort trying
> to figure out the right C code to replace "x / 13" with a multiplication
> and shifts.
That's not what I'm getting at. Suppose I wanted to find out how fast that
routine was, or how it compares with another that does it a little
differently.
If I did something as straightforward as calling foo() twice, the -O3 will
eliminate the first call if it's not needed (I've just tried it).
It happens that sometimes you want to a measure a bit of code compiled
with -O3, or compare with something else, then simply switching to -O0 won't
work. Then it becomes harder (because you want to apply -O3 to the code
being measured, but don't want the simple test harness to be optimised out
of existence).
--
Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-27 00:42 -0800
Re: harder case for optimization "BartC" <bc@freeuk.com> - 2014-11-27 11:34 +0000
Re: harder case for optimization David Brown <david.brown@hesbynett.no> - 2014-11-27 13:29 +0100
Re: harder case for optimization Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-11-27 05:58 -0800
Re: harder case for optimization Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-11-27 06:36 -0800
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-27 12:26 -0800
Re: harder case for optimization "BartC" <bc@freeuk.com> - 2014-11-27 22:07 +0000
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-27 14:49 -0800
Re: harder case for optimization "BartC" <bc@freeuk.com> - 2014-11-28 00:05 +0000
Re: harder case for optimization David Brown <david.brown@hesbynett.no> - 2014-11-28 00:46 +0100
Re: harder case for optimization "BartC" <bc@freeuk.com> - 2014-11-28 00:55 +0000
Re: harder case for optimization David Brown <david.brown@hesbynett.no> - 2014-11-28 07:20 +0100
Re: harder case for optimization Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-11-28 00:41 -0800
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-28 01:54 -0800
Re: harder case for optimization Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-11-28 02:19 -0800
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-28 04:05 -0800
Closed captioning (Was: harder case for something or other) gazelle@shell.xmission.com (Kenny McCormack) - 2014-11-28 12:15 +0000
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-28 06:11 -0800
Re: harder case for optimization gazelle@shell.xmission.com (Kenny McCormack) - 2014-11-28 12:18 +0000
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-28 04:42 -0800
Re: harder case for optimization gazelle@shell.xmission.com (Kenny McCormack) - 2014-11-28 16:37 +0000
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-28 08:48 -0800
Re: harder case for optimization Kaz Kylheku <kaz@kylheku.com> - 2014-11-28 16:51 +0000
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-28 10:38 -0800
Re: harder case for optimization David Brown <david.brown@hesbynett.no> - 2014-11-28 11:34 +0100
Re: harder case for optimization "BartC" <bc@freeuk.com> - 2014-11-28 11:21 +0000
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-28 04:23 -0800
Re: harder case for optimization David Brown <david.brown@hesbynett.no> - 2014-11-28 13:58 +0100
Re: harder case for optimization "BartC" <bc@freeuk.com> - 2014-11-28 13:46 +0000
Re: harder case for optimization David Brown <david.brown@hesbynett.no> - 2014-11-28 16:25 +0100
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-28 08:18 -0800
Re: harder case for optimization David Brown <david.brown@hesbynett.no> - 2014-11-28 20:17 +0100
Re: harder case for optimization Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-11-28 08:54 -0800
Re: harder case for optimization David Brown <david.brown@hesbynett.no> - 2014-11-28 20:22 +0100
Re: harder case for optimization Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-11-28 11:29 -0800
Re: harder case for optimization Kaz Kylheku <kaz@kylheku.com> - 2014-11-28 19:51 +0000
Re: harder case for optimization David Brown <david.brown@hesbynett.no> - 2014-11-28 20:58 +0100
Re: harder case for optimization Melzzzzz <mel@zzzzz.com> - 2014-11-28 21:03 +0100
Re: harder case for optimization Kaz Kylheku <kaz@kylheku.com> - 2014-11-28 20:11 +0000
Re: harder case for optimization Melzzzzz <mel@zzzzz.com> - 2014-11-28 21:31 +0100
Re: harder case for optimization "BartC" <bc@freeuk.com> - 2014-11-28 20:06 +0000
Re: harder case for optimization "BartC" <bc@freeuk.com> - 2014-11-28 17:14 +0000
Re: harder case for optimization David Brown <david.brown@hesbynett.no> - 2014-11-28 20:54 +0100
Re: harder case for optimization "BartC" <bc@freeuk.com> - 2014-11-28 20:16 +0000
Re: harder case for optimization David Brown <david.brown@hesbynett.no> - 2014-11-28 21:56 +0100
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-27 23:37 -0800
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-27 23:54 -0800
Re: harder case for optimization BartC <bc@freeuk.com> - 2014-11-28 11:01 +0000
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-28 23:52 -0800
Re: harder case for optimization Morris Dovey <mrdovey@iedu.com> - 2014-11-29 02:03 -0600
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-29 00:38 -0800
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-29 03:12 -0800
Re: harder case for optimization BartC <bc@freeuk.com> - 2014-11-29 12:09 +0000
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-29 04:18 -0800
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-29 05:22 -0800
Re: harder case for optimization BartC <bc@freeuk.com> - 2014-11-29 16:58 +0000
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-29 09:35 -0800
Re: harder case for optimization Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-11-29 10:55 -0800
Re: harder case for optimization BartC <bc@freeuk.com> - 2014-11-29 21:00 +0000
Re: harder case for optimization Ian Collins <ian-news@hotmail.com> - 2014-11-30 11:25 +1300
Re: harder case for optimization BartC <bc@freeuk.com> - 2014-11-29 22:56 +0000
Re: harder case for optimization Ian Collins <ian-news@hotmail.com> - 2014-11-30 12:00 +1300
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-29 16:01 -0800
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-29 16:21 -0800
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-29 16:52 -0800
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-11-29 17:14 -0800
Re: harder case for optimization glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-11-30 00:20 +0000
Re: harder case for optimization Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-11-29 16:43 -0800
Re: harder case for optimization Kaz Kylheku <kaz@kylheku.com> - 2014-11-29 17:29 +0000
Re: harder case for optimization fir <profesor.fir@gmail.com> - 2014-12-05 02:12 -0800
csiph-web