Re: Are f.p. manipulation functions only used in initialization?



"James Van Buskirk" <not_valid@xxxxxxxxxxx> writes:

Setting the rounding of floating-point operations to less than the
default 80 bits can speed some programs by 2% or more. Note that some
mathematical libraries assume that extended precision (80 bit)
floating-point operations are enabled by default; routines in such
libraries could suffer significant loss of accuracy, typically through
so-called "catastrophic cancellation", when this option is used to set
the precision to less than extended precision."

Notably, on GNU/Linux (i.e. GNU glibc on Linux/x86)
/usr/include/fpu_control.h defines

#define _FPU_GETCW(cw) __asm__ __volatile__ ("fnstcw %0" : "=m" (*&cw))
#define _FPU_SETCW(cw) __asm__ __volatile__ ("fldcw %0" : : "m" (*&cw))

and

/* precision control */
#define _FPU_EXTENDED 0x300 /*libm requires double extended precision. */
#define _FPU_DOUBLE 0x200
#define _FPU_SINGLE 0x0

The comment next to _FPU_EXTENDED should be written in a bold,
blinking, red font. You will screw up all of the libm routines (such
as cos, sin, exp, log) if you change the FPU precision. Since Fortran
intrinsics are usually (always?) implemented in terms of libm
routines, you will threfore screw up the corresponding intrinsics.
About the only reason to change the FPU precision is if you are
writing your own libm, or software floating point (such as some of the
arbitrary precision work done by David H. Bailey and Yozo Hida), or
something similar.

C:\gfortran\james\archpi>test_status
4000C90FDAA22168C000
4000C90FDAA22168C000
027F
4000C90FDAA22168C235
4000C90FDAA22168C236
037F

So you can see that gfortran isn't setting precision control to b'11'
even with the -mpc80 switch in effect so that real(10) arithmetic
isn't working until I set the x87 control word by hand.

I think what is happening here is an OS dependency. It must be that
gfortran/Win32 is linking to a Win32 math library that depends on
having the FPU in double precision, not double extended precision.
You might check to see what happens to some of the trigonometric
intrinsics after you diddle the FPU mode.

So perhaps the double extended precision can't work on Win32 because
either the FPU is in double extended precision and the math library is
borken, or the FPU is in single precision and real*10 is borken.

Chip

--
Charles M. "Chip" Coldwell
"Turn on, log in, tune out"
GPG Key ID: 852E052F
GPG Key Fingerprint: 77E5 2B51 4907 F08A 7E92 DE80 AFA9 9A8F 852E 052F
.



Relevant Pages

  • Re: About the accuarcy of SSE calculations
    ... > changed by libraries. ... It is true that a library could change the FPU control word, ... could either increase or decrease precision. ...
    (comp.lang.asm.x86)
  • Re: GPSMAP 60Cx or 76Cx?
    ... IEEE double precision). ... Anyway, for maximum precision you still need to jump through some hoops to keep more intermediate bits around: Either you can use the "easy" solution taken by x86 cpus which is to work internally with 16 extra bits, i.e. extended precision has 16-bit sign+exponent and 64 bits of mantissa, or you have to fake it by splitting the input into two parts which together represents the actual value. ... Anyway, as might be obvious by now, this has been sort of a hobby of mine since my high school days, and I've written several extended and/or arbitrary precision fp libraries. ... other in a fairly tight track and if there is multipath from one SV ...
    (sci.geo.satellite-nav)
  • Re: double to int conversion yields strange results
    ... giving me two different values for the int. ... the question raised is not about the precision of the ... is done in extended precision. ... It is the conversion to 'double' before the conversion to 'int' that ...
    (comp.lang.c)
  • Re: Who uses clapack?
    ... Use of traditional BLAS interposes a mandatory memory save ... > the sqrtin extended precision, but it is not forced to truncate ... > do a simple dot product to compute the vector norm, ...
    (sci.math.num-analysis)
  • Re: extended double precision: looking for a small C library
    ... full libraries like MPFR. ... just basic arithmetics over the Complex in 'extended' precison as C code? ... Your notion of extended precision may be just ...
    (sci.math.num-analysis)