mult.s
5.19 KB
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
310
311
312
313
314
315
/*
* mult.s Mon Apr 25 13:06:24 PDT 1994
*
* this is a simple RSP program that tests the permutations of
* multiplies that you might want to do...
*
* Notation:
* I - signed integer
* F - unsigned fraction
* SF - signed fraction
*
* so 'IF' is a 32-bit number: a 16-bit signed integer with a 16-bit
* unsigned fraction.
*
* Notice that since multiplication is communitive, I have not
* bothered to layout the possibilities with the terms reversed.
*
*/
#
# define some symbolic registers to make this clearer: (I hope)
#
.name s_int, $v2
.name s_frac, $v3
.name t_int, $v4
.name t_frac, $v5
.name res_int, $v6
.name res_frac, $v7
.name dev_null, $v0
.name vconst, $v31
.name in_base, $20
.name in_sip, $21
.name in_sfp, $22
.name in_tip, $23
.name in_tfp, $24
.name out_ip, $25
.name out_fp, $26
#define TASKDATABASE 0x0000
.base 0x04001000
vxor vconst, vconst, vconst
addi in_base, $0, TASKDATABASE
addi in_sip, in_base, 0 # s int
addi in_sfp, in_base, 2 # s frac
addi in_tip, in_base, 4 # t int
addi in_tfp, in_base, 6 # t frac
addi out_ip, in_base, 16 # result hi
addi out_fp, in_base, 18 # result lo
addi $1, $0, 1
mtc2 $0, vconst[2]
mtc2 $1, vconst[2]
addi $1, $0, 2
mtc2 $1, vconst[4]
addi $1, $0, 2
mtc2 $1, vconst[6]
main: # get s and t:
lsv s_int[0], 0(in_sip)
lsv s_frac[0], 0(in_sfp)
lsv t_int[0], 0(in_tip)
lsv t_frac[0], 0(in_tfp)
nop
nop
nop
nop
#
# enable the one you want to test:
#
# jal IFxIF
# jal IFxI
# jal IxIF
# jal IFxF
# jal IxI
# jal IxF
# jal FxF
# jal SFxSF
# jal SFxI
jal SFxIF
nop
break
nop
IFxIF:
#
# double precision multiply:
# IF * IF = IF
#
vmudl res_frac, s_frac, t_frac
vmadm res_frac, s_int, t_frac
vmadn res_frac, s_frac, t_int
vmadh res_int, s_int, t_int # leaves answer-lo in res_frac
vmadn res_frac, dev_null, dev_null[0]# 'extra' nop mult gets answer-hi
# store 32-bit answer...
nop
nop
nop
nop
nop
ssv res_int[0], 0(out_ip) # store the hi I
ssv res_frac[0], 0(out_fp) # store the lo F
jr $31
nop
IFxI:
#
# mixed precision multiply:
# IF * I = IF
#
vmudn res_frac, s_frac, t_int
vmadh res_int, s_int, t_int # leaves answer-hi in res_int
vmadn res_frac, dev_null, dev_null[0]# 'extra' nop mult gets answer-lo
# store 32-bit answer...
ssv res_int[0], 0(out_ip) # store the hi I
ssv res_frac[0], 0(out_fp) # store the lo F
nop
nop
jr $31
nop
IxIF:
#
# mixed precision multiply:
# I * IF = IF
#
vmudm res_frac, s_int, t_frac
vmadh res_int, s_int, t_int
vmadn res_frac, dev_null, dev_null[0]
# store 32-bit answer...
ssv res_int[0], 0(out_ip) # store the hi I
ssv res_frac[0], 0(out_fp) # store the lo F
nop
nop
jr $31
nop
IFxF:
#
# mixed precision multiply: (what about signed F?)
# IF * F = IF
#
vmudl res_frac, s_frac, t_frac
vmadm res_int, s_int, t_frac
vmadn res_frac, dev_null, dev_null[0]
# store 32-bit answer...
ssv res_int[0], 0(out_ip) # store the hi I
ssv res_frac[0], 0(out_fp) # store the lo F
nop
nop
jr $31
nop
IxI:
#
# single precision integer multiply:
# I * I = I
#
vmudh res_int, s_int, t_int
# store 16-bit answer...
ssv res_int[0], 0(out_ip) # store the hi I
nop
nop
jr $31
nop
IxF:
#
# single precision multiply: (what about signed F?)
# I * F = IF
#
vmudm res_int, s_int, t_frac
vmadn res_frac, dev_null, dev_null[0]
# store 32-bit answer...
ssv res_int[0], 0(out_ip) # store the hi I
ssv res_frac[0], 0(out_fp) # store the lo F
nop
nop
jr $31
nop
FxF:
#
# single precision (unsigned fractional) multiply:
# F * F = F
#
vmudl res_frac, s_frac, t_frac # this does the work
# store 16-bit answer...
ssv res_frac[0], 0(out_ip) # store the lo F
nop
nop
jr $31
nop
SFxSF:
#
# single precision (signed fractional) multiply:
# SF * SF = SF
#
vmulf res_frac, s_frac, t_frac
# store 16-bit answer...
ssv res_frac[0], 0(out_ip) # store the lo F
nop
nop
jr $31
nop
SFxI:
#
# single precision (signed fractional) multiply:
# I * SF = IF
# S15. * .S15 = S15.16
#
#if 0
mfc2 $1, t_frac[0]
sll $1, $1, 16
sra $1, $1, 15
mtc2 $1, t_frac[0]
sra $1, $1, 16
mtc2 $1, t_int[0]
vmudn res_frac, t_frac, s_int
vmadh res_int, t_int, s_int # leaves answer-hi in res_int
vmadn res_frac, dev_null, dev_null[0]# 'extra' nop mult gets answer-lo
#endif
#if 0
# vmudl res_frac, s_frac, vconst[0]
vmudm res_int, s_frac, t_int
vmadn res_frac, vconst, vconst[0]
#endif
vmudh dev_null, s_frac, t_int
vsaw res_int, res_int, res_int[0]
vsaw res_frac, res_frac, res_frac[1]
nop
nop
nop
nop
nop
break
# store 32-bit answer...
ssv res_int[0], 0(out_ip) # store the hi I
ssv res_frac[0], 0(out_fp) # store the lo F
nop
break
nop
nop
jr $31
nop
SFxIF:
#
# mixed precision (signed fractional) multiply:
# IF * SF = IF
# S15.16 * .S15 = S15.16
#
# make s S15.16
vmudm s_int, s_frac, vconst[2]
vmadn s_frac, vconst, vconst[0]
nop
nop
nop
nop
# multiply s by t
vmudl res_frac, s_frac, t_frac
vmadm res_frac, s_int, t_frac
vmadn res_frac, s_frac, t_int
vmadh res_int, s_int, t_int
nop
nop
nop
nop
nop
nop
break
nop
nop
#
# what about unsigned fractions? vmulu
#