Re: What is the FORTRAN for ?

Bart Massey <>
Wed, 01 Aug 90 01:12:53 GMT

          From comp.compilers

Related articles
Re: What is the FORTRAN for ? (1990-07-30)
Re: What is the FORTRAN for ? (Preston Briggs) (1990-07-30)
Re: What is the FORTRAN for ? (1990-07-31)
Re: What is the FORTRAN for ? (Bart Massey) (1990-08-01)
| List of all articles for this month |

Newsgroups: comp.compilers,comp.lang.misc
From: Bart Massey <>
Followup-To: comp.compilers
Keywords: Fortran, optimize
Organization: Tektronix TV Measurement Systems, Beaverton OR
References: <> <164@kaos.MATH.UCLA.EDU> <> <>
Date: Wed, 01 Aug 90 01:12:53 GMT

In article <> (Herman Rubin) writes:
> This appeared in an article posted to comp.lang.fortran, and I believe it
> illustrates a point about the weaknesses of HLLs (The poster was referring
> to C at this point) and compilers.
> In article <>, (Richard O'Keefe) writes:
> > double nint(double x)
> > {
> > return ceil(x + 0.5) - (fmod(x*0.5 + 0.25, 1.0) != 0);
> > }
> >
> > is all it takes.]
> 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. ...

I tend to like the GCC approach to all this a great deal. For the above
program, the nint() primitive above might be coded something like

inline double const nint(double const x)
#ifdef frobozzco
double result;
return result;
#elif foobarco
double result;
return result;
return ceil(x + 0.5) - (fmod(x*0.5 + 0.25, 1.0) != 0);

Note that the above code generates a single inline machine instruction on
machines which support it, and otherwise generates the best sequence of
inline machine instructions it can. This is as close as I've ever seen to a
"user-extensible code generator", and it seems to solve a large class of such
problems very well, at least IMHO, by shifting the burden of code generation
in specialized applications from the compiler designer to the application
programmer, the latter presumably having a better idea of what he/she wants
or needs.

Note also that in G++, one can even declare the standard C operators to be
implemented by such inline asm functions, and thus get, for example, maximum
efficiency from a C++ complex number package on a machine which supports
complex numbers directly in the FPU.

I've seen Mr. Rubin post on this topic before, and I would humbly suggest
that, if he would be so generous, he could benefit the computing community
greatly by generating a GCC-compatible header file containing a bunch of
these inline asm functions for the complicated numerical operations he feels
are important to optimize well, and for a number of common CPUs. I know
that I, for one, would be very interested in the results of such an exercise.
For a similar exercise in complex FPU insn utilization, at least for a
single processor, see Matthew Self's "math-68881.h", distributed with GCC.

I look at GCC's "inline asm function" feature as a way to extend the semantic
primitives of the language, in a syntactically compatible way. So far, it
seems to me to have worked pretty well.

Bart Massey

Post a followup to this message

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