当前位置: 首页>>代码示例>>C++>>正文


C++ count_leading_zeros函数代码示例

本文整理汇总了C++中count_leading_zeros函数的典型用法代码示例。如果您正苦于以下问题:C++ count_leading_zeros函数的具体用法?C++ count_leading_zeros怎么用?C++ count_leading_zeros使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了count_leading_zeros函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BM_count_leading_zeros_noasm

static void BM_count_leading_zeros_noasm(benchmark::State& state) {
	UINT32 cnt = 0x332533;
	while (state.KeepRunning()) {
		(void)count_leading_zeros(cnt);
		cnt++;
	}
}
开发者ID:Ashura-X,项目名称:mame,代码行数:7,代码来源:eminline_noasm.cpp

示例2: countleadbits

static inline std::size_t countleadbits(std::size_t x)
{
#ifndef count_leading_zeros
	std::size_t msk;
	std::size_t ret;
	if (x < 0x100)
	{
		msk = 0x80;
		ret = 24;
	}
	else if (x < 0x10000)
	{
		msk = 0x8000;
		ret = 16;
	}
	else if (x < 0x1000000)
	{
		msk = 0x800000;
		ret = 8;
	}
	else
	{
		msk = 0x80000000;
		ret = 0;
	}
	while ((msk & x) == 0 && ret < 31)
	{
		msk = msk >> 1;
		ret++;
	}
	return ret;
#else
	return count_leading_zeros(x);
#endif
}
开发者ID:antonioginer,项目名称:mame,代码行数:35,代码来源:pstring.cpp

示例3: mpfr_ui_div

int
mpfr_ui_div (mpfr_ptr y, unsigned long int u, mpfr_srcptr x, mpfr_rnd_t rnd_mode)
{
  mpfr_t uu;
  mp_limb_t up[1];
  unsigned long cnt;

  MPFR_LOG_FUNC
    (("u=%lu x[%Pu]=%.*Rg rnd=%d",
      u, mpfr_get_prec(x), mpfr_log_prec, x, rnd_mode),
     ("y[%Pu]=%.*Rg", mpfr_get_prec(y), mpfr_log_prec, y));

  if (MPFR_UNLIKELY(MPFR_IS_SINGULAR(x)))
    {
      if (MPFR_IS_NAN(x))
        {
          MPFR_SET_NAN(y);
          MPFR_RET_NAN;
        }
      else if (MPFR_IS_INF(x)) /* u/Inf = 0 */
        {
          MPFR_SET_ZERO(y);
          MPFR_SET_SAME_SIGN(y,x);
          MPFR_RET(0);
        }
      else /* u / 0 */
        {
          MPFR_ASSERTD(MPFR_IS_ZERO(x));
          if (u)
            {
              /* u > 0, so y = sign(x) * Inf */
              MPFR_SET_SAME_SIGN(y, x);
              MPFR_SET_INF(y);
              mpfr_set_divby0 ();
              MPFR_RET(0);
            }
          else
            {
              /* 0 / 0 */
              MPFR_SET_NAN(y);
              MPFR_RET_NAN;
            }
        }
    }
  else if (MPFR_LIKELY(u != 0))
    {
      MPFR_TMP_INIT1(up, uu, GMP_NUMB_BITS);
      MPFR_ASSERTN(u == (mp_limb_t) u);
      count_leading_zeros(cnt, (mp_limb_t) u);
      up[0] = (mp_limb_t) u << cnt;
      MPFR_SET_EXP (uu, GMP_NUMB_BITS - cnt);
      return mpfr_div (y, uu, x, rnd_mode);
    }
  else /* u = 0, and x != 0 */
    {
      MPFR_SET_ZERO(y);         /* if u=0, then set y to 0 */
      MPFR_SET_SAME_SIGN(y, x); /* u considered as +0: sign(+0/x) = sign(x) */
      MPFR_RET(0);
    }
}
开发者ID:SESA,项目名称:EbbRT-mpfr,代码行数:60,代码来源:ui_div.c

