mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
Stage bignum_simplify
This commit is contained in:
parent
fd6b5e6907
commit
b2879f8f36
1 changed files with 39 additions and 1 deletions
40
runtime.c
40
runtime.c
|
@ -2446,6 +2446,43 @@ int bignum2_num_digits(bignum2_type *bn, int radix)
|
|||
return len;
|
||||
}
|
||||
|
||||
/* Simplification: scan trailing zeroes, then return a fixnum if the
|
||||
* value fits, or trim the bignum's length. If the bignum was stored
|
||||
* in scratch space, we mark it as reclaimable. This means any
|
||||
* references to the original bignum are invalid after simplification!
|
||||
*/
|
||||
//C_regparm C_word C_fcall C_bignum_simplify(C_word big)
|
||||
//{
|
||||
// C_uword *start = C_bignum_digits(big),
|
||||
// *last_digit = start + C_bignum_size(big) - 1,
|
||||
// *scan = last_digit, tmp;
|
||||
// int length;
|
||||
//
|
||||
// while (scan >= start && *scan == 0)
|
||||
// scan--;
|
||||
// length = scan - start + 1;
|
||||
//
|
||||
// switch(length) {
|
||||
// case 0:
|
||||
// if (C_in_scratchspacep(C_internal_bignum_vector(big)))
|
||||
// C_mutate_scratch_slot(NULL, C_internal_bignum_vector(big));
|
||||
// return C_fix(0);
|
||||
// case 1:
|
||||
// tmp = *start;
|
||||
// if (C_bignum_negativep(big) ?
|
||||
// !(tmp & C_INT_SIGN_BIT) && C_fitsinfixnump(-(C_word)tmp) :
|
||||
// C_ufitsinfixnump(tmp)) {
|
||||
// if (C_in_scratchspacep(C_internal_bignum_vector(big)))
|
||||
// C_mutate_scratch_slot(NULL, C_internal_bignum_vector(big));
|
||||
// return C_bignum_negativep(big) ? C_fix(-(C_word)tmp) : C_fix(tmp);
|
||||
// }
|
||||
// /* FALLTHROUGH */
|
||||
// default:
|
||||
// if (scan < last_digit) C_bignum_mutate_size(big, length);
|
||||
// return big;
|
||||
// }
|
||||
//}
|
||||
|
||||
static uint32_t bignum_digits_destructive_scale_down(uint32_t *start, uint32_t *end, uint32_t denominator)
|
||||
{
|
||||
uint32_t digit, k = 0;
|
||||
|
@ -2724,7 +2761,8 @@ object bignum2_plus_unsigned(void *data, bignum2_type *x, bignum2_type *y, int n
|
|||
}
|
||||
assert(scan_r <= end_r);
|
||||
|
||||
return C_bignum_simplify(result);
|
||||
// TODO: return C_bignum_simplify(result);
|
||||
return NULL; // DEBUG only!
|
||||
}
|
||||
|
||||
object Cyc_symbol2string(void *data, object cont, object sym)
|
||||
|
|
Loading…
Add table
Reference in a new issue