/Teaching/Operating Systems/Tutorials/Floating Point Unit (FPU)

Floating Point Unit (FPU)

The FPU registers are a special case on x86. The amount of data that has to be copied on every thread switch to update the FPU status is huge compared to the other general purpose registers.

Luckily the number of programs that actually use the FPU is small so almost all of the modern operating systems use a special trick to handle the FPU registers. Instead of copying them on every thread switch one remembers which thread last used the FPU and upon a thread switch the FPU is switched to a special mode. In this mode the FPU will trigger a hardware exception on the next attempt to use it. If such an exception is thrown the operating system has to copy the data, but if only one thread uses the FPU such an exception will never need to be thrown and thus the FPU registers never have to be copied.


One problem / restriction however raises due to this: Kernel mode threads must not access the FPU. This is no problem since on all sane operating systems this is not allowed anyway.