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, 2012 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
either:
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.
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
21 dnl
or both
in parallel
, as here.
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
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
/.
32 include(`..
/config.m4
')
35 define(`rem_ptr',`r0
')
40 C divstep -- develop one quotient bit. Dividend in $1$2, divisor in $3.
41 C Quotient bit is shifted into $2.
49 PROLOGUE(mpn_udiv_qrnnd)
50 mov r12, #8 C loop counter for both loops below
51 cmp d, #0x80000000 C check divisor msb and clear carry
54 L(oop): divstep(n1,n0,d)
62 str n1, [rem_ptr] C store remainder
63 adc r0, n0, n0 C quotient: add last carry from divstep
69 and r8, n0, #1 C save lsb of dividend
71 orrs n0, lr, n0, lsr #1 C n0 = lo(n1n0 >> 1)
72 mov n1, n1, lsr #1 C n1 = hi(n1n0 >> 1)
74 and lr, d, #1 C save lsb of divisor
75 movs d, d, lsr #1 C d = floor(orig_d / 2)
76 adc d, d, #0 C d = ceil(orig_d / 2)
87 adc n0, n0, n0 C shift and add last carry from divstep
88 add n1, r8, n1, lsl #1 C shift in omitted dividend lsb
89 tst lr, lr C test saved divisor lsb
92 rsb d, lr, d, lsl #1 C restore orig d value
93 adds n1, n1, n0 C fix remainder for omitted divisor lsb
94 addcs n0, n0, #1 C adjust quotient if rem. fix carried
95 subcs n1, n1, d C adjust remainder accordingly
96 cmp n1, d C remainder >= divisor?
97 subcs n1, n1, d C adjust remainder
98 addcs n0, n0, #1 C adjust quotient
101 str n1, [rem_ptr] C store remainder
102 mov r0, n0 C quotient
103 ldmfd sp!, { r8, pc }
104 EPILOGUE(mpn_udiv_qrnnd)