# GMP Development Projects

An up-to-date version of this file is available at http://www.swox.com/gmp/projects.html.

This file lists projects suitable for volunteers. Please see the tasks file for smaller tasks.

If you want to work on any of the projects below, please let tege@swox.com know. If you want to help with a project that already somebody else is working on, please talk to that person too, tege@swox.com can put you in touch. (There are no email addresses of volunteers below, due to spamming problems.)

- C++ wrapper

  A C++ wrapper for GMP is highly desirable. Several people have started writing one, but nobody has so far finished it. For a wrapper to be useful, one needs to pay attention to efficiency.

  1. Write arithmetic functions for direct applications of most elementary C++ types. This might be necessary to avoid ambiguities, but it is also desirable from an efficiency standpoint.
  2. Avoid running constructors/destructors when not necessary. For example, implement `a += b` by directly applying mpz_add.

- Faster multiplication

  The current multiplication code uses Karatsuba, 3-way Toom-Cook, or Fermat FFT. Several new developments are desirable:

  1. Handle multiplication of operands with different digit count better than today. We now split the operands in a very inefficient way, see mpn/generic/mul.c.
  2. Consider N-way Toom-Cook. See Knuth's Seminumerical Algorithms for details on the method. Code implementing it exists. This is asymptotically inferior to FFTs, but is finer grained. A toom-4 might fit in between toom-3 and the FFTs (or it might not).
  3. It's possible CPU dependent effects like cache locality will have a greater impact on speed than algorithmic improvements.

- Assembly routines

  Write new and tune existing assembly routines. The programs in mpn/tests and the tune/speed.c program are useful for testing and timing the routines you write. See the README files in those directories for more information.

  Please make sure your new routines are fast for these three situations:

  1. Operands that fit into the cache.
  2. Small operands of less than, say, 10 limbs.
  3. Huge operands that does not fit into the cache.

  The most important routines are mpn_addmul_1, mpn_mul_basecase and mpn_sqr_basecase. The latter two don't exist for all machines, while mpn_addmul_1 exists for almost all machines.

  Standard techniques for these routines are unrolling, software pipelining, and specialization for common operand values. For machines with poor integer multiplication, it is often possible to improve the performance using floating-point operations, or SIMD operations such as MMX or Sun's VIS.

  Using floating-point operations is interesting but somewhat tricky. Since IEEE double has 53 bit of mantissa, one has to split the operands in small prices, so that no result is greater than 2^53. For 32-bit computers, splitting one operand into 16-bit pieces works. For 64-bit machines, one operand can be split into 21-bit pieces and the other into 32-bit pieces. (A 64-bit operand can be split into just three 21-bit pieces if one allows the split operands to be negative!)

- Faster extended GCD

  We currently have extended GCD based on Lehmer's method. But the binary method can quite easily be improved for bignums in a similar way Lehmer improved Euclid's algorithm. The result should beat Lehmer's method by about a factor of 2. Furthermore, the multiprecision step of Lehmer's method and the binary method will be identical, so the current code can mostly be reused. It should be possible to share code between GCD and GCDEXT, and probably with Jacobi symbols too.

- Math functions for the mpf layer

  Implement the functions of math.h for the GMP mpf layer! Check the book "Pi and the AGM" by Borwein and Borwein for ideas how to do this. These functions are desirable: acos, acosh, asin, asinh, atan, atanh, atan2, cos, cosh, exp, log, log10, pow, sin, sinh, tan, tanh.

- Faster sqrt

  The current code for computing square roots use a Newton iteration that rely on division. It is possible to avoid using division by computing 1/sqrt(A) using this formula:

                                          2
                         x   = x  (3 - A x )/2.
                          i+1   i         i

  The final result is then computed without division using,

                           sqrt(A) = A x .
                                        n

  The resulting code should be substantially faster than the current code.

- Nth root

  Implement, at the mpn level, a routine for computing the nth root of a number. The routine should use Newton's method, preferably without using division.

  If the routine becomes fast enough, perhaps square roots could be computed using this function.

- More random number generators

  Implement some more pseudo random number generator algorithms. Today there's only Linear Congruential.

- Test Suite

  Add a test suite for old bugs. These tests wouldn't loop or use random numbers, but just test for specific bugs found in the past.

  More importantly, improve the random number controls for test collections:

  1. Use the new random number framework.
  2. Have every test accept a seed parameter.
  3. Allow `make check' to set the seed parameter.
  4. Add more tests for important, now untested functions.

  With this in place, it should be possible to rid GMP of practically all bugs by having some dedicated GMP test machines running "make check" with ever increasing seeds (and periodically updating to the latest GMP).

  If a few more ASSERTs were sprinkled through the code, running some tests with --enable-assert might be useful, though not a substitute for tests on the normal build.

  An important feature of any random tests will be to record the seeds used, and perhaps to snapshot operands before performing each test, so any problem exposed can be reproduced.

Please send comments about this page to tege@swox.com. Copyright (C) 1999, 2000 Torbjörn Granlund. |