Subject: Re: Floating point calculation in the kernel
To: Peter Bex <Peter.Bex@student.kun.nl>
From: Steve Woodford <scw@netbsd.org>
List: tech-kern
Date: 02/24/2005 12:15:21
On Thursday 24 February 2005 11:08, Peter Bex wrote:
> On Thu, Feb 24, 2005 at 12:00:37PM +0100, Martin Husemann wrote:
> > That would be too weak - it's forbidden, unless you play special
> > arch dependend tricks to allow it. Some archs do that for their
> > memcpy/memset implementations. You will need to explicitly save and
> > restore fpu state before and after your code and enable/disable the
> > fpu.
>
> Meaning it's completely disallowed?

Correct. Many NetBSD architectures don't save/restore FPU state across 
context switches as doing so can be an expensive operation. Instead, 
where the hardware supports it, the save/restore is deferred until a 
process actually tries to use the FPU.

The kernel disables the FPU for all processes except the one which 'owns' 
it. If another process executes an FP instruction, the resulting 'FPU 
disabled' exception is used by the kernel to save FPU state for the 
current owner, then restore the new owner's FPU state before retrying 
the FP instruction with the FPU enabled.

If you try to use the FPU in the kernel, you run the risk of silently 
trashing a process' FPU state or causing a kernel-mode 'FPU disabled' 
exception (which will result in a panic).

Your options are to re-code your neural net using fixed-point arithmetic, 
or to investigate compiling it with -msoft-float.

Cheers, Steve