Debian Codegraph @

mpn/powerpc64/mode64/dive_1.asm

raw
1 dnl PowerPC-64 mpn_divexact_1 -- mpn by limb exact division.
2
3 dnl Copyright 2006, 2010 Free Software Foundation, Inc.
4
5 dnl This file is part of the GNU MP Library.
6 dnl
7 dnl The GNU MP Library is free software; you can redistribute it and/or modify
8 dnl it under the terms of either:
9 dnl
10 dnl * the GNU Lesser General Public License as published by the Free
11 dnl Software Foundation; either version 3 of the License, or (at your
12 dnl option) any later version.
13 dnl
14 dnl or
15 dnl
16 dnl * the GNU General Public License as published by the Free Software
17 dnl Foundation; either version 2 of the License, or (at your option) any
18 dnl later version.
19 dnl
20 dnl or both in parallel, as here.
21 dnl
22 dnl The GNU MP Library is distributed in the hope that it will be useful, but
23 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 dnl for more details.
26 dnl
27 dnl You should have received copies of the GNU General Public License and the
28 dnl GNU Lesser General Public License along with the GNU MP Library. If not,
29 dnl see https://www.gnu.org/licenses/.
30
31 include(`../config.m4')
32
33 C cycles/limb
34 C norm unorm
35 C POWER3/PPC630 13-19
36 C POWER4/PPC970 16
37 C POWER5 16 16
38 C POWER6 37 46
39 C POWER7 12 12
40 C POWER8 12 12
41
42 C TODO
43 C * Check if n=1 code is really an improvement. It probably isn't.
44 C * Make more similar to mode1o.asm.
45
46 C INPUT PARAMETERS
47 define(`rp', `r3')
48 define(`up', `r4')
49 define(`n', `r5')
50 define(`d', `r6')
51
52
53 ASM_START()
54
55 EXTERN(binvert_limb_table)
56
57 PROLOGUE(mpn_divexact_1,toc)
58 addic. n, n, -1
59 ld r12, 0(up)
60 bne cr0, L(2)
61 divdu r0, r12, d
62 std r0, 0(rp)
63 blr
64 L(2):
65 rldicl. r0, d, 0, 63
66 li r10, 0
67 bne cr0, L(7)
68 neg r0, d
69 and r0, d, r0
70 cntlzd r0, r0
71 subfic r0, r0, 63
72 rldicl r10, r0, 0, 32
73 srd d, d, r0
74 L(7):
75 mtctr n
76 LEA( r5, binvert_limb_table)
77 rldicl r11, d, 63, 57
78 lbzx r0, r5, r11
79 mulld r9, r0, r0
80 sldi r0, r0, 1
81 mulld r9, d, r9
82 subf r0, r9, r0
83 mulld r5, r0, r0
84 sldi r0, r0, 1
85 mulld r5, d, r5
86 subf r0, r5, r0
87 mulld r9, r0, r0
88 sldi r0, r0, 1
89 mulld r9, d, r9
90 subf r7, r9, r0 C r7 = 1/d mod 2^64
91
92 bne cr0, L(norm)
93 subfic r8, r10, 64 C set carry as side effect
94 li r5, 0
95 srd r11, r12, r10
96
97 ALIGN(16)
98 L(loop0):
99 ld r12, 8(up)
100 nop
101 addi up, up, 8
102 sld r0, r12, r8
103 or r11, r11, r0
104 subfe r9, r5, r11
105 srd r11, r12, r10
106 mulld r0, r7, r9
107 mulhdu r5, r0, d
108 std r0, 0(rp)
109 addi rp, rp, 8
110 bdnz L(loop0)
111
112 subfe r0, r5, r11
113 mulld r0, r7, r0
114 std r0, 0(rp)
115 blr
116
117 ALIGN(16)
118 L(norm):
119 mulld r11, r12, r7
120 mulhdu r5, r11, d
121 std r11, 0(rp)
122 ALIGN(16)
123 L(loop1):
124 ld r9, 8(up)
125 addi up, up, 8
126 subfe r5, r5, r9
127 mulld r11, r7, r5
128 mulhdu r5, r11, d C result not used in last iteration
129 std r11, 8(rp)
130 addi rp, rp, 8
131 bdnz L(loop1)
132
133 blr
134 EPILOGUE()
135 ASM_END()