Upload Tizen:Base source
[external/gmp.git] / mpn / x86_64 / mul_1.asm
1 dnl  AMD64 mpn_mul_1.
2
3 dnl  Copyright 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
4
5 dnl  This file is part of the GNU MP Library.
6
7 dnl  The GNU MP Library is free software; you can redistribute it and/or modify
8 dnl  it under the terms of the GNU Lesser General Public License as published
9 dnl  by the Free Software Foundation; either version 3 of the License, or (at
10 dnl  your option) any later version.
11
12 dnl  The GNU MP Library is distributed in the hope that it will be useful, but
13 dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 dnl  License for more details.
16
17 dnl  You should have received a copy of the GNU Lesser General Public License
18 dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
19
20 include(`../config.m4')
21
22 C            cycles/limb
23 C K8,K9:         2.5
24 C K10:           2.5
25 C P4:            12.3
26 C P6 core2:      4.0
27 C P6 corei7:     3.8
28 C Atom:         19.8
29
30 C The inner loop of this code is the result of running a code generation and
31 C optimization tool suite written by David Harvey and Torbjorn Granlund.
32
33 C TODO:
34 C  * The inner loop is great, but the prologue and epilogue code was
35 C    quickly written.  Tune it!
36
37 C INPUT PARAMETERS
38 define(`rp',     `%rdi')
39 define(`up',     `%rsi')
40 define(`n_param',`%rdx')
41 define(`vl',     `%rcx')
42
43 define(`n',     `%r11')
44
45 ASM_START()
46         TEXT
47         ALIGN(16)
48 PROLOGUE(mpn_mul_1c)
49         push    %rbx
50         mov     %r8, %r10
51         jmp     L(common)
52 EPILOGUE()
53
54 PROLOGUE(mpn_mul_1)
55         push    %rbx
56         xor     %r10, %r10
57 L(common):
58         mov     (up), %rax              C read first u limb early
59         mov     n_param, %rbx           C move away n from rdx, mul uses it
60         mul     vl
61         mov     %rbx, %r11
62
63         add     %r10, %rax
64         adc     $0, %rdx
65
66         and     $3, R32(%rbx)
67         jz      L(b0)
68         cmp     $2, R32(%rbx)
69         jz      L(b2)
70         jg      L(b3)
71
72 L(b1):  dec     n
73         jne     L(gt1)
74         mov     %rax, (rp)
75         jmp     L(ret)
76 L(gt1): lea     8(up,n,8), up
77         lea     -8(rp,n,8), rp
78         neg     n
79         xor     %r10, %r10
80         xor     R32(%rbx), R32(%rbx)
81         mov     %rax, %r9
82         mov     (up,n,8), %rax
83         mov     %rdx, %r8
84         jmp     L(L1)
85
86 L(b0):  lea     (up,n,8), up
87         lea     -16(rp,n,8), rp
88         neg     n
89         xor     %r10, %r10
90         mov     %rax, %r8
91         mov     %rdx, %rbx
92         jmp      L(L0)
93
94 L(b3):  lea     -8(up,n,8), up
95         lea     -24(rp,n,8), rp
96         neg     n
97         mov     %rax, %rbx
98         mov     %rdx, %r10
99         jmp     L(L3)
100
101 L(b2):  lea     -16(up,n,8), up
102         lea     -32(rp,n,8), rp
103         neg     n
104         xor     %r8, %r8
105         xor     R32(%rbx), R32(%rbx)
106         mov     %rax, %r10
107         mov     24(up,n,8), %rax
108         mov     %rdx, %r9
109         jmp     L(L2)
110
111         ALIGN(16)
112 L(top): mov     %r10, (rp,n,8)
113         add     %rax, %r9
114         mov     (up,n,8), %rax
115         adc     %rdx, %r8
116         mov     $0, %r10d
117 L(L1):  mul     vl
118         mov     %r9, 8(rp,n,8)
119         add     %rax, %r8
120         adc     %rdx, %rbx
121 L(L0):  mov     8(up,n,8), %rax
122         mul     vl
123         mov     %r8, 16(rp,n,8)
124         add     %rax, %rbx
125         adc     %rdx, %r10
126 L(L3):  mov     16(up,n,8), %rax
127         mul     vl
128         mov     %rbx, 24(rp,n,8)
129         mov     $0, %r8d                # zero
130         mov     %r8, %rbx               # zero
131         add     %rax, %r10
132         mov     24(up,n,8), %rax
133         mov     %r8, %r9                # zero
134         adc     %rdx, %r9
135 L(L2):  mul     vl
136         add     $4, n
137         js       L(top)
138
139         mov     %r10, (rp,n,8)
140         add     %rax, %r9
141         adc     %r8, %rdx
142         mov     %r9, 8(rp,n,8)
143         add     %r8, %rdx
144 L(ret): mov     %rdx, %rax
145
146         pop     %rbx
147         ret
148 EPILOGUE()