Newsgroups: comp.compilers Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!mit-eddie!bloom-beacon!world!esegue!compilers-sender From: Preston Briggs Subject: Re: What is the FORTRAN for ? In-Reply-To: <1990Jul30.180439.26627@esegue.segue.boston.ma.us> Message-ID: <1990Jul30.225941.28798@esegue.segue.boston.ma.us> Reply-to: Preston Briggs Keywords: Fortran, optimize, code Sender: compilers-sender@esegue.segue.boston.ma.us Organization: Rice University, Houston References: <1990Jul25.174153.16896@ecn.purdue.edu> <164@kaos.MATH.UCLA.EDU> <4922@munnari.oz.au> Date: Mon, 30 Jul 90 22:59:41 GMT Approved: compilers@esegue.segue.boston.ma.us Herman Rubin writes: >> double nint(double x) >> { >> return ceil(x + 0.5) - (fmod(x*0.5 + 0.25, 1.0) != 0); >> } >I have not checked the code, but this points out what is wrong with the >present HLLs and that compilers cannot be expected to overcome the problem. >If this #define were used, then this block of code would be inserted wherever >this is wanted, even if there is a machine instruction which does the job. >I do not see how a compiler can recognize that the complicated body of code >can be replaced by a single instruction and make that substitution. Sometimes these substitutions can be done via peephole optimizations. It's particularly useful when the patterns are generated automatically from a machine description (as in the work of Davidson and Fraser). The example given looks sort of complex, but could easily be added by hand. The usefulness of such effort depends on the instruction set of the machine -- for a machine with quite complicated instructions, a lot of effort seems justified. >continue to crop up as long as the language primitives are restricted as >they now are. I'm up for interesting language primitives too, though perhaps for different reasons. Consider Fortran's MAX and MIN functions. If they weren't provided as functions, people would have to code them by hand, as if statements. But the optimizer would rather see them as simple functions (expressions) so that CSE elimination and loop invariant code motion can be performed. The same idea is even more important when vectorizing compilers are used. -- Preston Briggs looking for the great leap forward preston@titan.rice.edu -- Send compilers articles to compilers@esegue.segue.boston.ma.us {spdcc | ima | lotus| world}!esegue. Meta-mail to compilers-request@esegue.