1 dnl AMD64 mpn_popcount
, mpn_hamdist
-- population count
and hamming distance.
3 dnl Copyright
2004, 2005, 2007, 2010-2012 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
/.
32 include(`..
/config.m4
')
36 C cycles/limb cycles/limb
42 C Intel atom 16.5 17.5
46 C * Tune. It should be possible to reach 5 c/l for popcount and 6 c/l for
50 ifdef(`OPERATION_popcount',`
51 define
(`func
',`mpn_popcount')
54 define
(`h55555555
', `%r10')
55 define
(`h33333333
', `%r11')
56 define
(`h0f0f0f0f
', `%rcx')
57 define
(`h01010101
', `%rdx')
61 ifdef(`OPERATION_hamdist',`
62 define
(`func
',`mpn_hamdist')
66 define
(`h55555555
', `%r10')
67 define
(`h33333333
', `%r11')
68 define
(`h0f0f0f0f
', `%rcx')
69 define
(`h01010101
', `%r14')
75 MULFUNC_PROLOGUE(mpn_popcount mpn_hamdist)
84 POP(` FUNC_ENTRY(2) ')
85 HAM
(` FUNC_ENTRY
(3) ')
90 mov $0x5555555555555555
, h55555555
91 mov $0x3333333333333333
, h33333333
92 mov $0x0f0f0f0f0f0f0f0f
, h0f0f0f0f
93 mov $0x0101010101010101
, h01010101
96 HAM
(`
lea (vp
,n
,8), vp
')
99 xor R32(%rax), R32(%rax)
105 HAM(` xor (vp,n,8), %r8 ')
116 add %r8
, %r9 C
16 4-bit fields
(0.
.4)
122 add %r8
, %r9 C
8 8-bit fields
(0.
.16)
124 imul h01010101
, %r9 C sum the
8 fields
in high 8 bits
127 mov %r9
, %rax C
add to total
132 L
(top
): mov (up
,n
,8), %r8
134 HAM
(`
xor (vp
,n
,8), %r8
')
135 HAM(` xor 8(vp,n,8), %r12 ')
154 add %r8
, %r9 C
16 4-bit fields
(0.
.4)
155 add %r12
, %r13 C
16 4-bit fields
(0.
.4)
157 add %r13
, %r9 C
16 4-bit fields
(0.
.8)
162 add %r8
, %r9 C
8 8-bit fields
(0.
.16)
164 imul h01010101
, %r9 C sum the
8 fields
in high 8 bits
167 add %r9
, %rax C
add to total