Page 1 of 1

How often do you find yourself using floating point data typ

Posted: Mon Jul 13, 2009 9:37 pm
by tkahn6
I haven't had to use a float or double yet. Does this come up in kernel space development?

Thanks!

Re: How often do you find yourself using floating point data typ

Posted: Mon Jul 13, 2009 9:42 pm
by Firestryke31
I've used it for color depth conversion (i.e. 24bit -> 16bit) but that was a while ago. It was more for my bootloader, though, and I don't really use it anymore. At the moment I can't think of anything kernel-specific (i.e. not something more suited to a driver or user-space library) that requires a float, though.

Re: How often do you find yourself using floating point data typ

Posted: Mon Jul 13, 2009 11:00 pm
by earlz
I just about never use floats unless it's part of some programming course in school... (Java's best friend is floats apparently)

The only real time I've used floats in any program I made as a hobby was for a little tool to calculate from my clock out stubs how much my check should be.. I would have been perfectly happy hacking around a fixed point though..

Re: How often do you find yourself using floating point data typ

Posted: Mon Jul 13, 2009 11:16 pm
by 01000101
I have float/double/long double and SSE support built-in to my kernel (if supported). I primarily use doubles and long doubles.

I use them quite often though, I perform a lot of averaging and want to make sure I maintain precision. I also have coded in double/long double printing support into my printf. There's not a lot that needs to be set up to support FPU ops, see the FPU wiki article and just make sure you use FSAVE and such when you use it in a multi-tasking environment.

Re: How often do you find yourself using floating point data typ

Posted: Tue Jul 14, 2009 10:53 am
by cyr1x
The only time I used floats(libgmp) was in a high-precision PI-calculation-programm.
I never used the standard floats (like in C).

Re: How often do you find yourself using floating point data typ

Posted: Tue Jul 14, 2009 11:03 am
by mathematician
tkahn6 wrote:I haven't had to use a float or double yet. Does this come up in kernel space development?

Thanks!
Personally I seldom use a float no matter what the type of development. Unless you are writing a program which makes explicit use of mathematics (or at least arithmetic), I wouldn't worry about it too much.

Re: How often do you find yourself using floating point data typ

Posted: Tue Jul 14, 2009 8:15 pm
by Brendan
Hi,
tkahn6 wrote:I haven't had to use a float or double yet. Does this come up in kernel space development?
I've never used floating point in any kernel, partly because my kernels are designed to work on CPUs that don't have FPU, and partly because I don't save FPU/MMX/SSE state during task switches unless it's necessary (where using FPU in the kernel makes this necessary, and therefore increases the cost of task switches). I can't think of anything that I would have wanted to use FPU for either - the closest would have been calculating timer counts (e.g. "PIT_count = (3579545 / 3) / desired_frequency") but this has to be an integer anyway, so there's no reason to use float/double for extra accuracy.

I never really used signed integers either. Almost everything uses unsigned integers, because almost everything is table indexes or addresses or bitfields.

FPU would have made one part of my boot code easier (GTF calculations for video modes), and I've been using floats/doubles a lot lately for bitmap image processing, but a micro-kernel doesn't do anything like that.

@01000101: Not sure why you'd need floats/doubles for averaging (or what you use averaging for). If the data is integers (which IMHO is likely), then you can keep track of the sum and the count with integers without any precision loss, and find the average with one division (where an integer answer can be accurate to within 0.5 without using fixed point).

Note: When I want "round to nearest" integer division, I do something like:

Code: Select all

    mov eax, <dividend_low_32bits>
    mov edx, <dividend_high_32bits>
    mov ecx, <divisor>
    div ecx           ;eax = quotient, edx = remainder
    dec ecx           ;ecx = divisor - 1
    add edx,edx       ;edx = remainder * 2
    cmp ecx,edx       ;Set carry flag if (remainder * 2) > (divisor - 1)
    adc eax,0

Cheers,

Brendan

Re: How often do you find yourself using floating point data typ

Posted: Wed Jul 15, 2009 3:03 am
by i586coder
Brendan wrote:Hi,
tkahn6 wrote:I haven't had to use a float or double yet. Does this come up in kernel space development?
I've never used floating point in any kernel, partly because my kernels are designed to work on CPUs that don't have FPU,
Me too. and i think FPU operations not needed in kernel :lol: ,if so please tell me where :roll:

CheerS,
a.T.d

Re: How often do you find yourself using floating point data typ

Posted: Wed Jul 15, 2009 3:27 am
by Solar
Brendan wrote:...I don't save FPU/MMX/SSE state during task switches unless it's necessary (where using FPU in the kernel makes this necessary, and therefore increases the cost of task switches).
Important point, here. Saving / restoring FPU state is a costly operation, which can easily be avoided because you don't exactly need floats for kernel-space code AFAICT.