summaryrefslogtreecommitdiff
path: root/gmp/mpn/ia64/add_n_sub_n.asm
blob: 34a506568f59b6ee5740d0d118569ce367351dff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
dnl  IA-64 mpn_add_n_sub_n -- mpn parallel addition and subtraction.

dnl  Contributed to the GNU project by Torbjorn Granlund.

dnl  Copyright 2010 Free Software Foundation, Inc.

dnl  This file is part of the GNU MP Library.
dnl
dnl  The GNU MP Library is free software; you can redistribute it and/or modify
dnl  it under the terms of either:
dnl
dnl    * the GNU Lesser General Public License as published by the Free
dnl      Software Foundation; either version 3 of the License, or (at your
dnl      option) any later version.
dnl
dnl  or
dnl
dnl    * the GNU General Public License as published by the Free Software
dnl      Foundation; either version 2 of the License, or (at your option) any
dnl      later version.
dnl
dnl  or both in parallel, as here.
dnl
dnl  The GNU MP Library is distributed in the hope that it will be useful, but
dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dnl  for more details.
dnl
dnl  You should have received copies of the GNU General Public License and the
dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
dnl  see https://www.gnu.org/licenses/.

include(`../config.m4')

C           cycles/limb
C Itanium:      ?
C Itanium 2:    2.25

C INPUT PARAMETERS
define(`sp', `r32')
define(`dp', `r33')
define(`up', `r34')
define(`vp', `r35')
define(`n',  `r36')

C Some useful aliases for registers we use
define(`u0',`r16') define(`u1',`r17') define(`u2',`r18') define(`u3',`r19')
define(`v0',`r20') define(`v1',`r21') define(`v2',`r22') define(`v3',`r23')
define(`s0',`r24') define(`s1',`r25') define(`s2',`r26') define(`s3',`r27')
define(`d0',`r28') define(`d1',`r29') define(`d2',`r30') define(`d3',`r31')
define(`up0',`up')
define(`up1',`r14')
define(`vp0',`vp')
define(`vp1',`r15')

define(`cmpltu',  `cmp.ltu')
define(`cmpeqor', `cmp.eq.or')

ASM_START()
PROLOGUE(mpn_add_n_sub_n)
	.prologue
	.save	ar.lc, r2
	.body
ifdef(`HAVE_ABI_32',`
	addp4	sp = 0, sp		C				M I
	addp4	dp = 0, dp		C				M I
	nop.i	0
	addp4	up = 0, up		C				M I
	addp4	vp = 0, vp		C				M I
	zxt4	n = n			C				I
	;;
')

	and	r9 = 3, n		C				M I
	mov.i	r2 = ar.lc		C				I0
	add	up1 = 8, up0		C				M I
	add	vp1 = 8, vp0		C				M I
	add	r8 = -2, n		C				M I
	add	r10 = 256, up		C				M I
	;;
	shr.u	r8 = r8, 2		C				I0
	cmp.eq	p10, p0 = 0, r9		C				M I
	cmp.eq	p11, p0 = 2, r9		C				M I
	cmp.eq	p12, p0 = 3, r9		C				M I
	add	r11 = 256, vp		C				M I
	;;
	mov.i	ar.lc = r8		C				I0
  (p10)	br	L(b0)			C				B
  (p11)	br	L(b2)			C				B
  (p12)	br	L(b3)			C				B

L(b1):	ld8	u3 = [up0], 8		C				M01
	add	up1 = 8, up1		C				M I
	cmpltu	p14, p15 = 4, n		C				M I
	ld8	v3 = [vp0], 8		C				M01
	add	vp1 = 8, vp1		C				M I
	;;
	add	s3 = u3, v3		C				M I
	sub	d3 = u3, v3		C				M I
	mov	r8 = 0			C				M I
	;;
	cmpltu	p9, p0 = s3, v3		C  carry from add3		M I
	cmpltu	p13, p0 = u3, v3	C borrow from sub3		M I
  (p15)	br	L(cj1)			C				B
	st8	[sp] = s3, 8		C				M23
	st8	[dp] = d3, 8		C				M23
	br	L(c0)			C				B

L(b0):	cmp.ne	p9, p0 = r0, r0		C				M I
	cmp.ne	p13, p0 = r0, r0	C				M I
L(c0):	ld8	u0 = [up0], 16		C				M01
	ld8	u1 = [up1], 16		C				M01
	;;
	ld8	v0 = [vp0], 16		C				M01
	ld8	v1 = [vp1], 16		C				M01
	;;
	ld8	u2 = [up0], 16		C				M01
	ld8	u3 = [up1], 16		C				M01
	;;
	ld8	v2 = [vp0], 16		C				M01
	ld8	v3 = [vp1], 16		C				M01
	;;
	add	s0 = u0, v0		C				M I
	add	s1 = u1, v1		C				M I
	sub	d0 = u0, v0		C				M I
	sub	d1 = u1, v1		C				M I
	;;
	cmpltu	p6, p0 = s0, v0		C  carry from add0		M I
	cmpltu	p7, p0 = s1, v1		C  carry from add1		M I
	cmpltu	p10, p0 = u0, v0	C borrow from sub0		M I
	cmpltu	p11, p0 = u1, v1	C borrow from sub1		M I
	;;
	nop	0			C
	br.cloop.dptk	L(top)		C				B
	br	L(end)			C				B

L(b3):	ld8	u1 = [up0], 8		C				M01
	add	up1 = 8, up1		C				M I
	ld8	v1 = [vp0], 8		C				M01
	;;
	add	vp1 = 8, vp1		C				M I
	add	s1 = u1, v1		C				M I
	sub	d1 = u1, v1		C				M I
	;;
	cmpltu	p7, p0 = s1, v1		C  carry from add1		M I
	cmpltu	p11, p0 = u1, v1	C borrow from sub1		M I
	;;
	st8	[sp] = s1, 8		C				M23
	st8	[dp] = d1, 8		C				M23
	br	L(c2)			C				B

	ALIGN(32)
L(b2):	cmp.ne	p7, p0 = r0, r0		C				M I
	cmp.ne	p11, p0 = r0, r0	C				M I
	nop	0
L(c2):	ld8	u2 = [up0], 16		C				M01
	ld8	u3 = [up1], 16		C				M01
	cmpltu	p14, p0 = 4, n		C				M I
	;;
	ld8	v2 = [vp0], 16		C				M01
	ld8	v3 = [vp1], 16		C				M01
  (p14)	br	L(gt4)			C				B
	;;
	add	s2 = u2, v2		C				M I
	add	s3 = u3, v3		C				M I
	sub	d2 = u2, v2		C				M I
	sub	d3 = u3, v3		C				M I
	;;
	cmpltu	p8, p0 = s2, v2		C  carry from add0		M I
	cmpltu	p9, p0 = s3, v3		C  carry from add3		M I
	cmpltu	p12, p0 = u2, v2	C borrow from sub2		M I
	cmpltu	p13, p0 = u3, v3	C borrow from sub3		M I
	br	L(cj2)			C				B
	;;
L(gt4):	ld8	u0 = [up0], 16		C				M01
	ld8	u1 = [up1], 16		C				M01
	;;
	ld8	v0 = [vp0], 16		C				M01
	ld8	v1 = [vp1], 16		C				M01
	;;
	add	s2 = u2, v2		C				M I
	add	s3 = u3, v3		C				M I
	sub	d2 = u2, v2		C				M I
	sub	d3 = u3, v3		C				M I
	;;
	cmpltu	p8, p0 = s2, v2		C  carry from add0		M I
	cmpltu	p9, p0 = s3, v3		C  carry from add1		M I
	cmpltu	p12, p0 = u2, v2	C borrow from sub0		M I
	cmpltu	p13, p0 = u3, v3	C borrow from sub1		M I
	br.cloop.dptk	L(mid)		C				B

	ALIGN(32)
L(top):
	ld8	u0 = [up0], 16		C				M01
	ld8	u1 = [up1], 16		C				M01
   (p9)	cmpeqor	p6, p0 = -1, s0		C				M I
   (p9)	add	s0 = 1, s0		C				M I
  (p13)	cmpeqor	p10, p0 = 0, d0		C				M I
  (p13)	add	d0 = -1, d0		C				M I
	;;
	ld8	v0 = [vp0], 16		C				M01
	ld8	v1 = [vp1], 16		C				M01
   (p6)	cmpeqor	p7, p0 = -1, s1		C				M I
   (p6)	add	s1 = 1, s1		C				M I
  (p10)	cmpeqor	p11, p0 = 0, d1		C				M I
  (p10)	add	d1 = -1, d1		C				M I
	;;
	st8	[sp] = s0, 8		C				M23
	st8	[dp] = d0, 8		C				M23
	add	s2 = u2, v2		C				M I
	add	s3 = u3, v3		C				M I
	sub	d2 = u2, v2		C				M I
	sub	d3 = u3, v3		C				M I
	;;
	st8	[sp] = s1, 8		C				M23
	st8	[dp] = d1, 8		C				M23
	cmpltu	p8, p0 = s2, v2		C  carry from add2		M I
	cmpltu	p9, p0 = s3, v3		C  carry from add3		M I
	cmpltu	p12, p0 = u2, v2	C borrow from sub2		M I
	cmpltu	p13, p0 = u3, v3	C borrow from sub3		M I
	;;
L(mid):
	ld8	u2 = [up0], 16		C				M01
	ld8	u3 = [up1], 16		C				M01
   (p7)	cmpeqor	p8, p0 = -1, s2		C				M I
   (p7)	add	s2 = 1, s2		C				M I
  (p11)	cmpeqor	p12, p0 = 0, d2		C				M I
  (p11)	add	d2 = -1, d2		C				M I
	;;
	ld8	v2 = [vp0], 16		C				M01
	ld8	v3 = [vp1], 16		C				M01
   (p8)	cmpeqor	p9, p0 = -1, s3		C				M I
   (p8)	add	s3 = 1, s3		C				M I
  (p12)	cmpeqor	p13, p0 = 0, d3		C				M I
  (p12)	add	d3 = -1, d3		C				M I
	;;
	st8	[sp] = s2, 8		C				M23
	st8	[dp] = d2, 8		C				M23
	add	s0 = u0, v0		C				M I
	add	s1 = u1, v1		C				M I
	sub	d0 = u0, v0		C				M I
	sub	d1 = u1, v1		C				M I
	;;
	st8	[sp] = s3, 8		C				M23
	st8	[dp] = d3, 8		C				M23
	cmpltu	p6, p0 = s0, v0		C  carry from add0		M I
	cmpltu	p7, p0 = s1, v1		C  carry from add1		M I
	cmpltu	p10, p0 = u0, v0	C borrow from sub0		M I
	cmpltu	p11, p0 = u1, v1	C borrow from sub1		M I
	;;
	lfetch	[r10], 32		C				M?
	lfetch	[r11], 32		C				M?
	br.cloop.dptk	L(top)		C				B
	;;

L(end):
	nop	0
	nop	0
   (p9)	cmpeqor	p6, p0 = -1, s0		C				M I
   (p9)	add	s0 = 1, s0		C				M I
  (p13)	cmpeqor	p10, p0 = 0, d0		C				M I
  (p13)	add	d0 = -1, d0		C				M I
	;;
	nop	0
	nop	0
   (p6)	cmpeqor	p7, p0 = -1, s1		C				M I
   (p6)	add	s1 = 1, s1		C				M I
  (p10)	cmpeqor	p11, p0 = 0, d1		C				M I
  (p10)	add	d1 = -1, d1		C				M I
	;;
	st8	[sp] = s0, 8		C				M23
	st8	[dp] = d0, 8		C				M23
	add	s2 = u2, v2		C				M I
	add	s3 = u3, v3		C				M I
	sub	d2 = u2, v2		C				M I
	sub	d3 = u3, v3		C				M I
	;;
	st8	[sp] = s1, 8		C				M23
	st8	[dp] = d1, 8		C				M23
	cmpltu	p8, p0 = s2, v2		C  carry from add2		M I
	cmpltu	p9, p0 = s3, v3		C  carry from add3		M I
	cmpltu	p12, p0 = u2, v2	C borrow from sub2		M I
	cmpltu	p13, p0 = u3, v3	C borrow from sub3		M I
	;;
L(cj2):
   (p7)	cmpeqor	p8, p0 = -1, s2		C				M I
   (p7)	add	s2 = 1, s2		C				M I
  (p11)	cmpeqor	p12, p0 = 0, d2		C				M I
  (p11)	add	d2 = -1, d2		C				M I
	mov	r8 = 0			C				M I
	nop	0
	;;
	st8	[sp] = s2, 8		C				M23
	st8	[dp] = d2, 8		C				M23
   (p8)	cmpeqor	p9, p0 = -1, s3		C				M I
   (p8)	add	s3 = 1, s3		C				M I
  (p12)	cmpeqor	p13, p0 = 0, d3		C				M I
  (p12)	add	d3 = -1, d3		C				M I
	;;
L(cj1):
   (p9)	mov	r8 = 2			C				M I
	;;
	mov.i	ar.lc = r2		C				I0
  (p13)	add	r8 = 1, r8		C				M I
	st8	[sp] = s3		C				M23
	st8	[dp] = d3		C				M23
	br.ret.sptk.many b0		C				B
EPILOGUE()
ASM_END()