1 /* Copyright (C) 2002 Free Software Foundation.
3 Test that (A & C1) op C2 optimizations behave correctly where C1 is
4 a constant power of 2, op is == or !=, and C2 is C1 or zero.
6 Written by Roger Sayle, 5th May 2002. */
10 extern void abort (void);
12 void test1 (signed char c
, int set
);
13 void test2 (unsigned char c
, int set
);
14 void test3 (short s
, int set
);
15 void test4 (unsigned short s
, int set
);
16 void test5 (int i
, int set
);
17 void test6 (unsigned int i
, int set
);
18 void test7 (long long l
, int set
);
19 void test8 (unsigned long long l
, int set
);
22 #define LONG_LONG_MAX __LONG_LONG_MAX__
25 #define LONG_LONG_MIN (-LONG_LONG_MAX-1)
27 #ifndef ULONG_LONG_MAX
28 #define ULONG_LONG_MAX (LONG_LONG_MAX * 2ULL + 1)
33 test1 (signed char c
, int set
)
35 if ((c
& (SCHAR_MAX
+1)) == 0)
42 if ((c
& (SCHAR_MAX
+1)) != 0)
49 if ((c
& (SCHAR_MAX
+1)) == (SCHAR_MAX
+1))
56 if ((c
& (SCHAR_MAX
+1)) != (SCHAR_MAX
+1))
65 test2 (unsigned char c
, int set
)
67 if ((c
& (SCHAR_MAX
+1)) == 0)
74 if ((c
& (SCHAR_MAX
+1)) != 0)
81 if ((c
& (SCHAR_MAX
+1)) == (SCHAR_MAX
+1))
88 if ((c
& (SCHAR_MAX
+1)) != (SCHAR_MAX
+1))
97 test3 (short s
, int set
)
99 if ((s
& (SHRT_MAX
+1)) == 0)
106 if ((s
& (SHRT_MAX
+1)) != 0)
113 if ((s
& (SHRT_MAX
+1)) == (SHRT_MAX
+1))
120 if ((s
& (SHRT_MAX
+1)) != (SHRT_MAX
+1))
129 test4 (unsigned short s
, int set
)
131 if ((s
& (SHRT_MAX
+1)) == 0)
138 if ((s
& (SHRT_MAX
+1)) != 0)
145 if ((s
& (SHRT_MAX
+1)) == (SHRT_MAX
+1))
152 if ((s
& (SHRT_MAX
+1)) != (SHRT_MAX
+1))
161 test5 (int i
, int set
)
163 if ((i
& (INT_MAX
+1U)) == 0)
170 if ((i
& (INT_MAX
+1U)) != 0)
177 if ((i
& (INT_MAX
+1U)) == (INT_MAX
+1U))
184 if ((i
& (INT_MAX
+1U)) != (INT_MAX
+1U))
193 test6 (unsigned int i
, int set
)
195 if ((i
& (INT_MAX
+1U)) == 0)
202 if ((i
& (INT_MAX
+1U)) != 0)
209 if ((i
& (INT_MAX
+1U)) == (INT_MAX
+1U))
216 if ((i
& (INT_MAX
+1U)) != (INT_MAX
+1U))
225 test7 (long long l
, int set
)
227 if ((l
& (LONG_LONG_MAX
+1ULL)) == 0)
234 if ((l
& (LONG_LONG_MAX
+1ULL)) != 0)
241 if ((l
& (LONG_LONG_MAX
+1ULL)) == (LONG_LONG_MAX
+1ULL))
248 if ((l
& (LONG_LONG_MAX
+1ULL)) != (LONG_LONG_MAX
+1ULL))
257 test8 (unsigned long long l
, int set
)
259 if ((l
& (LONG_LONG_MAX
+1ULL)) == 0)
266 if ((l
& (LONG_LONG_MAX
+1ULL)) != 0)
273 if ((l
& (LONG_LONG_MAX
+1ULL)) == (LONG_LONG_MAX
+1ULL))
280 if ((l
& (LONG_LONG_MAX
+1ULL)) != (LONG_LONG_MAX
+1ULL))
292 test1 (SCHAR_MAX
, 0);
293 test1 (SCHAR_MIN
, 1);
294 test1 (UCHAR_MAX
, 1);
297 test2 (SCHAR_MAX
, 0);
298 test2 (SCHAR_MIN
, 1);
299 test2 (UCHAR_MAX
, 1);
304 test3 (USHRT_MAX
, 1);
309 test4 (USHRT_MAX
, 1);
322 test7 (LONG_LONG_MAX
, 0);
323 test7 (LONG_LONG_MIN
, 1);
324 test7 (ULONG_LONG_MAX
, 1);
327 test8 (LONG_LONG_MAX
, 0);
328 test8 (LONG_LONG_MIN
, 1);
329 test8 (ULONG_LONG_MAX
, 1);