X86: Fix x87 floating point stack register indexing.
authorGabe Black <gblack@eecs.umich.edu>
Wed, 3 Oct 2007 05:57:33 +0000 (22:57 -0700)
committerGabe Black <gblack@eecs.umich.edu>
Wed, 3 Oct 2007 05:57:33 +0000 (22:57 -0700)
--HG--
extra : convert_revision : b515ec20cbfc50b38aa7da6cf4d465acf9054c08

src/arch/x86/floatregs.hh
src/arch/x86/insts/static_inst.cc
src/arch/x86/isa/insts/x87/data_transfer_and_conversion/load_or_store_floating_point.py
src/arch/x86/isa/microasm.isa
src/arch/x86/isa_traits.hh
src/arch/x86/regfile.cc

index 30846ec0067297a357e5288df56153b2eb577fd8..dc9867c4209d9344f21365f4302d9d3265d837a9 100644 (file)
@@ -166,7 +166,7 @@ namespace X86ISA
     static inline FloatRegIndex
     FLOATREG_STACK(int index, int top)
     {
-        return (FloatRegIndex)(NUM_FLOATREGS + ((top - index + 8) % 8));
+        return (FloatRegIndex)(NUM_FLOATREGS + ((top + index + 8) % 8));
     }
 };
 
index 4f6ec5390a12dd532948d12c30b879610c7919e0..510295157b87f4d54478f15a92b146e14c495584 100644 (file)
@@ -198,13 +198,18 @@ namespace X86ISA
                 return;
             }
             fpindex -= NumMMXRegs;
-            if(fpindex < NumXMMRegs) {
+            if(fpindex < NumXMMRegs * 2) {
                 ccprintf(os, "%%xmm%d_%s", fpindex / 2,
                         (fpindex % 2) ? "high": "low");
                 return;
             }
-            fpindex -= NumXMMRegs;
-            ccprintf(os, "%%ufp%d", fpindex);
+            fpindex -= NumXMMRegs * 2;
+            if(fpindex < NumMicroFpRegs) {
+                ccprintf(os, "%%ufp%d", fpindex);
+                return;
+            }
+            fpindex -= NumMicroFpRegs;
+            ccprintf(os, "%%st(%d)", fpindex);
         } else {
             switch (reg - Ctrl_Base_DepTag) {
               default:
index 6d56ac3bd41d14d2619ee1d2147de0c72c5b81c3..2a4c3f0ede1119b6d54b02191762ba5863109f29 100644 (file)
 microcode = '''
 def macroop FLD_M {
     ldfp ufp1, seg, sib, disp
-    movfp st(1), ufp1, spm=-1
+    movfp st(-1), ufp1, spm=-1
 };
 
 def macroop FLD_P {
     rdip t7
     ldfp ufp1, seg, riprel, disp
-    movfp st(1), ufp1, spm=-1
+    movfp st(-1), ufp1, spm=-1
 };
 
 def macroop FST_M {
index e961cc63cd8a7e6968ae9a250aa5bde16b0cf1c0..c8bc36b6967491a02397d5c1162f6ced29cb2179 100644 (file)
@@ -137,7 +137,7 @@ let {{
     assembler.symbols["label"] = labeler
 
     def stack_index(index):
-        return "(NUM_FLOATREGS + (%s))" % index
+        return "(NUM_FLOATREGS + (((%s) + 8) %% 8))" % index
 
     assembler.symbols["st"] = stack_index
 
index e698138362ae995c1c22fa38068f8d9c043b1ff6..6e8cac94a2ec6053310821fdb7b147f48f463121 100644 (file)
@@ -90,7 +90,9 @@ namespace X86ISA
             //mmx/x87 registers
             8 +
             //xmm registers
-            16 +
+            16 * 2 +
+            //The microcode fp registers
+            8 +
             //The indices that are mapped over the fp stack
             8
     };
index 889f2f5cd3cb53d18c7f62f57475e9b85af7c57c..c27ab08ba47113a252961092366651a43dc57de0 100644 (file)
@@ -221,7 +221,7 @@ int X86ISA::flattenIntIndex(ThreadContext * tc, int reg)
 
 int X86ISA::flattenFloatIndex(ThreadContext * tc, int reg)
 {
-    if (reg > NUM_FLOATREGS) {
+    if (reg >= NUM_FLOATREGS) {
         int top = tc->readMiscRegNoEffect(MISCREG_X87_TOP);
         reg = FLOATREG_STACK(reg - NUM_FLOATREGS, top);
     }