Changeset 40094f in git for factory/cf_util.cc


Ignore:
Timestamp:
Jul 2, 2020, 10:22:19 AM (4 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
53acc46a104d727e78284f0fda06b0ac9460dfae
Parents:
45e2d2305421369847cac77695d8c7aedcbfa7e5
Message:
move SI_LOG2 to factory/si_log2.h
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/cf_util.cc

    r45e2d2 r40094f  
    3939}
    4040
    41 int ilog2 (int a)
     41int ilog2 (int v)
    4242{
    43   int n = -1;
    44   while ( a > 0 )
    45   {
    46     n++;
    47     a /=2;
    48   }
    49   return n;
     43  const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
     44  const unsigned int S[] = {1, 2, 4, 8, 16};
     45
     46  unsigned int r = 0; // result of log2(v) will go here
     47  if (v & b[4]) { v >>= S[4]; r |= S[4]; }
     48  if (v & b[3]) { v >>= S[3]; r |= S[3]; }
     49  if (v & b[2]) { v >>= S[2]; r |= S[2]; }
     50  if (v & b[1]) { v >>= S[1]; r |= S[1]; }
     51  if (v & b[0]) { v >>= S[0]; r |= S[0]; }
     52  return (int)r;
    5053}
    5154
Note: See TracChangeset for help on using the changeset viewer.