Changeset 87192 in vbox
- Timestamp:
- Jan 7, 2021 8:43:08 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 142145
- Location:
- trunk
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/asm.h
r87191 r87192 5457 5457 * Sets a bit in a bitmap. 5458 5458 * 5459 * @param pvBitmap Pointer to the bitmap. This should be 32-bit aligned. 5459 * @param pvBitmap Pointer to the bitmap (little endian). This should be 5460 * 32-bit aligned. 5460 5461 * @param iBit The bit to set. 5461 5462 * … … 5498 5499 int32_t offBitmap = iBit / 32; 5499 5500 AssertStmt(!((uintptr_t)pvBitmap & 3), offBitmap += (uintptr_t)pvBitmap & 3; iBit += ((uintptr_t)pvBitmap & 3) * 8); 5500 ASMAtomicUoOrU32(&((uint32_t volatile *)pvBitmap)[offBitmap], RT_ BIT_32(iBit & 31));5501 ASMAtomicUoOrU32(&((uint32_t volatile *)pvBitmap)[offBitmap], RT_H2LE_U32(RT_BIT_32(iBit & 31))); 5501 5502 # endif 5502 5503 } … … 5507 5508 * Atomically sets a bit in a bitmap, ordered. 5508 5509 * 5509 * @param pvBitmap Pointer to the bitmap . Must be 32-bit aligned, otherwise5510 * the memory access isn't atomic!5510 * @param pvBitmap Pointer to the bitmap (little endian). Must be 32-bit 5511 * aligned, otherwise the memory access isn't atomic! 5511 5512 * @param iBit The bit to set. 5512 5513 * … … 5545 5546 5546 5547 # else 5547 ASMAtomicOrU32(&((uint32_t volatile *)pvBitmap)[iBit / 32], RT_ BIT_32(iBit & 31));5548 ASMAtomicOrU32(&((uint32_t volatile *)pvBitmap)[iBit / 32], RT_H2LE_U32(RT_BIT_32(iBit & 31))); 5548 5549 # endif 5549 5550 } … … 5554 5555 * Clears a bit in a bitmap. 5555 5556 * 5556 * @param pvBitmap Pointer to the bitmap .5557 * @param pvBitmap Pointer to the bitmap (little endian). 5557 5558 * @param iBit The bit to clear. 5558 5559 * … … 5595 5596 int32_t offBitmap = iBit / 32; 5596 5597 AssertStmt(!((uintptr_t)pvBitmap & 3), offBitmap += (uintptr_t)pvBitmap & 3; iBit += ((uintptr_t)pvBitmap & 3) * 8); 5597 ASMAtomicUoAndU32(&((uint32_t volatile *)pvBitmap)[offBitmap], ~RT_BIT_32(iBit & 31));5598 ASMAtomicUoAndU32(&((uint32_t volatile *)pvBitmap)[offBitmap], RT_H2LE_U32(~RT_BIT_32(iBit & 31))); 5598 5599 # endif 5599 5600 } … … 5604 5605 * Atomically clears a bit in a bitmap, ordered. 5605 5606 * 5606 * @param pvBitmap Pointer to the bitmap . Must be 32-bit aligned, otherwise5607 * the memory access isn't atomic!5607 * @param pvBitmap Pointer to the bitmap (little endian). Must be 32-bit 5608 * aligned, otherwise the memory access isn't atomic! 5608 5609 * @param iBit The bit to toggle set. 5609 5610 * … … 5640 5641 # endif 5641 5642 # else 5642 ASMAtomicAndU32(&((uint32_t volatile *)pvBitmap)[iBit / 32], ~RT_BIT_32(iBit & 31));5643 ASMAtomicAndU32(&((uint32_t volatile *)pvBitmap)[iBit / 32], RT_H2LE_U32(~RT_BIT_32(iBit & 31))); 5643 5644 # endif 5644 5645 } … … 5649 5650 * Toggles a bit in a bitmap. 5650 5651 * 5651 * @param pvBitmap Pointer to the bitmap .5652 * @param pvBitmap Pointer to the bitmap (little endian). 5652 5653 * @param iBit The bit to toggle. 5653 5654 * … … 5688 5689 int32_t offBitmap = iBit / 32; 5689 5690 AssertStmt(!((uintptr_t)pvBitmap & 3), offBitmap += (uintptr_t)pvBitmap & 3; iBit += ((uintptr_t)pvBitmap & 3) * 8); 5690 ASMAtomicUoXorU32(&((uint32_t volatile *)pvBitmap)[offBitmap], RT_ BIT_32(iBit & 31));5691 ASMAtomicUoXorU32(&((uint32_t volatile *)pvBitmap)[offBitmap], RT_H2LE_U32(RT_BIT_32(iBit & 31))); 5691 5692 # endif 5692 5693 } … … 5697 5698 * Atomically toggles a bit in a bitmap, ordered. 5698 5699 * 5699 * @param pvBitmap Pointer to the bitmap . Must be 32-bit aligned, otherwise5700 * the memory access isn't atomic!5700 * @param pvBitmap Pointer to the bitmap (little endian). Must be 32-bit 5701 * aligned, otherwise the memory access isn't atomic! 5701 5702 * @param iBit The bit to test and set. 5702 5703 * … … 5732 5733 # endif 5733 5734 # else 5734 ASMAtomicXorU32(&((uint32_t volatile *)pvBitmap)[iBit / 32], RT_ BIT_32(iBit & 31));5735 ASMAtomicXorU32(&((uint32_t volatile *)pvBitmap)[iBit / 32], RT_H2LE_U32(RT_BIT_32(iBit & 31))); 5735 5736 # endif 5736 5737 } … … 5744 5745 * @returns false if the bit was clear. 5745 5746 * 5746 * @param pvBitmap Pointer to the bitmap .5747 * @param pvBitmap Pointer to the bitmap (little endian). 5747 5748 * @param iBit The bit to test and set. 5748 5749 * … … 5791 5792 int32_t offBitmap = iBit / 32; 5792 5793 AssertStmt(!((uintptr_t)pvBitmap & 3), offBitmap += (uintptr_t)pvBitmap & 3; iBit += ((uintptr_t)pvBitmap & 3) * 8); 5793 rc.u32 = ASMAtomicUoOrExU32(&((uint32_t volatile *)pvBitmap)[offBitmap], RT_BIT_32(iBit & 31)) >> (iBit & 31); 5794 rc.u32 = RT_LE2H_U32(ASMAtomicUoOrExU32(&((uint32_t volatile *)pvBitmap)[offBitmap], RT_H2LE_U32(RT_BIT_32(iBit & 31)))) 5795 >> (iBit & 31); 5796 rc.u32 &= 1; 5794 5797 # endif 5795 5798 return rc.f; … … 5804 5807 * @returns false if the bit was clear. 5805 5808 * 5806 * @param pvBitmap Pointer to the bitmap . Must be 32-bit aligned, otherwise5807 * the memory access isn't atomic!5809 * @param pvBitmap Pointer to the bitmap (little endian). Must be 32-bit 5810 * aligned, otherwise the memory access isn't atomic! 5808 5811 * @param iBit The bit to set. 5809 5812 * … … 5848 5851 5849 5852 # else 5850 rc.u32 = ASMAtomicOrExU32(&((uint32_t volatile *)pvBitmap)[iBit / 32], RT_BIT_32(iBit & 31)) >> (iBit & 31); 5853 rc.u32 = RT_LE2H_U32(ASMAtomicOrExU32(&((uint32_t volatile *)pvBitmap)[iBit / 32], RT_H2LE_U32(RT_BIT_32(iBit & 31)))) 5854 >> (iBit & 31); 5855 rc.u32 &= 1; 5851 5856 # endif 5852 5857 return rc.f; … … 5861 5866 * @returns false if the bit was clear. 5862 5867 * 5863 * @param pvBitmap Pointer to the bitmap .5868 * @param pvBitmap Pointer to the bitmap (little endian). 5864 5869 * @param iBit The bit to test and clear. 5865 5870 * … … 5908 5913 int32_t offBitmap = iBit / 32; 5909 5914 AssertStmt(!((uintptr_t)pvBitmap & 3), offBitmap += (uintptr_t)pvBitmap & 3; iBit += ((uintptr_t)pvBitmap & 3) * 8); 5910 rc.u32 = ASMAtomicUoAndExU32(&((uint32_t volatile *)pvBitmap)[offBitmap], ~RT_BIT_32(iBit & 31)) >> (iBit & 31); 5915 rc.u32 = RT_LE2H_U32(ASMAtomicUoAndExU32(&((uint32_t volatile *)pvBitmap)[offBitmap], RT_H2LE_U32(~RT_BIT_32(iBit & 31)))) 5916 >> (iBit & 31); 5917 rc.u32 &= 1; 5911 5918 # endif 5912 5919 return rc.f; … … 5921 5928 * @returns false if the bit was clear. 5922 5929 * 5923 * @param pvBitmap Pointer to the bitmap . Must be 32-bit aligned, otherwise5924 * the memory access isn't atomic!5930 * @param pvBitmap Pointer to the bitmap (little endian). Must be 32-bit 5931 * aligned, otherwise the memory access isn't atomic! 5925 5932 * @param iBit The bit to test and clear. 5926 5933 * … … 5967 5974 5968 5975 # else 5969 rc.u32 = ASMAtomicAndExU32(&((uint32_t volatile *)pvBitmap)[iBit / 32], ~RT_BIT_32(iBit & 31)) >> (iBit & 31); 5976 rc.u32 = RT_LE2H_U32(ASMAtomicAndExU32(&((uint32_t volatile *)pvBitmap)[iBit / 32], RT_H2LE_U32(~RT_BIT_32(iBit & 31)))) 5977 >> (iBit & 31); 5978 rc.u32 &= 1; 5970 5979 # endif 5971 5980 return rc.f; … … 5980 5989 * @returns false if the bit was clear. 5981 5990 * 5982 * @param pvBitmap Pointer to the bitmap .5991 * @param pvBitmap Pointer to the bitmap (little endian). 5983 5992 * @param iBit The bit to test and toggle. 5984 5993 * … … 6027 6036 int32_t offBitmap = iBit / 32; 6028 6037 AssertStmt(!((uintptr_t)pvBitmap & 3), offBitmap += (uintptr_t)pvBitmap & 3; iBit += ((uintptr_t)pvBitmap & 3) * 8); 6029 rc.u32 = ASMAtomicUoXorExU32(&((uint32_t volatile *)pvBitmap)[offBitmap], RT_BIT_32(iBit & 31)) >> (iBit & 31); 6038 rc.u32 = RT_LE2H_U32(ASMAtomicUoXorExU32(&((uint32_t volatile *)pvBitmap)[offBitmap], RT_H2LE_U32(RT_BIT_32(iBit & 31)))) 6039 >> (iBit & 31); 6040 rc.u32 &= 1; 6030 6041 # endif 6031 6042 return rc.f; … … 6040 6051 * @returns false if the bit was clear. 6041 6052 * 6042 * @param pvBitmap Pointer to the bitmap . Must be 32-bit aligned, otherwise6043 * the memory access isn't atomic!6053 * @param pvBitmap Pointer to the bitmap (little endian). Must be 32-bit 6054 * aligned, otherwise the memory access isn't atomic! 6044 6055 * @param iBit The bit to test and toggle. 6045 6056 * … … 6082 6093 6083 6094 # else 6084 rc.u32 = ASMAtomicXorExU32(&((uint32_t volatile *)pvBitmap)[iBit / 32], RT_BIT_32(iBit & 31)) >> (iBit & 31); 6095 rc.u32 = RT_H2LE_U32(ASMAtomicXorExU32(&((uint32_t volatile *)pvBitmap)[iBit / 32], RT_LE2H_U32(RT_BIT_32(iBit & 31)))) 6096 >> (iBit & 31); 6097 rc.u32 &= 1; 6085 6098 # endif 6086 6099 return rc.f; … … 6095 6108 * @returns false if the bit is clear. 6096 6109 * 6097 * @param pvBitmap Pointer to the bitmap .6110 * @param pvBitmap Pointer to the bitmap (little endian). 6098 6111 * @param iBit The bit to test. 6099 6112 * … … 6142 6155 int32_t offBitmap = iBit / 32; 6143 6156 AssertStmt(!((uintptr_t)pvBitmap & 3), offBitmap += (uintptr_t)pvBitmap & 3; iBit += ((uintptr_t)pvBitmap & 3) * 8); 6144 rc.u32 = ASMAtomicUoReadU32(&((uint32_t volatile *)pvBitmap)[offBitmap]) >> (iBit & 31); 6157 rc.u32 = RT_LE2H_U32(ASMAtomicUoReadU32(&((uint32_t volatile *)pvBitmap)[offBitmap])) >> (iBit & 31); 6158 rc.u32 &= 1; 6145 6159 # endif 6146 6160 return rc.f; … … 6152 6166 * Clears a bit range within a bitmap. 6153 6167 * 6154 * @param pvBitmap Pointer to the bitmap .6168 * @param pvBitmap Pointer to the bitmap (little endian). 6155 6169 * @param iBitStart The First bit to clear. 6156 6170 * @param iBitEnd The first bit not to clear. … … 6164 6178 int32_t iEnd = iBitEnd & ~31; 6165 6179 if (iStart == iEnd) 6166 *pu32 &= ((UINT32_C(1) << (iBitStart & 31)) - 1) | ~((UINT32_C(1) << (iBitEnd & 31)) - 1);6180 *pu32 &= RT_H2LE_U32(((UINT32_C(1) << (iBitStart & 31)) - 1) | ~((UINT32_C(1) << (iBitEnd & 31)) - 1)); 6167 6181 else 6168 6182 { … … 6170 6184 if (iBitStart & 31) 6171 6185 { 6172 *pu32 &= (UINT32_C(1) << (iBitStart & 31)) - 1;6186 *pu32 &= RT_H2LE_U32((UINT32_C(1) << (iBitStart & 31)) - 1); 6173 6187 pu32++; 6174 6188 iBitStart = iStart + 32; … … 6183 6197 { 6184 6198 pu32 = (volatile uint32_t *)pvBitmap + (iBitEnd >> 5); 6185 *pu32 &= ~((UINT32_C(1) << (iBitEnd & 31)) - 1);6199 *pu32 &= RT_H2LE_U32(~((UINT32_C(1) << (iBitEnd & 31)) - 1)); 6186 6200 } 6187 6201 } … … 6193 6207 * Sets a bit range within a bitmap. 6194 6208 * 6195 * @param pvBitmap Pointer to the bitmap .6209 * @param pvBitmap Pointer to the bitmap (little endian). 6196 6210 * @param iBitStart The First bit to set. 6197 6211 * @param iBitEnd The first bit not to set. … … 6205 6219 int32_t iEnd = iBitEnd & ~31; 6206 6220 if (iStart == iEnd) 6207 *pu32 |= ((UINT32_C(1) << (iBitEnd - iBitStart)) - 1) << (iBitStart & 31);6221 *pu32 |= RT_H2LE_U32(((UINT32_C(1) << (iBitEnd - iBitStart)) - 1) << (iBitStart & 31)); 6208 6222 else 6209 6223 { … … 6211 6225 if (iBitStart & 31) 6212 6226 { 6213 *pu32 |= ~((UINT32_C(1) << (iBitStart & 31)) - 1);6227 *pu32 |= RT_H2LE_U32(~((UINT32_C(1) << (iBitStart & 31)) - 1)); 6214 6228 pu32++; 6215 6229 iBitStart = iStart + 32; … … 6223 6237 if (iBitEnd & 31) 6224 6238 { 6225 pu32 = (volatile uint32_t RT_FAR *)pvBitmap + (iBitEnd >> 5);6239 pu32 = RT_H2LE_U32((volatile uint32_t RT_FAR *)pvBitmap + (iBitEnd >> 5)); 6226 6240 *pu32 |= (UINT32_C(1) << (iBitEnd & 31)) - 1; 6227 6241 } … … 6236 6250 * @returns Index of the first zero bit. 6237 6251 * @returns -1 if no clear bit was found. 6238 * @param pvBitmap Pointer to the bitmap .6252 * @param pvBitmap Pointer to the bitmap (little endian). 6239 6253 * @param cBits The number of bits in the bitmap. Multiple of 32. 6240 6254 */ 6241 #if RT_INLINE_ASM_EXTERNAL 6255 #if RT_INLINE_ASM_EXTERNAL || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86)) 6242 6256 DECLASM(int32_t) ASMBitFirstClear(const volatile void RT_FAR *pvBitmap, uint32_t cBits) RT_NOTHROW_PROTO; 6243 6257 #else … … 6321 6335 * @returns Index of the first zero bit. 6322 6336 * @returns -1 if no clear bit was found. 6323 * @param pvBitmap Pointer to the bitmap .6337 * @param pvBitmap Pointer to the bitmap (little endian). 6324 6338 * @param cBits The number of bits in the bitmap. Multiple of 32. 6325 6339 * @param iBitPrev The bit returned from the last search. 6326 6340 * The search will start at iBitPrev + 1. 6327 6341 */ 6328 #if RT_INLINE_ASM_EXTERNAL 6342 #if RT_INLINE_ASM_EXTERNAL || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86)) 6329 6343 DECLASM(int) ASMBitNextClear(const volatile void RT_FAR *pvBitmap, uint32_t cBits, uint32_t iBitPrev) RT_NOTHROW_PROTO; 6330 6344 #else … … 6393 6407 * @returns Index of the first set bit. 6394 6408 * @returns -1 if no clear bit was found. 6395 * @param pvBitmap Pointer to the bitmap .6409 * @param pvBitmap Pointer to the bitmap (little endian). 6396 6410 * @param cBits The number of bits in the bitmap. Multiple of 32. 6397 6411 */ 6398 #if RT_INLINE_ASM_EXTERNAL 6412 #if RT_INLINE_ASM_EXTERNAL || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86)) 6399 6413 DECLASM(int32_t) ASMBitFirstSet(const volatile void RT_FAR *pvBitmap, uint32_t cBits) RT_NOTHROW_PROTO; 6400 6414 #else … … 6477 6491 * @returns Index of the next set bit. 6478 6492 * @returns -1 if no set bit was found. 6479 * @param pvBitmap Pointer to the bitmap .6493 * @param pvBitmap Pointer to the bitmap (little endian). 6480 6494 * @param cBits The number of bits in the bitmap. Multiple of 32. 6481 6495 * @param iBitPrev The bit returned from the last search. 6482 6496 * The search will start at iBitPrev + 1. 6483 6497 */ 6484 #if RT_INLINE_ASM_EXTERNAL 6498 #if RT_INLINE_ASM_EXTERNAL || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86)) 6485 6499 DECLASM(int) ASMBitNextSet(const volatile void RT_FAR *pvBitmap, uint32_t cBits, uint32_t iBitPrev) RT_NOTHROW_PROTO; 6486 6500 #else -
trunk/src/VBox/Runtime/Makefile.kmk
r87187 r87192 768 768 common/string/RTStrMemFind32.asm 769 769 RuntimeR3_SOURCES.arm32 := \ 770 common/asm/ASMBitFirstClear-generic.cpp \ 770 771 common/asm/ASMMemZeroPage-generic.cpp \ 771 772 common/asm/ASMMemZero32-generic.cpp \ … … 775 776 common/misc/zero-alt.S 776 777 RuntimeR3_SOURCES.arm64 := \ 778 common/asm/ASMBitFirstClear-generic.cpp \ 777 779 common/asm/ASMMemZeroPage-generic.cpp \ 778 780 common/asm/ASMMemZero32-generic.cpp \ … … 784 786 generic/RTMpGetDescription-generic-stub.cpp \ 785 787 generic/RTSystemIsInsideVM-generic.cpp \ 788 common/asm/ASMBitFirstClear-generic.cpp \ 786 789 common/asm/ASMMemZeroPage-generic.cpp \ 787 790 common/asm/ASMMemZero32-generic.cpp \ … … 795 798 generic/RTMpGetDescription-generic-stub.cpp \ 796 799 generic/RTSystemIsInsideVM-generic.cpp \ 800 common/asm/ASMBitFirstClear-generic.cpp \ 801 common/asm/ASMMemZeroPage-generic.cpp \ 802 common/asm/ASMMemZero32-generic.cpp \ 803 common/asm/ASMMemFill32-generic.cpp \ 804 common/asm/ASMMemFirstMismatchingU8-generic.cpp \ 805 common/asm/ASMMemFirstNonZero-generic.cpp \ 797 806 common/asm/asm-fake.cpp \ 798 807 common/misc/zero-alt.S \ -
trunk/src/VBox/Runtime/common/asm/ASMBitFirstClear-generic.cpp
r87185 r87192 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - ASM MemZeroPage- generic C implementation.3 * IPRT - ASMBitFirstClear - generic C implementation. 4 4 */ 5 5 … … 32 32 #include "internal/iprt.h" 33 33 34 #include <iprt/assert.h> 34 35 35 DECLASM(void *) ASMMemFirstMismatchingU8(void const RT_FAR *pv, size_t cb, uint8_t u8) RT_NOTHROW_DEF 36 37 DECLASM(int32_t) ASMBitFirstClear(const volatile void RT_FAR *pvBitmap, uint32_t cBits) RT_NOTHROW_DEF 36 38 { 37 uint8_t const *pb = (uint8_t const RT_FAR *)pv; 38 for (; cb; cb--, pb++) 39 if (RT_LIKELY(*pb == u8)) 40 { /* likely */ } 39 const volatile size_t RT_FAR *pu = (const volatile size_t RT_FAR *)pvBitmap; 40 Assert(!(cBits & 31)); 41 42 while (cBits >= sizeof(size_t) * 8) 43 { 44 size_t u = *pu; 45 if (u == ~(size_t)0) 46 { } 41 47 else 42 return (void *)pb; 43 return NULL; 48 { 49 size_t const iBaseBit = ((uintptr_t)pu - (uintptr_t)pvBitmap) * 8; 50 #if ARCH_BITS == 32 51 return iBaseBit + ASMBitFirstSetU32(~RT_LE2H_U32(u)) - 1; 52 #elif ARCH_BITS == 64 53 return iBaseBit + ASMBitFirstSetU64(~RT_LE2H_U64(u)) - 1; 54 #else 55 # error "ARCH_BITS or RT_BIG_ENDIAN/RT_LITTLE_ENDIAN is not supported" /** @todo figure out bitmaps on bigendian systems! */ 56 #endif 57 } 58 59 pu++; 60 cBits -= sizeof(size_t) * 8; 61 } 62 63 #if ARCH_BITS > 32 64 if (cBits >= 32) 65 { 66 uint32_t u32 = *(const volatile uint32_t RT_FAR *)pu; 67 if (u32 != UINT32_MAX) 68 { 69 size_t const iBaseBit = ((uintptr_t)pu - (uintptr_t)pvBitmap) * 8; 70 return iBaseBit + ASMBitFirstSetU32(~RT_LE2H_U32(u32)) - 1; 71 } 72 } 73 #endif 74 75 return -1; 44 76 } 45 77 -
trunk/src/VBox/Runtime/common/asm/asm-fake.cpp
r87187 r87192 297 297 } 298 298 299 RTDECL(int) ASMBitFirstClear(const volatile void *pvBitmap, uint32_t cBits)300 {301 uint32_t iBit = 0;302 uint8_t volatile *pu8 = (uint8_t volatile *)pvBitmap;303 304 while (iBit < cBits)305 {306 uint8_t u8 = *pu8;307 if (u8 != UINT8_MAX)308 {309 while (u8 & 1)310 {311 u8 >>= 1;312 iBit++;313 }314 if (iBit >= cBits)315 return -1;316 return iBit;317 }318 319 iBit += 8;320 pu8++;321 }322 return -1;323 }324 325 299 RTDECL(int) ASMBitNextClear(const volatile void *pvBitmap, uint32_t cBits, uint32_t iBitPrev) 326 300 {
Note:
See TracChangeset
for help on using the changeset viewer.