1 dnl AMD K6-2 mpn_popcount, mpn_hamdist -- mpn bit population count and
4 dnl Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
6 dnl This file is part of the GNU MP Library.
8 dnl The GNU MP Library is free software; you can redistribute it and/or
9 dnl modify it under the terms of the GNU Lesser General Public License as
10 dnl published by the Free Software Foundation; either version 3 of the
11 dnl License, or (at your option) any later version.
13 dnl The GNU MP Library is distributed in the hope that it will be useful,
14 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
15 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 dnl Lesser General Public License for more details.
18 dnl You should have received a copy of the GNU Lesser General Public License
19 dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
21 include(`../config.m4')
25 C K6-2: 9.0 11.5 cycles/limb
29 C unsigned long mpn_popcount (mp_srcptr src, mp_size_t size);
30 C unsigned long mpn_hamdist (mp_srcptr src, mp_srcptr src2, mp_size_t size);
32 C The code here isn't optimal, but it's already a 2x speedup over the plain
33 C integer mpn/generic/popcount.c,hamdist.c.
36 ifdef(`OPERATION_popcount',,
37 `ifdef(`OPERATION_hamdist',,
38 `m4_error(`Need OPERATION_popcount or OPERATION_hamdist
43 `ifdef(`OPERATION_hamdist',`$1')')
47 `ifdef(`OPERATION_popcount',`$1')')
50 defframe(PARAM_SIZE, 12)
51 defframe(PARAM_SRC2, 8)
52 defframe(PARAM_SRC, 4)
53 define(M4_function,mpn_hamdist)
56 defframe(PARAM_SIZE, 8)
57 defframe(PARAM_SRC, 4)
58 define(M4_function,mpn_popcount)
61 MULFUNC_PROLOGUE(mpn_popcount mpn_hamdist)
70 L(rodata_AAAAAAAAAAAAAAAA):
74 L(rodata_3333333333333333):
78 L(rodata_0F0F0F0F0F0F0F0F):
82 L(rodata_000000FF000000FF):
91 C avoid shrl crossing a 32-byte boundary
100 movl $0xAAAAAAAA, %eax
101 movl $0x33333333, %edx
106 movl $0x0F0F0F0F, %eax
107 movl $0x000000FF, %edx
119 movq L(rodata_AAAAAAAAAAAAAAAA), %mm7
120 movq L(rodata_3333333333333333), %mm6
121 movq L(rodata_0F0F0F0F0F0F0F0F), %mm5
122 movq L(rodata_000000FF000000FF), %mm4
125 define(REG_AAAAAAAAAAAAAAAA, %mm7)
126 define(REG_3333333333333333, %mm6)
127 define(REG_0F0F0F0F0F0F0F0F, %mm5)
128 define(REG_000000FF000000FF, %mm4)
132 HAM(` movl PARAM_SRC2, %edx')
134 pxor %mm2, %mm2 C total
139 Zdisp( movd, 0,(%eax,%ecx,8), %mm1)
142 Zdisp( movd, 0,(%edx,%ecx,8), %mm0)
151 POP(` nop C alignment to avoid crossing 32-byte boundaries')
156 C ecx counter, qwords, decrementing
161 C mm2 total (low dword)
164 C mm5 | special constants
168 movq -8(%eax,%ecx,8), %mm1
169 HAM(` pxor -8(%edx,%ecx,8), %mm1')
173 pand REG_AAAAAAAAAAAAAAAA, %mm1
176 HAM(` nop C code alignment')
178 psubd %mm1, %mm0 C bit pairs
179 HAM(` nop C code alignment')
185 pand REG_3333333333333333, %mm0
186 pand REG_3333333333333333, %mm1
188 paddd %mm1, %mm0 C nibbles
194 pand REG_0F0F0F0F0F0F0F0F, %mm0
195 pand REG_0F0F0F0F0F0F0F0F, %mm1
197 paddd %mm1, %mm0 C bytes
203 paddb %mm1, %mm0 C words
209 paddd %mm1, %mm0 C dwords
211 pand REG_000000FF000000FF, %mm0
213 paddd %mm0, %mm2 C low to total
216 paddd %mm0, %mm2 C high to total