unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Rob Browning <rlb@defaultvalue.org>
Cc: Marius Vollmer <mvo@zagadka.de>
Subject: Re: Nearly finished (re)integrating GMP for bignums.
Date: Wed, 12 Feb 2003 15:13:12 -0600	[thread overview]
Message-ID: <871y2dnqxj.fsf@raven.i.defaultvalue.org> (raw)
In-Reply-To: <xy77kc52yik.fsf@nada.kth.se> (Mikael Djurfeldt's message of "Wed, 12 Feb 2003 18:34:59 +0100")

Mikael Djurfeldt <djurfeldt@nada.kth.se> writes:

> Ideally, the bignum code would use the pluggable source of random bits
> in random.c and the GMP generators would be provided as optional
> plugins for random.c.  Rob, is this possible?

The main issue I have now is that in scm_c_random_bignum, the code
directly manipulates the old bignum internals.  So I'll need to
convert that to GMP. i.e.:

  LONG32 *bits, mask, w;
  nd = SCM_NUMDIGS (m);
  /* calculate mask for most significant digit */
#if SIZEOF_INT == 4
  /* 16 bit digits */
  if (nd & 1)
    {
      /* fix most significant 16 bits */
      unsigned short s = SCM_BDIGITS (m)[nd - 1];

To be sure have the details right -- SCM_NUMDIGS gives the number of
elements in SCM_BDIGITS, where the last element is the most
significant digit right?

I'll need to figure out how this should map onto the available GMP
operations.  Right now I don't expose much from numbers.c
"bignum-wise", but I'm thinking of adding some _i_ functions that map
onto gmp operations, and would probably also be appropriate for any
other bignum implementation, i.e.:

  void scm_i_bigadd_ui (SCM dest, SCM src, unsigned long n);
  void scm_i_bigsub_ui (SCM dest, SCM src, unsigned long n);
  void scm_i_bigneg (SCM dest);

etc.  These prototypes follow the GMP calling convention which can be
convenient since it allows you to express both "in-place"
modifications where dest == src, or copy operations where dest != src.
The ability to do "in-place" operations can be important when dealing
with large bignums because you don't necessarily want to have to
allocate a new bignum for each operation.

Alternately, I could just support in-place operations:

  void scm_i_bigadd_ui (SCM big, unsigned long n);

or I could only support our more traditional "always copy on write"
style operations:

  SCM scm_i_bigadd_ui (SCM big, unsigned long n);

The whole point of the scm_i_big* functions would be for use by other
parts of guile where the code needs to operate directly on bignums.

The alternative is to just expect the other code use SCM_I_BIG_MPZ(x),
to get hold of the mpz_t value and then manipulate that directly.  The
direct approach could be faster, and gives more flexibility, but of
course it's less portable (presuming we ever change our bignum
implementation again).

In truth, ATM we don't have that much code outside numbers.c that
manipulates bignums directly.  Aside from the GC and eq, it's mostly
random.c and socket.c so far.  So it may not be a big deal either way.

-- 
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592  F9A0 25C8 D377 8C7E 73A4


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


  parent reply	other threads:[~2003-02-12 21:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-12 16:07 Nearly finished (re)integrating GMP for bignums Rob Browning
2003-02-12 16:26 ` Marius Vollmer
2003-02-12 17:32   ` Rob Browning
2003-02-12 17:34   ` Mikael Djurfeldt
2003-02-12 18:57     ` Rob Browning
2003-02-12 21:13     ` Rob Browning [this message]
2003-02-12 23:00     ` Kevin Ryde
2003-02-27  5:11     ` Rob Browning
2003-03-03 13:13       ` Mikael Djurfeldt
2003-03-03 13:21         ` Mikael Djurfeldt
2003-03-06 17:31         ` Rob Browning
2003-03-06 18:13           ` Mikael Djurfeldt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871y2dnqxj.fsf@raven.i.defaultvalue.org \
    --to=rlb@defaultvalue.org \
    --cc=mvo@zagadka.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).