GMP lib in embedded environments

Torbjorn Granlund tg at
Thu Mar 12 15:07:48 CET 2009

Michał <spock2 at> writes:

  I have read that GMP lib supports ARM architecture. But I actually
  couldn’t find on exactly which microcontrollers it was ran
  successfully. I am especially interested in ARM7 chips
  e.g. AT91SAM7X256. Is it possible to compile and run GMP lib for this
I think so.  I think GMP for ARM uses just the basic, common
instructions, available in the ARM ISA since long.

  Another question regards using GMP lib on much less efficient
  architectures e.g. AVR. I know that GMP lib doesn`t have special
  support for AVR. But still C build of the library is possible. Does
  anyone have some experience in using GMP lib on AVR microcontrollers?
  Is it possible to use "clear C" build of the library on architectures
  that does not have a lot of RAM (e.g. on avr 4KB)?
I think this will be trickier.  GMP is not very large, but it is
probably too large for such a small device.  There are several places in
GMP that do not support word ("limb") sizes less than 32 bits, although
these should be clearly marked and trigger syntax errors.  To fix that,
one typically will need to fill out some tables.

To make the footprint as small as possible, stay away from generic I/O
functions like gmp_printf and gmp_scanf, since they pulls in lots of
functions you normally won't need.  Instead, use e.g. mpz_out_str, even
if its interface is less elegant than gmp_printf's interface.

You could also pass --disable-fft for configure, to save some space.

Creating a special gmp-mparam.h file with strategic MP_SIZE_T_MAX values
for the more advanced algorithms could also help q lot.  In most cases,
the compiler will be able to completely omit large chunks of code.

I have some plans to support minimal configurations for embedded usage
("--disable-subquad"), but not much has been done in that area yet.


More information about the gmp-discuss mailing list