示例4: mpfr_urandomb

int
mpfr_urandomb (mpfr_ptr rop, gmp_randstate_t rstate)
{
  mp_ptr rp;
  mp_prec_t nbits;
  mp_size_t nlimbs;
  mp_size_t k; /* number of high zero limbs */
  mp_exp_t exp;
  int cnt;

  MPFR_CLEAR_FLAGS (rop);

  rp = MPFR_MANT (rop);
  nbits = MPFR_PREC (rop);
  nlimbs = MPFR_LIMB_SIZE (rop);
  MPFR_SET_POS (rop);

  /* Uniform non-normalized significand */
  _gmp_rand (rp, rstate, nlimbs * BITS_PER_MP_LIMB);

  /* If nbits isn't a multiple of BITS_PER_MP_LIMB, mask the low bits */
  cnt = nlimbs * BITS_PER_MP_LIMB - nbits;
  if (MPFR_LIKELY (cnt != 0))
    rp[0] &= ~MPFR_LIMB_MASK (cnt);

  /* Count the null significant limbs and remaining limbs */
  exp = 0;
  k = 0;
  while (nlimbs != 0 && rp[nlimbs - 1] == 0)
    {
      k ++;
      nlimbs --;
      exp -= BITS_PER_MP_LIMB;
    }

  if (MPFR_LIKELY (nlimbs != 0)) /* otherwise value is zero */
    {
      count_leading_zeros (cnt, rp[nlimbs - 1]);
      /* Normalization */
      if (mpfr_set_exp (rop, exp - cnt))
        {
          /* If the exponent is not in the current exponent range, we
             choose to return a NaN as this is probably a user error.
             Indeed this can happen only if the exponent range has been
             reduced to a very small interval and/or the precision is
             huge (very unlikely). */
          MPFR_SET_NAN (rop);
          __gmpfr_flags |= MPFR_FLAGS_NAN; /* Can't use MPFR_RET_NAN */
          return 1;
        }
      if (cnt != 0)
        mpn_lshift (rp + k, rp, nlimbs, cnt);
      if (k != 0)
        MPN_ZERO (rp, k);
    }
  else
    MPFR_SET_ZERO (rop);

  return 0;
}
开发者ID:Scorpiion,项目名称:Renux_cross_gcc,代码行数:60,代码来源:urandomb.c

示例5: decode_base58

		data_chunk decode_base58(std::string encoded)
		{
			// Trim spaces and newlines around the string.
			boost::algorithm::trim(encoded);
			size_t leading_zeros = count_leading_zeros(encoded);

			// log(58) / log(256), rounded up.
			const size_t data_size = encoded.size() * 733 / 1000 + 1;
			// Allocate enough space in big-endian base256 representation.
			data_chunk data(data_size);

			// Process the characters.
			for (auto it = encoded.begin() + leading_zeros; it != encoded.end(); ++it)
			{
				size_t carry = base58_chars.find(*it);
				if (carry == std::string::npos)
					return data_chunk();
				unpack_char(data, carry);
			}

			// Skip leading zeroes in data.
			auto first_nonzero = search_first_nonzero(data);

			// Copy result into output vector.
			data_chunk decoded;
			const size_t estimated_size =
				leading_zeros + (data.end() - first_nonzero);
			decoded.reserve(estimated_size);
			decoded.assign(leading_zeros, 0x00);
			decoded.insert(decoded.end(), first_nonzero, data.cend());
			return decoded;
		}
开发者ID:ballisticwhisper,项目名称:decentralised,代码行数:32,代码来源:base58.cpp

示例6: mpfr_random2

