Skip to content

Commit 61da2bd

Browse files
committed
overlrd2: ctz
1 parent b54c4ba commit 61da2bd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

game/overlord/jak3/pagemanager.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "pagemanager.h"
2+
3+
namespace jak3 {
4+
5+
static inline int ctz(u32 x) {
6+
// Isolate lowest bit and subtract 1
7+
x = (x & -x) - 1;
8+
9+
// popcount
10+
x -= (x >> 1) & 0x55555555;
11+
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
12+
x = (x + (x >> 4)) & 0x0f0f0f0f;
13+
x += (x >> 8);
14+
x += (x >> 16);
15+
x &= 0x3f;
16+
17+
return static_cast<int>(x);
18+
}
19+
20+
} // namespace jak3

0 commit comments

Comments
 (0)