Mail Archives: djgpp-workers/2004/02/17/09:59:59
Kbwms AT aol DOT com wrote:
>In a message dated 2/16/2004 2:33:43 PM Eastern Standard Time,
>rudd AT cyberoptics DOT com writes:
>
>>f you want assembler, just compile the above fragment with the -S,
>>-O2, and -fomit-frame-pointer options and you will get assembler output,
>>which, for this particular function, is as good as can be done by hand.
>>
>This prompts me to ask, "What's the point of going to assembler when the C
>code is just as good?"
>
One advantage of assembler is confidence that the code won't change if
the compiler changes, or if some well-intentioned programmer makes some
seemingly-innocuous changes to the code. For instance, there is no
guarantee that the compiler won't round the product x*y to double
precision before doing the addition; in fact, some argue that the
product of two doubles is a double, and must be rounded to be a double.
I tried to get around that by writing
return (double) ((long double) x * (long double) y) + (long double z))
but I found that extra code was generated: the result was stored to the
stack and then popped off into the coprocessor again, which is wasteful
and unnecessary.
If you aren't very comfortable with your assembler skills, a good way to
get the control over the code that assembler provides is to compile the
C code to assembler, once, such that you get good code; then check in
that assembler. This will prevent the code from changing.
-Eric Rudd
- Raw text -