Changeset 43682 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Oct 18, 2012 3:41:15 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/asm/asm-fake.cpp
r40959 r43682 229 229 RTDECL(void) ASMBitSet(volatile void *pvBitmap, int32_t iBit) 230 230 { 231 uint 32_t volatile *pau32Bitmap = (uint32_t volatile *)pvBitmap;232 pau 32Bitmap[iBit / 32] |= RT_BIT_32(iBit & 31);231 uint8_t volatile *pau8Bitmap = (uint8_t volatile *)pvBitmap; 232 pau8Bitmap[iBit / 8] |= (uint8_t)RT_BIT_32(iBit & 7); 233 233 } 234 234 … … 240 240 RTDECL(void) ASMBitClear(volatile void *pvBitmap, int32_t iBit) 241 241 { 242 uint 32_t volatile *pau32Bitmap = (uint32_t volatile *)pvBitmap;243 pau 32Bitmap[iBit / 32] &= ~RT_BIT_32(iBit & 31);242 uint8_t volatile *pau8Bitmap = (uint8_t volatile *)pvBitmap; 243 pau8Bitmap[iBit / 8] &= ~((uint8_t)RT_BIT_32(iBit & 7)); 244 244 } 245 245 … … 251 251 RTDECL(void) ASMBitToggle(volatile void *pvBitmap, int32_t iBit) 252 252 { 253 uint 32_t volatile *pau32Bitmap = (uint32_t volatile *)pvBitmap;254 pau 32Bitmap[iBit / 32] ^= RT_BIT_32(iBit & 31);253 uint8_t volatile *pau8Bitmap = (uint8_t volatile *)pvBitmap; 254 pau8Bitmap[iBit / 8] ^= (uint8_t)RT_BIT_32(iBit & 7); 255 255 } 256 256 … … 300 300 RTDECL(bool) ASMBitTest(const volatile void *pvBitmap, int32_t iBit) 301 301 { 302 uint 32_t volatile *pau32Bitmap = (uint32_t volatile *)pvBitmap;303 return pau32Bitmap[iBit / 32] & RT_BIT_32(iBit & 31) ? true : false;302 uint8_t volatile *pau8Bitmap = (uint8_t volatile *)pvBitmap; 303 return pau8Bitmap[iBit / 8] & (uint8_t)RT_BIT_32(iBit & 7) ? true : false; 304 304 } 305 305 … … 307 307 { 308 308 uint32_t iBit = 0; 309 uint32_t volatile *pu32 = (uint32_t volatile *)pvBitmap; 309 uint8_t volatile *pu8 = (uint8_t volatile *)pvBitmap; 310 310 311 while (iBit < cBits) 311 312 { 312 uint 32_t u32 = *pu32;313 if (u 32 != UINT32_MAX)313 uint8_t u8 = *pu8; 314 if (u8 != UINT8_MAX) 314 315 { 315 while (u 32& 1)316 while (u8 & 1) 316 317 { 317 u 32>>= 1;318 u8 >>= 1; 318 319 iBit++; 319 320 } … … 323 324 } 324 325 325 iBit += 32;326 pu 32++;326 iBit += 8; 327 pu8++; 327 328 } 328 329 return -1; … … 331 332 RTDECL(int) ASMBitNextClear(const volatile void *pvBitmap, uint32_t cBits, uint32_t iBitPrev) 332 333 { 333 const volatile uint 32_t *pau32Bitmap = (const volatile uint32_t *)pvBitmap;334 int iBit = ++iBitPrev & 31;334 const volatile uint8_t *pau8Bitmap = (const volatile uint8_t *)pvBitmap; 335 int iBit = ++iBitPrev & 7; 335 336 if (iBit) 336 337 { 337 338 /* 338 * Inspect the 32-bit wordcontaining the unaligned bit.339 * Inspect the byte containing the unaligned bit. 339 340 */ 340 uint 32_t u32 = ~pau32Bitmap[iBitPrev / 32] >> iBit;341 if (u 32)341 uint8_t u8 = ~pau8Bitmap[iBitPrev / 8] >> iBit; 342 if (u8) 342 343 { 343 344 iBit = 0; 344 while (!(u 32& 1))345 while (!(u8 & 1)) 345 346 { 346 u 32>>= 1;347 u8 >>= 1; 347 348 iBit++; 348 349 } … … 353 354 * Skip ahead and see if there is anything left to search. 354 355 */ 355 iBitPrev |= 31;356 iBitPrev |= 7; 356 357 iBitPrev++; 357 if (cBits <= (uint32_t)iBitPrev)358 if (cBits <= iBitPrev) 358 359 return -1; 359 360 } 360 361 361 362 /* 362 * 32-bit alignedsearch, let ASMBitFirstClear do the dirty work.363 * Byte search, let ASMBitFirstClear do the dirty work. 363 364 */ 364 iBit = ASMBitFirstClear(&pau 32Bitmap[iBitPrev / 32], cBits - iBitPrev);365 iBit = ASMBitFirstClear(&pau8Bitmap[iBitPrev / 8], cBits - iBitPrev); 365 366 if (iBit >= 0) 366 367 iBit += iBitPrev; … … 371 372 { 372 373 uint32_t iBit = 0; 373 uint 32_t volatile *pu32 = (uint32_t volatile *)pvBitmap;374 uint8_t volatile *pu8 = (uint8_t volatile *)pvBitmap; 374 375 while (iBit < cBits) 375 376 { 376 uint 32_t u32 = *pu32;377 if (u 32!= 0)377 uint8_t u8 = *pu8; 378 if (u8 != 0) 378 379 { 379 while (!(u 32& 1))380 while (!(u8 & 1)) 380 381 { 381 u 32>>= 1;382 u8 >>= 1; 382 383 iBit++; 383 384 } … … 387 388 } 388 389 389 iBit += 32;390 pu 32++;390 iBit += 8; 391 pu8++; 391 392 } 392 393 return -1; … … 395 396 RTDECL(int) ASMBitNextSet(const volatile void *pvBitmap, uint32_t cBits, uint32_t iBitPrev) 396 397 { 397 const volatile uint 32_t *pau32Bitmap = (const volatile uint32_t *)pvBitmap;398 int iBit = ++iBitPrev & 31;398 const volatile uint8_t *pau8Bitmap = (const volatile uint8_t *)pvBitmap; 399 int iBit = ++iBitPrev & 7; 399 400 if (iBit) 400 401 { 401 402 /* 402 * Inspect the 32-bit wordcontaining the unaligned bit.403 * Inspect the byte containing the unaligned bit. 403 404 */ 404 uint 32_t u32 = pau32Bitmap[iBitPrev / 32] >> iBit;405 if (u 32)405 uint8_t u8 = pau8Bitmap[iBitPrev / 8] >> iBit; 406 if (u8) 406 407 { 407 408 iBit = 0; 408 while (!(u 32& 1))409 while (!(u8 & 1)) 409 410 { 410 u 32>>= 1;411 u8 >>= 1; 411 412 iBit++; 412 413 } … … 417 418 * Skip ahead and see if there is anything left to search. 418 419 */ 419 iBitPrev |= 31;420 iBitPrev |= 7; 420 421 iBitPrev++; 421 if (cBits <= (uint32_t)iBitPrev)422 if (cBits <= iBitPrev) 422 423 return -1; 423 424 } 424 425 425 426 /* 426 * 32-bit alignedsearch, let ASMBitFirstSet do the dirty work.427 * Byte search, let ASMBitFirstSet do the dirty work. 427 428 */ 428 iBit = ASMBitFirstSet(&pau 32Bitmap[iBitPrev / 32], cBits - iBitPrev);429 iBit = ASMBitFirstSet(&pau8Bitmap[iBitPrev / 8], cBits - iBitPrev); 429 430 if (iBit >= 0) 430 431 iBit += iBitPrev;
Note:
See TracChangeset
for help on using the changeset viewer.