Import upstream 5.1.3.
[platform/upstream/gmp.git] / mpn / arm / mode1o.asm
1 dnl  ARM mpn_modexact_1c_odd
2
3 dnl  Contributed to the GNU project by Torbjorn Granlund.
4
5 dnl  Copyright 2012 Free Software Foundation, Inc.
6
7 dnl  This file is part of the GNU MP Library.
8
9 dnl  The GNU MP Library is free software; you can redistribute it and/or modify
10 dnl  it under the terms of the GNU Lesser General Public License as published
11 dnl  by the Free Software Foundation; either version 3 of the License, or (at
12 dnl  your option) any later version.
13
14 dnl  The GNU MP Library is distributed in the hope that it will be useful, but
15 dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
17 dnl  License for more details.
18
19 dnl  You should have received a copy of the GNU Lesser General Public License
20 dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
21
22 include(`../config.m4')
23
24 C            cycles/limb
25 C StrongARM      ?
26 C XScale         ?
27 C Cortex-A8      ?
28 C Cortex-A9     10
29 C Cortex-A15     ?
30
31 define(`up', `r0')
32 define(`n',  `r1')
33 define(`d',  `r2')
34 define(`cy', `r3')
35
36         .protected      binvert_limb_table
37 ASM_START()
38 PROLOGUE(mpn_modexact_1c_odd)
39         stmfd   sp!, {r4, r5}
40
41         LEA(    r4, binvert_limb_table)
42
43         ldr     r5, [up], #4            C up[0]
44
45         and     r12, d, #254
46         ldrb    r4, [r4, r12, lsr #1]
47         mul     r12, r4, r4
48         mul     r12, d, r12
49         rsb     r12, r12, r4, asl #1
50         mul     r4, r12, r12
51         mul     r4, d, r4
52         rsb     r4, r4, r12, asl #1     C r4 = inverse
53
54         subs    n, n, #1                C set carry as side-effect
55         beq     L(end)
56
57 L(top): sbcs    cy, r5, cy
58         ldr     r5, [up], #4
59         sub     n, n, #1
60         mul     r12, r4, cy
61         tst     n, n
62         umull   r12, cy, d, r12
63         bne     L(top)
64
65 L(end): sbcs    cy, r5, cy
66         mul     r12, r4, cy
67         umull   r12, r0, d, r12
68         addcc   r0, r0, #1
69
70         ldmfd   sp!, {r4, r5}
71         bx      r14
72 EPILOGUE()