xref: /netbsd-src/external/lgpl3/gmp/dist/mpn/powerpc64/mode64/mode1o.asm (revision 3587d6f89c746bbb4f886219ddacd41ace480ecf)
1dnl  PowerPC-64 mpn_modexact_1_odd -- mpn by limb exact remainder.
2
3dnl  Copyright 2006 Free Software Foundation, Inc.
4
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 modify
8dnl  it under the terms of either:
9dnl
10dnl    * the GNU Lesser General Public License as published by the Free
11dnl      Software Foundation; either version 3 of the License, or (at your
12dnl      option) any later version.
13dnl
14dnl  or
15dnl
16dnl    * the GNU General Public License as published by the Free Software
17dnl      Foundation; either version 2 of the License, or (at your option) any
18dnl      later version.
19dnl
20dnl  or both in parallel, as here.
21dnl
22dnl  The GNU MP Library is distributed in the hope that it will be useful, but
23dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25dnl  for more details.
26dnl
27dnl  You should have received copies of the GNU General Public License and the
28dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
29dnl  see https://www.gnu.org/licenses/.
30
31include(`../config.m4')
32
33C                  cycles/limb
34C POWER3/PPC630        13-19
35C POWER4/PPC970         16
36C POWER5                16
37C POWER6                 ?
38C POWER7                12
39
40C TODO
41C  * Check if n=1 code is really an improvement.  It probably isn't.
42C  * Make more similar to dive_1.asm.
43
44C INPUT PARAMETERS
45define(`up', `r3')
46define(`n',  `r4')
47define(`d',  `r5')
48define(`cy', `r6')
49
50
51ASM_START()
52
53EXTERN(binvert_limb_table)
54
55PROLOGUE(mpn_modexact_1c_odd,toc)
56	addic.	n, n, -1		C set carry as side effect
57	ld	r8, 0(up)
58	bne	cr0, L(2)
59	cmpld	cr7, r6, r8
60	bge	cr7, L(4)
61	subf	r8, r6, r8
62	divdu	r3, r8, d
63	mulld	r3, r3, d
64	subf.	r3, r3, r8
65	beqlr	cr0
66	subf	r3, r3, d
67	blr
68
69L(4):	subf	r3, r8, r6
70	divdu	r8, r3, d
71	mulld	r8, r8, d
72	subf	r3, r8, r3
73	blr
74
75L(2):	LEA(	r7, binvert_limb_table)
76	rldicl	r9, d, 63, 57
77	mtctr	n
78	lbzx	r0, r7, r9
79	mulld	r7, r0, r0
80	sldi	r0, r0, 1
81	mulld	r7, d, r7
82	subf	r0, r7, r0
83	mulld	r9, r0, r0
84	sldi	r0, r0, 1
85	mulld	r9, d, r9
86	subf	r0, r9, r0
87	mulld	r7, r0, r0
88	sldi	r0, r0, 1
89	mulld	r7, d, r7
90	subf	r9, r7, r0
91
92	ALIGN(16)
93L(loop):
94	subfe	r0, r6, r8
95	ld	r8, 8(up)
96	addi	up, up, 8
97	mulld	r0, r9, r0
98	mulhdu	r6, r0, d
99	bdnz	L(loop)
100
101	cmpld	cr7, d, r8
102	blt	cr7, L(10)
103
104	subfe	r0, r0, r0
105	subf	r6, r0, r6
106	cmpld	cr7, r6, r8
107	subf	r3, r8, r6
108	bgelr	cr7
109	add	r3, d, r3
110	blr
111
112L(10):	subfe	r0, r6, r8
113	mulld	r0, r9, r0
114	mulhdu	r3, r0, d
115	blr
116EPILOGUE()
117ASM_END()
118