1
dnl Intel P5 mpn_hamdist -- mpn hamming distance.
3
dnl P5: 14.0 cycles/limb
5
dnl Copyright 2001 Free Software Foundation, Inc.
7
dnl This file is part of the GNU MP Library.
9
dnl The GNU MP Library is free software; you can redistribute it and/or
10
dnl modify it under the terms of the GNU Lesser General Public License as
11
dnl published by the Free Software Foundation; either version 2.1 of the
12
dnl License, or (at your option) any later version.
14
dnl The GNU MP Library is distributed in the hope that it will be useful,
15
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
16
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
dnl Lesser General Public License for more details.
19
dnl You should have received a copy of the GNU Lesser General Public
20
dnl License along with the GNU MP Library; see the file COPYING.LIB. If
21
dnl not, write to the Free Software Foundation, Inc., 59 Temple Place -
22
dnl Suite 330, Boston, MA 02111-1307, USA.
24
include(`../config.m4')
27
C unsigned long mpn_hamdist (mp_srcptr src1, mp_srcptr src2, mp_size_t size);
29
C It might be possible to shave 1 cycle from the loop, and hence 2
30
C cycles/limb. The xorb is taking 2 cycles, but a separate load and xor
31
C would be 1, if the right schedule could be found (not found so far).
32
C Wanting to avoid potential cache bank clashes makes it tricky.
34
C The slightly strange quoting here helps the renaming done by tune/many.pl.
36
m4_assert_defined(`GSYM_PREFIX')
37
GSYM_PREFIX`'mpn_popcount``'_table')
39
defframe(PARAM_SIZE,12)
40
defframe(PARAM_SRC2, 8)
41
defframe(PARAM_SRC1, 4)
50
pushl %esi FRAME_pushl()
52
shll %ecx C size in byte pairs
53
pushl %edi FRAME_pushl()
56
pushl %ebx FRAME_pushl()
57
pushl %ebp FRAME_pushl()
59
call L(here) FRAME_pushl()
62
popl %ebp FRAME_popl()
65
addl $_GLOBAL_OFFSET_TABLE_+[.-L(here)], %ebp
67
xorl %ebx, %ebx C byte
68
xorl %edx, %edx C byte
70
movl TABLE_NAME@GOT(%ebp), %ebp
71
xorl %eax, %eax C total
72
define(TABLE,`(%ebp,$1)')
79
xorl %eax, %eax C total
80
pushl %ebx FRAME_pushl()
82
xorl %edx, %edx C byte
83
xorl %ebx, %ebx C byte
85
define(TABLE,`TABLE_NAME($1)')
89
C The nop after the xorb seems necessary. Although a movb might be
90
C expected to go down the V pipe in the second cycle of the xorb, it
91
C doesn't and costs an extra 2 cycles.
95
C ecx counter, 2*size to 2
102
movb -1(%esi,%ecx,2), %bl
105
movb -1(%edi,%ecx,2), %dl
108
movb -2(%esi,%ecx,2), %dl
110
xorb -2(%edi,%ecx,2), %dl
113
movb TABLE(%ebx), %bl
116
movb TABLE(%edx), %dl