1dnl PowerPC-32 mpn_divexact_by3 -- mpn by 3 exact division 2 3dnl Copyright 2002, 2003, 2005, 2006 Free Software Foundation, Inc. 4 5dnl This file is part of the GNU MP Library. 6dnl 7dnl The GNU MP Library is free software; you can redistribute it and/or modify 8dnl it under the terms of either: 9dnl 10dnl * the GNU Lesser General Public License as published by the Free 11dnl Software Foundation; either version 3 of the License, or (at your 12dnl option) any later version. 13dnl 14dnl or 15dnl 16dnl * the GNU General Public License as published by the Free Software 17dnl Foundation; either version 2 of the License, or (at your option) any 18dnl later version. 19dnl 20dnl or both in parallel, as here. 21dnl 22dnl The GNU MP Library is distributed in the hope that it will be useful, but 23dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 24dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25dnl for more details. 26dnl 27dnl You should have received copies of the GNU General Public License and the 28dnl GNU Lesser General Public License along with the GNU MP Library. If not, 29dnl see https://www.gnu.org/licenses/. 30 31include(`../config.m4') 32 33C cycles/limb 34C 603e: ? 35C 604e: 5 36C 75x (G3): ? 37C 7400,7410 (G4): 8 38C 744x,745x (G4+): 6 39C power4/ppc970: 12 40C power5: ? 41 42C void mpn_divexact_by3 (mp_ptr dst, mp_srcptr src, mp_size_t size); 43C 44C We avoid the slow subfe instruction and instead rely on an extremely unlikely 45C branch. 46C 47C The mullw has the inverse in the first operand, since 0xAA..AB won't allow 48C any early-out. The src[] data normally won't either, but there's at least 49C a chance, whereas 0xAA..AB never will. If, for instance, src[] is all 50C zeros (not a sensible input of course) we run at 7.0 c/l on ppc750. 51C 52C The mulhwu has the "3" multiplier in the second operand, which lets 750 and 53C 7400 use an early-out. 54 55C INPUT PARAMETERS 56define(`rp', `r3') 57define(`up', `r4') 58define(`n', `r5') 59define(`cy', `r6') 60 61ASM_START() 62PROLOGUE(mpn_divexact_by3c) 63 lwz r11, 0(up) 64 mtctr n 65 lis r12, 0xAAAA 66 ori r12, r12, 0xAAAB 67 li r10, 3 68 69 cmplw cr7, cy, r11 70 subf r11, cy, r11 71 72 mullw r0, r11, r12 73 stw r0, 0(rp) 74 bdz L(one) 75 76L(top): lwzu r9, 4(up) 77 mulhwu r7, r0, r10 78 bgt- cr7, L(adj) C very unlikely branch 79L(bko): cmplw cr7, r7, r9 80 subf r0, r7, r9 81 mullw r0, r12, r0 82 stwu r0, 4(rp) 83 bdnz L(top) 84 85L(one): mulhwu r3, r0, r10 86 blelr+ cr7 87 addi r3, r3, 1 88 blr 89 90L(adj): addi r7, r7, 1 91 b L(bko) 92EPILOGUE() 93ASM_END() 94