| 1 |
#include <limits.h> |
| 2 |
|
| 3 |
extern void abort (); |
| 4 |
|
| 5 |
int test1(int x) |
| 6 |
{ |
| 7 |
return (x ^ INT_MIN) ^ 0x1234; |
| 8 |
} |
| 9 |
|
| 10 |
unsigned int test1u(unsigned int x) |
| 11 |
{ |
| 12 |
return (x ^ (unsigned int)INT_MIN) ^ 0x1234; |
| 13 |
} |
| 14 |
|
| 15 |
int test2(int x) |
| 16 |
{ |
| 17 |
return (x ^ 0x1234) ^ INT_MIN; |
| 18 |
} |
| 19 |
|
| 20 |
unsigned int test2u(unsigned int x) |
| 21 |
{ |
| 22 |
return (x ^ 0x1234) ^ (unsigned int)INT_MIN; |
| 23 |
} |
| 24 |
|
| 25 |
unsigned int test3u(unsigned int x) |
| 26 |
{ |
| 27 |
return (x + (unsigned int)INT_MIN) ^ 0x1234; |
| 28 |
} |
| 29 |
|
| 30 |
unsigned int test4u(unsigned int x) |
| 31 |
{ |
| 32 |
return (x ^ 0x1234) + (unsigned int)INT_MIN; |
| 33 |
} |
| 34 |
|
| 35 |
unsigned int test5u(unsigned int x) |
| 36 |
{ |
| 37 |
return (x - (unsigned int)INT_MIN) ^ 0x1234; |
| 38 |
} |
| 39 |
|
| 40 |
unsigned int test6u(unsigned int x) |
| 41 |
{ |
| 42 |
return (x ^ 0x1234) - (unsigned int)INT_MIN; |
| 43 |
} |
| 44 |
|
| 45 |
int test7(int x) |
| 46 |
{ |
| 47 |
int y = INT_MIN; |
| 48 |
int z = 0x1234; |
| 49 |
return (x ^ y) ^ z; |
| 50 |
} |
| 51 |
|
| 52 |
unsigned int test7u(unsigned int x) |
| 53 |
{ |
| 54 |
unsigned int y = (unsigned int)INT_MIN; |
| 55 |
unsigned int z = 0x1234; |
| 56 |
return (x ^ y) ^ z; |
| 57 |
} |
| 58 |
|
| 59 |
int test8(int x) |
| 60 |
{ |
| 61 |
int y = 0x1234; |
| 62 |
int z = INT_MIN; |
| 63 |
return (x ^ y) ^ z; |
| 64 |
} |
| 65 |
|
| 66 |
unsigned int test8u(unsigned int x) |
| 67 |
{ |
| 68 |
unsigned int y = 0x1234; |
| 69 |
unsigned int z = (unsigned int)INT_MIN; |
| 70 |
return (x ^ y) ^ z; |
| 71 |
} |
| 72 |
|
| 73 |
unsigned int test9u(unsigned int x) |
| 74 |
{ |
| 75 |
unsigned int y = (unsigned int)INT_MIN; |
| 76 |
unsigned int z = 0x1234; |
| 77 |
return (x + y) ^ z; |
| 78 |
} |
| 79 |
|
| 80 |
unsigned int test10u(unsigned int x) |
| 81 |
{ |
| 82 |
unsigned int y = 0x1234; |
| 83 |
unsigned int z = (unsigned int)INT_MIN; |
| 84 |
return (x ^ y) + z; |
| 85 |
} |
| 86 |
|
| 87 |
unsigned int test11u(unsigned int x) |
| 88 |
{ |
| 89 |
unsigned int y = (unsigned int)INT_MIN; |
| 90 |
unsigned int z = 0x1234; |
| 91 |
return (x - y) ^ z; |
| 92 |
} |
| 93 |
|
| 94 |
unsigned int test12u(unsigned int x) |
| 95 |
{ |
| 96 |
unsigned int y = 0x1234; |
| 97 |
unsigned int z = (unsigned int)INT_MIN; |
| 98 |
return (x ^ y) - z; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
void test(int a, int b) |
| 103 |
{ |
| 104 |
if (test1(a) != b) |
| 105 |
abort(); |
| 106 |
if (test2(a) != b) |
| 107 |
abort(); |
| 108 |
if (test7(a) != b) |
| 109 |
abort(); |
| 110 |
if (test8(a) != b) |
| 111 |
abort(); |
| 112 |
} |
| 113 |
|
| 114 |
void testu(unsigned int a, unsigned int b) |
| 115 |
{ |
| 116 |
if (test1u(a) != b) |
| 117 |
abort(); |
| 118 |
if (test2u(a) != b) |
| 119 |
abort(); |
| 120 |
if (test3u(a) != b) |
| 121 |
abort(); |
| 122 |
if (test4u(a) != b) |
| 123 |
abort(); |
| 124 |
if (test5u(a) != b) |
| 125 |
abort(); |
| 126 |
if (test6u(a) != b) |
| 127 |
abort(); |
| 128 |
if (test7u(a) != b) |
| 129 |
abort(); |
| 130 |
if (test8u(a) != b) |
| 131 |
abort(); |
| 132 |
if (test9u(a) != b) |
| 133 |
abort(); |
| 134 |
if (test10u(a) != b) |
| 135 |
abort(); |
| 136 |
if (test11u(a) != b) |
| 137 |
abort(); |
| 138 |
if (test12u(a) != b) |
| 139 |
abort(); |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
int main() |
| 144 |
{ |
| 145 |
#if INT_MAX == 2147483647 |
| 146 |
test(0x00000000,0x80001234); |
| 147 |
test(0x00001234,0x80000000); |
| 148 |
test(0x80000000,0x00001234); |
| 149 |
test(0x80001234,0x00000000); |
| 150 |
test(0x7fffffff,0xffffedcb); |
| 151 |
test(0xffffffff,0x7fffedcb); |
| 152 |
|
| 153 |
testu(0x00000000,0x80001234); |
| 154 |
testu(0x00001234,0x80000000); |
| 155 |
testu(0x80000000,0x00001234); |
| 156 |
testu(0x80001234,0x00000000); |
| 157 |
testu(0x7fffffff,0xffffedcb); |
| 158 |
testu(0xffffffff,0x7fffedcb); |
| 159 |
#endif |
| 160 |
|
| 161 |
#if INT_MAX == 32767 |
| 162 |
test(0x0000,0x9234); |
| 163 |
test(0x1234,0x8000); |
| 164 |
test(0x8000,0x1234); |
| 165 |
test(0x9234,0x0000); |
| 166 |
test(0x7fff,0xedcb); |
| 167 |
test(0xffff,0x6dcb); |
| 168 |
|
| 169 |
testu(0x0000,0x9234); |
| 170 |
testu(0x8000,0x1234); |
| 171 |
testu(0x1234,0x8000); |
| 172 |
testu(0x9234,0x0000); |
| 173 |
testu(0x7fff,0xedcb); |
| 174 |
testu(0xffff,0x6dcb); |
| 175 |
#endif |
| 176 |
|
| 177 |
return 0; |
| 178 |
} |
| 179 |
|