(no commit message)
[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` | see [[discussion]] |
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` | see [[discussion]] |
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` | see [[discussion]] |
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` | see [[discussion]] |
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 | 0-1 | 2 | 3 4 | description |
183 | --- | --- |---------|-------------------------- |
184 | 00 | 0 | sz dz | normal mode |
185 | 00 | 1 | sz CRM | reduce mode (mapreduce) |
186 | 01 | inv | CR-bit | Rc=1: ffirst CR sel |
187 | 01 | inv | sz dz | Rc=0: ffirst z/nonz |
188 | 10 | N | sz dz | sat mode: N=0/1 u/s |
189 | 11 | inv | CR-bit | Rc=1: pred-result CR sel |
190 | 11 | inv | sz dz | Rc=0: pred-result z/nonz |
191
192 Mode types:
193
194 * **sz dz predicate zeroing** 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.
195 * **ffirst** or data-dependent fail-on-first: see separate section.
196 * **sat mode** or saturation: clamps the result to a min/max rather than overflows / wraps. allows signed and unsigned clamping.
197 * **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.
198 note that reduce mode only applies to 2 src operations.
199 * **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).
200
201 ## Notes about rounding, clamp and saturate
202
203 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.
204
205 When N=1 the same occurs except that the result is saturated to the min or max of a signed result.
206
207 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]].
208
209
210 ## Notes about reduce mode
211
212 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)
213 2. limited to operations that make sense. divide is excluded, as is subtract. sane operations: multiply, add, logical bitwise OR, CR operations. operations that do not return the same register type are also excluded (isel, cmp)
214 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
215 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).
216 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".
217 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
218
219 TODO: Rc=1 on Scalar Logical Operations? is this possible? was space reserved in Logical Ops?
220
221 Pseudocode for the case where RA==RB:
222
223 result = op(iregs[RA], iregs[RA+1])
224 CR = analyse(result)
225 for i in range(2, VL):
226 result = op(result, iregs[RA+i])
227 CRnew = analyse(result)
228 if Rc=1
229 if CRM:
230 CR = CR bitwise or CRnew
231 else:
232 CR = CR bitwise AND CRnew
233
234 TODO: case where RA!=RB which involves first a vector of 2-operand results followed by a mapreduce on the intermediates.
235
236 ## Fail-on-first
237
238 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.
239
240 * 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.
241 * 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).
242
243 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.
244
245 Where the options provided by selecting from only one bit of the CR being tested (and optional inversion of the same) are insufficient, a vectorised crops (crand, cror) may be used and ffirst applied to that.
246
247 # R\*_EXTRA2 and R\*_EXTRA3 Encoding
248
249 In the following tables register numbers are constructed from the
250 standard v3.0B / v3.1B 32 bit register field (RA, FRA) and the EXTRA2
251 or EXTRA3 field from the SV Prefix. The prefixing is arranged so that
252 interoperability between prefixing and nonprefixing of scalar registers
253 is direct and convenient (when the EXTRA field is all zeros).
254
255 3 bit version
256
257 alternative which is understandable and, if EXTRA3 is zero, maps to
258 "no effect" (scalar OpenPOWER ISA field naming). also, these are the
259 encodings used in the original SV Prefix scheme. the reason why they
260 were chosen is so that scalar registers in v3.0B and prefixed scalar
261 registers have access to the same 32 registers.
262
263 | R\*\_EXTRA3 | Mode | Range | Encoded as |
264 |-----------|-------|---------------|---------------------|
265 | 000 | Scalar | `r0-r31` | `0b00 RA` |
266 | 001 | Scalar | `r32-r63` | `0b01 RA` |
267 | 010 | Scalar | `r64-r95` | `0b10 RA` |
268 | 011 | Scalar | `r96-r127` | `0b11 RA` |
269 | 100 | Vector | `r0-r124` | `RA 0b00` |
270 | 101 | Vector | `r1-r125` | `RA 0b01` |
271 | 110 | Vector | `r2-r126` | `RA 0b10` |
272 | 111 | Vector | `r3-r127` | `RA 0b11` |
273
274 algorithm for original version:
275
276 spec = EXTRA3
277 if spec[2]: # vector
278 return RA << 2 + spec[0:1]
279 else: # scalar
280 return RA + spec[0:1] << 5
281
282 2 bit version
283
284 alternative which is understandable and, if EXTRA2 is zero will map to
285 "no effect" i.e Scalar OpenPOWER register naming:
286
287 | R\*\_EXTRA2 | Mode | Range | Encoded as |
288 |-----------|-------|---------------|---------------------|
289 | 00 | Scalar | `r0-r31` | `0b00 RA` |
290 | 01 | Scalar | `r32-r63` | `0b01 RA` |
291 | 10 | Vector | `r0-r124` | `RA 0b00` |
292 | 11 | Vector | `r2-r126` | `RA 0b10` |
293
294 algorithm for original version is identical to the 3 bit version except
295 that the spec is shifted up by one bit
296
297 spec = EXTRA2 << 1 # same as EXTRA3, shifted
298 if spec[2]: # vector
299 return RA << 2 + spec[0:1]
300 else: # scalar
301 return RA + spec[0:1] << 5
302
303 # ELWIDTH Encoding
304
305 Default behaviour is set to 0b00 so that zeros follow the convention of
306 "npt doing anything". In this case it means that elwidth overrides
307 are not applicable. Thus if a 32 bit instruction operates on 32 bit,
308 `elwidth=0b00` specifies that this behaviour is unmodified. Likewise
309 when a processor is switched from 64 bit to 32 bit mode, `elwidth=0b00`
310 states that, again, the behaviour is not to be modified.
311
312 Only when elwidth is nonzero is the element width overridden to the
313 explicitly required value.
314
315 ## Elwidth for Integers:
316
317 | Value | Mnemonic | Description |
318 |-------|----------------|------------------------------------|
319 | 00 | DEFAULT | default behaviour for operation |
320 | 01 | `ELWIDTH=b` | Byte: 8-bit integer |
321 | 10 | `ELWIDTH=h` | Halfword: 16-bit integer |
322 | 11 | `ELWIDTH=w` | Word: 32-bit integer |
323
324 ## Elwidth for FP Registers:
325
326 | Value | Mnemonic | Description |
327 |-------|----------------|------------------------------------|
328 | 00 | DEFAULT | default behaviour for FP operation |
329 | 01 | `ELWIDTH=bf16` | Reserved for `bf16` |
330 | 10 | `ELWIDTH=f16` | 16-bit IEEE 754 Half floating-point |
331 | 11 | `ELWIDTH=f32` | 32-bit IEEE 754 Single floating-point |
332
333 Note:
334 [`bf16`](https://en.wikipedia.org/wiki/Bfloat16_floating-point_format)
335 is reserved for a future implementation of SV
336
337 ## Elwidth for CRs:
338
339 TODO, important, particularly for crops, mfcr and mtcr, what elwidth
340 even means. instead it may be possible to use the bits as extra indices
341 (EXTRA6) to access the full 64 CRs. TBD, several ideas
342
343 The actual width of the CRs cannot be altered: they are 4 bit. Thus,
344 for Rc=1 operations that produce a result and corresponding CR, it is
345 the result to which the elwidth override applies, not the CR.
346
347 As mentioned TBD, this leaves crops etc. to have a meaning defined for
348 elwidth, because these ops are pure explicit CR based.
349
350 Examples: mfxm may take the extra bits and use them as extra mask bits.
351
352 # SUBVL Encoding
353
354 the default for SUBVL is 1 and its encoding is 0b00 to indicate that
355 SUBVL is effectively disabled (a SUBVL for-loop of only one element). this
356 lines up in combination with all other "default is all zeros" behaviour.
357
358 | Value | Mnemonic | xxx | Description |
359 |-------|-----------|---------|------------------------|
360 | 00 | `SUBVL=1` | default | Sub-vector length of 1 |
361 | 01 | `SUBVL=2` | vec2 | Sub-vector length of 2 |
362 | 10 | `SUBVL=3` | vec3 | Sub-vector length of 3 |
363 | 11 | `SUBVL=4` | vec4 | Sub-vector length of 4 |
364
365 The SUBVL encoding value may be thought of as an inclusive range of a
366 sub-vector. SUBVL=2 represents a vec2, its encoding is 0b01, therefore
367 this may be considered to be elements 0b00 to 0b01 inclusive.
368
369 # MASK/MASK_SRC & MASK_KIND Encoding
370
371 One bit (`MASKMODE`) indicates the mode: CR or Int predication. The two
372 types may not be mixed.
373
374 Special note: to get default behaviour (SV disabled) this field must
375 be set to zero in combination with Integer Predication also being set
376 to 0b000. this has the effect of enabling "all 1s" in the predicate
377 mask, which is equivalent to "not having any predication at all"
378 and consequently, in combination with all other default zeros, fully
379 disables SV.
380
381 | Value | Description |
382 |-------|------------------------------------------------------|
383 | 0 | MASK/MASK_SRC are encoded using Integer Predication |
384 | 1 | MASK/MASK_SRC are encoded using CR-based Predication |
385
386 Integer Twin predication has a second set of 3 bits that uses the same
387 encoding thus allowing either the same register (r3 or r10) to be used
388 for both src and dest, or different regs (one for src, one for dest).
389
390 Likewise CR based twin predication has a second set of 3 bits, allowing
391 a different test to be applied.
392
393 ## Integer Predication (MASK_KIND=0)
394
395 When the predicate mode bit is zero the 3 bits are interpreted as below.
396 Twin predication has an identical 3 bit field similarly encoded.
397
398 | Value | Mnemonic | Element `i` enabled if: |
399 |-------|----------|------------------------------|
400 | 000 | ALWAYS | (Operation is not masked) |
401 | 001 | 1 << R3 | `i == R3` |
402 | 010 | R3 | `R3 & (1 << i)` is non-zero |
403 | 011 | ~R3 | `R3 & (1 << i)` is zero |
404 | 100 | R10 | `R10 & (1 << i)` is non-zero |
405 | 101 | ~R10 | `R10 & (1 << i)` is zero |
406 | 110 | R30 | `R30 & (1 << i)` is non-zero |
407 | 111 | ~R30 | `R30 & (1 << i)` is zero |
408
409 ## CR-based Predication (MASK_KIND=1)
410
411 When the predicate mode bit is one the 3 bits are interpreted as below.
412 Twin predication has an identical 3 bit field similarly encoded
413
414 | Value | Mnemonic | Description |
415 |-------|----------|-------------------------------------------------|
416 | 000 | lt | Element `i` is enabled if `CR[6+i].LT` is set |
417 | 001 | nl/ge | Element `i` is enabled if `CR[6+i].LT` is clear |
418 | 010 | gt | Element `i` is enabled if `CR[6+i].GT` is set |
419 | 011 | ng/le | Element `i` is enabled if `CR[6+i].GT` is clear |
420 | 100 | eq | Element `i` is enabled if `CR[6+i].EQ` is set |
421 | 101 | ne | Element `i` is enabled if `CR[6+i].EQ` is clear |
422 | 110 | so/un | Element `i` is enabled if `CR[6+i].FU` is set |
423 | 111 | ns/nu | Element `i` is enabled if `CR[6+i].FU` is clear |
424
425 CR based predication. TODO: select alternate CR for twin predication? see
426 [[discussion]] Overlap of the two CR based predicates must be taken
427 into account, so the starting point for one of them must be suitably
428 high, or accept that for twin predication VL must not exceed the range
429 where overlap will occur, *or* that they use the same starting point
430 but select different *bits* of the same CRs
431
432 # Twin Predication
433
434 This is a novel concept that allows predication to be applied to a single
435 source and a single dest register. The following types of traditional
436 Vector operations may be encoded with it, *without requiring explicit
437 opcodes to do so*
438
439 * VSPLAT (a single scalar distributed across a vector)
440 * VEXTRACT (like LLVM IR [`extractelement`](https://releases.llvm.org/11.0.0/docs/LangRef.html#extractelement-instruction))
441 * VINSERT (like LLVM IR [`insertelement`](https://releases.llvm.org/11.0.0/docs/LangRef.html#insertelement-instruction))
442 * VCOMPRESS (like LLVM IR [`llvm.masked.compressstore.*`](https://releases.llvm.org/11.0.0/docs/LangRef.html#llvm-masked-compressstore-intrinsics))
443 * VEXPAND (like LLVM IR [`llvm.masked.expandload.*`](https://releases.llvm.org/11.0.0/docs/LangRef.html#llvm-masked-expandload-intrinsics))
444
445 Those patterns (and more) may be applied to:
446
447 * mv (the usual way that V\* ISA operations are created)
448 * exts\* sign-extension
449 * rwlinm and other RS-RA shift operations (**note**: excluding
450 those that take RA as both a src and dest. These are not
451 1-src 1-dest, they are 2-src, 1-dest)
452 * LD and ST (treating AGEN as one source)
453 * FP fclass, fsgn, fneg, fabs, fcvt, frecip, fsqrt etc.
454 * Condition Register ops mfcr, mtcr and other similar
455
456 This is a huge list that creates extremely powerful combinations,
457 particularly given that one of the predicate options is `(1<<r3)`
458
459 Additional unusual capabilities of Twin Predication include a back-to-back
460 version of VCOMPRESS-VEXPAND which is effectively the ability to do an
461 ordered multiple VINSERT.
462
463 # Register Naming
464
465 SV Registers are simply the INT, FP and CR register files extended
466 linearly to larger sizes. Thus, the integer regfile in standard scalar
467 OpenPOWER v3.0B and v3.1B is r0 to r31: SV extends this as r0 to r127.
468 Likewise FP registers are extended to 128 (fp0 to fp127), and CRs are
469 extended to 64 entries, CR0 thru CR63.
470
471 The names of the registers therefore reflects a simple linear extension
472 of the OpenPOWER v3.0B / v3.1B register naming, and in hardware this
473 would be reflected by a linear increase in the size of the underlying
474 SRAM used for the regfiles.
475
476 Note: when the EXTRA fields are all zero, SV is deliberately designed
477 so that the register fields are identical to as if SV was not in effect
478 i.e. under these circumstances (EXTRA=0) the register field names RA,
479 RB etc. are interpreted as v3.0B / v3.1B scalar registers. This is termed
480 `scalar identity behaviour`
481
482 # Operation
483
484 ## CR fields as inputs/outputs of vector operations
485
486 When vectorized, the CR inputs/outputs are sequentially read/written
487 to 4-bit CR fields. Vectorised Integer results, when Rc=1, will begin
488 writing to CR8 (TBD evaluate) and increase sequentially from there. Vectorised FP
489 results, when Rc=1, start from CR32 (TBD evaluate). This is so that:
490
491 * scalar Rc=1 operation (CR0, CR1) and callee-saved CRs (CR2-4) are not overwritten by vector Rc=1 operations except for very large VL
492 * Vector FP and Integer Rc=1 operations do not overwrite each other except for large VL.
493
494 However when the SV result (destination) is marked as a scalar by the
495 EXTRA field the *standard* v3.0B behaviour applies: the accompanying
496 CR when Rc=1 is written to. This is CR0 for integer operations and CR1
497 for FP operations.
498
499 Note that yes, the CRs are genuinely Vectorised. Unlike in SIMD VSX which
500 has a single CR (CR6) for a given SIMD result, SV Vectorised OpenPOWER
501 v3.0B scalar operations produce a **tuple** of element results: the
502 result of the operation as one part of that element *and a corresponding
503 CR element*. Greatly simplified pseudocode:
504
505 for i in range(VL):
506 # calculate the vector result of an add
507 iregs[RT+i] = iregs[RA+i] + iregs[RB+i]
508 # now calculate CR bits
509 CRs[8+i].eq = iregs[RT+i] == 0
510 CRs[8+i].gt = iregs[RT+i] > 0
511 ... etc
512
513 If a "cumulated" CR based analysis of results is desired (a la VSX CR6) then a followup instruction must be performed, setting "reduce" mode on the Vector of CRs, using cr ops (crand, crnor)to do so. This provides far more flexibility in analysing vectors than standard Vector ISAs. Normal Vector ISAs are typically restricted to "were all results nonzero" and "were some results nonzero". The application of mapreduce to Vectorised cr operations allows far more sophisticated analysis, particularly in conjunction with the new crweird operations see [[sv/cr_int_predication]].
514
515 Note in particular that the use of a separate instruction in this way ensures that high performance multi-issue OoO inplementations do not have the computation of the cumulative analysis CR as a bottleneck and hindrance, regardless of the length of VL.
516
517 (see [[discussion]]. some alternative schemes are described there)
518
519 ## Table of CR fields
520
521 CR[i] is the notation used by the OpenPower spec to refer to CR field #i,
522 so FP instructions with Rc=1 write to CR[1] aka SVCR1_000.
523
524 CRs are not stored in SPRs: they are registers in their own right.
525 Therefore context-switching the full set of CRs involves a Vectorised
526 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.
527
528 The 64 SV CRs are arranged similarly to the way the 128 integer registers
529 are arranged. TODO a python program that auto-generates a CSV file
530 which can be included in a table, which is in a new page (so as not to
531 overwhelm this one). [[svp64/cr_names]]
532
533
534
535 # Register Profiles
536
537 **NOTE THIS TABLE SHOULD NO LONGER BE HAND EDITED** see
538 <https://bugs.libre-soc.org/show_bug.cgi?id=548> for details.
539
540 Instructions are broken down by Register Profiles as listed in the
541 following auto-generated page: [[opcode_regs_deduped]]. "Non-SV"
542 indicates that the operations with this Register Profile cannot be
543 Vectorised (mtspr, bc, dcbz, twi)
544
545 TODO generate table which will be here [[svp64/reg_profiles]]
546