aboutsummaryrefslogtreecommitdiff
path: root/vendor/gmp-6.3.0/mpn/sparc32/v9/mul_1.asm
blob: 40aeffad4f31568415c17448b601cf8038ec5e2a (plain) (blame)
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
dnl  SPARC v9 32-bit mpn_mul_1 -- Multiply a limb vector with a limb and store
dnl  the result in a second limb vector.

dnl  Copyright 1998, 2000, 2001, 2003 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 Algorithm: We use two floating-point multiplies per limb product, with the
C invariant v operand split into two 16-bit pieces, and the u operand split
C into 32-bit pieces.  We convert the two 48-bit products and transfer them to
C the integer unit.

C		   cycles/limb
C UltraSPARC 1&2:     6.5
C UltraSPARC 3:	      ?

C Possible optimizations:
C   1. Combine 32-bit memory operations into 64-bit operations.  Since we're
C      memory bandwidth limited, this could save 1.5 cycles/limb.
C   2. Unroll the inner loop.  Since we already use alternate temporary areas,
C      it is very straightforward to unroll, using an exit branch midways.
C      Unrolling would allow deeper scheduling which could improve speed for L2
C      cache case.
C   3. For mpn_mul_1: Use more alternating temp areas.  The std'es and ldx'es
C      aren't sufficiently apart-scheduled with just two temp areas.
C   4. Specialize for particular v values.  If its upper 16 bits are zero, we
C      could save many operations.

C INPUT PARAMETERS
C rp	i0
C up	i1
C n	i2
C v	i3

define(`FSIZE',224)

ASM_START()
PROLOGUE(mpn_mul_1)
	add	%sp, -FSIZE, %sp
	sethi	%hi(0xffff), %g1
	srl	%o3, 16, %g2
	or	%g1, %lo(0xffff), %g1
	and	%o3, %g1, %g1
	stx	%g1, [%sp+104]
	stx	%g2, [%sp+112]
	ldd	[%sp+104], %f6
	ldd	[%sp+112], %f8
	fxtod	%f6, %f6
	fxtod	%f8, %f8
	ld	[%sp+104], %f10		C zero f10

	mov	0, %g3			C cy = 0

define(`fanop', `fitod %f18, %f0')	C  A quasi nop running in the FA pipe

	add	%sp, 160, %o5		C point in scratch area
	and	%o5, -32, %o5		C align at 0 (mod 32) in scratch area

	subcc	%o2, 1, %o2
	ld	[%o1], %f11		C read up[i]
	add	%o1, 4, %o1		C up++
	bne,pt	%icc, .L_two_or_more
	fxtod	%f10, %f2

	fmuld	%f2, %f8, %f16
	fmuld	%f2, %f6, %f4
	fdtox	%f16, %f14
	fdtox	%f4, %f12
	std	%f14, [%o5+16]
	std	%f12, [%o5+24]
	ldx	[%o5+16], %g2		C p16
	ldx	[%o5+24], %g1		C p0
	b	.L1
	add	%o0, -16, %o0

	.align	16
.L_two_or_more:
	subcc	%o2, 1, %o2
	ld	[%o1], %f11		C read up[i]
	fmuld	%f2, %f8, %f16
	fmuld	%f2, %f6, %f4
	add	%o1, 4, %o1		C up++
	bne,pt	%icc, .L_three_or_more
	fxtod	%f10, %f2

	fdtox	%f16, %f14
	fdtox	%f4, %f12
	std	%f14, [%o5+16]
	fmuld	%f2, %f8, %f16
	std	%f12, [%o5+24]
	fmuld	%f2, %f6, %f4
	fdtox	%f16, %f14
	fdtox	%f4, %f12
	std	%f14, [%o5+0]
	std	%f12, [%o5+8]
	ldx	[%o5+16], %g2		C p16
	ldx	[%o5+24], %g1		C p0
	b	.L2
	add	%o0, -12, %o0

	.align	16
.L_three_or_more:
	subcc	%o2, 1, %o2
	ld	[%o1], %f11		C read up[i]
	fdtox	%f16, %f14
	fdtox	%f4, %f12
	std	%f14, [%o5+16]
	fmuld	%f2, %f8, %f16
	std	%f12, [%o5+24]
	fmuld	%f2, %f6, %f4
	add	%o1, 4, %o1		C up++
	bne,pt	%icc, .L_four_or_more
	fxtod	%f10, %f2

	fdtox	%f16, %f14
	fdtox	%f4, %f12
	std	%f14, [%o5+0]
	fmuld	%f2, %f8, %f16
	std	%f12, [%o5+8]
	fmuld	%f2, %f6, %f4
	fdtox	%f16, %f14
	ldx	[%o5+16], %g2		C p16
	fdtox	%f4, %f12
	ldx	[%o5+24], %g1		C p0
	std	%f14, [%o5+16]
	std	%f12, [%o5+24]
	b	.L3
	add	%o0, -8, %o0

	.align	16
