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