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