1 struct obstack {};
2 struct bitmap_head_def;
3 typedef struct bitmap_head_def *bitmap;
4 typedef const struct bitmap_head_def *const_bitmap;
5 typedef unsigned long BITMAP_WORD;
6
7 typedef struct bitmap_obstack
8 {
9 struct bitmap_element_def *elements;
10 struct bitmap_head_def *heads;
11 struct obstack obstack;
12 } bitmap_obstack;
13 typedef struct bitmap_element_def
14 {
15 struct bitmap_element_def *next;
16 struct bitmap_element_def *prev;
17 unsigned int indx;
18 BITMAP_WORD bits[(2)];
19 } bitmap_element;
20
21 struct bitmap_descriptor;
22
23 typedef struct bitmap_head_def {
24 bitmap_element *first;
25 bitmap_element *current;
26 unsigned int indx;
27 bitmap_obstack *obstack;
28 } bitmap_head;
29
30 bitmap_element bitmap_zero_bits;
31
32 typedef struct
33 {
34 bitmap_element *elt1;
35 bitmap_element *elt2;
36 unsigned word_no;
37 BITMAP_WORD bits;
38 } bitmap_iterator;
39
40 static __attribute__((noinline)) void
bmp_iter_set_init(bitmap_iterator * bi,const_bitmap map,unsigned start_bit,unsigned * bit_no)41 bmp_iter_set_init (bitmap_iterator *bi, const_bitmap map,
42 unsigned start_bit, unsigned *bit_no)
43 {
44 bi->elt1 = map->first;
45 bi->elt2 = ((void *)0);
46
47 while (1)
48 {
49 if (!bi->elt1)
50 {
51 bi->elt1 = &bitmap_zero_bits;
52 break;
53 }
54
55 if (bi->elt1->indx >= start_bit / (128u))
56 break;
57 bi->elt1 = bi->elt1->next;
58 }
59
60 if (bi->elt1->indx != start_bit / (128u))
61 start_bit = bi->elt1->indx * (128u);
62
63 bi->word_no = start_bit / 64u % (2);
64 bi->bits = bi->elt1->bits[bi->word_no];
65 bi->bits >>= start_bit % 64u;
66
67 start_bit += !bi->bits;
68
69 *bit_no = start_bit;
70 }
71
72 static __inline__ __attribute__((always_inline)) void
bmp_iter_next(bitmap_iterator * bi,unsigned * bit_no)73 bmp_iter_next (bitmap_iterator *bi, unsigned *bit_no)
74 {
75 bi->bits >>= 1;
76 *bit_no += 1;
77 }
78
79 static __inline__ __attribute__((always_inline)) unsigned char
bmp_iter_set(bitmap_iterator * bi,unsigned * bit_no)80 bmp_iter_set (bitmap_iterator *bi, unsigned *bit_no)
81 {
82 if (bi->bits)
83 {
84 while (!(bi->bits & 1))
85 {
86 bi->bits >>= 1;
87 *bit_no += 1;
88 }
89 return 1;
90 }
91
92 *bit_no = ((*bit_no + 64u - 1) / 64u * 64u);
93 bi->word_no++;
94
95 while (1)
96 {
97 while (bi->word_no != (2))
98 {
99 bi->bits = bi->elt1->bits[bi->word_no];
100 if (bi->bits)
101 {
102 while (!(bi->bits & 1))
103 {
104 bi->bits >>= 1;
105 *bit_no += 1;
106 }
107 return 1;
108 }
109 *bit_no += 64u;
110 bi->word_no++;
111 }
112
113 bi->elt1 = bi->elt1->next;
114 if (!bi->elt1)
115 return 0;
116 *bit_no = bi->elt1->indx * (128u);
117 bi->word_no = 0;
118 }
119 }
120
121 static void __attribute__((noinline))
foobar(bitmap_head * live_throughout)122 foobar (bitmap_head *live_throughout)
123 {
124 bitmap_iterator rsi;
125 unsigned int regno;
126 for (bmp_iter_set_init (&(rsi), (live_throughout), (0), &(regno));
127 bmp_iter_set (&(rsi), &(regno));
128 bmp_iter_next (&(rsi), &(regno)))
129 ;
130 }
main()131 int main()
132 {
133 bitmap_element elem = { (void *)0, (void *)0, 0, { 1, 1 } };
134 bitmap_head live_throughout = { &elem, &elem, 0, (void *)0 };
135 foobar (&live_throughout);
136 return 0;
137 }
138
139