1 /* Test count_leading_zeros and count_trailing_zeros.
3 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
28 check_clz (int want, mp_limb_t n)
31 count_leading_zeros (got, n);
34 printf ("count_leading_zeros wrong\n");
35 mp_limb_trace (" n ", n);
36 printf (" want %d\n", want);
37 printf (" got %d\n", got);
43 check_ctz (int want, mp_limb_t n)
46 count_trailing_zeros (got, n);
49 printf ("count_trailing_zeros wrong\n");
50 mpn_trace (" n ", &n, (mp_size_t) 1);
51 printf (" want %d\n", want);
52 printf (" got %d\n", got);
62 #ifdef COUNT_LEADING_ZEROS_0
63 check_clz (COUNT_LEADING_ZEROS_0, CNST_LIMB(0));
66 for (i=0; i < GMP_LIMB_BITS; i++)
68 check_clz (i, CNST_LIMB(1) << (GMP_LIMB_BITS-1-i));
69 check_ctz (i, CNST_LIMB(1) << i);
71 check_ctz (i, MP_LIMB_T_MAX << i);
72 check_clz (i, MP_LIMB_T_MAX >> i);
78 main (int argc, char *argv[])