(no commit message)
[libreriscv.git] / openpower / sv / po9_encoding / discussion.mdwn
1 [[!toc]]
2
3 # introduction
4
5 the purpose of this page is to create and evaluate alternative
6 encoding schemes that allow for a hybrid mixture of
7 (ultra-precious) 32-bit and 64-bit (actually `x86 REP`-like
8 prefixed) instructions.
9
10 a specific view to attaining high-speed massive-wide multi-issue decode
11 is a high priority. therefore especially length-detection must be kept
12 brutally simple.
13
14 **All evaluations point towards the original encoding proposed in the
15 very first revision of [[ls001]] as it is clear that all other decoders
16 are far too complex**. <a name="#sv_po9_ext2xx" />
17
18 # **superseded** alternative 32-64 encoding (1)
19
20 conflict to resolve: EXT90x and EXT232. they are indistinguishable.
21
22 ```
23 |0-5| 6-27 28 29|30-31|32|33-35|36-37| 38-59 | 60-63 | Description |
24 |---|-----|-----|-----|--|-----|-----|-------|-------|------------------|
25 |PO9| rm0 | 0 0 | 0 0 | 0 000 rm1 | xxxx | 0000 | SVP64:EXT900 |
26 |PO9| rm0 | 0 0 | 0 0 | 1 000 rm1 | xxxx | 0000 | SSingle:EXT900 |
27 |PO9| xxx | x 0 | 0 0 | x !zero0 | xxxx | !zero1| 55-bit RESERVED |
28 |PO9| xxx | 0 1 | 0 0 | 32-bit EXT900 (Vectorizable) |
29 |PO9| xxx | 1 1 | 0 0 | 32-bit EXT901 (Unvectorizable) |
30 |PO9| !ZERO | 0 0 | 1 | DWi | SSingle:EXT232-263 |
31 |PO9| 0000 | 0 0 | 1 | DWi | Scalar EXT232-263 |
32 |PO9| RM | 1 0 | 1 | DWi | SVP64:EXT232-263 |
33 |PO9| 0000 | 0 1 | Defined Word-instruction | 32-bit Unvec in 64b|
34 |PO9| !ZERO | 0 1 | Defined Word-instruction | SSingle:EXT000-063 |
35 |PO9| RM | 1 1 | Defined Word-instruction | SVP64:EXT000-063 |
36 ```
37
38 Fields:
39
40 * `RM`: 24-bit SVP64 prefix
41 * `RM <- rm0 || rm1` split field
42 * `!zero0 || !zero1` a split field that must not be zero
43
44 Length detection:
45
46 ```
47 if PO1 return 64
48 elif not PO9 return 32
49 elif Word[31] = 1 return 64
50 elif Word[29:30] = 0b10 return 32
51 elif Word[29:30] = 0b00 return 64
52 else return 32
53 ```
54
55 Instruction allocation restrictions:
56
57 * setvl is Unvectorizable but needs more space later: use 55-bit
58 * likewise svshape svindex and svshape2, all these need 32-bit
59 * svstep *is* Vectorizable but needs to be encoded 32-bit in order
60 to reduce loop-size
61 * space for 32-bit instructions is needed: some instructions
62 just make no sense if done as 64-bit because they **replace**
63 two 32-bit instructions.
64 * but those types of space-saving instructions
65 **also need to be Vectorizable**
66
67 # **superseded** alternative 32-64 encoding (2)
68
69 requires reducing SVP64Single to 23 bits. luckily there are 2 spare
70
71 the complexity of attempting to fit 32-bit instructions into
72 PO9 is very high. encoding (1) attempts to fit `setvl` etc. into
73 32-bit but it is very tight. the entire EXT900 area would be
74 taken up by the SVP64 Management instructions, below, defeating
75 the purpose of having it.
76
77 * `setvl` - Unvectorizable, EXT0xx, `RT RA CTR SVSTATE`, 6-bit XO (including Rc=1)
78 * `psetvl` - Unvectorizable, EXT1xx, ditto
79 * `svstep` - Vectorizable, either EXT900 (very precious) or EXT1xx (better), `RT, SVSTATE`, 6-bit XO (including Rc=1)
80 * `svindex` - Unvectorizable, EXT0xx, `SVSTATE,SVSHAPE0-3`, 5-bit XO
81 * `psvindex` - Unvectorizable, EXT1xx, ditto
82 * `svstep(2)` - Unvectorizable, EXT0xx, `SVSTATE,SVSHAPE0-3`, 5-bit XO
83 * `svstep(2)` - Unvectorizable, EXT1xx, ditto
84
85 ```
86 |0-5| 6-28|29 30 31|32|33-36|37 | 38-60 | 61-63 | Description |
87 |---|-----|--------|--|-----|---|-------|-------|------------------|
88 |PO9| rm0 | 1 0 0 | 0 0000 rm1| xxxx | 000 | SVP64:EXT900 |
89 |PO9|!ZERO| 1 0 0 | 0 1000 1 | xxxx | 000 | SSingle:EXT900 |
90 |PO9| xxx | 1 0 0 | 0 !zero0 | xxxx | !zero1| 55-bit RESERVED |
91 |PO9| xxx | 0 0 0 | 32-bit EXT900 |
92 |PO9|!ZERO| 1 0 0 | 1 | DWi | SSingle:EXT232-263 |
93 |PO9| 000 | 1 0 0 | 1 | DWi | Scalar EXT232-263 |
94 |PO9| nnnn | 1 0 | 1 | DWi | SVP64:EXT232-263 |
95 |PO9| 0000 | 0 1 | Defined Word-instruction | 32-bit Unvec in 64b|
96 |PO9|!ZERO | 0 1 | Defined Word-instruction | SSingle:EXT000-063 |
97 |PO9| nnnn | 1 1 | Defined Word-instruction | SVP64:EXT000-063 |
98 ```
99
100 Length detection:
101
102 ```
103 if PO1 return 64
104 elif not PO9 return 32
105 elif Word[29:31] = 0b000 return 32
106 else return 64
107 ```
108
109 # **revoked** alternative hybrid 32-64 encoding (3)
110
111 aim of this idea is to attempt simplification of area identification
112 and length. the 55-bit area is eliminated and may only be reintroduced
113 by sacrificing parts of EXT200-231, bear in mind that EXT240 is already
114 unavailable (used by EXT900).
115
116 ```
117 |0-5| 6-29 |30 31|32 |33-37 | 38-61 | 62-63 | Description |
118 |---|--------|-----|---|--------|-------|-------|------------------|
119 |PO9| xxxx | 0 0 | (next new instruction) | 32-bit EXT900 |
120 |PO9| 0000 | 1 0 | 0 | 10001 | //// | 00 | RESERVED |
121 |PO9| !ZERO | 1 0 | 0 | 10001 | xxxx | 00 | SSingle:EXT900 |
122 |PO9| SVRM | 1 0 | 0 | 10001 | xxxx | 01 | SVP64:EXT900 |
123 |PO9| //// | 1 0 | 0 | 10001 | //// | 10 | RESERVED |
124 |PO9| //// | 1 0 | 0 | 10001 | //// | 11 | RESERVED |
125 |PO9| !ZERO | 1 0 | 0 | !PO9 | xxxx | SSingle:EXT232-263 |
126 |PO9| 0000 | 1 0 | 0 | !PO9 | xxxx | Scalar EXT232-263 |
127 |PO9| SVRM | 1 0 | 1 | !PO9 | xxxx | SVP64:EXT232-263 |
128 |PO9| 0000 | 0 1 | Defined Word-instruction | 32-bit Unvec in 64b|
129 |PO9| !ZERO | 0 1 | Defined Word-instruction | SSingle:EXT000-063 |
130 |PO9| SVRM | 1 1 | Defined Word-instruction | SVP64:EXT000-063 |
131 ```
132
133 **Notes**:
134
135 * with `setvl` `svindex` `svshape` and `svshape2` being Unvectorizable Management
136 instructions requiring 6-bit `XO` and needing EXT1xx variants later, they are
137 best placed in EXT0xx. EXT900 is Vectorizable and extremely precious. Further
138 complication of Decode to create Vectorized EXT900 and Unvectorized EXT901
139 is inadviseable (rejected in alternative 1)
140 * EXT200-231 is intended to be partially-filled with LD/ST-Immediate-Postincrement
141 and it is strongly recommended that the exact same Primary Opcode be
142 used, matching the lower 5 bits. `lzbu` is EXT033, therefore `lzbup` is
143 recommended to be EXT233. This will greatly simplify Decode.
144 * With no "overlapping" Encodings permitted on top of EXT232-263 (except
145 EXT240) Speculative Decode may begin early in Multi-Issue systems safe
146 that for the most part the 32-bit instruction is either going to be
147 EXT0xx or EXT2xx, regardless of whether it is SVP64-Prefixed.
148 LD/ST-Immediate-Postincrement discernment from
149 LD/ST-Immediate is delayed, but Decode of other EXT232-263 operations
150 are *also delayed* pending identification.
151
152
153 **Identification**:
154
155 The following identification-criteria may be easily verified by taking
156 a copy of the table above and striking out each line that fails each
157 test. Only EXT000-063 is not by a "process of elimination" (if ... return True)
158
159 **Length detection**: (critically-important to be short)
160
161 ```
162 if PO1 return 64
163 elif not PO9 return 32
164 elif Word[30:31] = 0b00 return 32
165 else return 64
166 ```
167
168 **EXT232-263:**
169
170 ```
171 if not PO9 return False # eliminate EXT900
172 if Word[30:31] == 0b00 return False # eliminate EXT0xx
173 if Word[31] == 0b1 return False # eliminate EXT900 and reserved areas
174 if Word[33:37] != 0b10001 return False
175 return True
176 ```
177
178 **EXT900:**
179
180 ```
181 # easy first step
182 if not PO9 return False
183 # eliminate EXT0xx, 32-Unvec-in-64b
184 if Word[31] = 0b1 return False
185 # eliminate EXT2xx
186 if Word[30:31] = 0b10 and
187 Word[33:37] != 0b10001 return False
188 # eliminate currently-RESERVED areas
189 if Word[30:31] = 0b10 and
190 Word[62] = 0b1 return False
191 # eliminate final RESERVED area
192 if Word[30:31] = 0b10 and
193 Word[62:63] = 0b00 and
194 Word[6:29 ] = 0x000000 return False
195 # last-remaining is EXT900
196 return True
197 ```
198
199 **EXT000-063**: (includes Prefixed)
200
201 ```
202 if PO1 return False # or other reserved
203 if not PO9 return True # prefixed needs more
204 # eliminate EXT900
205 if Word[30:31] = 0b00 return False
206 # eliminate Prefixed-EXT900, RESERVED and EXT200
207 if Word[31] = 0b0 return False
208 # eliminate 32-bit Unvec in 64b area
209 if Word[30:31] = 0b01 and
210 Word[6:29 ] = 0x000000 return False
211 return True
212 ```
213
214 **SVP64**:
215
216 ```
217 # easy-elimination, first
218 if not PO9 return False
219 if Word[30] = 0b0 return False
220 # eliminate anything not SVP64:EXT900
221 if Word[30:31] = 0b10 and
222 Word[33:37] = 0b10001 and
223 Word[62:63] != 0b01 return False
224 # eliminate anything not SVP64:EXT200-231
225 if Word[31:32] = 0b00 return False
226 # all remaining combinations are SVP64:EXTnnn
227 return True
228 ```
229
230 **SVP64Single**:
231
232 ```
233 # easy-elimination, first
234 if not PO9 return False
235 # eliminate 32-bit EXT900
236 if Word[30:31] = 0b00 return False
237 # eliminate SVP64:EXT000-063
238 if Word[30:31] = 0b11 return False
239 # eliminate anything "Identity"
240 if Word[6:29 ] = 0x000000 return False
241 # eliminate SVP64:EXT200-231
242 if Word[30:32] = 0b101 return False
243 # eliminate anything not SSingle:EXT900
244 if Word[30:31] = 0b10 and
245 Word[33:37] = 0b10001 and
246 Word[62:63] != 0b00 return False
247 # everything left is SVP64Single
248 return True
249 ```
250
251 **RESERVED**: (no need to pass for further detailed decode)
252
253 ```
254 # easy-elimination, first
255 if not PO9 return False
256 # eliminate EXT900
257 if Word[30:31] = 0b00 return False
258 # eliminate SVP64:EXT000-031
259 if Word[30:31] = 0b11 return False
260 # eliminate SSingle:EXT000-063
261 if Word[6:29 ] != 0x000000 and
262 Word[30:31] = 0b01 return False
263 # eliminate EXT200-231
264 if Word[30:31] = 0b10 and
265 Word[33:37] = 0b10001 return False
266 # eliminate SSingle:EXT900
267 if Word[30:31] = 0b10 and
268 Word[6:29 ] != 0x000000 and
269 Word[33:37] = 0b10001 and
270 Word[62:63] = 0b00 return False
271 # eliminate SVP64:EXT900
272 if Word[30:31] = 0b10 and
273 Word[33:37] = 0b10001 and
274 Word[62:63] = 0b01 return False
275 # all else needs further detailed decode
276 return True
277 ```
278
279 # alternative **no 32 encoding** 64-bit only (4) **current** <a name="#sv_po9_ext2xx" />
280
281 this idea gets even simpler. the 55-bit area is eliminated and may only be
282 reintroduced by sacrificing parts of EXT200-263. however doing so **WILL** damage
283 high-performance decode.
284
285 advantages:
286
287 * brutally simple length detection (multi-issue 1 clock cycle)
288 * extremely easy SVP64 identification
289 * extremely easy SVP64Single identification
290
291
292 ```
293 |0-5| 6-29 |30 31|32-37 | 38-663 | Description |
294 |---|--------|-----|--------|--------|------------------|
295 |PO9| xxxx | x x | 010001 | //// | RESERVED |
296 |PO9| xxxx | x x | 000001 | //// | RESERVED |
297 |PO9| !ZERO | 1 1 | !PO9 | xxxx | SSingle:EXT200-263 |
298 |PO9| 0000 | 1 1 | !PO9 | xxxx | Scalar EXT200-263 |
299 |PO9| SVRM | 1 0 | !PO9 | xxxx | SVP64:EXT200-263 |
300 |PO9| 0000 | 0 1 | Defined Word-instruction | 32-bit EXT300-363 |
301 |PO9| !ZERO | 0 1 | Defined Word-instruction | SSingle:EXT000-063 |
302 |PO9| SVRM | 0 0 | Defined Word-instruction | SVP64:EXT000-063 |
303 ```
304 * bit 31 is "SVP64Single" if set else "SVP64"
305 * bit 30 is EXT200-263 if set otherwise EXT000-063
306
307 (note: this is one of the original early PO9 Encodings,
308 proposed in [[rfc/ls001]] and rejected at the time:
309 with hindsight it should not have been)
310
311 **Identification**:
312
313 The following identification-criteria may be easily verified by taking
314 a copy of the table above and striking out each line that fails each
315 test. Only EXT000-063 is not by a "process of elimination" (if ... return True)
316
317 **Length detection**: (critically-important to be short - 1 clock cycle)
318
319 ```
320 if PO1 or PO9 return 64
321 else return 32
322 ```
323
324 **Scalar**: (includes EXT0xx, EXT2xx and EXT3xx):
325
326 |0-5| 6-29 |30 31|32-37 | 38-663 | Description |
327 |---|--------|-----|--------|--------|------------------|
328 |PO9| xxxx | x x | 010001 | //// | RESERVED |
329 |PO9| xxxx | x x | 000001 | //// | RESERVED |
330 |PO9| !ZERO | 1 1 | !PO9 | xxxx | SSingle:EXT200-263 |
331 |PO9| 0000 | 1 1 | !PO9 | xxxx | Scalar EXT200-263 |
332 |PO9| SVRM | 1 0 | !PO9 | xxxx | SVP64:EXT200-263 |
333 |PO9| 0000 | 0 1 | Defined Word-instruction | 32-bit EXT300-363 |
334 |PO9| !ZERO | 0 1 | Defined Word-instruction | SSingle:EXT000-063 |
335 |PO9| SVRM | 0 0 | Defined Word-instruction | SVP64:EXT000-063 |
336
337 ```
338 if PO1 return True # EXT1xx is Scalar
339 if not PO9 return True # anything not PO9 is EXT0xx
340 if Word[6:29 ] = 0x000000 return True # EXT2xx and EXT3xx
341 if Word[32:37] = 0b010001 return False # double-PO9 Reserved
342 if Word[32:37] = 0b000001 return False # PO9-PO1 Reserved
343 return False # all else is SVP64/SSingle
344 ```
345
346 **EXT200-263:**
347
348 ```
349 if not PO9 return False # eliminate EXT0xx
350 if Word[31] == 0b1 return False # remaining is EXT2xx
351 return True
352 ```
353
354
355
356 **EXT000-063**: (includes Prefixed)
357
358 ```
359 if PO1 return False # or other reserved
360 if not PO9 return True # prefixed needs more
361 if Word[31] = 0b0 return False # eliminate EXT2xx
362 return True # remaining is EXT0xx
363 ```
364
365 **SVP64**:
366
367 ```
368 if not PO9 return False # easy-elimination, first
369 if Word[31] = 0b1 return False # eliminate anything not SVP64
370 return True # all remaining are SVP64:EXT0xx/EXT2xx
371 ```
372
373 **SVP64Single**:
374
375 ```
376 if not PO9 return False # easy-elimination, first
377 if Word[31] = 0b0 return False # eliminate SVP64:*
378 if Word[6:29 ] = 0x000000 return False # eliminate anything "Identity"
379 return True # everything left is SVP64Single
380
381 ```
382
383 **RESERVED**: (no need to pass for further detailed decode)
384
385 ```
386 if not PO9 return False # easy-elimination, first
387 if Word[32:37] = 0b010001 return False # eliminate double-PO9
388 if Word[32:37] = 0b000001 return False # eliminate PO9-PO1
389 return True # all else requires detailed decode
390 ```