Пример #1
0
 static IntType add(IntType x, IntType c)
 {
     if(((unsigned_m() - 1) & unsigned_m()) == 0)
         return (unsigned_type(x) + unsigned_type(c)) & (unsigned_m() - 1);
     else if(c == 0)
         return x;
     else if(x < m - c)
         return x + c;
     else
         return x - (m - c);
 }
Пример #2
0
 static IntType mult_add(IntType a, IntType x, IntType c)
 {
     if(((unsigned_m() - 1) & unsigned_m()) == 0)
         return (unsigned_type(a) * unsigned_type(x) + unsigned_type(c)) & (unsigned_m() - 1);
     else if(a == 0)
         return c;
     else if(m <= (traits::const_max-c)/a) {  // i.e. a*m+c <= max
         IntType supress_warnings = (m == 0);
         BOOST_ASSERT(supress_warnings == 0);
         return (a*x+c) % (m + supress_warnings);
     } else
         return add(mult(a, x), c);
 }
Пример #3
0
void request::check_alignment() const
{
    if (m_offset % STXXL_BLOCK_ALIGN != 0)
        STXXL_ERRMSG("Offset is not aligned: modulo " <<
                     STXXL_BLOCK_ALIGN << " = " << m_offset % STXXL_BLOCK_ALIGN);

    if (m_bytes % STXXL_BLOCK_ALIGN != 0)
        STXXL_ERRMSG("Size is not a multiple of " <<
                     STXXL_BLOCK_ALIGN << ", = " << m_bytes % STXXL_BLOCK_ALIGN);

    if (unsigned_type(m_buffer) % STXXL_BLOCK_ALIGN != 0)
        STXXL_ERRMSG("Buffer is not aligned: modulo " <<
                     STXXL_BLOCK_ALIGN << " = " << unsigned_type(m_buffer) % STXXL_BLOCK_ALIGN <<
                     " (" << m_buffer << ")");
}
Пример #4
0
 static IntType mult(IntType a, IntType x)
 {
     if(((unsigned_m() - 1) & unsigned_m()) == 0)
         return unsigned_type(a) * unsigned_type(x) & (unsigned_m() - 1);
     else if(a == 0)
         return 0;
     else if(a == 1)
         return x;
     else if(m <= traits::const_max/a)      // i.e. a*m <= max
         return mult_small(a, x);
     else if(traits::is_signed && (m%a < m/a))
         return mult_schrage(a, x);
     else
         return mult_general(a, x);
 }
Пример #5
0
  int utype_prior(unsigned_type ui)
  {
    // TBD: Implement a templated binary search for this.
    int priority_bit;

    unsigned_type priority_mask = unsigned_type(unsigned_type(1U) << (std::numeric_limits<unsigned_type>::digits - 1));

    for(priority_bit = std::numeric_limits<unsigned_type>::digits - 1; priority_bit >= 0; --priority_bit)
    {
      if(unsigned_type(priority_mask & ui) != unsigned_type(0U))
      {
        break;
      }

      priority_mask >>= 1;
    }

    return priority_bit;
  }
Пример #6
0
 static IntType apply(IntType x)
 {
     if(((unsigned_m() - 1) & unsigned_m()) == 0)
         return (unsigned_type(x)) & (unsigned_m() - 1);
     else {
         IntType supress_warnings = (m == 0);
         BOOST_ASSERT(supress_warnings == 0);
         return x % (m + supress_warnings);
     }
 }