xref: /netbsd-src/external/lgpl3/gmp/dist/mpn/powerpc64/mode64/p9/mul_1.asm (revision b2c35e17b976cf7ccd7250c86c6f5e95090ed636)
1dnl  Power9 mpn_mul_1.
2
3dnl  Copyright 2017, 2018 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		 ?
35C POWER4/PPC970		 ?
36C POWER5		 ?
37C POWER6		 ?
38C POWER7		 ?
39C POWER8		 ?
40C POWER9		 2.47
41
42C TODO
43C  * Schedule for Power9 pipeline.
44C  * Unroll 4x if that proves beneficial.
45C  * This is marginally faster (but much smaller) than ../mul_1.asm.
46
47C INPUT PARAMETERS
48define(`rp', `r3')
49define(`up', `r4')
50define(`n',  `r5')
51define(`v0', `r6')
52
53ASM_START()
54PROLOGUE(mpn_mul_1c)
55	b	L(ent)
56EPILOGUE()
57PROLOGUE(mpn_mul_1)
58	li	r7, 0
59L(ent):	ld	r11, 0(up)
60	cmpdi	cr6, n, 2
61	addi	r0, n, -1	C FIXME: postpone
62	srdi	r0, r0, 1	C FIXME: postpone
63	mtctr	r0		C FIXME: postpone
64	rldicl.	r12, n, 0,63	C r0 = n & 3, set cr0
65	bne	cr0, L(b1)
66
67L(b0):	ld	r0, 8(up)
68	maddld(	r9, r11, v0, r7)
69	maddhdu(r7, r11, v0, r7)
70	ble	cr6, L(2)
71	ld	r12, 16(up)
72	mulld	r8, r0, v0
73	mulhdu	r5, r0, v0
74	addic	up, up, 16
75	addi	rp, rp, -8
76	b	L(mid)
77
78L(b1):	ld	r0, 0(up)
79	ble	cr6, L(1)
80	ld	r12, 8(up)
81	maddld(	r8, r11, v0, r7)
82	maddhdu(r5, r11, v0, r7)
83	ld	r0, 16(up)
84	mulld	r9, r12, v0
85	mulhdu	r7, r12, v0
86	addic	up, up, 24
87	bdz	L(end)
88
89	ALIGN(16)
90L(top):	ld	r12, 0(up)
91	std	r8, 0(rp)
92	adde	r9, r5, r9
93	mulld	r8, r0, v0
94	mulhdu	r5, r0, v0
95L(mid):	ld	r0, 8(up)
96	std	r9, 8(rp)
97	adde	r8, r7, r8
98	mulld	r9, r12, v0
99	mulhdu	r7, r12, v0
100	addi	rp, rp, 16
101	addi	up, up, 16
102	bdnz	L(top)
103
104L(end):	std	r8, 0(rp)
105	mulld	r8, r0, v0
106	adde	r9, r5, r9
107	mulhdu	r5, r0, v0
108	std	r9, 8(rp)
109	adde	r8, r7, r8
110	std	r8, 16(rp)
111	addze	r3, r5
112	blr
113
114L(2):	mulld	r8, r0, v0
115	mulhdu	r5, r0, v0
116	std	r9, 0(rp)
117	addc	r8, r7, r8
118	std	r8, 8(rp)
119	addze	r3, r5
120	blr
121
122L(1):	maddld(	r8,  r0, v0, r7)
123	std	r8, 0(rp)
124	maddhdu(r3, r0, v0, r7)
125	blr
126EPILOGUE()
127