1 dnl Alpha ev67 mpn_popcount -- mpn bit population count.
3 dnl Copyright 2003, 2005 Free Software Foundation, Inc.
5 dnl This file is part of the GNU MP Library.
7 dnl The GNU MP Library is free software; you can redistribute it and/or
8 dnl modify it under the terms of the GNU Lesser General Public License as
9 dnl published by the Free Software Foundation; either version 3 of the
10 dnl License, or (at your option) any later version.
12 dnl The GNU MP Library is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 dnl Lesser General Public License for more details.
17 dnl You should have received a copy of the GNU Lesser General Public License
18 dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
20 include(`../config.m4')
23 C ev67: 1.5 cycles/limb
26 C unsigned long mpn_popcount (mp_srcptr src, mp_size_t size);
28 C This schedule seems necessary for the full 1.5 c/l, the IQ can't quite hide
29 C all latencies, the addq's must be deferred to the next iteration.
31 C Since we need just 3 instructions per limb, further unrolling could approach
34 C The main loop processes two limbs at a time. An odd size is handled by
35 C processing src[0] at the start. If the size is even that result is
36 C discarded, and src[0] is repeated by the main loop.
40 PROLOGUE(mpn_popcount)
45 ldq r0, 0(r16) C L0 src[0]
46 and r17, 1, r8 C U1 1 if size odd
47 srl r17, 1, r17 C U0 size, limb pairs
49 s8addq r8, r16, r16 C L1 src++ if size odd
51 beq r17, L(one) C U1 if size==1
53 cmoveq r8, r31, r0 C L discard first limb if size even
64 C r0 total accumulating
67 C r16 src, incrementing
68 C r17 size, decrementing
80 ldl r31, 512(r16) C L prefetch
87 ret r31, (r26), 1 C L0