void
mpfr_random2 (mpfr_ptr x, mp_size_t size, mp_exp_t exp)
{
  mp_size_t xn;
  unsigned long cnt;
  mp_ptr xp = MPFR_MANT(x), yp[1];
  mp_size_t prec = (MPFR_PREC(x) - 1)/BITS_PER_MP_LIMB; 

  MPFR_CLEAR_FLAGS(x);
  xn = ABS (size);
  if (xn != 0)
    {
      if (xn > prec + 1)
	xn = prec + 1;

      mpn_random2 (xp, xn);
    }

  if (exp != 0) {
    /* use mpn_random instead of random since that function is not
       available on all platforms (for example HPUX, DEC OSF, ...) */
    mpn_random ((mp_limb_t*) yp, 1);
    exp = (mp_exp_t) yp[0] % (2 * exp) - exp;
  }

  count_leading_zeros(cnt, xp[xn - 1]); 
  if (cnt) mpn_lshift(xp, xp, xn, cnt); 
  MPFR_EXP(x) = exp-cnt; 
  cnt = xn*BITS_PER_MP_LIMB - prec; 
  /* cnt is the number of non significant bits in the low limb */
  xp[0] &= ~((MP_LIMB_T_ONE << cnt) - MP_LIMB_T_ONE);
}
开发者ID:mahdiz,项目名称:mpclib,代码行数:32,代码来源:random2.c

示例7: countleadbits

static inline unsigned countleadbits(unsigned x)
{
#ifndef count_leading_zeros
	unsigned msk;
	unsigned ret;
	if (x < 0x100)
	{
		msk = 0x80;
		ret = 24;
	}
	else if (x < 0x10000)
	{
		msk = 0x8000;
		ret = 16;
	}
	else if (x < 0x1000000)
	{
		msk = 0x800000;
		ret = 8;
	}
	else
	{
		msk = 0x80000000;
		ret = 0;
	}
	while ((msk & x) == 0 && ret < 31)
	{
		msk = msk >> 1;
		ret++;
	}
	return ret;
#else
	return count_leading_zeros(x);
#endif
}
开发者ID:NULUSIOS,项目名称:mame,代码行数:35,代码来源:pstring.cpp

示例8: encode_base58

		std::string encode_base58(const data_chunk& unencoded)
		{
			size_t leading_zeros = count_leading_zeros(unencoded);

			// size = log(256) / log(58), rounded up.
			const size_t number_nonzero = unencoded.size() - leading_zeros;
			const size_t indexes_size = number_nonzero * 138 / 100 + 1;
			// Allocate enough space in big-endian base58 representation.
			data_chunk indexes(indexes_size);

			// Process the bytes.
			for (auto it = unencoded.begin() + leading_zeros;
				it != unencoded.end(); ++it)
			{
				pack_value(indexes, *it);
			}

			// Skip leading zeroes in base58 result.
			auto first_nonzero = search_first_nonzero(indexes);

			// Translate the result into a string.
			std::string encoded;
			const size_t estimated_size =
				leading_zeros + (indexes.end() - first_nonzero);
			encoded.reserve(estimated_size);
			encoded.assign(leading_zeros, '1');
			// Set actual main bytes.
			for (auto it = first_nonzero; it != indexes.end(); ++it)
			{
				const size_t index = *it;
				encoded += base58_chars[index];
			}
			return encoded;
		}
开发者ID:ballisticwhisper,项目名称:decentralised,代码行数:34,代码来源:base58.cpp

示例9: mpz_get_d_2exp

