lkml.org 
[lkml]   [2001]   [Mar]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: RFC: changing precision control setting in initial FPU context
From
Date
"Adam J. Richter" <adam@yggdrasil.com> writes:
>
> IEEE-754 floating point is available under glibc-based systems,
> including most current GNU/Linux distributions, by linking with -lieee.
> Your example program produces the "9 10" result you wanted when linked
> this way, even when compiled with -O2

No, you've got it backwards. The "9 10" result is the *wrong* result.
IEEE 64-bit arithmetic should give the result "10 10". Also, I can't
duplicate your outcome. I see no difference linking with "-lieee"
versus linking without it, at least under glibc-2.1.3:

$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.2/specs
gcc version 2.95.2 20000220 (Debian GNU/Linux)
$ cat modified.c
#include <stdio.h>
#include <fpu_control.h>
int main()
{
int a = 10;
fpu_control_t foo;
_FPU_GETCW(foo);
printf("%04x %d %d\n",
foo,
(int)( a*.3 + a*.7), /* first expression */
(int)(10*.3 + 10*.7)); /* second expression */
return 0;
}
$ gcc modified.c && ./a.out
037f 9 10
$ gcc -O2 modified.c && ./a.out
037f 10 10
$ gcc modified.c -lieee && ./a.out
037f 9 10
$ gcc -O2 modified.c -lieee && ./a.out
037f 10 10
$

As you can see, linking with "ieee" has no effect on the control word
setting or the results. Perhaps this has changed post-glibc 2.1.3?
Looking at the 2.1.3 code, it appears that all "ieee" does is set a
variable that's referenced in the math library innards. It has no
effect on startup code right now.

> When not linked with "-lieee", Linux personality ELF
> x86 binaries start with Precision Control set to 3, just because that
> is how the x86 fninit instruction sets it.

Yes. I know. In fact, the "fninit" instruction is executed in the
kernel's "init_fpu()" when the first FPU instruction is executed by
the program. I just think the hardware default happens to be a bad
default on a system where most floating-point software is GCC-compiled
with GCC's 64-bit doubles (and its 64-bit clean but 80-bit dirty
floating point optimizations), so I'm proposing adding an instruction
to "init_fpu()" to change the default hardware control word.

> In general, I think most real uses of floating point are for "fast and
> sloppy" purposes, and programs that want to use floating point and
> care about exact reproducibility will link with "-lieee".

However, this doesn't seem to work. Nor does "-ffloat-store".

Kevin <buhr@stat.wisc.edu>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:29    [W:0.041 / U:0.044 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site