VM: Erasing the last traces of GC_BIGNUM from bignum.cpp

db4
Björn Lindqvist 2014-06-17 17:03:50 +02:00 committed by John Benediktsson
parent 1f6d6b9a5d
commit 981a02be27
2 changed files with 15 additions and 20 deletions

View File

@ -1702,10 +1702,9 @@ bignum* factor_vm::bignum_gcd(bignum* a_, bignum* b_) {
} }
#else #else
/* Allocates memory */ /* Allocates memory */
bignum* factor_vm::bignum_gcd(bignum* a, bignum* b) { bignum* factor_vm::bignum_gcd(bignum* a_, bignum* b_) {
GC_BIGNUM(a); data_root<bignum> a(a_, this);
GC_BIGNUM(b); data_root<bignum> b(b_, this);
bignum* c, *d, *e, *f;
bignum_twodigit_type x, y, q, s, t, A, B, C, D; bignum_twodigit_type x, y, q, s, t, A, B, C, D;
int nbits, k; int nbits, k;
bignum_length_type size_a, size_b, size_c; bignum_length_type size_a, size_b, size_c;
@ -1714,19 +1713,18 @@ bignum* factor_vm::bignum_gcd(bignum* a, bignum* b) {
/* clone the bignums so we can modify them in-place */ /* clone the bignums so we can modify them in-place */
size_a = BIGNUM_LENGTH(a); size_a = BIGNUM_LENGTH(a);
c = allot_bignum(size_a, 0); data_root<bignum> c(allot_bignum(size_a, 0), this);
// c = allot_bignum(size_a, 0);
scan_a = BIGNUM_START_PTR(a); scan_a = BIGNUM_START_PTR(a);
a_end = scan_a + size_a; a_end = scan_a + size_a;
GC_BIGNUM(c);
scan_c = BIGNUM_START_PTR(c); scan_c = BIGNUM_START_PTR(c);
while (scan_a < a_end) while (scan_a < a_end)
(*scan_c++) = (*scan_a++); (*scan_c++) = (*scan_a++);
a = c; a = c;
size_b = BIGNUM_LENGTH(b); size_b = BIGNUM_LENGTH(b);
d = allot_bignum(size_b, 0); data_root<bignum> d(allot_bignum(size_b, 0), this);
scan_b = BIGNUM_START_PTR(b); scan_b = BIGNUM_START_PTR(b);
b_end = scan_b + size_b; b_end = scan_b + size_b;
GC_BIGNUM(d);
scan_d = BIGNUM_START_PTR(d); scan_d = BIGNUM_START_PTR(d);
while (scan_b < b_end) while (scan_b < b_end)
(*scan_d++) = (*scan_b++); (*scan_d++) = (*scan_b++);
@ -1734,7 +1732,7 @@ bignum* factor_vm::bignum_gcd(bignum* a, bignum* b) {
/* Initial reduction: make sure that 0 <= b <= a. */ /* Initial reduction: make sure that 0 <= b <= a. */
if (bignum_compare(a, b) == bignum_comparison_less) { if (bignum_compare(a, b) == bignum_comparison_less) {
std::swap(a, b); swap(a, b);
std::swap(size_a, size_b); std::swap(size_a, size_b);
} }
@ -1780,14 +1778,11 @@ bignum* factor_vm::bignum_gcd(bignum* a, bignum* b) {
if (size_b == 0) { if (size_b == 0) {
return bignum_trim(a); return bignum_trim(a);
} }
e = bignum_trim(a); data_root<bignum> e(bignum_trim(a.untagged()), this);
GC_BIGNUM(e); data_root<bignum> f(bignum_trim(b.untagged()), this);
f = bignum_trim(b); c = bignum_remainder(e.untagged(), f.untagged());
GC_BIGNUM(f); if (c.untagged() == BIGNUM_OUT_OF_BAND) {
c = bignum_remainder(e, f); return c.untagged();
GC_BIGNUM(c);
if (c == BIGNUM_OUT_OF_BAND) {
return c;
} }
// copy 'b' to 'a' // copy 'b' to 'a'
@ -1875,8 +1870,8 @@ bignum* factor_vm::bignum_gcd(bignum* a, bignum* b) {
} }
/* a fits into a fixnum, so b must too */ /* a fits into a fixnum, so b must too */
fixnum xx = bignum_to_fixnum(a); fixnum xx = bignum_to_fixnum(a.untagged());
fixnum yy = bignum_to_fixnum(b); fixnum yy = bignum_to_fixnum(b.untagged());
fixnum tt; fixnum tt;
/* usual Euclidean algorithm for longs */ /* usual Euclidean algorithm for longs */

View File

@ -304,7 +304,7 @@ struct factor_vm {
bignum* bignum_integer_length(bignum* x_); bignum* bignum_integer_length(bignum* x_);
int bignum_logbitp(int shift, bignum* arg); int bignum_logbitp(int shift, bignum* arg);
int bignum_unsigned_logbitp(int shift, bignum* bn); int bignum_unsigned_logbitp(int shift, bignum* bn);
bignum* bignum_gcd(bignum* a, bignum* b); bignum* bignum_gcd(bignum* a_, bignum* b_);
//data heap //data heap
void init_card_decks(); void init_card_decks();