double
mpz_get_d_2exp (signed long int *exp2, mpz_srcptr src)
{
  double res;
  mp_size_t size, i, n_limbs_to_use;
  int negative;
  mp_ptr qp;
  int cnt;

  size = SIZ(src);
  if (size == 0)
    {
      *exp2 = 0;
      return 0.0;
    }

  negative = size < 0;
  size = ABS (size);
  qp = PTR(src);

  n_limbs_to_use = MIN (LIMBS_PER_DOUBLE, size);
  qp += size - n_limbs_to_use;
  res = qp[0] / MP_BASE_AS_DOUBLE;
  for (i = 1; i < n_limbs_to_use; i++)
    res = (res + qp[i]) / MP_BASE_AS_DOUBLE;
  count_leading_zeros (cnt, qp[n_limbs_to_use - 1]);
  *exp2 = size * BITS_PER_MP_LIMB - cnt;
  res = res * ((mp_limb_t) 1 << cnt);

  return negative ? -res : res;
}
开发者ID:mahdiz,项目名称:mpclib,代码行数:31,代码来源:get_d_2exp.c

示例10: mpf_get_d_2exp

double
mpf_get_d_2exp (signed long *exp2, mpf_srcptr src)
{
  mp_size_t size, abs_size;
  mp_srcptr ptr;
  int cnt;
  signed long exp;

  size = SIZ(src);
  if (UNLIKELY (size == 0))
    {
      *exp2 = 0;
      return 0.0;
    }

  ptr = PTR(src);
  abs_size = ABS (size);
  count_leading_zeros (cnt, ptr[abs_size - 1]);
  cnt -= GMP_NAIL_BITS;

  exp = EXP(src) * GMP_NUMB_BITS - cnt;
  *exp2 = exp;

  return mpn_get_d (ptr, abs_size, size,
                    (long) - (abs_size * GMP_NUMB_BITS - cnt));
}
开发者ID:adyache,项目名称:mpir,代码行数:26,代码来源:get_d_2exp.c

示例11: mpfr_sub_ui

int
mpfr_sub_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
{
  if (MPFR_LIKELY (u != 0))  /* if u=0, do nothing */
    {
      mpfr_t uu;
      mp_limb_t up[1];
      unsigned long cnt;
      int inex;

      MPFR_SAVE_EXPO_DECL (expo);

      MPFR_TMP_INIT1 (up, uu, BITS_PER_MP_LIMB);
      MPFR_ASSERTN (u == (mp_limb_t) u);
      count_leading_zeros (cnt, (mp_limb_t) u);
      *up = (mp_limb_t) u << cnt;

      /* Optimization note: Exponent save/restore operations may be
         removed if mpfr_sub works even when uu is out-of-range. */
      MPFR_SAVE_EXPO_MARK (expo);
      MPFR_SET_EXP (uu, BITS_PER_MP_LIMB - cnt);
      inex = mpfr_sub (y, x, uu, rnd_mode);
      MPFR_SAVE_EXPO_FREE (expo);
      return mpfr_check_range (y, inex, rnd_mode);
    }
  else
    return mpfr_set (y, x, rnd_mode);
}
开发者ID:mmanley,项目名称:Antares,代码行数:28,代码来源:sub_ui.c

示例12: mpn_sizeinbase

size_t
mpn_sizeinbase (mp_srcptr xp, mp_size_t xsize, int base)
{
  int lb_base, cnt;
  mp_size_t totbits;

  ASSERT (xsize >= 0);
  ASSERT (base >= 2);
  ASSERT (base < numberof (__mp_bases));

  /* Special case for X == 0.  */
  if (xsize == 0)
    return 1;

  /* Calculate the total number of significant bits of X.  */
  count_leading_zeros (cnt, xp[xsize-1]);
  totbits = xsize * BITS_PER_MP_LIMB - cnt;

  if (POW2_P (base))
    {
      /* Special case for powers of 2, giving exact result.  */
      lb_base = __mp_bases[base].big_base;
      return (totbits + lb_base - 1) / lb_base;
    }
  else
    return (size_t) (totbits * __mp_bases[base].chars_per_bit_exactly) + 1;
}
开发者ID:RodneyBates,项目名称:M3Devel,代码行数:27,代码来源:sizeinbase.c

示例13: mpfr_add_ui

