1 dnl Intel P5 mpn_popcount -- mpn bit population count.
3 dnl Copyright 2001, 2002 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
8 dnl modify it under the terms of the GNU Lesser General Public License as
9 dnl published by the Free Software Foundation; either version 3 of the
10 dnl License, or (at your option) any later version.
12 dnl The GNU MP Library is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 dnl Lesser General Public 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/.
20 include(`../config.m4')
26 C unsigned long mpn_popcount (mp_srcptr src, mp_size_t size);
28 C An arithmetic approach has been found to be slower than the table lookup,
29 C due to needing too many instructions.
31 C The slightly strange quoting here helps the renaming done by tune/many.pl.
33 m4_assert_defined(`GSYM_PREFIX')
34 GSYM_PREFIX`'mpn_popcount``'_table')
41 ` .byte m4_popcount(i)
44 defframe(PARAM_SIZE,8)
45 defframe(PARAM_SRC, 4)
50 PROLOGUE(mpn_popcount)
54 pushl %esi FRAME_pushl()
57 pushl %ebx FRAME_pushl()
58 pushl %ebp FRAME_pushl()
63 shll %ecx C size in byte pairs
65 addl $_GLOBAL_OFFSET_TABLE_+[.-L(here)], %ebp
68 xorl %eax, %eax C total
69 xorl %ebx, %ebx C byte
71 movl TABLE_NAME@GOT(%ebp), %ebp
72 xorl %edx, %edx C byte
73 define(TABLE,`(%ebp,$1)')
76 shll %ecx C size in byte pairs
79 pushl %ebx FRAME_pushl()
80 xorl %eax, %eax C total
82 xorl %ebx, %ebx C byte
83 xorl %edx, %edx C byte
85 define(TABLE,`TABLE_NAME`'($1)')
89 ALIGN(8) C necessary on P55 for claimed speed
93 C ecx counter, 2*size to 2
100 movb -1(%esi,%ecx,2), %bl
103 movb -2(%esi,%ecx,2), %dl
105 movb TABLE(%ebx), %bl
108 movb TABLE(%edx), %dl