Debian Codegraph @

mpn/powerpc64/mode64/p7/gcd_22.asm

raw
1 dnl PowerPC-64 mpn_gcd_22 optimised for POWER7 and POWER8.
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 12.3
40 C POWER8 13.4
41 C POWER9 10.6
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 L(top): subfc. t0, v0, u0 C 0 12
76 beq cr0, L(lowz)
77 subfe t1, v1, u1 C 2 14
78 subfe. tmp, tmp, tmp C 4 set cr0 from the carry bit
79 subfc s0, u0, v0 C 0
80 subfe s1, u1, v1 C 2
81
82 L(bck): and tmp, s0, t0 C 2
83 cntlzd cnt, tmp C 4
84 addi tmp, cnt, 1 C 6
85 subfic cnt, cnt, 63 C 6
86
87 isel v0, v0, u0, 2 C 6 use condition set by subfe
88 isel v1, v1, u1, 2 C 6
89 isel u0, t0, s0, 2 C 6
90 isel u1, t1, s1, 2 C 6
91
92 srd u0, u0, cnt C 8
93 sld tmp, u1, tmp C 8
94 srd u1, u1, cnt C 8
95 or u0, u0, tmp C 10
96
97 or. r0, u1, v1 C 10
98 bne L(top)
99
100
101 li r0, 63
102 b L(odd)
103 ALIGN(16)
104 L(top1):isel v0, u0, v0, 29 C v = min(u,v)
105 isel u0, r10, r11, 29 C u = |u - v|
106 subf cnt, cnt, r0 C cnt = 63-cnt
107 srd u0, u0, cnt
108 L(odd): subf r10, u0, v0 C r10 = v - u
109 subf r11, v0, u0 C r11 = u - v
110 cmpld cr7, v0, u0
111 and r8, r11, r10 C isolate lsb
112 cntlzd cnt, r8
113 bne cr7, L(top1)
114
115 ifdef(`SLOW',`
116 std v0, 0(r3)
117 std r10, 8(r3) C zero
118 ',`
119 mr r3, v0
120 li r4, 0
121 ')
122 blr
123
124
125 L(lowz):C We come here when v0 - u0 = 0
126 C 1. If v1 - u1 = 0, then gcd is u = v.
127 C 2. Else compute gcd_21({v1,v0}, |u1-v1|)
128 subfc. t0, v1, u1 C 2 8
129 beq L(end)
130 li t1, 0
131 subfe. tmp, tmp, tmp C 4 set cr0 from the carry bit
132 subf s0, u1, v1 C 2
133 li s1, 0
134 b L(bck)
135
136 L(end):
137 ifdef(`SLOW',`
138 std v0, 0(r3)
139 std v1, 8(r3)
140 blr
141 ',`
142 mr r3, v0
143 mr r4, v1
144 blr
145 ')
146 EPILOGUE()