1dnl  ARM mpn_addmul_1 and mpn_submul_1.
2
3dnl  Copyright 1998, 2000, 2001, 2003, 2012 Free Software Foundation, Inc.
4
5dnl  This file is part of the GNU MP Library.
6dnl
7dnl  The GNU MP Library is free software; you can redistribute it and/or modify
8dnl  it under the terms of either:
9dnl
10dnl    * the GNU Lesser General Public License as published by the Free
11dnl      Software Foundation; either version 3 of the License, or (at your
12dnl      option) any later version.
13dnl
14dnl  or
15dnl
16dnl    * the GNU General Public License as published by the Free Software
17dnl      Foundation; either version 2 of the License, or (at your option) any
18dnl      later version.
19dnl
20dnl  or both in parallel, as here.
21dnl
22dnl  The GNU MP Library is distributed in the hope that it will be useful, but
23dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25dnl  for more details.
26dnl
27dnl  You should have received copies of the GNU General Public License and the
28dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
29dnl  see https://www.gnu.org/licenses/.
30
31include(`../config.m4')
32
33C              cycles/limb
34C StrongARM:     ?
35C XScale   ?
36C Cortex-A7          ?
37C Cortex-A8          ?
38C Cortex-A9          5.25
39C Cortex-A15         4
40
41define(`rp', `r0')
42define(`up', `r1')
43define(`n',  `r2')
44define(`vl', `r3')
45define(`rl', `r12')
46define(`ul', `r6')
47define(`r',  `lr')
48
49ifdef(`OPERATION_addmul_1', `
50  define(`ADDSUB',  adds)
51  define(`ADDSUBC', adcs)
52  define(`CLRRCY',  `mov      $1, #0
53                              adds      r0, r0, #0')
54  define(`RETVAL',  `adc      r0, r4, #0')
55  define(`func',    mpn_addmul_1)')
56ifdef(`OPERATION_submul_1', `
57  define(`ADDSUB',  subs)
58  define(`ADDSUBC', sbcs)
59  define(`CLRRCY',  `subs     $1, r0, r0')
60  define(`RETVAL',  `sbc      r0, r0, r0
61                              sub       r0, $1, r0')
62  define(`func',    mpn_submul_1)')
63
64MULFUNC_PROLOGUE(mpn_addmul_1 mpn_submul_1)
65
66ASM_START()
67PROLOGUE(func)
68          stmfd     sp!, { r4-r6, lr }
69          CLRRCY(   r4)
70          tst       n, #1
71          beq       L(skip1)
72          ldr       ul, [up], #4
73          ldr       rl, [rp, #0]
74          umull     r5, r4, ul, vl
75          ADDSUB    r, rl, r5
76          str       r, [rp], #4
77L(skip1):
78          tst       n, #2
79          beq       L(skip2)
80          ldr       ul, [up], #4
81          ldr       rl, [rp, #0]
82          mov       r5, #0
83          umlal     r4, r5, ul, vl
84          ldr       ul, [up], #4
85          ADDSUBC   r, rl, r4
86          ldr       rl, [rp, #4]
87          mov       r4, #0
88          umlal     r5, r4, ul, vl
89          str       r, [rp], #4
90          ADDSUBC   r, rl, r5
91          str       r, [rp], #4
92L(skip2):
93          bics      n, n, #3
94          beq       L(rtn)
95
96          ldr       ul, [up], #4
97          ldr       rl, [rp, #0]
98          mov       r5, #0
99          umlal     r4, r5, ul, vl
100          b         L(in)
101
102L(top):   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
108L(in):    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          str       r, [rp], #4
114          ldr       ul, [up], #4
115          ADDSUBC   r, rl, r5
116          ldr       rl, [rp, #4]
117          mov       r5, #0
118          umlal     r4, r5, ul, vl
119          str       r, [rp], #4
120          ldr       ul, [up], #4
121          ADDSUBC   r, rl, r4
122          ldr       rl, [rp, #4]
123          mov       r4, #0
124          umlal     r5, r4, ul, vl
125          sub       n, n, #4
126          tst       n, n
127          str       r, [rp], #4
128          bne       L(top)
129
130          ADDSUBC   r, rl, r5
131          str       r, [rp]
132
133L(rtn):   RETVAL(   r4)
134          ldmfd     sp!, { r4-r6, pc }
135EPILOGUE()
136