- Timestamp:
- Jan 12, 2021 4:11:02 PM (4 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/asm/ASMBitFirstSet-generic.cpp
r87203 r87229 46 46 { 47 47 uint32_t u32 = *(const volatile uint32_t RT_FAR *)pu; 48 if (u32 != UINT32_MAX)48 if (u32 != 0) 49 49 { 50 50 size_t const iBaseBit = ((uintptr_t)pu - (uintptr_t)pvBitmap) * 8; … … 85 85 { 86 86 uint32_t u32 = *(const volatile uint32_t RT_FAR *)pu; 87 if (u32 != UINT32_MAX)87 if (u32 != 0) 88 88 { 89 89 size_t const iBaseBit = ((uintptr_t)pu - (uintptr_t)pvBitmap) * 8; -
trunk/src/VBox/Runtime/testcase/tstRTBitOperations.cpp
r82968 r87229 154 154 #define CHECK_BIT2(expr, b1, b2) do { if (!(expr)) { RTTestFailed(hTest, "line %d, b1=%d b2=%d: %s", __LINE__, b1, b2, #expr); } CHECK_GUARD(s); } while (0) 155 155 #define CHECK_BIT3(expr, b1, b2, b3) do { if (!(expr)) { RTTestFailed(hTest, "line %d, b1=%d b2=%d b3=%d: %s", __LINE__, b1, b2, b3, #expr); } CHECK_GUARD(s); } while (0) 156 #define CHECK_VAL(a_RetType, a_Fmt, a_ValueExpr, a_Expect) \ 157 do { a_RetType rcCheckRet = (a_ValueExpr); \ 158 if (RT_LIKELY((rcCheckRet) == (a_Expect))) {} \ 159 else RTTestFailed(hTest, "line %d: %s -> " a_Fmt ", expected " a_Fmt "", \ 160 __LINE__, #a_ValueExpr, rcCheckRet, a_Expect); \ 161 CHECK_GUARD(s); \ 162 } while (0) 156 163 157 164 #define GUARD_MAP(p) do { } while (0) … … 163 170 MAP_CLEAR(p); 164 171 CHECK_GUARD(p); 172 173 /* 174 * Check the primitives first: 175 */ 176 CHECK_VAL(unsigned, "%u", ASMBitLastSetU32(0), 0); 177 CHECK(ASMBitLastSetU32(1) == 1); 178 CHECK(ASMBitLastSetU32(0x80000000) == 32); 179 CHECK(ASMBitLastSetU32(0xffffffff) == 32); 180 CHECK(ASMBitLastSetU32(RT_BIT(23) | RT_BIT(11)) == 24); 181 for (i = 0; i < 32; i++) 182 CHECK(ASMBitLastSetU32(1 << i) == (unsigned)i + 1); 183 184 CHECK(ASMBitFirstSetU32(0) == 0); 185 CHECK(ASMBitFirstSetU32(1) == 1); 186 CHECK(ASMBitFirstSetU32(0x80000000) == 32); 187 CHECK(ASMBitFirstSetU32(0xffffffff) == 1); 188 CHECK(ASMBitFirstSetU32(RT_BIT(23) | RT_BIT(11)) == 12); 189 for (i = 0; i < 32; i++) 190 CHECK(ASMBitFirstSetU32(1 << i) == (unsigned)i + 1); 191 192 CHECK(ASMBitLastSetU64(UINT64_C(0)) == 0); 193 CHECK(ASMBitLastSetU64(UINT64_C(1)) == 1); 194 CHECK(ASMBitLastSetU64(UINT64_C(0x80000000)) == 32); 195 CHECK(ASMBitLastSetU64(UINT64_C(0xffffffff)) == 32); 196 CHECK(ASMBitLastSetU64(RT_BIT_64(33) | RT_BIT_64(11)) == 34); 197 for (i = 0; i < 64; i++) 198 CHECK(ASMBitLastSetU64(UINT64_C(1) << i) == (unsigned)i + 1); 199 200 CHECK(ASMBitFirstSetU64(UINT64_C(0)) == 0); 201 CHECK(ASMBitFirstSetU64(UINT64_C(1)) == 1); 202 CHECK(ASMBitFirstSetU64(UINT64_C(0x80000000)) == 32); 203 CHECK(ASMBitFirstSetU64(UINT64_C(0x800000000000)) == 48); 204 CHECK(ASMBitFirstSetU64(UINT64_C(0x8000000000000000)) == 64); 205 CHECK(ASMBitFirstSetU64(UINT64_C(0xffffffff)) == 1); 206 CHECK(ASMBitFirstSetU64(UINT64_C(0xffffffffffffffff)) == 1); 207 CHECK(ASMBitFirstSetU64(RT_BIT_64(33) | RT_BIT_64(11)) == 12); 208 for (i = 0; i < 64; i++) 209 CHECK(ASMBitFirstSetU64(UINT64_C(1) << i) == (unsigned)i + 1); 210 211 CHECK_VAL(unsigned, "%u", ASMBitFirstSetU32(0), 0); 212 CHECK_VAL(unsigned, "%u", ASMBitFirstSetU32(UINT32_C(0x84210000)), 16+1); 213 CHECK_VAL(unsigned, "%u", ASMBitFirstSetU32(UINT32_C(0xffffffff)), 0+1); 214 CHECK_VAL(unsigned, "%u", ASMBitFirstSetU32(UINT32_C(0x80000000)), 31+1); 215 216 CHECK_VAL(unsigned, "%u", ASMBitFirstSetU64(0), 0); 217 CHECK_VAL(unsigned, "%u", ASMBitFirstSetU64(UINT64_C(0xffffeeee84210000)), 16+1); 218 CHECK_VAL(unsigned, "%u", ASMBitFirstSetU64(UINT64_C(0xffffeeee00000000)), 33+1); 219 CHECK_VAL(unsigned, "%u", ASMBitFirstSetU64(UINT64_C(0x8000000000000000)), 63+1); 220 CHECK_VAL(unsigned, "%u", ASMBitFirstSetU64(UINT64_C(0xffffffffffffffff)), 0+1); 221 222 CHECK_VAL(unsigned, "%u", ASMBitLastSetU32(0), 0); 223 CHECK_VAL(unsigned, "%u", ASMBitLastSetU32(UINT32_C(0xffffffff)), 31+1); 224 CHECK_VAL(unsigned, "%u", ASMBitLastSetU32(UINT32_C(0x00000001)), 0+1); 225 CHECK_VAL(unsigned, "%u", ASMBitLastSetU32(UINT32_C(0x0001ffff)), 16+1); 226 CHECK_VAL(unsigned, "%u", ASMBitLastSetU32(UINT32_C(0x01234567)), 24+1); 227 228 CHECK_VAL(unsigned, "%u", ASMBitLastSetU64(0), 0); 229 CHECK_VAL(unsigned, "%u", ASMBitLastSetU64(UINT64_C(0x0000807060504030)), 47+1); 230 231 CHECK_VAL(uint16_t, "%#x", ASMByteSwapU16(UINT16_C(0x1234)), UINT16_C(0x3412)); 232 233 CHECK_VAL(uint32_t, "%#x", ASMByteSwapU32(UINT32_C(0x12345678)), UINT32_C(0x78563412)); 234 235 CHECK_VAL(uint64_t, "%#llx", ASMByteSwapU64(UINT64_C(0x1122334455667788)), UINT64_C(0x8877665544332211)); 236 237 CHECK_VAL(uint32_t, "%#x", ASMRotateLeftU32(UINT32_C(0x12345678), 4), UINT32_C(0x23456781)); 238 CHECK_VAL(uint32_t, "%#x", ASMRotateLeftU32(UINT32_C(0x12345678), 16), UINT32_C(0x56781234)); 239 CHECK_VAL(uint32_t, "%#x", ASMRotateLeftU32(UINT32_C(0x82868080), 29), UINT32_C(0x1050d010)); 240 CHECK_VAL(uint32_t, "%#x", ASMRotateLeftU32(UINT32_C(0xfedcba89), 1), UINT32_C(0xfdb97513)); 241 242 CHECK_VAL(uint32_t, "%#x", ASMRotateRightU32(UINT32_C(0x12345678), 4), UINT32_C(0x81234567)); 243 CHECK_VAL(uint32_t, "%#x", ASMRotateRightU32(UINT32_C(0x12345678), 16), UINT32_C(0x56781234)); 244 CHECK_VAL(uint32_t, "%#x", ASMRotateRightU32(UINT32_C(0x82868080), 29), UINT32_C(0x14340404)); 245 CHECK_VAL(uint32_t, "%#x", ASMRotateRightU32(UINT32_C(0xfedcba89), 1), UINT32_C(0xff6e5d44)); 246 247 CHECK_VAL(uint64_t, "%#llx", ASMRotateLeftU64(UINT64_C(0x123456789abcdef0), 4), UINT64_C(0x23456789abcdef01)); 248 CHECK_VAL(uint64_t, "%#llx", ASMRotateLeftU64(UINT64_C(0x123456789abcdef0), 16), UINT64_C(0x56789abcdef01234)); 249 CHECK_VAL(uint64_t, "%#llx", ASMRotateLeftU64(UINT64_C(0x123456789abcdef0), 32), UINT64_C(0x9abcdef012345678)); 250 CHECK_VAL(uint64_t, "%#llx", ASMRotateLeftU64(UINT64_C(0x123456789abcdef0), 48), UINT64_C(0xdef0123456789abc)); 251 CHECK_VAL(uint64_t, "%#llx", ASMRotateLeftU64(UINT64_C(0x123456789abcdef0), 56), UINT64_C(0xf0123456789abcde)); 252 CHECK_VAL(uint64_t, "%#llx", ASMRotateLeftU64(UINT64_C(0x123456789abcdef0), 60), UINT64_C(0x0123456789abcdef)); 253 CHECK_VAL(uint64_t, "%#llx", ASMRotateLeftU64(UINT64_C(0x8182838485868788), 63), UINT64_C(0x40c141c242c343c4)); 254 CHECK_VAL(uint64_t, "%#llx", ASMRotateLeftU64(UINT64_C(0x8182838485868788), 1), UINT64_C(0x030507090b0d0f11)); 255 CHECK_VAL(uint64_t, "%#llx", ASMRotateLeftU64(UINT64_C(0x8182838485868788), 29), UINT64_C(0x90b0d0f110305070)); 256 257 CHECK_VAL(uint64_t, "%#llx", ASMRotateRightU64(UINT64_C(0x123456789abcdef0), 4), UINT64_C(0x0123456789abcdef)); 258 CHECK_VAL(uint64_t, "%#llx", ASMRotateRightU64(UINT64_C(0x123456789abcdef0), 16), UINT64_C(0xdef0123456789abc)); 259 CHECK_VAL(uint64_t, "%#llx", ASMRotateRightU64(UINT64_C(0x123456789abcdef0), 32), UINT64_C(0x9abcdef012345678)); 260 CHECK_VAL(uint64_t, "%#llx", ASMRotateRightU64(UINT64_C(0x123456789abcdef0), 48), UINT64_C(0x56789abcdef01234)); 261 CHECK_VAL(uint64_t, "%#llx", ASMRotateRightU64(UINT64_C(0x123456789abcdef0), 56), UINT64_C(0x3456789abcdef012)); 262 CHECK_VAL(uint64_t, "%#llx", ASMRotateRightU64(UINT64_C(0x123456789abcdef0), 60), UINT64_C(0x23456789abcdef01)); 263 CHECK_VAL(uint64_t, "%#llx", ASMRotateRightU64(UINT64_C(0x8182838485868788), 63), UINT64_C(0x030507090b0d0f11)); 264 CHECK_VAL(uint64_t, "%#llx", ASMRotateRightU64(UINT64_C(0x8182838485868788), 1), UINT64_C(0x40c141c242c343c4)); 265 CHECK_VAL(uint64_t, "%#llx", ASMRotateRightU64(UINT64_C(0x8182838485868788), 29), UINT64_C(0x2c343c440c141c24)); 266 267 268 /* 269 * Variable sized bitmaps: 270 */ 165 271 166 272 /* bit set */ … … 263 369 /* bit searching */ 264 370 MAP_SET(p); 265 CHECK (ASMBitFirstClear(&p->au32[0], sizeof(p->au32) * 8) ==-1);266 CHECK (ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8) ==0);371 CHECK_VAL(int32_t, "%d", ASMBitFirstClear(&p->au32[0], sizeof(p->au32) * 8), -1); 372 CHECK_VAL(int32_t, "%d", ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8), 0); 267 373 268 374 ASMBitClear(&p->au32[0], 1); 269 CHECK (ASMBitFirstClear(&p->au32[0], sizeof(p->au32) * 8) ==1);270 CHECK (ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8) ==0);375 CHECK_VAL(int32_t, "%d", ASMBitFirstClear(&p->au32[0], sizeof(p->au32) * 8), 1); 376 CHECK_VAL(int32_t, "%d", ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8), 0); 271 377 272 378 MAP_SET(p); 273 379 ASMBitClear(&p->au32[0], 95); 274 CHECK (ASMBitFirstClear(&p->au32[0], sizeof(p->au32) * 8) ==95);275 CHECK (ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8) ==0);380 CHECK_VAL(int32_t, "%d", ASMBitFirstClear(&p->au32[0], sizeof(p->au32) * 8), 95); 381 CHECK_VAL(int32_t, "%d", ASMBitFirstSet(&p->au32[0], sizeof(p->au32) * 8), 0); 276 382 277 383 MAP_SET(p); … … 411 517 } 412 518 413 414 CHECK(ASMBitLastSetU32(0) == 0);415 CHECK(ASMBitLastSetU32(1) == 1);416 CHECK(ASMBitLastSetU32(0x80000000) == 32);417 CHECK(ASMBitLastSetU32(0xffffffff) == 32);418 CHECK(ASMBitLastSetU32(RT_BIT(23) | RT_BIT(11)) == 24);419 for (i = 0; i < 32; i++)420 CHECK(ASMBitLastSetU32(1 << i) == (unsigned)i + 1);421 422 CHECK(ASMBitFirstSetU32(0) == 0);423 CHECK(ASMBitFirstSetU32(1) == 1);424 CHECK(ASMBitFirstSetU32(0x80000000) == 32);425 CHECK(ASMBitFirstSetU32(0xffffffff) == 1);426 CHECK(ASMBitFirstSetU32(RT_BIT(23) | RT_BIT(11)) == 12);427 for (i = 0; i < 32; i++)428 CHECK(ASMBitFirstSetU32(1 << i) == (unsigned)i + 1);429 430 CHECK(ASMBitLastSetU64(UINT64_C(0)) == 0);431 CHECK(ASMBitLastSetU64(UINT64_C(1)) == 1);432 CHECK(ASMBitLastSetU64(UINT64_C(0x80000000)) == 32);433 CHECK(ASMBitLastSetU64(UINT64_C(0xffffffff)) == 32);434 CHECK(ASMBitLastSetU64(RT_BIT_64(33) | RT_BIT_64(11)) == 34);435 for (i = 0; i < 64; i++)436 CHECK(ASMBitLastSetU64(UINT64_C(1) << i) == (unsigned)i + 1);437 438 CHECK(ASMBitFirstSetU64(UINT64_C(0)) == 0);439 CHECK(ASMBitFirstSetU64(UINT64_C(1)) == 1);440 CHECK(ASMBitFirstSetU64(UINT64_C(0x80000000)) == 32);441 CHECK(ASMBitFirstSetU64(UINT64_C(0xffffffff)) == 1);442 CHECK(ASMBitFirstSetU64(RT_BIT_64(33) | RT_BIT_64(11)) == 12);443 for (i = 0; i < 64; i++)444 CHECK(ASMBitFirstSetU64(UINT64_C(1) << i) == (unsigned)i + 1);445 446 519 /* 447 520 * Special tests.
Note:
See TracChangeset
for help on using the changeset viewer.