Page 1 of 1

Fixed-Point OS

Posted: Sat Oct 02, 2021 10:35 am
by PavelChekov
Pretty much every complete OS I've seen initializes floating point units, but would it be possible to make an OS that uses fixed-point arithmetic?

Thanks

Re: Fixed-Point OS

Posted: Sat Oct 02, 2021 11:20 am
by Korona
Fixed point and floating point calculations often have different purposes. Even mainstream OSes use fixed point calculations for some purposes. For example, fixed point calculations can be useful when dealing with running times of processes (which are typically in a range between some microseconds to a few months; for example, POSIX' struct timespec is essentially a fixed point representation for times), while floating point calculations are useful if accuracy is needed over a range that spans many orders of magnitude.

Re: Fixed-Point OS

Posted: Sat Oct 02, 2021 1:58 pm
by alexfru
Old x86 PCs didn't always have an x87 chip installed and many compilers of the time came with floating point emulation in their libraries (that is, either x87 instructions were never generated and instead replaced by calls to the library to perform addition, multiplication, etc or they were intercepted (on 80286+ or 80386+)).

Your OS itself may do something similar. However, if it needs to support floating point in user programs, it needs to be able to save and restore the FPU context (nowadays, it's pretty fat: many long AVX registers and some control/status regs as well). It can, however, intercept FPU instructions as well.

Re: Fixed-Point OS

Posted: Sat Oct 02, 2021 3:05 pm
by Octocontrabass
Yes, it's possible to make an entire OS that doesn't use any floating-point arithmetic.

Why don't you want to initialize the FPU? Even if you don't use the FPU anywhere in your OS, you might want to initialize it for usermode programs.

Re: Fixed-Point OS

Posted: Sat Oct 02, 2021 4:18 pm
by zaval
Octocontrabass wrote: Why don't you want to initialize the FPU? Even if you don't use the FPU anywhere in your OS, you might want to initialize it for usermode programs.
he just likes to create threads about pretty much everything, he doesn't want to do his own re/search on. :mrgreen:

Re: Fixed-Point OS

Posted: Sun Oct 03, 2021 11:19 am
by PavelChekov
I am still going to use floating-point in my OS, I was just curious. Some microcontrollers don't have floating point support.

Re: Fixed-Point OS

Posted: Mon Oct 04, 2021 9:05 am
by Ethin
In that case, you'd emulate floating-point operations.

For x86, you should probably just initialize SSE/AVX (I'm pretty sure that most compilers will nowadays translate FP operations to SSE/AVX operations and not x87 FP ops).

Re: Fixed-Point OS

Posted: Tue Oct 05, 2021 9:45 am
by rdos
I don't see much of a reason why an OS would need to use floating point. Mine certainly doesn't. Floating point is mostly for user programs.

Re: Fixed-Point OS

Posted: Tue Oct 05, 2021 9:49 am
by rdos
Ethin wrote:In that case, you'd emulate floating-point operations.

For x86, you should probably just initialize SSE/AVX (I'm pretty sure that most compilers will nowadays translate FP operations to SSE/AVX operations and not x87 FP ops).
Regardless if that is true or not, the OS will still need to save x87 and support the use of x87 FP ops. There is no guarantee that an application will not use x87 FP ops.

My design only supports x87 FP ops, and I only save that state, which is not currently a problem since OpenWatcom doesn't use SSE or AVX, and it is the only supported compiler. Makes for faster FP state saving too.