diff options
Diffstat (limited to 'mpn/generic/redc_2.c')
-rw-r--r-- | mpn/generic/redc_2.c | 143 |
1 files changed, 4 insertions, 139 deletions
diff --git a/mpn/generic/redc_2.c b/mpn/generic/redc_2.c index eeaf01fa4..9942338ce 100644 --- a/mpn/generic/redc_2.c +++ b/mpn/generic/redc_2.c @@ -8,9 +8,11 @@ Copyright (C) 2000, 2001, 2002, 2004, 2008 Free Software Foundation, Inc. This file is part of the GNU MP Library. +This file is part of the GNU MP Library. + The GNU MP Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your +the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The GNU MP Library is distributed in the hope that it will be useful, but @@ -19,21 +21,12 @@ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License -along with the GNU MP Library; see the file COPYING.LIB. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -MA 02111-1307, USA. */ - -#if defined (CHECK) || defined (TIMING) -#include <stdlib.h> -#include <stdio.h> -#endif +along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp.h" #include "gmp-impl.h" #include "longlong.h" -void mpn_redc_1 (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_limb_t); -void mpn_redc_2 (mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_srcptr); #if GMP_NAIL_BITS != 0 you lose @@ -104,131 +97,3 @@ mpn_redc_2 (mp_ptr rp, mp_ptr up, mp_srcptr mp, mp_size_t n, mp_srcptr mip) if (cy != 0) mpn_sub_n (rp, rp, mp, n); } - -#if CHECK -void -dumpy (mp_srcptr p, mp_size_t n) -{ - mp_size_t i; - if (n > 20) - { - for (i = n - 1; i >= n - 4; i--) - { - printf ("%0*lx", (int) (2 * sizeof (mp_limb_t)), p[i]); - printf (" "); - } - printf ("... "); - for (i = 3; i >= 0; i--) - { - printf ("%0*lx", (int) (2 * sizeof (mp_limb_t)), p[i]); - printf (" " + (i == 0)); - } - } - else - { - for (i = n - 1; i >= 0; i--) - { - printf ("%0*lx", (int) (2 * sizeof (mp_limb_t)), p[i]); - printf (" " + (i == 0)); - } - } - puts (""); -} - -int -main (int argc, char *argv[]) -{ - mp_size_t nmax, n, itch; - mp_ptr scratch, up, ap, mp, rp1, rp2; - mp_limb_t mip[2]; - unsigned long test; - - nmax = strtol (argv[1], 0, 0); - itch = mpn_binvert_itch (2); - scratch = malloc (itch * sizeof (mp_limb_t)); - up = malloc (nmax * 2 * sizeof (mp_limb_t)); - ap = malloc (nmax * 2 * sizeof (mp_limb_t)); - mp = malloc (nmax * sizeof (mp_limb_t)); - rp1 = malloc (nmax * sizeof (mp_limb_t)); - rp2 = malloc (nmax * sizeof (mp_limb_t)); - - for (test = 0;; test++) - { - if (test % (726211 / nmax + 1) == 0) - { printf ("\r%lu", test); fflush (stdout); } - - n = random () % nmax + 1; - - mpn_random2 (up, 2 * n); - mpn_random2 (mp, n); mp[0] |= 1; - mpn_binvert (mip, mp, 2, scratch); - mip[0] = -mip[0]; mip[1] = ~mip[1]; - - MPN_COPY (ap, up, 2 * n); - mpn_redc_1 (rp1, ap, mp, n, mip[0]); - - MPN_COPY (ap, up, 2 * n); - mpn_redc_2 (rp2, ap, mp, n, mip); - - if (mpn_cmp (rp1, rp2, n) != 0) - { - printf ("ERROR in test %lu\n", test); - printf ("N= "); dumpy (up, 2 * n); - printf ("D= "); dumpy (mp, n); - printf ("Q(1)="); dumpy (rp1, n); - printf ("Q(2)="); dumpy (rp2, n); - } - } -} -#endif - -#if TIMING -#include "timing.h" -int -main (int argc, char *argv[]) -{ - mp_size_t n, itch; - mp_ptr scratch, up, ap, mp, rp1, rp2; - mp_limb_t mip[2]; - double t; - - n = strtol (argv[1], 0, 0); - itch = mpn_binvert_itch (2); - scratch = malloc (itch * sizeof (mp_limb_t)); - up = malloc (n * 2 * sizeof (mp_limb_t)); - ap = malloc (n * 2 * sizeof (mp_limb_t)); - mp = malloc (n * sizeof (mp_limb_t)); - rp1 = malloc (n * sizeof (mp_limb_t)); - rp2 = malloc (n * sizeof (mp_limb_t)); - - mpn_random2 (up, 2 * n); - mpn_random2 (mp, n); mp[0] |= 1; - mpn_binvert (mip, mp, 2, scratch); - mip[0] = -mip[0]; mip[1] = ~mip[1]; - - MPN_COPY (ap, up, 2 * n); - TIME (t, mpn_redc_1 (rp1, ap, mp, n, mip[0])); - printf ("mpn_redc_1: %f", t); -#ifdef CLOCK - printf (" %.2f c/l", CLOCK * t / 1000 / (n * n)); -#endif - puts (""); - - MPN_COPY (ap, up, 2 * n); - TIME (t, mpn_redc_2 (rp2, ap, mp, n, mip)); - printf ("mpn_redc_2: %f", t); -#ifdef CLOCK - printf (" %.2f c/l", CLOCK * t / 1000 / (n * n)); -#endif - puts (""); - - TIME (t, mpn_mul_basecase (up, ap, n, mp, n)); - printf ("mpn_mul_basecase: %f", t); -#ifdef CLOCK - printf (" %.2f c/l", CLOCK * t / 1000 / (n * n)); -#endif - puts (""); - - return 0; -} -#endif |