1dnl  PowerPC-64 mpn_addlshC_n, mpn_sublshC_n, mpn_rsblshC_n.
2
3dnl  Copyright 2003, 2005, 2009, 2010, 2013 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
31C                  cycles/limb
32C POWER3/PPC630          ?
33C POWER4/PPC970          ?
34C POWER5                 ?
35C POWER6                 ?
36C POWER7                 2.5
37
38C INPUT PARAMETERS
39define(`rp', `r3')
40define(`up', `r4')
41define(`vp', `r5')
42define(`n',  `r6')
43
44ifdef(`DO_add', `
45  define(`ADDSUBC',	`addc	$1, $2, $3')
46  define(`ADDSUBE',	`adde	$1, $2, $3')
47  define(INITCY,	`addic	$1, r1, 0')
48  define(RETVAL,	`addze	r3, $1')
49  define(`func',	mpn_addlsh`'LSH`'_n)')
50ifdef(`DO_sub', `
51  define(`ADDSUBC',	`subfc	$1, $2, $3')
52  define(`ADDSUBE',	`subfe	$1, $2, $3')
53  define(INITCY,	`addic	$1, r1, -1')
54  define(RETVAL,	`subfze	r3, $1
55			neg	r3, r3')
56  define(`func',	mpn_sublsh`'LSH`'_n)')
57ifdef(`DO_rsb', `
58  define(`ADDSUBC',	`subfc	$1, $3, $2')
59  define(`ADDSUBE',	`subfe	$1, $3, $2')
60  define(INITCY,	`addic	$1, r1, -1')
61  define(RETVAL,	`addme	r3, $1')
62  define(`func',	mpn_rsblsh`'LSH`'_n)')
63
64define(`s0', `r0')  define(`s1', `r9')
65define(`u0', `r6')  define(`u1', `r7')
66define(`v0', `r10') define(`v1', `r11')
67
68
69ASM_START()
70PROLOGUE(func)
71	rldic	r7, n, 3, 59
72	add	up, up, r7
73	add	vp, vp, r7
74	add	rp, rp, r7
75
76ifdef(`DO_add', `
77	addic	r0, n, 3	C set cy flag as side effect
78',`
79	subfc	r0, r0, r0	C set cy flag
80	addi	r0, n, 3
81')
82	srdi	r0, r0, 2
83	mtctr	r0
84
85	andi.	r0, n, 1
86	beq	L(bx0)
87
88L(bx1):	andi.	r0, n, 2
89	li	s0, 0
90	bne	L(lo3)
91	b	L(lo1)
92
93L(bx0):	andi.	r0, n, 2
94	li	s1, 0
95	bne	L(lo2)
96
97	ALIGN(32)
98L(top):	addi	rp, rp, 32
99	ld	v0, 0(vp)
100	addi	vp, vp, 32
101	rldimi	s1, v0, LSH, 0
102	ld	u0, 0(up)
103	addi	up, up, 32
104	srdi	s0, v0, RSH
105	ADDSUBE(s1, s1, u0)
106	std	s1, -32(rp)
107L(lo3):	ld	v1, -24(vp)
108	rldimi	s0, v1, LSH, 0
109	ld	u1, -24(up)
110	srdi	s1, v1, RSH
111	ADDSUBE(s0, s0, u1)
112	std	s0, -24(rp)
113L(lo2):	ld	v0, -16(vp)
114	rldimi	s1, v0, LSH, 0
115	ld	u0, -16(up)
116	srdi	s0, v0, RSH
117	ADDSUBE(s1, s1, u0)
118	std	s1, -16(rp)
119L(lo1):	ld	v1, -8(vp)
120	rldimi	s0, v1, LSH, 0
121	ld	u1, -8(up)
122	srdi	s1, v1, RSH
123	ADDSUBE(s0, s0, u1)
124	std	s0, -8(rp)
125	bdnz	L(top)		C decrement CTR and loop back
126
127	RETVAL(	s1)
128	blr
129EPILOGUE()
130