mirror of
https://github.com/Z3Prover/z3
synced 2025-07-23 04:38:53 +00:00
Eliminated the old MS-Bignum interface because it stood in the way of progress.
Signed-off-by: Christoph M. Wintersteiger <cwinter@microsoft.com>
This commit is contained in:
parent
da01f237fd
commit
7e579604e1
8 changed files with 95 additions and 183 deletions
|
@ -22,13 +22,15 @@ Revision History:
|
|||
#include<ostream>
|
||||
#include"util.h"
|
||||
#include"buffer.h"
|
||||
|
||||
// we supply a definition of a basic max because mpz relies on it.
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#include"z3_omp.h"
|
||||
|
||||
typedef unsigned int mpn_digit;
|
||||
|
||||
class mpn_manager {
|
||||
omp_nest_lock_t m_lock;
|
||||
#define MPN_BEGIN_CRITICAL() omp_set_nest_lock(&const_cast<omp_nest_lock_t>(m_lock));
|
||||
#define MPN_END_CRITICAL() omp_unset_nest_lock(&const_cast<omp_nest_lock_t>(m_lock));
|
||||
|
||||
public:
|
||||
mpn_manager();
|
||||
~mpn_manager();
|
||||
|
@ -56,7 +58,6 @@ public:
|
|||
|
||||
char * to_string(mpn_digit const * a, size_t const lng,
|
||||
char * buf, size_t const lbuf) const;
|
||||
|
||||
private:
|
||||
#ifdef _AMD64_
|
||||
class mpn_sbuffer : public sbuffer<mpn_digit> {
|
||||
|
@ -112,85 +113,6 @@ private:
|
|||
|
||||
void trace(mpn_digit const * a, size_t const lnga) const;
|
||||
void trace_nl(mpn_digit const * a, size_t const lnga) const;
|
||||
|
||||
public:
|
||||
// This function is needed because of the static_mpn_manager global variable.
|
||||
// It must be invoked by the memory_manager during finalization.
|
||||
// After we remove MSBignum from the code base, the global variable will
|
||||
// not be needed anymore, and we will be able to eliminate this function.
|
||||
void finalize() {
|
||||
u.finalize();
|
||||
v.finalize();
|
||||
t_ms.finalize();
|
||||
t_ab.finalize();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// MSBignum compatible interface
|
||||
// Note: The `owner' parameter is ignored. We use separate mpn_manager objects for the
|
||||
// same purpose. Multiple owners are not supported in these compatibility functions,
|
||||
// instead a static mpn_manager is used.
|
||||
|
||||
extern mpn_manager static_mpn_manager;
|
||||
|
||||
typedef unsigned int digit_t;
|
||||
|
||||
typedef struct {
|
||||
mpn_digit multiplier;
|
||||
size_t shiftamt;
|
||||
} reciprocal_1_t;
|
||||
|
||||
#define reciprocal_1_NULL ((reciprocal_1_t*)0)
|
||||
|
||||
inline int compare_diff(digit_t const * a, size_t const lnga,
|
||||
digit_t const * b, size_t const lngb)
|
||||
{
|
||||
return static_mpn_manager.compare(a, lnga, b, lngb);
|
||||
}
|
||||
|
||||
inline char * mp_decimal(digit_t const * a, size_t const lng, // Number to be converted and its length
|
||||
char * buf, size_t const lbuf, // output buffer and its length
|
||||
int owner)
|
||||
{
|
||||
return static_mpn_manager.to_string(a, lng, buf, lbuf);
|
||||
}
|
||||
|
||||
inline bool add_full(digit_t const * a, size_t const lnga,
|
||||
digit_t const * b, size_t const lngb,
|
||||
digit_t *c, size_t const lngc_alloc,
|
||||
size_t * plngc,
|
||||
int owner)
|
||||
{
|
||||
return static_mpn_manager.add(a, lnga, b, lngb, c, lngc_alloc, plngc);
|
||||
}
|
||||
|
||||
inline bool sub_diff(digit_t const * a, size_t const lnga,
|
||||
digit_t const * b, size_t const lngb,
|
||||
digit_t * c, digit_t * pborrow,
|
||||
int owner)
|
||||
{
|
||||
return static_mpn_manager.sub(a, lnga, b, lngb, c, pborrow);
|
||||
}
|
||||
|
||||
inline bool multiply(digit_t const * a, size_t const lnga,
|
||||
digit_t const * b, size_t const lngb,
|
||||
digit_t * c,
|
||||
int owner)
|
||||
{
|
||||
return static_mpn_manager.mul(a, lnga, b, lngb, c);
|
||||
}
|
||||
|
||||
inline bool divide(digit_t const * numer, size_t const lnum,
|
||||
digit_t const * denom, size_t const lden,
|
||||
reciprocal_1_t const * supplied_reciprocal, /* reciprocal_t struct for this denominator,
|
||||
or reciprocal_1_NULL
|
||||
if not previously precomputed */
|
||||
digit_t * quot, /* Quotient -- length MAX(lnum - lden + 1, 0) */
|
||||
digit_t * rem, /* Remainder -- length lden */
|
||||
int owner)
|
||||
{
|
||||
return static_mpn_manager.div(numer, lnum, denom, lden, quot, rem);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue