My Project
Loading...
Searching...
No Matches
Functions
si_log2.h File Reference
#include "factory/factoryconf.h"

Go to the source code of this file.

Functions

static int SI_LOG2 (int v)
 
static int SI_LOG2_LONG (long v)
 

Function Documentation

◆ SI_LOG2()

static int SI_LOG2 ( int  v)
inlinestatic

Definition at line 6 of file si_log2.h.

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}
CanonicalForm b
Definition: cfModGcd.cc:4103
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39

◆ SI_LOG2_LONG()

static int SI_LOG2_LONG ( long  v)
inlinestatic

Definition at line 22 of file si_log2.h.

23{
24 const unsigned long b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000, 0xFFFFFFFF00000000UL};
25 const unsigned int S[] = {1, 2, 4, 8, 16, 32};
26
27 unsigned int r = 0; // result of log2(v) will go here
28 if (v & b[5]) { v >>= S[5]; r |= S[5]; }
29 if (v & b[4]) { v >>= S[4]; r |= S[4]; }
30 if (v & b[3]) { v >>= S[3]; r |= S[3]; }
31 if (v & b[2]) { v >>= S[2]; r |= S[2]; }
32 if (v & b[1]) { v >>= S[1]; r |= S[1]; }
33 if (v & b[0]) { v >>= S[0]; r |= S[0]; }
34 return (int)r;
35}