1 dnl ARM mpn_udiv_qrnnd -- divide a two limb dividend and a one limb divisor.
2 dnl Return quotient and store remainder through a supplied pointer.
4 dnl Copyright 2001 Free Software Foundation, Inc.
6 dnl This file is part of the GNU MP Library.
8 dnl The GNU MP Library is free software; you can redistribute it and/or modify
9 dnl it under the terms of the GNU Lesser General Public License as published
10 dnl by the Free Software Foundation; either version 3 of the License, or (at
11 dnl your option) any later version.
13 dnl The GNU MP Library is distributed in the hope that it will be useful, but
14 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 dnl License for more details.
18 dnl You should have received a copy of the GNU Lesser General Public License
19 dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
21 include(`../config.m4')
24 define(`rem_ptr',`r0')
29 C divstep -- develop one quotient bit. Dividend in $1$2, divisor in $3.
30 C Quotient bit is shifted into $2.
38 PROLOGUE(mpn_udiv_qrnnd)
39 mov r12, #8 C loop counter for both loops below
40 cmp d, #0x80000000 C check divisor msb and clear carry
43 L(oop): divstep(n1,n0,d)
51 str n1, [ rem_ptr ] C store remainder
52 adc r0, n0, n0 C quotient: add last carry from divstep
58 and r8, n0, #1 C save lsb of dividend
60 orrs n0, lr, n0, lsr #1 C n0 = lo(n1n0 >> 1)
61 mov n1, n1, lsr #1 C n1 = hi(n1n0 >> 1)
63 and lr, d, #1 C save lsb of divisor
64 movs d, d, lsr #1 C d = floor(orig_d / 2)
65 adc d, d, #0 C d = ceil(orig_d / 2)
76 adc n0, n0, n0 C shift and add last carry from divstep
77 add n1, r8, n1, lsl #1 C shift in omitted dividend lsb
78 tst lr, lr C test saved divisor lsb
81 rsb d, lr, d, lsl #1 C restore orig d value
82 adds n1, n1, n0 C fix remainder for omitted divisor lsb
83 addcs n0, n0, #1 C adjust quotient if rem. fix carried
84 subcs n1, n1, d C adjust remainder accordingly
85 cmp n1, d C remainder >= divisor?
86 subcs n1, n1, d C adjust remainder
87 addcs n0, n0, #1 C adjust quotient
90 str n1, [ rem_ptr ] C store remainder
93 EPILOGUE(mpn_udiv_qrnnd)