Skip to content

Commit

Permalink
overlrd2: ctz
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziemas committed Jan 27, 2024
1 parent b54c4ba commit 61da2bd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions game/overlord/jak3/pagemanager.cpp
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

0 comments on commit 61da2bd

Please sign in to comment.