diff options
author | Torbjorn Granlund <tege@gmplib.org> | 2011-10-16 15:50:49 +0200 |
---|---|---|
committer | Torbjorn Granlund <tege@gmplib.org> | 2011-10-16 15:50:49 +0200 |
commit | 10b35af7f1b1b20973ca12c9fad655902da2938b (patch) | |
tree | c88fe71aaaba02e78386f29292c1191da3202e02 /tests/devel/shift.c | |
parent | 23e28626dcc670b12a23d9dc626698ed42a88116 (diff) | |
download | gmp-10b35af7f1b1b20973ca12c9fad655902da2938b.tar.gz |
Overhaul low-level mpn test code.
Diffstat (limited to 'tests/devel/shift.c')
-rw-r--r-- | tests/devel/shift.c | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/tests/devel/shift.c b/tests/devel/shift.c index 089edd3ac..5561c1349 100644 --- a/tests/devel/shift.c +++ b/tests/devel/shift.c @@ -1,5 +1,5 @@ /* -Copyright 1996, 1998, 1999, 2000, 2001, 2004, 2007, 2009 Free Software +Copyright 1996, 1998, 1999, 2000, 2001, 2004, 2007, 2009, 2011 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include <stdlib.h> +#include <string.h> #include <stdio.h> #include "gmp.h" #include "gmp-impl.h" @@ -60,8 +61,10 @@ cputime () } #endif +static void print_posneg (mp_limb_t); static void mpn_print (mp_ptr, mp_size_t); +#define LXW ((int) (2 * sizeof (mp_limb_t))) #define M * 1000000 #ifndef CLOCK @@ -166,11 +169,27 @@ main (int argc, char **argv) if (cyx != cyy || mpn_cmp (dx, dy, size+2) != 0 || dx[0] != 0x87654321 || dx[size+1] != 0x12345678) { + mp_size_t s, e; + for (s = 0;; s++) + if ((unsigned long long) (dx+1)[s] != (unsigned long long) (dy+1)[s]) + break; + for (e = size - 1;; e--) + if ((unsigned long long) (dx+1)[e] != (unsigned long long) (dy+1)[e]) + break; #ifndef PRINT - mpn_print (&cyx, 1); - mpn_print (dx+1, size); - mpn_print (&cyy, 1); - mpn_print (dy+1, size); + printf ("cnt=%-*d\n", (int) (2 * sizeof(mp_limb_t)) - 4, cnt); + for (i = s; i <= e; i++) + { + printf ("%6d: ", i); + printf ("%0*llX ", LXW, (unsigned long long) (dx+1)[i]); + printf ("%0*llX ", LXW, (unsigned long long) (dy+1)[i]); + print_posneg ((dy+1)[i] - (dx+1)[i]); + printf ("\n"); + } + printf ("%6s: ", "retval"); + printf ("%0*llX ", LXW, (unsigned long long) cyx); + printf ("%0*llX ", LXW, (unsigned long long) cyy); + print_posneg (cyx - cyy); #endif printf ("\n"); if (dy[0] != 0x87654321) @@ -186,6 +205,24 @@ main (int argc, char **argv) } static void +print_posneg (mp_limb_t d) +{ + char buf[LXW + 2]; + if (d == 0) + printf (" %*X", LXW, 0); + else if (-d < d) + { + sprintf (buf, "%llX", (unsigned long long) -d); + printf ("%*s-%s", LXW - (int) strlen (buf), "", buf); + } + else + { + sprintf (buf, "%llX", (unsigned long long) d); + printf ("%*s+%s", LXW - (int) strlen (buf), "", buf); + } +} + +static void mpn_print (mp_ptr p, mp_size_t size) { mp_size_t i; |