Mercurial > projects > ldc
annotate tests/mini/bitops.d @ 1351:8d501abecd24
Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Thu, 14 May 2009 17:20:17 +0200 |
parents | 1bb99290e03a |
children |
rev | line source |
---|---|
270
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
86
diff
changeset
|
1 |
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
86
diff
changeset
|
2 extern(C) int printf(char*, ...); |
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
86
diff
changeset
|
3 |
1 | 4 void main() |
5 { | |
6 printf("Bitwise operations test\n"); | |
7 { ushort a = 0xFFF0; | |
8 ushort b = 0x0FFF; | |
9 assert((a&b) == 0x0FF0); | |
10 assert((a|b) == 0xFFFF); | |
11 assert((a^b) == 0xF00F); | |
12 } | |
13 { ubyte a = 0xFF; | |
14 ulong b = 0xFFFF_FFFF_FFFF_FFF0; | |
15 assert((a&b) == 0xF0); | |
16 } | |
17 { ushort s = 0xFF; | |
18 assert((s<<1) == s*2); | |
19 assert((s>>>1) == s/2); | |
20 } | |
21 { int s = -10; | |
22 assert((s>>1) == -5); | |
23 assert((s>>>1) != -5); | |
24 } | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
1
diff
changeset
|
25 |
1 | 26 { ushort a = 0xFFF0; |
27 ushort b = 0x0FFF; | |
28 auto t = a; | |
29 t &= b; | |
30 assert(t == 0x0FF0); | |
31 t = a; | |
32 t |= b; | |
33 assert(t == 0xFFFF); | |
34 t = a; | |
35 t ^= b; | |
36 assert(t == 0xF00F); | |
37 } | |
38 { ubyte a = 0xFF; | |
39 ulong b = 0xFFFF_FFFF_FFFF_FFF0; | |
40 a &= b; | |
41 assert(a == 0xF0); | |
42 } | |
43 { ushort s = 0xFF; | |
44 auto t = s; | |
45 t <<= 1; | |
46 assert(t == (s*2)); | |
47 t = s; | |
48 t >>>= 1; | |
49 assert(t == s/2); | |
50 } | |
51 { int s = -10; | |
52 auto t = s; | |
53 t >>= 1; | |
54 assert(t == -5); | |
55 t = s; | |
56 t >>>= 1; | |
57 assert(t != -5); | |
58 } | |
59 { struct S | |
60 { | |
61 uint i; | |
62 ulong l; | |
63 }; | |
64 S s = S(1,4); | |
65 auto a = s.i | s.l; | |
66 assert(a == 5); | |
67 s.i = 0xFFFF_00FF; | |
68 s.l = 0xFFFF_FFFF_0000_FF00; | |
69 s.l ^= s.i; | |
70 assert(s.l == ulong.max); | |
71 s.i = 0x__FFFF_FF00; | |
72 s.l = 0xFF00FF_FF00; | |
73 s.i &= s.l; | |
74 assert(s.i == 0x00FF_FF00); | |
75 } | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
1
diff
changeset
|
76 |
1 | 77 printf(" SUCCESS\n"); |
78 } |