| 1 |
#define func(vol, op1, op2) \ |
| 2 |
_Bool op1##_##op2##_##vol (int a, int b) \ |
| 3 |
{ \ |
| 4 |
vol int x = op_##op1(a, b); \ |
| 5 |
return op_##op2(x, a); \ |
| 6 |
} |
| 7 |
|
| 8 |
#define op_lt(a, b) ((a) < (b)) |
| 9 |
#define op_le(a, b) ((a) <= (b)) |
| 10 |
#define op_eq(a, b) ((a) == (b)) |
| 11 |
#define op_ne(a, b) ((a) != (b)) |
| 12 |
#define op_gt(a, b) ((a) > (b)) |
| 13 |
#define op_ge(a, b) ((a) >= (b)) |
| 14 |
#define op_min(a, b) ((a) < (b) ? (a) : (b)) |
| 15 |
#define op_max(a, b) ((a) > (b) ? (a) : (b)) |
| 16 |
|
| 17 |
|
| 18 |
#define funcs(a) \ |
| 19 |
a(min,lt) \ |
| 20 |
a(max,lt) \ |
| 21 |
a(min,gt) \ |
| 22 |
a(max,gt) \ |
| 23 |
a(min,le) \ |
| 24 |
a(max,le) \ |
| 25 |
a(min,ge) \ |
| 26 |
a(max,ge) \ |
| 27 |
a(min,ne) \ |
| 28 |
a(max,ne) \ |
| 29 |
a(min,eq) \ |
| 30 |
a(max,eq) |
| 31 |
|
| 32 |
#define funcs1(a,b) \ |
| 33 |
func(,a,b) \ |
| 34 |
func(volatile,a,b) |
| 35 |
|
| 36 |
funcs(funcs1) |
| 37 |
|
| 38 |
#define test(op1,op2) \ |
| 39 |
do { \ |
| 40 |
if (op1##_##op2##_(x,y) != op1##_##op2##_volatile(x,y)) \ |
| 41 |
__builtin_abort(); \ |
| 42 |
} while(0); |
| 43 |
|
| 44 |
int main() |
| 45 |
{ |
| 46 |
for(int x = -10; x < 10; x++) |
| 47 |
for(int y = -10; y < 10; y++) |
| 48 |
{ |
| 49 |
funcs(test) |
| 50 |
} |
| 51 |
} |