@@ -86,37 +86,42 @@ static void pmix_pointer_array_destruct(pmix_pointer_array_t *array)
86
86
* A classical find first zero bit (ffs) on a large array. It checks starting
87
87
* from the indicated position until it finds a zero bit. If SET is true,
88
88
* the bit is set. The position of the bit is returned in store.
89
+ *
90
+ * According to Section 6.4.4.1 of the C standard we don't need to prepend a type
91
+ * indicator to constants (the type is inferred by the compiler according to
92
+ * the number of bits necessary to represent it).
89
93
*/
90
- #define FIND_FIRST_ZERO (START_IDX , STORE , SET ) \
94
+ #define FIND_FIRST_ZERO (START_IDX , STORE ) \
91
95
do { \
92
96
uint32_t __b_idx, __b_pos; \
97
+ if( 0 == table->number_free ) { \
98
+ (STORE) = table->size; \
99
+ break; \
100
+ } \
93
101
GET_BIT_POS((START_IDX), __b_idx, __b_pos); \
94
- for (; table->free_bits[__b_idx] == 0xFFFFFFFFFFFFFFFFULL ; __b_idx++); \
102
+ for (; table->free_bits[__b_idx] == 0xFFFFFFFFFFFFFFFFu ; __b_idx++); \
95
103
assert(__b_idx < (uint32_t)table->size); \
96
104
uint64_t __check_value = table->free_bits[__b_idx]; \
97
105
__b_pos = 0; \
98
106
\
99
- if( 0x00000000FFFFFFFFULL == (__check_value & 0x00000000FFFFFFFFULL ) ) { \
107
+ if( 0x00000000FFFFFFFFu == (__check_value & 0x00000000FFFFFFFFu ) ) { \
100
108
__check_value >>= 32; __b_pos += 32; \
101
109
} \
102
- if( 0x000000000000FFFFULL == (__check_value & 0x000000000000FFFFULL ) ) { \
110
+ if( 0x000000000000FFFFu == (__check_value & 0x000000000000FFFFu ) ) { \
103
111
__check_value >>= 16; __b_pos += 16; \
104
112
} \
105
- if( 0x00000000000000FFULL == (__check_value & 0x00000000000000FFULL ) ) { \
113
+ if( 0x00000000000000FFu == (__check_value & 0x00000000000000FFu ) ) { \
106
114
__check_value >>= 8; __b_pos += 8; \
107
115
} \
108
- if( 0x000000000000000FULL == (__check_value & 0x000000000000000FULL ) ) { \
116
+ if( 0x000000000000000Fu == (__check_value & 0x000000000000000Fu ) ) { \
109
117
__check_value >>= 4; __b_pos += 4; \
110
118
} \
111
- if( 0x0000000000000003ULL == (__check_value & 0x0000000000000003ULL ) ) { \
119
+ if( 0x0000000000000003u == (__check_value & 0x0000000000000003u ) ) { \
112
120
__check_value >>= 2; __b_pos += 2; \
113
121
} \
114
- if( 0x0000000000000001ULL == (__check_value & 0x0000000000000001ULL ) ) { \
122
+ if( 0x0000000000000001u == (__check_value & 0x0000000000000001u ) ) { \
115
123
__b_pos += 1; \
116
124
} \
117
- if( (SET) ) { \
118
- table->free_bits[__b_idx] |= (1ULL << __b_pos); \
119
- } \
120
125
(STORE) = (__b_idx * 8 * sizeof(uint64_t)) + __b_pos; \
121
126
} while(0)
122
127
@@ -127,8 +132,8 @@ static void pmix_pointer_array_destruct(pmix_pointer_array_t *array)
127
132
do { \
128
133
uint32_t __b_idx, __b_pos; \
129
134
GET_BIT_POS((IDX), __b_idx, __b_pos); \
130
- assert( 0 == (table->free_bits[__b_idx] & (1UL << __b_pos))); \
131
- table->free_bits[__b_idx] |= (1ULL << __b_pos); \
135
+ assert( 0 == (table->free_bits[__b_idx] & (((uint64_t)1) << __b_pos))); \
136
+ table->free_bits[__b_idx] |= (((uint64_t)1) << __b_pos); \
132
137
} while(0)
133
138
134
139
/**
@@ -138,8 +143,8 @@ static void pmix_pointer_array_destruct(pmix_pointer_array_t *array)
138
143
do { \
139
144
uint32_t __b_idx, __b_pos; \
140
145
GET_BIT_POS((IDX), __b_idx, __b_pos); \
141
- assert( (table->free_bits[__b_idx] & (1UL << __b_pos))); \
142
- table->free_bits[__b_idx] ^= (1ULL << __b_pos); \
146
+ assert( (table->free_bits[__b_idx] & (((uint64_t)1) << __b_pos))); \
147
+ table->free_bits[__b_idx] ^= (((uint64_t)1) << __b_pos); \
143
148
} while(0)
144
149
145
150
#if 0
@@ -157,9 +162,9 @@ static void pmix_pointer_array_validate(pmix_pointer_array_t *array)
157
162
GET_BIT_POS (i , b_idx , p_idx );
158
163
if ( NULL == array -> addr [i ] ) {
159
164
cnt ++ ;
160
- assert ( 0 == (array -> free_bits [b_idx ] & (1ULL << p_idx )) );
165
+ assert ( 0 == (array -> free_bits [b_idx ] & ((( uint64_t ) 1 ) << p_idx )) );
161
166
} else {
162
- assert ( 0 != (array -> free_bits [b_idx ] & (1ULL << p_idx )) );
167
+ assert ( 0 != (array -> free_bits [b_idx ] & ((( uint64_t ) 1 ) << p_idx )) );
163
168
}
164
169
}
165
170
assert (cnt == array -> number_free );
@@ -236,7 +241,7 @@ int pmix_pointer_array_add(pmix_pointer_array_t *table, void *ptr)
236
241
table -> number_free -- ;
237
242
SET_BIT (index );
238
243
if (table -> number_free > 0 ) {
239
- FIND_FIRST_ZERO (index , table -> lowest_free , 0 );
244
+ FIND_FIRST_ZERO (index , table -> lowest_free );
240
245
} else {
241
246
table -> lowest_free = table -> size ;
242
247
}
@@ -290,7 +295,7 @@ int pmix_pointer_array_set_item(pmix_pointer_array_t *table, int index,
290
295
SET_BIT (index );
291
296
/* Reset lowest_free if required */
292
297
if ( index == table -> lowest_free ) {
293
- FIND_FIRST_ZERO (index , table -> lowest_free , 0 );
298
+ FIND_FIRST_ZERO (index , table -> lowest_free );
294
299
}
295
300
} else {
296
301
assert ( index != table -> lowest_free );
@@ -362,7 +367,7 @@ bool pmix_pointer_array_test_and_set_item (pmix_pointer_array_t *table,
362
367
/* Reset lowest_free if required */
363
368
if ( table -> number_free > 0 ) {
364
369
if ( index == table -> lowest_free ) {
365
- FIND_FIRST_ZERO (index , table -> lowest_free , 0 );
370
+ FIND_FIRST_ZERO (index , table -> lowest_free );
366
371
}
367
372
} else {
368
373
table -> lowest_free = table -> size ;
0 commit comments