Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between hard and soft floating point numbers?

When I compile C code with my cross toolchain, the linker prints pages of warnings saying that my executable uses hard floats but my libc uses soft floats. What's the difference?

like image 669
Evan Kroske Avatar asked Jul 23 '10 19:07

Evan Kroske


People also ask

What does soft float mean?

adj. 1 (of an egg) boiled for a short time so that the yolk is still soft.

What is hard FPU?

hard. The hard option enables full hardware floating-point support. The compiler generates floating-point instructions and uses the floating-point ABI. Floating-point function arguments are passed directly into FPU registers.

How many floating point numbers are there?

For any given value of the exponent, there are [latex] 2^{24} = 16777216[/latex] possible numbers that can be represented.

What is floating point data type?

The floating-point data type is a family of data types that act alike and differ only in the size of their domains (the allowable values). The floating-point family of data types represents number values with fractional parts. They are technically stored as two integer values: a mantissa and an exponent.


2 Answers

Hard floats use an on-chip floating point unit. Soft floats emulate one in software. The difference is speed. It's strange to see both used on the same target architecture, since the chip either has an FPU or doesn't. You can enable soft floating point in GCC with -msoft-float. You may want to recompile your libc to use hardware floating point if you use it.

like image 138
nmichaels Avatar answered Sep 19 '22 06:09

nmichaels


There are three ways to do floating point arithmetic:

  • Use float instructions if your CPU has a FPU. (fast)
  • Have your compiler translate floating point arithmetic to integer arithmetic. (slow)
  • Use float instructions and a CPU with no FPU. Your CPU will generate a exception (Reserved Instruction, Unimplemented Instruction or similar), and if your OS kernel includes a floating point emulator it will emulate those instructions (slowest).
like image 34
ninjalj Avatar answered Sep 19 '22 06:09

ninjalj