int
mpfr_add_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
{

  if (u)  /* if u=0, do nothing */
    {
      mpfr_t uu;
      mp_limb_t up[1];
      unsigned long cnt;
      int inex;

      MPFR_INIT1(up, uu, BITS_PER_MP_LIMB, 1);
      count_leading_zeros(cnt, (mp_limb_t) u);
      *up = (mp_limb_t) u << cnt;
      MPFR_EXP(uu) = BITS_PER_MP_LIMB - cnt;

      /* Optimization note: Exponent operations may be removed
	 if mpfr_add works even when uu is out-of-range. */
      mpfr_save_emin_emax();
      inex = mpfr_add(y, x, uu, rnd_mode);
      MPFR_RESTORE_RET(inex, y, rnd_mode);
    }
  else
    return mpfr_set (y, x, rnd_mode);
}
开发者ID:mahdiz,项目名称:mpclib,代码行数:25,代码来源:add_ui.c

示例14: set_z

/*
 * Set f to z, choosing the smallest precision for f
 * so that z = f*(2^BPML)*zs*2^(RetVal)
 */
static int
set_z (mpfr_ptr f, mpz_srcptr z, mp_size_t *zs)
{
  mp_limb_t *p;
  mp_size_t s;
  int c;
  mp_prec_t pf;

  MPFR_ASSERTD (mpz_sgn (z) != 0);

  /* Remove useless ending 0 */
  for (p = PTR (z), s = *zs = ABS (SIZ (z)) ; *p == 0; p++, s--)
    MPFR_ASSERTD (s >= 0);

  /* Get working precision */
  count_leading_zeros (c, p[s-1]);
  pf = s * BITS_PER_MP_LIMB - c;
  if (pf < MPFR_PREC_MIN)
    pf = MPFR_PREC_MIN;
  mpfr_init2 (f, pf);

  /* Copy Mantissa */
  if (MPFR_LIKELY (c))
    mpn_lshift (MPFR_MANT (f), p, s, c);
  else
    MPN_COPY (MPFR_MANT (f), p, s);

  MPFR_SET_SIGN (f, mpz_sgn (z));
  MPFR_SET_EXP (f, 0);

  return -c;
}
开发者ID:STAR111,项目名称:GCC_parser,代码行数:36,代码来源:set_q.c

示例15: mpfr_add_ui

int
mpfr_add_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mpfr_rnd_t rnd_mode)
{
  MPFR_LOG_FUNC
    (("x[%Pu]=%.*Rg u=%lu rnd=%d",
      mpfr_get_prec(x), mpfr_log_prec, x, u, rnd_mode),
     ("y[%Pu]=%.*Rg", mpfr_get_prec (y), mpfr_log_prec, y));

  if (MPFR_LIKELY(u != 0) )  /* if u=0, do nothing */
    {
      mpfr_t uu;
      mp_limb_t up[1];
      unsigned long cnt;
      int inex;
      MPFR_SAVE_EXPO_DECL (expo);

      MPFR_TMP_INIT1 (up, uu, GMP_NUMB_BITS);
      MPFR_ASSERTD (u == (mp_limb_t) u);
      count_leading_zeros(cnt, (mp_limb_t) u);
      up[0] = (mp_limb_t) u << cnt;

      /* Optimization note: Exponent save/restore operations may be
         removed if mpfr_add works even when uu is out-of-range. */
      MPFR_SAVE_EXPO_MARK (expo);
      MPFR_SET_EXP (uu, GMP_NUMB_BITS - cnt);
      inex = mpfr_add(y, x, uu, rnd_mode);
      MPFR_SAVE_EXPO_FREE (expo);
      return mpfr_check_range(y, inex, rnd_mode);
    }
  else
    /* (unsigned long) 0 is assumed to be a real 0 (unsigned) */
    return mpfr_set (y, x, rnd_mode);
}
开发者ID:texlive,项目名称:texlive-source,代码行数:33,代码来源:add_ui.c


注:本文中的count_leading_zeros函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。