gcd_22.asm revision 1.1 1 1.1 mrg dnl ARM v8a mpn_gcd_22.
2 1.1 mrg
3 1.1 mrg dnl Copyright 2019 Free Software Foundation, Inc.
4 1.1 mrg
5 1.1 mrg dnl This file is part of the GNU MP Library.
6 1.1 mrg dnl
7 1.1 mrg dnl The GNU MP Library is free software; you can redistribute it and/or modify
8 1.1 mrg dnl it under the terms of either:
9 1.1 mrg dnl
10 1.1 mrg dnl * the GNU Lesser General Public License as published by the Free
11 1.1 mrg dnl Software Foundation; either version 3 of the License, or (at your
12 1.1 mrg dnl option) any later version.
13 1.1 mrg dnl
14 1.1 mrg dnl or
15 1.1 mrg dnl
16 1.1 mrg dnl * the GNU General Public License as published by the Free Software
17 1.1 mrg dnl Foundation; either version 2 of the License, or (at your option) any
18 1.1 mrg dnl later version.
19 1.1 mrg dnl
20 1.1 mrg dnl or both in parallel, as here.
21 1.1 mrg dnl
22 1.1 mrg dnl The GNU MP Library is distributed in the hope that it will be useful, but
23 1.1 mrg dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 1.1 mrg dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 1.1 mrg dnl for more details.
26 1.1 mrg dnl
27 1.1 mrg dnl You should have received copies of the GNU General Public License and the
28 1.1 mrg dnl GNU Lesser General Public License along with the GNU MP Library. If not,
29 1.1 mrg dnl see https://www.gnu.org/licenses/.
30 1.1 mrg
31 1.1 mrg include(`../config.m4')
32 1.1 mrg
33 1.1 mrg changecom(blah)
34 1.1 mrg
35 1.1 mrg C cycles/bit (approx)
36 1.1 mrg C Cortex-A35 ?
37 1.1 mrg C Cortex-A53 7.26
38 1.1 mrg C Cortex-A55 ?
39 1.1 mrg C Cortex-A57 ?
40 1.1 mrg C Cortex-A72 5.72
41 1.1 mrg C Cortex-A73 6.43
42 1.1 mrg C Cortex-A75 ?
43 1.1 mrg C Cortex-A76 ?
44 1.1 mrg C Cortex-A77 ?
45 1.1 mrg
46 1.1 mrg
47 1.1 mrg define(`u1', `x0')
48 1.1 mrg define(`u0', `x1')
49 1.1 mrg define(`v1', `x2')
50 1.1 mrg define(`v0', `x3')
51 1.1 mrg
52 1.1 mrg define(`t0', `x5')
53 1.1 mrg define(`t1', `x6')
54 1.1 mrg define(`cnt', `x7')
55 1.1 mrg define(`tnc', `x8')
56 1.1 mrg
57 1.1 mrg ASM_START()
58 1.1 mrg PROLOGUE(mpn_gcd_22)
59 1.1 mrg
60 1.1 mrg ALIGN(16)
61 1.1 mrg L(top): subs t0, u0, v0 C 0 6
62 1.1 mrg cbz t0, L(lowz)
63 1.1 mrg sbcs t1, u1, v1 C 1 7
64 1.1 mrg
65 1.1 mrg rbit cnt, t0 C 1
66 1.1 mrg
67 1.1 mrg cneg t0, t0, cc C 2
68 1.1 mrg cinv t1, t1, cc C 2 u = |u - v|
69 1.1 mrg L(bck): csel v0, v0, u0, cs C 2
70 1.1 mrg csel v1, v1, u1, cs C 2 v = min(u,v)
71 1.1 mrg
72 1.1 mrg clz cnt, cnt C 2
73 1.1 mrg sub tnc, xzr, cnt C 3
74 1.1 mrg
75 1.1 mrg lsr u0, t0, cnt C 3
76 1.1 mrg lsl x14, t1, tnc C 4
77 1.1 mrg lsr u1, t1, cnt C 3
78 1.1 mrg orr u0, u0, x14 C 5
79 1.1 mrg
80 1.1 mrg orr x11, u1, v1
81 1.1 mrg cbnz x11, L(top)
82 1.1 mrg
83 1.1 mrg
84 1.1 mrg subs x4, u0, v0 C 0
85 1.1 mrg b.eq L(end1) C
86 1.1 mrg
87 1.1 mrg ALIGN(16)
88 1.1 mrg L(top1):rbit x12, x4 C 1,5
89 1.1 mrg clz x12, x12 C 2
90 1.1 mrg csneg x4, x4, x4, cs C v = abs(u-v), even 1
91 1.1 mrg csel u0, v0, u0, cs C u = min(u,v) 1
92 1.1 mrg lsr v0, x4, x12 C 3
93 1.1 mrg subs x4, u0, v0 C 4
94 1.1 mrg b.ne L(top1) C
95 1.1 mrg L(end1):mov x0, u0
96 1.1 mrg mov x1, #0
97 1.1 mrg ret
98 1.1 mrg
99 1.1 mrg L(lowz):C We come here when v0 - u0 = 0
100 1.1 mrg C 1. If v1 - u1 = 0, then gcd is u = v.
101 1.1 mrg C 2. Else compute gcd_21({v1,v0}, |u1-v1|)
102 1.1 mrg subs t0, u1, v1
103 1.1 mrg b.eq L(end)
104 1.1 mrg mov t1, #0
105 1.1 mrg rbit cnt, t0 C 1
106 1.1 mrg cneg t0, t0, cc C 2
107 1.1 mrg b L(bck) C FIXME: make conditional
108 1.1 mrg
109 1.1 mrg L(end): mov x0, v0
110 1.1 mrg mov x1, v1
111 1.1 mrg ret
112 1.1 mrg EPILOGUE()
113