qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paul Brook <paul@codesourcery.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [patch] vfp register ordering
Date: Sat, 26 Mar 2005 21:38:54 +0000	[thread overview]
Message-ID: <200503262138.54778.paul@codesourcery.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 257 bytes --]

In most VFP implementations the registers are defined such that single 
precision registers s0 and s1 map onto the low and high halves of double 
precision register d0.

The attached patch modifies the qemu implementation to be consistent with 
this.

Paul

[-- Attachment #2: patch.qemu_vfp_s0 --]
[-- Type: text/x-diff, Size: 3546 bytes --]

Index: target-arm/cpu.h
===================================================================
RCS file: /cvsroot/qemu/qemu/target-arm/cpu.h,v
retrieving revision 1.8
diff -u -p -r1.8 cpu.h
--- target-arm/cpu.h	13 Mar 2005 18:50:12 -0000	1.8
+++ target-arm/cpu.h	26 Mar 2005 21:27:45 -0000
@@ -35,9 +35,9 @@
    precision respectively.
    Doing runtime conversions is tricky because VFP registers may contain
    integer values (eg. as the result of a FTOSI instruction).
-   A double precision register load/store must also load/store the
-   corresponding single precision pair, although it is undefined how
-   these overlap.  */
+   s<2n> maps to the least significant half of d<n>
+   s<2n+1> maps to the most significant half of d<n>
+ */
 
 typedef struct CPUARMState {
     uint32_t regs[16];
@@ -71,10 +71,7 @@ typedef struct CPUARMState {
                                       memory was written */
     /* VFP coprocessor state.  */
     struct {
-        union {
-            float32 s[32];
-            float64 d[16];
-        } regs;
+        float64 regs[16];
 
         /* We store these fpcsr fields separately for convenience.  */
         int vec_len;
Index: target-arm/translate.c
===================================================================
RCS file: /cvsroot/qemu/qemu/target-arm/translate.c,v
retrieving revision 1.18
diff -u -p -r1.18 translate.c
--- target-arm/translate.c	22 Feb 2005 19:27:29 -0000	1.18
+++ target-arm/translate.c	26 Mar 2005 21:27:45 -0000
@@ -385,28 +385,41 @@ VFP_OP(st)
 
 #undef VFP_OP
 
+static inline long
+vfp_reg_offset (int dp, int reg)
+{
+    if (dp)
+        return offsetof(CPUARMState, vfp.regs[reg]);
+    else if (reg & 1) {
+        return offsetof(CPUARMState, vfp.regs[reg >> 1])
+          + offsetof(CPU_DoubleU, l.upper);
+    } else {
+        return offsetof(CPUARMState, vfp.regs[reg >> 1])
+          + offsetof(CPU_DoubleU, l.lower);
+    }
+}
 static inline void gen_mov_F0_vreg(int dp, int reg)
 {
     if (dp)
-        gen_op_vfp_getreg_F0d(offsetof(CPUARMState, vfp.regs.d[reg]));
+        gen_op_vfp_getreg_F0d(vfp_reg_offset(dp, reg));
     else
-        gen_op_vfp_getreg_F0s(offsetof(CPUARMState, vfp.regs.s[reg]));
+        gen_op_vfp_getreg_F0s(vfp_reg_offset(dp, reg));
 }
 
 static inline void gen_mov_F1_vreg(int dp, int reg)
 {
     if (dp)
-        gen_op_vfp_getreg_F1d(offsetof(CPUARMState, vfp.regs.d[reg]));
+        gen_op_vfp_getreg_F1d(vfp_reg_offset(dp, reg));
     else
-        gen_op_vfp_getreg_F1s(offsetof(CPUARMState, vfp.regs.s[reg]));
+        gen_op_vfp_getreg_F1s(vfp_reg_offset(dp, reg));
 }
 
 static inline void gen_mov_vreg_F0(int dp, int reg)
 {
     if (dp)
-        gen_op_vfp_setreg_F0d(offsetof(CPUARMState, vfp.regs.d[reg]));
+        gen_op_vfp_setreg_F0d(vfp_reg_offset(dp, reg));
     else
-        gen_op_vfp_setreg_F0s(offsetof(CPUARMState, vfp.regs.s[reg]));
+        gen_op_vfp_setreg_F0s(vfp_reg_offset(dp, reg));
 }
 
 /* Disassemble a VFP instruction.  Returns nonzero if an error occured
@@ -2120,9 +2133,9 @@ void cpu_dump_state(CPUState *env, FILE 
             env->cpsr & (1 << 28) ? 'V' : '-');
 
     for (i = 0; i < 16; i++) {
-        s0.s = env->vfp.regs.s[i * 2];
-        s1.s = env->vfp.regs.s[i * 2 + 1];
-        d.d = env->vfp.regs.d[i];
+        d.d = env->vfp.regs[i];
+        s0.i = d.l.lower;
+        s1.i = d.l.upper;
         cpu_fprintf(f, "s%02d=%08x(%8f) s%02d=%08x(%8f) d%02d=%08x%08x(%8f)\n",
                     i * 2, (int)s0.i, s0.s,
                     i * 2 + 1, (int)s0.i, s0.s,

                 reply	other threads:[~2005-03-26 21:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=200503262138.54778.paul@codesourcery.com \
    --to=paul@codesourcery.com \
    --cc=qemu-devel@nongnu.org \
    /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;
as well as URLs for NNTP newsgroup(s).