--- gmp-glue.c | 26 ++++++++++++++++++++++++++ gmp-glue.h | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+)
diff --git a/gmp-glue.c b/gmp-glue.c index b468699..a2633a5 100644 --- a/gmp-glue.c +++ b/gmp-glue.c @@ -106,6 +106,32 @@ mpz_roinit_n (mpz_ptr x, const mp_limb_t *xp, mp_size_t xs) } #endif /* !GMP_HAVE_mpz_limbs_read */
+#if !GMP_HAVE_mpn_copyd +void +mpn_copyd (mp_ptr dst, mp_srcptr src, mp_size_t n) +{ + mp_size_t i; + for (i = n - 1; i >= 0; i--) + dst[i] = src[i]; +} + +void +mpn_copyi (mp_ptr dst, mp_srcptr src, mp_size_t n) +{ + mp_size_t i; + for (i = 0; i < n; i++) + dst[i] = src[i]; +} + +void +mpn_zero (mp_ptr ptr, mp_size_t n) +{ + mp_size_t i; + for (i = 0; i < n; i++) + ptr[i] = 0; +} +#endif /* !GMP_HAVE_mpn_copyd */ + /* Additional convenience functions. */
int diff --git a/gmp-glue.h b/gmp-glue.h index ef17c2f..27c0942 100644 --- a/gmp-glue.h +++ b/gmp-glue.h @@ -33,6 +33,12 @@ #define GMP_HAVE_mpz_limbs_read 0 #endif
+#ifdef mpz_copyd +#define GMP_HAVE_mpz_copyd 1 +#else +#define GMP_HAVE_mpz_copyd 0 +#endif + #if __GNU_MP__ < 5 typedef unsigned long int mp_bitcnt_t; #endif @@ -46,6 +52,12 @@ typedef unsigned long int mp_bitcnt_t; #define mpz_roinit_n _nettle_mpz_roinit_n #endif
+#if !GMP_HAVE_mpn_copyd +#define mpn_copyd _nettle_mpn_copyd +#define mpn_copyi _nettle_mpn_copyi +#define mpn_zero _nettle_mpn_zero +#endif + #define mpz_limbs_cmp _nettle_mpz_limbs_cmp #define mpz_limbs_read_n _nettle_mpz_limbs_read_n #define mpz_limbs_copy _nettle_mpz_limbs_copy @@ -87,6 +99,20 @@ mpz_roinit_n (mpz_ptr x, const mp_limb_t *xp, mp_size_t xs);
#endif /* !GMP_HAVE_mpz_limbs_read */
+#if !GMP_HAVE_mpn_copyd +/* Copy elements, backwards */ +void +mpn_copyd (mp_ptr dst, mp_srcptr src, mp_size_t n); + +/* Copy elements, forwards */ +void +mpn_copyi (mp_ptr dst, mp_srcptr src, mp_size_t n); + +/* Zero elements */ +void +mpn_zero (mp_ptr ptr, mp_size_t n); +#endif /* !GMP_HAVE_mpn_copyd */ + /* Convenience functions */ int mpz_limbs_cmp (mpz_srcptr a, const mp_limb_t *bp, mp_size_t bn);