Import gmp-4.3.1
[dragonfly.git] / contrib / gmp / mpn / generic / dump.c
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
6 Copyright 1996, 2000, 2001, 2002, 2005 Free Software Foundation, Inc.
7
8 This file is part of the GNU MP Library.
9
10 The GNU MP Library is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
14
15 The GNU MP Library is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
18 License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
22
23 #include <stdio.h>
24 #include "gmp.h"
25 #include "gmp-impl.h"
26
27 #if GMP_NUMB_BITS % 4 == 0
28 void
29 mpn_dump (mp_srcptr ptr, mp_size_t n)
30 {
31   MPN_NORMALIZE (ptr, n);
32
33   if (n == 0)
34     printf ("0\n");
35   else
36     {
37       n--;
38 #if _LONG_LONG_LIMB
39       if ((ptr[n] >> GMP_LIMB_BITS / 2) != 0)
40         {
41           printf ("%lX", (unsigned long) (ptr[n] >> GMP_LIMB_BITS / 2));
42           printf ("%0*lX", (GMP_LIMB_BITS / 2 / 4), (unsigned long) ptr[n]);
43         }
44       else
45 #endif
46         printf ("%lX", (unsigned long) ptr[n]);
47
48       while (n)
49         {
50           n--;
51 #if _LONG_LONG_LIMB
52           printf ("%0*lX", (GMP_NUMB_BITS - GMP_LIMB_BITS / 2) / 4,
53                   (unsigned long) (ptr[n] >> GMP_LIMB_BITS / 2));
54           printf ("%0*lX", GMP_LIMB_BITS / 2 / 4, (unsigned long) ptr[n]);
55 #else
56           printf ("%0*lX", GMP_NUMB_BITS / 4, (unsigned long) ptr[n]);
57 #endif
58         }
59       printf ("\n");
60     }
61 }
62
63 #else
64
65 static void
66 mpn_recdump (mp_ptr p, mp_size_t n)
67 {
68   mp_limb_t lo;
69   if (n != 0)
70     {
71       lo = p[0] & 0xf;
72       mpn_rshift (p, p, n, 4);
73       mpn_recdump (p, n);
74       printf ("%lX", lo);
75     }
76 }
77
78 void
79 mpn_dump (mp_srcptr p, mp_size_t n)
80 {
81   mp_ptr tp;
82   TMP_DECL;
83   TMP_MARK;
84   tp = TMP_ALLOC_LIMBS (n);
85   MPN_COPY (tp, p, n);
86   TMP_FREE;
87 }
88
89 #endif