Commit 38859630 authored by Martin Storsjö's avatar Martin Storsjö Committed by Niels Möller

Add fallback functions for mpn_copyd, mpn_copyi and mpn_zero.

parent 0d039117
2013-04-04 Niels Möller <nisse@lysator.liu.se> 2013-04-04 Niels Möller <nisse@lysator.liu.se>
From Martin Storsjö. Fallback functions for older GMP releases.
* gmp-glue.c (mpn_copyd, mpn_copyi, mpn_zero): New functions.
* gmp-glue.h: Declare them.
* gmp-glue.h (cnd_add_n, cnd_sub_n): Moved here, define in terms * gmp-glue.h (cnd_add_n, cnd_sub_n): Moved here, define in terms
of mpn_cnd_add_n and mpn_sub_n if available, otherwise in terms of of mpn_cnd_add_n and mpn_sub_n if available, otherwise in terms of
mpn_addmul_1 and mpn_submul_1. This seems to be an improvement for mpn_addmul_1 and mpn_submul_1. This seems to be an improvement for
......
...@@ -106,6 +106,32 @@ mpz_roinit_n (mpz_ptr x, const mp_limb_t *xp, mp_size_t xs) ...@@ -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 */ #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. */ /* Additional convenience functions. */
int int
......
...@@ -33,6 +33,12 @@ ...@@ -33,6 +33,12 @@
#define GMP_HAVE_mpz_limbs_read 0 #define GMP_HAVE_mpz_limbs_read 0
#endif #endif
#ifdef mpn_copyd
#define GMP_HAVE_mpn_copyd 1
#else
#define GMP_HAVE_mpn_copyd 0
#endif
/* Name mangling. */ /* Name mangling. */
#if !GMP_HAVE_mpz_limbs_read #if !GMP_HAVE_mpz_limbs_read
#define mpz_limbs_read _nettle_mpz_limbs_read #define mpz_limbs_read _nettle_mpz_limbs_read
...@@ -42,6 +48,12 @@ ...@@ -42,6 +48,12 @@
#define mpz_roinit_n _nettle_mpz_roinit_n #define mpz_roinit_n _nettle_mpz_roinit_n
#endif #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_cmp _nettle_mpz_limbs_cmp
#define mpz_limbs_read_n _nettle_mpz_limbs_read_n #define mpz_limbs_read_n _nettle_mpz_limbs_read_n
#define mpz_limbs_copy _nettle_mpz_limbs_copy #define mpz_limbs_copy _nettle_mpz_limbs_copy
...@@ -92,6 +104,20 @@ mpz_roinit_n (mpz_ptr x, const mp_limb_t *xp, mp_size_t xs); ...@@ -92,6 +104,20 @@ mpz_roinit_n (mpz_ptr x, const mp_limb_t *xp, mp_size_t xs);
#endif /* !GMP_HAVE_mpz_limbs_read */ #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 */ /* Convenience functions */
int int
mpz_limbs_cmp (mpz_srcptr a, const mp_limb_t *bp, mp_size_t bn); mpz_limbs_cmp (mpz_srcptr a, const mp_limb_t *bp, mp_size_t bn);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment