[BACK]Return to t-count_zeros.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / tests

Annotation of OpenXM_contrib/gmp/tests/t-count_zeros.c, Revision 1.1

1.1     ! ohara       1: /* Test count_leading_zeros and count_trailing_zeros.
        !             2:
        !             3: Copyright 2001 Free Software Foundation, Inc.
        !             4:
        !             5: This file is part of the GNU MP Library.
        !             6:
        !             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 2.1 of the License, or (at your
        !            10: option) any later version.
        !            11:
        !            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.
        !            16:
        !            17: You should have received a copy of the GNU Lesser General Public License
        !            18: along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
        !            19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
        !            20: MA 02111-1307, USA. */
        !            21:
        !            22: #include <stdio.h>
        !            23: #include <stdlib.h>
        !            24: #include "gmp.h"
        !            25: #include "gmp-impl.h"
        !            26: #include "longlong.h"
        !            27: #include "tests.h"
        !            28:
        !            29: void
        !            30: check_clz (int want, mp_limb_t n)
        !            31: {
        !            32:   int  got;
        !            33:   count_leading_zeros (got, n);
        !            34:   if (got != want)
        !            35:     {
        !            36:       printf ("count_leading_zeros wrong\n");
        !            37:       printf    ("  n    %lX\n", n);
        !            38:       printf    ("  want %d\n", want);
        !            39:       printf    ("  got  %d\n", got);
        !            40:       abort ();
        !            41:     }
        !            42: }
        !            43:
        !            44: void
        !            45: check_ctz (int want, mp_limb_t n)
        !            46: {
        !            47:   int  got;
        !            48:   count_trailing_zeros (got, n);
        !            49:   if (got != want)
        !            50:     {
        !            51:       printf ("count_trailing_zeros wrong\n");
        !            52:       mpn_trace ("  n    ", &n, (mp_size_t) 1);
        !            53:       printf    ("  want %d\n", want);
        !            54:       printf    ("  got  %d\n", got);
        !            55:       abort ();
        !            56:     }
        !            57: }
        !            58:
        !            59: void
        !            60: check_various (void)
        !            61: {
        !            62:   mp_limb_t  n;
        !            63:   int        i;
        !            64:
        !            65: #ifdef COUNT_LEADING_ZEROS_0
        !            66:   check_clz (COUNT_LEADING_ZEROS_0, CNST_LIMB(0));
        !            67: #endif
        !            68:
        !            69:   for (n=1, i=0; i < BITS_PER_MP_LIMB; n<<=1, i++)
        !            70:     {
        !            71:       check_clz (i, CNST_LIMB(1) << (BITS_PER_MP_LIMB-1-i));
        !            72:       check_ctz (i, CNST_LIMB(1) << i);
        !            73:
        !            74:       check_ctz (i, MP_LIMB_T_MAX << i);
        !            75:       check_clz (i, MP_LIMB_T_MAX >> i);
        !            76:     }
        !            77: }
        !            78:
        !            79:
        !            80: int
        !            81: main (int argc, char *argv[])
        !            82: {
        !            83:   tests_start ();
        !            84:   mp_trace_base = 16;
        !            85:
        !            86:   check_various ();
        !            87:
        !            88:   tests_end ();
        !            89:   exit (0);
        !            90: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>