Since C generates assembly code, would you get a higher performance by writing the code in assembly instead of C? Can you give me some general examples when assembly would be more beneficial in terms of speed?
Since C generates assembly code, would you get a higher performance by writing the code in assembly instead of C? Can you give me some general examples when assembly would be more beneficial in terms of speed?
Yes, you can do that, but you really need to be reasoably skiled in assembler programming to achieve BETTER than the compiler. If we look at the example given with a for-loop by andinue(sp?) earlier, I wouldn't be able to improve on what gcc generated with -O2.
It is also non-portable, harder to write (because one average line of C turns into 2-3 lines of assembler) harder to maintain, and less error checking.
Many compilers support inline assembler, but you can't compile gcc-inline assembler with MS compiler or vice-versa, so you are tied to a particular compiler vendor.
All these factors make it so that you really need to think carefully before you start using assembler instead of C.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Moreover - using profiler and some optimizing technincs - you can actually optimize the assembler output of your compiler still writing code in C
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Well, is there any AT&T to Intel syntax converter? :P
Btw, I'm a little bit confusing using AT&T on GCC.