vpack.c
5.49 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
/**************************************************************************
* *
* Copyright (C) 1994, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
*************************************************************************/
/*
* File: vpack.c
* Creator: hsa@sgi.com
* Create Date: Tue Mar 8 11:00:56 PST 1994
*
* This file holds the pack instructions for the VU.
*
*/
#include <stdio.h>
#include "rsp.h"
#include "i128.h"
#include "rspctl.h"
#include "opcode.h"
#include "vu.h"
#include "trace_print.h"
rsp_vuPipe_t vu_PackPipe[rsp_VUPIPEDEPTH+1];
/*
* decode and execute a pack instruction
*/
static void
rsp_VUPackExec(rsp_vuPipe_t *mp)
{
boolean dopack;
int op, nib, i, fshift, nibsize[4], index, hi, lo;
u16 du;
u32 t32; /* for macro usage */
/* decode instruction */
op = ExtractBits(mp->inst, 5, 0);
mp->format = ExtractBits(mp->inst, 24, 21);
mp->rt = ExtractBits(mp->inst, 20, 16);
mp->rs = ExtractBits(mp->inst, 15, 11);
mp->rd = ExtractBits(mp->inst, 10, 6);
switch (mp->format) {
case 0x01:
nib = 0;
break;
case 0x02:
nib = 1;
break;
case 0x04:
nib = 2;
break;
case 0x08:
nib = 3;
break;
default:
fprintf(stderr,"bad element for vins/vext [%02x]\n",mp->format);
break;
}
dopack = TRUE;
fshift = 0;
nibsize[0] = nibsize[1] = nibsize[2] = nibsize[3] = 4;
switch (op) {
case rsp_VEXTT:
dopack = FALSE; /* fall through */
case rsp_VINST:
fshift = 10;
nibsize[0] = nibsize[1] = nibsize[2] = 5;
nibsize[3] = 1;
break;
case rsp_VEXTQ:
dopack = FALSE; /* fall through */
case rsp_VINSQ:
fshift = 11;
break;
case rsp_VEXTN:
dopack = FALSE; /* fall through */
case rsp_VINSN:
break;
}
rsp_VURegLock(mp->rd, mp->pc);
/* check for stall. If okay, execute and decrement delay field */
if (rsp_VURegIsLocked(mp->rs, mp->pc)) {
/* can't do anything right now... */
mp->stalled = TRUE;
rsp_VUStalled = TRUE;
rsp_Verbose(stderr,"VU pack stalled... (%08x)\n",mp->pc);
} else {
/* execute */
index = 16; /* pick out nibble */
for (i=0; i<=nib; i++)
index -= nibsize[i];
lo = index;
hi = index + nibsize[nib] - 1;
if (dopack) {
/*
Set128(&(mp->result), &(rsp_VUR[mp->rd]));
*/
for (i=0; i<8; i++) { /* do all vector elements */
du = (u32) Get128By16(&(rsp_VUR[mp->rs]), i);
du >>= fshift; /* move to right place in dest */
/* fix up special cases */
if (op == rsp_VINST && nib == 3) {
du >>= 4; /* fix alpha bit */
}
du &= ((0x01 << nibsize[nib])-1); /* clean up upper bits */
t32 = (u32) Get128By16(&(rsp_VUR[mp->rt]), i);
LoadField(t32, hi, lo, du);
Set128By16(&(mp->result), (u16) t32, i);
}
} else {
for (i=0; i<8; i++) { /* all elements */
t32 = (u32) Get128By16(&(rsp_VUR[mp->rs]), i);
du = ExtractBits(t32, hi, lo);
du <<= fshift; /* move to right place in dest */
/* fix up special cases */
if (op == rsp_VEXTN) { /* do sign-extend for nibble */
if (du & 0x08)
du |= 0xfff8;
} else if (op == rsp_VEXTT && nib == 3) {
du <<= 4; /* fix alpha bit */
}
Set128By16(&(mp->result), (u16) du, i);
}
}
mp->stalled = FALSE;
mp->delay--;
}
}
/* PUBLIC FUNCTIONS */
/*
* check pack pipeline for stalls
* returns TRUE is stalled.
*/
boolean
rsp_VUPackCheckStall(void)
{
int i;
for (i=0; i<rsp_VUPIPEDEPTH; i++) {
if (vu_PackPipe[i].delay > 0 && vu_PackPipe[i].stalled)
return TRUE;
}
return FALSE;
}
/*
* install a VU instruction into the pipeline
*/
void
rsp_VUPackInstall(u32 inst, u32 pc)
{
int i;
for (i=0; i<rsp_VUPIPEDEPTH; i++) {
if (vu_PackPipe[i].delay == 0 || VUZeroPipe) {
vu_PackPipe[i].inst = inst;
vu_PackPipe[i].pc = pc;
vu_PackPipe[i].delay = (VUZeroPipe) ? 1 : rsp_VUPIPEDEPTH;
vu_PackPipe[i].stalled = FALSE;
if (VUZeroPipe) rsp_VUPackPipeStep();
break;
}
}
}
/*
* this function is called once per clock, advances the pack
* pipeline one step.
*/
boolean
rsp_VUPackPipeStep(void)
{
int i;
/* advance all the things in the pipe */
for (i=0; i<rsp_VUPIPEDEPTH; i++) {
if (vu_PackPipe[i].delay > 0) {
if (vu_PackPipe[i].delay == rsp_VUPIPE_STAGE_EX || VUZeroPipe) {
/* do decode and exec, if possible */
rsp_VUPackExec(&(vu_PackPipe[i]));
} else {
/*
* fakes pipelining by waiting to write-back answer
*/
if (rsp_VUStalled==FALSE ||
vu_PackPipe[i].delay<rsp_VUPIPE_STAGE_EX)
vu_PackPipe[i].delay--;
}
if (vu_PackPipe[i].delay == rsp_VUPIPE_STAGE_WB) {
/* do write-back */
rsp_Verbose(stderr,"VU PACK did write-back. (v%d)\n",
vu_PackPipe[i].rd);
rsp_VUR[vu_PackPipe[i].rd] = vu_PackPipe[i].result;
traceVUbyVU(vu_PackPipe[i].rd,0xff,&(vu_PackPipe[i].result),
vu_PackPipe[i].pc);
/* mark registers not in use */
rsp_VURegUnLock(vu_PackPipe[i].rd, vu_PackPipe[i].pc);
}
}
}
}