1 dnl AMD64 mpn_popcount
-- population count.
3 dnl Copyright
2008, 2010-2012 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 modify
8 dnl it under the terms of
either:
10 dnl
* the GNU Lesser General
Public License as published by the Free
11 dnl Software Foundation
; either version 3 of the License, or (at your
12 dnl option
) any later version.
16 dnl
* the GNU General
Public License as published by the Free Software
17 dnl Foundation
; either version 2 of the License, or (at your option) any
20 dnl
or both
in parallel
, as here.
22 dnl The GNU MP Library is distributed
in the hope that it will be useful
, but
23 dnl WITHOUT ANY WARRANTY
; without even the implied warranty of MERCHANTABILITY
24 dnl
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License
27 dnl You should have received copies of the GNU General
Public License
and the
28 dnl GNU Lesser General
Public License along with the GNU MP Library. If
not,
29 dnl see
https://www.gnu.
org/licenses
/.
31 include(`..
/config.m4
')
42 C * The zero-offset of popcount is misassembled to the offset-less form, which
43 C is one byte shorter and therefore will mess up the switching code.
44 C * The outdated gas used in FreeBSD and NetBSD cannot handle the POPCNT insn,
45 C which is the main reason for our usage of '.
byte'.
48 C * Improve switching code, the current code sucks.
59 PROLOGUE(mpn_popcount)
65 C mov R32(n), R32(%rcx)
67 imul $-1, R32(n), R32(%rcx)
72 mov R32(%rcx), R32(%rax)
76 xor R32(%rax), R32(%rax)
78 lea (%rcx,%rcx,4), %rcx
80 lea L(top)(%rip), %rdx
81 lea (%rdx,%rcx,2), %rdx
92 mov R32
(%rcx
), R32
(%rax
)
96 xor R32
(%rax
), R32
(%rax
)
98 C
add R32
(%rcx
), R32
(%rcx
) C
2x
99 C
lea (%rcx
,%rcx
,4), %rcx C
10x
102 lea L
(top
)(%rip
), %rdx
110 .byte 0xf3,0x4c,0x0f,0xb8,0x44,0xf7,0x00 C popcnt 0(up,n,8), %r8
113 .byte 0xf3,0x4c,0x0f,0xb8,0x4c,0xf7,0x08 C popcnt 8(up,n,8), %r9
116 .byte 0xf3,0x4c,0x0f,0xb8,0x44,0xf7,0x10 C popcnt 16(up,n,8), %r8
119 .byte 0xf3,0x4c,0x0f,0xb8,0x4c,0xf7,0x18 C popcnt 24(up,n,8), %r9
122 .byte 0xf3,0x4c,0x0f,0xb8,0x44,0xf7,0x20 C popcnt 32(up,n,8), %r8
125 .byte 0xf3,0x4c,0x0f,0xb8,0x4c,0xf7,0x28 C popcnt 40(up,n,8), %r9
128 .byte 0xf3,0x4c,0x0f,0xb8,0x44,0xf7,0x30 C popcnt 48(up,n,8), %r8
131 .byte 0xf3,0x4c,0x0f,0xb8,0x4c,0xf7,0x38 C popcnt 56(up,n,8), %r9