beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / mpn / x86_64 / coreisbr / mul_1.asm
blobded7d899c2350e1c2af1943f53f928f5f5f8bef1
1 dnl X86-64 mpn_mul_1 optimised for Intel Sandy Bridge.
3 dnl Contributed to the GNU project by Torbjörn Granlund.
5 dnl Copyright 2003-2005, 2007, 2008, 2011-2013 Free Software Foundation, Inc.
7 dnl This file is part of the GNU MP Library.
8 dnl
9 dnl The GNU MP Library is free software; you can redistribute it and/or modify
10 dnl it under the terms of either:
11 dnl
12 dnl * the GNU Lesser General Public License as published by the Free
13 dnl Software Foundation; either version 3 of the License, or (at your
14 dnl option) any later version.
15 dnl
16 dnl or
17 dnl
18 dnl * the GNU General Public License as published by the Free Software
19 dnl Foundation; either version 2 of the License, or (at your option) any
20 dnl later version.
21 dnl
22 dnl or both in parallel, as here.
23 dnl
24 dnl The GNU MP Library is distributed in the hope that it will be useful, but
25 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
26 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 dnl for more details.
28 dnl
29 dnl You should have received copies of the GNU General Public License and the
30 dnl GNU Lesser General Public License along with the GNU MP Library. If not,
31 dnl see https://www.gnu.org/licenses/.
33 include(`../config.m4')
35 C cycles/limb
36 C AMD K8,K9
37 C AMD K10
38 C AMD bd1
39 C AMD bobcat
40 C Intel P4
41 C Intel core2
42 C Intel NHM
43 C Intel SBR 2.5
44 C Intel IBR 2.4
45 C Intel atom
46 C VIA nano
48 C The loop of this code is the result of running a code generation and
49 C optimisation tool suite written by David Harvey and Torbjorn Granlund.
51 C TODO
52 C * The loop is great, but the prologue code was quickly written. Tune it!
53 C * Add mul_1c entry point.
54 C * We could preserve one less register under DOS64 calling conventions, using
55 C r10 instead of rsi.
57 define(`rp', `%rdi') C rcx
58 define(`up', `%rsi') C rdx
59 define(`n_param', `%rdx') C r8
60 define(`v0', `%rcx') C r9
62 define(`n', `%r11')
64 ABI_SUPPORT(DOS64)
65 ABI_SUPPORT(STD64)
67 IFDOS(` define(`up', ``%rsi'')') dnl
68 IFDOS(` define(`rp', ``%rcx'')') dnl
69 IFDOS(` define(`v0', ``%r9'')') dnl
70 IFDOS(` define(`r9', ``rdi'')') dnl
71 IFDOS(` define(`n_param',``%r8'')') dnl
72 IFDOS(` define(`n', ``%r8'')') dnl
73 IFDOS(` define(`r8', ``r11'')') dnl
75 ASM_START()
76 TEXT
77 ALIGN(16)
78 PROLOGUE(mpn_mul_1)
80 IFDOS(``push %rsi '')
81 IFDOS(``push %rdi '')
82 IFDOS(``mov %rdx, %rsi '')
84 mov (up), %rax
85 mov R32(`n_param'), R32(%r10)
86 IFSTD(` mov n_param, n ')
88 lea (up,n_param,8), up
89 lea -8(rp,n_param,8), rp
90 neg n
91 mul v0
92 and $3, R32(%r10)
93 jz L(b0)
94 cmp $2, R32(%r10)
95 jb L(b1)
96 jz L(b2)
98 L(b3): add $-1, n
99 mov %rax, %r9
100 mov %rdx, %r8
101 mov 16(up,n,8), %rax
102 jmp L(L3)
104 L(b1): mov %rax, %r9
105 mov %rdx, %r8
106 add $1, n
107 jnc L(L1)
108 mov %rax, (rp)
109 mov %rdx, %rax
110 IFDOS(``pop %rdi '')
111 IFDOS(``pop %rsi '')
114 L(b2): add $-2, n
115 mov %rax, %r8
116 mov %rdx, %r9
117 mov 24(up,n,8), %rax
118 jmp L(L2)
120 L(b0): mov %rax, %r8
121 mov %rdx, %r9
122 mov 8(up,n,8), %rax
123 jmp L(L0)
125 ALIGN(8)
126 L(top): mov %rdx, %r8
127 add %rax, %r9
128 L(L1): mov 0(up,n,8), %rax
129 adc $0, %r8
130 mul v0
131 add %rax, %r8
132 mov %r9, 0(rp,n,8)
133 mov 8(up,n,8), %rax
134 mov %rdx, %r9
135 adc $0, %r9
136 L(L0): mul v0
137 mov %r8, 8(rp,n,8)
138 add %rax, %r9
139 mov %rdx, %r8
140 mov 16(up,n,8), %rax
141 adc $0, %r8
142 L(L3): mul v0
143 mov %r9, 16(rp,n,8)
144 mov %rdx, %r9
145 add %rax, %r8
146 mov 24(up,n,8), %rax
147 adc $0, %r9
148 L(L2): mul v0
149 mov %r8, 24(rp,n,8)
150 add $4, n
151 jnc L(top)
153 L(end): add %rax, %r9
154 mov %rdx, %rax
155 adc $0, %rax
156 mov %r9, (rp)
158 IFDOS(``pop %rdi '')
159 IFDOS(``pop %rsi '')
161 EPILOGUE()