Blame mpn/powerpc32/diveby3.asm

Packit 5c3484
dnl  PowerPC-32 mpn_divexact_by3 -- mpn by 3 exact division
Packit 5c3484
Packit 5c3484
dnl  Copyright 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
Packit 5c3484
Packit 5c3484
dnl  This file is part of the GNU MP Library.
Packit 5c3484
dnl
Packit 5c3484
dnl  The GNU MP Library is free software; you can redistribute it and/or modify
Packit 5c3484
dnl  it under the terms of either:
Packit 5c3484
dnl
Packit 5c3484
dnl    * the GNU Lesser General Public License as published by the Free
Packit 5c3484
dnl      Software Foundation; either version 3 of the License, or (at your
Packit 5c3484
dnl      option) any later version.
Packit 5c3484
dnl
Packit 5c3484
dnl  or
Packit 5c3484
dnl
Packit 5c3484
dnl    * the GNU General Public License as published by the Free Software
Packit 5c3484
dnl      Foundation; either version 2 of the License, or (at your option) any
Packit 5c3484
dnl      later version.
Packit 5c3484
dnl
Packit 5c3484
dnl  or both in parallel, as here.
Packit 5c3484
dnl
Packit 5c3484
dnl  The GNU MP Library is distributed in the hope that it will be useful, but
Packit 5c3484
dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit 5c3484
dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit 5c3484
dnl  for more details.
Packit 5c3484
dnl
Packit 5c3484
dnl  You should have received copies of the GNU General Public License and the
Packit 5c3484
dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
Packit 5c3484
dnl  see https://www.gnu.org/licenses/.
Packit 5c3484
Packit 5c3484
include(`../config.m4')
Packit 5c3484
Packit 5c3484
C                cycles/limb
Packit 5c3484
C 603e:              ?
Packit 5c3484
C 604e:              5
Packit 5c3484
C 75x (G3):          ?
Packit 5c3484
C 7400,7410 (G4):    8
Packit 5c3484
C 744x,745x (G4+):   6
Packit 5c3484
C power4/ppc970:    12
Packit 5c3484
C power5:            ?
Packit 5c3484
Packit 5c3484
C void mpn_divexact_by3 (mp_ptr dst, mp_srcptr src, mp_size_t size);
Packit 5c3484
C
Packit 5c3484
C We avoid the slow subfe instruction and instead rely on an extremely unlikely
Packit 5c3484
C branch.
Packit 5c3484
C
Packit 5c3484
C The mullw has the inverse in the first operand, since 0xAA..AB won't allow
Packit 5c3484
C any early-out.  The src[] data normally won't either, but there's at least
Packit 5c3484
C a chance, whereas 0xAA..AB never will.  If, for instance, src[] is all
Packit 5c3484
C zeros (not a sensible input of course) we run at 7.0 c/l on ppc750.
Packit 5c3484
C
Packit 5c3484
C The mulhwu has the "3" multiplier in the second operand, which lets 750 and
Packit 5c3484
C 7400 use an early-out.
Packit 5c3484
Packit 5c3484
C INPUT PARAMETERS
Packit 5c3484
define(`rp', `r3')
Packit 5c3484
define(`up', `r4')
Packit 5c3484
define(`n',  `r5')
Packit 5c3484
define(`cy', `r6')
Packit 5c3484
Packit 5c3484
ASM_START()
Packit 5c3484
PROLOGUE(mpn_divexact_by3c)
Packit 5c3484
	lwz	r11, 0(up)
Packit 5c3484
	mtctr	n
Packit 5c3484
	lis	r12, 0xAAAA
Packit 5c3484
	ori	r12, r12, 0xAAAB
Packit 5c3484
	li	r10, 3
Packit 5c3484
Packit 5c3484
	cmplw	cr7, cy, r11
Packit 5c3484
	subf	r11, cy, r11
Packit 5c3484
Packit 5c3484
	mullw	r0, r11, r12
Packit 5c3484
	stw	r0, 0(rp)
Packit 5c3484
	bdz	L(one)
Packit 5c3484
Packit 5c3484
L(top):	lwzu	r9, 4(up)
Packit 5c3484
	mulhwu	r7, r0, r10
Packit 5c3484
	bgt-	cr7, L(adj)		C very unlikely branch
Packit 5c3484
L(bko):	cmplw	cr7, r7, r9
Packit 5c3484
	subf	r0, r7, r9
Packit 5c3484
	mullw	r0, r12, r0
Packit 5c3484
	stwu	r0, 4(rp)
Packit 5c3484
	bdnz	L(top)
Packit 5c3484
Packit 5c3484
L(one):	mulhwu	r3, r0, r10
Packit 5c3484
	blelr+	cr7
Packit 5c3484
	addi	r3, r3, 1
Packit 5c3484
	blr
Packit 5c3484
Packit 5c3484
L(adj):	addi	r7, r7, 1
Packit 5c3484
	b	L(bko)
Packit 5c3484
EPILOGUE()
Packit 5c3484
ASM_END()