1 /* Test arithmetics on bitfields. */
4 extern void abort (void);
5 extern void exit (int);
14 struct { FIELDS1
unsigned int i
: 6, j
: 11, k
: 15; FIELDS2
} b
;
15 struct { FIELDS1
unsigned int i
: 5, j
: 1, k
: 26; FIELDS2
} c
;
16 struct { FIELDS1
unsigned int i
: 16, j
: 8, k
: 8; FIELDS2
} d
;
18 unsigned int ret1 (void) { return b
.i
; }
19 unsigned int ret2 (void) { return b
.j
; }
20 unsigned int ret3 (void) { return b
.k
; }
21 unsigned int ret4 (void) { return c
.i
; }
22 unsigned int ret5 (void) { return c
.j
; }
23 unsigned int ret6 (void) { return c
.k
; }
24 unsigned int ret7 (void) { return d
.i
; }
25 unsigned int ret8 (void) { return d
.j
; }
26 unsigned int ret9 (void) { return d
.k
; }
28 #define T(n, pre, post, op) \
29 void fn1_##n (unsigned int x) { pre b.i post; } \
30 void fn2_##n (unsigned int x) { pre b.j post; } \
31 void fn3_##n (unsigned int x) { pre b.k post; } \
32 void fn4_##n (unsigned int x) { pre c.i post; } \
33 void fn5_##n (unsigned int x) { pre c.j post; } \
34 void fn6_##n (unsigned int x) { pre c.k post; } \
35 void fn7_##n (unsigned int x) { pre d.i post; } \
36 void fn8_##n (unsigned int x) { pre d.j post; } \
37 void fn9_##n (unsigned int x) { pre d.k post; }
39 #include "20040629-1.c"
42 #define FAIL(n, i) abort ()
47 #define T(n, pre, post, op) \
58 if (ret1 () != (op (51, 3) & ((1 << 6) - 1))) \
62 if (ret2 () != (op (636, 251) & ((1 << 11) - 1))) \
66 if (ret3 () != (op (31278, 13279) & ((1 << 15) - 1))) \
70 if (ret4 () != (op (21, 24) & ((1 << 5) - 1))) \
74 if (ret5 () != (op (1, 1) & ((1 << 1) - 1))) \
78 if (ret6 () != (op (33554432, 264151) & ((1 << 26) - 1))) \
82 if (ret7 () != (op (26812, 713) & ((1 << 16) - 1))) \
86 if (ret8 () != (op (156, 17) & ((1 << 8) - 1))) \
90 if (ret9 () != (op (187, 199) & ((1 << 8) - 1))) \
94 #include "20040629-1.c"
102 #define opadd(x, y) (x + y)
103 #define opsub(x, y) (x - y)
104 #define opinc(x, y) (x + 1)
105 #define opdec(x, y) (x - 1)
106 #define opand(x, y) (x & y)
107 #define opior(x, y) (x | y)
108 #define opxor(x, y) (x ^ y)
109 #define opdiv(x, y) (x / y)
110 #define oprem(x, y) (x % y)
111 #define opadd3(x, y) (x + 3)
112 #define opsub7(x, y) (x - 7)
113 #define opand21(x, y) (x & 21)
114 #define opior19(x, y) (x | 19)
115 #define opxor37(x, y) (x ^ 37)
116 #define opdiv17(x, y) (x / 17)
117 #define oprem19(x, y) (x % 19)
133 T(e
, , &= 21, opand21
)
134 T(f
, , |= 19, opior19
)
135 T(g
, , ^= 37, opxor37
)
136 T(h
, , /= 17, opdiv17
)
137 T(i
, , %= 19, oprem19
)