power_enums: sync forms
[openpower-isa.git] / openpower / isa / simplev.mdwn
1 <!-- This defines Draft SVP64 instructions to augment PowerISA Version 3.0 -->
2 <!-- These are not described in book 1 -->
3
4 # svstep
5
6 SVL-Form
7
8 * svstep RT,SVi,vf (Rc=0)
9 * svstep. RT,SVi,vf (Rc=1)
10
11 Pseudo-code:
12
13 if SVi[3:4] = 0b11 then
14 # store pack and unpack in SVSTATE
15 SVSTATE[53] <- SVi[5]
16 SVSTATE[54] <- SVi[6]
17 RT <- [0]*62 || SVSTATE[53:54]
18 else
19 step <- SVSTATE_NEXT(SVi, vf)
20 RT <- [0]*57 || step
21
22 Special Registers Altered:
23
24 CR0 (if Rc=1)
25
26 # setvl
27
28 SVL-Form
29
30 * setvl RT,RA,SVi,vf,vs,ms (Rc=0)
31 * setvl. RT,RA,SVi,vf,vs,ms (Rc=1)
32
33 Pseudo-code:
34
35 overflow <- 0b0
36 VLimm <- SVi + 1
37 # set or get MVL
38 if ms = 1 then MVL <- VLimm[0:6]
39 else MVL <- SVSTATE[0:6]
40 # set or get VL
41 if vs = 0 then VL <- SVSTATE[7:13]
42 else if _RA != 0 then
43 if (RA) >u 0b1111111 then
44 VL <- 0b1111111
45 overflow <- 0b1
46 else VL <- (RA)[57:63]
47 else if _RT = 0 then VL <- VLimm[0:6]
48 else if CTR >u 0b1111111 then
49 VL <- 0b1111111
50 overflow <- 0b1
51 else VL <- CTR[57:63]
52 # limit VL to within MVL
53 if VL >u MVL then
54 overflow <- 0b1
55 VL <- MVL
56 SVSTATE[0:6] <- MVL
57 SVSTATE[7:13] <- VL
58 if _RT != 0 then
59 GPR(_RT) <- [0]*57 || VL
60 # MAXVL is a static "state-reset".
61 if ms = 1 then
62 SVSTATE[63] <- vf # set Vertical-First mode
63 SVSTATE[62] <- 0b0 # clear persist bit
64
65 Special Registers Altered:
66
67 CR0 (if Rc=1)
68
69 # svremap
70
71 SVRM-Form
72
73 * svremap SVme,mi0,mi1,mi2,mo0,mo1,pst
74
75 Pseudo-code:
76
77 # registers RA RB RC RT EA/FRS SVSHAPE0-3 indices
78 SVSTATE[32:33] <- mi0
79 SVSTATE[34:35] <- mi1
80 SVSTATE[36:37] <- mi2
81 SVSTATE[38:39] <- mo0
82 SVSTATE[40:41] <- mo1
83 # enable bit for RA RB RC RT EA/FRS
84 SVSTATE[42:46] <- SVme
85 # persistence bit (applies to more than one instruction)
86 SVSTATE[62] <- pst
87
88 Special Registers Altered:
89
90 None
91
92 # svshape
93
94 SVM-Form
95
96 * svshape SVxd,SVyd,SVzd,SVrm,vf
97
98 Pseudo-code:
99
100 # for convenience, VL to be calculated and stored in SVSTATE
101 vlen <- [0] * 7
102 mscale[0:5] <- 0b000001 # for scaling MAXVL
103 itercount[0:6] <- [0] * 7
104 SVSTATE[0:31] <- [0] * 32
105 # only overwrite REMAP if "persistence" is zero
106 if (SVSTATE[62] = 0b0) then
107 SVSTATE[32:33] <- 0b00
108 SVSTATE[34:35] <- 0b00
109 SVSTATE[36:37] <- 0b00
110 SVSTATE[38:39] <- 0b00
111 SVSTATE[40:41] <- 0b00
112 SVSTATE[42:46] <- 0b00000
113 SVSTATE[62] <- 0b0
114 SVSTATE[63] <- 0b0
115 # clear out all SVSHAPEs
116 SVSHAPE0[0:31] <- [0] * 32
117 SVSHAPE1[0:31] <- [0] * 32
118 SVSHAPE2[0:31] <- [0] * 32
119 SVSHAPE3[0:31] <- [0] * 32
120 # set schedule up for multiply
121 if (SVrm = 0b0000) then
122 # VL in Matrix Multiply is xd*yd*zd
123 xd <- (0b00 || SVxd) + 1
124 yd <- (0b00 || SVyd) + 1
125 zd <- (0b00 || SVzd) + 1
126 n <- xd * yd * zd
127 vlen[0:6] <- n[14:20]
128 # set up template in SVSHAPE0, then copy to 1-3
129 SVSHAPE0[0:5] <- (0b0 || SVxd) # xdim
130 SVSHAPE0[6:11] <- (0b0 || SVyd) # ydim
131 SVSHAPE0[12:17] <- (0b0 || SVzd) # zdim
132 SVSHAPE0[28:29] <- 0b11 # skip z
133 # copy
134 SVSHAPE1[0:31] <- SVSHAPE0[0:31]
135 SVSHAPE2[0:31] <- SVSHAPE0[0:31]
136 SVSHAPE3[0:31] <- SVSHAPE0[0:31]
137 # set up FRA
138 SVSHAPE1[18:20] <- 0b001 # permute x,z,y
139 SVSHAPE1[28:29] <- 0b01 # skip z
140 # FRC
141 SVSHAPE2[18:20] <- 0b001 # permute x,z,y
142 SVSHAPE2[28:29] <- 0b11 # skip y
143 # set schedule up for FFT butterfly
144 if (SVrm = 0b0001) then
145 # calculate O(N log2 N)
146 n <- [0] * 3
147 do while n < 5
148 if SVxd[4-n] = 0 then
149 leave
150 n <- n + 1
151 n <- ((0b0 || SVxd) + 1) * n
152 vlen[0:6] <- n[1:7]
153 # set up template in SVSHAPE0, then copy to 1-3
154 # for FRA and FRT
155 SVSHAPE0[0:5] <- (0b0 || SVxd) # xdim
156 SVSHAPE0[12:17] <- (0b0 || SVzd) # zdim - "striding" (2D FFT)
157 mscale <- (0b0 || SVzd) + 1
158 SVSHAPE0[30:31] <- 0b01 # Butterfly mode
159 # copy
160 SVSHAPE1[0:31] <- SVSHAPE0[0:31]
161 SVSHAPE2[0:31] <- SVSHAPE0[0:31]
162 # set up FRB and FRS
163 SVSHAPE1[28:29] <- 0b01 # j+halfstep schedule
164 # FRC (coefficients)
165 SVSHAPE2[28:29] <- 0b10 # k schedule
166 # set schedule up for (i)DCT Inner butterfly
167 # SVrm Mode 4 (Mode 12 for iDCT) is for on-the-fly (Vertical-First Mode)
168 if ((SVrm = 0b0100) |
169 (SVrm = 0b1100)) then
170 # calculate O(N log2 N)
171 n <- [0] * 3
172 do while n < 5
173 if SVxd[4-n] = 0 then
174 leave
175 n <- n + 1
176 n <- ((0b0 || SVxd) + 1) * n
177 vlen[0:6] <- n[1:7]
178 # set up template in SVSHAPE0, then copy to 1-3
179 # set up FRB and FRS
180 SVSHAPE0[0:5] <- (0b0 || SVxd) # xdim
181 SVSHAPE0[12:17] <- (0b0 || SVzd) # zdim - "striding" (2D DCT)
182 mscale <- (0b0 || SVzd) + 1
183 if (SVrm = 0b1100) then
184 SVSHAPE0[30:31] <- 0b11 # iDCT mode
185 SVSHAPE0[18:20] <- 0b011 # iDCT Inner Butterfly sub-mode
186 else
187 SVSHAPE0[30:31] <- 0b01 # DCT mode
188 SVSHAPE0[18:20] <- 0b001 # DCT Inner Butterfly sub-mode
189 SVSHAPE0[21:23] <- 0b001 # "inverse" on outer loop
190 SVSHAPE0[6:11] <- 0b000011 # (i)DCT Inner Butterfly mode 4
191 # copy
192 SVSHAPE1[0:31] <- SVSHAPE0[0:31]
193 SVSHAPE2[0:31] <- SVSHAPE0[0:31]
194 if (SVrm != 0b0100) & (SVrm != 0b1100) then
195 SVSHAPE3[0:31] <- SVSHAPE0[0:31]
196 # for FRA and FRT
197 SVSHAPE0[28:29] <- 0b01 # j+halfstep schedule
198 # for cos coefficient
199 SVSHAPE2[28:29] <- 0b10 # ci (k for mode 4) schedule
200 SVSHAPE2[12:17] <- 0b000000 # reset costable "striding" to 1
201 if (SVrm != 0b0100) & (SVrm != 0b1100) then
202 SVSHAPE3[28:29] <- 0b11 # size schedule
203 # set schedule up for (i)DCT Outer butterfly
204 if (SVrm = 0b0011) | (SVrm = 0b1011) then
205 # calculate O(N log2 N) number of outer butterfly overlapping adds
206 vlen[0:6] <- [0] * 7
207 n <- 0b000
208 size <- 0b0000001
209 itercount[0:6] <- (0b00 || SVxd) + 0b0000001
210 itercount[0:6] <- (0b0 || itercount[0:5])
211 do while n < 5
212 if SVxd[4-n] = 0 then
213 leave
214 n <- n + 1
215 count <- (itercount - 0b0000001) * size
216 vlen[0:6] <- vlen + count[7:13]
217 size[0:6] <- (size[1:6] || 0b0)
218 itercount[0:6] <- (0b0 || itercount[0:5])
219 # set up template in SVSHAPE0, then copy to 1-3
220 # set up FRB and FRS
221 SVSHAPE0[0:5] <- (0b0 || SVxd) # xdim
222 SVSHAPE0[12:17] <- (0b0 || SVzd) # zdim - "striding" (2D DCT)
223 mscale <- (0b0 || SVzd) + 1
224 if (SVrm = 0b1011) then
225 SVSHAPE0[30:31] <- 0b11 # iDCT mode
226 SVSHAPE0[18:20] <- 0b011 # iDCT Outer Butterfly sub-mode
227 SVSHAPE0[21:23] <- 0b101 # "inverse" on outer and inner loop
228 else
229 SVSHAPE0[30:31] <- 0b01 # DCT mode
230 SVSHAPE0[18:20] <- 0b100 # DCT Outer Butterfly sub-mode
231 SVSHAPE0[6:11] <- 0b000010 # DCT Butterfly mode
232 # copy
233 SVSHAPE1[0:31] <- SVSHAPE0[0:31] # j+halfstep schedule
234 SVSHAPE2[0:31] <- SVSHAPE0[0:31] # costable coefficients
235 # for FRA and FRT
236 SVSHAPE1[28:29] <- 0b01 # j+halfstep schedule
237 # reset costable "striding" to 1
238 SVSHAPE2[12:17] <- 0b000000
239 # set schedule up for DCT COS table generation
240 if (SVrm = 0b0101) | (SVrm = 0b1101) then
241 # calculate O(N log2 N)
242 vlen[0:6] <- [0] * 7
243 itercount[0:6] <- (0b00 || SVxd) + 0b0000001
244 itercount[0:6] <- (0b0 || itercount[0:5])
245 n <- [0] * 3
246 do while n < 5
247 if SVxd[4-n] = 0 then
248 leave
249 n <- n + 1
250 vlen[0:6] <- vlen + itercount
251 itercount[0:6] <- (0b0 || itercount[0:5])
252 # set up template in SVSHAPE0, then copy to 1-3
253 # set up FRB and FRS
254 SVSHAPE0[0:5] <- (0b0 || SVxd) # xdim
255 SVSHAPE0[12:17] <- (0b0 || SVzd) # zdim - "striding" (2D DCT)
256 mscale <- (0b0 || SVzd) + 1
257 SVSHAPE0[30:31] <- 0b01 # DCT/FFT mode
258 SVSHAPE0[6:11] <- 0b000100 # DCT Inner Butterfly COS-gen mode
259 if (SVrm = 0b0101) then
260 SVSHAPE0[21:23] <- 0b001 # "inverse" on outer loop for DCT
261 # copy
262 SVSHAPE1[0:31] <- SVSHAPE0[0:31]
263 SVSHAPE2[0:31] <- SVSHAPE0[0:31]
264 # for cos coefficient
265 SVSHAPE1[28:29] <- 0b10 # ci schedule
266 SVSHAPE2[28:29] <- 0b11 # size schedule
267 # set schedule up for iDCT / DCT inverse of half-swapped ordering
268 if (SVrm = 0b0110) | (SVrm = 0b1110) | (SVrm = 0b1111) then
269 vlen[0:6] <- (0b00 || SVxd) + 0b0000001
270 # set up template in SVSHAPE0
271 SVSHAPE0[0:5] <- (0b0 || SVxd) # xdim
272 SVSHAPE0[12:17] <- (0b0 || SVzd) # zdim - "striding" (2D DCT)
273 mscale <- (0b0 || SVzd) + 1
274 if (SVrm = 0b1110) then
275 SVSHAPE0[18:20] <- 0b001 # DCT opposite half-swap
276 if (SVrm = 0b1111) then
277 SVSHAPE0[30:31] <- 0b01 # FFT mode
278 else
279 SVSHAPE0[30:31] <- 0b11 # DCT mode
280 SVSHAPE0[6:11] <- 0b000101 # DCT "half-swap" mode
281 # set schedule up for parallel reduction
282 if (SVrm = 0b0111) then
283 # calculate the total number of operations (brute-force)
284 vlen[0:6] <- [0] * 7
285 itercount[0:6] <- (0b00 || SVxd) + 0b0000001
286 step[0:6] <- 0b0000001
287 i[0:6] <- 0b0000000
288 do while step <u itercount
289 newstep <- step[1:6] || 0b0
290 j[0:6] <- 0b0000000
291 do while (j+step <u itercount)
292 j <- j + newstep
293 i <- i + 1
294 step <- newstep
295 # VL in Parallel-Reduce is the number of operations
296 vlen[0:6] <- i
297 # set up template in SVSHAPE0, then copy to 1. only 2 needed
298 SVSHAPE0[0:5] <- (0b0 || SVxd) # xdim
299 SVSHAPE0[12:17] <- (0b0 || SVzd) # zdim - "striding" (2D DCT)
300 mscale <- (0b0 || SVzd) + 1
301 SVSHAPE0[30:31] <- 0b10 # parallel reduce submode
302 # copy
303 SVSHAPE1[0:31] <- SVSHAPE0[0:31]
304 # set up right operand (left operand 28:29 is zero)
305 SVSHAPE1[28:29] <- 0b01 # right operand
306 # set VL, MVL and Vertical-First
307 m[0:12] <- vlen * mscale
308 maxvl[0:6] <- m[6:12]
309 SVSTATE[0:6] <- maxvl # MAVXL
310 SVSTATE[7:13] <- vlen # VL
311 SVSTATE[63] <- vf
312
313 Special Registers Altered:
314
315 None
316
317 # svindex
318
319 SVI-Form
320
321 * svindex SVG,rmm,SVd,ew,SVyx,mm,sk
322
323 Pseudo-code:
324
325 # based on nearest MAXVL compute other dimension
326 MVL <- SVSTATE[0:6]
327 d <- [0] * 6
328 dim <- SVd+1
329 do while d*dim <u ([0]*4 || MVL)
330 d <- d + 1
331 # set up template, then copy once location identified
332 shape <- [0]*32
333 shape[30:31] <- 0b00 # mode
334 if SVyx = 0 then
335 shape[18:20] <- 0b110 # indexed xd/yd
336 shape[0:5] <- (0b0 || SVd) # xdim
337 if sk = 0 then shape[6:11] <- 0 # ydim
338 else shape[6:11] <- 0b111111 # ydim max
339 else
340 shape[18:20] <- 0b111 # indexed yd/xd
341 if sk = 1 then shape[6:11] <- 0 # ydim
342 else shape[6:11] <- d-1 # ydim max
343 shape[0:5] <- (0b0 || SVd) # ydim
344 shape[12:17] <- (0b0 || SVG) # SVGPR
345 shape[28:29] <- ew # element-width override
346 shape[21] <- sk # skip 1st dimension
347 # select the mode for updating SVSHAPEs
348 SVSTATE[62] <- mm # set or clear persistence
349 if mm = 0 then
350 # clear out all SVSHAPEs first
351 SVSHAPE0[0:31] <- [0] * 32
352 SVSHAPE1[0:31] <- [0] * 32
353 SVSHAPE2[0:31] <- [0] * 32
354 SVSHAPE3[0:31] <- [0] * 32
355 SVSTATE[32:41] <- [0] * 10 # clear REMAP.mi/o
356 SVSTATE[42:46] <- rmm # rmm exactly REMAP.SVme
357 idx <- 0
358 for bit = 0 to 4
359 if rmm[4-bit] then
360 # activate requested shape
361 if idx = 0 then SVSHAPE0 <- shape
362 if idx = 1 then SVSHAPE1 <- shape
363 if idx = 2 then SVSHAPE2 <- shape
364 if idx = 3 then SVSHAPE3 <- shape
365 SVSTATE[bit*2+32:bit*2+33] <- idx
366 # increment shape index, modulo 4
367 if idx = 3 then idx <- 0
368 else idx <- idx + 1
369 else
370 # refined SVSHAPE/REMAP update mode
371 bit <- rmm[0:2]
372 idx <- rmm[3:4]
373 if idx = 0 then SVSHAPE0 <- shape
374 if idx = 1 then SVSHAPE1 <- shape
375 if idx = 2 then SVSHAPE2 <- shape
376 if idx = 3 then SVSHAPE3 <- shape
377 SVSTATE[bit*2+32:bit*2+33] <- idx
378 SVSTATE[46-bit] <- 1
379
380 Special Registers Altered:
381
382 None
383
384 # svshape2
385
386 SVM2-Form
387
388 * svshape2 SVo,SVyx,rmm,SVd,sk,mm
389
390 Pseudo-code:
391
392 # based on nearest MAXVL compute other dimension
393 MVL <- SVSTATE[0:6]
394 d <- [0] * 6
395 dim <- SVd+1
396 do while d*dim <u ([0]*4 || MVL)
397 d <- d + 1
398 # set up template, then copy once location identified
399 shape <- [0]*32
400 shape[30:31] <- 0b00 # mode
401 shape[0:5] <- (0b0 || SVd) # x/ydim
402 if SVyx = 0 then
403 shape[18:20] <- 0b000 # ordering xd/yd(/zd)
404 if sk = 0 then shape[6:11] <- 0 # ydim
405 else shape[6:11] <- 0b111111 # ydim max
406 else
407 shape[18:20] <- 0b010 # ordering yd/xd(/zd)
408 if sk = 1 then shape[6:11] <- 0 # ydim
409 else shape[6:11] <- d-1 # ydim max
410 # offset (the prime purpose of this instruction)
411 shape[24:27] <- SVo # offset
412 if sk = 1 then shape[28:29] <- 0b01 # skip 1st dimension
413 else shape[28:29] <- 0b00 # no skipping
414 # select the mode for updating SVSHAPEs
415 SVSTATE[62] <- mm # set or clear persistence
416 if mm = 0 then
417 # clear out all SVSHAPEs first
418 SVSHAPE0[0:31] <- [0] * 32
419 SVSHAPE1[0:31] <- [0] * 32
420 SVSHAPE2[0:31] <- [0] * 32
421 SVSHAPE3[0:31] <- [0] * 32
422 SVSTATE[32:41] <- [0] * 10 # clear REMAP.mi/o
423 SVSTATE[42:46] <- rmm # rmm exactly REMAP.SVme
424 idx <- 0
425 for bit = 0 to 4
426 if rmm[4-bit] then
427 # activate requested shape
428 if idx = 0 then SVSHAPE0 <- shape
429 if idx = 1 then SVSHAPE1 <- shape
430 if idx = 2 then SVSHAPE2 <- shape
431 if idx = 3 then SVSHAPE3 <- shape
432 SVSTATE[bit*2+32:bit*2+33] <- idx
433 # increment shape index, modulo 4
434 if idx = 3 then idx <- 0
435 else idx <- idx + 1
436 else
437 # refined SVSHAPE/REMAP update mode
438 bit <- rmm[0:2]
439 idx <- rmm[3:4]
440 if idx = 0 then SVSHAPE0 <- shape
441 if idx = 1 then SVSHAPE1 <- shape
442 if idx = 2 then SVSHAPE2 <- shape
443 if idx = 3 then SVSHAPE3 <- shape
444 SVSTATE[bit*2+32:bit*2+33] <- idx
445 SVSTATE[46-bit] <- 1
446
447 Special Registers Altered:
448
449 None
450