Debian Codegraph @

mpn/powerpc64/mode64/p9/gcd_22.asm

raw
1 dnl PowerPC-64 mpn_gcd_22 optimised for POWER9.
2
3 dnl Copyright 2000-2002, 2005, 2009, 2011-2013, 2019 Free Software Foundation,
4 dnl Inc.
5
6 dnl This file is part of the GNU MP Library.
7 dnl
8 dnl The GNU MP Library is free software; you can redistribute it and/or modify
9 dnl it under the terms of either:
10 dnl
11 dnl * the GNU Lesser General Public License as published by the Free
12 dnl Software Foundation; either version 3 of the License, or (at your
13 dnl option) any later version.
14 dnl
15 dnl or
16 dnl
17 dnl * the GNU General Public License as published by the Free Software
18 dnl Foundation; either version 2 of the License, or (at your option) any
19 dnl later version.
20 dnl
21 dnl or both in parallel, as here.
22 dnl
23 dnl The GNU MP Library is distributed in the hope that it will be useful, but
24 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 dnl for more details.
27 dnl
28 dnl You should have received copies of the GNU General Public License and the
29 dnl GNU Lesser General Public License along with the GNU MP Library. If not,
30 dnl see https://www.gnu.org/licenses/.
31
32 include(`../config.m4')
33
34 C cycles/bit (approx)
35 C POWER3/PPC630 -
36 C POWER4/PPC970 -
37 C POWER5 -
38 C POWER6 -
39 C POWER7 -
40 C POWER8 -
41 C POWER9 9.58
42
43 C We define SLOW if this target uses a slow struct return mechanism, with
44 C r3 as an implicit parameter for the struct pointer.
45 undefine(`SLOW')dnl
46 ifdef(`AIX',`define(`SLOW',`due to AIX')',`
47 ifdef(`DARWIN',,`
48 ifdef(`ELFv2_ABI',,`define(`SLOW',`due to ELFv1')')dnl
49 ')
50 ')
51
52 ifdef(`SLOW',`
53 define(`IFSLOW', `$1')
54 define(`u1', `r4')
55 define(`u0', `r5')
56 define(`v1', `r6')
57 define(`v0', `r7')
58 ',`
59 define(`IFSLOW', `')
60 define(`u1', `r3')
61 define(`u0', `r4')
62 define(`v1', `r5')
63 define(`v0', `r6')
64 ')
65
66 define(`tmp', `r0')
67 define(`t0', `r8')
68 define(`t1', `r9')
69 define(`s0', `r10')
70 define(`s1', `r11')
71 define(`cnt', `r12')
72
73 ASM_START()
74 PROLOGUE(mpn_gcd_22)
75 cmpld cr7, v0, u0
76 L(top): subfc t0, v0, u0 C 0 12
77 beq cr7, L(lowz)
78 subfe t1, v1, u1 C 2 14
79 subfe. tmp, tmp, tmp C 4 set cr0 from the carry bit
80 subfc s0, u0, v0 C 0
81 subfe s1, u1, v1 C 2
82
83 L(bck): cnttzd cnt, t0 C 2
84 subfic tmp, cnt, 64 C 4
85
86 isel v0, v0, u0, 2 C 6 use condition set by subfe
87 isel u0, t0, s0, 2 C 6
88 isel v1, v1, u1, 2 C 6
89 isel u1, t1, s1, 2 C 6
90
91 srd u0, u0, cnt C 8
92 sld tmp, u1, tmp C 8
93 srd u1, u1, cnt C 8
94 or u0, u0, tmp C 10
95
96 or. r0, u1, v1 C 10
97 cmpld cr7, v0, u0
98 bne L(top)
99
100
101 b L(odd)
102 ALIGN(16)
103 L(top1):isel v0, u0, v0, 29 C v = min(u,v)
104 isel u0, r10, r11, 29 C u = |u - v|
105 srd u0, u0, cnt
106 L(odd): subf r10, u0, v0 C r10 = v - u
107 subf r11, v0, u0 C r11 = u - v
108 cmpld cr7, v0, u0
109 cnttzd cnt, r10
110 bne cr7, L(top1)
111
112 ifdef(`SLOW',`
113 std v0, 0(r3)
114 std r10, 8(r3)
115 ',`
116 mr r3, v0
117 li r4, 0
118 ')
119 blr
120
121
122 L(lowz):C We come here when v0 - u0 = 0
123 C 1. If v1 - u1 = 0, then gcd is u = v.
124 C 2. Else compute gcd_21({v1,v0}, |u1-v1|)
125 subfc. t0, v1, u1 C 2 8
126 beq L(end)
127 li t1, 0
128 subfe. tmp, tmp, tmp C 4 set cr0 from the carry bit
129 subf s0, u1, v1 C 2
130 li s1, 0
131 b L(bck)
132
133 L(end):
134 ifdef(`SLOW',`
135 std v0, 0(r3)
136 std v1, 8(r3)
137 blr
138 ',`
139 mr r3, v0
140 mr r4, v1
141 blr
142 ')
143 EPILOGUE()