From: | conway@mundook.cs.mu.OZ.AU (Thomas Charles CONWAY) |
Newsgroups: | comp.lang.scheme,comp.compilers |
Date: | 22 May 1997 22:22:39 -0400 |
Organization: | Comp Sci, University of Melbourne |
References: | 97-05-183 97-05-197 |
Keywords: | C, assembler |
hbaker@netcom.com (Henry Baker) writes:
>BTW, the 'inlining' capabilities of the C compilers I tried were
>pretty miserable, but this information is now >5 years old, so I don't
>know if the situation has improved.
A student in our department used Mercury to implement his graphics
project (a simple rendering engine).
By far the most costly part of the inner loop was calculating the area
of a triangle projected onto some plane. The code used several 3d
vector operations, followed by a big fat arithmetic expression.
When he wrote it, the performance wasn't great, so I had a look at the
generated code. It had three important defects:
- it needed cross module inlining for the vector operations
- it was creating unnecessary intermediate vector structures
- the value-numbering pass was not eliminating common subexpressions
that it should have
So I filed a bug report and set about fixing the problems. By the
time Fergus got to the bug report Zoltan and I had fixed the last two
problems (the next release will support the first). He looked at the
generated code, and couldn't see the fault - the code was compiled in
to a great long string of floating-point arithmetic, with all the
common subexpressions elminated. Since I had filed a bug report, he
figured there must have been a reason, so he wrote an equivalent piece
of C code (all in one module) which passed and returned structures,
just as the Mercury code did. He tried several C compilers - even
with `const' in all the right places (etc), the compiler didn't do any
inlining, and created the intermediate structures even though it
should have been painfully obvious to do so.
I think the conventional wisdom that C is great for allowing the
programmer to write optimized code, but not so great for clever
compilation of "high-level" code is still true.
Thomas
--
Thomas Conway conway@cs.mu.oz.au
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.