1dnl Intel P5 mpn_popcount -- mpn bit population count. 2 3dnl Copyright 2001, 2002 Free Software Foundation, Inc. 4dnl 5dnl This file is part of the GNU MP Library. 6dnl 7dnl The GNU MP Library is free software; you can redistribute it and/or 8dnl modify it under the terms of the GNU Lesser General Public License as 9dnl published by the Free Software Foundation; either version 3 of the 10dnl License, or (at your option) any later version. 11dnl 12dnl The GNU MP Library is distributed in the hope that it will be useful, 13dnl but WITHOUT ANY WARRANTY; without even the implied warranty of 14dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15dnl Lesser General Public License for more details. 16dnl 17dnl You should have received a copy of the GNU Lesser General Public License 18dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. 19 20include(`../config.m4') 21 22 23C P5: 8.0 cycles/limb 24 25 26C unsigned long mpn_popcount (mp_srcptr src, mp_size_t size); 27C 28C An arithmetic approach has been found to be slower than the table lookup, 29C due to needing too many instructions. 30 31C The slightly strange quoting here helps the renaming done by tune/many.pl. 32deflit(TABLE_NAME, 33m4_assert_defined(`GSYM_PREFIX') 34GSYM_PREFIX`'mpn_popcount``'_table') 35 36 RODATA 37 ALIGN(8) 38 GLOBL TABLE_NAME 39TABLE_NAME: 40forloop(i,0,255, 41` .byte m4_popcount(i) 42') 43 44defframe(PARAM_SIZE,8) 45defframe(PARAM_SRC, 4) 46 47 TEXT 48 ALIGN(8) 49 50PROLOGUE(mpn_popcount) 51deflit(`FRAME',0) 52 53 movl PARAM_SIZE, %ecx 54 pushl %esi FRAME_pushl() 55 56ifdef(`PIC',` 57 pushl %ebx FRAME_pushl() 58 pushl %ebp FRAME_pushl() 59 60 call L(here) 61L(here): 62 popl %ebp 63 shll %ecx C size in byte pairs 64 65 addl $_GLOBAL_OFFSET_TABLE_+[.-L(here)], %ebp 66 movl PARAM_SRC, %esi 67 68 xorl %eax, %eax C total 69 xorl %ebx, %ebx C byte 70 71 movl TABLE_NAME@GOT(%ebp), %ebp 72 xorl %edx, %edx C byte 73define(TABLE,`(%ebp,$1)') 74',` 75dnl non-PIC 76 shll %ecx C size in byte pairs 77 movl PARAM_SRC, %esi 78 79 pushl %ebx FRAME_pushl() 80 xorl %eax, %eax C total 81 82 xorl %ebx, %ebx C byte 83 xorl %edx, %edx C byte 84 85define(TABLE,`TABLE_NAME`'($1)') 86') 87 88 89 ALIGN(8) C necessary on P55 for claimed speed 90L(top): 91 C eax total 92 C ebx byte 93 C ecx counter, 2*size to 2 94 C edx byte 95 C esi src 96 C edi 97 C ebp [PIC] table 98 99 addl %ebx, %eax 100 movb -1(%esi,%ecx,2), %bl 101 102 addl %edx, %eax 103 movb -2(%esi,%ecx,2), %dl 104 105 movb TABLE(%ebx), %bl 106 decl %ecx 107 108 movb TABLE(%edx), %dl 109 jnz L(top) 110 111 112ifdef(`PIC',` 113 popl %ebp 114') 115 addl %ebx, %eax 116 popl %ebx 117 118 addl %edx, %eax 119 popl %esi 120 121 ret 122 123EPILOGUE() 124