Subject: Re: CCL:Linux/x86 compiler question

From: "Armin M. Sobhani" <[email-masked]>
Date: Mon, 01 Apr 2002 19:23:45 +0430

On Friday, 29 March 2002, Joe Leonard wrote:
>I've been trying to develop numerically-intensive code on
>an x86/Linux box (RedHat) after years of working on SGI's.
>To date, I've found that the double-precision floating-point
>performance of gcc isn't quite as good as IRIX C, and I
>wonder whether it's the compiler, the chipset or both...
>
>Has anybody tried different compilers with things like GAMESS
>or Amber?  Has there been noticeable improvement with these
>or similar codes?
>
>Are there alternate chipset/compiler Linux's which I should
>be looking at?

The matter that you have raised about the performance of double-precision 
math on x86 platform is not only a compiler related thing but also 
architecture dependent. Traditionally, floating point performance of RISC 
chips (as you have mentioned about SGI's Iris) is better than CISC 
counterparts. Nevertheless, there are some workarounds to increase floating 
point performance of x86 platform. But some history lessons (or better to 
say terminology) first:

When Intel planned to introduce a floating point coprocessor for their new 
8086 microprocessor, named 8087 FPU, they actually introduced three 
floating point formats: single precision (32 bits: 24 bits significand, 8 
bits exponent), double precision (64 bits: 53 sig., 11 exp.), and extended 
precision (80 bits: 64 sig., 15 exp, 1 sign). The single and double 
precision formats corresponded to C's float and double types or FORTRAN's 
real and double precision types. But the important thing is that on the x87 
FPUs and the 80486 CPU, all computations are done using the extended 
precision form which is rather slow. Whenever you load a single or double 
precision value, the FPU automatically converts it to an extended precision 
value. Likewise, when you store a single or double precision value to 
memory, the FPU automatically rounds the value down to the appropriate size 
before storing it. However, when designing the Pentium CPU, Intel 
redesigned the built-in floating point unit to better compete with RISC 
chips. Most RISC chips support a native 64 bit double precision format 
which is faster than Intel's extended precision format. Therefore, Intel 
provided native 64 bit operations on the Pentium to better compete against 
the RISC chips. So by changing precision control field of x87 FPU Control 
Word on the Pentium and latter chips (PII, PIII, P4 ...), you can choose 
between 24, 53 or 64 bits of precision for floating point operations.

That's exactly where the compiler can play an important role: while default 
precision of FPU is 64 bits (extended double-precision), optimizing 
compilers on Wintel platform like MS Visual C++ and Intel C/C++ and Fortran 
compilers use 53 bits (double-precision) for floating point calculation in 
order to increase the speed. I am not sure about this but I think gcc 
doesn't switch to 53 bits mode and that's why its double-precision floating 
point performance is rather low.

Considering above mentioned matters, it's clear that using a right compiler 
can do the trick, but which compiler? Intel C/C++ and  Fortran line of 
optimizing compilers for x86 and Itanium architectures are definitely worth 
a try. You can download the latest non-commercial version of both compilers 
(i.e. V5.0) for RedHat Linux 6.2 and 7.1 from Intel's web site 
(http://developer.intel.com/software/products/compilers/) free of charge 
but without any support. I have successfully installed them on both RedHat 
7.2 and Mandrake 8.0 but with a minor change to installation script for the 
later case. Both compilers can produce optimized code for PIII, P4 and also 
MMX, SSE and SSE2 technologies on x86 platform. You can use the -Qpcn 
compiler option to enable floating-point significand precision control as 
follows:

         -Qpc32  24 bits (single precision)
         -Qpc64  53 bits (double precision)    <------- default
         -Qpc80  64 bits (extended precision)

Good luck,

Armin

p-----__---_________----____----------------------------------------q
|    /  \ /  _   _  \  / ____\ Armin M. Sobhani, PharmD, PhD        |
|   /    \\  \\  \\  \/\ \___/_ Assitant Prof., Pharmacology Dept.  |
|  /  /\  \\  \\  \\  \ \_____ \ Iran University of Medical Sciences|
| (   ___  \\  \\  \\  \/____/\ \ mailto:[email-masked]           |
|( \__\_/\__\\__\\__\\__\/\_____/ Tel: +98 (21) 805 2265, Fax: ~64  |
| \/__/ \/__//__//__//__/\/____/ P.O.Box: 14155-6183, Tehran, IRAN  |
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
|  Once you understand the universe at the atomic level everything  |
|  else is easy.                               -Richard P. Feynman  |
b-------------------------------------------------------------------d