Fixed-Point OS

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
PavelChekov
Member
Member
Posts: 113
Joined: Mon Sep 21, 2020 9:51 am
Location: Aboard the Enterprise

Fixed-Point OS

Post 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
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Fixed-Point OS

Post 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.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

Re: Fixed-Point OS

Post 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.
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: Fixed-Point OS

Post 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.
User avatar
zaval
Member
Member
Posts: 656
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: Fixed-Point OS

Post 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:
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
User avatar
PavelChekov
Member
Member
Posts: 113
Joined: Mon Sep 21, 2020 9:51 am
Location: Aboard the Enterprise

Re: Fixed-Point OS

Post 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.
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!
Ethin
Member
Member
Posts: 625
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Re: Fixed-Point OS

Post 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).
rdos
Member
Member
Posts: 3276
Joined: Wed Oct 01, 2008 1:55 pm

Re: Fixed-Point OS

Post 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.
rdos
Member
Member
Posts: 3276
Joined: Wed Oct 01, 2008 1:55 pm

Re: Fixed-Point OS

Post 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.
Post Reply