github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/mpn/powerpc32/diveby3.asm (about)

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