dnl This file is part of the GNU MP Library.
dnl
dnl The GNU MP Library is free software; you can redistribute it and/or modify
dnl it under the terms of either:
dnl
dnl * the GNU Lesser General Public License as published by the Free
dnl Software Foundation; either version 3 of the License, or (at your
dnl option) any later version.
dnl
dnl or
dnl
dnl * the GNU General Public License as published by the Free Software
dnl Foundation; either version 2 of the License, or (at your option) any
dnl later version.
dnl
dnl or both in parallel, as here.
dnl
dnl The GNU MP Library is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
dnl for more details.
dnl
dnl You should have received copies of the GNU General Public License and the
dnl GNU Lesser General Public License along with the GNU MP Library. If not,
dnl see https://www.gnu.org/licenses/.
include(`../config.m4')
C 32-bit popcount hamdist
C cycles/limb cycles/limb
C P5 -
C P6 model0-8,10-12 -
C P6 model9 (Banias) ?
C P6 model13 (Dothan) 4
C P4 model0 (Willamette) ?
C P4 model1 (?) ?
C P4 model2 (Northwood) 3.9
C P4 model3 (Prescott) ?
C P4 model4 (Nocona) ?
C AMD K6 -
C AMD K7 -
C AMD K8 ?
C 64-bit popcount hamdist
C cycles/limb cycles/limb
C P4 model4 (Nocona): 8
C AMD K8,K9 7.5
C AMD K10 3.5
C Intel core2 3.68
C Intel corei 3.15
C Intel atom 10.8
C VIA nano 6.5
C TODO
C * Make an mpn_hamdist based on this. Alignment could either be handled by
C using movdqu for one operand and movdqa for the other, or by painfully
C shifting as we go. Unfortunately, there seem to be no usable shift
C instruction, except for one that takes an immediate count.
C * It would probably be possible to cut a few cycles/limb using software
C pipelining.
C * There are 35 decode slots unused by the SSE2 instructions. Loop control
C needs just 2or3 slots, leaving around 32 slots. This allows a parallel
C integer based popcount. Such a combined loop would handle 6 limbs in
C about 30 cycles on K8.
C * We could save a byteor two by using 32-bit operations on areg.
C * Check if using movdqa to a temp of and then register-based pand is faster.
undefine(`psadbw') C override inherited m4 version
C This file is shared between 32-bit and64-bit builds. Only the former has
C LEAL. Default LEAL as an alias of LEA. ifdef(`LEAL',,`define(`LEAL', `LEA($1,$2)')')
ASM_START()
C Make cnsts global to work around Apple relocation bug. ifdef(`DARWIN',`
define(`cnsts', MPN(popccnsts))
GLOBL cnsts')
TEXT ALIGN(32)
PROLOGUE(mpn_popcount)
LIMB32(`mov4(%esp), up ')
LIMB32(`mov8(%esp), n ')
LIMB32(`push %ebx ')
pxor %xmm3, %xmm3 C zero grand total count
LIMB64(`pxor zero, zero')
mov up, areg and $-16, up C round `up' down to 128-bit boundary and $12, areg C 32:areg = 0, 4, 8, 12
C 64:areg = 0, 8
movdqa (up), %xmm0
pand 64(breg,areg,4), %xmm0 shr $m4_log2(GMP_LIMB_BYTES), %eax add areg, n C compensate n for rounded down `up'
pxor %xmm4, %xmm4 sub $LIMBS_PER_XMM, n
jbe L(sum)
psadbw zero, %xmm1
paddq %xmm1, %xmm3 C add to grand total
C Add the two 64-bit halves of the grand total counter
L(rt): movdqa %xmm3, %xmm0
psrldq $8, %xmm3
paddq %xmm3, %xmm0 movd %xmm0, areg C movq avoided due to gas bug
LIMB32(`pop %ebx ') ret
EPILOGUE()
DEF_OBJECT(dummy,16)
C Three magic constants used for masking out bits
.byte0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
.byte0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
.byte0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f
.byte0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f
cnsts:
C Masks for high end of number
.byte0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
.byte0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
.byte0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
.byte0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00
C Masks for low end of number
.byte0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
.byte0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.