mirror of
https://github.com/Z3Prover/z3
synced 2025-04-26 18:45:33 +00:00
test / fix wrap-around for mod-interval
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
1355ea432a
commit
ff717a9db1
5 changed files with 120 additions and 51 deletions
|
@ -274,6 +274,7 @@ void Hacl_Bignum256_sqr(uint64_t *a, uint64_t *res)
|
|||
res[i0 + i0] = r;
|
||||
}
|
||||
uint64_t c0 = Hacl_Bignum_Addition_bn_add_eq_len_u64(resLen, res, res, res);
|
||||
(void)c0;
|
||||
KRML_CHECK_SIZE(sizeof (uint64_t), resLen);
|
||||
uint64_t *tmp = alloca(resLen * sizeof (uint64_t));
|
||||
memset(tmp, 0U, resLen * sizeof (uint64_t));
|
||||
|
@ -286,6 +287,7 @@ void Hacl_Bignum256_sqr(uint64_t *a, uint64_t *res)
|
|||
tmp[(uint32_t)2U * i + (uint32_t)1U] = hi;
|
||||
}
|
||||
uint64_t c1 = Hacl_Bignum_Addition_bn_add_eq_len_u64(resLen, res, tmp, res);
|
||||
(void)c1;
|
||||
}
|
||||
|
||||
static inline void precompr2(uint32_t nBits, uint64_t *n, uint64_t *res)
|
||||
|
@ -414,6 +416,7 @@ static inline void areduction(uint64_t *n, uint64_t nInv, uint64_t *c, uint64_t
|
|||
uint64_t c00 = c0;
|
||||
uint64_t tmp[4U] = { 0U };
|
||||
uint64_t c1 = Hacl_Bignum256_sub(res, n, tmp);
|
||||
(void)c1;
|
||||
uint64_t m = (uint64_t)0U - c00;
|
||||
for (uint32_t i = (uint32_t)0U; i < (uint32_t)4U; i++)
|
||||
{
|
||||
|
@ -497,6 +500,7 @@ static inline void amont_sqr(uint64_t *n, uint64_t nInv_u64, uint64_t *aM, uint6
|
|||
c[i0 + i0] = r;
|
||||
}
|
||||
uint64_t c0 = Hacl_Bignum_Addition_bn_add_eq_len_u64(resLen, c, c, c);
|
||||
(void)c0;
|
||||
KRML_CHECK_SIZE(sizeof (uint64_t), resLen);
|
||||
uint64_t *tmp = alloca(resLen * sizeof (uint64_t));
|
||||
memset(tmp, 0U, resLen * sizeof (uint64_t));
|
||||
|
|
|
@ -21,35 +21,19 @@ u256 u256::operator*(u256 const& other) const {
|
|||
return u256(result);
|
||||
}
|
||||
|
||||
u256 u256::operator+(u256 const& other) const {
|
||||
u256 result;
|
||||
Hacl_Bignum256_add(const_cast<uint64_t*>(m_num), const_cast<uint64_t*>(other.m_num), result.m_num);
|
||||
return result;
|
||||
}
|
||||
|
||||
u256 u256::operator-(u256 const& other) const {
|
||||
u256 result;
|
||||
Hacl_Bignum256_sub(const_cast<uint64_t*>(m_num), const_cast<uint64_t*>(other.m_num), result.m_num);
|
||||
return result;
|
||||
}
|
||||
|
||||
u256& u256::operator*=(u256 const& other) {
|
||||
uint64_t result[8];
|
||||
Hacl_Bignum256_add(const_cast<uint64_t*>(m_num), const_cast<uint64_t*>(other.m_num), result);
|
||||
Hacl_Bignum256_mul(const_cast<uint64_t*>(m_num), const_cast<uint64_t*>(other.m_num), result);
|
||||
std::uninitialized_copy(m_num, m_num + sizeof(*this), result);
|
||||
return *this;
|
||||
}
|
||||
|
||||
u256& u256::operator+=(u256 const& other) {
|
||||
uint64_t result[4];
|
||||
Hacl_Bignum256_add(const_cast<uint64_t*>(m_num), const_cast<uint64_t*>(other.m_num), result);
|
||||
std::uninitialized_copy(m_num, m_num + sizeof(*this), result);
|
||||
Hacl_Bignum256_add(const_cast<uint64_t*>(m_num), const_cast<uint64_t*>(other.m_num), m_num);
|
||||
return *this;
|
||||
}
|
||||
|
||||
u256& u256::operator-=(u256 const& other) {
|
||||
uint64_t result[4];
|
||||
Hacl_Bignum256_sub(const_cast<uint64_t*>(m_num), const_cast<uint64_t*>(other.m_num), result);
|
||||
std::uninitialized_copy(m_num, m_num + sizeof(*this), result);
|
||||
Hacl_Bignum256_sub(const_cast<uint64_t*>(m_num), const_cast<uint64_t*>(other.m_num), m_num);
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ public:
|
|||
u256(uint64_t n);
|
||||
u256(uint64_t const* v);
|
||||
u256 operator*(u256 const& other) const;
|
||||
u256 operator+(u256 const& other) const;
|
||||
u256 operator-(u256 const& other) const;
|
||||
u256 operator+(u256 const& other) const { u256 r = *this; return r += other; }
|
||||
u256 operator-(u256 const& other) const { u256 r = *this; return r -= other; }
|
||||
u256& operator+=(u256 const& other);
|
||||
u256& operator*=(u256 const& other);
|
||||
u256& operator-=(u256 const& other);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue