Major updates integration from all upstreams
This commit is contained in:
@@ -79,7 +79,7 @@ void _basic_parallel_radix2_FFT_inner(std::vector<FieldT> &a, const FieldT &omeg
|
||||
|
||||
const size_t m = a.size();
|
||||
const size_t log_m = log2(m);
|
||||
assert_except(m == UINT64_C(1)<<log_m);
|
||||
assert(m == UINT64_C(1)<<log_m);
|
||||
|
||||
if (log_m < log_cpus)
|
||||
{
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
size_t max_bits() const { return n * GMP_NUMB_BITS; }
|
||||
size_t num_bits() const;
|
||||
|
||||
uint64_t as_ulong() const; /* return the last limb of the integer */
|
||||
uint64_t as_uint64() const; /* return the last limb of the integer */
|
||||
void to_mpz(mpz_t r) const;
|
||||
bool test_bit(const std::size_t bitno) const;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
namespace libsnark {
|
||||
|
||||
template<mp_size_t n>
|
||||
bigint<n>::bigint(const uint64_t x) /// Initalize from a small integer
|
||||
bigint<n>::bigint(const uint64_t x) /// Initialize from a small integer
|
||||
{
|
||||
static_assert(UINT64_MAX <= GMP_NUMB_MAX, "uint64_t does not fit in a GMP limb");
|
||||
this->data[0] = x;
|
||||
@@ -125,6 +125,7 @@ size_t bigint<n>::num_bits() const
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(GMP_NUMB_MAX <= ULLONG_MAX, "coercing limb to unsigned long long might truncate");
|
||||
return ((i+1) * GMP_NUMB_BITS) - __builtin_clzll(x);
|
||||
}
|
||||
}
|
||||
@@ -132,7 +133,7 @@ size_t bigint<n>::num_bits() const
|
||||
}
|
||||
|
||||
template<mp_size_t n>
|
||||
uint64_t bigint<n>::as_ulong() const
|
||||
uint64_t bigint<n>::as_uint64() const
|
||||
{
|
||||
return this->data[0];
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
Fp_model(const bigint<n> &b);
|
||||
Fp_model(const int64_t x, const bool is_unsigned=false);
|
||||
|
||||
void set_ulong(const uint64_t x);
|
||||
void set_uint64(const uint64_t x);
|
||||
|
||||
void mul_reduce(const bigint<n> &other);
|
||||
|
||||
@@ -80,9 +80,9 @@ public:
|
||||
would return bigint(2) */
|
||||
bigint<n> as_bigint() const;
|
||||
/* Return the last limb of the standard representation of the
|
||||
field element. E.g. on 64-bit architectures Fp(123).as_ulong()
|
||||
and Fp(2^64+123).as_ulong() would both return 123. */
|
||||
uint64_t as_ulong() const;
|
||||
field element. E.g. on 64-bit architectures Fp(123).as_uint64()
|
||||
and Fp(2^64+123).as_uint64() would both return 123. */
|
||||
uint64_t as_uint64() const;
|
||||
|
||||
bool operator==(const Fp_model& other) const;
|
||||
bool operator!=(const Fp_model& other) const;
|
||||
|
||||
@@ -210,7 +210,7 @@ Fp_model<n,modulus>::Fp_model(const int64_t x, const bool is_unsigned)
|
||||
}
|
||||
|
||||
template<mp_size_t n, const bigint<n>& modulus>
|
||||
void Fp_model<n,modulus>::set_ulong(const uint64_t x)
|
||||
void Fp_model<n,modulus>::set_uint64(const uint64_t x)
|
||||
{
|
||||
this->mont_repr.clear();
|
||||
this->mont_repr.data[0] = x;
|
||||
@@ -237,9 +237,9 @@ bigint<n> Fp_model<n,modulus>::as_bigint() const
|
||||
}
|
||||
|
||||
template<mp_size_t n, const bigint<n>& modulus>
|
||||
uint64_t Fp_model<n,modulus>::as_ulong() const
|
||||
uint64_t Fp_model<n,modulus>::as_uint64() const
|
||||
{
|
||||
return this->as_bigint().as_ulong();
|
||||
return this->as_bigint().as_uint64();
|
||||
}
|
||||
|
||||
template<mp_size_t n, const bigint<n>& modulus>
|
||||
@@ -690,7 +690,7 @@ Fp_model<n, modulus> Fp_model<n,modulus>::random_element() /// returns random el
|
||||
const uint64_t part = bitno/GMP_NUMB_BITS;
|
||||
const uint64_t bit = bitno - (GMP_NUMB_BITS*part);
|
||||
|
||||
r.mont_repr.data[part] &= ~(1ull<<bit);
|
||||
r.mont_repr.data[part] &= ~(UINT64_C(1)<<bit);
|
||||
|
||||
bitno--;
|
||||
}
|
||||
|
||||
@@ -348,7 +348,7 @@ Fp12_2over3over2_model<n, modulus> Fp12_2over3over2_model<n,modulus>::cyclotomic
|
||||
res = res.cyclotomic_squared();
|
||||
}
|
||||
|
||||
if (exponent.data[i] & (UINT64_C(1)<<j))
|
||||
if (exponent.data[i] & (((mp_limb_t) 1)<<j))
|
||||
{
|
||||
found_one = true;
|
||||
res = res * (*this);
|
||||
|
||||
@@ -11,7 +11,6 @@ using namespace libsnark;
|
||||
|
||||
void test_bigint()
|
||||
{
|
||||
static_assert(UINT64_MAX == 0xFFFFFFFFFFFFFFFFul, "uint64_t not 64-bit");
|
||||
static_assert(GMP_NUMB_BITS == 64, "GMP limb not 64-bit");
|
||||
|
||||
const char *b1_decimal = "76749407";
|
||||
@@ -24,17 +23,17 @@ void test_bigint()
|
||||
bigint<1> b1 = bigint<1>(b1_decimal);
|
||||
bigint<2> b2 = bigint<2>(b2_decimal);
|
||||
|
||||
assert(b0.as_ulong() == UINT64_C(0));
|
||||
assert(b0.is_zero());
|
||||
assert(b1.as_ulong() == UINT64_C(76749407));
|
||||
assert(!(b1.is_zero()));
|
||||
assert(b2.as_ulong() == UINT64_C(15747124762497195938));
|
||||
assert(!(b2.is_zero()));
|
||||
assert(b0 != b1);
|
||||
assert(!(b0 == b1));
|
||||
EXPECT_EQ(b0.as_uint64(), UINT64_C(0));
|
||||
EXPECT_TRUE(b0.is_zero());
|
||||
EXPECT_EQ(b1.as_uint64(), UINT64_C(76749407));
|
||||
EXPECT_FALSE(b1.is_zero());
|
||||
EXPECT_EQ(b2.as_uint64(), UINT64_C(15747124762497195938));
|
||||
EXPECT_FALSE(b2.is_zero());
|
||||
EXPECT_NE(b0, b1);
|
||||
EXPECT_FALSE(b0 == b1);
|
||||
|
||||
assert(b2.max_bits() == 128);
|
||||
assert(b2.num_bits() == 99);
|
||||
EXPECT_EQ(b2.max_bits(), 128u);
|
||||
EXPECT_EQ(b2.num_bits(), 99u);
|
||||
for (size_t i = 0; i < 128; i++) {
|
||||
assert(b2.test_bit(i) == (b2_binary[127-i] == '1'));
|
||||
}
|
||||
@@ -58,8 +57,8 @@ void test_bigint()
|
||||
bigint<2> quotient;
|
||||
bigint<2> remainder;
|
||||
bigint<3>::div_qr(quotient, remainder, b3, b2);
|
||||
assert(quotient.num_bits() < GMP_NUMB_BITS);
|
||||
assert(quotient.as_ulong() == b1.as_ulong());
|
||||
EXPECT_LT(quotient.num_bits(), static_cast<size_t>(GMP_NUMB_BITS));
|
||||
EXPECT_EQ(quotient.as_uint64(), b1.as_uint64());
|
||||
bigint<1> b1inc = bigint<1>("76749408");
|
||||
bigint<1> b1a = quotient.shorten(b1inc, "test");
|
||||
assert(b1a == b1);
|
||||
@@ -82,15 +81,15 @@ void test_bigint()
|
||||
assert(!(b3a > b3));
|
||||
|
||||
bigint<3>::div_qr(quotient, remainder, b3, b2);
|
||||
assert(quotient.num_bits() < GMP_NUMB_BITS);
|
||||
assert(quotient.as_ulong() == b1.as_ulong());
|
||||
assert(remainder.num_bits() < GMP_NUMB_BITS);
|
||||
assert(remainder.as_ulong() == 42);
|
||||
EXPECT_LT(quotient.num_bits(), static_cast<size_t>(GMP_NUMB_BITS));
|
||||
EXPECT_EQ(quotient.as_uint64(), b1.as_uint64());
|
||||
EXPECT_LT(remainder.num_bits(), static_cast<size_t>(GMP_NUMB_BITS));
|
||||
EXPECT_EQ(remainder.as_uint64(), 42u);
|
||||
|
||||
b3a.clear();
|
||||
assert(b3a.is_zero());
|
||||
assert(b3a.num_bits() == 0);
|
||||
assert(!(b3.is_zero()));
|
||||
EXPECT_TRUE(b3a.is_zero());
|
||||
EXPECT_EQ(b3a.num_bits(), 0u);
|
||||
EXPECT_FALSE(b3.is_zero());
|
||||
|
||||
bigint<4> bx = bigint<4>().randomize();
|
||||
bigint<4> by = bigint<4>().randomize();
|
||||
|
||||
@@ -89,7 +89,7 @@ void test_Frobenius()
|
||||
template<typename FieldT>
|
||||
void test_unitary_inverse()
|
||||
{
|
||||
assert(FieldT::extension_degree() % 2 == 0);
|
||||
EXPECT_EQ(FieldT::extension_degree() % 2, 0u);
|
||||
FieldT a = FieldT::random_element();
|
||||
FieldT aqcubed_minus1 = a.Frobenius_map(FieldT::extension_degree()/2) * a.inverse();
|
||||
assert(aqcubed_minus1.inverse() == aqcubed_minus1.unitary_inverse());
|
||||
|
||||
Reference in New Issue
Block a user