Imported Upstream version 2.9.0
[debian/cc1111] / src / regression / add2.c
1 #include "gpsim_assert.h"
2
3 // Addition tests - mostly int's
4
5 /* bit types are not ANSI - so provide a way of disabling bit types
6  * if this file is used to test other compilers besides SDCC */
7 #define SUPPORT_BIT_TYPES 0
8
9
10 unsigned char failures=0;
11
12
13 unsigned int aint0 = 0;
14 unsigned int aint1 = 0;
15 unsigned int aint2 = 0;
16 unsigned int aint3 = 0;
17 unsigned char achar0 = 0;
18 unsigned char achar1 = 0;
19 unsigned char achar2 = 0;
20 unsigned char achar3 = 0;
21 unsigned char *acharP = 0;
22
23 #if SUPPORT_BIT_TYPES
24
25 bit bit0 = 0;
26 bit bit1 = 0;
27 bit bit2 = 0;
28 bit bit3 = 0;
29 bit bit4 = 0;
30 bit bit5 = 0;
31 bit bit6 = 0;
32 bit bit7 = 0;
33 bit bit8 = 0;
34 bit bit9 = 0;
35 bit bit10 = 0;
36 bit bit11 = 0;
37
38 #endif
39
40
41 void
42 done()
43 {
44   ASSERT(MANGLE(failures) == 0);
45   PASSED();
46 }
47
48 void add_lit2uint(void)
49 {
50
51   aint0 = aint0 + 5;
52
53   if(aint0 != 5)
54     failures++;
55
56   aint0 += 10;
57
58   if(aint0 != 15)
59     failures++;
60
61   aint0 = aint0 +1;  // Should be an increment
62   if(aint0 != 16)
63     failures++;
64
65   for(aint1 = 0; aint1 < 100; aint1++)
66     aint0 += 2;
67
68   if(aint0 != 216)
69     failures++;
70
71 }
72
73 void add_uint2uint (void)
74 {
75
76   aint1 = aint1 + aint0;
77
78   if(aint1 != 16)
79     failures++;
80
81   for(aint2 = 0; aint2<7; aint2++)
82     aint1 += aint0;
83
84   if(aint1 != 128)
85     failures++;
86
87 }
88
89 // assumes
90 //  aint0 = 0
91 //  aint1 = 32
92 //  aint2, aint3 can be anything.
93
94 void add_uint2uint2(void)
95 {
96
97
98   aint0++;
99   aint0 = aint0 + 1;
100   aint0 = aint0 + 2;
101   aint0 = aint0 + 3;
102   if(aint0 != 7)
103     failures++;
104
105   aint1 += aint0;
106   if(aint1 != 0x27)
107     failures++;
108
109   aint2 = aint1 + aint0;
110   if(aint2 != 0x2e)
111     failures++;
112
113   aint3 = aint2 + aint1 + aint0;
114   if(aint3 != 0x5c)
115     failures++;
116
117   aint3 += 0xa0;
118   if(aint3 != 0xfc)
119     failures++;
120
121   aint3 += aint0;
122   if(aint3 != 0x103)
123     failures++;
124
125   aint1 += 0xffc0;
126   if(aint1 != 0xffe7)
127     failures++;
128
129   aint3 = aint2 + aint1 + aint0;
130   if(aint3 != 0x1c)
131     failures++;
132
133
134 }
135
136 #if SUPPORT_BIT_TYPES
137 void add_bits(void)
138 {
139
140   bit1 = bit0;
141
142   bit0 = 1;
143
144   if(bit1 != 0)
145     failures++;
146
147   bit1 = bit1+bit0;
148   if(bit1 != 1)
149     failures++;
150
151   bit2 = bit1+bit3;
152   if(!bit2)
153     failures++;
154
155   bit3 = bit4+bit5+bit6+bit7+bit0;
156   if(!bit3)
157     failures++;
158 }
159 #endif
160
161 /* add_bit2uchar(void) - assumes bit0 = 1, aint0 = 7  */
162
163 #if SUPPORT_BIT_TYPES
164 void add_bit2uchar(void)
165 {
166
167   achar0 += bit0;
168
169   if(achar0 != 8)
170     failures++;
171
172   if(achar0 == bit0)
173     failures++;
174
175 }
176
177 void add_bit2uint(void)
178 {
179
180   if(aint0 != bit11)
181     failures++;
182
183   aint0 += bit0;
184   if(aint0!=1)
185     failures++;
186
187 }
188 #endif
189
190 /***********************************/
191
192 void addlits(void)
193 {
194   aint0 += 0x0001;
195
196   if(aint0 != 1)
197     failures++;
198
199   aint0 += 0x00;
200
201   if(aint0 != 1)
202     failures++;
203
204   aint0 += 0x00fe;
205   if(aint0 != 0x00ff)
206     failures++;
207
208   aint0 += 0x0001;
209
210   if(aint0 != 0x0100)
211     failures++;
212
213   aint0++;
214   if(aint0 != 0x0101)
215     failures++;
216
217   aint0 += 0x00ff;
218   if(aint0 != 0x0200)
219     failures++;
220
221   aint0 += 0x00a0;
222   if(aint0 != 0x02a0)
223     failures++;
224
225   aint0 += 0x0061;
226   if(aint0 != 0x0301)
227     failures++;
228
229   aint0 += 0x0100;
230   if(aint0 != 0x0401)
231     failures++;
232
233   aint0 += 0x0101;
234   if(aint0 != 0x0502)
235     failures++;
236
237   aint0 += 0x00fd;
238   if(aint0 != 0x05ff)
239     failures++;
240
241   aint0 += 0x0101;
242   if(aint0 != 0x0700)
243     failures++;
244
245   aint0 += 0x01ff;
246   if(aint0 != 0x08ff)
247     failures++;
248
249   aint0 += 0x01ff;
250   if(aint0 != 0x0afe)
251     failures++;
252
253   aint0 += 0xff02;
254   if(aint0 != 0x0a00)
255     failures++;
256
257   aint0 += 0xffff;
258   if(aint0 != 0x09ff)
259     failures++;
260
261   aint0 += 0xff01;
262   if(aint0 != 0x0900)
263     failures++;
264
265   aint0 += 0xff00;
266   if(aint0 != 0x0800)
267     failures++;
268
269   aint0 += 0xff01;
270   if(aint0 != 0x0701)
271     failures++;
272
273   aint0 += 0x0300;
274   if(aint0 != 0x0a01)
275     failures++;
276
277   aint0 += 0x03ff;
278   if(aint0 != 0x0e00)
279     failures++;
280
281   aint0 += 0x0301;
282   if(aint0 != 0x1101)
283     failures++;
284
285   aint0 += 0x03fe;
286   if(aint0 != 0x14ff)
287     failures++;
288
289   aint0 += 0x0301;
290   if(aint0 != 0x1800)
291     failures++;
292  
293 }
294
295
296 void main(void)
297 {
298
299   add_lit2uint();
300
301   aint0=16;
302   aint1=0;
303   add_uint2uint();
304
305
306   aint0 = 0;
307   aint1 = 32;
308   aint2 = 0;
309   add_uint2uint2();
310
311 #if SUPPORT_BIT_TYPES
312   add_bits();
313
314   achar0 = 7;
315   add_bit2uchar();
316
317   aint0 = 0;
318   bit0 = 1;
319   add_bit2uint();
320 #endif
321
322   aint0 = 0;
323   addlits();
324
325   done();
326 }