-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "pagemanager.h" | ||
|
||
namespace jak3 { | ||
|
||
static inline int ctz(u32 x) { | ||
// Isolate lowest bit and subtract 1 | ||
x = (x & -x) - 1; | ||
|
||
// popcount | ||
x -= (x >> 1) & 0x55555555; | ||
x = (x & 0x33333333) + ((x >> 2) & 0x33333333); | ||
x = (x + (x >> 4)) & 0x0f0f0f0f; | ||
x += (x >> 8); | ||
x += (x >> 16); | ||
x &= 0x3f; | ||
|
||
return static_cast<int>(x); | ||
} | ||
|
||
} // namespace jak3 |