1/* Test BSWAP_LIMB.
2
3Copyright 2002 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library.
6
7The GNU MP Library is free software; you can redistribute it and/or modify
8it under the terms of the GNU Lesser General Public License as published by
9the Free Software Foundation; either version 3 of the License, or (at your
10option) any later version.
11
12The GNU MP Library is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15License for more details.
16
17You should have received a copy of the GNU Lesser General Public License
18along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
19
20#include <stdio.h>
21#include <stdlib.h>
22
23#include "gmp.h"
24#include "gmp-impl.h"
25#include "tests.h"
26
27
28int
29main (void)
30{
31  mp_limb_t  src, want, got;
32  int        i;
33
34  tests_start ();
35  mp_trace_base = -16;
36
37  for (i = 0; i < 1000; i++)
38    {
39      mpn_random (&src, (mp_size_t) 1);
40
41      want = ref_bswap_limb (src);
42
43      BSWAP_LIMB (got, src);
44      if (got != want)
45        {
46          printf ("BSWAP_LIMB wrong result\n");
47        error:
48          mpn_trace ("  src ", &src,  (mp_size_t) 1);
49          mpn_trace ("  want", &want, (mp_size_t) 1);
50          mpn_trace ("  got ", &got,  (mp_size_t) 1);
51          abort ();
52        }
53
54      BSWAP_LIMB_FETCH (got, &src);
55      if (got != want)
56        {
57          printf ("BSWAP_LIMB_FETCH wrong result\n");
58          goto error;
59        }
60
61      BSWAP_LIMB_STORE (&got, src);
62      if (got != want)
63        {
64          printf ("BSWAP_LIMB_STORE wrong result\n");
65          goto error;
66        }
67    }
68
69  tests_end ();
70  exit (0);
71}
72