dump.c revision 1.1.1.2
1/* THIS IS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE.  IT IS NOT SAFE TO
2   CALL THIS FUNCTION DIRECTLY.  IN FACT, IT IS ALMOST GUARANTEED THAT THIS
3   FUNCTION WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
4
5
6Copyright 1996, 2000-2002, 2005 Free Software Foundation, Inc.
7
8This file is part of the GNU MP Library.
9
10The GNU MP Library is free software; you can redistribute it and/or modify
11it under the terms of either:
12
13  * the GNU Lesser General Public License as published by the Free
14    Software Foundation; either version 3 of the License, or (at your
15    option) any later version.
16
17or
18
19  * the GNU General Public License as published by the Free Software
20    Foundation; either version 2 of the License, or (at your option) any
21    later version.
22
23or both in parallel, as here.
24
25The GNU MP Library is distributed in the hope that it will be useful, but
26WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
27or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
28for more details.
29
30You should have received copies of the GNU General Public License and the
31GNU Lesser General Public License along with the GNU MP Library.  If not,
32see https://www.gnu.org/licenses/.  */
33
34#include <stdio.h>
35#include "gmp.h"
36#include "gmp-impl.h"
37
38#if GMP_NUMB_BITS % 4 == 0
39void
40mpn_dump (mp_srcptr ptr, mp_size_t n)
41{
42  MPN_NORMALIZE (ptr, n);
43
44  if (n == 0)
45    printf ("0\n");
46  else
47    {
48      n--;
49#if _LONG_LONG_LIMB
50      if ((ptr[n] >> GMP_LIMB_BITS / 2) != 0)
51	{
52	  printf ("%lX", (unsigned long) (ptr[n] >> GMP_LIMB_BITS / 2));
53	  printf ("%0*lX", (GMP_LIMB_BITS / 2 / 4), (unsigned long) ptr[n]);
54	}
55      else
56#endif
57	printf ("%lX", (unsigned long) ptr[n]);
58
59      while (n)
60	{
61	  n--;
62#if _LONG_LONG_LIMB
63	  printf ("%0*lX", (GMP_NUMB_BITS - GMP_LIMB_BITS / 2) / 4,
64		  (unsigned long) (ptr[n] >> GMP_LIMB_BITS / 2));
65	  printf ("%0*lX", GMP_LIMB_BITS / 2 / 4, (unsigned long) ptr[n]);
66#else
67	  printf ("%0*lX", GMP_NUMB_BITS / 4, (unsigned long) ptr[n]);
68#endif
69	}
70      printf ("\n");
71    }
72}
73
74#else
75
76static void
77mpn_recdump (mp_ptr p, mp_size_t n)
78{
79  mp_limb_t lo;
80  if (n != 0)
81    {
82      lo = p[0] & 0xf;
83      mpn_rshift (p, p, n, 4);
84      mpn_recdump (p, n);
85      printf ("%lX", lo);
86    }
87}
88
89void
90mpn_dump (mp_srcptr p, mp_size_t n)
91{
92  mp_ptr tp;
93  TMP_DECL;
94  TMP_MARK;
95  tp = TMP_ALLOC_LIMBS (n);
96  MPN_COPY (tp, p, n);
97  TMP_FREE;
98}
99
100#endif
101