Changeset 1887 in kBuild
- Timestamp:
- Oct 19, 2008 11:08:10 PM (16 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/Makefile.kmk
r1870 r1887 144 144 KMK \ 145 145 KMK_HELPERS \ 146 VARIABLE_HASH \147 146 CONFIG_NO_DEFAULT_SUFFIXES \ 148 147 CONFIG_NO_DEFAULT_PATTERN_RULES \ -
trunk/src/kmk/strcache2.c
r1885 r1887 259 259 } 260 260 261 #if 0 /* FIXME: Use this (salvaged from variable.c) */ 262 263 MY_INLINE int 264 variable_hash_cmp_2_memcmp (const char *xs, const char *ys, unsigned int length) 265 { 266 /* short string compare - ~50% of the kBuild calls. */ 267 assert ( !((size_t)ys & 3) ); 268 if (!((size_t)xs & 3)) 269 { 270 /* aligned */ 271 int result; 272 switch (length) 273 { 274 case 8: 275 result = *(int32_t*)(xs + 4) - *(int32_t*)(ys + 4); 276 result |= *(int32_t*)xs - *(int32_t*)ys; 277 return result; 278 case 7: 279 result = xs[6] - ys[6]; 280 result |= xs[5] - ys[5]; 281 result |= xs[4] - ys[4]; 282 result |= *(int32_t*)xs - *(int32_t*)ys; 283 return result; 284 case 6: 285 result = xs[5] - ys[5]; 286 result |= xs[4] - ys[4]; 287 result |= *(int32_t*)xs - *(int32_t*)ys; 288 return result; 289 case 5: 290 result = xs[4] - ys[4]; 291 result |= *(int32_t*)xs - *(int32_t*)ys; 292 return result; 293 case 4: 294 return *(int32_t*)xs - *(int32_t*)ys; 295 case 3: 296 result = xs[2] - ys[2]; 297 result |= xs[1] - ys[1]; 298 result |= xs[0] - ys[0]; 299 return result; 300 case 2: 301 result = xs[1] - ys[1]; 302 result |= xs[0] - ys[0]; 303 return result; 304 case 1: 305 return *xs - *ys; 306 case 0: 307 return 0; 308 } 309 } 310 else 311 { 312 /* unaligned */ 313 int result = 0; 314 switch (length) 315 { 316 case 8: result |= xs[7] - ys[7]; 317 case 7: result |= xs[6] - ys[6]; 318 case 6: result |= xs[5] - ys[5]; 319 case 5: result |= xs[4] - ys[4]; 320 case 4: result |= xs[3] - ys[3]; 321 case 3: result |= xs[2] - ys[2]; 322 case 2: result |= xs[1] - ys[1]; 323 case 1: result |= xs[0] - ys[0]; 324 case 0: 325 return result; 326 } 327 } 328 329 /* memcmp for longer strings */ 330 # ifdef __GNUC__ 331 return __builtin_memcmp (xs, ys, length); 332 # else 333 return memcmp (xs, ys, length); 334 # endif 335 } 336 337 MY_INLINE int 338 variable_hash_cmp_2_inlined (const char *xs, const char *ys, unsigned int length) 339 { 340 #ifndef ELECTRIC_HEAP 341 assert ( !((size_t)ys & 3) ); 342 #endif 343 if (!((size_t)xs & 3)) 344 { 345 int result; 346 /* aligned */ 347 while (length >= 8) 348 { 349 result = *(int32_t*)xs - *(int32_t*)ys; 350 result |= *(int32_t*)(xs + 4) - *(int32_t*)(ys + 4); 351 if (MY_PREDICT_FALSE(result)) 352 return result; 353 xs += 8; 354 ys += 8; 355 length -= 8; 356 } 357 switch (length) 358 { 359 case 7: 360 result = *(int32_t*)xs - *(int32_t*)ys; 361 result |= xs[6] - ys[6]; 362 result |= xs[5] - ys[5]; 363 result |= xs[4] - ys[4]; 364 return result; 365 case 6: 366 result = *(int32_t*)xs - *(int32_t*)ys; 367 result |= xs[5] - ys[5]; 368 result |= xs[4] - ys[4]; 369 return result; 370 case 5: 371 result = *(int32_t*)xs - *(int32_t*)ys; 372 result |= xs[4] - ys[4]; 373 return result; 374 case 4: 375 return *(int32_t*)xs - *(int32_t*)ys; 376 case 3: 377 result = xs[2] - ys[2]; 378 result |= xs[1] - ys[1]; 379 result |= xs[0] - ys[0]; 380 return result; 381 case 2: 382 result = xs[1] - ys[1]; 383 result |= xs[0] - ys[0]; 384 return result; 385 case 1: 386 return *xs - *ys; 387 default: 388 case 0: 389 return 0; 390 } 391 } 392 else 393 { 394 /* unaligned */ 395 int result; 396 while (length >= 8) 397 { 398 #if defined(__i386__) || defined(__x86_64__) 399 result = ( ((int32_t)xs[3] << 24) 400 | ((int32_t)xs[2] << 16) 401 | ((int32_t)xs[1] << 8) 402 | xs[0] ) 403 - *(int32_t*)ys; 404 result |= ( ((int32_t)xs[7] << 24) 405 | ((int32_t)xs[6] << 16) 406 | ((int32_t)xs[5] << 8) 407 | xs[4] ) 408 - *(int32_t*)(ys + 4); 409 #else 410 result = xs[3] - ys[3]; 411 result |= xs[2] - ys[2]; 412 result |= xs[1] - ys[1]; 413 result |= xs[0] - ys[0]; 414 result |= xs[7] - ys[7]; 415 result |= xs[6] - ys[6]; 416 result |= xs[5] - ys[5]; 417 result |= xs[4] - ys[4]; 418 #endif 419 if (MY_PREDICT_FALSE(result)) 420 return result; 421 xs += 8; 422 ys += 8; 423 length -= 8; 424 } 425 result = 0; 426 switch (length) 427 { 428 case 7: result |= xs[6] - ys[6]; 429 case 6: result |= xs[5] - ys[5]; 430 case 5: result |= xs[4] - ys[4]; 431 case 4: result |= xs[3] - ys[3]; 432 case 3: result |= xs[2] - ys[2]; 433 case 2: result |= xs[1] - ys[1]; 434 case 1: result |= xs[0] - ys[0]; 435 return result; 436 default: 437 case 0: 438 return 0; 439 } 440 } 441 } 442 443 #endif 444 261 445 MY_INLINE int 262 446 strcache2_is_equal (struct strcache2 *cache, struct strcache2_entry const *entry, … … 375 559 } 376 560 377 /* The public add /lookupstring interface. */561 /* The public add string interface. */ 378 562 const char * 379 563 strcache2_add (struct strcache2 *cache, const char *str, unsigned int length) … … 428 612 } 429 613 430 /* The public add /lookupstring interface for prehashed strings.614 /* The public add string interface for prehashed strings. 431 615 Use strcache2_hash_str to calculate the hash of a string. */ 432 616 const char * … … 494 678 } 495 679 680 /* The public lookup string interface. */ 681 const char * 682 strcache2_lookup (struct strcache2 *cache, const char *str, unsigned int length) 683 { 684 struct strcache2_entry const *entry; 685 unsigned int hash2; 686 unsigned int hash1 = strcache2_case_sensitive_hash_1 (str, length); 687 unsigned int idx; 688 689 assert (!cache->case_insensitive); 690 691 cache->lookup_count++; 692 693 /* Lookup the entry in the hash table, hoping for an 694 early match. */ 695 idx = hash1 & cache->hash_mask; 696 entry = cache->hash_tab[idx]; 697 if (strcache2_is_equal (cache, entry, str, length, hash1)) 698 return (const char *)(entry + 1); 699 if (!entry) 700 hash2 = 0; 701 else 702 { 703 cache->collision_1st_count++; 704 705 hash2 = strcache2_case_sensitive_hash_2 (str, length); 706 idx += hash2; 707 idx &= cache->hash_mask; 708 entry = cache->hash_tab[idx]; 709 if (strcache2_is_equal (cache, entry, str, length, hash1)) 710 return (const char *)(entry + 1); 711 712 if (entry) 713 { 714 cache->collision_2nd_count++; 715 do 716 { 717 idx += hash2; 718 idx &= cache->hash_mask; 719 entry = cache->hash_tab[idx]; 720 cache->collision_3rd_count++; 721 if (strcache2_is_equal (cache, entry, str, length, hash1)) 722 return (const char *)(entry + 1); 723 } 724 while (entry); 725 } 726 } 727 728 /* Not found. */ 729 return NULL; 730 } 731 496 732 #if defined(HAVE_CASE_INSENSITIVE_FS) 497 733 498 /* The public add /lookupstring interface for case insensitive strings. */734 /* The public add string interface for case insensitive strings. */ 499 735 const char * 500 736 strcache2_iadd (struct strcache2 *cache, const char *str, unsigned int length) -
trunk/src/kmk/strcache2.h
r1885 r1887 82 82 const char *strcache2_add_hashed (struct strcache2 *cache, const char *str, unsigned int length, 83 83 unsigned int hash1, unsigned int hash2); 84 const char *strcache2_lookup (struct strcache2 *cache, const char *str, unsigned int length); 84 85 int strcache2_is_cached (struct strcache2 *cache, const char *str); 85 86 int strcache2_verify_entry (struct strcache2 *cache, const char *str); -
trunk/src/kmk/variable.c
r1886 r1887 104 104 105 105 106 #ifdef CONFIG_WITH_STRCACHE2 107 static struct strcache2 variable_strcache; 108 #endif 109 106 110 /* Hash table of all global variable definitions. */ 107 111 108 #if defined(VARIABLE_HASH) || defined(CONFIG_WITH_OPTIMIZATION_HACKS) 109 # ifdef _MSC_VER 110 typedef signed int int32_t; 111 # endif 112 #if defined(VARIABLE_HASH) || defined(CONFIG_WITH_OPTIMIZATION_HACKS) || defined(CONFIG_WITH_STRCACHE2) 112 113 MY_INLINE unsigned long variable_hash_2i(register const char *var, register int length) 113 114 { 114 # define UPDATE_HASH(ch) hash = (ch) + (hash << 6) + (hash << 16) - hash 115 # ifndef CONFIG_WITH_OPTIMIZATION_HACKS 116 # if 1 117 register const unsigned char *uvar = (const unsigned char *)var; 118 register unsigned long hash = 0; 119 while (length-- > 0) 120 UPDATE_HASH(*uvar++); 121 return hash; 122 # else 123 return_STRING_N_HASH_2 (var, length); 124 # endif 125 # else /* CONFIG_WITH_OPTIMIZATION_HACKS */ 126 register unsigned long hash = 0; 127 register const unsigned char *uvar = (const unsigned char *)var; 128 register const unsigned char *uvar_end = uvar + length; 129 switch (length) 130 { 131 default: 132 case 32: /*UPDATE_HASH(uvar_end[-16]);*/ 133 case 31: UPDATE_HASH(uvar_end[-15]); 134 case 30: /*UPDATE_HASH(uvar_end[-14]);*/ 135 case 29: UPDATE_HASH(uvar_end[-13]); 136 case 28: /*UPDATE_HASH(uvar_end[-12]);*/ 137 case 27: UPDATE_HASH(uvar_end[-11]); 138 case 26: /*UPDATE_HASH(uvar_end[-10]);*/ 139 case 25: UPDATE_HASH(uvar_end[-9]); 140 case 24: /*UPDATE_HASH(uvar[15]);*/ 141 case 23: UPDATE_HASH(uvar[14]); 142 case 22: /*UPDATE_HASH(uvar[13]);*/ 143 case 21: UPDATE_HASH(uvar[12]); 144 case 20: /*UPDATE_HASH(uvar[11]);*/ 145 case 19: UPDATE_HASH(uvar[10]); 146 case 18: /*UPDATE_HASH(uvar[9]);*/ 147 case 17: UPDATE_HASH(uvar[8]); 148 case 16: /*UPDATE_HASH(uvar_end[-8]);*/ 149 case 15: UPDATE_HASH(uvar_end[-7]); 150 case 14: /*UPDATE_HASH(uvar_end[-6]);*/ 151 case 13: UPDATE_HASH(uvar_end[-5]); 152 case 12: /*UPDATE_HASH(uvar_end[-4]);*/ 153 case 11: UPDATE_HASH(uvar_end[-3]); 154 case 10: /*UPDATE_HASH(uvar_end[-2]);*/ 155 case 9: UPDATE_HASH(uvar_end[-1]); 156 case 8: /*UPDATE_HASH(uvar[7]);*/ 157 case 7: UPDATE_HASH(uvar[6]); 158 case 6: /*UPDATE_HASH(uvar[5]);*/ 159 case 5: UPDATE_HASH(uvar[4]); 160 case 4: /*UPDATE_HASH(uvar[3]);*/ 161 case 3: UPDATE_HASH(uvar[2]); 162 case 2: /*UPDATE_HASH(uvar[1]);*/ 163 case 1: UPDATE_HASH(uvar[0]); 164 case 0: 165 return hash; 166 } 167 # endif /* CONFIG_WITH_OPTIMIZATION_HACKS*/ 168 # undef UPDATE_HASH 115 /* all requests are served from the cache. */ 116 return strcache2_get_hash2 (&variable_strcache, var); 169 117 } 170 118 171 119 MY_INLINE unsigned long variable_hash_1i(register const char *var, register int length) 172 120 { 173 # define UPDATE_HASH(ch) hash = ((hash << 5) + hash) + (ch) 174 # ifndef CONFIG_WITH_OPTIMIZATION_HACKS 175 # if 1 176 register const unsigned char *uvar = (const unsigned char *)var; 177 register unsigned long hash = 5381; 178 while (length-- > 0) 179 UPDATE_HASH(*uvar++); 180 return hash; 181 # else 182 return_STRING_N_HASH_1 (var, length); 183 # endif 184 # else /* CONFIG_WITH_OPTIMIZATION_HACKS */ 185 register const unsigned char *uvar = (const unsigned char *)var; 186 register const unsigned char *uvar_end = (const unsigned char *)var + length; 187 register unsigned long hash = ((5381 << 5) + 5381) + *uvar; 188 switch (length) 189 { 190 default: 191 #if 0 /* seems to be a waste of time. */ 192 case 97: UPDATE_HASH(uvar_end[-77]); 193 case 96: /*UPDATE_HASH(uvar_end[-76]);*/ 194 case 95: /*UPDATE_HASH(uvar_end[-75]);*/ 195 case 94: /*UPDATE_HASH(uvar_end[-74]);*/ 196 case 93: UPDATE_HASH(uvar_end[-73]); 197 case 92: /*UPDATE_HASH(uvar_end[-72]);*/ 198 case 91: /*UPDATE_HASH(uvar_end[-71]);*/ 199 case 90: /*UPDATE_HASH(uvar_end[-70]);*/ 200 case 89: UPDATE_HASH(uvar_end[-69]); 201 case 88: /*UPDATE_HASH(uvar_end[-68]);*/ 202 case 87: /*UPDATE_HASH(uvar_end[-67]);*/ 203 case 86: /*UPDATE_HASH(uvar_end[-66]);*/ 204 case 85: UPDATE_HASH(uvar_end[-65]); 205 case 84: /*UPDATE_HASH(uvar_end[-64]);*/ 206 case 83: /*UPDATE_HASH(uvar_end[-63]);*/ 207 case 82: /*UPDATE_HASH(uvar_end[-62]);*/ 208 case 81: UPDATE_HASH(uvar_end[-61]); 209 case 80: /*UPDATE_HASH(uvar_end[-60]);*/ 210 case 79: /*UPDATE_HASH(uvar_end[-59]);*/ 211 case 78: /*UPDATE_HASH(uvar_end[-58]);*/ 212 case 77: UPDATE_HASH(uvar_end[-57]); 213 case 76: /*UPDATE_HASH(uvar_end[-56]);*/ 214 case 75: /*UPDATE_HASH(uvar_end[-55]);*/ 215 case 74: /*UPDATE_HASH(uvar_end[-54]);*/ 216 case 73: UPDATE_HASH(uvar_end[-53]); 217 case 72: /*UPDATE_HASH(uvar_end[-52]);*/ 218 case 71: /*UPDATE_HASH(uvar_end[-51]);*/ 219 case 70: /*UPDATE_HASH(uvar_end[-50]);*/ 220 case 69: UPDATE_HASH(uvar_end[-49]); 221 case 68: /*UPDATE_HASH(uvar_end[-48]);*/ 222 case 67: /*UPDATE_HASH(uvar_end[-47]);*/ 223 case 66: /*UPDATE_HASH(uvar_end[-46]);*/ 224 case 65: UPDATE_HASH(uvar_end[-49]); 225 case 64: /*UPDATE_HASH(uvar_end[-48]);*/ 226 case 63: /*UPDATE_HASH(uvar_end[-47]);*/ 227 case 62: /*UPDATE_HASH(uvar_end[-46]);*/ 228 case 61: UPDATE_HASH(uvar_end[-45]); 229 case 60: /*UPDATE_HASH(uvar_end[-44]);*/ 230 case 59: /*UPDATE_HASH(uvar_end[-43]);*/ 231 case 58: /*UPDATE_HASH(uvar_end[-42]);*/ 232 case 57: UPDATE_HASH(uvar_end[-41]); 233 case 56: /*UPDATE_HASH(uvar_end[-40]);*/ 234 case 55: /*UPDATE_HASH(uvar_end[-39]);*/ 235 case 54: /*UPDATE_HASH(uvar_end[-38]);*/ 236 case 53: UPDATE_HASH(uvar_end[-37]); 237 case 52: /*UPDATE_HASH(uvar_end[-36]);*/ 238 case 51: UPDATE_HASH(uvar_end[-35]); 239 case 50: /*UPDATE_HASH(uvar_end[-34]);*/ 240 case 49: UPDATE_HASH(uvar_end[-33]); 241 #endif 242 case 48: /*UPDATE_HASH(uvar_end[-32]);*/ 243 case 47: UPDATE_HASH(uvar_end[-31]); 244 case 46: /*UPDATE_HASH(uvar_end[-30]);*/ 245 case 45: UPDATE_HASH(uvar_end[-29]); 246 case 44: /*UPDATE_HASH(uvar_end[-28]);*/ 247 case 43: UPDATE_HASH(uvar_end[-27]); 248 case 42: /*UPDATE_HASH(uvar_end[-26]);*/ 249 case 41: UPDATE_HASH(uvar_end[-25]); 250 case 40: /*UPDATE_HASH(uvar_end[-24]);*/ 251 case 39: UPDATE_HASH(uvar_end[-23]); 252 case 38: /*UPDATE_HASH(uvar_end[-22]);*/ 253 case 37: UPDATE_HASH(uvar_end[-21]); 254 case 36: /*UPDATE_HASH(uvar_end[-20]);*/ 255 case 35: UPDATE_HASH(uvar_end[-19]); 256 case 34: /*UPDATE_HASH(uvar_end[-18]);*/ 257 case 33: UPDATE_HASH(uvar_end[-17]); 258 259 case 32: UPDATE_HASH(uvar_end[-16]); 260 case 31: UPDATE_HASH(uvar_end[-15]); 261 case 30: UPDATE_HASH(uvar_end[-14]); 262 case 29: UPDATE_HASH(uvar_end[-13]); 263 case 28: UPDATE_HASH(uvar[15]); 264 case 27: UPDATE_HASH(uvar[14]); 265 case 26: UPDATE_HASH(uvar[13]); 266 case 25: UPDATE_HASH(uvar[12]); 267 268 case 24: UPDATE_HASH(uvar_end[-12]); 269 case 23: UPDATE_HASH(uvar_end[-11]); 270 case 22: UPDATE_HASH(uvar_end[-10]); 271 case 21: UPDATE_HASH(uvar_end[-9]); 272 case 20: UPDATE_HASH(uvar[7]); 273 case 19: UPDATE_HASH(uvar[6]); 274 case 18: UPDATE_HASH(uvar[5]); 275 case 17: UPDATE_HASH(uvar[4]); 276 277 case 16: UPDATE_HASH(uvar_end[-8]); 278 case 15: UPDATE_HASH(uvar_end[-7]); 279 case 14: UPDATE_HASH(uvar_end[-6]); 280 case 13: UPDATE_HASH(uvar_end[-5]); 281 case 12: UPDATE_HASH(uvar[11]); 282 case 11: UPDATE_HASH(uvar[10]); 283 case 10: UPDATE_HASH(uvar[9]); 284 case 9: UPDATE_HASH(uvar[8]); 285 286 case 8: UPDATE_HASH(uvar_end[-4]); 287 case 7: UPDATE_HASH(uvar_end[-3]); 288 case 6: UPDATE_HASH(uvar_end[-2]); 289 case 5: UPDATE_HASH(uvar_end[-1]); 290 case 4: UPDATE_HASH(uvar[3]); 291 case 3: UPDATE_HASH(uvar[2]); 292 case 2: UPDATE_HASH(uvar[1]); 293 case 1: return hash; 294 case 0: return 5381; /* shouldn't happen */ 295 } 296 # endif /* CONFIG_WITH_OPTIMIZATION_HACKS */ 297 # undef UPDATE_HASH 121 /* all requests are served from the cache. */ 122 return strcache2_get_hash1 (&variable_strcache, var); 298 123 } 299 124 #endif /* CONFIG_WITH_OPTIMIZATION_HACKS */ … … 312 137 return key->hash1; 313 138 #else 314 # if def CONFIG_WITH_OPTIMIZATION_HACKS139 # if defined(CONFIG_WITH_STRCACHE2) 315 140 return variable_hash_1i (key->name, key->length); 316 141 # else … … 330 155 #else 331 156 struct variable const *key = (struct variable const *) keyv; 332 # ifdef CONFIG_WITH_ OPTIMIZATION_HACKS157 # ifdef CONFIG_WITH_STRCACHE2 333 158 return variable_hash_2i (key->name, key->length); 334 159 # else … … 338 163 } 339 164 340 #if defined(VARIABLE_HASH) || defined(KMK)341 342 MY_INLINE int343 variable_hash_cmp_2_memcmp (const char *xs, const char *ys, unsigned int length)344 {345 /* short string compare - ~50% of the kBuild calls. */346 assert ( !((size_t)ys & 3) );347 if (!((size_t)xs & 3))348 {349 /* aligned */350 int result;351 switch (length)352 {353 case 8:354 result = *(int32_t*)(xs + 4) - *(int32_t*)(ys + 4);355 result |= *(int32_t*)xs - *(int32_t*)ys;356 return result;357 case 7:358 result = xs[6] - ys[6];359 result |= xs[5] - ys[5];360 result |= xs[4] - ys[4];361 result |= *(int32_t*)xs - *(int32_t*)ys;362 return result;363 case 6:364 result = xs[5] - ys[5];365 result |= xs[4] - ys[4];366 result |= *(int32_t*)xs - *(int32_t*)ys;367 return result;368 case 5:369 result = xs[4] - ys[4];370 result |= *(int32_t*)xs - *(int32_t*)ys;371 return result;372 case 4:373 return *(int32_t*)xs - *(int32_t*)ys;374 case 3:375 result = xs[2] - ys[2];376 result |= xs[1] - ys[1];377 result |= xs[0] - ys[0];378 return result;379 case 2:380 result = xs[1] - ys[1];381 result |= xs[0] - ys[0];382 return result;383 case 1:384 return *xs - *ys;385 case 0:386 return 0;387 }388 }389 else390 {391 /* unaligned */392 int result = 0;393 switch (length)394 {395 case 8: result |= xs[7] - ys[7];396 case 7: result |= xs[6] - ys[6];397 case 6: result |= xs[5] - ys[5];398 case 5: result |= xs[4] - ys[4];399 case 4: result |= xs[3] - ys[3];400 case 3: result |= xs[2] - ys[2];401 case 2: result |= xs[1] - ys[1];402 case 1: result |= xs[0] - ys[0];403 case 0:404 return result;405 }406 }407 408 /* memcmp for longer strings */409 # ifdef __GNUC__410 return __builtin_memcmp (xs, ys, length);411 # else412 return memcmp (xs, ys, length);413 # endif414 }415 416 MY_INLINE int417 variable_hash_cmp_2_inlined (const char *xs, const char *ys, unsigned int length)418 {419 #ifndef ELECTRIC_HEAP420 assert ( !((size_t)ys & 3) );421 #endif422 if (!((size_t)xs & 3))423 {424 int result;425 /* aligned */426 while (length >= 8)427 {428 result = *(int32_t*)xs - *(int32_t*)ys;429 result |= *(int32_t*)(xs + 4) - *(int32_t*)(ys + 4);430 if (MY_PREDICT_FALSE(result))431 return result;432 xs += 8;433 ys += 8;434 length -= 8;435 }436 switch (length)437 {438 case 7:439 result = *(int32_t*)xs - *(int32_t*)ys;440 result |= xs[6] - ys[6];441 result |= xs[5] - ys[5];442 result |= xs[4] - ys[4];443 return result;444 case 6:445 result = *(int32_t*)xs - *(int32_t*)ys;446 result |= xs[5] - ys[5];447 result |= xs[4] - ys[4];448 return result;449 case 5:450 result = *(int32_t*)xs - *(int32_t*)ys;451 result |= xs[4] - ys[4];452 return result;453 case 4:454 return *(int32_t*)xs - *(int32_t*)ys;455 case 3:456 result = xs[2] - ys[2];457 result |= xs[1] - ys[1];458 result |= xs[0] - ys[0];459 return result;460 case 2:461 result = xs[1] - ys[1];462 result |= xs[0] - ys[0];463 return result;464 case 1:465 return *xs - *ys;466 default:467 case 0:468 return 0;469 }470 }471 else472 {473 /* unaligned */474 int result;475 while (length >= 8)476 {477 #if defined(__i386__) || defined(__x86_64__)478 result = ( ((int32_t)xs[3] << 24)479 | ((int32_t)xs[2] << 16)480 | ((int32_t)xs[1] << 8)481 | xs[0] )482 - *(int32_t*)ys;483 result |= ( ((int32_t)xs[7] << 24)484 | ((int32_t)xs[6] << 16)485 | ((int32_t)xs[5] << 8)486 | xs[4] )487 - *(int32_t*)(ys + 4);488 #else489 result = xs[3] - ys[3];490 result |= xs[2] - ys[2];491 result |= xs[1] - ys[1];492 result |= xs[0] - ys[0];493 result |= xs[7] - ys[7];494 result |= xs[6] - ys[6];495 result |= xs[5] - ys[5];496 result |= xs[4] - ys[4];497 #endif498 if (MY_PREDICT_FALSE(result))499 return result;500 xs += 8;501 ys += 8;502 length -= 8;503 }504 result = 0;505 switch (length)506 {507 case 7: result |= xs[6] - ys[6];508 case 6: result |= xs[5] - ys[5];509 case 5: result |= xs[4] - ys[4];510 case 4: result |= xs[3] - ys[3];511 case 3: result |= xs[2] - ys[2];512 case 2: result |= xs[1] - ys[1];513 case 1: result |= xs[0] - ys[0];514 return result;515 default:516 case 0:517 return 0;518 }519 }520 }521 522 #endif /* VARIABLE_HASH || KMK */523 524 #ifndef VARIABLE_HASH525 165 static int 526 166 variable_hash_cmp (const void *xv, const void *yv) … … 528 168 struct variable const *x = (struct variable const *) xv; 529 169 struct variable const *y = (struct variable const *) yv; 530 # 170 #ifndef CONFIG_WITH_STRCACHE2 531 171 int result = x->length - y->length; 532 172 if (result) 533 173 return result; 534 # else /* CONFIG_WITH_STRCACHE2 */ 535 int result; 536 537 if (x->value != (char *)x) /* hack: strcache indicator */ 538 { 539 assert (y->value != (char *)y); 540 return x->name == y->name ? 0 : -1; 541 } 542 543 /* lookup path: */ 544 result = x->length - y->length; 545 if (result) 546 return result; 547 # endif /* CONFIG_WITH_STRCACHE2 */ 548 549 # ifndef KMK 174 550 175 return_STRING_N_COMPARE (x->name, y->name, x->length); 551 # else /* KMK */ 552 # if 0 553 return variable_hash_cmp_2_memcmp(x->name, y->name, x->length); 554 # else 555 return variable_hash_cmp_2_inlined(x->name, y->name, x->length); 556 # endif 557 # endif /* KMK */ 558 } 559 560 #else /* VARIABLE_HASH */ 561 562 MY_INLINE int 563 variable_hash_cmp (const void *xv, const void *yv) 564 { 565 struct variable const *x = (struct variable const *) xv; 566 struct variable const *y = (struct variable const *) yv; 567 int result; 568 569 # ifdef VARIABLE_HASH_STRICT 570 if (x->hash1 != variable_hash_1i (x->name, x->length)) 571 __asm__("int3"); 572 if (x->hash2 && x->hash2 != variable_hash_2i (x->name, x->length)) 573 __asm__("int3"); 574 if (y->hash1 != variable_hash_1i (y->name, y->length)) 575 __asm__("int3"); 576 if (y->hash2 && y->hash2 != variable_hash_2i (y->name, y->length)) 577 __asm__("int3"); 578 # endif /* VARIABLE_HASH_STRICT */ 579 580 # ifdef CONFIG_WITH_STRCACHE2 581 /* strcaching */ 582 if (x->value != (char *)x) /* hack: strcache indicator */ 583 { 584 assert (y->value != (char *)y); 585 return x->name == y->name ? 0 : -1; 586 } 587 #endif 588 589 /* hash 1 & length */ 590 result = (x->hash1 - y->hash1) 591 | (x->length - y->length); 592 if (MY_PREDICT_TRUE(result)) 593 return result; 594 595 # if 0 /* too few hits at this point. */ 596 /* hash 2, but only if X has it since lookup_variable will give us an X 597 which resides on the stack and which result will be lost to us. */ 598 if (x->hash2) 599 { 600 if (!y->hash2) 601 ((struct variable *)y)->hash2 = variable_hash_2i (y->name, y->length); 602 result = x->hash2 - y->hash2; 603 if (result) 604 return result; 605 } 606 # endif 607 608 # if 0 609 return variable_hash_cmp_2_memcmp(x->name, y->name, x->length); 610 # else 611 return variable_hash_cmp_2_inlined(x->name, y->name, x->length); 612 # endif 613 } 614 #endif /* VARIABLE_HASH */ 176 #else /* CONFIG_WITH_STRCACHE2 */ 177 178 /* everything is in the cache. */ 179 return x->name == y->name ? 0 : -1; 180 #endif /* CONFIG_WITH_STRCACHE2 */ 181 } 615 182 616 183 #ifndef VARIABLE_BUCKETS … … 640 207 = { 0, &global_variable_set }; 641 208 struct variable_set_list *current_variable_set_list = &global_setlist; 642 #ifdef CONFIG_WITH_STRCACHE2643 static struct strcache2 variable_strcache;644 #endif645 209 646 210 … … 923 487 const struct variable_set_list *setlist; 924 488 struct variable var_key; 489 #if defined(KMK) && !defined(VARIABLE_HASH) 490 unsigned int hash_2 = 0; 491 #endif 492 #ifdef CONFIG_WITH_STRCACHE2 493 const char *cached_name; 494 495 /* lookup the name in the string case, if it's not there it won't 496 be in any of the sets either. */ 497 cached_name = strcache2_lookup(&variable_strcache, name, length); 498 if (!cached_name) 499 return NULL; 500 name = cached_name; 501 #endif /* CONFIG_WITH_STRCACHE2 */ 925 502 926 503 var_key.name = (char *) name; … … 937 514 setlist != 0; setlist = setlist->next) 938 515 { 939 #if def VARIABLE_HASH/* bird: speed */516 #if defined(KMK) /* bird: speed */ 940 517 struct hash_table *ht = &setlist->set->table; 518 # ifdef VARIABLE_HASH 941 519 unsigned int hash_1 = var_key.hash1; 520 # else 521 unsigned int hash_1 = strcache2_get_hash1 (&variable_strcache, name); 522 # endif 942 523 struct variable *v; 943 524 … … 962 543 ht->ht_collisions++; 963 544 } 545 # ifdef VARIABLE_HASH 964 546 if (!var_key.hash2) 965 547 var_key.hash2 = variable_hash_2i(name, length); 966 548 hash_1 += (var_key.hash2 | 1); 549 # else 550 if (!hash_2) 551 { 552 hash_2 = strcache2_get_hash2 (&variable_cache, name, length); 553 assert (hash_2 & 1); 554 } 555 hash_1 += hash_2; 556 # endif 967 557 } 968 558 … … 1047 637 { 1048 638 struct variable var_key; 639 #ifdef CONFIG_WITH_STRCACHE2 640 const char *cached_name; 641 642 /* lookup the name in the string case, if it's not there it won't 643 be in any of the sets either. */ 644 cached_name = strcache2_lookup(&variable_strcache, name, length); 645 if (!cached_name) 646 return NULL; 647 name = cached_name; 648 #endif /* CONFIG_WITH_STRCACHE2 */ 1049 649 1050 650 var_key.name = (char *) name; … … 1810 1410 } 1811 1411 1412 #ifndef CONFIG_WITH_STRCACHE2 1812 1413 makelevel_key.name = MAKELEVEL_NAME; 1813 1414 makelevel_key.length = MAKELEVEL_LENGTH; … … 1820 1421 #endif 1821 1422 hash_delete (&table, &makelevel_key); 1423 #else /* CONFIG_WITH_STRCACHE2 */ 1424 /* lookup the name in the string case, if it's not there it won't 1425 be in any of the sets either. */ 1426 { 1427 const char *cached_name = strcache2_lookup(&variable_strcache, 1428 MAKELEVEL_NAME, MAKELEVEL_LENGTH); 1429 if (cached_name) 1430 { 1431 makelevel_key.name = cached_name; 1432 makelevel_key.length = MAKELEVEL_LENGTH; 1433 #ifdef VARIABLE_HASH /* bird */ 1434 makelevel_key.hash1 = variable_hash_1i (MAKELEVEL_NAME, MAKELEVEL_LENGTH); 1435 makelevel_key.hash2 = 0; 1436 #endif 1437 makelevel_key.value = NULL; 1438 hash_delete (&table, &makelevel_key); 1439 } 1440 } 1441 #endif /* CONFIG_WITH_STRCACHE2 */ 1822 1442 1823 1443 result = result_0 = xmalloc ((table.ht_fill + 2) * sizeof (char *));
Note:
See TracChangeset
for help on using the changeset viewer.