Changeset 75ff31607066f7bcb0b471c3652443662c0f985f
- Timestamp:
- 04/30/08 14:32:42 (8 months ago)
- Parents:
- 1c4d613e749d9e677b5d4a13214e93bfee485937
- Children:
- 1bc545c8942b47e034f824644b4834a991178afc
- git-committer:
- krayouva <krayouva@gmail.com> / 2008-04-30T00:32:42Z-0400
- Location:
- c
- Files:
-
- 2 modified
-
include/global.h (modified) (2 diffs)
-
src/bitvector.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
c/include/global.h
red4cf5 r75ff31 133 133 134 134 /** 135 * Returns the count of leading [MSB] 0 bits in +word+. 136 */ 137 extern FRT_ATTR_ALWAYS_INLINE FRT_ATTR_CONST 138 int frt_count_leading_zeros(frt_u32 word) 139 { 140 #ifdef __GNUC__ 141 return __builtin_clz(word); 142 #else 143 static const int count_leading_zeros[] = { 144 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 145 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 146 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 147 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 148 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 149 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 150 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 151 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 152 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 153 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 154 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 156 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 157 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 158 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 159 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 160 }; 161 if (word & 0xff) return count_leading_zeros[word & 0xff]; 162 word >>= 8; if (word & 0xff) return count_leading_zeros[word & 0xff] + 8; 163 word >>= 8; if (word & 0xff) return count_leading_zeros[word & 0xff] + 16; 164 word >>= 8; return count_leading_zeros[word & 0xff] + 24; 165 #endif 166 } 167 168 extern FRT_ATTR_ALWAYS_INLINE FRT_ATTR_CONST 169 int frt_count_leading_ones(frt_u32 word) 170 { 171 return frt_count_leading_zeros(~word); 172 } 173 174 /** 135 175 * Return the count of trailing [LSB] 0 bits in +word+. 136 176 */ … … 211 251 212 252 /** 253 * Round up to the next power of 2 254 */ 255 extern FRT_ATTR_ALWAYS_INLINE FRT_ATTR_CONST 256 int frt_round2(frt_u32 word) 257 { 258 return 1 << (32 - frt_count_leading_zeros(word)); 259 } 260 261 /** 213 262 * For coverage, we don't want FRT_XEXIT to actually exit on uncaught 214 263 * exceptions. +frt_x_abort_on_exception+ is +true+ by default, set it to -
c/src/bitvector.c
r1c4d61 r75ff31 1 1 #include "bitvector.h" 2 #include "internal.h" 2 3 #include <string.h> 3 #include "internal.h"4 4 5 5 BitVector *bv_new_capa(int capa) … … 126 126 } 127 127 } 128 hash = (hash << 1) | bv->extends_as_ones; 129 return hash; 128 return (hash << 1) | bv->extends_as_ones; 129 } 130 131 static INLINE void bv_capa(BitVector *bv, int capa, int size) 132 { 133 int word_size = (size >> 5) + 1; 134 REALLOC_N(bv->bits, u32, capa); 135 bv->capa = capa; 136 bv->size = size; 137 memset(bv->bits + word_size, (bv->extends_as_ones ? 0xFF : 0), 138 sizeof(u32) * (capa - word_size)); 130 139 } 131 140 … … 147 156 int capa = 4; 148 157 149 if (bv1->extends_as_ones && bv2->extends_as_ones) { 150 size = max2(bv1->size, bv2->size); 151 bv->extends_as_ones = true; 152 } 153 else if (bv1->extends_as_ones || bv2->extends_as_ones) { 154 size = max2(bv1->size, bv2->size); 155 bv->extends_as_ones = false; 156 } 157 else { 158 size = min2(bv1->size, bv2->size); 159 bv->extends_as_ones = false; 160 } 158 bv->extends_as_ones = (bv1->extends_as_ones & bv2->extends_as_ones); 159 160 if (bv1->extends_as_ones || bv2->extends_as_ones) 161 size = max2(bv1->size, bv2->size); 162 else size = min2(bv1->size, bv2->size); 161 163 162 164 word_size = (size >> 5) + 1; 163 while (capa < word_size) { 164 capa <<= 1; 165 } 165 capa = max2(frt_round2(word_size), 4); 166 166 167 bv_recapa(bv1, capa); 167 168 bv_recapa(bv2, capa); 168 REALLOC_N(bv->bits, u32, capa); 169 bv->capa = capa; 170 bv->size = size; 171 172 memset(bv->bits + word_size, (bv->extends_as_ones ? 0xFF : 0), 173 sizeof(u32) * (capa - word_size)); 169 bv_capa(bv, capa, size); 174 170 175 171 for (i = 0; i < word_size; i++) { … … 196 192 int max_size = max2(bv1->size, bv2->size); 197 193 int word_size = (max_size >> 5) + 1; 198 int capa = 4; 199 while (capa < word_size) { 200 capa <<= 1; 201 } 202 REALLOC_N(bv->bits, u32, capa); 203 bv->capa = capa; 204 bv->size = max_size; 205 194 int capa = max2(frt_round2(word_size), 4); 195 196 bv->extends_as_ones = (bv1->extends_as_ones | bv2->extends_as_ones); 206 197 bv_recapa(bv1, capa); 207 198 bv_recapa(bv2, capa); 208 209 if (bv1->extends_as_ones || bv2->extends_as_ones) { 210 bv->extends_as_ones = true; 211 } 212 else { 213 bv->extends_as_ones = false; 214 } 215 216 memset(bv->bits + word_size, (bv->extends_as_ones ? 0xFF : 0), 217 sizeof(u32) * (capa - word_size)); 199 bv_capa(bv, capa, max_size); 218 200 219 201 for (i = 0; i < word_size; i++) { … … 239 221 int max_size = max2(bv1->size, bv2->size); 240 222 int word_size = (max_size >> 5) + 1; 241 int capa = 4; 242 while (capa < word_size) { 243 capa <<= 1; 244 } 245 REALLOC_N(bv->bits, u32, capa); 246 bv->capa = capa; 247 bv->size = max_size; 248 223 int capa = max2(frt_round2(word_size), 4); 224 225 bv->extends_as_ones = (bv1->extends_as_ones ^ bv2->extends_as_ones); 249 226 bv_recapa(bv1, capa); 250 227 bv_recapa(bv2, capa); 251 252 if (bv1->extends_as_ones != bv2->extends_as_ones) { 253 bv->extends_as_ones = true; 254 } 255 else { 256 bv->extends_as_ones = false; 257 } 258 259 memset(bv->bits + word_size, (bv->extends_as_ones ? 0xFF : 0), 260 sizeof(u32) * (capa - word_size)); 228 bv_capa(bv, capa, max_size); 261 229 262 230 for (i = 0; i < word_size; i++) { … … 281 249 int i; 282 250 int word_size = (bv1->size >> 5) + 1; 283 int capa = 4; 284 while (capa < word_size) { 285 capa <<= 1; 286 } 287 REALLOC_N(bv->bits, u32, capa); 288 bv->capa = capa; 289 bv->size = bv1->size; 251 int capa = max2(frt_round2(word_size), 4); 252 290 253 bv->extends_as_ones = !bv1->extends_as_ones; 291 memset(bv->bits + word_size, (bv->extends_as_ones ? 0xFF : 0), 292 sizeof(u32) * (capa - word_size)); 254 bv_capa(bv, capa, bv1->size); 293 255 294 256 for (i = 0; i < word_size; i++) {
