Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2005-10-14
00:47 • Ticket [1299153fff] MP_PREC is too large status still Closed with 2 other ch... artifact: 5f6932b77b user: dgp
00:47 • Closed ticket [1299153fff]. artifact: c95d573562 user: dgp
2005-09-23
23:47 • Ticket [1299153fff]: 4 changes artifact: fb24fca8a3 user: dgp
2005-09-22
21:37 • New ticket [1299153fff]. artifact: 0ea9279db6 user: dgp

MP_PREC is too large

Closed / Fixed1299153fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-09-22 21:37:51
The libtommath library has a
configuration value MP_PREC
that specifies the minimum number
of mp_digits in an mp_int.  The
default value of MP_PREC is 64.

This means that once an integer
value is too large to fit in a Tcl_WideInt,
the storage requirements balloon from
8 bytes to hold 64 bits to 256 bytes
just for the digits array holding 64 4-byte
mp_digits to hold 65 bits.

Even worse is the Tcl routine
TclBNInitBignumFromLong()
which calls mp_init_size().  Through
some quirkiness in libtommath,
mp_init_size actually creates an
mp_int with a minimum of
2*MP_PREC mp_digits.  So when
we're explicitly creating an
mp_int to hold a long value -- one we
know will fit in two mp_digits -- we're
forced to allocate 128 mp_digits, or
a whopping 512 bytes, just for the
digits array.

These defaults may be appropriate
for some clients of libtommath, but
they're not a good fit for Tcl to require
such an explosion of memory expense
just to cross over into mp_int's.

There is an MP_LOW_MEM configuration
that sets MP_PREC to 8 rather than 64.
That would help a lot, but even that seems
too abrupt across the wide->bignum transition.
A value of MP_PREC = 4 would seem to be
a better fit for Tcl's bignum needs.

Even with that revision, we should probably
rewrite TclBNInitBignumFromLong to
avoid making a call to mp_init_size().
Other mp_init_size() callers ought to be
examined as well.
dgpplain2005-09-23 23:47:52
Logged In: YES 
user_id=80530


-DMP_PREC=4 added to Makefiles
on the numerics branch.
dgpplain2005-10-14 00:47:40
Logged In: YES 
user_id=80530

fixed by the TIP 237 merge.
dgp Ticket [1299153fff]: 2 changes [History diff]2005-10-14 00:47:41
Log in (anonymous is fine) to add a comment.