G
glen herrmannsfeldt
So, the upshot from this:
* Trying to optimize the code by hand is likely to have unexpected
effects on modern compilers. In general, writing it in the most
straightforward way increases the chance that it will be optimized
well.
* Trying to optimize for speed by hand is basically impossible nowadays;
the compiler has a better idea than you of what will run quickly.
* It's still possible to optimize for size by hand and beat the compiler,
if you know of an optimization that it doesn't know, or are just
better at allocating registers. (This last advantage only really
matters on x86; other systems tend to have less insane register
allocation requirements.)
This has been true for many compilers, at least since the OS/360
Fortran H compiler in the 1970's.
On many systems that are some strange assembler instructions that the
compiler doesn't know about. More likely to be smaller than faster,
though.
* Trying to generate specific assembler from specific C code is very
difficult, or near impossible, to do in such a way that the original
C code is platform-agnostic. (I have done this before, but it basically
involves trying lots of different C as compiler input until it
generates the output that you want.)
And the answer to the original question is "I wouldn't". I think the
cleanest solution involves goto, and when the cleanest solution uses
goto, it's probably not the sort of problem you want to solve.
-- glen