17#ifndef LIB_BIG_INT_UTIL_H_
18#define LIB_BIG_INT_UTIL_H_
20#include <boost/version.hpp>
22#if BOOST_VERSION < 106700
23#include <boost/functional/hash.hpp>
34big_int ripBits(big_int &value,
int bits);
43BitRange findOnes(
const big_int &value);
45big_int cvtInt(
const char *s,
unsigned base);
46big_int shift_left(
const big_int &v,
unsigned bits);
47big_int shift_right(
const big_int &v,
unsigned bits);
49big_int maskFromSlice(
unsigned m,
unsigned l);
50big_int mask(
unsigned bits);
52inline unsigned scan0_positive(
const boost::multiprecision::cpp_int &val,
unsigned pos) {
53 while (boost::multiprecision::bit_test(val, pos)) ++pos;
56inline unsigned scan1_positive(
const boost::multiprecision::cpp_int &val,
unsigned pos) {
57 if (val == 0 || pos > boost::multiprecision::msb(val))
return ~0U;
58 unsigned lsb = boost::multiprecision::lsb(val);
59 if (lsb >= pos)
return lsb;
60 while (!boost::multiprecision::bit_test(val, pos)) ++pos;
63inline unsigned scan0(
const boost::multiprecision::cpp_int &val,
unsigned pos) {
64 if (val < 0)
return scan1_positive(-val - 1, pos);
65 return scan0_positive(val, pos);
67inline unsigned scan1(
const boost::multiprecision::cpp_int &val,
unsigned pos) {
68 if (val < 0)
return scan0_positive(-val - 1, pos);
69 return scan1_positive(val, pos);
76static inline unsigned bitcount(big_int v) {
77 if (v < 0)
return ~0U;
86static inline int ffs(big_int v) {
87 if (v <= 0)
return -1;
88 return boost::multiprecision::lsb(v);
91static inline int floor_log2(big_int v) {
100static inline int ceil_log2(big_int v) {
return v ? floor_log2(v - 1) + 1 : -1; }
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition big_int_util.h:36