Re: Compiling to C (where C is used as misspelled assembly)

conway@mundook.cs.mu.OZ.AU (Thomas Charles CONWAY)
22 May 1997 22:22:39 -0400

          From comp.compilers

Related articles
[7 earlier articles]
Re: Compiling to C (where C is used as misspelled assembly) dwight@pentasoft.com (Dwight VandenBerghe) (1997-05-16)
Re: Compiling to C (where C is used as misspelled assembly) conway@mundook.cs.mu.OZ.AU (1997-05-17)
Re: Compiling to C (where C is used as misspelled assembly) fjh@mundook.cs.mu.OZ.AU (1997-05-17)
Re: Compiling to C (where C is used as misspelled assembly) monnier+/news/comp/compilers@tequila.cs.yale.edu (Stefan Monnier) (1997-05-17)
Re: Compiling to C (where C is used as misspelled assembly) cdg@nullstone.com (Christopher Glaeser) (1997-05-17)
Re: Compiling to C (where C is used as misspelled assembly) conway@mundook.cs.mu.OZ.AU (1997-05-22)
Re: Compiling to C (where C is used as misspelled assembly) conway@mundook.cs.mu.OZ.AU (1997-05-22)
Re: Compiling to C (where C is used as misspelled assembly) Dave@occl-cam.demon.co.uk (Dave Lloyd) (1997-05-22)
Re: Compiling to C (where C is used as misspelled assembly) partain@dcs.gla.ac.uk (Will Partain) (1997-05-22)
Re: Compiling to C (where C is used as misspelled assembly) fjh@mundook.cs.mu.OZ.AU (1997-05-25)
Re: Compiling to C (where C is used as misspelled assembly) fjh@mundook.cs.mu.OZ.AU (1997-05-25)
| List of all articles for this month |

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
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.