4668585c97137768cbada7c55c0af57f8452f6ce
[platform/upstream/gmp.git] / mpn / arm / aorsmul_1.asm
1 dnl  ARM mpn_addmul_1 and mpn_submul_1.
2
3 dnl  Copyright 1998, 2000, 2001, 2003, 2012 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 StrongARM:     ?
24 C XScale         ?
25 C Cortex-A8      ?
26 C Cortex-A9      5.25
27 C Cortex-A15     4
28
29 define(`rp', `r0')
30 define(`up', `r1')
31 define(`n',  `r2')
32 define(`vl', `r3')
33 define(`rl', `r12')
34 define(`ul', `r6')
35 define(`r',  `lr')
36
37 ifdef(`OPERATION_addmul_1', `
38   define(`ADDSUB',      adds)
39   define(`ADDSUBC',     adcs)
40   define(`CLRRCY',      `mov    $1, #0
41                         adds    r0, r0, #0')
42   define(`RETVAL',      `adc    r0, r4, #0')
43   define(`func',        mpn_addmul_1)')
44 ifdef(`OPERATION_submul_1', `
45   define(`ADDSUB',      subs)
46   define(`ADDSUBC',     sbcs)
47   define(`CLRRCY',      `subs   $1, r0, r0')
48   define(`RETVAL',      `sbc    r0, r0, r0
49                         sub     r0, $1, r0')
50   define(`func',        mpn_submul_1)')
51
52 MULFUNC_PROLOGUE(mpn_addmul_1 mpn_submul_1)
53
54 ASM_START()
55 PROLOGUE(func)
56         stmfd   sp!, { r4-r6, lr }
57         CLRRCY( r4)
58         tst     n, #1
59         beq     L(skip1)
60         ldr     ul, [up], #4
61         ldr     rl, [rp, #0]
62         umull   r5, r4, ul, vl
63         ADDSUB  r, rl, r5
64         str     r, [rp], #4
65 L(skip1):
66         tst     n, #2
67         beq     L(skip2)
68         ldr     ul, [up], #4
69         ldr     rl, [rp, #0]
70         mov     r5, #0
71         umlal   r4, r5, ul, vl
72         ldr     ul, [up], #4
73         ADDSUBC r, rl, r4
74         ldr     rl, [rp, #4]
75         mov     r4, #0
76         umlal   r5, r4, ul, vl
77         str     r, [rp], #4
78         ADDSUBC r, rl, r5
79         str     r, [rp], #4
80 L(skip2):
81         bics    n, n, #3
82         beq     L(rtn)
83
84         ldr     ul, [up], #4
85         ldr     rl, [rp, #0]
86         mov     r5, #0
87         umlal   r4, r5, ul, vl
88         b       L(in)
89
90 L(top): ldr     ul, [up], #4
91         ADDSUBC r, rl, r5
92         ldr     rl, [rp, #4]
93         mov     r5, #0
94         umlal   r4, r5, ul, vl
95         str     r, [rp], #4
96 L(in):  ldr     ul, [up], #4
97         ADDSUBC r, rl, r4
98         ldr     rl, [rp, #4]
99         mov     r4, #0
100         umlal   r5, r4, ul, vl
101         str     r, [rp], #4
102         ldr     ul, [up], #4
103         ADDSUBC r, rl, r5
104         ldr     rl, [rp, #4]
105         mov     r5, #0
106         umlal   r4, r5, ul, vl
107         str     r, [rp], #4
108         ldr     ul, [up], #4
109         ADDSUBC r, rl, r4
110         ldr     rl, [rp, #4]
111         mov     r4, #0
112         umlal   r5, r4, ul, vl
113         sub     n, n, #4
114         tst     n, n
115         str     r, [rp], #4
116         bne     L(top)
117
118         ADDSUBC r, rl, r5
119         str     r, [rp]
120
121 L(rtn): RETVAL( r4)
122         ldmfd   sp!, { r4-r6, pc }
123 EPILOGUE()