3 Copyright (C) 1994, 1996 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 Library General Public License as published by
9 the Free Software Foundation; either version 2 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 Library General Public
15 License for more details.
17 You should have received a copy of the GNU Library 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 #if defined __sparc_v9__ && BITS_PER_MP_LIMB == 64
27 #define popc_limb(a) \
30 asm ("popc %1,%0" : "=r" (__res) : "rI" (a)); \
38 /* Cool population count of a mp_limb_t.
39 You have to figure out how this works, I won't tell you! */
41 static inline unsigned int
45 #if BITS_PER_MP_LIMB == 64
46 /* We have to go into some trouble to define these constants.
47 (For mp_limb_t being `long long'.) */
49 cnst = 0x55555555L | ((mp_limb_t) 0x55555555L << BITS_PER_MP_LIMB/2);
50 x = ((x & ~cnst) >> 1) + (x & cnst);
51 cnst = 0x33333333L | ((mp_limb_t) 0x33333333L << BITS_PER_MP_LIMB/2);
52 x = ((x & ~cnst) >> 2) + (x & cnst);
53 cnst = 0x0f0f0f0fL | ((mp_limb_t) 0x0f0f0f0fL << BITS_PER_MP_LIMB/2);
54 x = ((x >> 4) + x) & cnst;
57 x = ((x >> 32) + x) & 0xff;
59 #if BITS_PER_MP_LIMB == 32
60 x = ((x >> 1) & 0x55555555L) + (x & 0x55555555L);
61 x = ((x >> 2) & 0x33333333L) + (x & 0x33333333L);
62 x = ((x >> 4) + x) & 0x0f0f0f0fL;
64 x = ((x >> 16) + x) & 0xff;
72 mpn_hamdist (mp_srcptr up, mp_srcptr vp, mp_size_t size)
74 mpn_hamdist (up, vp, size)
75 register mp_srcptr up;
76 register mp_srcptr vp;
77 register mp_size_t size;
80 unsigned long int hamdist;
84 for (i = 0; i < size; i++)
85 hamdist += popc_limb (up[i] ^ vp[i]);