|
Packit |
5c3484 |
dnl AMD64 mpn_popcount -- population count.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
dnl Copyright 2008, 2010-2012 Free Software Foundation, Inc.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
dnl This file is part of the GNU MP Library.
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl The GNU MP Library is free software; you can redistribute it and/or modify
|
|
Packit |
5c3484 |
dnl it under the terms of either:
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl * the GNU Lesser General Public License as published by the Free
|
|
Packit |
5c3484 |
dnl Software Foundation; either version 3 of the License, or (at your
|
|
Packit |
5c3484 |
dnl option) any later version.
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl or
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl * the GNU General Public License as published by the Free Software
|
|
Packit |
5c3484 |
dnl Foundation; either version 2 of the License, or (at your option) any
|
|
Packit |
5c3484 |
dnl later version.
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl or both in parallel, as here.
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl The GNU MP Library is distributed in the hope that it will be useful, but
|
|
Packit |
5c3484 |
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
Packit |
5c3484 |
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
Packit |
5c3484 |
dnl for more details.
|
|
Packit |
5c3484 |
dnl
|
|
Packit |
5c3484 |
dnl You should have received copies of the GNU General Public License and the
|
|
Packit |
5c3484 |
dnl GNU Lesser General Public License along with the GNU MP Library. If not,
|
|
Packit |
5c3484 |
dnl see https://www.gnu.org/licenses/.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
include(`../config.m4')
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
C cycles/limb
|
|
Packit |
5c3484 |
C AMD K8,K9 n/a
|
|
Packit |
5c3484 |
C AMD K10 1.125
|
|
Packit |
5c3484 |
C Intel P4 n/a
|
|
Packit |
5c3484 |
C Intel core2 n/a
|
|
Packit |
5c3484 |
C Intel corei 1.25
|
|
Packit |
5c3484 |
C Intel atom n/a
|
|
Packit |
5c3484 |
C VIA nano n/a
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
C * The zero-offset of popcount is misassembled to the offset-less form, which
|
|
Packit |
5c3484 |
C is one byte shorter and therefore will mess up the switching code.
|
|
Packit |
5c3484 |
C * The outdated gas used in FreeBSD and NetBSD cannot handle the POPCNT insn,
|
|
Packit |
5c3484 |
C which is the main reason for our usage of '.byte'.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
C TODO
|
|
Packit |
5c3484 |
C * Improve switching code, the current code sucks.
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
define(`up', `%rdi')
|
|
Packit |
5c3484 |
define(`n', `%rsi')
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ABI_SUPPORT(DOS64)
|
|
Packit |
5c3484 |
ABI_SUPPORT(STD64)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ASM_START()
|
|
Packit |
5c3484 |
TEXT
|
|
Packit |
5c3484 |
ALIGN(32)
|
|
Packit |
5c3484 |
PROLOGUE(mpn_popcount)
|
|
Packit |
5c3484 |
FUNC_ENTRY(2)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ifelse(1,1,`
|
|
Packit |
5c3484 |
lea (up,n,8), up
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
C mov R32(n), R32(%rcx)
|
|
Packit |
5c3484 |
C neg R32(%rcx)
|
|
Packit |
5c3484 |
imul $-1, R32(n), R32(%rcx)
|
|
Packit |
5c3484 |
and $8-1, R32(%rcx)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
neg n
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mov R32(%rcx), R32(%rax)
|
|
Packit |
5c3484 |
neg %rax
|
|
Packit |
5c3484 |
lea (up,%rax,8),up
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
xor R32(%rax), R32(%rax)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
lea (%rcx,%rcx,4), %rcx
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
lea L(top)(%rip), %rdx
|
|
Packit |
5c3484 |
lea (%rdx,%rcx,2), %rdx
|
|
Packit |
5c3484 |
jmp *%rdx
|
|
Packit |
5c3484 |
',`
|
|
Packit |
5c3484 |
lea (up,n,8), up
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mov R32(n), R32(%rcx)
|
|
Packit |
5c3484 |
neg R32(%rcx)
|
|
Packit |
5c3484 |
and $8-1, R32(%rcx)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
neg n
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
mov R32(%rcx), R32(%rax)
|
|
Packit |
5c3484 |
shl $3, R32(%rax)
|
|
Packit |
5c3484 |
sub %rax, up
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
xor R32(%rax), R32(%rax)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
C add R32(%rcx), R32(%rcx) C 2x
|
|
Packit |
5c3484 |
C lea (%rcx,%rcx,4), %rcx C 10x
|
|
Packit |
5c3484 |
imul $10, R32(%rcx)
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
lea L(top)(%rip), %rdx
|
|
Packit |
5c3484 |
add %rcx, %rdx
|
|
Packit |
5c3484 |
jmp *%rdx
|
|
Packit |
5c3484 |
')
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
ALIGN(32)
|
|
Packit |
5c3484 |
L(top):
|
|
Packit |
5c3484 |
C 0 = n mod 8
|
|
Packit |
5c3484 |
.byte 0xf3,0x4c,0x0f,0xb8,0x44,0xf7,0x00 C popcnt 0(up,n,8), %r8
|
|
Packit |
5c3484 |
add %r8, %rax
|
|
Packit |
5c3484 |
C 7 = n mod 8
|
|
Packit |
5c3484 |
.byte 0xf3,0x4c,0x0f,0xb8,0x4c,0xf7,0x08 C popcnt 8(up,n,8), %r9
|
|
Packit |
5c3484 |
add %r9, %rax
|
|
Packit |
5c3484 |
C 6 = n mod 8
|
|
Packit |
5c3484 |
.byte 0xf3,0x4c,0x0f,0xb8,0x44,0xf7,0x10 C popcnt 16(up,n,8), %r8
|
|
Packit |
5c3484 |
add %r8, %rax
|
|
Packit |
5c3484 |
C 5 = n mod 8
|
|
Packit |
5c3484 |
.byte 0xf3,0x4c,0x0f,0xb8,0x4c,0xf7,0x18 C popcnt 24(up,n,8), %r9
|
|
Packit |
5c3484 |
add %r9, %rax
|
|
Packit |
5c3484 |
C 4 = n mod 8
|
|
Packit |
5c3484 |
.byte 0xf3,0x4c,0x0f,0xb8,0x44,0xf7,0x20 C popcnt 32(up,n,8), %r8
|
|
Packit |
5c3484 |
add %r8, %rax
|
|
Packit |
5c3484 |
C 3 = n mod 8
|
|
Packit |
5c3484 |
.byte 0xf3,0x4c,0x0f,0xb8,0x4c,0xf7,0x28 C popcnt 40(up,n,8), %r9
|
|
Packit |
5c3484 |
add %r9, %rax
|
|
Packit |
5c3484 |
C 2 = n mod 8
|
|
Packit |
5c3484 |
.byte 0xf3,0x4c,0x0f,0xb8,0x44,0xf7,0x30 C popcnt 48(up,n,8), %r8
|
|
Packit |
5c3484 |
add %r8, %rax
|
|
Packit |
5c3484 |
C 1 = n mod 8
|
|
Packit |
5c3484 |
.byte 0xf3,0x4c,0x0f,0xb8,0x4c,0xf7,0x38 C popcnt 56(up,n,8), %r9
|
|
Packit |
5c3484 |
add %r9, %rax
|
|
Packit |
5c3484 |
|
|
Packit |
5c3484 |
add $8, n
|
|
Packit |
5c3484 |
js L(top)
|
|
Packit |
5c3484 |
FUNC_EXIT()
|
|
Packit |
5c3484 |
ret
|
|
Packit |
5c3484 |
EPILOGUE()
|
|
rpm-build |
01f633 |
CF_PROT
|