- And'ing with a constant works (again).
[fw/sdcc] / src / regression / and1.c
1
2 unsigned char success=0;
3 unsigned char failures=0;
4 unsigned char dummy=0;
5
6
7 unsigned int uint0 = 0;
8 unsigned int uint1 = 0;
9 unsigned char uchar0 = 0;
10 unsigned char uchar1 = 0;
11 unsigned long ulong0 = 0;
12
13 void done()
14 {
15
16   dummy++;
17
18 }
19
20 // uchar0 = 0xff;
21 void and_lit2uchar(void)
22 {
23
24   if(uchar0 != 0xff)
25     failures++;
26
27   uchar0 &= 0x7f;
28
29   if(uchar0 != 0x7f)
30     failures++;
31
32   uchar0 &= 0x3f;
33
34   if(uchar0 != 0x3f)
35     failures++;
36
37   uchar0 &= 0xdf;
38
39   if(uchar0 != 0x1f)
40     failures++;
41 }
42
43 void and_lit2uint(void)
44 {
45   if(uint0 != 0xffff)
46     failures++;
47
48   uint0 &= 0x7fff;
49
50   if(uint0 != 0x7fff)
51     failures++;
52
53   uint0 &= 0x3fff;
54
55   if(uint0 != 0x3fff)
56     failures++;
57
58   uint0 &= 0xdfff;
59
60   if(uint0 != 0x1fff)
61     failures++;
62
63
64   uint0 &= 0xff7f;
65
66   if(uint0 != 0x1f7f)
67     failures++;
68
69   uint0 &= 0x0f0f;
70
71   if(uint0 != 0x0f0f)
72     failures++;
73
74   uint0 &= 0xfefe;
75
76   if(uint0 != 0x0e0e)
77     failures++;
78
79   uint0 &= 0xf0f0;
80
81   if(uint0 != 0)
82     failures++;
83 }
84
85 void and_lit2ulong(void)
86 {
87
88   if(ulong0 != 0xffffffff)
89     failures++;
90
91   ulong0 &= 0x7fffffff;
92
93   if(ulong0 != 0x7fffffff)
94     failures++;
95
96   ulong0 &= 0xff00ffff;
97
98   if(ulong0 != 0x7f00ffff)
99     failures++;
100
101   ulong0 &= 0xfeff00ff;
102
103   if(ulong0 != 0x7e0000ff)
104     failures++;
105 }
106
107 void main(void)
108 {
109
110   uchar0 = 0xff;
111   and_lit2uchar();
112
113   uint0 = 0xffff;
114   and_lit2uint();
115
116   ulong0 = 0xffffffff;
117   and_lit2ulong();
118
119   success = failures;
120   done();
121 }