shithub: mc

Download patch

ref: 95fc77c94bec1b7e1d3df3abd6706bec795225e0
parent: e6348f2c9c194b15960dab8695ddc1f250655ebe
author: Ori Bernstein <[email protected]>
date: Thu Sep 26 07:08:31 EDT 2013

More support for FP operations.

--- a/6/asm.h
+++ b/6/asm.h
@@ -222,5 +222,6 @@
 int stacktype(Type *t);
 int floattype(Type *t);
 int stacknode(Node *n);
+int floatnode(Node *n);
 void breakhere();
 void dumpasm(Isel *s, FILE *fd);
--- a/6/insns.def
+++ b/6/insns.def
@@ -20,7 +20,7 @@
 
 Insn(Inone,     "BAD_INSN",                     Use(), Def())
 /* Note, the mov instruction is specified in an overly general manner. */
-Insn(Imov,      "\tmov%t %x,%x\n",              Use(.l={1}),                    Def(.l={2}))
+Insn(Imov,      "\tmov%t %x,%x\n",             Use(.l={1}),                    Def(.l={2}))
 Insn(Imovz,     "\tmovz%1t%2t %x,%x\n",         Use(.l={1}),                    Def(.l={2}))
 Insn(Imovs,     "\tmovs%1t%2t %x,%x\n",         Use(.l={1}),                    Def(.l={2}))
 Insn(Irepmovsb, "\trep movsb\n",                Use(.r={Rrcx,Rrsi,Rrdi}),       Def())
@@ -43,8 +43,8 @@
 Insn(Isar,      "\tshr%2t %u,%r\n",             Use(.l={1,2}),                  Def(.l={2}))
 Insn(Ishr,      "\tshr%2t %u,%r\n",             Use(.l={1,2}),                  Def(.l={2}))
 
-Insn(Itest,     "\ttest%t %x,%r\n",             Use(.l={1,2}),                  Def(.l={2}))
-Insn(Icmp,      "\tcmp%t  %x,%r\n",             Use(.l={1,2}),                  Def(.l={2}))
+Insn(Itest,     "\ttest%t %x,%r\n",             Use(.l={1,2}),                  Def(.l={}))
+Insn(Icmp,      "\tcmp%t  %x,%r\n",             Use(.l={1,2}),                  Def(.l={}))
 
 Insn(Ipush,     "\tpush%t %r\n",                Use(.l={1}),                    Def())
 Insn(Ipop,      "\tpop%t %r\n",                 Use(.l={1}),                    Def())
@@ -58,8 +58,11 @@
 Insn(Isetge,    "\tsetge %v\n",                 Use(),  Def(.l={1}))
 
 /* fp specific instructions */
-Insn(Icvttsd2si, "\tcvttsd2si%2t %x,%r\n",         Use(.l={1}),    Def(.l={2}))
-Insn(Icvttsi2sd, "\tcvttsd2si%2t %x,%r\n",         Use(.l={1}),    Def(.l={2}))
+Insn(Icvttsd2si, "\tcvttsd2si%2t %x,%r\n",      Use(.l={1}),                    Def(.l={2}))
+Insn(Icvttsi2sd, "\tcvttsd2si%2t %x,%r\n",      Use(.l={1}),                    Def(.l={2}))
+Insn(Ifdiv,      "\tdiv%t %x,%r\n",             Use(.l={1},.r={Reax,Redx}),     Def(.r={Reax,Redx}))
+Insn(Ifmul,      "\tmul%t %x,%r\n",             Use(.l={1,2}),                  Def(.l={2}))
+Insn(Icomi,      "\tcomi%d %x,%r\n",            Use(.l={1,2}),                  Def())
 
 /* branch instructions */
 Insn(Icall,     "\tcall %v\n",                  Use(.l={1}), Def(.r={Rrax}))
--- a/6/isel.c
+++ b/6/isel.c
@@ -459,28 +459,37 @@
         case Obor:      r = binop(s, Ior,  args[0], args[1]); break;
         case Oband:     r = binop(s, Iand, args[0], args[1]); break;
         case Obxor:     r = binop(s, Ixor, args[0], args[1]); break;
-        case Omul:      r = binop(s, Iimul, args[0], args[1]); break;
+        case Omul:      
+            if (floattype(exprtype(n)))
+                r = binop(s, Ifmul, args[0], args[1]);
+            else
+                r = binop(s, Iimul, args[0], args[1]);
+            break;
         case Odiv:
         case Omod:
-            /* these get clobbered by the div insn */
-            a = selexpr(s, args[0]);
-            b = selexpr(s, args[1]);
-            b = inr(s, b);
-            c = coreg(Reax, mode(n));
-            r = locreg(a->mode);
-            if (r->mode == ModeB)
-                g(s, Ixor, eax, eax, NULL);
-            else
-                g(s, Ixor, edx, edx, NULL);
-            g(s, Imov, a, c, NULL);
-            g(s, Idiv, b, NULL);
-            if (exprop(n) == Odiv)
-                d = coreg(Reax, mode(n));
-            else if (r->mode != ModeB)
-                d = coreg(Redx, mode(n));
-            else
-                d = locphysreg(Rah);
-            g(s, Imov, d, r, NULL);
+            if (floattype(exprtype(n))) {
+                r = binop(s, Ifdiv, args[0], args[1]);
+            } else {
+                /* these get clobbered by the div insn */
+                a = selexpr(s, args[0]);
+                b = selexpr(s, args[1]);
+                b = inr(s, b);
+                c = coreg(Reax, mode(n));
+                r = locreg(a->mode);
+                if (r->mode == ModeB)
+                    g(s, Ixor, eax, eax, NULL);
+                else
+                    g(s, Ixor, edx, edx, NULL);
+                g(s, Imov, a, c, NULL);
+                g(s, Idiv, b, NULL);
+                if (exprop(n) == Odiv)
+                    d = coreg(Reax, mode(n));
+                else if (r->mode != ModeB)
+                    d = coreg(Redx, mode(n));
+                else
+                    d = locphysreg(Rah);
+                g(s, Imov, d, r, NULL);
+            }
             break;
         case Oneg:
             r = selexpr(s, args[0]);
--- a/6/simp.c
+++ b/6/simp.c
@@ -248,6 +248,14 @@
         return stacktype(n->decl.type);
 }
 
+int floatnode(Node *n)
+{
+    if (n->type == Nexpr)
+        return floattype(n->expr.type);
+    else
+        return floattype(n->decl.type);
+}
+
 size_t tysize(Type *t)
 {
     size_t sz;