|
![](/i/fill.gif) |
Thorsten Froehlich <tho### [at] trf de> wrote:
: It is a complete waste of time to optimize these by hand. Every compiler
: can do a much better job on these and the code stays readable on your site!
This is true, of course.
It's important to know what kind of code does the compiler generate from
certain operations so that you can concentrate on the important parts when
optimizing and forget the obsolete parts (because the compiler handles them).
For example, trying to optimize an operation where an integer variable
is multiplied/divided with an integer constant by replacing it with shifts
and or operations is a complete waste of time since the compiler will do
it itself anyways.
In some platforms it can be even slower to make all those shifts and
ors instead of letting the compiler optimize the code. That is, for example
the compiler-generated code for this:
a = b*1040;
may be in some platforms faster than the compiler-generated code for this:
a = (b<<10)|(b<<4);
because the compiler might be able to use some platform-dependant optimizations
for the multiplication which it can't do to the shifts (for example in some
platforms integer multiplication takes just 1 clock while the shifts and the
or take 3 clocks).
By the way, some times the compiler can go too far in this.
This is the case with gcc. When generating the assembler code, it will
always convert the multiplication of an integer variable and an integer
constant to shifts and ors/additions/substractions, no matter what is the
constant value.
For example something like a*123456789 generates about 10-20 assembler
operations.
One could think that after a certain amount of operations a plain integer
multplication would be faster (specially with current processors).
Go figure.
--
char*i="b[7FK@`3NB6>B:b3O6>:B:b3O6><`3:;8:6f733:>::b?7B>:>^B>C73;S1";
main(_,c,m){for(m=32;c=*i++-49;c&m?puts(""):m)for(_=(
c/4)&7;putchar(m),_--?m:(_=(1<<(c&3))-1,(m^=3)&3););} /*- Warp -*/
Post a reply to this message
|
![](/i/fill.gif) |