1dnl ARM mpn_udiv_qrnnd -- divide a two limb dividend and a one limb divisor. 2dnl Return quotient and store remainder through a supplied pointer. 3 4dnl Copyright 2001 Free Software Foundation, Inc. 5 6dnl This file is part of the GNU MP Library. 7 8dnl The GNU MP Library is free software; you can redistribute it and/or modify 9dnl it under the terms of the GNU Lesser General Public License as published 10dnl by the Free Software Foundation; either version 3 of the License, or (at 11dnl your option) any later version. 12 13dnl The GNU MP Library is distributed in the hope that it will be useful, but 14dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16dnl License for more details. 17 18dnl You should have received a copy of the GNU Lesser General Public License 19dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. 20 21include(`../config.m4') 22 23C INPUT PARAMETERS 24define(`rem_ptr',`r0') 25define(`n1',`r1') 26define(`n0',`r2') 27define(`d',`r3') 28 29C divstep -- develop one quotient bit. Dividend in $1$2, divisor in $3. 30C Quotient bit is shifted into $2. 31define(`divstep', 32 `adcs $2, $2, $2 33 adc $1, $1, $1 34 cmp $1, $3 35 subcs $1, $1, $3') 36 37ASM_START() 38PROLOGUE(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 41 bcs L(_large_divisor) 42 43L(oop): divstep(n1,n0,d) 44 divstep(n1,n0,d) 45 divstep(n1,n0,d) 46 divstep(n1,n0,d) 47 sub r12, r12, #1 48 teq r12, #0 49 bne L(oop) 50 51 str n1, [ rem_ptr ] C store remainder 52 adc r0, n0, n0 C quotient: add last carry from divstep 53 mov pc, lr 54 55L(_large_divisor): 56 stmfd sp!, { r8, lr } 57 58 and r8, n0, #1 C save lsb of dividend 59 mov lr, n1, lsl #31 60 orrs n0, lr, n0, lsr #1 C n0 = lo(n1n0 >> 1) 61 mov n1, n1, lsr #1 C n1 = hi(n1n0 >> 1) 62 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) 66 67L(oop2): 68 divstep(n1,n0,d) 69 divstep(n1,n0,d) 70 divstep(n1,n0,d) 71 divstep(n1,n0,d) 72 sub r12, r12, #1 73 teq r12, #0 74 bne L(oop2) 75 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 79 beq L(_even_divisor) 80 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 88 89L(_even_divisor): 90 str n1, [ rem_ptr ] C store remainder 91 mov r0, n0 C quotient 92 ldmfd sp!, { r8, pc } 93EPILOGUE(mpn_udiv_qrnnd) 94