1 dnl AMD64 mpn_popcount, mpn_hamdist -- population count and hamming distance.
3 dnl Copyright 2004, 2005, 2007 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 the GNU Lesser General Public License as published
9 dnl by the Free Software Foundation; either version 3 of the License, or (at
10 dnl your option) any later version.
12 dnl The GNU MP Library is distributed in the hope that it will be useful, but
13 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 dnl 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/.
21 include(`../config.m4')
25 C cycles/limb cycles/limb
32 C * Tune. It should be possible to reach 5 c/l for popcount and 6 c/l for
36 ifdef(`OPERATION_popcount',`
37 define(`func',`mpn_popcount')
40 define(`h55555555', `%r10')
41 define(`h33333333', `%r11')
42 define(`h0f0f0f0f', `%rcx')
43 define(`h01010101', `%rdx')
46 ifdef(`OPERATION_hamdist',`
47 define(`func',`mpn_hamdist')
51 define(`h55555555', `%r10')
52 define(`h33333333', `%r11')
53 define(`h0f0f0f0f', `%rcx')
54 define(`h01010101', `%r14')
59 MULFUNC_PROLOGUE(mpn_popcount mpn_hamdist)
70 movq $0x5555555555555555, h55555555
71 movq $0x3333333333333333, h33333333
72 movq $0x0f0f0f0f0f0f0f0f, h0f0f0f0f
73 movq $0x0101010101010101, h01010101
76 HAM(` leaq (vp,n,8), vp ')
85 HAM(` xorq (vp,n,8), %r8 ')
96 addq %r8, %r9 C 16 4-bit fields (0..4)
102 addq %r8, %r9 C 8 8-bit fields (0..16)
104 imulq h01010101, %r9 C sum the 8 fields in high 8 bits
107 addq %r9, %rax C add to total
112 L(oop): movq (up,n,8), %r8
114 HAM(` xorq (vp,n,8), %r8 ')
115 HAM(` xorq 8(vp,n,8), %r12 ')
134 addq %r8, %r9 C 16 4-bit fields (0..4)
135 addq %r12, %r13 C 16 4-bit fields (0..4)
137 addq %r13, %r9 C 16 4-bit fields (0..8)
142 addq %r8, %r9 C 8 8-bit fields (0..16)
144 imulq h01010101, %r9 C sum the 8 fields in high 8 bits
147 addq %r9, %rax C add to total