Changeset 40094f in git


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

Legend:

Unmodified
Added
Removed
  • factory/FLINTconvert.cc

    r45e2d2 r40094f  
    711711  Free(exp,N*sizeof(ulong));
    712712  return result;
    713 }
    714 
    715 // stolen from:
    716 // https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog
    717 static inline int SI_LOG2(int v)
    718 {
    719   const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
    720   const unsigned int S[] = {1, 2, 4, 8, 16};
    721 
    722   unsigned int r = 0; // result of log2(v) will go here
    723   if (v & b[4]) { v >>= S[4]; r |= S[4]; }
    724   if (v & b[3]) { v >>= S[3]; r |= S[3]; }
    725   if (v & b[2]) { v >>= S[2]; r |= S[2]; }
    726   if (v & b[1]) { v >>= S[1]; r |= S[1]; }
    727   if (v & b[0]) { v >>= S[0]; r |= S[0]; }
    728   return (int)r;
    729713}
    730714
  • factory/Makefile.am

    r45e2d2 r40094f  
    101101# factory header files
    102102factory_headers = \
     103                si_log2.h \
    103104                cf_assert.h \
    104105                canonicalform.h \
  • factory/canonicalform.cc

    r45e2d2 r40094f  
    427427      case 0: if ( value->inBaseDomain() )
    428428              return value->degree();
    429               break;
     429              break;
    430430    }
    431431#endif
     
    721721        }
    722722        else
    723         /*-----------------------------------------------------*/
     723        /*-----------------------------------------------------*/
    724724        if ((getCharacteristic()==0)
    725725        &&(!hasAlgVar(*this))
     
    13841384        long a = imm2int( value );
    13851385        ASSERT( a > 0, "arg to ilog2() less or equal zero" );
    1386         int n = -1;
    1387         while ( a > 0 )
    1388         {
    1389           n++;
    1390           a /=2;
    1391         }
    1392         return n;
     1386        return SI_LOG2_LONG(a);
    13931387    }
    13941388    else
  • factory/canonicalform.h

    r45e2d2 r40094f  
    3333#include "factory/templates/ftmpl_factor.h"
    3434#include "factory/templates/ftmpl_matrix.h"
     35#include "si_log2.h"
    3536#ifdef HAVE_OMALLOC
    3637#ifndef XMEMORY_H
  • 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
  • factory/factory.template

    r45e2d2 r40094f  
    2525#include "factory/factoryconf.h"
    2626#include <stdint.h>
     27#include "factory/si_log2.h"
    2728#ifdef HAVE_OMALLOC
    2829#include "omalloc/omalloc.h"
  • libpolys/coeffs/longrat.h

    r45e2d2 r40094f  
    1111#include "coeffs/si_gmp.h"
    1212#include "coeffs/coeffs.h"
     13#include "factory/si_log2.h"
    1314
    1415number   nlGetDenom(number &n, const coeffs r); /*for SAGE,, better: n_GetDenom */
     
    8384    unsigned long v;
    8485    v = ABS(i);
    85     return SI_LOG2(v) + 1;
     86    return SI_LOG2_LONG(v) + 1;
    8687  }
    8788  //assume denominator is 0
  • libpolys/misc/auxiliary.h

    r45e2d2 r40094f  
    116116}
    117117#endif
    118 
    119 // stolen from:
    120 // https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog
    121 static inline int SI_LOG2(int v)
    122 {
    123   const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
    124   const unsigned int S[] = {1, 2, 4, 8, 16};
    125 
    126   unsigned int r = 0; // result of log2(v) will go here
    127   if (v & b[4]) { v >>= S[4]; r |= S[4]; }
    128   if (v & b[3]) { v >>= S[3]; r |= S[3]; }
    129   if (v & b[2]) { v >>= S[2]; r |= S[2]; }
    130   if (v & b[1]) { v >>= S[1]; r |= S[1]; }
    131   if (v & b[0]) { v >>= S[0]; r |= S[0]; }
    132   return (int)r;
    133 }
    134118
    135119typedef void* ADDRESS;
Note: See TracChangeset for help on using the changeset viewer.