beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / mpn / arm / v6t2 / gcd_1.asm
blob20636479630d6f09ab2e45fd7a7b739edad9c9d8
1 dnl ARM v6t2 mpn_gcd_1.
3 dnl Based on the K7 gcd_1.asm, by Kevin Ryde. Rehacked for ARM by Torbjörn
4 dnl Granlund.
6 dnl Copyright 2000-2002, 2005, 2009, 2011, 2012 Free Software Foundation, Inc.
8 dnl This file is part of the GNU MP Library.
9 dnl
10 dnl The GNU MP Library is free software; you can redistribute it and/or modify
11 dnl it under the terms of either:
12 dnl
13 dnl * the GNU Lesser General Public License as published by the Free
14 dnl Software Foundation; either version 3 of the License, or (at your
15 dnl option) any later version.
16 dnl
17 dnl or
18 dnl
19 dnl * the GNU General Public License as published by the Free Software
20 dnl Foundation; either version 2 of the License, or (at your option) any
21 dnl later version.
22 dnl
23 dnl or both in parallel, as here.
24 dnl
25 dnl The GNU MP Library is distributed in the hope that it will be useful, but
26 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
27 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 dnl for more details.
29 dnl
30 dnl You should have received copies of the GNU General Public License and the
31 dnl GNU Lesser General Public License along with the GNU MP Library. If not,
32 dnl see https://www.gnu.org/licenses/.
34 include(`../config.m4')
36 C cycles/bit (approx)
37 C StrongARM -
38 C XScale -
39 C Cortex-A7 ?
40 C Cortex-A8 ?
41 C Cortex-A9 5.3
42 C Cortex-A15 3.5
43 C Numbers measured with: speed -CD -s8-32 -t24 mpn_gcd_1
45 C TODO
46 C * Optimise inner-loop better.
47 C * Push saving/restoring of callee-user regs into call code
49 C Threshold of when to call bmod when U is one limb. Should be about
50 C (time_in_cycles(bmod_1,1) + call_overhead) / (cycles/bit).
51 define(`BMOD_THRES_LOG2', 7)
53 C INPUT PARAMETERS
54 define(`up', `r0')
55 define(`n', `r1')
56 define(`v0', `r2')
58 ifdef(`BMOD_1_TO_MOD_1_THRESHOLD',,
59 `define(`BMOD_1_TO_MOD_1_THRESHOLD',0xffffffff)')
61 ASM_START()
62 TEXT
63 ALIGN(16)
64 PROLOGUE(mpn_gcd_1)
65 push {r4, r7, lr}
66 ldr r3, [up] C U low limb
68 orr r3, r3, v0
69 rbit r4, r3
70 clz r4, r4 C min(ctz(u0),ctz(v0))
72 rbit r12, v0
73 clz r12, r12
74 mov v0, v0, lsr r12
76 mov r7, v0
78 cmp n, #1
79 bne L(nby1)
81 C Both U and V are single limbs, reduce with bmod if u0 >> v0.
82 ldr r3, [up]
83 cmp v0, r3, lsr #BMOD_THRES_LOG2
84 bhi L(red1)
86 L(bmod):mov r3, #0 C carry argument
87 bl mpn_modexact_1c_odd
88 b L(red0)
90 L(nby1):cmp n, #BMOD_1_TO_MOD_1_THRESHOLD
91 blo L(bmod)
93 bl mpn_mod_1
95 L(red0):mov r3, r0
96 L(red1):cmp r3, #0
97 rbit r12, r3
98 clz r12, r12
99 bne L(mid)
100 b L(end)
102 ALIGN(8)
103 L(top): movcs r3, r1 C if x-y < 0
104 movcs r7, r0 C use x,y-x
105 L(mid): mov r3, r3, lsr r12 C
106 mov r0, r3 C
107 subs r1, r7, r3 C
108 rsb r3, r7, r3 C
109 rbit r12, r1
110 clz r12, r12 C
111 bne L(top) C
113 L(end): mov r0, r7, lsl r4
114 pop {r4, r7, pc}
115 EPILOGUE()