From: Richard Sandiford <rsandifo@redhat.com>
To: gdb-patches@sources.redhat.com
Subject: Simulation of MIPS recip and rsqrt instructions
Date: Tue, 26 Nov 2002 11:41:00 -0000 [thread overview]
Message-ID: <m3smxom7q9.fsf@localhost.localdomain> (raw)
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;
}
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.
Richard
* cp1.c (inner_sqrt): Use sim_fpu_div instead of sim_fpu_inv.
(fpu_inv): New function.
(fp_recip): Use it.
Index: sim/mips/cp1.c
===================================================================
RCS file: /cvs/src/src/sim/mips/cp1.c,v
retrieving revision 1.19
diff -u -d -p -F^[(a-zA-Z0-9_^#] -r1.19 cp1.c
--- sim/mips/cp1.c 29 Jul 2002 23:17:10 -0000 1.19
+++ sim/mips/cp1.c 26 Nov 2002 19:13:24 -0000
@@ -900,7 +900,7 @@ inner_rsqrt(unsigned64 op1,
status |= sim_fpu_sqrt (&ans, &wop1);
status |= sim_fpu_round_32 (&ans, status, round);
wop1 = ans;
- op_status = sim_fpu_inv (&ans, &wop1);
+ op_status = sim_fpu_div (&ans, &sim_fpu_one, &wop1);
op_status |= sim_fpu_round_32 (&ans, round, denorm);
sim_fpu_to32 (&res, &ans);
temp = res;
@@ -914,7 +914,7 @@ inner_rsqrt(unsigned64 op1,
status |= sim_fpu_sqrt (&ans, &wop1);
status |= sim_fpu_round_64 (&ans, round, denorm);
wop1 = ans;
- op_status = sim_fpu_inv (&ans, &wop1);
+ op_status = sim_fpu_div (&ans, &sim_fpu_one, &wop1);
op_status |= sim_fpu_round_64 (&ans, round, denorm);
sim_fpu_to64 (&res, &ans);
temp = res;
@@ -1027,13 +1027,19 @@ fp_div(sim_cpu *cpu,
return fp_binary(cpu, cia, &sim_fpu_div, op1, op2, fmt);
}
+static int
+fpu_inv(sim_fpu *f, const sim_fpu *l)
+{
+ return sim_fpu_div (f, &sim_fpu_one, l);
+}
+
unsigned64
fp_recip(sim_cpu *cpu,
address_word cia,
unsigned64 op,
FP_formats fmt)
{
- return fp_unary(cpu, cia, &sim_fpu_inv, op, fmt);
+ return fp_unary(cpu, cia, &fpu_inv, op, fmt);
}
unsigned64
next reply other threads:[~2002-11-26 19:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-26 11:41 Richard Sandiford [this message]
2002-11-26 12:12 ` Andrew Cagney
2002-11-26 12:38 ` Richard Sandiford
[not found] ` <mailpost.1038339722.6479@news-sj1-1>
2002-11-26 12:42 ` cgd
2002-11-27 0:12 ` Richard Sandiford
[not found] ` <mailpost.1038384740.26359@news-sj1-1>
2002-11-27 17:33 ` cgd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3smxom7q9.fsf@localhost.localdomain \
--to=rsandifo@redhat.com \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox