Mercurial > projects > dstress
annotate run/mini/naked_asm5.d @ 1630:d0efa3ae5522 default tip
run/mini/naked_asm5: New x86_64 ABI passes the arguments in reverse order.
author | David Nadlinger <code@klickverbot.at> |
---|---|
date | Sat, 23 Apr 2011 22:57:32 +0200 |
parents | c6ef09dfba4d |
children |
rev | line source |
---|---|
1628
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
1 int foo(int op)(int a, int b) |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
2 { |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
3 version(X86) |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
4 { |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
5 const OP = (op == '+') ? "add" : "sub"; |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
6 version (Windows) |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
7 { |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
8 asm { naked; } |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
9 mixin("asm{push EBP;mov EBP,ESP;sub ESP,8;mov ECX,[EBP+8];"~OP~" EAX, ECX;add ESP,8;pop EBP;}"); |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
10 asm { ret; } |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
11 } else |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
12 { |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
13 asm { naked; } |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
14 mixin("asm{"~OP~" EAX, [ESP+4];}"); |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
15 asm { ret 4; } |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
16 } |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
17 } |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
18 else version(X86_64) |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
19 { |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
20 const OP = (op == '+') ? "add" : "sub"; |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
21 asm { naked; } |
1630
d0efa3ae5522
run/mini/naked_asm5: New x86_64 ABI passes the arguments in reverse order.
David Nadlinger <code@klickverbot.at>
parents:
1628
diff
changeset
|
22 mixin("asm{"~OP~" EDI,ESI; mov EAX, EDI;}"); |
1628
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
23 asm { ret; } |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
24 } |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
25 else static assert(0, "todo"); |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
26 } |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
27 |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
28 void main() |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
29 { |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
30 int i = foo!('+')(2, 4); |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
31 assert(i == 6); |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
32 i = foo!('-')(2, 4); |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
33 assert(i == 2); |
c6ef09dfba4d
add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff
changeset
|
34 } |