bug-gmp
[Top][All Lists]

## symbol catenation and montgomery

 From: Niels Möller Subject: symbol catenation and montgomery Date: 27 Sep 2000 10:06:58 +0200

```Hi,

I have a few more questions about gmp-3.1. First, the symbol
catenation in gmp.h:

: #ifndef __MPN
: /* Really use `defined (__STDC__)' here; we want it to be true for Sun C */
: #if defined (__STDC__) || defined (__cplusplus)
: #define __MPN(x) __gmpn_##x
: #else
: #define __MPN(x) __gmpn_/**/x
: #endif
: #endif

According to Henrik GrubbstrÃ¶m (address@hidden), there are a few
compilers that define __STDC__ only in strict ansi mode. I can see two
ways to fix that, either do some autoconf test and insert a symbol in
gmp.h depending on the result, or doing a test using only cpp,
something like

: #define A     1
: #define B     +1
: #define AB    0
: #define TOKCAT(x,y)   x/**/y
: #if TOKCAT(A,B)
: ANSI
: #else
: K&R
: #endif

Secondly, someone told me that gmp's modular exponentiation is slow,
because it doesn't use montgomery style multiplication. I've had a
look at mpz/powm.c, but I can't really tell if that is true. To me,
the mpz_redc resembles montgomery reduction a little, but on the other
hand it is used only for small moduli, so I guess it is something
different. What is the status, and do you have any plans for a more
this.

BTW, I think a macro

#define MUL_RED(c, a, b, m, invm) \
do { if (use_redc) mpz_redc(c, a, b, m, invm) \
else { mpz_mul(c, a, b); mpz_mod(c, c, m); } \
} while(0)

would make the code a little easier to read, at least for me.

Regards,
/Niels

```