xref: /netbsd-src/external/lgpl3/gmp/dist/tests/t-bswap.c (revision 87d689fb734c654d2486f87f7be32f1b53ecdbec)
1 /* Test BSWAP_LIMB.
2 
3 Copyright 2002 Free Software Foundation, Inc.
4 
5 This file is part of the GNU MP Library test suite.
6 
7 The GNU MP Library test suite is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 3 of the License,
10 or (at your option) any later version.
11 
12 The GNU MP Library test suite is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
15 Public License for more details.
16 
17 You should have received a copy of the GNU General Public License along with
18 the GNU MP Library test suite.  If not, see https://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 
28 int
29 main (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