
8 Oct
2009
8 Oct
'09
2:49 p.m.
Dear Joakim Tjernlund,
In message OF26FEA2CB.36E102EE-ONC1257649.0031301D-C1257649.0031EDAF@transmode.se you wrote:
How about:
cl = 0; for (i=0; i<sizeof(long); ++i) { cl <<= 8; cl |= c & 0xff; }
GCC optimization will do the rest...
If you want gcc to optimise well, make it easy to do so. Changing the for loop into: for (i=sizeof(long); i; --i) makes it easier for gcc and more likely to result in optimal code.
Did you actually _check_ the code? (I did).
It does not matter. The generated code is identical.
What matters might be compiler options - "-Os" generates a small loop, and "-O3" and higher will unroll the loop, which is way more code.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
When you die, the first thing you lose is your life. The next thing
is the illusions. - Terry Pratchett, _Pyramids_