.L_four_or_more:
	subcc	%o2, 1, %o2
	ld	[%o1], %f11		C read up[i]
	fdtox	%f16, %f14
	fdtox	%f4, %f12
	std	%f14, [%o5+0]
	fmuld	%f2, %f8, %f16
	std	%f12, [%o5+8]
	fmuld	%f2, %f6, %f4
	add	%o1, 4, %o1		C up++
	bne,pt	%icc, .L_five_or_more
	fxtod	%f10, %f2

	fdtox	%f16, %f14
	ldx	[%o5+16], %g2		C p16
	fdtox	%f4, %f12
	ldx	[%o5+24], %g1		C p0
	std	%f14, [%o5+16]
	fmuld	%f2, %f8, %f16
	std	%f12, [%o5+24]
	fmuld	%f2, %f6, %f4
	add	%o1, 4, %o1		C up++
	b	.L4
	add	%o0, -4, %o0

	.align	16
.L_five_or_more:
	subcc	%o2, 1, %o2
	ld	[%o1], %f11		C read up[i]
	fdtox	%f16, %f14
	ldx	[%o5+16], %g2		C p16
	fdtox	%f4, %f12
	ldx	[%o5+24], %g1		C p0
	std	%f14, [%o5+16]
	fmuld	%f2, %f8, %f16
	std	%f12, [%o5+24]
	fmuld	%f2, %f6, %f4
	add	%o1, 4, %o1		C up++
	bne,pt	%icc, .Loop
	fxtod	%f10, %f2
	b,a	.L5

C BEGIN MAIN LOOP
	.align 16
C -- 0
.Loop:	nop
	subcc	%o2, 1, %o2
	ld	[%o1], %f11		C read up[i]
	fdtox	%f16, %f14
C -- 1
	sllx	%g2, 16, %g4		C (p16 << 16)
	add	%o0, 4, %o0		C rp++
	ldx	[%o5+0], %g2		C p16
	fdtox	%f4, %f12
C -- 2
	nop
	add	%g1, %g4, %g4		C p = p0 + (p16 << 16)
	ldx	[%o5+8], %g1		C p0
	fanop
C -- 3
	nop
	add	%g3, %g4, %g4		C p += cy
	std	%f14, [%o5+0]
	fmuld	%f2, %f8, %f16
C -- 4
	srlx	%g4, 32, %g3		C new cy
	add	%o1, 4, %o1		C up++
	std	%f12, [%o5+8]
	fmuld	%f2, %f6, %f4
C -- 5
	xor	%o5, 16, %o5		C alternate scratch variables
	stw	%g4, [%o0-4]
	bne,pt	%icc, .Loop
	fxtod	%f10, %f2
C END MAIN LOOP

.L5:	fdtox	%f16, %f14
	sllx	%g2, 16, %g4		C (p16 << 16)
	ldx	[%o5+0], %g2		C p16
	fdtox	%f4, %f12
	add	%g1, %g4, %g4		C p = p0 + (p16 << 16)
	ldx	[%o5+8], %g1		C p0
	add	%g4, %g3, %g4		C p += cy
	std	%f14, [%o5+0]
	fmuld	%f2, %f8, %f16
	std	%f12, [%o5+8]
	fmuld	%f2, %f6, %f4
	xor	%o5, 16, %o5
	stw	%g4, [%o0+0]
	srlx	%g4, 32, %g3		C new cy

.L4:	fdtox	%f16, %f14
	sllx	%g2, 16, %g4		C (p16 << 16)
	ldx	[%o5+0], %g2		C p16
	fdtox	%f4, %f12
	add	%g1, %g4, %g4		C p = p0 + (p16 << 16)
	ldx	[%o5+8], %g1		C p0
	add	%g3, %g4, %g4		C p += cy
	std	%f14, [%o5+0]
	std	%f12, [%o5+8]
	xor	%o5, 16, %o5
	stw	%g4, [%o0+4]
	srlx	%g4, 32, %g3		C new cy

.L3:	sllx	%g2, 16, %g4		C (p16 << 16)
	ldx	[%o5+0], %g2		C p16
	add	%g1, %g4, %g4		C p = p0 + (p16 << 16)
	ldx	[%o5+8], %g1		C p0
	add	%g3, %g4, %g4		C p += cy
	xor	%o5, 16, %o5
	stw	%g4, [%o0+8]
	srlx	%g4, 32, %g3		C new cy

.L2:	sllx	%g2, 16, %g4		C (p16 << 16)
	ldx	[%o5+0], %g2		C p16
	add	%g1, %g4, %g4		C p = p0 + (p16 << 16)
	ldx	[%o5+8], %g1		C p0
	add	%g3, %g4, %g4		C p += cy
	stw	%g4, [%o0+12]
	srlx	%g4, 32, %g3		C new cy

.L1:	sllx	%g2, 16, %g4		C (p16 << 16)
	add	%g1, %g4, %g4		C p = p0 + (p16 << 16)
	add	%g3, %g4, %g4		C p += cy
	stw	%g4, [%o0+16]
	srlx	%g4, 32, %g3		C new cy

	mov	%g3, %o0
	retl
	sub	%sp, -FSIZE, %sp
EPILOGUE(mpn_mul_1)