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