Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)

Fixed align N; in asm blocks.

Fixed inreg parameter passing on x86 for ref/out params.

Removed support for lazy initialization of function local static variables, I have no idea why I ever implemented this, it's not in the D spec, and DMD doesn't support it :P

Some of the global variable related changes might cause minor regressions, but they should be easily fixable.
This commit is contained in:
Tomas Lindquist Olsen
2009-02-03 08:54:57 +01:00
parent 8ab98dad49
commit dc5944df99
28 changed files with 491 additions and 153 deletions

View File

@@ -1,5 +1,3 @@
module tangotests.asm5;
extern(C) int printf(char*, ...);
void main()
@@ -13,18 +11,20 @@ int func()
{
version (LLVM_InlineAsm_X86)
{
asm
{
naked;
mov EAX, 42;
ret;
}
asm
{
naked;
mov EAX, 42;
ret;
}
}
else version(LLVM_InlineAsm_X86_64)
{
asm
{
movq RAX, 42;
naked;
movq RAX, 42;
ret;
}
}
}

21
tests/mini/naked_asm2.d Normal file
View File

@@ -0,0 +1,21 @@
int foo()
{
static int fourty2 = 42;
version(X86)
asm
{
naked;
mov EAX, fourty2;
ret;
}
else static assert(0, "todo");
}
void main()
{
int i = foo();
printf("i == %d\n", i);
assert(i == 42);
}
extern(C) int printf(char*, ...);

21
tests/mini/naked_asm3.d Normal file
View File

@@ -0,0 +1,21 @@
int foo()
{
enum { fourty2 = 42 }
version(X86)
asm
{
naked;
mov EAX, fourty2;
ret;
}
else static assert(0, "todo");
}
void main()
{
int i = foo();
printf("i == %d\n", i);
assert(i == 42);
}
extern(C) int printf(char*, ...);

17
tests/mini/naked_asm4.d Normal file
View File

@@ -0,0 +1,17 @@
void foo()
{
version(X86)
asm
{
naked;
jmp pass;
hlt;
pass: ret;
}
else static assert(0, "todo");
}
void main()
{
foo();
}

19
tests/mini/naked_asm5.d Normal file
View File

@@ -0,0 +1,19 @@
int foo(int op)(int a, int b)
{
version(X86)
{
const OP = (op == '+') ? "add" : "sub";
asm { naked; }
mixin("asm{"~OP~" EAX, [ESP+4];}");
asm { ret 4; }
}
else static assert(0, "todo");
}
void main()
{
int i = foo!('+')(2, 4);
assert(i == 6);
i = foo!('-')(2, 4);
assert(i == 2);
}

18
tests/mini/naked_asm6.d Normal file
View File

@@ -0,0 +1,18 @@
extern(C) int printf(char*, ...);
ulong retval() {
asm { naked; mov EAX, 0xff; mov EDX, 0xaa; ret; }
}
ulong retval2() {
return (cast(ulong)0xaa << 32) | 0xff;
}
void main() {
ulong a,b;
a = retval();
b = retval2();
printf("%llu\n%llu\n", retval(), retval2());
assert(a == 0x000000aa000000ff);
assert(a == b);
}

18
tests/mini/structinit4.d Normal file
View File

@@ -0,0 +1,18 @@
// testcase from bug #199
struct Color {
uint c;
}
struct Vertex {
Color c;
}
void main() {
Color c = {0xffffffff};
auto v = Vertex(c);
assert(v.c.c == 0xffffffff); // fails in LDC
}

11
tests/mini/structinit5.d Normal file
View File

@@ -0,0 +1,11 @@
struct Vertex {
uint[1] c;
}
void main() {
uint[1] c = 0xffffffff;
auto v = Vertex(c);
assert(v.c[0] == 0xffffffff); // fails in LDC
}

View File

@@ -1,11 +0,0 @@
module templ1;
T func1(T)(T a)
{
static T b = a;
return b;
}
void main()
{
}

View File

@@ -1,7 +0,0 @@
module templ2;
import templ1;
void main()
{
func1(1);
}