struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / onebyte.c.in
blobde66a057e1f614f2cd04ce2c7630ce341ad71136
1 /** test one byte mul/div/mod operations.
3 attrL: volatile,
4 attrR: volatile,
5 */
6 #include <testfwk.h>
8 void
9 testMul (void)
11 #ifndef __SDCC_pdk14 // Lack of memory
12 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
13 {attrL} signed char cL;
14 {attrL} unsigned char ucL;
15 {attrR} signed char cR;
16 {attrR} unsigned char ucR;
17 volatile signed char r8 , r8b;
18 volatile unsigned char ur8, ur8b;
19 volatile short r16, r16b;
20 #ifndef __SDCC_pic16
21 cL = -127; cR = -5; r16 = cL * cR; r16b = cR * cL; ASSERT (r16 == 635); ASSERT (r16b == 635);
22 cL = 127; cR = -5; r16 = cL * cR; r16b = cR * cL; ASSERT (r16 == -635); ASSERT (r16b == -635);
23 cL = -127; cR = 5; r16 = cL * cR; r16b = cR * cL; ASSERT (r16 == -635); ASSERT (r16b == -635);
24 cL = 127; cR = 5; r16 = cL * cR; r16b = cR * cL; ASSERT (r16 == 635); ASSERT (r16b == 635);
26 cL = -128; cR = -1; ur8 = cL * cR; ur8b = cR * cL; ASSERT (ur8 == 128); ASSERT (ur8b == 128);
27 cL = 128; cR = -1; r8 = cL * cR; r8b = cR * cL; ASSERT ( r8 == -128); ASSERT ( r8b == -128);
28 cL = -128; cR = 1; r8 = cL * cR; r8b = cR * cL; ASSERT ( r8 == -128); ASSERT ( r8b == -128);
29 cL = 128; cR = 1; ur8 = cL * cR; ur8b = cR * cL; ASSERT (ur8 == 128); ASSERT (ur8b == 128);
31 ucL = 128; cR = -5; r16 = ucL * cR; r16b = cR * ucL; ASSERT (r16 == -640); ASSERT (r16b == -640);
32 ucL = 128; cR = 5; r16 = ucL * cR; r16b = cR * ucL; ASSERT (r16 == 640); ASSERT (r16b == 640);
34 ucL = 127; cR = -1; r8 = ucL * cR; r8b = cR * ucL; ASSERT ( r8 == -127); ASSERT ( r8b == -127);
35 ucL = 128; cR = 1; ur8 = ucL * cR; ur8b = cR * ucL; ASSERT (ur8 == 128); ASSERT (ur8b == 128);
36 ucL = 128; ucR = 5; r16 = ucL * ucR; r16b = ucR * ucL; ASSERT (r16 == 640); ASSERT (r16b == 640);
37 ucL = 128; ucR = 1; ur8 = ucL * ucR; ur8b = ucR * ucL; ASSERT (ur8 == 128); ASSERT (ur8b == 128);
39 ucL = 254; cR = -1; r16 = ucL * cR; ASSERT (r16 == -254);
40 cL = -128; cR = -1; r16 = cL * cR; ASSERT (r16 == 128);
41 #endif
42 #endif
43 #endif
46 void
47 testDiv (void)
49 #ifndef __SDCC_pdk14 // Lack of memory
50 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
51 {attrL} signed char cL;
52 {attrL} unsigned char ucL;
53 {attrR} signed char cR;
54 {attrR} unsigned char ucR;
55 volatile signed char r8;
56 volatile unsigned char ur8;
57 volatile short r16;
59 cL = -128; cR = -2; r8 = cL / cR; ASSERT (r8 == 64);
60 cL = -128; cR = -2; r16 = cL / cR; ASSERT (r16 == 64);
62 ucL = 255; ucR = 3; r8 = ucL / ucR; ASSERT (r8 == 85);
63 ucL = 255; ucR = 255; r8 = ucL / ucR; ASSERT (r8 == 1);
64 ucL = 3; ucR = 255; r8 = ucL / ucR; ASSERT (r8 == 0);
66 cL = 127; cR = 3; r8 = cL / cR; ASSERT (r8 == 42);
67 cL = -127; cR = 3; r8 = cL / cR; ASSERT (r8 == -42);
68 cL = 127; cR = -3; r8 = cL / cR; ASSERT (r8 == -42);
69 cL = -127; cR = -3; r8 = cL / cR; ASSERT (r8 == 42);
71 ucL = 127; cR = 3; r8 = ucL / cR; ASSERT (r8 == 42);
72 ucL = 255; cR = 3; r8 = ucL / cR; ASSERT (r8 == 85);
73 ucL = 127; cR = -3; r8 = ucL / cR; ASSERT (r8 == -42);
74 ucL = 255; cR = -3; r8 = ucL / cR; ASSERT (r8 == -85);
76 cL = 127; ucR = 3; r8 = cL / ucR; ASSERT (r8 == 42);
77 cL = -127; ucR = 3; r8 = cL / ucR; ASSERT (r8 == -42);
78 cL = 127; ucR = 128; r8 = cL / ucR; ASSERT (r8 == 0);
79 cL = -127; ucR = 128; r8 = cL / ucR; ASSERT (r8 == 0);
81 cL = 127; cR = 1; r8 = cL / cR; ASSERT (r8 == 127);
82 cL = 127; cR = 1; r16 = cL / cR; ASSERT (r16 == 127);
84 ucL = 251; cR = 1; ur8 = ucL / cR; ASSERT (ur8 == 251);
85 ucL = 251; cR = 1; r16 = ucL / cR; ASSERT (r16 == 251);
87 ucL = 253; cR = -3; r8 = ucL / cR; ASSERT (r8 == -84);
88 ucL = 253; cR = -3; r16 = ucL / cR; ASSERT (r16 == -84);
90 ucL = 254; cR = -1; r16 = ucL / cR; ASSERT (r16 == -254);
91 cL = -128; cR = -1; r16 = cL / cR; ASSERT (r16 == 128);
92 #endif
93 #endif
96 void
97 testMod (void)
99 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
100 {attrL} signed char cL;
101 {attrL} unsigned char ucL;
102 {attrR} signed char cR;
103 {attrR} unsigned char ucR;
104 volatile signed char r8;
105 volatile unsigned char ur8;
106 volatile short r16;
108 ucL = 128; cR = 5; r16 = ucL % cR; ASSERT (r16 == 3);
109 ucL = 128; cR = -5; r16 = ucL % cR; ASSERT (r16 == 3);
110 ucL = 128; ucR = 5; r16 = ucL % ucR; ASSERT (r16 == 3);
112 ucL = 128; ucR = 255; ur8 = ucL % ucR; ASSERT (ur8 == 128);
113 ucL = 128; ucR = 255; r16 = ucL % ucR; ASSERT (r16 == 128);
115 ucL = 128; cR = 127; r8 = ucL % cR; ASSERT (r8 == 1);
117 cL = 127; cR = 5; r16 = cL % cR; ASSERT (r16 == 2);
118 r16 = -1;
119 cL = 127; cR = -5; r16 = cL % cR; ASSERT (r16 == 2);
120 r16 = -1;
121 cL = 127; ucR = 5; r16 = cL % ucR; ASSERT (r16 == 2);
122 r16 = -1;
123 cL = 127; ucR = 6; r16 = cL % ucR; ASSERT (r16 == 1);
125 cL = -128; cR = 5; r16 = cL % cR; ASSERT (r16 == -3);
126 r16 = 0;
127 cL = -128; cR = -5; r16 = cL % cR; ASSERT (r16 == -3);
128 r16 = 0;
129 cL = -128; ucR = 5; r16 = cL % ucR; ASSERT (r16 == -3);
130 #endif
133 void
134 testOr (void)
136 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
137 {attrL} signed char cL;
138 {attrL} unsigned char ucL;
139 {attrR} signed char cR;
140 {attrR} unsigned char ucR;
141 volatile short r16, r16b;
143 cL = 0x00; cR = 0x80; r16 = cL | cR; r16b = cR | cL; ASSERT (r16 == (short) 0xff80); ASSERT (r16b == (short) 0xff80);
144 ucL = 0x80; cR = 0x00; r16 = ucL | cR; r16b = cR | ucL; ASSERT (r16 == 0x80); ASSERT (r16b == 0x80);
145 ucL = 0x80; ucR = 0x80; r16 = ucL | ucR; r16b = ucR | ucL; ASSERT (r16 == 0x80); ASSERT (r16b == 0x80);
146 #endif
149 void
150 testXor (void)
152 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
153 {attrL} signed char cL;
154 {attrL} unsigned char ucL;
155 {attrR} signed char cR;
156 {attrR} unsigned char ucR;
157 volatile short r16, r16b;
159 cL = 0x80; cR = 0x80; r16 = cL ^ cR; r16b = cR ^ cL; ASSERT (r16 == 0); ASSERT (r16b == 0);
160 cL = 0x80; cR = 0x00; r16 = cL ^ cR; r16b = cR ^ cL; ASSERT (r16 == (short) 0xff80); ASSERT (r16b == (short) 0xff80);
162 ucL = 0x80; cR = 0x80; r16 = ucL ^ cR; r16b = cR ^ ucL; ASSERT (r16 == (short) 0xff00); ASSERT (r16b == (short) 0xff00);
163 ucL = 0x80; cR = 0; r16 = ucL ^ cR; r16b = cR ^ ucL; ASSERT (r16 == 0x80); ASSERT (r16b == 0x80);
164 ucL = 0; cR = 0x80; r16 = ucL ^ cR; r16b = cR ^ ucL; ASSERT (r16 == (short) 0xff80); ASSERT (r16b == (short) 0xff80);
166 ucL = 0x80; ucR = 0x80; r16 = ucL ^ ucR; r16b = ucR ^ ucL; ASSERT (r16 == 0); ASSERT (r16b == 0);
167 ucL = 0; ucR = 0x80; r16 = ucL ^ ucR; r16b = ucR ^ ucL; ASSERT (r16 == 0x80); ASSERT (r16b == 0x80);
168 #endif
171 void
172 testAnd (void)
174 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
175 {attrL} signed char cL;
176 {attrL} unsigned char ucL;
177 {attrR} signed char cR;
178 {attrR} unsigned char ucR;
179 volatile short r16, r16b;
181 cL = 0x80; cR = 0x80; r16 = cL & cR; r16b = cR & cL; ASSERT (r16 == (short) 0xff80); ASSERT (r16b == (short) 0xff80);
182 ucL = 0x80; cR = 0x80; r16 = ucL & cR; r16b = cR & ucL; ASSERT (r16 == 0x80); ASSERT (r16b == 0x80);
183 ucL = 0x80; ucR = 0x80; r16 = ucL & ucR; r16b = ucR & ucL; ASSERT (r16 == 0x80); ASSERT (r16b == 0x80);
184 #endif
187 void
188 testComplement (void)
190 {attrR} signed char c;
191 {attrR} unsigned char uc;
192 volatile short r16;
194 c = 0x00; r16 = ~ c; ASSERT (r16 == (short) 0xffff); ASSERT (~ c < 0);
195 uc = 0x00; r16 = ~uc; ASSERT (r16 == (short) 0xffff); ASSERT (~uc < 0);
196 ASSERT (~ (signed char) 0x00 == (short) 0xffff); ASSERT (~ (signed char) 0x00 < 0);
197 ASSERT (~ (unsigned char) 0x00 == (short) 0xffff); ASSERT (~ (unsigned char) 0x00 < 0);
198 c = 0x80; r16 = ~ c; ASSERT (r16 == (short) 0x007f); ASSERT (~ c > 0);
199 uc = 0x80; r16 = ~uc; ASSERT (r16 == (short) 0xff7f); ASSERT (~uc < 0);
200 ASSERT (~ (signed char) 0x80 == (short) 0x007f); ASSERT (~ (signed char) 0x80 > 0);
201 ASSERT (~ (unsigned char) 0x80 == (short) 0xff7f); ASSERT (~ (unsigned char) 0x80 < 0);
203 ASSERT (~ 1 < 0);
204 ASSERT (~ 1u > 0);
205 ASSERT (~ 1l < 0);
206 ASSERT (~ 1ul > 0);
209 void
210 testCompare (void)
212 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
213 {attrL} signed char c;
214 {attrR} unsigned char uc;
216 c = 0x80; /* -128 */
217 uc = 0x80; /* +128 */
219 ASSERT (!(c == uc));
220 ASSERT ( c != uc );
221 ASSERT ( c < uc );
222 ASSERT ( c <= uc );
223 ASSERT (!(c > uc));
224 ASSERT (!(c >= uc));
225 #endif
228 void
229 testUMinus (void)
231 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
232 signed char {attrL} sc;
233 unsigned char {attrL} uc;
234 signed int {attrL} si;
235 unsigned int {attrL} ui;
236 signed long {attrL} sl;
237 unsigned long {attrL} ul;
239 ASSERT (-(53l ) < 0);
240 ASSERT (-(53ul) > 0);
241 ul = 53;
242 ASSERT (-ul > 0);
243 sl = 53;
244 ASSERT (-sl < 0);
246 ASSERT (-(53 ) < 0);
247 ASSERT (-(53u ) > 0);
248 ui = 53;
249 ASSERT (-ui > 0);
250 si = 53;
251 ASSERT (-si < 0);
253 ASSERT (-( 250 ) == -250);
254 uc = 250;
255 ASSERT (-uc == -250);
257 ASSERT (-(-128 ) == 128);
258 sc = -128;
259 ASSERT (-sc == 128);
260 #endif
263 void
264 testBug1571231 (void)
266 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
267 unsigned char {attrL} uc;
269 /* bug-1571231 */
270 uc = 0x80;
271 if (uc + 0x80)
272 ASSERT (1);
273 else
274 ASSERT (0);
275 #endif