Hi Uros!

Thanks for lookin at this. I am a real newcomer to 387, and it took me a long 
time perusing the Intel doc, as well as glibc sources, to come up with that. 
The “reference” implementation of these FPU functions, the one I am confident 
in, is that in config/fpu-glibc.h: i.e., the functions in config/fpu-i387.h 
should have the same effect that config/fpu-glibc.h on i386/x86_64 hardware.

I’ll reply to your comments, but in some cases I was not sure exactly what you 
were saying… thanks for your help, and patience!


> @@ -136,16 +165,54 @@ set_fpu (void)
>       __asm__ __volatile__ ("%vstmxcsr\t%0" : "=m" (cw_sse));
> 
>       /* The SSE exception masks are shifted by 7 bits.  */
> -      cw_sse |= _FPU_MASK_ALL << 7;
> -      cw_sse &= ~(excepts << 7);
> -
> -      /* Clear stalled exception flags.  */
> -      cw_sse &= ~_FPU_EX_ALL;
> 
> You have to clear stalled SSE exceptions here. Their flags are in LSB
> bits, so their position is different than the position of exception
> mask bits in the control word.

So, if I get you right, I should restore the "cw_sse &= ~_FPU_EX_ALL”, which I 
had mistakenly removed.
But I’m looking at glibc-2.18/sysdeps/x86_64/fpu/feenablxcpt.c and 
fedisblxcpt.c, and it doesn’t seem to be done there.


> +  __asm__ __volatile__ ("fnstenv\t%0" : "=m" (*&temp));
> [...]
> +  __asm__ __volatile__ ("fldenv\t%0" : : "m" (*&temp));
> 
> Why do you need "*&" here?

I don’t.


> fldenv will also trigger exceptions with set flags on the next x87 FP insn ...
> 
> +    __asm__ __volatile__ ("%vstmxcsr\t%0" : "=m" (cw_sse));
> +
> +    cw_sse &= ~exc_clr;
> +    cw_sse |= exc_set;
> +
> +    __asm__ __volatile__ ("%vldmxcsr\t%0" : : "m" (cw_sse));
> 
> ... and ldmxcsr won't trigger exceptions, neither with SSE insn.
> Please see Intel documentation on FP exceptions.

This code should be equivalent to glibc’s:

  feclearexcept (exc_clr);
  feraiseexcept (exc_set);

So yes, raising an exception is the except action. I’ve attached a new version 
of config/fpu-387.h, along with the glibc version (fpu-glibc.h). I’d be glad if 
you could review it.

Thanks a lot!
FX


Attachment: fpu-387.h
Description: Binary data

Attachment: fpu-glibc.h
Description: Binary data

Reply via email to