Re: floating-point abuse in 2.1.113

Richard B. Johnson (root@chaos.analogic.com)
Fri, 7 Aug 1998 09:43:19 -0400 (EDT)


On 6 Aug 1998, Andi Kleen wrote:

> Mikael Pettersson <mikpe@csd.uu.se> writes:
>
> > 4. The C language doesn't guarantee this behaviour. While empirical
> > evidence suggests that gcc will evaluate FP constant expressions
> > at compile-time, this is really dodgey and beyond specs.
> > By Murphy's law, this _will_ break at some point.
>
> But Linux kernel not allowing FP is also beyond specs (the C standard
> requires floating point - it is not a optional feature). The spec for
> the C language used in the Linux kernel is the language understood by
> gcc, and it is quite clear that gcc knows how to do it.
>
> -Andi

But the linux kernel could not be written entirely in C. In fact
as the 'C' language matures, the physical machine is deliberately
hidden to improve portability.

Gcc provides a lot of non 'C' capability such as in-line assembly. This
allows it to be the language of choice for the kernel. The fact that
'C' allows (or requires) floating-point is moot.

A constraint imposed by the kernel, to improve speed, results in state of
the FP unit being undefined within the kernel itself. This is not a 'C'
constraint. It is a 'system' constraint.

To use the FP unit within the kernel, you would have to prefix
each FP operation with "FINIT". You would also need to make
sure that the FP operation was atomic. Such operations are not
part of any 'C' standard.

Of course, one could do a complete FSAVE/FRSTOR for every context-switch
and every path into/out-from the kernel. It takes 143 clocks to save
and 120 clocks to restore the FPU state in protected mode (i486). This
does not count the clocks necessary to set up some addressing of where
the information is saved.

FYI, FPU operations within the kernel, with very few exceptions are
not fatal. You are just not guaranteed to get the right answer.
One of the exceptions, previously discussed, occurs with interruptable
FP operations where the FPU's internal state is corrupted by otherwise
legal operations attempted to be performed, before an interruptable
operation has completed. This will generate a FPU fault that is
not restartable because it becomes a double fault.

Cheers,
Dick Johnson
***** FILE SYSTEM MODIFIED *****
Penguin : Linux version 2.1.113 on an i586 machine (66.15 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html