beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / mpn / x86_64 / coreisbr / popcount.asm
bloba5be33e6a79bc120651d1b757c9090ccfe371bbe
1 dnl AMD64 mpn_popcount -- population count.
3 dnl Copyright 2008, 2010-2013 Free Software Foundation, Inc.
5 dnl This file is part of the GNU MP Library.
6 dnl
7 dnl The GNU MP Library is free software; you can redistribute it and/or modify
8 dnl it under the terms of either:
9 dnl
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.
13 dnl
14 dnl or
15 dnl
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
18 dnl later version.
19 dnl
20 dnl or both in parallel, as here.
21 dnl
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
25 dnl for more details.
26 dnl
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')
33 C cycles/limb
34 C AMD K8,K9 n/a
35 C AMD K10 1.5 slower than 8-way non-pipelined code
36 C AMD bd1 4.2
37 C AMD bobcat 6.28 slower than 8-way non-pipelined code
38 C Intel P4 n/a
39 C Intel core2 n/a
40 C Intel NHM 1.32
41 C Intel SBR 1.05 fluctuating
42 C Intel IBR 1.05 fluctuating
43 C Intel HSW 1
44 C Intel atom n/a
45 C VIA nano n/a
47 define(`up', `%rdi')
48 define(`n_param', `%rsi')
50 define(`n', `%rcx')
52 ABI_SUPPORT(DOS64)
53 ABI_SUPPORT(STD64)
55 ASM_START()
56 TEXT
57 ALIGN(32)
58 PROLOGUE(mpn_popcount)
59 FUNC_ENTRY(2)
61 lea (up,n_param,8), up
62 xor R32(%rax), R32(%rax)
64 test $1, R8(n_param)
65 jnz L(bx1)
67 L(bx0): test $2, R8(n_param)
68 jnz L(b10)
70 L(b00): mov $0, R32(n)
71 sub n_param, n
72 .byte 0xf3,0x4c,0x0f,0xb8,0x04,0xcf C popcnt (up,n,8), %r8
73 .byte 0xf3,0x4c,0x0f,0xb8,0x4c,0xcf,0x08 C popcnt 8(up,n,8), %r9
74 jmp L(lo0)
76 L(b10): mov $2, R32(n)
77 sub n_param, n
78 .byte 0xf3,0x4c,0x0f,0xb8,0x54,0xcf,0xf0 C popcnt -16(up,n,8), %r10
79 .byte 0xf3,0x4c,0x0f,0xb8,0x5c,0xcf,0xf8 C popcnt -8(up,n,8), %r11
80 test n, n
81 jz L(cj2)
82 jmp L(lo2)
84 L(bx1): test $2, R8(n_param)
85 jnz L(b11)
87 L(b01): mov $1, R32(n)
88 sub n_param, n
89 .byte 0xf3,0x4c,0x0f,0xb8,0x5c,0xcf,0xf8 C popcnt -8(up,n,8), %r11
90 test n, n
91 jz L(cj1)
92 .byte 0xf3,0x4c,0x0f,0xb8,0x04,0xcf C popcnt 0(up,n,8), %r8
93 jmp L(lo1)
95 L(b11): mov $-1, n
96 sub n_param, n
97 .byte 0xf3,0x4c,0x0f,0xb8,0x4c,0xcf,0x08 C popcnt 8(up,n,8), %r9
98 .byte 0xf3,0x4c,0x0f,0xb8,0x54,0xcf,0x10 C popcnt 16(up,n,8), %r10
99 jmp L(lo3)
101 ALIGN(32)
102 L(top): add %r9, %rax
103 L(lo2): .byte 0xf3,0x4c,0x0f,0xb8,0x04,0xcf C popcnt 0(up,n,8), %r8
104 add %r10, %rax
105 L(lo1): .byte 0xf3,0x4c,0x0f,0xb8,0x4c,0xcf,0x08 C popcnt 8(up,n,8), %r9
106 add %r11, %rax
107 L(lo0): .byte 0xf3,0x4c,0x0f,0xb8,0x54,0xcf,0x10 C popcnt 16(up,n,8), %r10
108 add %r8, %rax
109 L(lo3): .byte 0xf3,0x4c,0x0f,0xb8,0x5c,0xcf,0x18 C popcnt 24(up,n,8), %r11
110 add $4, n
111 js L(top)
113 L(end): add %r9, %rax
114 L(cj2): add %r10, %rax
115 L(cj1): add %r11, %rax
116 FUNC_EXIT()
118 EPILOGUE()