How to avoid FPU when providing floating point numbers?

Well, this is not at all a matter of optimization.

I am writing (at the moment) a simple Linux kernel module in which I need to find the average value for some positions. These positions are stored as floating point variables (i.e. float). (I am the author of all this, so I can change it, but I would prefer to keep the swimming limit and not interfere with it if I can avoid it).

Now these position values ​​are stored (or at least used) in the kernel just for storage. One user application writes this data (via shared memory (I use RTAI, so yes, I have shared memory between the kernel and user spaces)), while others read from it. I believe that reading and writing from float variables will not use FPU, therefore it is safe.

Safely, I mean avoiding FPUs in the kernel , not to mention that some systems may not even have FPUs. I am not going to use kernel_fpu_begin / end , as this is likely to disrupt the real work of my tasks.

Now, in my kernel module, I really don't need much accuracy (since the positions are averaged anyway), but I needed to do this to 0.001. My question is: how can I transfer a floating point number to an integer (1000 times the original) without using FPU?

I thought about manually extracting the number from the bitwise bit pattern, but I'm not sure if this is a good idea, because I'm not sure how endianness affects it, or even if floating points are standard in all architectures.

+3
source share
4 answers

If you want to tell gcc to use the floating point program library, obviously there is a switch for this, although it may not be turnkey in the standard environment:

x86 linux

, , linux kernel -msoft-float:

http://www.linuxsmiths.com/blog/?p=253

, @PaulR . API, , , , - , - .

+4

SoftFloat float32_to_int32, , ( IEEE 754 ).

, - ( ), , , . .

+5

, , API- , , . - , kernelspace.

, float , , , IEEE 754, endianness . , , Linux. , 32- . 1024, 1000, ; . ( 0-22), "" 23, , ( 127) 23 , 23. , 32 ( C , ) ( , ).

, , , , . , 1, , 2 ^ 23, ((float_bits & 0x7fffff)|0x800000) , , - .

+2

. (, ) .

1/1000, x * 1000 .

0

All Articles