This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [fortran, patch] Add Fortran 2003 IEEE intrinsic modules


On Sat, Nov 23, 2013 at 4:30 PM, FX <fxcoudert@gmail.com> wrote:

> 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.

The idea was that since control word is changed, status word should be
cleared. But since stalled flags won't raise an exception, it actually
doesn't matter, although it looks nicer in a debugger. However, if you
remove SSE clear, you should also remove fnclex from x87 code.


>> 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.

Hm, I don't see the feraiseexcept part in your patch. As said in other
reply, you can use the code from libatomic/config/x86/fenv.h. This
source also handles FE_DENORM.

Uros.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]