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 modify
8 dnl it under the terms of
either:
10 dnl
* the GNU Lesser General
Public License as published by the Free
11 dnl Software Foundation
; either version 3 of the License, or (at your
12 dnl option
) any later version.
16 dnl
* the GNU General
Public License as published by the Free Software
17 dnl Foundation
; either version 2 of the License, or (at your option) any
20 dnl
or both
in parallel
, as here.
22 dnl The GNU MP Library is distributed
in the hope that it will be useful
, but
23 dnl WITHOUT ANY WARRANTY
; without even the implied warranty of MERCHANTABILITY
24 dnl
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License
27 dnl You should have received copies of the GNU General
Public License
and the
28 dnl GNU Lesser General
Public License along with the GNU MP Library. If
not,
29 dnl see
https://www.gnu.
org/licenses
/.
31 include(`..
/config.m4
')
34 C ev67: 1.5 cycles/limb
37 C unsigned long mpn_popcount (mp_srcptr src, mp_size_t size);
39 C This schedule seems necessary for the full 1.5 c/l, the IQ can't quite hide
40 C all latencies
, the addq
's must be deferred to the next iteration.
42 C Since we need just 3 instructions per limb, further unrolling could approach
45 C The main loop processes two limbs at a time. An odd size is handled by
46 C processing src[0] at the start. If the size is even that result is
47 C discarded, and src[0] is repeated by the main loop.
51 PROLOGUE(mpn_popcount)
56 ldq r0, 0(r16) C L0 src[0]
57 and r17, 1, r8 C U1 1 if size odd
58 srl r17, 1, r17 C U0 size, limb pairs
60 s8addq r8, r16, r16 C L1 src++ if size odd
62 beq r17, L(one) C U1 if size==1
64 cmoveq r8, r31, r0 C L discard first limb if size even
75 C r0 total accumulating
78 C r16 src, incrementing
79 C r17 size, decrementing
91 ldl r31, 512(r16) C L prefetch
98 ret r31, (r26), 1 C L0