1 dnl PPC-32 mpn_divrem_2 -- Divide an mpn number by a normalized 2-limb number.
3 dnl Copyright 2007, 2008 Free Software Foundation, Inc.
5 dnl This file is part of the GNU MP Library.
7 dnl The GNU MP Library is free software; you can redistribute it and/or modify
8 dnl it under the terms of the GNU Lesser General Public License as published
9 dnl by the Free Software Foundation; either version 3 of the License, or (at
10 dnl your option) any later version.
12 dnl The GNU MP Library is distributed in the hope that it will be useful, but
13 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 dnl License for more details.
17 dnl You should have received a copy of the GNU Lesser General Public License
18 dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
20 include(`../config.m4')
35 C * Decrease register usage.
36 C * Make sure mul operands and optimal for early-out.
37 C * Check that things work well for a shared library build.
38 C * Write an invert_limb, perhaps inline, perhaps as a private call. Or at
39 C least vastly improve the current __udiv_qrnnd_c based code.
43 PROLOGUE(mpn_divrem_2)
48 addi r29, r5, -8 C up = up_param + un - 2
59 L(4): subfc r28, r7, r28
70 add r8, r8, r9 C rp += un + fn
77 rlwinm r5, r10, 0, 16, 31
88 addi r31, r31, -1 C q1--
91 addi r31, r31, -1 C q1--
105 addi r6, r6, -1 C q0--
108 C add r0, r0, r10 C final remainder
109 addi r6, r6, -1 C q0--
110 L(13): rlwimi r6, r31, 16, 0, 15 C assemble final quotient
112 C Adjust di by including d0
113 mullw r9, r10, r6 C t0 = LO(di * d1)
116 mulhwu r9, r6, r7 C s1 = HI(di * d0)
120 L(18): subfc r9, r10, r9
126 C r0 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r28 r29 r30 r31
127 C msl di d0 qp d1 fn up un
129 mullw r0, r12, r6 C q0 = LO(n2 * di)
131 addc r31, r0, r28 C q0 += n1
132 mulhwu r9, r12, r6 C q = HI(n2 * di)
133 adde r12, r9, r12 C q += n2
135 mullw r0, r10, r12 C d1 * q
137 subf r0, r0, r28 C n1 -= d1 * q
141 L(23): mullw r11, r12, r7 C t0 = LO(d0 * q)
142 subfc r28, r7, r9 C n0 -= d0
143 subfe r0, r10, r0 C n1 -= d1
144 mulhwu r12, r12, r7 C t1 = HI(d0 * q)
145 subfc r28, r11, r28 C n0 -= t0
146 subfe r12, r12, r0 C n1 -= t1
152 L(24): cmplw cr7, r12, r10
154 L(bck): stw r5, 0(r8)
158 L(ret): stw r28, 0(r29)
164 L(fix): cmplw cr6, r28, r7
167 L(28): subfc r28, r7, r28