Re: Floating point in kernel

From: David Wragg (
Date: Wed May 03 2000 - 16:54:01 EST

"B. James Phillippe" <> writes:
> unsigned long foo = some_other_ulong * 1.234;

It's actually possible to compile this to code that doesn't use FP
instructions. To do the trick with three instructions on x86:

  unsigned long t, junk;

  /* Do res = x * 1.234; */

  asm("mull %2"
      : "=d" (t), "=a" (junk)
      : "r" (x), "1" ((unsigned long)((1ULL << 32) * 0.234)));
  res = x + t;

The assembly is needed to get an explicit MUL instruction, which gives
a full 64-bit result in edx:eax. (A similar thing can be done without
asm using long long, but the generated code is far worse.)

However, I don't know of any version of gcc/egcs which performs this
optimization, so you get the problems with FPU use in the kernel.

David Wragg

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

This archive was generated by hypermail 2b29 : Sun May 07 2000 - 21:00:13 EST