struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bitopcse.c.in
blob3bb45efc1fa11ebb4e18a818417702f35583b5e0
1 /* Test CSE with |&^
3 type: bool, char, short, long
4 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_sdcc99
9 #endif
11 #include <stdbool.h>
13 /* This is not only a regression test, the focus of this test
14 is more on the generated code (volatile!). */
16 #define TYPE_{type}
18 #if defined(TYPE_bool)
19 # define UNSIGNED
20 #else
21 # define UNSIGNED unsigned
22 #endif
24 #if defined(__SDCC_MODEL_SMALL)
25 # define _data __idata
26 #else
27 # define _data
28 #endif
30 #if defined(TYPE_bool) && defined(__bool_true_false_are_defined)
31 # define MASK 1
32 #elif defined(TYPE_bool) && !defined(__bool_true_false_are_defined)
33 # if defined(PORT_HOST)
34 # define MASK 0xffffffff
35 # else
36 # define MASK 0xffff
37 # endif
38 # define bool int
39 #elif defined(TYPE_char)
40 # define MASK 0xff
41 #elif defined(TYPE_short)
42 # define MASK 0xffff
43 #elif defined(TYPE_long)
44 # define MASK 0xffffffff
45 #else
46 # warning Unknown type
47 #endif
49 #if !(defined(__SDCC_pdk14) && defined(TYPE_long)) // Not enough RAM
50 /* the variable 'mask' is only defined to see if MASK is correctly set up */
51 const unsigned long mask = MASK;
53 volatile {type} v;
54 volatile UNSIGNED {type} uv;
55 /* an array would be nicer, but an array of bits isn't possible */
56 _data {type} a0, a1, a2, a3, a4, a5, a6, a7, a8, a9
57 #if !(defined(__SDCC_pdk14) && defined(TYPE_short)) // Not enough RAM
58 , a10, a11, a15 , a12, a13, a14, a16, a17, a18, a19, a20
59 #endif
61 _data UNSIGNED {type} ua0, ua1, ua2, ua3, ua4, ua5, ua6;
62 _data {type} b;
63 _data volatile UNSIGNED {type} ub = 0xbe;
64 #endif
66 void
67 testcse(void)
69 #if !(defined(__SDCC_pdk14) && defined(TYPE_long)) // Not enough RAM
70 b = 0xeb;
71 ub = 0xbe;
72 v = 0x33;
73 uv = 0x7b;
75 a0 = 0 & b;
76 a1 = 0 & v;
78 a2 = MASK & b;
79 a3 = MASK & v;
80 ua0 = MASK & ub;
81 ua1 = MASK & uv;
83 a4 = b & b;
84 a5 = v & v;
86 a6 &= 0;
87 v &= 0;
88 a7 &= MASK;
89 v &= MASK;
90 ua2 &= MASK;
91 uv &= MASK;
94 a8 = 0 | b;
95 a9 = 0 | v;
97 #if !(defined(__SDCC_pdk14) && defined(TYPE_short)) // Not enough RAM
98 a10 = MASK | b;
99 a11 = MASK | v;
100 ua3 = MASK | ub;
101 ua4 = MASK | uv;
102 a12 = b | b;
103 a13 = v | v;
105 a14 |= 0;
106 #endif
107 v |= 0;
108 #if !(defined(__SDCC_pdk14) && defined(TYPE_short)) // Not enough RAM
109 a15 |= MASK;
110 #endif
111 v |= MASK;
112 ua5 |= MASK;
113 uv |= MASK;
115 #if !(defined(__SDCC_pdk14) && defined(TYPE_short)) // Not enough RAM
116 a16 = 0 ^ b;
117 a17 = 0 ^ v;
119 a18 = b ^ b;
120 a19 = v ^ v;
122 a20 ^= 0;
123 #endif
124 v ^= 0;
126 ASSERT( a0 == 0);
127 ASSERT( a1 == 0);
128 ASSERT( a2 == b);
129 #if defined(TYPE_bool) && defined(__bool_true_false_are_defined)
130 ASSERT( a3 == 1);
131 ASSERT(ua1 == 1);
132 ASSERT( a5 == 1);
133 ASSERT( b == 1);
134 ASSERT( ub == 1);
135 ASSERT(ua0 == 1);
136 ASSERT( a4 == 1);
137 #else
138 ASSERT( a3 == ({type}) 0x33);
139 ASSERT(ua1 == ({type}) 0x7b);
140 ASSERT( a5 == ({type}) 0x33);
141 #endif
142 ASSERT(ua0 == ub);
143 ASSERT( a4 == b);
144 ASSERT( a6 == 0);
145 // ASSERT( a7 == 0);
146 // ASSERT(ua2 == 0);
147 ASSERT( a8 == b);
148 ASSERT( a9 == 0);
149 #if !(defined(__SDCC_pdk14) && defined(TYPE_short)) // Not enough RAM
150 ASSERT( a10 == ({type}) MASK);
151 ASSERT( a11 == ({type}) MASK);
152 ASSERT(ua3 == MASK);
153 ASSERT(ua4 == MASK);
154 ASSERT( a12 == b);
155 ASSERT( a13 == 0);
156 // ASSERT( a14 == 0);
157 ASSERT( a15 == ({type}) MASK);
158 ASSERT(ua5 == MASK);
159 ASSERT( a16 == b);
160 ASSERT( a17 == ({type}) MASK);
161 ASSERT( a18 == 0);
162 ASSERT( a19 == 0);
163 // ASSERT( a20 == 0);
164 #endif
165 ASSERT( v == ({type}) MASK);
166 ASSERT(uv == MASK);
167 #endif