1189251Ssamdnl PowerPC-32 mpn_divexact_by3 -- mpn by 3 exact division 2189251Ssam 3214734Srpaulodnl Copyright 2002, 2003, 2005, 2006 Free Software Foundation, Inc. 4189251Ssamdnl 5252726Srpaulodnl This file is part of the GNU MP Library. 6252726Srpaulodnl 7189251Ssamdnl The GNU MP Library is free software; you can redistribute it and/or 8189251Ssamdnl modify it under the terms of the GNU Lesser General Public License as 9189251Ssamdnl published by the Free Software Foundation; either version 3 of the 10189251Ssamdnl License, or (at your option) any later version. 11189251Ssamdnl 12214734Srpaulodnl The GNU MP Library is distributed in the hope that it will be useful, 13189251Ssamdnl but WITHOUT ANY WARRANTY; without even the implied warranty of 14189251Ssamdnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15214734Srpaulodnl Lesser General Public License for more details. 16189251Ssamdnl 17189251Ssamdnl You should have received a copy of the GNU Lesser General Public License 18189251Ssamdnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. 19189251Ssam 20189251Ssaminclude(`../config.m4') 21189251Ssam 22189251SsamC cycles/limb 23189251SsamC 603e: ? 24189251SsamC 604e: 5 25189251SsamC 75x (G3): ? 26189251SsamC 7400,7410 (G4): 8 27214734SrpauloC 744x,745x (G4+): 6 28189251SsamC 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