Ejemplo n.º 1
0
void generate_prime(bigint& p, int lgp, int m)
{
  // Here we choose a prime which is the order of a BN curve
  //    - Reason is that there are some applications where this
  //      would be a good idea. So I have hard coded it in here
  //    - This is pointless/impossible for lgp=32, 64 so for 
  //      these do something naive
  //    - Have not tested 256 and 512
  bigint u;
  int ex;
  if (lgp!=32 && lgp!=64)
    { u=1; u=u<<(lgp-1); u=sqrt(sqrt(u/36))/m;
      u=u*m;
      bigint q;
      //   cout << ex << " " << u << " " << numBits(u) << endl;
      p=(((36*u+36)*u+18)*u+6)*u+1;   // The group order of a BN curve
      q=(((36*u+36)*u+24)*u+6)*u+1;   // The base field size of a BN curve
      while (!probPrime(p) || !probPrime(q) || numBits(p)<lgp) 
        { u=u+m;
          p=(((36*u+36)*u+18)*u+6)*u+1;
          q=(((36*u+36)*u+24)*u+6)*u+1;
        }
    }
  else
    { ex=lgp-numBits(m);
      u=1; u=(u<<ex)*m;  p=u+1;
      while (!probPrime(p) || numBits(p)<lgp)
        { u=u+m;  p=u+1; }
    }
  cout << "\t p = " << p << "  u = " << u << "  :   ";
  cout << lgp << " <= " << numBits(p) << endl;
}
Ejemplo n.º 2
0
//----------------------------------------------------------------------------
//
void
TextureMemoryLayout::getMinSize(int& width, int& height, int pixMode)
{
    PixelType pType = modeToPixelType(pixMode);

    // Now get the minimum size
    int tw = numBits(width) - 1;
    int th = numBits(height) - 1;

    width = minSize[pType][tw][th].width;
    height = minSize[pType][tw][th].height;
}
Ejemplo n.º 3
0
void initBitsTab(){
    int i;
    for(i=0;i<256;i++){
	bitsTab[i]=numBits(i);
	printf("%d, ",bitsTab[i]);
    }
}
Ejemplo n.º 4
0
UInt Binarization::binarizeTU_NumBits( UInt val, UInt maxLenBeforeSuffix, UInt riceParam )
{
    UInt len = 0;
    UInt prefix = val >> riceParam;
    UInt threshold = maxLenBeforeSuffix >> riceParam;

    len = prefix + 1;

    if( maxLenBeforeSuffix > val )
    {
        UInt suffix = val - ( prefix << riceParam );
        len += numBits( suffix );
    }
    return len;
}
Ejemplo n.º 5
0
UInt Binarization::binarizeCoefficientRemainingLevel_NumBits( UInt symbol, UInt &rParam )
{
    Int value = (Int)symbol;
    Int threshold = 3 << rParam;

    if( value < threshold )
    {
        return ( value >> rParam ) + 1 + rParam;
    }
    value -= threshold;

    return ( ( ( numBits( value + ( 1 << rParam ) ) ) - 1 ) << 1 ) + 4 - rParam;

    /*Int codeNumber = (Int)symbol;
    UInt length;

    UInt prefixBins, prefixLength, suffixBins, suffixLength;

    log << "(" << symbol << "," << rParam << ")" << std::endl;
    if( codeNumber < ( COEFF_REMAIN_THRESHOLD << rParam ) )
    {
    log << "kodowanie GR, remain: " << codeNumber << " < " << ( COEFF_REMAIN_THRESHOLD << rParam ) << std::endl;
    ++log;

    length = codeNumber >> rParam;

    prefixBins = ( 1 << ( length + 1 ) ) - 2;
    prefixLength = length + 1;
    suffixBins = codeNumber % ( 1 << rParam );
    suffixLength = rParam;

    std::bitset<( sizeof Int ) * 8> first( prefixBins );
    std::bitset<( sizeof Int ) * 8> second( suffixBins );
    for( int i = prefixLength - 1; i >= 0; --i )
    log << first[ i ];
    log << " ";
    for( int i = suffixLength - 1; i >= 0; --i )
    log << second[ i ];
    log << std::endl;
    --log;
    }
    else
    {
    log << "kodowanie TU+EG(k), remain: " << codeNumber << " >= " << ( COEFF_REMAIN_THRESHOLD << rParam ) << std::endl;
    ++log;
    length = rParam;
    codeNumber = codeNumber - ( COEFF_REMAIN_THRESHOLD << rParam );

    log << "poprawka remain: " << codeNumber << std::endl;

    ++log;
    while( codeNumber >= ( 1 << length ) )
    {
    log << "remain = " << codeNumber << " >= 1<<length = " << ( 1 << length ) << std::endl;
    codeNumber -= ( 1 << ( length++ ) );
    log << "remain = " << codeNumber << ", length = " << length << std::endl;
    }
    --log;

    prefixBins = ( 1 << ( COEFF_REMAIN_THRESHOLD + length + 1 - rParam ) ) - 2;
    prefixLength = COEFF_REMAIN_THRESHOLD + length + 1 - rParam;
    suffixBins = codeNumber;
    suffixLength = length;

    std::bitset<( sizeof Int ) * 8> first( prefixBins );
    std::bitset<( sizeof Int ) * 8> second( suffixBins );
    for( int i = prefixLength - 1; i >= 0; --i )
    log << first[ i ];
    log << " ";
    for( int i = suffixLength - 1; i >= 0; --i )
    log << second[ i ];
    log << std::endl;
    --log;
    }
    log << "(" << symbol << "," << rParam << ") -> " << ( prefixLength + suffixLength ) << " bitow" << std::endl;
    return prefixLength + suffixLength;*/
}
Ejemplo n.º 6
0
 vector<int> countBits(int num) {
     vector<int> numBits(num + 1, 0);
     for(int i = 1; i <= num; ++i)
         numBits[i] = numBits[i >> 1] + (i & 1);
     return numBits;
 }