3 Copyright (C) 1994, 1996, 2000 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 2.1 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; 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. */
26 /* No processor claiming to be SPARC v9 compliant seem to
27 implement the POPC instruction. Disable pattern for now. */
28 #if 0 && defined __sparc_v9__ && BITS_PER_MP_LIMB == 64
29 #define popc_limb(a) \
32 asm ("popc %1,%0" : "=r" (__res) : "rI" (a)); \
40 /* Cool population count of a mp_limb_t.
41 You have to figure out how this works, I won't tell you! */
43 static inline unsigned int
45 popc_limb (mp_limb_t x)
51 #if BITS_PER_MP_LIMB == 64
52 /* We have to go into some trouble to define these constants.
53 (For mp_limb_t being `long long'.) */
55 cnst = 0xaaaaaaaaL | ((mp_limb_t) 0xaaaaaaaaL << BITS_PER_MP_LIMB/2);
57 cnst = 0x33333333L | ((mp_limb_t) 0x33333333L << BITS_PER_MP_LIMB/2);
58 x = ((x & ~cnst) >> 2) + (x & cnst);
59 cnst = 0x0f0f0f0fL | ((mp_limb_t) 0x0f0f0f0fL << BITS_PER_MP_LIMB/2);
60 x = ((x >> 4) + x) & cnst;
63 x = ((x >> 32) + x) & 0xff;
65 #if BITS_PER_MP_LIMB == 32
66 x -= (x & 0xaaaaaaaa) >> 1;
67 x = ((x >> 2) & 0x33333333L) + (x & 0x33333333L);
68 x = ((x >> 4) + x) & 0x0f0f0f0fL;
70 x = ((x >> 16) + x) & 0xff;
78 mpn_hamdist (mp_srcptr up, mp_srcptr vp, mp_size_t size)
80 mpn_hamdist (up, vp, size)
81 register mp_srcptr up;
82 register mp_srcptr vp;
83 register mp_size_t size;
86 unsigned long int hamdist;
90 for (i = 0; i < size; i++)
91 hamdist += popc_limb (up[i] ^ vp[i]);