1dnl PowerPC-64 mpn_divexact_1 -- mpn by limb exact division. 2 3dnl Copyright 2006, 2010 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 norm unorm 24C POWER3/PPC630 13-19 25C POWER4/PPC970 16 26C POWER5 16 16 27C POWER6 37 46 28C POWER7 12 12 29 30C TODO 31C * Check if n=1 code is really an improvement. It probably isn't. 32C * Make more similar to mode1o.asm. 33 34C INPUT PARAMETERS 35define(`rp', `r3') 36define(`up', `r4') 37define(`n', `r5') 38define(`d', `r6') 39 40 41ASM_START() 42 43EXTERN(binvert_limb_table) 44 45PROLOGUE(mpn_divexact_1) 46 addic. n, n, -1 47 ld r12, 0(up) 48 bne cr0, L(2) 49 divdu r0, r12, d 50 std r0, 0(rp) 51 blr 52L(2): 53 rldicl. r0, d, 0, 63 54 li r10, 0 55 bne cr0, L(7) 56 neg r0, d 57 and r0, d, r0 58 cntlzd r0, r0 59 subfic r0, r0, 63 60 rldicl r10, r0, 0, 32 61 srd d, d, r0 62L(7): 63 mtctr n 64 LEA( r5, binvert_limb_table) 65 rldicl r11, d, 63, 57 66 lbzx r0, r5, r11 67 mulld r9, r0, r0 68 sldi r0, r0, 1 69 mulld r9, d, r9 70 subf r0, r9, r0 71 mulld r5, r0, r0 72 sldi r0, r0, 1 73 mulld r5, d, r5 74 subf r0, r5, r0 75 mulld r9, r0, r0 76 sldi r0, r0, 1 77 mulld r9, d, r9 78 subf r7, r9, r0 C r7 = 1/d mod 2^64 79 bne cr0, L(norm) 80 subfic r8, r10, 64 C set carry as side effect 81 li r5, 0 82 srd r11, r12, r10 83 84 ALIGN(16) 85L(loop0): 86 ld r12, 8(up) 87 nop 88 addi up, up, 8 89 sld r0, r12, r8 90 or r11, r11, r0 91 subfe r9, r5, r11 92 srd r11, r12, r10 93 mulld r0, r7, r9 94 mulhdu r5, r0, d 95 std r0, 0(rp) 96 addi rp, rp, 8 97 bdnz L(loop0) 98 99 subfe r0, r5, r11 100 mulld r0, r7, r0 101 std r0, 0(rp) 102 blr 103 104 ALIGN(16) 105L(norm): 106 mulld r11, r12, r7 107 mulhdu r5, r11, d 108 std r11, 0(rp) 109 ALIGN(16) 110L(loop1): 111 ld r9, 8(up) 112 addi up, up, 8 113 subfe r5, r5, r9 114 mulld r11, r7, r5 115 mulhdu r5, r11, d C result not used 116 std r11, 8(rp) 117 addi rp, rp, 8 118 bdnz L(loop1) 119 blr 120EPILOGUE() 121ASM_END() 122