1
dnl Intel Pentium 4 mpn_popcount, mpn_hamdist -- population count and
4
dnl P4: popcount 8.5 cycles/limb
5
dnl hamdist 9.5 cycles/limb
7
dnl Copyright 2000, 2001 Free Software Foundation, Inc.
9
dnl This file is part of the GNU MP Library.
11
dnl The GNU MP Library is free software; you can redistribute it and/or
12
dnl modify it under the terms of the GNU Lesser General Public License as
13
dnl published by the Free Software Foundation; either version 2.1 of the
14
dnl License, or (at your option) any later version.
16
dnl The GNU MP Library is distributed in the hope that it will be useful,
17
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
18
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
dnl Lesser General Public License for more details.
21
dnl You should have received a copy of the GNU Lesser General Public
22
dnl License along with the GNU MP Library; see the file COPYING.LIB. If
23
dnl not, write to the Free Software Foundation, Inc., 59 Temple Place -
24
dnl Suite 330, Boston, MA 02111-1307, USA.
26
include(`../config.m4')
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 Loading with unaligned movq's costs an extra 1 c/l and hence is avoided.
33
C Two movd's and a punpckldq seems to be the same speed as an aligned movq,
34
C and using them saves fiddling about with alignment testing on entry.
36
C For popcount there's 13 mmx instructions in the loop, so perhaps 6.5 c/l
37
C might be possible, but 8.5 c/l relying on out-of-order execution is
38
C already quite reasonable.
40
ifdef(`OPERATION_popcount',,
41
`ifdef(`OPERATION_hamdist',,
42
`m4_error(`Need OPERATION_popcount or OPERATION_hamdist defined
47
`ifdef(`OPERATION_hamdist',`$1')')
51
`ifdef(`OPERATION_popcount',`$1')')
54
defframe(PARAM_SIZE, 12)
55
defframe(PARAM_SRC2, 8)
56
defframe(PARAM_SRC, 4)
57
define(M4_function,mpn_hamdist)
60
defframe(PARAM_SIZE, 8)
61
defframe(PARAM_SRC, 4)
62
define(M4_function,mpn_popcount)
65
MULFUNC_PROLOGUE(mpn_popcount mpn_hamdist)
72
LF(M4_function,rodata_AAAAAAAAAAAAAAAA):
75
LF(M4_function,rodata_3333333333333333):
78
LF(M4_function,rodata_0F0F0F0F0F0F0F0F):
93
movl $0xAAAAAAAA, %edx
97
movl $0x33333333, %edx
101
movl $0x0F0F0F0F, %edx
105
HAM(` movl PARAM_SRC2, %edx')
109
HAM(` movl PARAM_SRC2, %edx')
110
movq L(rodata_AAAAAAAAAAAAAAAA), %mm7
111
movq L(rodata_3333333333333333), %mm6
112
movq L(rodata_0F0F0F0F0F0F0F0F), %mm5
115
pxor %mm4, %mm4 C zero
116
pxor %mm0, %mm0 C total
122
movd (%eax,%ecx,4), %mm1 C src high limb
123
HAM(` movd (%edx,%ecx,4), %mm2
132
C ecx counter, size-1 to 2 or 1, inclusive
135
C mm0 total (low dword)
139
C mm4 0x0000000000000000
140
C mm5 0x0F0F0F0F0F0F0F0F
141
C mm6 0x3333333333333333
142
C mm7 0xAAAAAAAAAAAAAAAA
149
HAM(` movd (%edx), %mm2
160
psubd %mm2, %mm1 C bit pairs
166
paddd %mm2, %mm1 C nibbles
172
paddd %mm2, %mm1 C bytes
175
paddd %mm1, %mm0 C to total
180
C ecx is 0 or -1 representing respectively 1 or 0 further limbs