summaryrefslogtreecommitdiff
path: root/mpi/alpha/mpih-shift.S
blob: dcf0a1f46e1d0203e571cd519c858989b67534d7 (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
/* alpha    rshift, lshift
 *	Copyright (C) 1994, 1995 Free Software Foundation, Inc.
 *	Copyright (c) 1997 by Werner Koch (dd9jn)
 *
 * This file is part of G10.
 *
 * G10 is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * G10 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 *
 * Note: This code is heavily based on the GNU MP Library.
 *	 Actually it's the same code with only minor changes in the
 *	 way the data is stored; this is to support the abstraction
 *	 of an optional secure memory allocation which may be used
 *	 to avoid revealing of sensitive data due to paging etc.
 *	 The GNU MP Library itself is published under the LGPL;
 *	 however I decided to publish this code under the plain GPL.
 */



/*******************
 * mpi_limb_t
 * mpihelp_lshift( mpi_ptr_t wp,	(r16)
 *		   mpi_ptr_t up,	(r17)
 *		   mpi_size_t usize,	(r18)
 *		   unsigned cnt)	(r19)
 *
 * This code runs at 4.8 cycles/limb on the 21064.  With infinite unrolling,
 * it would take 4 cycles/limb.  It should be possible to get down to 3
 * cycles/limb since both ldq and stq can be paired with the other used
 * instructions.  But there are many restrictions in the 21064 pipeline that
 * makes it hard, if not impossible, to get down to 3 cycles/limb:
 *
 * 1. ldq has a 3 cycle delay, srl and sll have a 2 cycle delay.
 * 2. Only aligned instruction pairs can be paired.
 * 3. The store buffer or silo might not be able to deal with the bandwidth.
 */

	.set	noreorder
	.set	noat
.text
	.align	3
	.globl	mpihelp_lshift
	.ent	mpihelp_lshift
mpihelp_lshift:
	.frame	$30,0,$26,0

	s8addq	$18,$17,$17	# make r17 point at end of s1
	ldq	$4,-8($17)	# load first limb
	subq	$17,8,$17
	subq	$31,$19,$7
	s8addq	$18,$16,$16	# make r16 point at end of RES
	subq	$18,1,$18
	and	$18,4-1,$20	# number of limbs in first loop
	srl	$4,$7,$0	# compute function result

	beq	$20,.L0
	subq	$18,$20,$18

	.align	3
.Loop0:
	ldq	$3,-8($17)
	subq	$16,8,$16
	subq	$17,8,$17
	subq	$20,1,$20
	sll	$4,$19,$5
	srl	$3,$7,$6
	bis	$3,$3,$4
	bis	$5,$6,$8
	stq	$8,0($16)
	bne	$20,.Loop0

.L0:	beq	$18,.Lend

	.align	3
.Loop:	ldq	$3,-8($17)
	subq	$16,32,$16
	subq	$18,4,$18
	sll	$4,$19,$5
	srl	$3,$7,$6

	ldq	$4,-16($17)
	sll	$3,$19,$1
	bis	$5,$6,$8
	stq	$8,24($16)
	srl	$4,$7,$2

	ldq	$3,-24($17)
	sll	$4,$19,$5
	bis	$1,$2,$8
	stq	$8,16($16)
	srl	$3,$7,$6

	ldq	$4,-32($17)
	sll	$3,$19,$1
	bis	$5,$6,$8
	stq	$8,8($16)
	srl	$4,$7,$2

	subq	$17,32,$17
	bis	$1,$2,$8
	stq	$8,0($16)

	bgt	$18,.Loop

.Lend:	sll	$4,$19,$8
	stq	$8,-8($16)
	ret	$31,($26),1
	.end	mpihelp_lshift





/*******************
 * mpi_limb_t
 * mpihelp_rshift( mpi_ptr_t wp,	(r16)
 *		   mpi_ptr_t up,	(r17)
 *		   mpi_size_t usize,	(r18)
 *		   unsigned cnt)	(r19)
 *
 * This code runs at 4.8 cycles/limb on the 21064.  With infinite unrolling,
 * it would take 4 cycles/limb.  It should be possible to get down to 3
 * cycles/limb since both ldq and stq can be paired with the other used
 * instructions.  But there are many restrictions in the 21064 pipeline that
 * makes it hard, if not impossible, to get down to 3 cycles/limb:
 *
 * 1. ldq has a 3 cycle delay, srl and sll have a 2 cycle delay.
 * 2. Only aligned instruction pairs can be paired.
 * 3. The store buffer or silo might not be able to deal with the bandwidth.
 */

	.set	noreorder
	.set	noat
.text
	.align	3
	.globl	mpihelp_rshift
	.ent	mpihelp_rshift
mpihelp_rshift:
	.frame	$30,0,$26,0

	ldq	$4,0($17)	# load first limb
	addq	$17,8,$17
	subq	$31,$19,$7
	subq	$18,1,$18
	and	$18,4-1,$20	# number of limbs in first loop
	sll	$4,$7,$0	# compute function result

	beq	$20,.R0
	subq	$18,$20,$18

	.align	3
.Roop0:
	ldq	$3,0($17)
	addq	$16,8,$16
	addq	$17,8,$17
	subq	$20,1,$20
	srl	$4,$19,$5
	sll	$3,$7,$6
	bis	$3,$3,$4
	bis	$5,$6,$8
	stq	$8,-8($16)
	bne	$20,.Roop0

.R0:	beq	$18,.Rend

	.align	3
.Roop:	ldq	$3,0($17)
	addq	$16,32,$16
	subq	$18,4,$18
	srl	$4,$19,$5
	sll	$3,$7,$6

	ldq	$4,8($17)
	srl	$3,$19,$1
	bis	$5,$6,$8
	stq	$8,-32($16)
	sll	$4,$7,$2

	ldq	$3,16($17)
	srl	$4,$19,$5
	bis	$1,$2,$8
	stq	$8,-24($16)
	sll	$3,$7,$6

	ldq	$4,24($17)
	srl	$3,$19,$1
	bis	$5,$6,$8
	stq	$8,-16($16)
	sll	$4,$7,$2

	addq	$17,32,$17
	bis	$1,$2,$8
	stq	$8,-8($16)

	bgt	$18,.Roop

.Rend:	srl	$4,$19,$8
	stq	$8,0($16)
	ret	$31,($26),1
	.end	mpihelp_rshift