Re: Floating point environment



Skarmander wrote:
jacob navia wrote:

The standard assumes that there is only one floating point environment.
In all functions like fetestexcept, for instance, it is assumed that
there is only one floating point environment

Now, there is the standard, and there is Intel/Amd.

This people build a circuit where you have two floating point
units in the same machine, one for double precision
and another for extended precision (80 bits)

No. All formats (single precision, double precision, extended double precision) can be handled by the same floating-point unit. This has been true since the very first 8087.

Now, there are TWO floating point environments, one for
the 64 bit format (double precision) and another for the
80 bit format.

Again, no. You're thinking of regular x87 floating-point versus SSE. Those are different environments, but it has only tangentially to do with the format used.

??? SSE2 uses 64 bits, x87 uses 80 bits. Now you tell me that is "tangentially" important ???


It is true that internally, the x87 FP uses extended double precision rather than double precision, even though it can load and store all formats; this means calculations are actually done with more precision than is required, losing the extra bits only when the value is stored. Even so, most if not all C platforms simply use this format for their calculations, rounding afterwards. The extra precision rarely hurts (though there are cases where it is inconvenient, of course).


My implementation supports long doubles with 80 bits, that are
channeled to the FPU, and the normal double precision format, that
are channeled to the new "SSE" floating point unit.

That's where your problems come in. The SSE extensions are intended specifically for SIMD applications, not generic floating point calculations.

Excuse me but you have to account the fact that Microsoft exists, declaring that for the new version of windows the coprocessor is "legacy floating point and no longer supported"

(!!!!!!!)

ALL floating point should be now in SSE2 registers. In the first
versions of windows 64 bits, the OS did NOT save the FPU, making
its usage impossible since its contents were lost after any
context switch.

This has been softened somewhat now, but still, the X87 is considered
"LEGACY" floating point. (Even by AMD)


The regular x87 instructions are perfectly capable of
handling your floating-point needs (and are natively supported by all x86 processors from 486DX up, as opposed to SSE).

I am very aware of that, and have avoided SSE2 until now, but Microsoft declared it mandatory. Floating point arguments (float and doubles) are passed by binary API in XMM0..XMM4. You CAN'T ignore them any more.


While you can take
advantage of SSE for some floating-point calculations, it is then your responsibility to make it work.


Of course it is MY responsability to make the compiler work. Who else? I do not see your point.


You are, by the way, talking about SSE2/SSE3, not SSE. SSE only supports single precision; SSE2/SSE3 supports double precision. All versions of SSE use a status/control word separate from the main FPU, however, so they can indeed be considered a separate environment.


Exactly what worries me: there are now TWO environments in the same CPU.


The problem now arises when implementing this floating point
environment functions. Should feclearexcept clear BOTH environments?
Or should I implement feclearexcept and feclearexceptl, what would
be more rational?

If you insist on using SSE for floating point, then it's your responsibility to make things appear sane to the environment.


But this is the crucial point. By the way I AM NOT INSISTING
in using SSE2, it is Microsoft, and I have to follow them if I want it or not.


So feclearexcept() should clear the SSE exception environment if SSE instructions are going to be used; if SSE instructions will not be used it's pointless to clear it; if SSE is not supported it's impossible.


I am using BOTH environments:

SSE2 for floats and doubles,
X87 for long doubles.

More important, fetestexcept should test BOTH environments and make
and OR of the result? or what should I do there?

Again: if you use SSE instructions, it's your responsibility to make sure the right set of flags is tested. ORing should work, though.


OK, then I should simulate a single environment, where any SSE2 exceptions are ORED with the x87 exception. Is that correct?

jacob
.



Relevant Pages

  • Re: Floating point environment
    ... In all functions like fetestexcept, for instance, it is assumed that there is only one floating point environment ... one for double precision ... The regular x87 instructions are perfectly capable of handling your floating-point needs (and are natively supported by all x86 processors from 486DX up, as opposed to SSE). ... All versions of SSE use a status/control word separate from the main FPU, however, so they can indeed be considered a separate environment. ...
    (comp.std.c)
  • Re: Floating point environment
    ... In all functions like fetestexcept, for instance, it is assumed that there is only one floating point environment ... one for double precision ... the 64 bit format and another for the 80 bit format. ... Those are different environments, but it has only tangentially to do with the format used. ...
    (comp.std.c)
  • Re: Range and precision of floating-point numbers
    ... values of operations with floating operands and values subject to the ... to a format whose range and precision may be greater than required by ... this is required by the standard. ...
    (comp.std.c)
  • critical floating point incompatibility
    ... environment of the 32-bit compatibility environment of AMD64 systems ... The default setting of the x87 floating point control word on the i386 ... this value sets the precision ...
    (freebsd-hackers)
  • Floating point environment
    ... The standard assumes that there is only one floating point environment. ... one for double precision ... fetestexcept should test BOTH environments and make ...
    (comp.std.c)