changeset 949:b2d27ddf8f45

changes to get the naked asm stuff working for x64
author wilsonk@ubuntu
date Tue, 10 Feb 2009 08:02:25 -0700
parents 780530d1cad3
children f31b29eb6980
files gen/naked.cpp gen/tocall.cpp tests/mini/asm5.d tests/mini/asm8.d
diffstat 4 files changed, 125 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/gen/naked.cpp	Sun Feb 08 21:44:46 2009 +0100
+++ b/gen/naked.cpp	Tue Feb 10 08:02:25 2009 -0700
@@ -179,8 +179,8 @@
     asmblock->retty = llretTy;
     asmblock->retn = 1;
 
-    // x86
-    if (global.params.cpu == ARCHx86)
+    // x86 or x86_64
+    if (global.params.cpu == ARCHx86 || global.params.cpu == ARCHx86_64)
     {
         LINK l = fdecl->linkage;
         assert((l == LINKd || l == LINKc || l == LINKwindows) && "invalid linkage for asm implicit return");
--- a/gen/tocall.cpp	Sun Feb 08 21:44:46 2009 +0100
+++ b/gen/tocall.cpp	Tue Feb 10 08:02:25 2009 -0700
@@ -464,7 +464,7 @@
     LLValue* retllval = (retinptr) ? args[0] : call->get();
 
     // swap real/imag parts on a x87
-    if (global.params.cpu == ARCHx86 && tf->nextOf()->toBasetype()->iscomplex())
+    if ((global.params.cpu == ARCHx86 || global.params.cpu == ARCHx86_64) && tf->nextOf()->toBasetype()->iscomplex())
     {
         retllval = DtoAggrPairSwap(retllval);
     }
--- a/tests/mini/asm5.d	Sun Feb 08 21:44:46 2009 +0100
+++ b/tests/mini/asm5.d	Tue Feb 10 08:02:25 2009 -0700
@@ -1,14 +1,24 @@
 int foo()
 {
     version(X86)
-    asm { mov EAX, 42; }
+    {
+      asm { mov EAX, 42; }
+    } else version(X86_64)
+    {
+      asm { movq RAX, 42; }
+    }
     else static assert(0, "todo");
 }
 
 ulong bar()
 {
     version(X86)
-    asm { mov EAX, 0xFF; mov EDX, 0xAA; }
+    {
+      asm { mov EAX, 0xFF; mov EDX, 0xAA; }
+    } else version(X86_64)
+    {
+      asm { movq RAX, 0xFF; }
+    }
     else static assert(0, "todo");
 }
 
@@ -19,5 +29,11 @@
     l = 4;
     l = 8;
     assert(foo() == 42);
-    assert(bar() == 0x000000AA000000FF);
+    version(X86)
+    {
+        assert(bar() == 0x000000AA000000FF);
+    } else version(X86_64)
+    {
+        assert(bar() == 0x00000000000000FF);
+    }
 }
--- a/tests/mini/asm8.d	Sun Feb 08 21:44:46 2009 +0100
+++ b/tests/mini/asm8.d	Tue Feb 10 08:02:25 2009 -0700
@@ -1,56 +1,105 @@
 int foo()
 {
     version(X86)
-    asm { mov EAX, 42; }
+    {
+        asm { mov EAX, 42; }
+    }
+    else version (X86_64)
+    {
+        asm { mov EAX, 42; }
+    }
     else static assert(0, "todo");
 }
 
 ulong bar()
 {
     version(X86)
-    asm { mov EDX, 0xAA; mov EAX, 0xFF; }
+    {
+        asm { mov EDX, 0xAA; mov EAX, 0xFF; }
+    }
+    else version (X86_64)
+    {
+        asm { movq RAX, 0xFF; }
+    }
     else static assert(0, "todo");
 }
 
 float onef()
 {
     version(X86)
-    asm { fld1; }
+    {
+        asm { fld1; }
+    }
+    else version (X86_64)
+    {
+        asm { fld1; }
+    }
     else static assert(0, "todo");
 }
 
 double oned()
 {
     version(X86)
-    asm { fld1; }
+    {
+        asm { fld1; }
+    }
+    else version (X86_64)
+    {
+        asm { fld1; }
+    }
     else static assert(0, "todo");
 }
 
 real oner()
 {
     version(X86)
-    asm { fld1; }
+    {
+        asm { fld1; }
+    }
+    else version (X86_64)
+    {
+        asm { fld1; }
+    }
     else static assert(0, "todo");
 }
 
+
 real two = 2.0;
 
 creal cr()
 {
     version(X86)
-    asm { fld1; fld two; }
+    {
+        asm { fld1; fld two; }
+    }
+    else version (X86_64)
+    {
+        asm { fld1; fld two; }
+    }
     else static assert(0, "todo");
 }
 
 creal cr2()
 {
     version(X86)
+    {
+        asm
+        {
+            naked;
+            fld1;
+            fld two;
+            ret;
+        }
+    }
+    else version (X86_64)
+    {
     asm
-    {
-        naked;
-        fld1;
-        fld two;
-        ret;
+        {
+            naked;
+            fld1;
+            fld two;
+            ret;
+        }
     }
     else static assert(0, "todo");
 }
@@ -58,7 +107,13 @@
 void* vp()
 {
     version(X86)
-    asm { mov EAX, 0x80; }
+    {
+        asm { mov EAX, 0x80; }
+    }
+    else version (X86_64)
+    {
+        asm { movq RAX, 0x80; }
+    }
     else static assert(0, "todo");
 }
 
@@ -67,7 +122,13 @@
 int[int] aa()
 {
     version(X86)
-    asm { mov EAX, gaa; }
+    {
+        asm { mov EAX, gaa; }
+    }
+    else version (X86_64)
+    {
+        asm { movq RAX, gaa; }
+    }
     else static assert(0, "todo");
 }
 
@@ -76,7 +137,13 @@
 Object ob()
 {
     version(X86)
-    asm { mov EAX, gobj; }
+    {
+        asm { mov EAX, gobj; }
+    }
+    else version (X86_64)
+    {
+        asm { movq RAX, gobj; }
+    }
     else static assert(0, "todo");
 }
 
@@ -85,14 +152,26 @@
 char[] str()
 {
     version(X86)
-    asm { lea ECX, ghello; mov EAX, [ECX]; mov EDX, [ECX+4]; }
+    {
+        asm { lea ECX, ghello; mov EAX, [ECX]; mov EDX, [ECX+4]; }
+    }
+    else version (X86_64)
+    {
+        asm { movq RAX, [ghello]; movq RDX, [ghello]+8; }
+    }
     else static assert(0, "todo");
 }
 
 char[] delegate() dg()
 {
     version(X86)
-    asm { mov EAX, gobj; lea EDX, Object.toString; }
+    {
+        asm { mov EAX, gobj; lea EDX, Object.toString; }
+    }
+    else version (X86_64)
+    {
+        asm { movq RAX, [gobj]; leaq RDX, Object.toString; }
+    }
     else static assert(0, "todo");
 }
 
@@ -103,7 +182,14 @@
     auto adg = &gobj.toString;
 
     assert(foo() == 42);
-    assert(bar() == 0x000000AA000000FF);
+    version(X86)
+    {
+        assert(bar() == 0x000000AA000000FF);
+    } 
+    else version (X86_64)
+    {
+        assert(bar() == 0x00000000000000FF);
+    }
     assert(onef() == 1);
     assert(oned() == 1);
     assert(oner() == 1);