move CR tables
[libreriscv.git] / openpower / sv / svp_rewrite / svp64.mdwn
1 # Rewrite of SVP64 for OpenPower ISA v3.1
2
3 * [[svp64/discussion]]
4 * <http://lists.libre-soc.org/pipermail/libre-soc-dev/2020-December/001650.html>
5
6 The plan is to create an encoding for SVP64, then to create an encoding
7 for SVP48, then to reorganize them both to improve field overlap,
8 reducing the amount of decoder hardware necessary.
9
10 All bit numbers are in MSB0 form (the bits are numbered from 0 at the MSB
11 and counting up as you move to the LSB end). All bit ranges are inclusive
12 (so `4:6` means bits 4, 5, and 6).
13
14 64-bit instructions are split into two 32-bit words, the prefix and the
15 suffix. The prefix always comes before the suffix in PC order.
16
17 # Definition of Reserved in this spec.
18
19 For the new fields added in SVP64, instructions that have any of their
20 fields set to a reserved value must cause an illegal instruction trap,
21 to allow emulation of future instruction sets.
22
23 This is unlike OpenPower ISA v3.1, which in many instances does not require a trap.
24
25 # Identity Behaviour
26
27 SVP64 is designed so that when the prefix is all zeros, no effect or
28 influence occurs (no augmentation) such that all standard OpenPOWER
29 v3.0/1B instructions are "unaltered". This is termed `scalar identity behaviour` (based on the mathematical definition for "identity", as in, "identity matrix" or better "identity transformation").
30
31 Note that this is completely different from when VL=0. VL=0 turns all operations under its influence into `nops`, whereas when VL=1 and the SV prefix is all zeros, the operation simply acts as if SV had not been applied at all to the instruction (an "identity operation").
32
33 # Remapped Encoding (`RM[0:23]`)
34
35 To allow relatively easy remapping of which portions of the Prefix Opcode
36 Map are used for SVP64 without needing to rewrite a large portion of the
37 SVP64 spec, a mapping is defined from the OpenPower v3.1 prefix bits to
38 a new 24-bit Remapped Encoding denoted `RM[0]` at the MSB to `RM[23]`
39 at the LSB.
40
41 The mapping from the OpenPower v3.1 prefix bits to the Remapped Encoding
42 is defined in the Prefix Fields section.
43
44 ## Prefix Opcode Map (64-bit instruction encoding) (prefix bits 6:11)
45
46 (shows both PowerISA v3.1 instructions as well as new SVP instructions; empty spaces are yet-to-be-allocated Illegal Instructions)
47
48 | 6:11 | ---000 | ---001 | ---010 | ---011 | ---100 | ---101 | ---110 | ---111 |
49 | ---- | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ |
50 |000---| 8LS | 8LS | 8LS | 8LS | 8LS | 8LS | 8LS | 8LS |
51 |001---| | | | | | | | |
52 |010---| 8RR | | | | `SVP64`| `SVP64`| `SVP64`| `SVP64`|
53 |011---| | | | | `SVP64`| `SVP64`| `SVP64`| `SVP64`|
54 |100---| MLS | MLS | MLS | MLS | MLS | MLS | MLS | MLS |
55 |101---| | | | | | | | |
56 |110---| MRR | | | | `SVP64`| `SVP64`| `SVP64`| `SVP64`|
57 |111---| | MMIRR | | | `SVP64`| `SVP64`| `SVP64`| `SVP64`|
58
59 ## Prefix Fields
60
61 | Prefix Field Name | Field | Value | Description |
62 |---------------------|---------|-------|--------------------------------------------|
63 | PO (Primary Opcode) | `0:5` | `1` | Indicates this is Prefixed 64-bit |
64 | `RM[0]` | `6` | | Bit 0 of the Remapped Encoding |
65 | SVP64_7 | `7` | `1` | Indicates this is SVP64 |
66 | `RM[1]` | `8` | | Bit 1 of the Remapped Encoding |
67 | SVP64_9 | `9` | `1` | Indicates this is SVP64 |
68 | `RM[2:23]` | `10:31` | | Bits 2-23 of the Remapped Encoding |
69
70
71 # Remapped Encoding Fields
72
73 Shows all fields in the Remapped Encoding `RM[0:23]` for all instruction
74 variants. There are two categories: Single and Twin Predication.
75 Due to space considerations further subdivision of Single Predication
76 is based on whether the number of src operands is 2 or 3.
77
78
79 * `RM-1P-3S1D` Single Predication dest/src1/2/3, applies to 4-operand instructions (fmadd, isel, madd).
80 * `RM-1P-2S1D` Single Predication dest/src1/2 applies to 3-operand instructions (src1 src2 dest)
81 * `RM-2P-1S1D` Twin Predication (src=1, dest=1)
82 * `RM-2P-2S1D` Twin Predication (src=2, dest=1) primarily for LDST (Indexed)
83 * `RM-2P-1S2D` Twin Predication (src=1, dest=2) primarily for LDST Update
84
85 ## RM-1P-3S1D
86
87 | Field Name | Field bits | Description |
88 |------------|------------|------------------------------------------------|
89 | MASK\_KIND | `0` | Execution Mask Kind |
90 | MASK | `1:3` | Execution Mask |
91 | ELWIDTH | `4:5` | Element Width |
92 | SUBVL | `6:7` | Sub-vector length |
93 | Rdest\_EXTRA2 | `8:9` | extra bits for Rdest (R\*\_EXTRA2 Encoding) |
94 | Rsrc1\_EXTRA2 | `10:11` | extra bits for Rsrc1 (R\*\_EXTRA2 Encoding) |
95 | Rsrc2\_EXTRA2 | `12:13` | extra bits for Rsrc2 (R\*\_EXTRA2 Encoding) |
96 | Rsrc3\_EXTRA2 | `14:15` | extra bits for Rsrc3 (R\*\_EXTRA2 Encoding|
97 | reserved | `16` | reserved |
98 | MODE | `19:23` | changes Vector behaviour |
99
100 ## RM-1P-2S1D
101
102 | Field Name | Field bits | Description |
103 |------------|------------|------------------------------------------------|
104 | MASK\_KIND | `0` | Execution Mask Kind |
105 | MASK | `1:3` | Execution Mask |
106 | ELWIDTH | `4:5` | Element Width |
107 | SUBVL | `6:7` | Sub-vector length |
108 | Rdest\_EXTRA3 | `8:10` | extra bits for Rdest (Uses R\*\_EXTRA3 Encoding) |
109 | Rsrc1\_EXTRA3 | `11:13` | extra bits for Rsrc1 (Uses R\*\_EXTRA3 Encoding) |
110 | Rsrc2\_EXTRA3 | `14:16` | extra bits for Rsrc3 (Uses R\*\_EXTRA3 Encoding) |
111 | MODE | `19:23` | changes Vector behaviour |
112
113 These are for 2 operand 1 dest instructions, such as `add RT, RA,
114 RB`. However also included are unusual instructions with the same src
115 and dest, such as `rlwinmi`.
116
117 Normally, the scalar v3.0B ISA would not have sufficient bits to allow
118 an alternative destination. With SV however this becomes possible.
119 Therefore, the fact that the dest is implicitly also a src should not
120 mislead: due to the *prefix* they are different SV regs.
121
122 * `rlwimi RA, RS, ...`
123 * Rsrc1_EXTRA3 applies to RS as the first src
124 * Rsrc2_EXTRA3 applies to RA as the secomd src
125 * Rdest_EXTRA3 applies to RA to create an **independent** dest.
126
127 Otherwise the normal SV hardware for-loop applies. The three registers
128 each may be independently made vector or scalar, and may independently
129 augmented to 7 bits in length.
130
131 ## RM-2P-1S1D
132
133 | Field Name | Field bits | Description |
134 |------------|------------|----------------------------|
135 | MASK_KIND | `0` | Execution Mask Kind |
136 | MASK | `1:3` | Execution Mask |
137 | ELWIDTH | `4:5` | Element Width |
138 | SUBVL | `6:7` | Sub-vector length |
139 | Rdest_EXTRA3 | `8:10` | extra bits for Rdest |
140 | Rsrc1_EXTRA3 | `11:13` | extra bits for Rsrc1 |
141 | MASK_SRC | `14:16` | Execution Mask for Source |
142 | ELWIDTH_SRC | `17:18` | Element Width for Source |
143 | MODE | `19:23` | changes Vector behaviour |
144
145 note in [[discussion]]: TODO, evaluate if 2nd SUBVL should be added.
146 conclusion: no. 2nd SUBVL makes no sense except for mv, and that is
147 covered by [[mv.vec]]
148
149 ## RM-2P-2S1D/1S2D
150
151 The primary purpose for this encoding is for Twin Predication on LOAD
152 and STORE operations. see [[sv/ldst]] for detailed anslysis.
153
154 RM-2P-2S1D:
155
156 | Field Name | Field bits | Description |
157 |------------|------------|----------------------------|
158 | MASK_KIND | `0` | Execution Mask Kind |
159 | MASK | `1:3` | Execution Mask |
160 | ELWIDTH | `4:5` | Element Width |
161 | SUBVL | `6:7` | Sub-vector length |
162 | Rdest_EXTRA2 | `8:9` | extra bits for Rdest (R\*\_EXTRA2 Encoding) |
163 | Rsrc1_EXTRA2 | `10:11` | extra bits for Rsrc1 (R\*\_EXTRA2 Encoding) |
164 | Rsrc2_EXTRA2 | `12:13` | extra bits for Rsrc2 (R\*\_EXTRA2 Encoding) |
165 | MASK_SRC | `14:16` | Execution Mask for Source |
166 | ELWIDTH_SRC | `17:18` | Element Width for Source |
167 | MODE | `19:23` | changes Vector behaviour |
168
169 Note that for 1S2P the EXTRA2 dest and src names are switched (Rsrc_EXTRA2
170 is in bits 8:9, Rdest1_EXTRA2 in 10:11)
171
172 Note also that LD with update indexed, which takes 2 src and 2 dest
173 (e.g. `lhaux RT,RA,RB`), does not have room for 4 registers and also
174 Twin Predication. therefore these are treated as RM-2P-2S1D and the
175 src spec for RA is also used for the same RA as a dest.
176
177
178 # Mode
179
180 Mode is an augmentation of SV behaviour. Some of these alterations are element-based (saturation), others involve post-analysis (predicate result) and others are Vector-based (mapreduce, fail-on-first).
181
182 These are the modes:
183
184
185
186 * **normal** mode is straight vectorisation. no augmentations: the vector comprises an array of independently created results.
187 * **ffirst** or data-dependent fail-on-first: see separate section. the vector may be truncated depending on certain criteria.
188 * **sat mode** or saturation: clamps each elemrnt result to a min/max rather than overflows / wraps. allows signed and unsigned clamping.
189 * **reduce mode**. when M=1 a mapreduce is performed. the result is a scalar. a vector however is required, as it may be used to store intermediary computations. the result is in the first element with a nonzero predicate bit.
190 note that reduce mode only applies to 2 src operations.
191 * **pred-result** will test the result (CR testing selects a bit of CR and inverts it, just like branch testing) and if the test fails it is as if the predicate bit was zero. When Rc=1 the CR element (CR0) however is still stored in the CR regfile. This scheme does not apply to crops (crand, cror).
192
193 | 0-1 | 2 | 3 4 | description |
194 | --- | --- |---------|-------------------------- |
195 | 00 | 0 | sz dz | normal mode |
196 | 00 | 1 | sz CRM | reduce mode (mapreduce) |
197 | 01 | inv | CR-bit | Rc=1: ffirst CR sel |
198 | 01 | inv | sz dz | Rc=0: ffirst z/nonz |
199 | 10 | N | sz dz | sat mode: N=0/1 u/s |
200 | 11 | inv | CR-bit | Rc=1: pred-result CR sel |
201 | 11 | inv | sz dz | Rc=0: pred-result z/nonz |
202
203 Fields:
204
205 * **sz / dz** if predication is enabled will put zeros into the dest (or as src in the case of twin pred) when the predicate bit is zero. otherwise the element is ignored or skipped, depending on context.
206 * **inv CR bit** just as in branches (BO) these bits allow testing of a CR bit and whether it is set (inv=0) or unset (inv=1)
207
208 ## Notes about rounding, clamp and saturate
209
210 When N=0 the result is saturated to within the maximum range of an unsigned value. For integer ops this will be 0 to 2^elwidth-1. Similar logic applies to FP operations, with the result being saturated to maximum rather than returning INF.
211
212 When N=1 the same occurs except that the result is saturated to the min or max of a signed result.
213
214 One of the issues with vector ops is that in integer DSP ops for example in Audio the operation must clamp or saturate rather than overflow or ignore the upper bits and become a modulo operation. This for Audio is extremely important, also to provide an indicator as to whether saturation occurred. see [[av_opcodes]].
215
216
217 ## Notes about reduce mode
218
219 1. limited to single predicated dual src operations (add RT, RA, RB) and to triple source operations where one of the inputs is set to a scalar (these are rare)
220 2. limited to operations that make sense. divide is excluded, as is subtract (X - Y - Z produces different answers depending on the order). sane operations: multiply, add, logical bitwise OR, CR operations. operations that do not return the same register type are also excluded (isel, cmp)
221 3. the destination is a vector but the result is stored, ultimately, in the first nonzero predicated element. all other nonzero predicated elements are undefined. *this includes the CR vector* when Rc=1
222 4. implementations may use any ordering and any algorithm to reduce down to a single result. However it must be equivalent to a straight application of mapreduce. The destination vector (except masked out elements) may be used for storing any intermediate results. these may be left in the vector (undefined).
223 5. CRM applies when Rc=1. When CRM is zero, the CR associated with the result is regarded as a "some results met standard CR result criteria". When CRM is one, this changes to "all results met standard CR criteria".
224 6. implementations MAY use destoffs as well as srcoffs (see [[sv/sprs]]) in order to store sufficient state to resume operation should an interrupt occur. this is also why implementations are permitted to use the destination vector to store intermediary computations
225
226 TODO: Rc=1 on Scalar Logical Operations? is this possible? was space reserved in Logical Ops?
227
228 Pseudocode for the case where RA==RB:
229
230 result = op(iregs[RA], iregs[RA+1])
231 CR = analyse(result)
232 for i in range(2, VL):
233 result = op(result, iregs[RA+i])
234 CRnew = analyse(result)
235 if Rc=1
236 if CRM:
237 CR = CR bitwise or CRnew
238 else:
239 CR = CR bitwise AND CRnew
240
241 TODO: case where RA!=RB which involves first a vector of 2-operand results followed by a mapreduce on the intermediates.
242
243 ## Fail-on-first
244
245 Data-dependent fail-on-first has two distinct variants: one for LD/ST, the other for arithmetic operations (actually, CR-driven). Note in each case the assumption is that vector elements are required appear to be executed in sequential Program Order, element 0 being the first.
246
247 * LD/ST ffirst treats the first LD/ST in a vector (element 0) as an ordinary one. Exceptions occur "as normal". However for elements 1 and above, if an exception would occur, then VL is **truncated** to the previous element.
248 * Data-driven (CR-driven) fail-on-first activates when Rc=1 or other CR-creating operation produces a result (including cmp). Similar to branch, an analysis of the CR is performed and if the test fails, the vector operation terminates and discards all element operations at and above the current one, and VL is truncated to the *previous* element. Thus the new VL comprises a contiguous vector of results, all of which pass the testing criteria (equal to zero, less than zero).
249
250 The CR-based data-driven fail-on-first is new and not found in ARM SVE or RVV. It is extremely useful for reducing instruction count, however requires speculative execution involving modifications of VL to get high performance implementations.
251
252 In CR-based data-driven fail-on-first there is only the option to select and test one bit of each CR (just as with branch BO). For more complex tests this may be insufficient. If that is the case, a vectorised crops (crand, cror) may be used, and ffirst applied to the crop instead of to the arithmetic vector.
253
254 One extremely important aspect of ffirst is:
255
256 * LDST ffirst may never set VL equal to zero. This because on the first element an exception must be raised "as normal".
257 * CR-based data-dependent ffirst **can** set VL equal to zero. This is the only means in the entirety of SV that VL may be set to zero (with the exception of via the SV.STATE SPR). When VL is set zero due to the first element failing the CR bit-test, all subsequent vectorised operations are effectively `nops` which is *precisely the desired and intended behaviour*.
258
259 # R\*_EXTRA2 and R\*_EXTRA3 Encoding
260
261 In the following tables register numbers are constructed from the
262 standard v3.0B / v3.1B 32 bit register field (RA, FRA) and the EXTRA2
263 or EXTRA3 field from the SV Prefix. The prefixing is arranged so that
264 interoperability between prefixing and nonprefixing of scalar registers
265 is direct and convenient (when the EXTRA field is all zeros).
266
267 3 bit version
268
269 alternative which is understandable and, if EXTRA3 is zero, maps to
270 "no effect" (scalar OpenPOWER ISA field naming). also, these are the
271 encodings used in the original SV Prefix scheme. the reason why they
272 were chosen is so that scalar registers in v3.0B and prefixed scalar
273 registers have access to the same 32 registers.
274
275 | R\*\_EXTRA3 | Mode | Range | Encoded as |
276 |-----------|-------|---------------|---------------------|
277 | 000 | Scalar | `r0-r31` | `0b00 RA` |
278 | 001 | Scalar | `r32-r63` | `0b01 RA` |
279 | 010 | Scalar | `r64-r95` | `0b10 RA` |
280 | 011 | Scalar | `r96-r127` | `0b11 RA` |
281 | 100 | Vector | `r0-r124` | `RA 0b00` |
282 | 101 | Vector | `r1-r125` | `RA 0b01` |
283 | 110 | Vector | `r2-r126` | `RA 0b10` |
284 | 111 | Vector | `r3-r127` | `RA 0b11` |
285
286 algorithm for original version:
287
288 spec = EXTRA3
289 if spec[2]: # vector
290 return RA << 2 + spec[0:1]
291 else: # scalar
292 return RA + spec[0:1] << 5
293
294 2 bit version
295
296 alternative which is understandable and, if EXTRA2 is zero will map to
297 "no effect" i.e Scalar OpenPOWER register naming:
298
299 | R\*\_EXTRA2 | Mode | Range | Encoded as |
300 |-----------|-------|---------------|---------------------|
301 | 00 | Scalar | `r0-r31` | `0b00 RA` |
302 | 01 | Scalar | `r32-r63` | `0b01 RA` |
303 | 10 | Vector | `r0-r124` | `RA 0b00` |
304 | 11 | Vector | `r2-r126` | `RA 0b10` |
305
306 algorithm for original version is identical to the 3 bit version except
307 that the spec is shifted up by one bit
308
309 spec = EXTRA2 << 1 # same as EXTRA3, shifted
310 if spec[2]: # vector
311 return RA << 2 + spec[0:1]
312 else: # scalar
313 return RA + spec[0:1] << 5
314
315 # ELWIDTH Encoding
316
317 Default behaviour is set to 0b00 so that zeros follow the convention of
318 "npt doing anything". In this case it means that elwidth overrides
319 are not applicable. Thus if a 32 bit instruction operates on 32 bit,
320 `elwidth=0b00` specifies that this behaviour is unmodified. Likewise
321 when a processor is switched from 64 bit to 32 bit mode, `elwidth=0b00`
322 states that, again, the behaviour is not to be modified.
323
324 Only when elwidth is nonzero is the element width overridden to the
325 explicitly required value.
326
327 ## Elwidth for Integers:
328
329 | Value | Mnemonic | Description |
330 |-------|----------------|------------------------------------|
331 | 00 | DEFAULT | default behaviour for operation |
332 | 01 | `ELWIDTH=b` | Byte: 8-bit integer |
333 | 10 | `ELWIDTH=h` | Halfword: 16-bit integer |
334 | 11 | `ELWIDTH=w` | Word: 32-bit integer |
335
336 ## Elwidth for FP Registers:
337
338 | Value | Mnemonic | Description |
339 |-------|----------------|------------------------------------|
340 | 00 | DEFAULT | default behaviour for FP operation |
341 | 01 | `ELWIDTH=bf16` | Reserved for `bf16` |
342 | 10 | `ELWIDTH=f16` | 16-bit IEEE 754 Half floating-point |
343 | 11 | `ELWIDTH=f32` | 32-bit IEEE 754 Single floating-point |
344
345 Note:
346 [`bf16`](https://en.wikipedia.org/wiki/Bfloat16_floating-point_format)
347 is reserved for a future implementation of SV
348
349 ## Elwidth for CRs:
350
351 TODO, important, particularly for crops, mfcr and mtcr, what elwidth
352 even means. instead it may be possible to use the bits as extra indices
353 (EXTRA6) to access the full 64 CRs. TBD, several ideas
354
355 The actual width of the CRs cannot be altered: they are 4 bit. Also,
356 for Rc=1 operations that produce a result (in RT or FRT) and corresponding CR, it is
357 the INT/FP result to which the elwidth override applies, *not* the CR.
358 This therefore inherently places Rc=1 operations firmly out of scope as far as a "meaning" for elwidth on CRs is concerned.
359
360 As mentioned TBD, this leaves crops etc. to have a meaning defined for
361 elwidth, because these ops are pure explicit CR based.
362
363 Examples: mfxm may take the extra bits and use them as extra mask bits.
364
365 # SUBVL Encoding
366
367 the default for SUBVL is 1 and its encoding is 0b00 to indicate that
368 SUBVL is effectively disabled (a SUBVL for-loop of only one element). this
369 lines up in combination with all other "default is all zeros" behaviour.
370
371 | Value | Mnemonic | xxx | Description |
372 |-------|-----------|---------|------------------------|
373 | 00 | `SUBVL=1` | default | Sub-vector length of 1 |
374 | 01 | `SUBVL=2` | vec2 | Sub-vector length of 2 |
375 | 10 | `SUBVL=3` | vec3 | Sub-vector length of 3 |
376 | 11 | `SUBVL=4` | vec4 | Sub-vector length of 4 |
377
378 The SUBVL encoding value may be thought of as an inclusive range of a
379 sub-vector. SUBVL=2 represents a vec2, its encoding is 0b01, therefore
380 this may be considered to be elements 0b00 to 0b01 inclusive.
381
382 # MASK/MASK_SRC & MASK_KIND Encoding
383
384 One bit (`MASKMODE`) indicates the mode: CR or Int predication. The two
385 types may not be mixed.
386
387 Special note: to get default behaviour (SV disabled) this field must
388 be set to zero in combination with Integer Predication also being set
389 to 0b000. this has the effect of enabling "all 1s" in the predicate
390 mask, which is equivalent to "not having any predication at all"
391 and consequently, in combination with all other default zeros, fully
392 disables SV.
393
394 | Value | Description |
395 |-------|------------------------------------------------------|
396 | 0 | MASK/MASK_SRC are encoded using Integer Predication |
397 | 1 | MASK/MASK_SRC are encoded using CR-based Predication |
398
399 Integer Twin predication has a second set of 3 bits that uses the same
400 encoding thus allowing either the same register (r3 or r10) to be used
401 for both src and dest, or different regs (one for src, one for dest).
402
403 Likewise CR based twin predication has a second set of 3 bits, allowing
404 a different test to be applied.
405
406 ## Integer Predication (MASK_KIND=0)
407
408 When the predicate mode bit is zero the 3 bits are interpreted as below.
409 Twin predication has an identical 3 bit field similarly encoded.
410
411 | Value | Mnemonic | Element `i` enabled if: |
412 |-------|----------|------------------------------|
413 | 000 | ALWAYS | (Operation is not masked) |
414 | 001 | 1 << R3 | `i == R3` |
415 | 010 | R3 | `R3 & (1 << i)` is non-zero |
416 | 011 | ~R3 | `R3 & (1 << i)` is zero |
417 | 100 | R10 | `R10 & (1 << i)` is non-zero |
418 | 101 | ~R10 | `R10 & (1 << i)` is zero |
419 | 110 | R30 | `R30 & (1 << i)` is non-zero |
420 | 111 | ~R30 | `R30 & (1 << i)` is zero |
421
422 ## CR-based Predication (MASK_KIND=1)
423
424 When the predicate mode bit is one the 3 bits are interpreted as below.
425 Twin predication has an identical 3 bit field similarly encoded
426
427 | Value | Mnemonic | Description |
428 |-------|----------|-------------------------------------------------|
429 | 000 | lt | Element `i` is enabled if `CR[6+i].LT` is set |
430 | 001 | nl/ge | Element `i` is enabled if `CR[6+i].LT` is clear |
431 | 010 | gt | Element `i` is enabled if `CR[6+i].GT` is set |
432 | 011 | ng/le | Element `i` is enabled if `CR[6+i].GT` is clear |
433 | 100 | eq | Element `i` is enabled if `CR[6+i].EQ` is set |
434 | 101 | ne | Element `i` is enabled if `CR[6+i].EQ` is clear |
435 | 110 | so/un | Element `i` is enabled if `CR[6+i].FU` is set |
436 | 111 | ns/nu | Element `i` is enabled if `CR[6+i].FU` is clear |
437
438 CR based predication. TODO: select alternate CR for twin predication? see
439 [[discussion]] Overlap of the two CR based predicates must be taken
440 into account, so the starting point for one of them must be suitably
441 high, or accept that for twin predication VL must not exceed the range
442 where overlap will occur, *or* that they use the same starting point
443 but select different *bits* of the same CRs
444
445 # Twin Predication
446
447 This is a novel concept that allows predication to be applied to a single
448 source and a single dest register. The following types of traditional
449 Vector operations may be encoded with it, *without requiring explicit
450 opcodes to do so*
451
452 * VSPLAT (a single scalar distributed across a vector)
453 * VEXTRACT (like LLVM IR [`extractelement`](https://releases.llvm.org/11.0.0/docs/LangRef.html#extractelement-instruction))
454 * VINSERT (like LLVM IR [`insertelement`](https://releases.llvm.org/11.0.0/docs/LangRef.html#insertelement-instruction))
455 * VCOMPRESS (like LLVM IR [`llvm.masked.compressstore.*`](https://releases.llvm.org/11.0.0/docs/LangRef.html#llvm-masked-compressstore-intrinsics))
456 * VEXPAND (like LLVM IR [`llvm.masked.expandload.*`](https://releases.llvm.org/11.0.0/docs/LangRef.html#llvm-masked-expandload-intrinsics))
457
458 Those patterns (and more) may be applied to:
459
460 * mv (the usual way that V\* ISA operations are created)
461 * exts\* sign-extension
462 * rwlinm and other RS-RA shift operations (**note**: excluding
463 those that take RA as both a src and dest. These are not
464 1-src 1-dest, they are 2-src, 1-dest)
465 * LD and ST (treating AGEN as one source)
466 * FP fclass, fsgn, fneg, fabs, fcvt, frecip, fsqrt etc.
467 * Condition Register ops mfcr, mtcr and other similar
468
469 This is a huge list that creates extremely powerful combinations,
470 particularly given that one of the predicate options is `(1<<r3)`
471
472 Additional unusual capabilities of Twin Predication include a back-to-back
473 version of VCOMPRESS-VEXPAND which is effectively the ability to do an
474 ordered multiple VINSERT.
475
476 # Register Naming
477
478 SV Registers are simply the INT, FP and CR register files extended
479 linearly to larger sizes. Thus, the integer regfile in standard scalar
480 OpenPOWER v3.0B and v3.1B is r0 to r31: SV extends this as r0 to r127.
481 Likewise FP registers are extended to 128 (fp0 to fp127), and CRs are
482 extended to 64 entries, CR0 thru CR63.
483
484 The names of the registers therefore reflects a simple linear extension
485 of the OpenPOWER v3.0B / v3.1B register naming, and in hardware this
486 would be reflected by a linear increase in the size of the underlying
487 SRAM used for the regfiles.
488
489 Note: when the EXTRA fields are all zero, SV is deliberately designed
490 so that the register fields are identical to as if SV was not in effect
491 i.e. under these circumstances (EXTRA=0) the register field names RA,
492 RB etc. are interpreted as v3.0B / v3.1B scalar registers. This is termed
493 `scalar identity behaviour`
494
495 # CR Operations
496
497 CRs are slightly more involved than INT or FP registers due to the
498 possibility for indexing individual bits (crops BA/BB/BT). Again however
499 the access pattern needs to be understandable in relation to v3.0B / v3.1B
500 numbering, with a clear linear relationship and mapping existing when
501 SV is applied.
502
503 ## CR EXTRA mapping table and algorithm
504
505 Numbering relationships for CR fields are already complex due to being
506 in BE format (*the relationship is not clearly explained in the v3.0B
507 or v3.1B specification*). However with some care and consideration
508 the exact same mapping used for INT and FP regfiles may be applied,
509 just to the upper bits, as explained below.
510
511 In OpenPOWER v3.0/1, BF/BT/BA/BB are all 5 bits. The top 3 bits (2:4)
512 select one of the 8 CRs; the bottom 2 bits (0:1) select one of 4 bits
513 *in* that CR. The numbering was determined (after 4 months of
514 analysis and research) to be as follows:
515
516 CR_index = 7-(BA>>2) # top 3 bits but BE
517 bit_index = 3-(BA & 0b11) # low 2 bits but BE
518 CR_reg = CR[CR_index] # get the CR
519 # finally get the bit from the CR.
520 CR_bit = (CR_reg & (1<<bit_index)) != 0
521
522 When it comes to applying SV, it is the CR\_reg number to which SV EXTRA2/3
523 applies, **not** the CR\_bit portion (bits 0:1):
524
525 if extra3_mode:
526 spec = EXTRA3
527 else:
528 spec = EXTRA2<<1 | 0b0
529 if spec[2]:
530 # vector constructs "BA[2:4] spec[0:1] BA[0:1]"
531 return ((BA >> 2)<<4) | # hi 3 bits shifted up
532 (spec[0:1]<<2) | # to make room for these
533 (BA & 0b11) # CR_bit on the end
534 else:
535 # scalar constructs "spec[0:1] BA[0:4]"
536 return (spec[0:1] << 5) | BA
537
538 Thus, for example, to access a given bit for a CR in SV mode, the v3.0B
539 algorithm to determin CR\_reg is modified to as follows:
540
541 CR_index = 7-(BA>>2) # top 3 bits but BE
542 if spec[2]:
543 # vector mode
544 CR_index = (CR_index<<2) | (spec[0:1])
545 else:
546 # scalar mode
547 CR_index = CR_index | (spec[0:1]<<3)
548 # same as for v3.0/v3.1 from this point onwards
549 bit_index = 3-(BA & 0b11) # low 2 bits but BE
550 CR_reg = CR[CR_index] # get the CR
551 # finally get the bit from the CR.
552 CR_bit = (CR_reg & (1<<bit_index)) != 0
553
554 Note here that the decoding pattern to determine CR\_bit does not change.
555
556 Note: high-performance implementations may read/write Vectors of CRs in
557 batches of aligned 32-bit chunks (CR0-7, CR7-15). This is to greatly
558 simplify internal design. If instructions are issued where CR Vectors
559 do not start on a 32-bit aligned boundary, performance may be affected.
560
561 ### CR EXTRA3
562
563 In table form. Encoding shown MSB down to LSB
564
565 | R\*\_EXTRA3 | Mode | 6..5 | 4..2 | 1..0 |
566 |-------------|------|---------| --------|---------|
567 | 000 | Scalar | 0b00 | BA[4:2] | BA[1:0] |
568 | 001 | Scalar | 0b01 | BA[4:2] | BA[1:0] |
569 | 010 | Scalar | 0b10 | BA[4:2] | BA[1:0] |
570 | 011 | Scalar | 0b11 | BA[4:2] | BA[1:0] |
571 | 100 | Vector | BA[4:2] | 0b00 | BA[1:0] |
572 | 101 | Vector | BA[4:2] | 0b01 | BA[1:0] |
573 | 110 | Vector | BA[4:2] | 0b10 | BA[1:0] |
574 | 111 | Vector | BA[4:2] | 0b11 | BA[1:0] |
575
576 ### CR EXTRA2
577
578 In table form. Encoding shown MSB down to LSB
579
580 | R\*\_EXTRA2 | Mode | 6..5 | 4..2 | 1..0 |
581 |-------------|--------|---------|---------|---------|
582 | 00 | Scalar | 0b00 | BA[4:2] | BA[1:0] |
583 | 01 | Scalar | 0b01 | BA[4:2] | BA[1:0] |
584 | 10 | Vector | BA[4:2] | 0b00 | BA[1:0] |
585 | 11 | Vector | BA[4:2] | 0b10 | BA[1:0] |
586
587 ## CR fields as inputs/outputs of vector operations
588
589 When vectorized, the CR inputs/outputs are sequentially read/written
590 to 4-bit CR fields. Vectorised Integer results, when Rc=1, will begin
591 writing to CR8 (TBD evaluate) and increase sequentially from there.
592 Vectorised FP results, when Rc=1, start from CR32 (TBD evaluate).
593 This is so that:
594
595 * implementations may rely on the Vector CRs being aligned to 8. This
596 means that CRs may be read or written in aligned batches of 32 bits
597 (8 CRs per batch), for high performance implementations.
598 * scalar Rc=1 operation (CR0, CR1) and callee-saved CRs (CR2-4) are not
599 overwritten by vector Rc=1 operations except for very large VL
600 * Vector FP and Integer Rc=1 operations do not overwrite each other
601 except for large VL.
602
603 However when the SV result (destination) is marked as a scalar by the
604 EXTRA field the *standard* v3.0B behaviour applies: the accompanying
605 CR when Rc=1 is written to. This is CR0 for integer operations and CR1
606 for FP operations.
607
608 Note that yes, the CRs are genuinely Vectorised. Unlike in SIMD VSX which
609 has a single CR (CR6) for a given SIMD result, SV Vectorised OpenPOWER
610 v3.0B scalar operations produce a **tuple** of element results: the
611 result of the operation as one part of that element *and a corresponding
612 CR element*. Greatly simplified pseudocode:
613
614 for i in range(VL):
615 # calculate the vector result of an add
616 iregs[RT+i] = iregs[RA+i] + iregs[RB+i]
617 # now calculate CR bits
618 CRs[8+i].eq = iregs[RT+i] == 0
619 CRs[8+i].gt = iregs[RT+i] > 0
620 ... etc
621
622 If a "cumulated" CR based analysis of results is desired (a la VSX CR6)
623 then a followup instruction must be performed, setting "reduce" mode on
624 the Vector of CRs, using cr ops (crand, crnor)to do so. This provides far
625 more flexibility in analysing vectors than standard Vector ISAs. Normal
626 Vector ISAs are typically restricted to "were all results nonzero" and
627 "were some results nonzero". The application of mapreduce to Vectorised
628 cr operations allows far more sophisticated analysis, particularly in
629 conjunction with the new crweird operations see [[sv/cr_int_predication]].
630
631 Note in particular that the use of a separate instruction in this way
632 ensures that high performance multi-issue OoO inplementations do not
633 have the computation of the cumulative analysis CR as a bottleneck and
634 hindrance, regardless of the length of VL.
635
636 (see [[discussion]]. some alternative schemes are described there)
637
638 ## Table of CR fields
639
640 CR[i] is the notation used by the OpenPower spec to refer to CR field #i,
641 so FP instructions with Rc=1 write to CR[1] aka SVCR1_000.
642
643 CRs are not stored in SPRs: they are registers in their own right.
644 Therefore context-switching the full set of CRs involves a Vectorised
645 mfcr or mtcr, using VL=64, elwidth=8 to do so. This is exactly as how scalar OpenPOWER context-switches CRs: it is just that there are now more of them.
646
647 The 64 SV CRs are arranged similarly to the way the 128 integer registers
648 are arranged. TODO a python program that auto-generates a CSV file
649 which can be included in a table, which is in a new page (so as not to
650 overwhelm this one). [[svp64/cr_names]]
651
652
653
654 # Register Profiles
655
656 **NOTE THIS TABLE SHOULD NO LONGER BE HAND EDITED** see
657 <https://bugs.libre-soc.org/show_bug.cgi?id=548> for details.
658
659 Instructions are broken down by Register Profiles as listed in the
660 following auto-generated page: [[opcode_regs_deduped]]. "Non-SV"
661 indicates that the operations with this Register Profile cannot be
662 Vectorised (mtspr, bc, dcbz, twi)
663
664 TODO generate table which will be here [[svp64/reg_profiles]]
665