Re: Floating point in kernel

From: David Wragg (dpw@doc.ic.ac.uk)
Date: Sun May 07 2000 - 07:48:37 EST


Marc Lehmann <pcg@goof.com> writes:
> On Wed, May 03, 2000 at 09:54:01PM +0000,
> David Wragg <dpw@doc.ic.ac.uk> wrote:
> > It's actually possible to compile this to code that doesn't use FP
> > instructions. To do the trick with three instructions on x86:
> >
> > However, I don't know of any version of gcc/egcs which performs this
> > optimization
>
> A C compiler couldn't do this transformation since your code gives
> different results (and would thus be incorrect).

You're right, it was completely broken. There are some restricted
cases where a single MUL is sufficient, but that wasn't one of them
(and even in those cases a shift is also needed).

Two MULs are needed to do it correctly:

      /* Do res = x * 1.234; */
      asm("mull %3\n\t"
          "movl %%edx, %1\n\t"
          "movl %4, %%eax\n\t"
          "mull %3\n\t"
          "addl %1, %%eax\n\t"
          "adcl %3, %%edx"
          : "=&d" (res), "=&r" (junk), "=&a" (junk2)
          : "r" (x), "i" (0x3BE76C8B), "2" (0x43958106));

David Wragg

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



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