[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What about _FPU_IEEE?

From: Andreas Jaeger
Subject: Re: What about _FPU_IEEE?
Date: Wed, 18 Jul 2001 19:13:15 +0200
User-agent: Gnus/5.090004 (Oort Gnus v0.04) XEmacs/21.4 (Academic Rigor)

"Richard B. Kreckel" <address@hidden> writes:

> On Tue, 17 Jul 2001, Andreas Jaeger wrote:
>> > Err, I need to manipulate the FPU control register, at least on i386 and
>> > m68k.  <fenv.h> does not seem to be appropiate.  I would be happy to be
>> > proven wrong, though...
>> For what purpose do you need to manipulate it?  <fenv.h> is a hardware
>> independend way to manipulate it but it might not work exactly in your
>> situation.  Unfortunatly I don't know enough details about your problem,
> Sorry, but after banging ISO/IEC 9899:1999 section 7.6 against my
> forhead several times I am still confused.
> I want to force the FPU to enter IEEE mode at initialization time of a
> library.  That means I do not want it to generate a SIGFPE when

That's the default at startup.
> somebody divides by zero or such and I want it to obey to certain
> rounding modes.  The former is probably done by a call to

Round to nearest is default.

> feholdexcept() and the latter by a call to fesetround().  Writing to
> __fpu_control from <fpu_control.h>, as intended in my first email,
> didn't affect rounding anyways, AFAICT.

It does - depending on the CPU.

> The problem is that I need to link -lm for these, something that is
> usually not needed by the library.  So I want to write a configure
> test to see if the FPU is in a reasonable mode at program startup, if
> not I have to bite the bullet and add `-lm' to my LDFLAGS and call
> the above mentioned routines at library initialization.
> How can I test whether they are set up by the system at runtime?
> Like this?
>       fenv_t save_env1, save_env2;
>       int result;
>       /* clear the status flags, since feholdexcept may alter them */
>       feclearexcept(FE_ALL_EXCEPT);
>       /* get the current floating point environment */
>       fegetenv(&save_env1);
>       /* force FPU into non-stop mode, if available */
>       result = feholdexcept(&save_env2);
>       if (result) {
>               printf("non-stop mode could not be installed  :-(\n");
>       } else {
>               printf("non-stop mode was successfully installed  :-)\n");
>       }
>       if (memcmp(&save_env1,&save_env2,sizeof(fenv_t))) {
>               printf("we must set the default explicitly  :-(\n");
>       } else {
>               printf("the default seems to have been fine  :-)\n");
>       }
> I see no other way since lacking standardization fenv_t should be
> regarded as rather opaque.
> I would love flames of the kind "dude, you are totally confused"
> together with a better suggestion.  :-)

Check the glibc sources file math/test-fenv.c, I hope it gives you
some ideas.

 Andreas Jaeger
  SuSE Labs address@hidden
   private address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]