bignum indentation and macro cleanup
parent
1c2292d36a
commit
0022f5c45f
253
vm/bignum.cpp
253
vm/bignum.cpp
|
|
@ -1,5 +1,4 @@
|
||||||
/* :tabSize=2:indentSize=2:noTabs=true:
|
/*
|
||||||
|
|
||||||
Copyright (C) 1989-94 Massachusetts Institute of Technology
|
Copyright (C) 1989-94 Massachusetts Institute of Technology
|
||||||
Portions copyright (C) 2004-2008 Slava Pestov
|
Portions copyright (C) 2004-2008 Slava Pestov
|
||||||
|
|
||||||
|
|
@ -330,34 +329,34 @@ bignum *factorvm::bignum_remainder(bignum * numerator, bignum * denominator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FOO_TO_BIGNUM(name,type,utype) \
|
#define FOO_TO_BIGNUM(name,type,utype) \
|
||||||
bignum * factorvm::name##_to_bignum(type n) \
|
bignum * factorvm::name##_to_bignum(type n) \
|
||||||
{ \
|
{ \
|
||||||
int negative_p; \
|
int negative_p; \
|
||||||
bignum_digit_type result_digits [BIGNUM_DIGITS_FOR(type)]; \
|
bignum_digit_type result_digits [BIGNUM_DIGITS_FOR(type)]; \
|
||||||
bignum_digit_type * end_digits = result_digits; \
|
bignum_digit_type * end_digits = result_digits; \
|
||||||
/* Special cases win when these small constants are cached. */ \
|
/* Special cases win when these small constants are cached. */ \
|
||||||
if (n == 0) return (BIGNUM_ZERO ()); \
|
if (n == 0) return (BIGNUM_ZERO ()); \
|
||||||
if (n == 1) return (BIGNUM_ONE (0)); \
|
if (n == 1) return (BIGNUM_ONE (0)); \
|
||||||
if (n < (type)0 && n == (type)-1) return (BIGNUM_ONE (1)); \
|
if (n < (type)0 && n == (type)-1) return (BIGNUM_ONE (1)); \
|
||||||
{ \
|
{ \
|
||||||
utype accumulator = ((negative_p = (n < (type)0)) ? (-n) : n); \
|
utype accumulator = ((negative_p = (n < (type)0)) ? (-n) : n); \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
(*end_digits++) = (accumulator & BIGNUM_DIGIT_MASK); \
|
(*end_digits++) = (accumulator & BIGNUM_DIGIT_MASK); \
|
||||||
accumulator >>= BIGNUM_DIGIT_LENGTH; \
|
accumulator >>= BIGNUM_DIGIT_LENGTH; \
|
||||||
} \
|
} \
|
||||||
while (accumulator != 0); \
|
while (accumulator != 0); \
|
||||||
} \
|
} \
|
||||||
{ \
|
{ \
|
||||||
bignum * result = \
|
bignum * result = \
|
||||||
(allot_bignum ((end_digits - result_digits), negative_p)); \
|
(allot_bignum ((end_digits - result_digits), negative_p)); \
|
||||||
bignum_digit_type * scan_digits = result_digits; \
|
bignum_digit_type * scan_digits = result_digits; \
|
||||||
bignum_digit_type * scan_result = (BIGNUM_START_PTR (result)); \
|
bignum_digit_type * scan_result = (BIGNUM_START_PTR (result)); \
|
||||||
while (scan_digits < end_digits) \
|
while (scan_digits < end_digits) \
|
||||||
(*scan_result++) = (*scan_digits++); \
|
(*scan_result++) = (*scan_digits++); \
|
||||||
return (result); \
|
return (result); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* all below allocate memory */
|
/* all below allocate memory */
|
||||||
|
|
@ -366,19 +365,19 @@ FOO_TO_BIGNUM(fixnum,fixnum,cell)
|
||||||
FOO_TO_BIGNUM(long_long,s64,u64)
|
FOO_TO_BIGNUM(long_long,s64,u64)
|
||||||
FOO_TO_BIGNUM(ulong_long,u64,u64)
|
FOO_TO_BIGNUM(ulong_long,u64,u64)
|
||||||
|
|
||||||
#define BIGNUM_TO_FOO(name,type,utype) \
|
#define BIGNUM_TO_FOO(name,type,utype) \
|
||||||
type factorvm::bignum_to_##name(bignum * bignum) \
|
type factorvm::bignum_to_##name(bignum * bignum) \
|
||||||
{ \
|
{ \
|
||||||
if (BIGNUM_ZERO_P (bignum)) \
|
if (BIGNUM_ZERO_P (bignum)) \
|
||||||
return (0); \
|
return (0); \
|
||||||
{ \
|
{ \
|
||||||
utype accumulator = 0; \
|
utype accumulator = 0; \
|
||||||
bignum_digit_type * start = (BIGNUM_START_PTR (bignum)); \
|
bignum_digit_type * start = (BIGNUM_START_PTR (bignum)); \
|
||||||
bignum_digit_type * scan = (start + (BIGNUM_LENGTH (bignum))); \
|
bignum_digit_type * scan = (start + (BIGNUM_LENGTH (bignum))); \
|
||||||
while (start < scan) \
|
while (start < scan) \
|
||||||
accumulator = ((accumulator << BIGNUM_DIGIT_LENGTH) + (*--scan)); \
|
accumulator = ((accumulator << BIGNUM_DIGIT_LENGTH) + (*--scan)); \
|
||||||
return ((BIGNUM_NEGATIVE_P (bignum)) ? (-((type)accumulator)) : accumulator); \
|
return ((BIGNUM_NEGATIVE_P (bignum)) ? (-((type)accumulator)) : accumulator); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* all of the below allocate memory */
|
/* all of the below allocate memory */
|
||||||
|
|
@ -401,12 +400,12 @@ double factorvm::bignum_to_double(bignum * bignum)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DTB_WRITE_DIGIT(factor) \
|
#define DTB_WRITE_DIGIT(factor) \
|
||||||
{ \
|
{ \
|
||||||
significand *= (factor); \
|
significand *= (factor); \
|
||||||
digit = ((bignum_digit_type) significand); \
|
digit = ((bignum_digit_type) significand); \
|
||||||
(*--scan) = digit; \
|
(*--scan) = digit; \
|
||||||
significand -= ((double) digit); \
|
significand -= ((double) digit); \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocates memory */
|
/* allocates memory */
|
||||||
|
|
@ -494,7 +493,7 @@ enum bignum_comparison factorvm::bignum_compare_unsigned(bignum * x, bignum * y)
|
||||||
/* allocates memory */
|
/* allocates memory */
|
||||||
bignum *factorvm::bignum_add_unsigned(bignum * x, bignum * y, int negative_p)
|
bignum *factorvm::bignum_add_unsigned(bignum * x, bignum * y, int negative_p)
|
||||||
{
|
{
|
||||||
GC_BIGNUM(x,this); GC_BIGNUM(y,this);
|
GC_BIGNUM(x); GC_BIGNUM(y);
|
||||||
|
|
||||||
if ((BIGNUM_LENGTH (y)) > (BIGNUM_LENGTH (x)))
|
if ((BIGNUM_LENGTH (y)) > (BIGNUM_LENGTH (x)))
|
||||||
{
|
{
|
||||||
|
|
@ -561,7 +560,7 @@ bignum *factorvm::bignum_add_unsigned(bignum * x, bignum * y, int negative_p)
|
||||||
/* allocates memory */
|
/* allocates memory */
|
||||||
bignum *factorvm::bignum_subtract_unsigned(bignum * x, bignum * y)
|
bignum *factorvm::bignum_subtract_unsigned(bignum * x, bignum * y)
|
||||||
{
|
{
|
||||||
GC_BIGNUM(x,this); GC_BIGNUM(y,this);
|
GC_BIGNUM(x); GC_BIGNUM(y);
|
||||||
|
|
||||||
int negative_p = 0;
|
int negative_p = 0;
|
||||||
switch (bignum_compare_unsigned (x, y))
|
switch (bignum_compare_unsigned (x, y))
|
||||||
|
|
@ -639,7 +638,7 @@ bignum *factorvm::bignum_subtract_unsigned(bignum * x, bignum * y)
|
||||||
/* allocates memory */
|
/* allocates memory */
|
||||||
bignum *factorvm::bignum_multiply_unsigned(bignum * x, bignum * y, int negative_p)
|
bignum *factorvm::bignum_multiply_unsigned(bignum * x, bignum * y, int negative_p)
|
||||||
{
|
{
|
||||||
GC_BIGNUM(x,this); GC_BIGNUM(y,this);
|
GC_BIGNUM(x); GC_BIGNUM(y);
|
||||||
|
|
||||||
if ((BIGNUM_LENGTH (y)) > (BIGNUM_LENGTH (x)))
|
if ((BIGNUM_LENGTH (y)) > (BIGNUM_LENGTH (x)))
|
||||||
{
|
{
|
||||||
|
|
@ -708,9 +707,9 @@ bignum *factorvm::bignum_multiply_unsigned(bignum * x, bignum * y, int negative_
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocates memory */
|
/* allocates memory */
|
||||||
bignum *factorvm::bignum_multiply_unsigned_small_factor(bignum * x, bignum_digit_type y,int negative_p)
|
bignum *factorvm::bignum_multiply_unsigned_small_factor(bignum * x, bignum_digit_type y, int negative_p)
|
||||||
{
|
{
|
||||||
GC_BIGNUM(x,this);
|
GC_BIGNUM(x);
|
||||||
|
|
||||||
bignum_length_type length_x = (BIGNUM_LENGTH (x));
|
bignum_length_type length_x = (BIGNUM_LENGTH (x));
|
||||||
|
|
||||||
|
|
@ -784,7 +783,7 @@ void factorvm::bignum_destructive_scale_up(bignum * bignum, bignum_digit_type fa
|
||||||
/* allocates memory */
|
/* allocates memory */
|
||||||
void factorvm::bignum_divide_unsigned_large_denominator(bignum * numerator, bignum * denominator, bignum * * quotient, bignum * * remainder, int q_negative_p, int r_negative_p)
|
void factorvm::bignum_divide_unsigned_large_denominator(bignum * numerator, bignum * denominator, bignum * * quotient, bignum * * remainder, int q_negative_p, int r_negative_p)
|
||||||
{
|
{
|
||||||
GC_BIGNUM(numerator,this); GC_BIGNUM(denominator,this);
|
GC_BIGNUM(numerator); GC_BIGNUM(denominator);
|
||||||
|
|
||||||
bignum_length_type length_n = ((BIGNUM_LENGTH (numerator)) + 1);
|
bignum_length_type length_n = ((BIGNUM_LENGTH (numerator)) + 1);
|
||||||
bignum_length_type length_d = (BIGNUM_LENGTH (denominator));
|
bignum_length_type length_d = (BIGNUM_LENGTH (denominator));
|
||||||
|
|
@ -793,10 +792,10 @@ void factorvm::bignum_divide_unsigned_large_denominator(bignum * numerator, bign
|
||||||
((quotient != ((bignum * *) 0))
|
((quotient != ((bignum * *) 0))
|
||||||
? (allot_bignum ((length_n - length_d), q_negative_p))
|
? (allot_bignum ((length_n - length_d), q_negative_p))
|
||||||
: BIGNUM_OUT_OF_BAND);
|
: BIGNUM_OUT_OF_BAND);
|
||||||
GC_BIGNUM(q,this);
|
GC_BIGNUM(q);
|
||||||
|
|
||||||
bignum * u = (allot_bignum (length_n, r_negative_p));
|
bignum * u = (allot_bignum (length_n, r_negative_p));
|
||||||
GC_BIGNUM(u,this);
|
GC_BIGNUM(u);
|
||||||
|
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
BIGNUM_ASSERT (length_d > 1);
|
BIGNUM_ASSERT (length_d > 1);
|
||||||
|
|
@ -852,18 +851,18 @@ void factorvm::bignum_divide_unsigned_normalized(bignum * u, bignum * v, bignum
|
||||||
bignum_digit_type * q_scan = NULL;
|
bignum_digit_type * q_scan = NULL;
|
||||||
bignum_digit_type v1 = (v_end[-1]);
|
bignum_digit_type v1 = (v_end[-1]);
|
||||||
bignum_digit_type v2 = (v_end[-2]);
|
bignum_digit_type v2 = (v_end[-2]);
|
||||||
bignum_digit_type ph; /* high half of double-digit product */
|
bignum_digit_type ph; /* high half of double-digit product */
|
||||||
bignum_digit_type pl; /* low half of double-digit product */
|
bignum_digit_type pl; /* low half of double-digit product */
|
||||||
bignum_digit_type guess;
|
bignum_digit_type guess;
|
||||||
bignum_digit_type gh; /* high half-digit of guess */
|
bignum_digit_type gh; /* high half-digit of guess */
|
||||||
bignum_digit_type ch; /* high half of double-digit comparand */
|
bignum_digit_type ch; /* high half of double-digit comparand */
|
||||||
bignum_digit_type v2l = (HD_LOW (v2));
|
bignum_digit_type v2l = (HD_LOW (v2));
|
||||||
bignum_digit_type v2h = (HD_HIGH (v2));
|
bignum_digit_type v2h = (HD_HIGH (v2));
|
||||||
bignum_digit_type cl; /* low half of double-digit comparand */
|
bignum_digit_type cl; /* low half of double-digit comparand */
|
||||||
#define gl ph /* low half-digit of guess */
|
#define gl ph /* low half-digit of guess */
|
||||||
#define uj pl
|
#define uj pl
|
||||||
#define qj ph
|
#define qj ph
|
||||||
bignum_digit_type gm; /* memory loc for reference parameter */
|
bignum_digit_type gm; /* memory loc for reference parameter */
|
||||||
if (q != BIGNUM_OUT_OF_BAND)
|
if (q != BIGNUM_OUT_OF_BAND)
|
||||||
q_scan = ((BIGNUM_START_PTR (q)) + (BIGNUM_LENGTH (q)));
|
q_scan = ((BIGNUM_START_PTR (q)) + (BIGNUM_LENGTH (q)));
|
||||||
while (u_scan_limit < u_scan)
|
while (u_scan_limit < u_scan)
|
||||||
|
|
@ -991,12 +990,12 @@ bignum_digit_type factorvm::bignum_divide_subtract(bignum_digit_type * v_start,
|
||||||
/* allocates memory */
|
/* allocates memory */
|
||||||
void factorvm::bignum_divide_unsigned_medium_denominator(bignum * numerator,bignum_digit_type denominator, bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p)
|
void factorvm::bignum_divide_unsigned_medium_denominator(bignum * numerator,bignum_digit_type denominator, bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p)
|
||||||
{
|
{
|
||||||
GC_BIGNUM(numerator,this);
|
GC_BIGNUM(numerator);
|
||||||
|
|
||||||
bignum_length_type length_n = (BIGNUM_LENGTH (numerator));
|
bignum_length_type length_n = (BIGNUM_LENGTH (numerator));
|
||||||
bignum_length_type length_q;
|
bignum_length_type length_q;
|
||||||
bignum * q = NULL;
|
bignum * q = NULL;
|
||||||
GC_BIGNUM(q,this);
|
GC_BIGNUM(q);
|
||||||
|
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
/* Because `bignum_digit_divide' requires a normalized denominator. */
|
/* Because `bignum_digit_divide' requires a normalized denominator. */
|
||||||
|
|
@ -1092,27 +1091,27 @@ void factorvm::bignum_destructive_unnormalization(bignum * bignum, int shift_rig
|
||||||
case of dividing two bignum digits by one bignum digit. It is
|
case of dividing two bignum digits by one bignum digit. It is
|
||||||
assumed that the numerator, denominator are normalized. */
|
assumed that the numerator, denominator are normalized. */
|
||||||
|
|
||||||
#define BDD_STEP(qn, j) \
|
#define BDD_STEP(qn, j) \
|
||||||
{ \
|
{ \
|
||||||
uj = (u[j]); \
|
uj = (u[j]); \
|
||||||
if (uj != v1) \
|
if (uj != v1) \
|
||||||
{ \
|
{ \
|
||||||
uj_uj1 = (HD_CONS (uj, (u[j + 1]))); \
|
uj_uj1 = (HD_CONS (uj, (u[j + 1]))); \
|
||||||
guess = (uj_uj1 / v1); \
|
guess = (uj_uj1 / v1); \
|
||||||
comparand = (HD_CONS ((uj_uj1 % v1), (u[j + 2]))); \
|
comparand = (HD_CONS ((uj_uj1 % v1), (u[j + 2]))); \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
guess = (BIGNUM_RADIX_ROOT - 1); \
|
guess = (BIGNUM_RADIX_ROOT - 1); \
|
||||||
comparand = (HD_CONS (((u[j + 1]) + v1), (u[j + 2]))); \
|
comparand = (HD_CONS (((u[j + 1]) + v1), (u[j + 2]))); \
|
||||||
} \
|
} \
|
||||||
while ((guess * v2) > comparand) \
|
while ((guess * v2) > comparand) \
|
||||||
{ \
|
{ \
|
||||||
guess -= 1; \
|
guess -= 1; \
|
||||||
comparand += (v1 << BIGNUM_HALF_DIGIT_LENGTH); \
|
comparand += (v1 << BIGNUM_HALF_DIGIT_LENGTH); \
|
||||||
if (comparand >= BIGNUM_RADIX) \
|
if (comparand >= BIGNUM_RADIX) \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
qn = (bignum_digit_divide_subtract (v1, v2, guess, (&u[j]))); \
|
qn = (bignum_digit_divide_subtract (v1, v2, guess, (&u[j]))); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1154,35 +1153,35 @@ bignum_digit_type factorvm::bignum_digit_divide(bignum_digit_type uh, bignum_dig
|
||||||
|
|
||||||
#undef BDD_STEP
|
#undef BDD_STEP
|
||||||
|
|
||||||
#define BDDS_MULSUB(vn, un, carry_in) \
|
#define BDDS_MULSUB(vn, un, carry_in) \
|
||||||
{ \
|
{ \
|
||||||
product = ((vn * guess) + carry_in); \
|
product = ((vn * guess) + carry_in); \
|
||||||
diff = (un - (HD_LOW (product))); \
|
diff = (un - (HD_LOW (product))); \
|
||||||
if (diff < 0) \
|
if (diff < 0) \
|
||||||
{ \
|
{ \
|
||||||
un = (diff + BIGNUM_RADIX_ROOT); \
|
un = (diff + BIGNUM_RADIX_ROOT); \
|
||||||
carry = ((HD_HIGH (product)) + 1); \
|
carry = ((HD_HIGH (product)) + 1); \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
un = diff; \
|
un = diff; \
|
||||||
carry = (HD_HIGH (product)); \
|
carry = (HD_HIGH (product)); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BDDS_ADD(vn, un, carry_in) \
|
#define BDDS_ADD(vn, un, carry_in) \
|
||||||
{ \
|
{ \
|
||||||
sum = (vn + un + carry_in); \
|
sum = (vn + un + carry_in); \
|
||||||
if (sum < BIGNUM_RADIX_ROOT) \
|
if (sum < BIGNUM_RADIX_ROOT) \
|
||||||
{ \
|
{ \
|
||||||
un = sum; \
|
un = sum; \
|
||||||
carry = 0; \
|
carry = 0; \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
un = (sum - BIGNUM_RADIX_ROOT); \
|
un = (sum - BIGNUM_RADIX_ROOT); \
|
||||||
carry = 1; \
|
carry = 1; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
bignum_digit_type factorvm::bignum_digit_divide_subtract(bignum_digit_type v1, bignum_digit_type v2, bignum_digit_type guess, bignum_digit_type * u)
|
bignum_digit_type factorvm::bignum_digit_divide_subtract(bignum_digit_type v1, bignum_digit_type v2, bignum_digit_type guess, bignum_digit_type * u)
|
||||||
|
|
@ -1221,10 +1220,10 @@ bignum_digit_type factorvm::bignum_digit_divide_subtract(bignum_digit_type v1, b
|
||||||
/* allocates memory */
|
/* allocates memory */
|
||||||
void factorvm::bignum_divide_unsigned_small_denominator(bignum * numerator, bignum_digit_type denominator, bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p)
|
void factorvm::bignum_divide_unsigned_small_denominator(bignum * numerator, bignum_digit_type denominator, bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p)
|
||||||
{
|
{
|
||||||
GC_BIGNUM(numerator,this);
|
GC_BIGNUM(numerator);
|
||||||
|
|
||||||
bignum * q = (bignum_new_sign (numerator, q_negative_p));
|
bignum * q = (bignum_new_sign (numerator, q_negative_p));
|
||||||
GC_BIGNUM(q,this);
|
GC_BIGNUM(q);
|
||||||
|
|
||||||
bignum_digit_type r = (bignum_destructive_scale_down (q, denominator));
|
bignum_digit_type r = (bignum_destructive_scale_down (q, denominator));
|
||||||
|
|
||||||
|
|
@ -1355,7 +1354,7 @@ bignum *factorvm::bignum_trim(bignum * bignum)
|
||||||
/* allocates memory */
|
/* allocates memory */
|
||||||
bignum *factorvm::bignum_new_sign(bignum * x, int negative_p)
|
bignum *factorvm::bignum_new_sign(bignum * x, int negative_p)
|
||||||
{
|
{
|
||||||
GC_BIGNUM(x,this);
|
GC_BIGNUM(x);
|
||||||
bignum * result = (allot_bignum ((BIGNUM_LENGTH (x)), negative_p));
|
bignum * result = (allot_bignum ((BIGNUM_LENGTH (x)), negative_p));
|
||||||
|
|
||||||
bignum_destructive_copy (x, result);
|
bignum_destructive_copy (x, result);
|
||||||
|
|
@ -1416,11 +1415,11 @@ bignum *factorvm::bignum_bitwise_and(bignum * arg1, bignum * arg2)
|
||||||
return(
|
return(
|
||||||
(BIGNUM_NEGATIVE_P (arg1))
|
(BIGNUM_NEGATIVE_P (arg1))
|
||||||
? (BIGNUM_NEGATIVE_P (arg2))
|
? (BIGNUM_NEGATIVE_P (arg2))
|
||||||
? bignum_negneg_bitwise_op(AND_OP, arg1, arg2)
|
? bignum_negneg_bitwise_op(AND_OP, arg1, arg2)
|
||||||
: bignum_posneg_bitwise_op(AND_OP, arg2, arg1)
|
: bignum_posneg_bitwise_op(AND_OP, arg2, arg1)
|
||||||
: (BIGNUM_NEGATIVE_P (arg2))
|
: (BIGNUM_NEGATIVE_P (arg2))
|
||||||
? bignum_posneg_bitwise_op(AND_OP, arg1, arg2)
|
? bignum_posneg_bitwise_op(AND_OP, arg1, arg2)
|
||||||
: bignum_pospos_bitwise_op(AND_OP, arg1, arg2)
|
: bignum_pospos_bitwise_op(AND_OP, arg1, arg2)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1430,11 +1429,11 @@ bignum *factorvm::bignum_bitwise_ior(bignum * arg1, bignum * arg2)
|
||||||
return(
|
return(
|
||||||
(BIGNUM_NEGATIVE_P (arg1))
|
(BIGNUM_NEGATIVE_P (arg1))
|
||||||
? (BIGNUM_NEGATIVE_P (arg2))
|
? (BIGNUM_NEGATIVE_P (arg2))
|
||||||
? bignum_negneg_bitwise_op(IOR_OP, arg1, arg2)
|
? bignum_negneg_bitwise_op(IOR_OP, arg1, arg2)
|
||||||
: bignum_posneg_bitwise_op(IOR_OP, arg2, arg1)
|
: bignum_posneg_bitwise_op(IOR_OP, arg2, arg1)
|
||||||
: (BIGNUM_NEGATIVE_P (arg2))
|
: (BIGNUM_NEGATIVE_P (arg2))
|
||||||
? bignum_posneg_bitwise_op(IOR_OP, arg1, arg2)
|
? bignum_posneg_bitwise_op(IOR_OP, arg1, arg2)
|
||||||
: bignum_pospos_bitwise_op(IOR_OP, arg1, arg2)
|
: bignum_pospos_bitwise_op(IOR_OP, arg1, arg2)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1444,11 +1443,11 @@ bignum *factorvm::bignum_bitwise_xor(bignum * arg1, bignum * arg2)
|
||||||
return(
|
return(
|
||||||
(BIGNUM_NEGATIVE_P (arg1))
|
(BIGNUM_NEGATIVE_P (arg1))
|
||||||
? (BIGNUM_NEGATIVE_P (arg2))
|
? (BIGNUM_NEGATIVE_P (arg2))
|
||||||
? bignum_negneg_bitwise_op(XOR_OP, arg1, arg2)
|
? bignum_negneg_bitwise_op(XOR_OP, arg1, arg2)
|
||||||
: bignum_posneg_bitwise_op(XOR_OP, arg2, arg1)
|
: bignum_posneg_bitwise_op(XOR_OP, arg2, arg1)
|
||||||
: (BIGNUM_NEGATIVE_P (arg2))
|
: (BIGNUM_NEGATIVE_P (arg2))
|
||||||
? bignum_posneg_bitwise_op(XOR_OP, arg1, arg2)
|
? bignum_posneg_bitwise_op(XOR_OP, arg1, arg2)
|
||||||
: bignum_pospos_bitwise_op(XOR_OP, arg1, arg2)
|
: bignum_pospos_bitwise_op(XOR_OP, arg1, arg2)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1457,7 +1456,7 @@ bignum *factorvm::bignum_bitwise_xor(bignum * arg1, bignum * arg2)
|
||||||
/* assume arg1 is a big number, n is a long */
|
/* assume arg1 is a big number, n is a long */
|
||||||
bignum *factorvm::bignum_magnitude_ash(bignum * arg1, fixnum n)
|
bignum *factorvm::bignum_magnitude_ash(bignum * arg1, fixnum n)
|
||||||
{
|
{
|
||||||
GC_BIGNUM(arg1,this);
|
GC_BIGNUM(arg1);
|
||||||
|
|
||||||
bignum * result = NULL;
|
bignum * result = NULL;
|
||||||
bignum_digit_type *scan1;
|
bignum_digit_type *scan1;
|
||||||
|
|
@ -1518,7 +1517,7 @@ bignum *factorvm::bignum_magnitude_ash(bignum * arg1, fixnum n)
|
||||||
/* allocates memory */
|
/* allocates memory */
|
||||||
bignum *factorvm::bignum_pospos_bitwise_op(int op, bignum * arg1, bignum * arg2)
|
bignum *factorvm::bignum_pospos_bitwise_op(int op, bignum * arg1, bignum * arg2)
|
||||||
{
|
{
|
||||||
GC_BIGNUM(arg1,this); GC_BIGNUM(arg2,this);
|
GC_BIGNUM(arg1); GC_BIGNUM(arg2);
|
||||||
|
|
||||||
bignum * result;
|
bignum * result;
|
||||||
bignum_length_type max_length;
|
bignum_length_type max_length;
|
||||||
|
|
@ -1552,7 +1551,7 @@ bignum *factorvm::bignum_pospos_bitwise_op(int op, bignum * arg1, bignum * arg2)
|
||||||
/* allocates memory */
|
/* allocates memory */
|
||||||
bignum *factorvm::bignum_posneg_bitwise_op(int op, bignum * arg1, bignum * arg2)
|
bignum *factorvm::bignum_posneg_bitwise_op(int op, bignum * arg1, bignum * arg2)
|
||||||
{
|
{
|
||||||
GC_BIGNUM(arg1,this); GC_BIGNUM(arg2,this);
|
GC_BIGNUM(arg1); GC_BIGNUM(arg2);
|
||||||
|
|
||||||
bignum * result;
|
bignum * result;
|
||||||
bignum_length_type max_length;
|
bignum_length_type max_length;
|
||||||
|
|
@ -1604,7 +1603,7 @@ bignum *factorvm::bignum_posneg_bitwise_op(int op, bignum * arg1, bignum * arg2)
|
||||||
/* allocates memory */
|
/* allocates memory */
|
||||||
bignum *factorvm::bignum_negneg_bitwise_op(int op, bignum * arg1, bignum * arg2)
|
bignum *factorvm::bignum_negneg_bitwise_op(int op, bignum * arg1, bignum * arg2)
|
||||||
{
|
{
|
||||||
GC_BIGNUM(arg1,this); GC_BIGNUM(arg2,this);
|
GC_BIGNUM(arg1); GC_BIGNUM(arg2);
|
||||||
|
|
||||||
bignum * result;
|
bignum * result;
|
||||||
bignum_length_type max_length;
|
bignum_length_type max_length;
|
||||||
|
|
@ -1691,7 +1690,7 @@ void factorvm::bignum_negate_magnitude(bignum * arg)
|
||||||
/* Allocates memory */
|
/* Allocates memory */
|
||||||
bignum *factorvm::bignum_integer_length(bignum * x)
|
bignum *factorvm::bignum_integer_length(bignum * x)
|
||||||
{
|
{
|
||||||
GC_BIGNUM(x,this);
|
GC_BIGNUM(x);
|
||||||
|
|
||||||
bignum_length_type index = ((BIGNUM_LENGTH (x)) - 1);
|
bignum_length_type index = ((BIGNUM_LENGTH (x)) - 1);
|
||||||
bignum_digit_type digit = (BIGNUM_REF (x, index));
|
bignum_digit_type digit = (BIGNUM_REF (x, index));
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
namespace factor
|
namespace factor
|
||||||
{
|
{
|
||||||
|
|
||||||
/* :tabSize=2:indentSize=2:noTabs=true:
|
/*
|
||||||
|
|
||||||
Copyright (C) 1989-1992 Massachusetts Institute of Technology
|
Copyright (C) 1989-1992 Massachusetts Institute of Technology
|
||||||
Portions copyright (C) 2004-2009 Slava Pestov
|
Portions copyright (C) 2004-2009 Slava Pestov
|
||||||
|
|
@ -45,9 +45,6 @@ enum bignum_comparison
|
||||||
};
|
};
|
||||||
|
|
||||||
struct factorvm;
|
struct factorvm;
|
||||||
bignum * digit_stream_to_bignum(unsigned int n_digits,
|
bignum * digit_stream_to_bignum(unsigned int n_digits, unsigned int (*producer)(unsigned int,factorvm*), unsigned int radix, int negative_p);
|
||||||
unsigned int (*producer)(unsigned int,factorvm*),
|
|
||||||
unsigned int radix,
|
|
||||||
int negative_p);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ struct gc_bignum
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define GC_BIGNUM(x,vm) gc_bignum x##__gc_root(&x,vm)
|
#define GC_BIGNUM(x) gc_bignum x##__gc_root(&x,this)
|
||||||
|
|
||||||
//generic_arrays.hpp
|
//generic_arrays.hpp
|
||||||
template <typename TYPE> TYPE *factorvm::allot_array_internal(cell capacity)
|
template <typename TYPE> TYPE *factorvm::allot_array_internal(cell capacity)
|
||||||
|
|
|
||||||
|
|
@ -857,9 +857,9 @@ VM_ASM_API_OVERFLOW void overflow_fixnum_subtract(fixnum x, fixnum y, factorvm *
|
||||||
inline void factorvm::overflow_fixnum_multiply(fixnum x, fixnum y)
|
inline void factorvm::overflow_fixnum_multiply(fixnum x, fixnum y)
|
||||||
{
|
{
|
||||||
bignum *bx = fixnum_to_bignum(x);
|
bignum *bx = fixnum_to_bignum(x);
|
||||||
GC_BIGNUM(bx,this);
|
GC_BIGNUM(bx);
|
||||||
bignum *by = fixnum_to_bignum(y);
|
bignum *by = fixnum_to_bignum(y);
|
||||||
GC_BIGNUM(by,this);
|
GC_BIGNUM(by);
|
||||||
drepl(tag<bignum>(bignum_multiply(bx,by)));
|
drepl(tag<bignum>(bignum_multiply(bx,by)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue