1dnl  PowerPC-64 mpn_add_n_sub_n optimised for POWER9.
2
3dnl  Copyright 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.25
41
42
43C INPUT PARAMETERS
44define(`arp',	`r3')
45define(`srp',	`r4')
46define(`up',	`r5')
47define(`vp',	`r6')
48define(`n',	`r7')
49
50ASM_START()
51PROLOGUE(mpn_add_n_sub_n)
52	cmpdi	cr7, n, 2
53	subfo	r0, r0, r0		C clear OV
54	rldicl.	r9, n, 0, 63		C n & 1
55	beq	cr0, L(bx0)
56
57L(bx1):	ld	r10, 0(up)
58	ld	r11, 0(vp)
59	ble	cr7, L(1)
60	srdi	r7, r7, 1
61	mtctr	r7
62	ld	r8, 8(up)
63	ld	r9, 8(vp)
64	addex(	r0, r10, r11, 0)
65	subfc	r12, r11, r10
66	addi	up, up, -8
67	addi	vp, vp, -8
68	b	L(lo1)
69
70L(bx0):	ld	r8, 0(up)
71	ld	r9, 0(vp)
72	ld	r10, 8(up)
73	ld	r11, 8(vp)
74	addex(	r0, r8, r9, 0)
75	subfc	r12, r9, r8
76	addi	arp, arp, 8
77	addi	srp, srp, 8
78	ble	cr7, L(end)
79	addi	r7, r7, -1
80	srdi	r7, r7, 1
81	mtctr	r7
82
83L(top):	ld	r8, 16(up)
84	ld	r9, 16(vp)
85	std	r0, -8(arp)
86	std	r12, -8(srp)
87	addex(	r0, r10, r11, 0)
88	subfe	r12, r11, r10
89L(lo1):	ld	r10, 24(up)
90	ld	r11, 24(vp)
91	std	r0, 0(arp)
92	std	r12, 0(srp)
93	addex(	r0, r8, r9, 0)
94	subfe	r12, r9, r8
95	addi	up, up, 16
96	addi	vp, vp, 16
97	addi	arp, arp, 16
98	addi	srp, srp, 16
99	bdnz	L(top)
100
101L(end):	std	r0, -8(arp)
102	std	r12, -8(srp)
103L(1):	addex(	r0, r10, r11, 0)
104	subfe	r12, r11, r10
105	std	r0, 0(arp)
106	std	r12, 0(srp)
107	subfe	r3, r3, r3
108	addex(	r3, r3, r3, 0)
109	rldicl	r3, r3, 1, 62
110	blr
111EPILOGUE()
112ASM_END()
113