annotate run/mini/asm9.d @ 1628:c6ef09dfba4d

add mini test set from ldc project
author Moritz Warning <moritzwarning@web.de>
date Mon, 10 Jan 2011 19:47:18 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1628
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
1 module asm9;
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) version = DoSome;
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
4 else version(X86_64) version = DoSome;
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
5
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
6 T add(T, T t)(T a) {
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
7 asm {
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
8 add a, t;
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
9 }
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
10 return a;
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
11 }
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 void main() {
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
14 version (DoSome) {
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
15 assert(add!(ubyte, 20)(10) == 30);
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
16 assert(add!(ushort, 20_000)(10_000) == 30_000);
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
17 assert(add!(uint, 2_000_000)(1_000_000) == 3_000_000);
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
18 }
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
19 version(X86_64) {
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
20 // 64-bit immediates aren't allowed on "ADD", nor are
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
21 // unsigned 32-bit ones, so make the template parameter
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
22 // fit in a 32-bit signed int.
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
23 // These values were chosen so that the lower 32-bits overflow
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
24 // and we can see the upper half of the 64-bit input increment.
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
25 auto result = add!(long, 2_000_000_000)(21_000_000_000);
c6ef09dfba4d add mini test set from ldc project
Moritz Warning <moritzwarning@web.de>
parents:
diff changeset
26 assert(result == 23_000_000_000);
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 }