MCPcopy Create free account
hub / github.com/Singular/Singular / SI_LOG2

Function SI_LOG2

factory/si_log2.h:6–18  ·  view source on GitHub ↗

stolen from: https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog

Source from the content-addressed store, hash-verified

4// stolen from:
5// https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog
6static inline int SI_LOG2(int v)
7{
8 const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
9 const unsigned int S[] = {1, 2, 4, 8, 16};
10
11 unsigned int r = 0; // result of log2(v) will go here
12 if (v & b[4]) { v >>= S[4]; r |= S[4]; }
13 if (v & b[3]) { v >>= S[3]; r |= S[3]; }
14 if (v & b[2]) { v >>= S[2]; r |= S[2]; }
15 if (v & b[1]) { v >>= S[1]; r |= S[1]; }
16 if (v & b[0]) { v >>= S[0]; r |= S[0]; }
17 return (int)r;
18}
19#if SIZEOF_LONG==4
20#define SI_LOG2_LONG(A) SI_LOG2(A)
21#else

Callers 12

mulFlintMP_ZpFunction · 0.85
mulFlintMP_QQFunction · 0.85
gcdFlintMP_ZpFunction · 0.85
UnivariateQuadraticLiftFunction · 0.85
sBucket_Merge_mFunction · 0.85
sBucket_Merge_pFunction · 0.85
sBucket_Add_mFunction · 0.85
sBucket_Add_pFunction · 0.85
sBucketCanonicalizeFunction · 0.85
pLogLengthFunction · 0.85
jjCRING_ZpFunction · 0.85
ssiWriteRing_RFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected