ECN No Name Newsletter: September, 1989

The ECN No Name Newsletter is no longer being published. This is an archived issue.

[previous article] [next article]

Sun Inline Floating Point

Dwight McKay

You may recall a January 1988 article in the No Name Newsletter regarding floating point performance on Suns. Under the previous release of SunOS (3.5) the best thing you could do was to use the "-f68881" flag when compiling your programs. This instructed the compiler to make calls to code using the Motorola MC68881 Floating Point Co-processor which is installed in all ECN Sun3 workstations.

Under the current release of SunOS (4.0) you can go a bit further by actually putting MC68881 floating point instructions directly into your program. This technique, called "inlining", saves a considerable amount of time over the normal method of calling a floating point routine. I tested this method with a discrete fourier transform program I use for benchmarking. I got the following results on an idle Sun 3/50:

% cc -f68881 -O -o no-inline dft.c -lm
% time no-inline < testdata
935.5u 0.5s 15:39 99% 0+128k 1+0io 2pf+0w

% cc -O -o inline dft.c /usr/lib/f68881/libm.il
% time inline < testdata
547.4u 0.3s 9:09 99% 0+120k 1+0io 1pf+0w

The first three of lines of the above example shows how I compiled my dft program and the time it took to run. This is using the "-f68881" method and it runs in about 15 minutes.

The second set of lines show how simple it is to compile the program using the "inline" technique. Note the speed increase! With just a recompilation, my dft program now runs in only 9 minutes!

The inline file "/usr/lib/f68881/libm.il" is not a library, but a set of assembly language routines and replacement rules. These are used by an optimization pass of the compiler to replace function calls to math routines in your program. These assembly language routines are inserted in the middle of your program replacing the function calls, hence the name, "inline".

Inline routines are faster for two reasons. First, they avoid the overhead of making a function call, saving several instructions each time they are used. Second, and most importantly, they are hand-assembled, making direct use of the floating point co-processor in the most efficient manner possible. Inline "files" are also available for use with FORTRAN programs. You use this in much the same way: % f77 -O -o inline myprogram.f /usr/lib/f68881/libm.il As you would expect, there are a couple of things you need to watch out for when using the "inline" facility: All the components of your program must be compiled using the "inline" files. You can't mix and match pieces which have been "inlined" with those which have not. If you have a program which consists of three pieces, you'll need to compile it like so: cc -c -O part1.c /usr/lib/f68881/libm.il cc -c -O part2.c /usr/lib/f68881/libm.il cc -c -O part3.c /usr/lib/f68881/libm.il cc -O -o prog part1.o part2.o part3.o /usr/lib/f68881/libm.il The inline files are NOT libraries. You cannot compile them separately. The compiler looks for the ".il" extension to the file name and passes the inline file onto the appropriate utility. SunOS (4.0) provides a complete set of these "inline" libraries for both C and FORTRAN using both the MC68881 and the Sun4 FPU. This table summarizes the available inline files: Machine FPU Type Library Sun3 MC68881 /usr/lib/f68881/libm.il Sun4 Sun FPU /usr/lib/libm.il A complete list of the inline facilities provided by SunOS (4.0) and further directions for using inline files can be found in Appendix G of the Sun Floating Point Programmer's Guide. You'll also find information on how you can build your own inline files for routines which are commonly used in your own programs. Be sure you have the SunOS (4.0) release of the manual.


webmaster@ecn.purdue.edu
Last modified: Wednesday, 29-Oct-97 16:41:11 EST

[HTML Check] HTML