Debian Codegraph @

mpn/powerpc64/mode64/bdiv_q_1.asm

raw
1 dnl PowerPC-64 mpn_bdiv_q_1, mpn_pi1_bdiv_q_1 -- Hensel division by 1-limb
2 dnl divisor.
3
4 dnl Copyright 2006, 2010, 2017 Free Software Foundation, 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/limb
35 C norm unorm
36 C POWER3/PPC630 13-19
37 C POWER4/PPC970 16
38 C POWER5 16 16
39 C POWER6 37 46
40 C POWER7 12 12
41 C POWER8 12 12
42
43 C INPUT PARAMETERS
44 define(`rp', `r3')
45 define(`up', `r4')
46 define(`n', `r5')
47 define(`d', `r6')
48 define(`di', `r7')
49 define(`cnt',`r8')
50
51 define(`tnc',`r10')
52
53 ASM_START()
54
55 EXTERN(binvert_limb_table)
56
57 PROLOGUE(mpn_bdiv_q_1,toc)
58 addi r7, n, -1
59 cmpdi cr1, n, 1
60 ld r12, 0(up)
61 li cnt, 0
62 neg r0, d
63 and r0, d, r0
64 cntlzd r0, r0
65 subfic cnt, r0, 63
66 srd d, d, cnt
67 L(7):
68 mtctr r7
69 LEA( r10, binvert_limb_table)
70 rldicl r11, d, 63, 57
71 lbzx r0, r10, r11
72 mulld r9, r0, r0
73 sldi r0, r0, 1
74 mulld r9, d, r9
75 subf r0, r9, r0
76 mulld r10, r0, r0
77 sldi r0, r0, 1
78 mulld r10, d, r10
79 subf r0, r10, r0
80 mulld r9, r0, r0
81 sldi r0, r0, 1
82 mulld r9, d, r9
83 subf di, r9, r0 C di = 1/d mod 2^64
84 ifdef(`AIX',
85 ` C For AIX it is not clear how to jump into another function.
86 b .mpn_pi1_bdiv_q_1
87 ',`
88 C For non-AIX, dispatch into the pi1 variant.
89 bne cr0, L(norm)
90 b L(unorm)
91 ')
92 EPILOGUE()
93
94 PROLOGUE(mpn_pi1_bdiv_q_1)
95 cmpdi cr0, cnt, 0
96 ld r12, 0(up)
97 addic r0, n, -1 C set carry as side effect
98 cmpdi cr1, n, 1
99 mtctr r0
100 beq cr0, L(norm)
101
102 L(unorm):
103 subfic tnc, cnt, 64 C set carry as side effect
104 li r5, 0
105 srd r11, r12, cnt
106 beq cr1, L(ed1)
107
108 ALIGN(16)
109 L(tpu): ld r12, 8(up)
110 nop
111 addi up, up, 8
112 sld r0, r12, tnc
113 or r11, r11, r0
114 subfe r9, r5, r11
115 srd r11, r12, cnt
116 mulld r0, di, r9
117 mulhdu r5, r0, d
118 std r0, 0(rp)
119 addi rp, rp, 8
120 bdnz L(tpu)
121
122 subfe r11, r5, r11
123 L(ed1): mulld r0, di, r11
124 std r0, 0(rp)
125 blr
126
127 ALIGN(16)
128 L(norm):
129 mulld r11, r12, di
130 mulhdu r5, r11, d
131 std r11, 0(rp)
132 beqlr cr1
133
134 ALIGN(16)
135 L(tpn): ld r9, 8(up)
136 addi up, up, 8
137 subfe r5, r5, r9
138 mulld r11, di, r5
139 mulhdu r5, r11, d C result not used in last iteration
140 std r11, 8(rp)
141 addi rp, rp, 8
142 bdnz L(tpn)
143
144 blr
145 EPILOGUE()
146 ASM_END()