clarify REMAP modes
[libreriscv.git] / openpower / sv / rfc / ls001.mdwn
1 # OPF ISA WG External RFC LS001 v2 14Sep2022
2
3 * RFC Author: Luke Kenneth Casson Leighton.
4 * RFC Contributors/Ideas: Brad Frey, Paul Mackerras, Konstantinos Magritis,
5 Cesar Strauss, Jacob Lifshay, Toshaan Bharvani, Dimitry Selyutin, Andrey
6 Miroshnikov
7 * Funded by NLnet under the Privacy and Enhanced Trust Programme, EU
8 Horizon2020 Grant 825310
9 * <https://git.openpower.foundation/isa/PowerISA/issues/64>
10 [[ls001/discussion]]
11
12 This proposal is to extend the Power ISA with an Abstract RISC-Paradigm
13 Vectorisation Concept that may be orthogonally applied to **all and any** suitable
14 Scalar instructions, present and future, in the Scalar Power ISA.
15 The Vectorisation System is called
16 ["Simple-V"](https://libre-soc.org/openpower/sv/)
17 and the Prefix Format is called
18 ["SVP64"](https://libre-soc.org/openpower/sv/).
19 **Simple-V is not a Traditional Vector ISA and therefore
20 does not add Vector opcodes or regfiles**.
21 An ISA Concept similar to Simple-V was originally invented in 1994 by
22 Peter Hsu (Architect of the MIPS R8000) but was dropped as MIPS did not
23 have an Out-of-Order Microarchitecture at the time.
24
25 Simple-V is designed for Embedded Scenarios right the way through
26 Audio/Visual DSPs to 3D GPUs and Supercomputing. As it does **not**
27 add actual Vector Instructions, relying solely and exclusively on the
28 **Scalar** ISA, it is **Scalar** instructions that need to be added to
29 the **Scalar** Power ISA before Simple-V may orthogonally Vectorise them.
30
31 The goal of RED Semiconductor Ltd, an OpenPOWER
32 Stakeholder, is to bring to market mass-volume general-purpose compute
33 processors that are competitive in the 3D GPU Audio Visual DSP EDGE IoT
34 desktop chromebook netbook smartphone laptop markets, performance-leveraged
35 by Simple-V. Simple-V thus has to
36 be accompanied by corresponding **Scalar** instructions that bring the
37 **Scalar** Power ISA up-to-date. These include IEEE754
38 [Transcendentals](https://libre-soc.org/openpower/transcendentals/)
39 [AV](https://libre-soc.org/openpower/sv/av_opcodes/)
40 cryptographic
41 [Biginteger](https://libre-soc.org/openpower/sv/biginteger/) and
42 [bitmanipulation](https://libre-soc.org/openpower/sv/bitmanip)
43 operations that ARM
44 Intel AMD and many other ISAs have been adding over the past 12 years
45 and Power ISA has not. Three additional FP-related sets are needed
46 (missing from SFFS) -
47 [int_fp_mv](https://libre-soc.org/openpower/sv/int_fp_mv/)
48 [fclass](https://libre-soc.org/openpower/sv/fclass/) and
49 [fcvt](https://libre-soc.org/openpower/sv/fcvt/)
50 and one set named
51 [crweird](https://libre-soc.org/openpower/sv/cr_int_predication/)
52 increase the capability of CR Fields.
53
54 *Thus it becomes necesary to consider the Architectural Resource
55 Allocation of not just Simple-V but the 80-100 Scalar instructions all
56 at the same time*.
57
58 It is also critical to note that Simple-V **does not modify the Scalar
59 Power ISA**, that **only** Scalar words may be
60 Vectorised, and that Vectorised instructions are **not** permitted to be
61 different from their Scalar words (`addi` must use the same Word encoding
62 as `sv.addi`, and any new Prefixed instruction added **must** also
63 be added as Scalar).
64 The sole semi-exception is Vectorised
65 Branch Conditional, in order to provide the usual Advanced Branching
66 capability present in every Commercial 3D GPU ISA, but it
67 is the *Vectorised* Branch-Conditional that is augmented, not Scalar
68 Branch.
69
70 # Basic principle
71
72 The inspiration for Simple-V came from the fact that on examination of every
73 Vector ISA pseudocode encountered the Vector operations were expressed
74 as a for-loop on a Scalar element
75 operation, and then both a Scalar **and** a Vector instruction was added.
76 With Zero-Overhead Looping *already* being mainstream in DSPs for over three
77 decades it felt natural to separate the looping at both the ISA and
78 the Hardware Level
79 and thus provide only Scalar instructions (instantly halving the number
80 of instructions), but rather than go the VLIW route (TI MSP Series)
81 keep closely to existing Power ISA standard Scalar execution.
82
83 Thus the basic principle of Simple-V is to provide a Precise-Interruptible
84 Zero-Overhead Loop system[^zolc] with associated register "offsetting"
85 which augments a Suffixed instruction as a "template",
86 incrementing the register numbering progressively *and automatically*
87 each time round the "loop". Thus it may be considered to be a form
88 of "Sub-Program-Counter" and at its simplest level can replace a large
89 sequence of regularly-increasing loop-unrolled instructions with just two:
90 one to set the Vector length and one saying where to
91 start from in the regfile.
92
93 On this sound and profoundly simple concept which leverages *Scalar*
94 Micro-architectural capabilities much more comprehensive festures are
95 easy to add, working up towards an ISA that easily matches the capability
96 of powerful 3D GPU Vector Supercomputing ISAs, without ever adding even
97 one single Vector opcode.
98
99 # Extension Levels
100
101 Simple-V has been subdivided into levels akin to the Power ISA Compliancy
102 Levels. For now let us call them "SV Extension Levels" to differentiate
103 the two. The reason for the
104 [SV Extension Levels](https://libre-soc.org/openpower/sv/compliancy_levels/)
105 is the same as for the
106 Power ISA Compliancy Levels (SFFS, SFS): to not overburden implementors
107 with features that they do not need. *There is no dependence between
108 the two types of Levels*. The resources below therefore are
109 not all required for all SV Extension Levels but they are all required
110 to be reserved.
111
112 # Binary Interoperability
113
114 Power ISA has a reputation as being long-term stable.
115 **Simple-V guarantees binary interoperability** by defining fixed
116 register file bitwidths and size for all instructions.
117 The seduction of permitting different implementors to choose a register file
118 bitwidth and size with the same instructions unfortunately has
119 the catastrophic side-effect of introducing not only binary incompatibility
120 but silent data corruption as well as no means to trap-and-emulate differing
121 bitwidths.[^vsx256]
122
123 "Silicon-Partner" Scalability is identical to mixing 32-bit Power ISA
124 with 64-bit in the same binary (just as catastrophic), and
125 is prohibited in the Simple-V Scalable Vector ISA,
126 `RESERVED` space is thus crucial to have, in order
127 to provide the option of
128 future expanded register file bitwidths and sizes[^msr],
129 under **explicitly-distinguishable** encoding,
130 **at the discretion of the OPF ISA WG**,
131 not the implementor ("Silicon Partner").
132
133 # Hardware Implementations
134
135 The fundamental principle of Simple-V is that it sits between Issue and
136 Decode, pausing the Program-Counter to service a "Sub-PC"
137 hardware for-loop. This is very similar to "Zero-Overhead Loops"
138 in High-end DSPs (TI MSP Series).
139
140 Considerable effort has been expended to ensure that Simple-V is
141 practical to implement on an extremely wide range of Industry-wide
142 common **Scalar** micro-architectures. Finite State Machine (for
143 ultra-low-resource and Mission-Critical), In-order single-issue, all the
144 way through to Great-Big Out-of-Order Superscalar Multi-Issue. The
145 SV Extension Levels specifically recognise these differing scenarios.
146
147 SIMD back-end ALUs particularly those with element-level predicate
148 masks may be exploited to good effect with very little additional
149 complexity to achieve high throughput, even on a single-issue in-order
150 microarchitecture. As usually becomes quickly apparent with in-order, its
151 limitations extend also to when Simple-V is deployed, which is why
152 Multi-Issue Out-of-Order is the recommended (but not mandatory) Scalar
153 Micro-architecture. Byte-level write-enable regfiles (like SRAMs) are
154 strongly recommended, to avoid a Read-Modify-Write cycle.
155
156 The only major concern is in the upper SV Extension Levels: the Hazard
157 Management for increased number of Scalar Registers to 128 (in current
158 versions) but given that IBM POWER9/10 has VSX register numbering 64,
159 and modern GPUs have 128, 256 amd even 512 registers this was deemed
160 acceptable. Strategies do exist in hardware for Hazard Management of
161 such large numbers of registers, even for Multi-Issue microarchitectures.
162
163 # Simple-V Architectural Resources
164
165 * No new Interrupt types are required.
166 No modifications to existing Power ISA opcodes are required.
167 No new Register Files are required (all because Simple-V is a category of
168 Zero-Overhead Looping on Scalar instructions)
169 * GPR FPR and CR Field Register extend to 128. A future
170 version may extend to 256 or beyond[^extend] or also extend VSX[^futurevsx]
171 * 24-bits are needed within the main SVP64 Prefix (equivalent to a 2-bit XO)
172 * Another 24-bit (a second 2-bit XO) is needed for a planned future encoding,
173 currently named "SVP64-Single"[^likeext001]
174 * A third 24-bits (third 2-bit XO) is strongly recommended to be `RESERVED`
175 such that future unforeseen capability is needed (although this may be
176 alternatively achieved with a mandatory PCR or MSR bit)
177 * To hold all Vector Context, five SPRs are needed for userspace.
178 If Supervisor and Hypervisor mode are to
179 also support Simple-V they will correspondingly need five SPRs each.
180 (Some 32/32-to-64 aliases are advantageous but not critical).
181 * Five 6-bit XO (A-Form) "Management" instructions are needed. These are
182 Scalar 32-bit instructions and *may* be 64-bit-extended in future
183 (safely within the SVP64 space: no need for an EXT001 encoding).
184
185 **Summary of Simple-V Opcode space**
186
187 * 75% of one Major Opcode (equivalent to the rest of EXT017)
188 * Five 6-bit XO 32-bit operations.
189
190 No further opcode space *for Simple-V* is envisaged to be required for
191 at least the next decade (including if added on VSX)
192
193 **Simple-V SPRs**
194
195 * **SVSTATE** - Vectorisation State sufficient for Precise-Interrupt
196 Context-switching and no adverse latency, it may be considered to
197 be a "Sub-PC" and as such absolutely must be treated with the same
198 respect and priority as MSR and PC.
199 * **SVSRR0** - identical in purpose to SRR0/1: storing SVSTATE on context-switch
200 along-side MSR and PC.
201 * **SVSHAPE0-3** - these are 32-bit and may be grouped in pairs, they REMAP
202 (shape) the Vectors[^svshape]
203 * **SVLR** - again similar to LR for exactly the same purpose, SVSTATE
204 is swapped with SVLR by SV-Branch-Conditional for exactly the same
205 reason that NIA is swapped with LR
206
207 **Vector Management Instructions**
208
209 These fit into QTY 5of 6-bit XO 32-bit encoding (svshape and svshape2 share
210 the same space):
211
212 * **setvl** - Cray-style Scalar Vector Length instruction
213 * **svstep** - used for Vertical-First Mode and for enquiring about internal
214 state
215 * **svremap** - "tags" registers for activating REMAP
216 * **svshape** - convenience instruction for quickly setting up Matrix, DCT,
217 FFT and Parallel Reduction REMAP
218 * **svshape2** - additional convenience instruction to set up "Offset" REMAP
219 (fits within svshape's XO encoding)
220 * **svindex** - convenience instruction for setting up "Indexed" REMAP.
221
222 \newpage{}
223 # SVP64 24-bit Prefixes
224
225 The SVP64 24-bit Prefix (RM) options aim to reduce instruction count
226 and assembler complexity.
227 These Modes do not interact with SVSTATE per se. SVSTATE
228 primarily controls the looping (quantity, order), RM
229 influences the *elements* (the Suffix). There is however
230 some close interaction when it comes to predication.
231 REMAP is outlined separately.
232
233 * **element-width overrides**, which dynamically redefine each SFFS or SFS
234 Scalar prefixed instruction to be 8-bit, 16-bit, 32-bit or 64-bit
235 operands **without requiring new 8/16/32 instructions.**[^pseudorewrite]
236 This results in full BF16 and FP16 opcodes being added to the Power ISA
237 **without adding BF16 or FP16 opcodes** including full conversion
238 between all formats.
239 * **predication**.
240 this is an absolutely essential feature for a 3D GPU VPU ISA.
241 CR Fields are available as Predicate Masks hence the reason for their
242 extension to 128. Twin-Predication is also provided: this may best
243 be envisaged as back-to-back VGATHER-VSCATTER but is not restricted
244 to LD/ST, its use saves on instruction count. Enabling one or other
245 of the predicates provides all of the other types of operations
246 found in Vector ISAs (VEXTRACT, VINSERT etc) again with no need
247 to actually provide explicit such instructions.
248 * **Saturation**. applies to **all** LD/ST and Arithmetic and Logical
249 operations (without adding explicit saturation ops)
250 * **Reduction and Prefix-Sum** (Fibonnacci Series) Modes, including a
251 "Reverse Gear" (running loops in reverse order).
252 * **vec2/3/4 "Packing" and "Unpacking"** (similar to VSX `vpack` and `vpkss`)
253 accessible in a way that is easier than REMAP, added for the same reasons
254 that drove `vpack` and `vpkss` etc. to be added: pixel, audio, and 3D
255 data manipulation. With Pack/Unpack being part of SVSTATE it can be
256 applied *in-place* saving register file space (no copy/mv needed).
257 * **Load/Store "fault-first"** speculative behaviour,
258 identical to SVE and RVV
259 Fault-first: provides auto-truncation of a speculative sequential parallel
260 LD/ST batch, helping
261 solve the "SIMD Considered Harmful" stripmining problem from a Memory
262 Access perspective.
263 * **Data-Dependent Fail-First**: a 100% Deterministic extension of the LDST
264 ffirst concept: first `Rc=1 BO test` failure terminates looping and
265 truncates VL to that exact point. Useful for implementing algorithms
266 such as `strcpy` in around 14 high-performance Vector instructions, the
267 option exists to include or exclude the failing element.
268 * **Predicate-result**: a strategic mode that effectively turns all and any
269 operations into a type of `cmp`. An `Rc=1 BO test` is performed and if
270 failing that element result is **not** written to the regfile. The `Rc=1`
271 Vector of co-results **is** always written (subject to usual predication).
272 Termed "predicate-result" because the combination of producing then
273 testing a result is as if the test was in a follow-up predicated
274 copy/mv operation, it reduces regfile pressure and instruction count.
275 Also useful on saturated or other overflowing operations, the overflowing
276 elements may be excluded from outputting to the regfile then
277 post-analysed outside of critical hot-loops.
278
279 **RM Modes**
280
281 There are five primary categories of instructions in Power ISA, each of
282 which needed slightly different Modes. For example, saturation and
283 element-width overrides are meaningless to Condition Register Field
284 operations, and Reduction is meaningless to LD/ST but Saturation
285 saves register file ports in critical hot-loops. Thus the 24 bits may
286 be suitably adapted to each category.
287
288 * Normal - arithmetic and logical including IEEE754 FP
289 * LD/ST immediate - includes element-strided and unit-strided
290 * LD/ST indexed
291 * CR Field ops
292 * Branch-Conditional - saves on instruction count in 3D parallel if/else
293
294 It does have to be pointed out that there is huge pressure on the
295 Mode bits. There was therefore insufficient room, unlike the way that
296 EXT001 was designed, to provide "identifying bits" *without first partially
297 decoding the Suffix*. This should in no way be conflated with or taken
298 as an indicator that changing the meaning of the Suffix is performed
299 or desirable.
300
301 Some considerable care has been taken to ensure that Decoding may be
302 performed in a strict forward-pipelined fashion that, aside from changes in
303 SVSTATE (necessarily cached and propagated alongside MSR and PC)
304 and aside from the initial 32/64 length detection (also kept simple),
305 a Multi-Issue Engine would have no difficulty (performance maximisable).
306 With the initial partial RM Mode type-identification
307 decode performed above the Vector operations may then
308 easily be passed downstream in a fully forward-progressive piplined fashion
309 to independent parallel units for further analysis.
310
311 **Vectorised Branch-Conditional**
312
313 As mentioned in the introduction this is the one sole instruction group
314 that
315 is different pseudocode from its scalar equivalent. However even there
316 its various Mode bits and options can be set such that in the degenerate
317 case the behaviour becomes identical to Scalar Branch-Conditional.
318
319 The two additional Modes within Vectorised Branch-Conditional, both of
320 which may be combined, are `CTR-Mode` and `VLI-Test` (aka "Data Fail First").
321 CTR Mode extends the way that CTR may be decremented unconditionally
322 within Scalar Branch-Conditional, and not only makes it conditional but
323 also interacts with predication. VLI-Test provides the same option
324 as Data-Dependent Fault-First to Deterministically truncate the Vector
325 Length at the fail **or success** point.
326
327 Boolean Logic rules on sets (treating the Vector of CR Fields to be tested by
328 `BO` as a set) dictate that the Branch should take place on either 'ALL'
329 tests succeeding (or failing) or whether 'SOME' tests succeed (or fail).
330 These options provide the ability to cover the majority of Parallel
331 3D GPU Conditions, saving a not inconsiderable number of instructions
332 especially given the close interaction with CTR in hot-loops.
333
334 Also `SVLR` is introduced, which is a parallel twin of `LR`, and saving
335 and restoring of LR and SVLR may be deferred until the final decision
336 as to whether to branch. In this way `sv.bclrl` does not corrupt `LR`.
337
338 Vectorised Branch-Conditional due to its side-effects (e.g. reducing CTR
339 or truncating VL) has practical uses even if the Branch is deliberately
340 set to the next instruction (CIA+8). For example it may be used to reduce
341 CTR by the number of bits set in a GPR, if that GPR is given as the predicate
342 mask `sv.bc/pm=r3`.
343
344 # LD/ST RM Modes
345
346 Traditional Vector ISAs have vastly more (and more complex) addressing
347 modes: unit strided, element strided, Indexed, Structure Packing. All
348 of these had to be jammed in on top of existing Scalar instructions
349 **without modifying or adding new Scalar instructions**.
350 A small conceptual
351 "cheat" was therefore needed. The Immediate (D) is in some Modes
352 multiplied by the element index, which gives us element-strided.
353 For unit-strided the width of the operation (`ld`, 8 byte) is
354 multiplied by the element index and *substituted* for "D" when
355 the immediate, D, is zero. Modifications to support this
356 "cheat" on top of pre-existing Scalar HDL (and Simulators)
357 have both turned out to be minimal.[^mul]
358 Also added was the option to perform signed or unsigned Effective
359 Address calculation, which comes into play only on LD/ST Indexed,
360 when elwidth overrides are used. Another quirk: `RA` is never
361 allowed to have its width altered: it remains 64-bit, as it is
362 the Base Address.
363
364 One confusing thing is the unfortunate naming of LD/ST Indexed and
365 REMAP Indexed: some care is taken in the spec to discern the two.
366 LD/ST Indexed is Scalar `EA=RA+RB` (where **either** RA or RB
367 may be marked as Vectorised), where obviously the order in which
368 that Vector of RA (or RB) is read in the usual linear sequential
369 fashion. REMAP Indexed affects the
370 **order** in which the Vector of RA (or RB) is accessed,
371 according to a schedule determined by *another* vector of offsets
372 in the register file. Effectively this combines VSX `vperm`
373 back-to-back with LD/ST operations *in the calculation of each
374 Effective Address* in one instruction.
375
376 For DCT and FFT, normally it is very expensive to perform the
377 "bit-inversion" needed for address calculation and/or reordering
378 of elements. DCT in particular needs both bit-inversion *and
379 Gray-Coding* offsets (a complexity that often "justifies" full
380 assmbler loop-unrolling). DCT/FFT REMAP **automatically** performs
381 the required offset adjustment to get data loaded and stored in
382 the required order. Matrix REMAP can likewise perform up to 3
383 Dimensions of reordering (on both Immediate and Indexed), and
384 when combined with vec2/3/4 the reordering can even go as far as
385 four dimensions (four nested fixed size loops).
386
387 Twin Predication is worth a special mention. Many Vector ISAs have
388 special LD/ST `VCOMPRESS` and `VREDUCE` instructions, which sequentially
389 skip elements based on predicate mask bits. They also add special
390 `VINSERT` and `VEXTRACT` Register-based instructions to compensate
391 for lack of single-element LD/ST (where in Simple-V you just use
392 Scalar LD/ST). Also Broadcasting (`VSPLAT`) is either added to LDST
393 or as Register-based.
394
395 *All of the above modes are covered by Twin-Predication*
396
397 In particular, a special predicate mode `1<<r3` uses the register `r3`
398 *binary* value, converted to single-bit unary mask,
399 effectively as a single (Scalar) Index *runtime*-dynamic offset into
400 a Vector.[^r3] Combined with the
401 (mis-named) "mapreduce" mode when used as a source predicate
402 a `VSPLAT` (broadcast) is performed. When used as a destination
403 predicate `1<<r3`
404 provides `VINSERT` behaviour.
405
406 [^r3]: Effectively: `GPR(RA+r3)`
407
408 Also worth an explicit mention is that Twin Predication when using
409 different source from destination predicate masks effectively combines
410 back-to-back `VCOMPRESS` and `VEXPAND` (in a single instruction), and,
411 further, that the benefits of Twin Predication are not limited to LD/ST,
412 they may be applied to Arithmetic, Logical and CR Field operations as well.
413
414 Overall the LD/ST Modes available are astoundingly powerful, especially
415 when combining arithmetic (lharx) with saturation, element-width overrides,
416 Twin Predication,
417 vec2/3/4 Structure Packing *and* REMAP, the combinations far exceed anything
418 seen in any other Vector ISA in history, yet are really nothing more
419 than concepts abstracted out in pure RISC form.[^ldstcisc]
420
421 # CR Field RM Modes.
422
423 CR Field operations (`crand` etc.) are somewhat underappreciated in the
424 Power ISA. The CR Fields however are perfect for providing up to four
425 separate Vectors of Predicate Masks: `EQ LT GT SO` and thus some special
426 attention was given to first making transfer between GPR and CR Fields
427 much more powerful with the
428 [crweird](https://libre-soc.org/openpower/sv/cr_int_predication/)
429 operations, and secondly by adding powerful binary and ternary CR Field
430 operations into the bitmanip extension.[^crops]
431
432 On these instructions RM Modes may still be applied (mapreduce and Data-Dependent Fail-first). The usefulness of
433 being able to auto-truncate subsequent Vector Processing at the point
434 at which a CR Field test fails, based on any arbitary logical operation involving `three` CR Field Vectors (`crternlogi`) should be clear, as
435 should the benefits of being able to do mapreduce and REMAP Parallel
436 Reduction on `crternlogi`: dramatic reduction in instruction count
437 for Branch-based control flow when faced with complex analysis of
438 multiple Vectors, including XOR-reduction (parity).
439
440 Overall the addition of the CR Operations and the CR RM Modes is about
441 getting instruction count down and increasing the power and flexibility of CR Fields as pressed into service for the purpose of Predicate Masks.
442
443 [^crops]: the alternative to powerful transfer instructions between GPR and CR Fields was to add the full duplicated suite of BMI and TBM operations present in GPR (popcnt, cntlz, set-before-first) as CR Field Operations. all of which was deemed inappropriate.
444
445 # SVP64Single 24-bits
446
447 The `SVP64-Single` 24-bit encoding focusses primarily on ensuring that
448 all 128 Scalar registers are fully accessible, provides element-width
449 overrides, one-bit predication
450 and brings Saturation to all existing Scalar operations.
451 BF16 and FP16 are thus
452 provided in the Scalar Power ISA without one single explicit FP16 or BF16
453 32-bit opcode being added. The downside: such Scalar operations are
454 all 64-bit encodings.
455
456 As SVP64Single is new and still under development, space for it may
457 instead be `RESERVED`. It is however necessary in *some* form
458 as there are limitations
459 in SVP64 Register numbering, particularly for 4-operand instructions,
460 that can only be easily overcome by SVP64Single.
461
462 # Vertical-First Mode
463
464 This is a Computer Science term that needed first to be invented.
465 There exists only one other Vertical-First Vector ISA in the world:
466 Mitch Alsup's VVM Extension for the 66000, details of which may be
467 obtained publicly on `comp.arch` or directly from Mitch Alsup under
468 NDA. Several people have
469 independently derived Vertical-First: it simply did not have a
470 Computer Science term associated with it.
471
472 If we envisage register and Memory layout to be Horizontal and
473 instructions to be Vertical, and to then have some form of Loop
474 System (wherther Zero-Overhead or just branch-conditional based)
475 it is easier to then conceptualise VF vs HF Mode:
476
477 * Vertical-First progresses through *instructions* first before
478 moving on to the next *register* (or Memory-address in the case
479 of Mitch Alsup's VVM).
480 * Horizontal-First (also known as Cray-style Vectors) progresses
481 through **registers** (or, register *elements* in traditional
482 Cray-Vector ISAs) in full before moving on to the next *instruction*.
483
484 Mitch Alsup's VVM Extension is a form of hardware-level auto-vectorisation
485 based around Zero-Overhead Loops. Using a Variable-Length Encoding all
486 loop-invariant registers are "tagged" such that the Hazard Management
487 Engine may perform optimally and do less work in automatically identifying
488 parallelism opportunities.
489 With it not being appropriate to use Variable-Length Encoding in the Power
490 ISA a different much more explicit strategy was taken in Simple-V.
491
492 The biggest advantage inherent in Vertical-First is that it is very easy
493 to introduce into compilers, because all looping, as far as programs
494 is concerned, remains expressed as *Scalar assembler*.[^autovec]
495 Whilst Mitch Alsup's
496 VVM biggest strength is its hardware-level auto-vectorisation
497 but is limited in its ability to call
498 functions, Simple-V's Vertical-First provides explicit control over the
499 parallelism ("hphint")[^hphint] and also allows for full state to be stored/restored
500 (SVLR combined with LR), permitting full function calls to be made
501 from inside Vertical-First Loops, and potentially allows arbitrarily-depth
502 nested VF Loops.
503
504 Simple-V Vertical-First Looping requires an explicit instruction to
505 move `SVSTATE` regfile offsets forward: `svstep`. An early version of
506 Vectorised
507 Branch-Conditional attempted to merge the functionality of `svstep`
508 into `sv.bc`: it became CISC-like in its complexity and was quickly reverted.
509
510 # Simple-V REMAP subsystem
511
512 [REMAP](https://libre-soc.org/openpower/sv/remap)
513 is extremely advanced but brings features already present in other
514 DSPs and Supercomputing ISAs. The usual sequential progression
515 through elements is pushed through a hardware-defined
516 *fully Deterministic*
517 "remapping". Normally (without REMAP)
518 algorithms are costly or
519 convoluted to implement. They are typically implemented
520 as hard-coded fully loop-unrolled assembler which is often
521 auto-generated by specialist tools, or written
522 entirely by hand.
523 All REMAP Schedules *including Indexed*
524 are 100% Deterministic from their point of declaration,
525 making it possible to forward-plan
526 Issue, Memory access and Register Hazard Management
527 in Multi-Issue Micro-architectures.
528
529 If combined with Vertical-First then much more complex operations may exploit
530 REMAP Schedules, such as Complex Number FFTs, by using Scalar intermediary
531 temporary registers to compute results that have a Vector destination.
532 Contrast this with a Standard Horizontal-First Vector ISA where the only
533 way to perform Vectorised Complex Arithmetic would be to add Complex Vector
534 Arithmetic operations.
535
536 * **DCT/FFT** REMAP brings more capability than TI's MSP-Series DSPs and
537 Qualcom Hexagon DSPs, and is not restricted to Integer or FP.
538 (Galois Field is possible, implementing NTT). Operates *in-place*
539 significantly reducing register usage.
540 * **Matrix** REMAP brings more capability than any other Matrix Extension
541 (AMD GPUs, Intel, ARM), not being restricted to Power-2 sizes. Also not
542 limited to the type of operation, it may perform Warshall Transitive
543 Closure, Integer Matrix, Bitmanipulation Matrix, Galois Field (carryless
544 mul) Matrix, and with care potentially Graph Maximum Flow as well. Also
545 suited to Convolutions, Matrix Transpose and rotate, *all* of which is
546 in-place.
547 * **General-purpose Indexed** REMAP, this option is provided to implement
548 an equivalent of VSX `vperm`, as a general-purpose catch-all means of
549 covering algorithms outside of the other REMAP Engines.
550 * **Parallel Reduction** REMAP, performs an automatic map-reduce using
551 *any suitable scalar operation*.
552
553 All REMAP Schedules are Precise-Interruptible. No latency penalty is caused by
554 the fact that the Schedule is Parallel-Reduction, for example. The operations
555 are Issued (Deterministically) as **Scalar** operations and thus any latency
556 associated with **Scalar** operation Issue exactly as in a **Scalar**
557 Micro-architecture will result. Contrast this with a Standard Vector ISA
558 where frequently there is either considerable interrupt latency due to
559 requiring a Parallel Reduction to complete in full, or partial results
560 to be discarded and re-started should a high-priority Interrupt occur
561 in the middle.
562
563 Note that predication is possible on REMAP but is hard to use effectively.
564 It is often best to make copies of data (`VCOMPRESS`) then apply REMAP.
565
566 \newpage{}
567 # Scalar Operations
568
569 The primary reason for mentioning the additional Scalar operations
570 is because they are so numerous, with Power ISA not having advanced
571 in the *general purpose* compute area in the past 12 years, that some
572 considerable care is needed.
573
574 Summary:
575 **Including Simple-V, to fit everything at least 75% of 3 separate
576 Major Opcodes would be required**
577
578 Candidates (for all but the X-Form instructions) include:
579
580 * EXT006 (80% free)
581 * EXT017 (75% free but not recommended)
582 * EXT001 (50% free)
583 * EXT009 (100% free)
584 * EXT005 (100% free)
585 * brownfield space in EXT019 (25% but NOT recommended)
586
587 SVP64, SVP64-Single and SVP64-Reserved would require on their own each 25%
588 of one Major Opcode for a total of 75% of one Major Opcode. The remaining
589 **Scalar** opcodes, due to there being two separate sets of operations
590 with 16-bit immediates, will require the other space totalling two 75%
591 Majors.
592
593 Note critically that:
594
595 * Unlike EXT001, SVP64's 24-bits may **not** hold also any Scalar
596 operations. There is no free available space: a 25th bit would
597 be required. The entire 24-bits is **required** for the abstracted
598 Hardware-Looping Concept **even when these 24-bits are zero**
599 * Any Scalar 64-bit instruction (regardless of how it is encoded) is unsafe to
600 then Vectorise because this creates the situation of Prefixed-Prefixed,
601 resulting in deep complexity in Hardware Decode at a critical juncture, as
602 well as introducing 96-bit instructions.
603 * **All** of these Scalar instructions are candidates for Vectorisation.
604 Thus none of them may be 64-bit-Scalar-only.
605
606 **Minor Opcodes to fit candidates above**
607
608 In order of size, for bitmanip and A/V DSP purposes:
609
610 * QTY 3of 2-bit XO: ternlogi, crternlogi, grevlogi
611 * QTY 7of 3-bit XO: xpermi, binlut, grevlog, swizzle-mv/fmv, bitmask, bmrevi
612 * QTY 8of 5/6-bit (A-Form): xpermi, bincrflut, bmask, fmvis, fishmv, bmrev,
613 Galois Field
614 * QTY 30of 10-bit (X-Form): cldiv/mul, av-min/max/diff, absdac, xperm etc.
615 (easily fit EXT019, EXT031).
616
617 Note: Some of the Galois Field operations will require QTY 1of Polynomial
618 SPR (per userspace supervisor hypervisor).
619
620 **EXT004**
621
622 For biginteger math, two instructions in the same space as "madd" are to
623 be proposed. They are both 3-in 2-out operations taking or producing a
624 64-bit "pair" (like RTp), and perform 128/64 mul and div/mod operations
625 respectively. These are **not** the same as VSX operations which are
626 128/128, and they are **not** the same as existing Scalar mul/div/mod,
627 all of which are 64/64 (or 64/32).
628
629 **EXT059 and EXT063**
630
631 Additionally for High-Performance Compute and Competitive 3D GPU, IEEE754 FP
632 Transcendentals are required, as are some DCT/FFT "Twin-Butterfly" operations.
633 For each of EXT059 and EXT063:
634
635 * QTY 33of X-Form "1-argument" (fsin, fsins, fcos, fcoss)
636 * QTY 15of X-Form "2-argument" (pow, atan2, fhypot)
637 * QTY 5of A-Form "3-in 2-out" FP Butterfly operations for DCT/FFT
638 * QTY 8of X-Form "2-in 2-out" FP Butterfly operations (again for DCT/FFT)
639 * An additional 16 instructions for IEEE754-2019
640 (fminss/fmaxss, fminmag/fmaxmag)
641 [under evaluation](https://bugs.libre-soc.org/show_bug.cgi?id=923)
642 as of 08Sep2022
643
644 # Adding new opcodes.
645
646 With Simple-V being a type of Zero-Overhead Loop Engine on top of
647 Scalar operations some clear guidelines are needed on how both
648 existing "Defined Words" (Public v3.1 Section 1.6.3 term) and future
649 Scalar operations are added within the 64-bit space. Examples of
650 legal and illegal allocations are given later.
651
652 The primary point is that once an instruction is defined in Scalar
653 32-bit form its corresponding space **must** be reserved in the
654 SVP64 area with the exact same 32-bit form, even if that instruction
655 is "Unvectoriseable" (`sc`, `sync`, `rfid` and `mtspr` for example).
656 Instructions may **not** be added in the Vector space without also
657 being added in the Scalar space, and vice-versa, *even if Unvectoriseable*.
658
659 This is extremely important because the worst possible situation
660 is if a conflicting Scalar instruction is added by another Stakeholder,
661 which then turns out to be Vectoriseable: it would then have to be
662 added to the Vector Space with a *completely different Defined Word*
663 and things go rapidly downhill in the Decode Phase from there.
664 Setting a simple inviolate rule helps avoid this scenario but does
665 need to be borne in mind when discussing potential allocation
666 schemes, as well as when new Vectoriseable Opcodes are proposed
667 for addition by future RFCs: the opcodes **must** be uniformly
668 added to Scalar **and** Vector spaces, or added in one and reserved
669 in the other, or
670 not added at all in either.[^whoops]
671
672 \newpage{}
673 # Potential Opcode allocation solution (superseded)
674
675 *Note this scheme is superseded below but kept for completeness as it
676 defines terms and context*.
677 There are unfortunately some inviolate requirements that directly place
678 pressure on the EXT000-EXT063 (32-bit) opcode space to such a degree that
679 it risks jeapordising the Power ISA. These requirements are:
680
681 * all of the scalar operations must be Vectoriseable
682 * all of the scalar operations intended for Vectorisation
683 must be in a 32-bit encoding (not prefixed-prefixed to 96-bit)
684 * bringing Scalar Power ISA up-to-date from the past 12 years
685 needs 75% of two Major opcodes all on its own
686
687 There exists a potential scheme which meets (exceeds) the above criteria,
688 providing plenty of room for both Scalar (and Vectorised) operations,
689 *and* provides SVP64-Single with room to grow. It
690 is based loosely around Public v3.1 EXT001 Encoding.[^ext001]
691
692 | 0-5 | 6 | 7 | 8-31 | Description |
693 |-----|---|---|-------|---------------------------|
694 | PO | 0 | 0 | 0000 | new-suffix `RESERVED1` |
695 | PO | 0 | 0 | !zero | new-suffix, scalar (SVP64Single), or `RESERVED3` |
696 | PO | 1 | 0 | 0000 | new scalar-only word, or `RESERVED2` |
697 | PO | 1 | 0 | !zero | old-suffix, scalar (SVP64Single), or `RESERVED4` |
698 | PO | 0 | 1 | nnnn | new-suffix, vector (SVP64) |
699 | PO | 1 | 1 | nnnn | old-suffix, vector (SVP64) |
700
701 * **PO** - Primary Opcode. Likely candidates: EXT005, EXT009
702 * **bit 6** - specifies whether the suffix is old (EXT000-EXT063)
703 or new (EXTn00-EXTn63, n greater than 1)
704 * **bit 7** - defines whether the Suffix is Scalar-Prefixed or Vector-Prefixed
705 (caveat: see bits 8-31)
706 * **old-suffix** - the EXT000 to EXT063 32-bit Major opcodes of Power ISA 3.0
707 * **new scalar-only** - a **new** Major Opcode area **exclusively**
708 for Scalar-only instructions that shall **never** be Prefixed by SVP64
709 (RESERVED2 EXT300-EXT363)
710 * **new-suffix** - a **new** Major Opcode area (RESERVED1 EXT200-EXT263)
711 that **may** be Prefixed by SVP64 and SVP64Single
712 * **0000** - all 24 bits bits 8-31 are zero (0x000000)
713 * **!zero** - bits 8-31 may be any value *other* than zero (0x000001-0xffffff)
714 * **nnnn** - bits 8-31 may be any value in the range 0x000000 to 0xffffff
715 * **SVP64Single** - a ([TBD](https://bugs.libre-soc.org/show_bug.cgi?id=905))
716 *Scalar* Encoding that is near-identical to SVP64
717 except that it is equivalent to hard-coded VL=1
718 at all times. Predication is permitted, Element-width-overrides is
719 permitted, Saturation is permitted.
720 If not allocated within the scope of this RFC
721 then these are requested to be `RESERVED` for a future Simple-V
722 proposal.
723 * **SVP64** - a (well-defined, 2 years) DRAFT Proposal for a Vectorisation
724 Augmentation of suffixes.
725
726 For the needs identified by Libre-SOC (75% of 2 POs),
727 `RESERVED1` space *needs*
728 allocation to new POs, `RESERVED2` does not.[^only2]
729
730 | | Scalar (bit7=0,8-31=0000) | Scalar (bit7=0,8-31=!zero)| Vector (bit7=1) |
731 |----------|---------------------------|---------------------------|------------------|
732 |new bit6=0| `RESERVED1`:{EXT200-263} | `RESERVED3`:SVP64-Single:{EXT200-263} | SVP64:{EXT200-263} |
733 |old bit6=1| `RESERVED2`:{EXT300-363} | `RESERVED4`:SVP64-Single:{EXT000-063} | SVP64:{EXT000-063} |
734
735 * **`RESERVED2`:{EXT300-363}** (not strictly necessary to be added) is not
736 and **cannot** ever be Vectorised or Augmented by Simple-V or any future
737 Simple-V Scheme.
738 it is a pure **Scalar-only** word-length PO Group. It may remain `RESERVED`.
739 * **`RESERVED1`:{EXT200-263}** is also a new set of 64 word-length Major
740 Opcodes.
741 These opcodes would be Simple-V-Augmentable
742 unlike `EXT300-363` which may **never** be Simple-V-Augmented
743 under any circumstances.
744 * **RESERVED3:`SVP64-Single:{EXT200-263}`** - Major opcodes 200-263 with
745 Single-Augmentation, providing a one-bit predicate mask, element-width
746 overrides on source and destination, and the option to extend the Scalar
747 Register numbering (r0-32 extends to r0-127). **Placing of alternative
748 instruction encodings other than those exactly defined in EXT200-263
749 is prohibited**.
750 * **RESERVED4:`SVP64-Single:{EXT000-063}`** - Major opcodes 000-063 with
751 Single-Augmentation, just like SVP64-Single on EXT200-263, these are
752 in effect Single-Augmented-Prefixed variants of the v3.0 32-bit Power ISA.
753 Alternative instruction encodings other than the exact same 32-bit word
754 from EXT000-EXT063 are likewise prohibited.
755 * **`SVP64:{EXT000-063}`** and **`SVP64:{EXT200-263}`** - Full Vectorisation
756 of EXT000-063 and EXT200-263 respectively, these Prefixed instructions
757 are likewise prohibited from being a different encoding from their
758 32-bit scalar versions.
759
760 Limitations of this scheme is that new 32-bit Scalar operations have to have
761 a 32-bit "prefix pattern" in front of them. If commonly-used this could
762 increase binary size. Thus the Encodings EXT300-363 and EXT200-263 should
763 only be allocated for less-popular operations. However the scheme does
764 have the strong advantage of *tripling* the available number of Major
765 Opcodes in the Power ISA, caveat being that care on allocation is needed
766 because EXT200-EXT263 may be SVP64-Augmented whilst EXT300-EXT363 may **not**.
767 The issues of allocation for bitmanip etc. from Libre-SOC is therefore
768 overwhelmingly made moot. The only downside is that there is no
769 `SVP64-Reserved` which will have to be achieved with SPRs (PCR or MSR).
770
771 *Most importantly what this scheme does not do is provide large areas
772 for other (non-Vectoriseable) RFCs.*
773
774 # Potential Opcode allocation solution (2)
775
776 One of the risks of the bit 6/7 scheme above is that there is no
777 room to share PO9 (EXT009) with other potential uses. A workaround for
778 that is as follows:
779
780 * EXT009, like EXT001 of Public v3.1, is **defined** as a 64-bit
781 encoding. This makes Multi-Issue Length-identification trivial.
782 * bit 6 if 0b1 is 100% for Simple-V augmentation of (Public v3.1 1.6.3)
783 "Defined Words" (aka EXT000-063), with the exception of 0x26000000
784 as a Prefix, which is a new RESERVED encoding.
785 * when bit 6 is 0b0 and bits 32-33 are 0b11 are **defined** as also
786 allocated to Simple-V
787 * all other patterns are `RESERVED` for other non-Vectoriseable
788 purposes (just over 37.5%).
789
790 | 0-5 | 6 | 7 | 8-31 | 32:33 | Description |
791 |-----|---|---|-------|-------|----------------------------|
792 | PO9?| 0 | 0 | !zero | 00-10 | RESERVED (other) |
793 | PO9?| 0 | 1 | xxxx | 00-10 | RESERVED (other) |
794 | PO9?| x | 0 | 0000 | xx | RESERVED (other) |
795 | PO9?| 0 | 0 | !zero | 11 | SVP64 (current and future) |
796 | PO9?| 0 | 1 | xxxx | 11 | SVP64 (current and future) |
797 | PO9?| 1 | 0 | !zero | xx | SVP64 (current and future) |
798 | PO9?| 1 | 1 | xxxx | xx | SVP64 (current and future) |
799
800 This ensures that any potential for future conflict over uses of the
801 EXT009 space, jeapordising Simple-V in the process, are avoided,
802 yet leaves huge areas (just over 37.5% of the 64-bit space) for other
803 (non-Vectoriseable) uses.
804
805 These areas thus need to be Allocated (SVP64 and Scalar EXT248-263):
806
807 | 0-5 | 6 | 7 | 8-31 | 32-3 | Description |
808 |-----|---|---|-------|------|---------------------------|
809 | PO | 0 | 0 | !zero | 0b11 | SVP64Single:EXT248-263, or `RESERVED3` |
810 | PO | 0 | 0 | 0000 | 0b11 | Scalar EXT248-263 |
811 | PO | 0 | 1 | nnnn | 0b11 | SVP64:EXT248-263 |
812 | PO | 1 | 0 | !zero | nn | SVP64Single:EXT000-063 or `RESERVED4` |
813 | PO | 1 | 1 | nnnn | nn | SVP64:EXT000-063 |
814
815 and reserved areas, QTY 1of 32-bit, and QTY 3of 55-bit, are:
816
817 | 0-5 | 6 | 7 | 8-31 | 32-3 | Description |
818 |-----|---|---|-------|------|---------------------------|
819 | PO9?| 1 | 0 | 0000 | xx | `RESERVED1` or EXT300-363 |
820 | PO9?| 0 | x | xxxx | 0b00 | `RESERVED2` or EXT200-216 |
821 | PO9?| 0 | x | xxxx | 0b01 | `RESERVED2` or EXT216-231 |
822 | PO9?| 0 | x | xxxx | 0b10 | `RESERVED2` or EXT232-247 |
823
824 Where:
825
826 * SVP64Single (`RESERVED3/4`) is *planned* for a future RFC
827 (but needs reserving as part of this RFC)
828 * `RESERVED1/2` is available for new general-purpose
829 (non-Vectoriseable) 32-bit encodings (other RFCs)
830 * EXT248-263 is for "new" instructions
831 which **must** be granted corresponding space
832 in SVP64.
833 * Anything Vectorised-EXT000-063 is **automatically** being
834 requested as 100% Reserved for every single "Defined Word"
835 (Public v3.1 1.6.3 definition). Vectorised-EXT001 or EXT009
836 is defined as illegal.
837 * Any **future** instruction
838 added to EXT000-063 likewise, must **automatically** be
839 assigned corresponding reservations in the SVP64:EXT000-063
840 and SVP64Single:EXT000-063 area, regardless of whether the
841 instruction is Vectoriseable or not.
842
843 Bit-allocation Summary:
844
845 * EXT3nn and other areas provide space for up to
846 QTY 4of non-Vectoriseable EXTn00-EXTn47 ranges.
847 * QTY 3of 55-bit spaces also exist for future use (longer by 3 bits
848 than opcodes allocated in EXT001)
849 * Simple-V EXT2nn is restricted to range EXT248-263
850 * non-Simple-V EXT2nn (if ever allocated by a future RFC) is restricted to range EXT200-247
851 * Simple-V EXT0nn takes up 50% of PO9 for this and future Simple-V RFCs
852
853 The clear separation between Simple-V and non-Simple-V stops
854 conflict in future RFCs, both of which get plenty of space.
855 EXT000-063 pressure is reduced in both Vectoriseable and
856 non-Vectoriseable, and the 100+ Vectoriseable Scalar operations
857 identified by Libre-SOC may safely be proposed and each evaluated
858 on their merits.
859
860 \newpage{}
861
862 **EXT000-EXT063**
863
864 These are Scalar word-encodings. Often termed "v3.0 Scalar" in this document
865 Power ISA v3.1 Section 1.6.3 Book I calls it a "defined word".
866
867 | 0-5 | 6-31 |
868 |--------|--------|
869 | PO | EXT000-063 "Defined word" |
870
871 **SVP64Single:{EXT000-063}** bit6=old bit7=scalar
872
873 This encoding, identical to SVP64Single:{EXT248-263},
874 introduces SVP64Single Augmentation of Scalar "defined words".
875 All meanings must be identical to EXT000-063, and is is likewise
876 prohibited to add an instruction in this area without also adding
877 the exact same (non-Augmented) instruction in EXT000-063 with the
878 exact same Scalar word.
879 Bits 32-37 0b00000 to 0b11111 represent EXT000-063 respectively.
880 Augmenting EXT001 or EXT009 is prohibited.
881
882 | 0-5 | 6 | 7 | 8-31 | 32-63 |
883 |--------|---|---|-------|---------|
884 | PO (9)?| 1 | 0 | !zero | SVP64Single:{EXT000-063} |
885
886 **SVP64:{EXT000-063}** bit6=old bit7=vector
887
888 This encoding is identical to **SVP64:{EXT248-263}** except it
889 is the Vectorisation of existing v3.0/3.1 Scalar-words, EXT000-063.
890 All the same rules apply with the addition that
891 Vectorisation of EXT001 or EXT009 is prohibited.
892
893 | 0-5 | 6 | 7 | 8-31 | 32-63 |
894 |--------|---|---|-------|---------|
895 | PO (9)?| 1 | 1 | nnnn | SVP64:{EXT000-063} |
896
897 **{EXT248-263}** bit6=new bit7=scalar
898
899 This encoding represents the opportunity to introduce EXT248-263.
900 It is a Scalar-word encoding, and does not require implementing
901 SVP64 or SVP64-Single, but does require the Vector-space to be allocated.
902 PO2 is in the range 0b11000 to 0b111111 to represent EXT248-263 respectively.
903
904 | 0-5 | 6 | 7 | 8-31 | 32-3 | 34-37 | 38-63 |
905 |--------|---|---|-------|------|---------|---------|
906 | PO (9)?| 0 | 0 | 0000 | 0b11 |PO2[2:5] | {EXT248-263} |
907
908 **SVP64Single:{EXT248-263}** bit6=new bit7=scalar
909
910 This encoding, which is effectively "implicit VL=1"
911 and comprising (from bits 8-31 being non-zero)
912 *at least some* form of Augmentation, it represents the opportunity
913 to Augment EXT248-263 with the SVP64Single capabilities.
914 Must be allocated under Scalar *and* SVP64 simultaneously.
915
916 | 0-5 | 6 | 7 | 8-31 | 32-3 | 34-37 | 38-63 |
917 |--------|---|---|-------|------|---------|---------|
918 | PO (9)?| 0 | 0 | !zero | 0b11 |PO2[2:5] | SVP64Single:{EXT248-263} |
919
920 **SVP64:{EXT248-263}** bit6=new bit7=vector
921
922 This encoding, which permits VL to be dynamic (settable from GPR or CTR)
923 is the Vectorisation of EXT248-263.
924 Instructions may not be placed in this category without also being
925 implemented as pure Scalar *and* SVP64Single. Unlike SVP64Single
926 however, there is **no reserved encoding** (bits 8-24 zero).
927 VL=1 may occur dynamically
928 at runtime, even when bits 8-31 are zero.
929
930 | 0-5 | 6 | 7 | 8-31 | 32-3 | 34-37 | 38-63 |
931 |--------|---|---|-------|------|---------|---------|
932 | PO (9)?| 0 | 1 | nnnn | 0b11 |PO2[2:5] | SVP64:{EXT248-263} |
933
934 **RESERVED2 / EXT300-363** bit6=old bit7=scalar
935
936 This is entirely at the discretion of the ISA WG. Libre-SOC is *not*
937 proposing the addition of EXT300-363: it is merely a possibility for
938 future. The reason the space is not needed is because this is within
939 the realm of Scalar-extended (SVP64Single), and with the 24-bit prefix
940 area being all-zero (bits 8-31) this is defined as "having no augmentation"
941 (in the Simple-V Specification it is termed `Scalar Identity Behaviour`).
942 This in turn makes this prefix a *degenerate duplicate* so may be allocated
943 for other purposes.
944
945 | 0-5 | 6 | 7 | 8-31 | 32-63 |
946 |--------|---|---|-------|---------|
947 | PO (9)?| 1 | 0 | 0000 | EXT300-363 or `RESERVED1` |
948
949 \newpage{}
950 # Example Legal Encodings and RESERVED spaces
951
952 This section illustrates what is legal encoding, what is not, and
953 why the 4 spaces should be `RESERVED` even if not allocated as part
954 of this RFC.
955
956 **legal, scalar and vector**
957
958 | width | assembler | prefix? | suffix | description |
959 |-------|-----------|--------------|-----------|---------------|
960 | 32bit | fishmv | none | 0x12345678| scalar EXT0nn |
961 | 64bit | ss.fishmv | 0x26!zero | 0x12345678| scalar SVP64Single:EXT0nn |
962 | 64bit | sv.fishmv | 0x27nnnnnn | 0x12345678| vector SVP64:EXT0nn |
963
964 OR:
965
966 | width | assembler | prefix? | suffix | description |
967 |-------|-----------|--------------|-----------|---------------|
968 | 64bit | fishmv | 0x24000000 | 0x12345678| scalar EXT2nn |
969 | 64bit | ss.fishmv | 0x24!zero | 0x12345678| scalar SVP64Single:EXT2nn |
970 | 64bit | sv.fishmv | 0x25nnnnnn | 0x12345678| vector SVP64:EXT2nn |
971
972 Here the encodings are the same, 0x12345678 means the same thing in
973 all cases. Anything other than this risks either damage (truncation
974 of capabilities of Simple-V) or far greater complexity in the
975 Decode Phase.
976
977 This drives the compromise proposal (above) to reserve certain
978 EXT2nn POs right
979 across the board
980 (in the Scalar Suffix side, irrespective of Prefix), some allocated
981 to Simple-V, some not.
982
983 **illegal due to missing**
984
985 | width | assembler | prefix? | suffix | description |
986 |-------|-----------|--------------|-----------|---------------|
987 | 32bit | fishmv | none | 0x12345678| scalar EXT0nn |
988 | 64bit | ss.fishmv | 0x26!zero | 0x12345678| scalar SVP64Single:EXT0nn |
989 | 64bit | unallocated | 0x27nnnnnn | 0x12345678| vector SVP64:EXT0nn |
990
991 This is illegal because the instruction is possible to Vectorise,
992 therefore it should be **defined** as Vectoriseable.
993
994 **illegal due to unvectoriseable**
995
996 | width | assembler | prefix? | suffix | description |
997 |-------|-----------|--------------|-----------|---------------|
998 | 32bit | mtmsr | none | 0x12345678| scalar EXT0nn |
999 | 64bit | ss.mtmsr | 0x26!zero | 0x12345678| scalar SVP64Single:EXT0nn |
1000 | 64bit | sv.mtmsr | 0x27nnnnnn | 0x12345678| vector SVP64:EXT0nn |
1001
1002 This is illegal because the instruction `mtmsr` is not possible to Vectorise,
1003 at all. This does **not** convey an opportunity to allocate the
1004 space to an alternative instruction.
1005
1006 **illegal unvectoriseable in EXT2nn**
1007
1008 | width | assembler | prefix? | suffix | description |
1009 |-------|-----------|--------------|-----------|---------------|
1010 | 64bit | mtmsr2 | 0x24000000 | 0x12345678| scalar EXT2nn |
1011 | 64bit | ss.mtmsr2 | 0x24!zero | 0x12345678| scalar SVP64Single:EXT2nn |
1012 | 64bit | sv.mtmsr2 | 0x25nnnnnn | 0x12345678| vector SVP64:EXT2nn |
1013
1014 For a given hypothetical `mtmsr2` which is inherently Unvectoriseable
1015 whilst it may be put into the scalar EXT2nn space it may **not** be
1016 allocated in the Vector space. As with Unvectoriseable EXT0nn opcodes
1017 this does not convey the right to use the 0x24/0x26 space for alternative
1018 opcodes. This hypothetical Unvectoriseable operation would be better off
1019 being allocated as EXT001 Prefixed, EXT000-063, or hypothetically in
1020 EXT300-363.
1021
1022 **ILLEGAL: dual allocation**
1023
1024 | width | assembler | prefix? | suffix | description |
1025 |-------|-----------|--------------|-----------|---------------|
1026 | 32bit | fredmv | none | 0x12345678| scalar EXT0nn |
1027 | 64bit | ss.fredmv | 0x26!zero | 0x12345678| scalar SVP64Single:EXT0nn |
1028 | 64bit | sv.fishmv | 0x27nnnnnn | 0x12345678| vector SVP64:EXT0nn |
1029
1030 the use of 0x12345678 for fredmv in scalar but fishmv in Vector is
1031 illegal. the suffix in both 64-bit locations
1032 must be allocated to a Vectoriseable EXT000-063
1033 "Defined Word" (Public v3.1 Section 1.6.3 definition)
1034 or not at all.
1035
1036 \newpage{}
1037
1038 **illegal unallocated scalar EXT0nn or EXT2nn:**
1039
1040 | width | assembler | prefix? | suffix | description |
1041 |-------|-----------|--------------|-----------|---------------|
1042 | 32bit | unallocated | none | 0x12345678| scalar EXT0nn |
1043 | 64bit | ss.fredmv | 0x26!zero | 0x12345678| scalar SVP64Single:EXT0nn |
1044 | 64bit | sv.fishmv | 0x27nnnnnn | 0x12345678| vector SVP64:EXT0nn |
1045
1046 and:
1047
1048 | width | assembler | prefix? | suffix | description |
1049 |-------|-----------|--------------|-----------|---------------|
1050 | 64bit | unallocated | 0x24000000 | 0x12345678| scalar EXT2nn |
1051 | 64bit | ss.fishmv | 0x24!zero | 0x12345678| scalar SVP64Single:EXT2nn |
1052 | 64bit | sv.fishmv | 0x25nnnnnn | 0x12345678| vector SVP64:EXT2nn |
1053
1054 Both of these Simple-V operations are illegally-allocated. The fact that
1055 there does not exist a scalar "Defined Word" (even for EXT200-263) - the
1056 unallocated block - means that the instruction may **not** be allocated in
1057 the Simple-V space.
1058
1059 **illegal attempt to put Scalar EXT004 into Vector EXT2nn**
1060
1061 | width | assembler | prefix? | suffix | description |
1062 |-------|-----------|--------------|-----------|---------------|
1063 | 32bit | unallocated | none | 0x10345678| scalar EXT0nn |
1064 | 64bit | ss.fishmv | 0x24!zero | 0x10345678| scalar SVP64Single:EXT2nn |
1065 | 64bit | sv.fishmv | 0x25nnnnnn | 0x10345678| vector SVP64:EXT2nn |
1066
1067 This is an illegal attempt to place an EXT004 "Defined Word"
1068 (Public v3.1 Section 1.6.3) into the EXT2nn Vector space.
1069 This is not just illegal it is not even possible to achieve.
1070 If attempted, by dropping EXT004 into bits 32-37, the top two
1071 MSBs are actually *zero*, and the Vector EXT2nn space is only
1072 legal for Primary Opcodes in the range 248-263, where the top
1073 two MSBs are 0b11. Thus this faulty attempt actually falls
1074 unintentionally
1075 into `RESERVED` "Non-Vectoriseable" Encoding space.
1076
1077 **illegal attempt to put Scalar EXT001 into Vector space**
1078
1079 | width | assembler | prefix? | suffix | description |
1080 |-------|-----------|--------------|-----------|---------------|
1081 | 64bit | EXT001 | 0x04nnnnnn | any | scalar EXT001 |
1082 | 96bit | sv.EXT001 | 0x24!zero | EXT001 | scalar SVP64Single:EXT001 |
1083 | 96bit | sv.EXT001 | 0x25nnnnnn | EXT001 | vector SVP64:EXT001 |
1084
1085 This becomes in effect an effort to define 96-bit instructions,
1086 which are illegal due to cost at the Decode Phase (Variable-Length
1087 Encoding). Likewise attempting to embed EXT009 (chained) is also
1088 illegal. The implications are clear unfortunately that all 64-bit
1089 EXT001 Scalar instructions are Unvectoriseable.
1090
1091 \newpage{}
1092 # Use cases
1093
1094 In the following examples the programs are fully executable under the
1095 Libre-SOC Simple-V-augmented Power ISA Simulator. Reproducible
1096 (scripted) Installation instructions:
1097 <https://libre-soc.org/HDL_workflow/devscripts/>
1098
1099 ## LD/ST-Multi
1100
1101 Context-switching saving and restoring of registers on the stack often
1102 requires explicit loop-unrolling to achieve effectively. In SVP64 it
1103 is possible to use a Predicate Mask to "compact" or "expand" a swathe
1104 of desired registers, dynamically. Known as "VCOMPRESS" and "VEXPAND",
1105 runtime-configurable LD/ST-Multi is achievable with 2 instructions.
1106
1107 ```
1108 # load 64 registers off the stack, in-order, skipping unneeded ones
1109 # by using CR0-CR63's "EQ" bits to select only those needed.
1110 setvli 64
1111 sv.ld/sm=EQ *rt,0(ra)
1112 ```
1113
1114 ## Twin-Predication, re-entrant
1115
1116 This example demonstrates two key concepts: firstly Twin-Predication
1117 (separate source predicate mask from destination predicate mask) and
1118 that sufficient state is stored within the Vector Context SPR, SVSTATE,
1119 for full re-entrancy on a Context Switch or function call *even if
1120 in the middle of executing a loop*. Also demonstrates that it is
1121 permissible for a programmer to write **directly** to the SVSTATE
1122 SPR, and still expect Deterministic Behaviour. It's not exactly recommended
1123 (performance may be impacted by direct SVSTATE access), but it is not
1124 prohibited either.
1125
1126 ```
1127 292 # checks that we are able to resume in the middle of a VL loop,
1128 293 # after an interrupt, or after the user has updated src/dst step
1129 294 # let's assume the user has prepared src/dst step before running this
1130 295 # vector instruction
1131 296 # test_intpred_reentrant
1132 297 # reg num 0 1 2 3 4 5 6 7 8 9 10 11 12
1133 298 # srcstep=1 v
1134 299 # src r3=0b0101 Y N Y N
1135 300 # : |
1136 301 # + - - + |
1137 302 # : +-------+
1138 303 # : |
1139 304 # dest ~r3=0b1010 N Y N Y
1140 305 # dststep=2 ^
1141 306
1142 307 sv.extsb/sm=r3/dm=~r3 *5, *9
1143 ```
1144
1145 <https://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=src/openpower/decoder/isa/test_caller_svp64_predication.py;hb=HEAD>
1146
1147 ## 3D GPU style "Branch Conditional"
1148
1149 (*Note: Specification is ready, Simulator still under development of
1150 full specification capabilities*)
1151 This example demonstrates a 2-long Vector Branch-Conditional only
1152 succeeding if *all* elements in the Vector are successful. This
1153 avoids the need for additional instructions that would need to
1154 perform a Parallel Reduction of a Vector of Condition Register
1155 tests down to a single value, on which a Scalar Branch-Conditional
1156 could then be performed. Full Rationale at
1157 <https://libre-soc.org/openpower/sv/branches/>
1158
1159 ```
1160 80 # test_sv_branch_cond_all
1161 81 for i in [7, 8, 9]:
1162 83 addi 1, 0, i+1 # set r1 to i
1163 84 addi 2, 0, i # set r2 to i
1164 85 cmpi cr0, 1, 1, 8 # compare r1 with 8 and store to cr0
1165 86 cmpi cr1, 1, 2, 8 # compare r2 with 8 and store to cr1
1166 87 sv.bc/all 12, *1, 0xc # bgt 0xc - branch if BOTH
1167 88 # r1 AND r2 greater 8 to the nop below
1168 89 addi 3, 0, 0x1234, # if tests fail this shouldn't execute
1169 90 or 0, 0, 0 # branch target
1170 ```
1171
1172 <https://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=src/openpower/decoder/isa/test_caller_svp64_bc.py;hb=HEAD>
1173
1174 \newpage{}
1175 ## DCT
1176
1177 DCT has dozens of uses in Audio-Visual processing and CODECs.
1178 A full 8-wide in-place triple-loop Inverse DCT may be achieved
1179 in 8 instructions. Expanding this to 16-wide is a matter of setting
1180 `svshape 16` **and the same instructions used**.
1181 Lee Composition may be deployed to construct non-power-two DCTs.
1182 The cosine table may be computed (once) with 18 Vector instructions
1183 (one of them `fcos`)
1184
1185 ```
1186 1014 # test_sv_remap_fpmadds_ldbrev_idct_8_mode_4
1187 1015 # LOAD bit-reversed with half-swap
1188 1016 svshape 8, 1, 1, 14, 0
1189 1017 svremap 1, 0, 0, 0, 0, 0, 0
1190 1018 sv.lfs/els *0, 4(1)
1191 1019 # Outer butterfly, iterative sum
1192 1020 svremap 31, 0, 1, 2, 1, 0, 1
1193 1021 svshape 8, 1, 1, 11, 0
1194 1022 sv.fadds *0, *0, *0
1195 1023 # Inner butterfly, twin +/- MUL-ADD-SUB
1196 1024 svshape 8, 1, 1, 10, 0
1197 1025 sv.ffmadds *0, *0, *0, *8
1198 ```
1199
1200 <https://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=src/openpower/decoder/isa/test_caller_svp64_dct.py;hb=HEAD>
1201
1202 ## Matrix Multiply
1203
1204 Matrix Multiply of any size (non-power-2) up to a total of 127 operations
1205 is achievable with only three instructions. Normally in any other SIMD
1206 ISA at least one source requires Transposition and often massive rolling
1207 repetition of data is required. These 3 instructions may be used as the
1208 "inner triple-loop kernel" of the usual 6-loop Massive Matrix Multiply.
1209
1210 ```
1211 28 # test_sv_remap1 5x4 by 4x3 matrix multiply
1212 29 svshape 5, 4, 3, 0, 0
1213 30 svremap 31, 1, 2, 3, 0, 0, 0
1214 31 sv.fmadds *0, *8, *16, *0
1215 ```
1216
1217 <https://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=src/openpower/decoder/isa/test_caller_svp64_matrix.py;hb=HEAD>
1218
1219 ## Parallel Reduction
1220
1221 Parallel (Horizontal) Reduction is often deeply problematic in SIMD and
1222 Vector ISAs. Parallel Reduction is Fully Deterministic in Simple-V and
1223 thus may even usefully be deployed on non-associative and non-commutative
1224 operations.
1225
1226 ```
1227 75 # test_sv_remap2
1228 76 svshape 7, 0, 0, 7, 0
1229 77 svremap 31, 1, 0, 0, 0, 0, 0 # different order
1230 78 sv.subf *0, *8, *16
1231 79
1232 80 REMAP sv.subf RT,RA,RB - inverted application of RA/RB
1233 81 left/right due to subf
1234 ```
1235
1236 <https://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=src/openpower/decoder/isa/test_caller_svp64_parallel_reduce.py;hb=HEAD>
1237
1238 [[!tag opf_rfc]]
1239
1240 [^zolc]: first introduced in DSPs, Zero-Overhead Loops are astoundingly effective in reducing total number of instructions executed or needed. [ZOLC](https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.301.4646&rep=rep1&type=pdf) reduces instructions by **25 to 80 percent**.
1241 [^msr]: an MSR bit or bits, conceptually equivalent to `MSR.SF` and added for the same reasons, would suffice perfectly.
1242 [^extend]: Prefix opcode space (or MSR bits) **must** be reserved in advance to do so, in order to avoid the catastrophic binary-incompatibility mistake made by RISC-V RVV and ARM SVE/2
1243 [^likeext001]: SVP64-Single is remarkably similar to the "bit 1" of EXT001 being set to indicate that the 64-bits is to be allocated in full to a new encoding, but in fact SVP64-single still embeds v3.0 Scalar operations.
1244 [^pseudorewrite]: elwidth overrides does however mean that all SFS / SFFS pseudocode will need rewriting to be in terms of XLEN. This has the indirect side-effect of automatically making a 32-bit Scalar Power ISA Specification possible, as well as a future 128-bit one (Cross-reference: RISC-V RV32 and RV128
1245 [^only2]: reminder that this proposal only needs 75% of two POs for Scalar instructions. The rest of EXT200-263 is for general use.
1246 [^ext001]: Recall that EXT100 to EXT163 is for Public v3.1 64-bit-augmented Operations prefixed by EXT001, for which, from Section 1.6.3, bit 6 is set to 1. This concept is where the above scheme originated. Section 1.6.3 uses the term "defined word" to refer to pre-existing EXT000-EXT063 32-bit instructions so prefixed to create the new numbering EXT100-EXT163, respectively
1247 [^futurevsx]: A future version or other Stakeholder *may* wish to drop Simple-V onto VSX: this would be a separate RFC
1248 [^vsx256]: imagine a hypothetical future VSX-256 using the exact same instructions as VSX. the binary incompatibility introducrd would catastrophically **and retroactively** damage existing IBM POWER8,9,10 hardware's reputation and that of Power ISA overall.
1249 [^autovec]: Compiler auto-vectorisation for best exploitation of SIMD and Vector ISAs on Scalar programming languages (c, c++) is an Indusstry-wide known-hard decades-long problem. Cross-reference the number of hand-optimised assembler algorithms.
1250 [^hphint]: intended for use when the compiler has determined the extent of Memory or register aliases in loops: `a[i] += a[i+4]` would necessitate a Vertical-First hphint of 4
1251 [^svshape]: although SVSHAPE0-3 should, realistically, be regarded as high a priority as SVSTATE, and given corresponding SVSRR and SVLR equivalents, it was felt that having to context-switch **five** SPRs on Interrupts and function calls was too much.
1252 [^whoops]: two efforts were made to mix non-uniform encodings into Simple-V space: one deliberate to see how it would go, and one accidental. They both went extremely badly, the deliberate one costing over two months to add then remove.
1253 [^mul]: Setting this "multiplier" to 1 clearly leaves pre-existing Scalar behaviour completely intact as a degenerate case.
1254 [^ldstcisc]: At least the CISC "auto-increment" modes are not present, from the CDC 6600 and Motorola 68000! although these would be fun to introduce they do unfortunately make for 3-in 3-out register profiles, all 64-bit, which explains why the 6600 and 68000 had separate special dedicated address regfiles.