Re: Intel floating-point initialization

Xavier Leroy (
Tue, 19 May 1998 10:14:52 +0200

In 2.1.102, floating-point initialization in arch/i386/kernel/process.c,
function copy_thread, has been changed to the following:

* This tried to copy the FPU state, but I wonder whether we really
* want this at all. It is probably nicer to just have a newly started
* process start with a clean slate wrt the fpu. - Linus
#if 1
current->used_math = 0;
current->flags &= ~PF_USEDFPU;
if (last_task_used_math == current)
__asm__("clts ; fnsave %0 ; frstor %0":"=m" (p->tss.i387));

I beg to disagree with Linus. The parent process/thread may have set
the FPU control word to a non-default value (i.e. change rounding
modes, etc). The programmer legitimely expects the child process to
inherit those settings (just like it inherits pretty much everything
else from its parent).

So, it is not correct to reinitialize the FPU in the new process.
At least the FPU control word should be copied from the parent process.
Let's just copy the whole FPU state as the original code meant to do,
and fix it so that it works correctly on an SMP machine as well:

#ifdef __SMP__
if (current->flags & PF_USEDFPU)
if (last_task_used_math == current)
__asm__("clts ; fnsave %0 ; frstor %0":"=m" (p->tss.i387));

- Xavier Leroy

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to