Simulation of MIPS recip and rsqrt instructions
Andrew Cagney
ac131313@redhat.com
Tue Nov 26 12:12:00 GMT 2002
> The mips simulator uses sim_fpu_inv() as a reciprocal function
> but all it really does is negate the exponent. So we end up
> calculating 1 / (x*2^y) as x*2^-y.
>
> Test case:
>
> #include <stdio.h>
>
> int
> main ()
> {
> double d;
> float f;
>
> asm ("recip.s %0,%1" : "=f" (f) : "f" (20.0f));
> printf ("%g\n", f);
>
> asm ("recip.d %0,%1" : "=f" (d) : "f" (10.0));
> printf ("%g\n", d);
>
> asm ("rsqrt.s %0,%1" : "=f" (f) : "f" (0.01f));
> printf ("%g\n", f);
>
> asm ("rsqrt.d %0,%1" : "=f" (d) : "f" (25.0));
> printf ("%g\n", d);
>
> return 0;
> }
Can this test case be written in strict assembler so that it can be
added to the simulator testsuite?
> The simulator says:
>
> 0.078125
> 0.15625
> 25.6
> 0.3125
>
> while a vr5500 says:
>
> 0.05
> 0.1
> 10
> 0.2
>
> Unfortunately, sim_fpu_inv isn't commented and cp1.c seems to be
> its only active user. Which should change?
>
> FWIW, the patch below fixes the test case. Please install if OK.
Hmm, I guess:
1 / (x * 2^y) == (1/x) * (1/(2^y)) == (1/x) * (2^(-y))
and
1/x != x
so I think the inv() function should be fixed - that suggests it is
pretty broken.
Does GLIBC's softfloat code contain an efficient INV implementation that
could be used?
Andrew
More information about the Gdb-patches
mailing list