(no commit message)
[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.
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.
62 The sole exception to that is Vectorised
63 Branch Conditional, in order to provide the usual Advanced Branching
64 capability present in every Commercial 3D GPU ISA, but it
65 is the *Vectorised* Branch-Conditional that is augmented, not Scalar
66 Branch.
67
68 # Basic principle
69
70 The basic principle of Simple-V is to provide a Precise-Interruptible
71 Zero-Overhead register "offsetting" system which augments instructions, by
72 incrementing the register numbering progressively *and automatically*
73 each time round the "loop". Thus it may be considered to be a form
74 of "Sub-Program-Counter" and at its simplest level can replace a large
75 sequence of regularly-increasing loop-unrolled instructions with just two:
76 one to set the Vector length and one saying where to
77 start from in the regfile.
78
79 On this sound and profoundly simple concept which leverages *Scalar*
80 Micro-architectural capabilities much more comprehensive festures are
81 easy to add, working up towards an ISA that easily matches the capability
82 of powerful 3D GPU Vector Supercomputing ISAs, without ever adding even
83 one single Vector opcode.
84 The inspiration for this came from the fact that on examination of every
85 Vector ISA pseudocode encountered the Vector operations were expressed
86 as a for-loop on a Scalar element
87 operation, and then both a Scalar **and** a Vector instruction was added.
88
89 It felt natural to separate the two at both the ISA and the Hardware Level
90 and thus provide only Scalar instructions (instantly halving the number
91 of instructions), leaving it up to implementors
92 to implement Superscalar and Multi-Issue Micro-architectures at their
93 discretion.
94
95 # Extension Levels
96
97 Simple-V has been subdivided into levels akin to the Power ISA Compliancy
98 Levels. For now let us call them "SV Extension Levels" to differentiate
99 the two. The reason for the
100 [SV Extension Levels](https://libre-soc.org/openpower/sv/compliancy_levels/)
101 is the same as for the
102 Power ISA Compliancy Levels (SFFS, SFS): to not overburden implementors
103 with features that they do not need. *There is no dependence between
104 the two types of Levels*. The resources below therefore are
105 not all required for all SV Extension Levels but they are all required
106 to be reserved.
107
108 # Binary Interoperability
109
110 Power ISA has a reputation as being long-term stable.
111 **Simple-V guarantees binary interoperability** by defining fixed
112 register file bitwidths and size for all instructions.
113 The seduction of permitting different implementors to choose a register file
114 bitwidth and size with the same instructions unfortunately has
115 the catastrophic side-effect of introducing not only binary incompatibility
116 but silent data corruption as well as no means to trap-and-emulate differing
117 bitwidths.[^vsx256]
118
119 Thus "Silicon-Partner" Scalability
120 is prohibited in the Simple-V Scalable Vector ISA,
121 This does
122 mean that `RESERVED` space is crucial to have, in order
123 to safely provide the option of
124 future expanded register file bitwidths and sizes[^msr],
125 under explicitly-distinguishable encoding,
126 **at the discretion of and with the full authority of the OPF ISA WG**,
127 not the implementor ("Silicon Partner").
128
129 # Hardware Implementations
130
131 The fundamental principle of Simple-V is that it sits between Issue and
132 Decode, pausing the Program-Counter to service a "Sub-PC"
133 hardware for-loop. This is very similar to "Zero-Overhead Loops"
134 in High-end DSPs (TI MSP Series).
135
136 Considerable effort has been expended to ensure that Simple-V is
137 practical to implement on an extremely wide range of Industry-wide
138 common **Scalar** micro-architectures. Finite State Machine (for
139 ultra-low-resource and Mission-Critical), In-order single-issue, all the
140 way through to Great-Big Out-of-Order Superscalar Multi-Issue. The
141 SV Extension Levels specifically recognise these differing scenarios.
142
143 SIMD back-end ALUs particularly those with element-level predicate
144 masks may be exploited to good effect with very little additional
145 complexity to achieve high throughput, even on a single-issue in-order
146 microarchitecture. As usually becomes quickly apparent with in-order, its
147 limitations extend also to when Simple-V is deployed, which is why
148 Multi-Issue Out-of-Order is the recommended (but not mandatory) Scalar
149 Micro-architecture.
150
151 The only major concern is in the upper SV Extension Levels: the Hazard
152 Management for increased number of Scalar Registers to 128 (in current
153 versions) but given that IBM POWER9/10 has VSX register numbering 64,
154 and modern GPUs have 128, 256 amd even 512 registers this was deemed
155 acceptable. Strategies do exist in hardware for Hazard Management of
156 such large numbers of registers, even for Multi-Issue microarchitectures.
157
158 # Simple-V Architectural Resources
159
160 * No new Interrupt types are required.
161 (**No modifications to existing Power ISA opcodes are required either**).
162 * GPR FPR and CR Field Register extend to 128. A future
163 version may extend to 256 or beyond[^extend] or also extend VSX[^futurevsx]
164 * 24-bits are needed within the main SVP64 Prefix (equivalent to a 2-bit XO)
165 * Another 24-bit (a second 2-bit XO) is needed for a planned future encoding,
166 currently named "SVP64-Single"[^likeext001]
167 * A third 24-bits (third 2-bit XO) is strongly recommended to be `RESERVED`
168 such that future unforeseen capability is needed (although this may be
169 alternatively achieved with a mandatory PCR or MSR bit)
170 * To hold all Vector Context, five SPRs are needed for userspace.
171 If Supervisor and Hypervisor mode are to
172 also support Simple-V they will correspondingly need five SPRs each.
173 (Some 32/32-to-64 aliases are advantageous but not critical).
174 * Five 6-bit XO (A-Form) "Management" instructions are needed. These are
175 Scalar 32-bit instructions and *may* be 64-bit-extended in future
176 (safely within the SVP64 space: no need for an EXT001 encoding).
177
178 **Summary of Simple-V Opcode space**
179
180 * 75% of one Major Opcode (equivalent to the rest of EXT017)
181 * Five 6-bit XO 32-bit operations.
182
183 No further opcode space *for Simple-V* is envisaged to be required for
184 at least the next decade (including if added on VSX)
185
186 **Simple-V SPRs**
187
188 * **SVSTATE** - Vectorisation State sufficient for Precise-Interrupt
189 Context-switching and no adverse latency.
190 * **SVSRR0** - identical in purpose to SRR0/1: storing SVSTATE on context-switch
191 along-side MSR and PC.
192 * **SVSHAPE0-3** - these are 32-bit and may be grouped in pairs, they REMAP
193 (shape) the Vectors
194 * **SVLR** - again similar to LR for exactly the same purpose, SVSTATE
195 is swapped with SVLR by SV-Branch-Conditional for exactly the same
196 reason that NIA is swapped with LR
197
198 **Vector Management Instructions**
199
200 These fit into QTY 5of 6-bit XO 32-bit encoding (svshape and svshape2 share
201 the same space):
202
203 * **setvl** - Cray-style Scalar Vector Length instruction
204 * **svstep** - used for Vertical-First Mode and for enquiring about internal
205 state
206 * **svremap** - "tags" registers for activating REMAP
207 * **svshape** - convenience instruction for quickly setting up Matrix, DCT,
208 FFT and Parallel Reduction REMAP
209 * **svshape2** - additional convenience instruction to set up "Offset" REMAP
210 (fits within svshape's XO encoding)
211 * **svindex** - convenience instruction for setting up "Indexed" REMAP.
212
213 # SVP64 24-bit Prefixes
214
215 The SVP64 24-bit Prefix (RM) provides several options,
216 all fitting within the 24-bit space (and no other).
217 These Modes do not interact with SVSTATE per se. SVSTATE
218 primarily controls the looping (quantity, order), RM
219 influences the *elements* (the Suffix). There is however
220 some close interaction when it comes to predication.
221 REMAP is separately
222 outlined in another section.
223
224 The primary options all of which are aimed at reducing instruction
225 count and reducing assembler complexity are:
226
227 * element-width overrides, which dynamically redefine each SFFS or SFS
228 Scalar prefixed instruction to be 8-bit, 16-bit, 32-bit or 64-bit
229 operands **without requiring new 8/16/32 instructions.**[^pseudorewrite]
230 This results in full BF16 and FP16 opcodes being added to the Power ISA
231 **without adding BF16 or FP16 opcodes** including full conversion
232 between all formats.
233 * predication. this is an absolutely essential feature for a 3D GPU VPU ISA.
234 CR Fields are available as Predicate Masks hence the reason for their
235 extension to 128. Twin-Predication is also provided: this may best
236 be envisaged as back-to-back VGATHER-VSCATTER but is not restricted
237 to LD/ST, its use saves on instruction count. Enabling one or other
238 of the predicates provides all of the other types of operations
239 found in Vector ISAs (VEXTRACT, VINSERT etc) again with no need
240 to actually provide explicit such instructions.
241 * Saturation. **all** LD/ST and Arithmetic and Logical operations may
242 be saturated (without adding explicit scalar saturated opcodes)
243 * Reduction and Prefix-Sum (Fibonnacci Series) Modes
244 * vec2/3/4 "Packing" and "Unpacking" (similar to VSX `vpack` and `vpkss`)
245 accessible in a way that is easier than REMAP, added for the same reasons
246 that drove `vpack` and `vpkss` etc. to be added: pixel, audio, and 3D
247 data manipulation. With Pack/Unpack being part of SVSTATE it can be
248 applied *in-place* saving register file space (no copy/mv needed).
249 * Load/Store speculative "fault-first" behaviour, identical to ARM and RVV
250 Fault-first: provides auto-truncation of a speculative LD/ST helping
251 solve the "SIMD Considered Harmful" stripmining problem from a Memory
252 Access perspective.
253 * Data-Dependent Fail-First: a 100% Deterministic extension of the LDST
254 ffirst concept: first `Rc=1 BO test` failure terminates looping and
255 truncates VL to that exact point. Useful for implementing algorithms
256 such as `strcpy` in around 14 high-performance Vector instructions, the
257 option exists to include or exclude the failing element.
258 * Predicate-result: a strategic mode that effectively turns all and any
259 operations into a type of `cmp`. An `Rc=1 BO test` is performed and if
260 failing the result is **not** written to the regfile. The `Rc=1`
261 Vector of co-results **is** always written (subject to predication).
262 Termed "predicate-result" because the combination of producing then
263 testing a result is as if the test was in a follow-up predicated
264 copy/mv operation, it reduces regfile pressure and instruction count.
265 Also useful on saturated or other overflowing operations, the overflowing
266 elements may be excluded from outputting to the regfile then
267 post-analysed outside of critical hot-loops.
268
269 **RM Modes**
270
271 There are five primary categories of instructions in Power ISA, each of
272 which needed slightly different Modes. For example, saturation and
273 element-width overrides are meaningless to Condition Register Field
274 operations, and Reduction is meaningless to LD/ST but Saturation
275 saves register file ports in critical hot-loops. Thus the 24 bits may
276 be suitably adapted to each category.
277
278 * Normal - arithmetic and logical including IEEE754 FP
279 * LD/ST immediate - includes element-strided and unit-strided
280 * LD/ST indexed
281 * CR Field ops
282 * Branch-Conditional - saves on instruction count in 3D parallel if/else
283
284 It does have to be pointed out that there is huge pressure on the
285 Mode bits. There was therefore insufficient room, unlike the way that
286 EXT001 was designed, to provide "identifying bits" *without first partially
287 decoding the Suffix*. This should in no way be conflated with or taken
288 as an indicator that changing the meaning of the Suffix is performed
289 or desirable.
290
291 Some considerable care has been taken to ensure that Decoding may be
292 performed in a strict forward-pipelined fashion that, aside from changes in
293 SVSTATE and aside from the initial 32/64 length detection (also kept simple),
294 a Multi-Issue Engine would have no difficulty (performance maximisable).
295 With the initial partial RM identification
296 decode performed above the Vector operations may easily be passed downstream
297 to independent parallel units for further analysis.
298
299 **Vectorised Branch-Conditional**
300
301 As mentioned in the introduction this is the one sole instruction group
302 that
303 is different pseudocode from its scalar equivalent. However even there
304 its various Mode bits and options can be set such that in the degenerate
305 case the behaviour becomes identical to Scalar Branch-Conditional.
306
307 The two additional Modes within Vectorised Branch-Conditional, both of
308 which may be combined, are `CTR-Mode` and `VLI-Test` (aka "Data Fail First").
309 CTR Mode extends the way that CTR may be decremented unconditionally
310 within Scalar Branch-Conditional, and not only makes it conditional but
311 also interacts with predication. VLI-Test provides the same option
312 as Data-Dependent Fault-First to Deterministically truncate the Vector
313 Length at the fail **or success** point.
314
315 Boolean Logic rules on sets (treating the Vector of CR Fields to be tested by
316 `BO` as a set) dictate that the Branch should take place on either 'ALL'
317 tests succeeding (or failing) or whether 'SOME' tests succeed (or fail).
318 These options provide the ability to cover the majority of Parallel
319 3D GPU Conditions, saving a not inconsiderable number of instructions
320 especially given the close interaction with CTR in hot-loops.
321
322 Also `SVLR` is introduced, which is a parallel twin of `LR`, and saving
323 and restoring of LR and SVLR may be deferred until the final decision
324 as to whether to branch. In this way `sv.bclrl` does not corrupt `LR`.
325
326 **SVP64Single**
327
328 The `SVP64-Single` 24-bit encoding focusses primarily on ensuring that
329 all 128 Scalar registers are fully accessible, provides element-width
330 overrides, one-bit predication
331 and brings Saturation to all existing Scalar operations.
332 BF16 and FP16 are thus
333 provided in the Scalar Power ISA without one single explicit FP16 or BF16
334 32-bit opcode being added. The downside: such Scalar operations are
335 all 64-bit encodings.
336
337 # Vertical-First Mode
338
339 This is a Computer Science term that needed first to be invented.
340 There exists only one other Vertical-First Vector ISA in the world:
341 Mitch Alsup's VVM Extension for the 66000. Several people have
342 independently derived Vertical-First: it simply did not have a
343 Computer Science term associated with it.
344
345 If we envisage register and Memory layout to be Horizontal and
346 instructions to be Vertical, and to then have some form of Loop
347 System (wherther Zero-Overhead or just branch-conditional based)
348 it is easier to then conceptualise VF vs HF Mode:
349
350 * Vertical-First progresses through *instructions* first before
351 moving on to the next *register* (or Memory-address in the case
352 of Mitch Alsup's VVM).
353 * Horizontal-First (also known as Cray-style Vectors) progresses
354 through **registers** (or, register *elements* in traditional
355 Cray-Vector ISAs) in full before moving on to the next instruction.
356
357 Mitch Alsup's VVM Extension is a form of hardware-level auto-vectorisation
358 based around Zero-Overhead Loops. Using a Variable-Length Encoding all
359 loop-invariant registers are "tagged" such that the Hazard Management
360 Engine may perform optimally and do less work in automatically identifying
361 parallelism opportunities.
362 With it not being appropriate to use Variable-Length Encoding in the Power
363 ISA a different much more explicit strategy was taken in Simple-V.
364
365 The biggest advantage inherent in Vertical-First is that it is very easy
366 to introduce into compilers, because all looping, as far as the architecture
367 is concerned, remains expressed as *Scalar assembler*. Whilst Mitch Alsup's
368 VVM advocates auto-vectorisation and is limited in its ability to call
369 functions, Simple-V's Vertical-First provides explicit control over the
370 parallelism ("hphint") and also allows for full state to be stored/restored
371 (SVLR combined with LR), permitting full function calls to be made.
372
373 Simple-V Vertical-First Looping requires an explicit instruction to
374 move `SVSTATE` regfile offsets forward: `svstep`. An early version of
375 Vectorised
376 Branch-Conditional attempted to merge the functionality of `svstep`
377 into `sv.bc`: it became CISC-like and was reverted.
378
379 \newpage{}
380 # Simple-V REMAP subsystem
381
382 [REMAP](https://libre-soc.org/openpower/sv/remap)
383 is extremely advanced but brings features already present in other
384 DSPs and Supercomputing ISAs. Normally (without these features)
385 algorithms are are costly or
386 convoluted to implement. They are typically implemented
387 as hard-coded fully loop-unrolled assembler which is often
388 auto-generated by specialist dedicated tools, or written
389 entirely by hand.
390
391 All REMAP Schedules *including Indexed*
392 are 100% Deterministic from their point of declaration,
393 making it possible to forward-plan
394 Issue, Memory access and Register Hazard Management
395 in Multi-Issue Micro-architectures.
396
397 * **DCT/FFT** REMAP brings more capability than TI's MSP-Series DSPs and
398 Qualcom Hexagon DSPs, and is not restricted to Integer or FP.
399 (Galois Field is possible, implementing NTT). Operates *in-place*
400 significantly reducing register usage.
401 * **Matrix** REMAP brings more capability than any other Matrix Extension
402 (AMD GPUs, Intel, ARM), not being restricted to Power-2 sizes. Also not
403 limited to the type of operation, it may perform Warshall Transitive
404 Closure, Integer Matrix, Bitmanipulation Matrix, Galois Field (carryless
405 mul) Matrix, and with care potentially Graph Maximum Flow as well. Also
406 suited to Convolutions, Matrix Transpose and rotate, *all* of which is
407 in-place.
408 * **General-purpose Indexed** REMAP, this option is provided to implement
409 an equivalent of VSX `vperm`, as a general-purpose catch-all means of
410 covering algorithms outside of the other REMAP Engines.
411 * **Parallel Reduction** REMAP, performs an automatic map-reduce using
412 *any suitable scalar operation*.
413
414 # Scalar Operations
415
416 The primary reason for mentioning the additional Scalar operations
417 is because they are so numerous, with Power ISA not having advanced
418 in the *general purpose* compute area in the past 12 years, that some
419 considerable care is needed.
420
421 Summary:
422 **Including Simple-V, to fit everything at least 75% of 3 separate
423 Major Opcodes would be required**
424
425 Candidates (for all but the X-Form instructions) include:
426
427 * EXT006 (80% free)
428 * EXT017 (75% free but not recommended)
429 * EXT001 (50% free)
430 * EXT009 (100% free)
431 * EXT005 (100% free)
432 * brownfield space in EXT019 (25% but NOT recommended)
433
434 SVP64, SVP64-Single and SVP64-Reserved would require on their own each 25%
435 of one Major Opcode for a total of 75% of one Major Opcode. The remaining
436 **Scalar** opcodes, due to there being two separate sets of operations
437 with 16-bit immediates, will require the other space totalling two 75%
438 Majors.
439
440 Note critically that:
441
442 * Unlike EXT001, SVP64's 24-bits may **not** hold also any Scalar
443 operations. There is no free available space: a 25th bit would
444 be required. The entire 24-bits is **required** for the abstracted
445 Hardware-Looping Concept **even when these 24-bits are zero**
446 * Any Scalar 64-bit instruction (regardless of how it is encoded) is unsafe to
447 then Vectorise because this creates the situation of Prefixed-Prefixed,
448 resulting in deep complexity in Hardware Decode at a critical juncture, as
449 well as introducing 96-bit instructions.
450 * **All** of these Scalar instructions are candidates for Vectorisation.
451 Thus none of them may be 64-bit-Scalar-only.
452
453 **Minor Opcodes to fit candidates above**
454
455 In order of size, for bitmanip and A/V DSP purposes:
456
457 * QTY 3of 2-bit XO: ternlogi, crternlogi, grevlogi
458 * QTY 7of 3-bit XO: xpermi, binlut, grevlog, swizzle-mv/fmv, bitmask, bmrevi
459 * QTY 8of 5/6-bit (A-Form): xpermi, bincrflut, bmask, fmvis, fishmv, bmrev,
460 Galois Field
461 * QTY 30of 10-bit (X-Form): cldiv/mul, av-min/max/diff, absdac, xperm etc.
462 (easily fit EXT019, EXT031).
463
464 Note: Some of the Galois Field operations will require QTY 1of Polynomial
465 SPR (per userspace supervisor hypervisor).
466
467 **EXT004**
468
469 For biginteger math, two instructions in the same space as "madd" are to
470 be proposed. They are both 3-in 2-out operations taking or producing a
471 64-bit "pair" (like RTp), and perform 128/64 mul and div/mod operations
472 respectively. These are **not** the same as VSX operations which are
473 128/128, and they are **not** the same as existing Scalar mul/div/mod,
474 all of which are 64/64 (or 64/32).
475
476 **EXT059 and EXT063**
477
478 Additionally for High-Performance Compute and Competitive 3D GPU, IEEE754 FP
479 Transcendentals are required, as are some DCT/FFT "Twin-Butterfly" operations.
480 For each of EXT059 and EXT063:
481
482 * QTY 33of X-Form "1-argument" (fsin, fsins, fcos, fcoss)
483 * QTY 15of X-Form "2-argument" (pow, atan2, fhypot)
484 * QTY 5of A-Form "3-in 2-out" FP Butterfly operations for DCT/FFT
485 * QTY 8of X-Form "2-in 2-out" FP Butterfly operations (again for DCT/FFT)
486 * An additional 16 instructions for IEEE754-2019
487 (fminss/fmaxss, fminmag/fmaxmag)
488 [under evaluation](https://bugs.libre-soc.org/show_bug.cgi?id=923)
489 as of 08Sep2022
490
491 \newpage{}
492 # Potential Opcode allocation solution
493
494 There are unfortunately some inviolate requirements that directly place
495 pressure on the EXT000-EXT063 (32-bit) opcode space to such a degree that
496 it risks jeapordising the Power ISA. These requirements are:
497
498 * all of the scalar operations must be Vectoriseable
499 * all of the scalar operations intended for Vectorisation
500 must be in a 32-bit encoding (not prefixed-prefixed to 96-bit)
501 * bringing Scalar Power ISA up-to-date from the past 12 years
502 needs 75% of two Major opcodes all on its own
503
504 There exists a potential scheme which meets (exceeds) the above criteria,
505 providing plenty of room for both Scalar (and Vectorised) operations,
506 *and* provides SVP64-Single with room to grow. It
507 is based loosely around Public v3.1 EXT001 Encoding.[^ext001]
508
509 | 0-5 | 6 | 7 | 8-31 | Description |
510 |-----|---|---|-------|---------------------------|
511 | PO | 0 | 0 | 0000 | new-suffix `RESERVED1` |
512 | PO | 0 | 0 | !zero | new-suffix, scalar (SVP64Single) |
513 | PO | 1 | 0 | 0000 | new scalar-only word, or `RESERVED2` |
514 | PO | 1 | 0 | !zero | old-suffix, scalar (SVP64Single) |
515 | PO | 0 | 1 | nnnn | new-suffix, vector (SVP64) |
516 | PO | 1 | 1 | nnnn | old-suffix, vector (SVP64) |
517
518 * **PO** - Primary Opcode. Likely candidates: EXT005, EXT009
519 * **bit 6** - specifies whether the suffix is old (EXT000-EXT063)
520 or new (EXTn00-EXTn63, n greater than 1)
521 * **bit 7** - defines whether the Suffix is Scalar-Prefixed or Vector-Prefixed
522 (caveat: see bits 8-31)
523 * **old-suffix** - the EXT000 to EXT063 32-bit Major opcodes of Power ISA 3.0
524 * **new scalar-only** - a **new** Major Opcode area **exclusively**
525 for Scalar-only instructions that shall **never** be Prefixed by SVP64
526 (RESERVED2 EXT300-EXT363)
527 * **new-suffix** - a **new** Major Opcode area (RESERVED1 EXT200-EXT263)
528 that **may** be Prefixed by SVP64 and SVP64Single
529 * **0000** - all 24 bits bits 8-31 are zero (0x000000)
530 * **!zero** - bits 8-31 may be any value *other* than zero (0x000001-0xffffff)
531 * **nnnn** - bits 8-31 may be any value in the range 0x000000 to 0xffffff
532 * **SVP64Single** - a ([TBD](https://bugs.libre-soc.org/show_bug.cgi?id=905))
533 *Scalar* Encoding that is near-identical to SVP64
534 except that it is equivalent to hard-coded VL=1
535 at all times. Predication is permitted, Element-width-overrides is
536 permitted, Saturation is permitted.
537 * **SVP64** - a (well-defined, 2 years) DRAFT Proposal for a Vectorisation
538 Augmentation of suffixes.
539
540 For the needs identified by Libre-SOC (75% of 2 POs),
541 `RESERVED1` space *needs*
542 allocation to new POs, `RESERVED2` does not.[^only2]
543
544 | | Scalar (bit7=0,8-31=0000) | Scalar (bit7=0,8-31=!zero)| Vector (bit7=1) |
545 |----------|---------------------------|---------------------------|------------------|
546 |new bit6=0| `RESERVED1`:{EXT200-263} | SVP64-Single:{EXT200-263} | SVP64:{EXT200-263} |
547 |old bit6=1| `RESERVED2`:{EXT300-363} | SVP64-Single:{EXT000-063} | SVP64:{EXT000-063} |
548
549 * **`RESERVED2`:{EXT300-363}** (not strictly necessary to be added) is not
550 and **cannot** ever be Vectorised or Augmented by Simple-V or any future
551 Simple-V Scheme.
552 it is a pure **Scalar-only** word-length PO Group. It may remain `RESERVED`.
553 * **`RESERVED1`:{EXT200-263}** is also a new set of 64 word-length Major
554 Opcodes.
555 These opcodes do not *need* to be Simple-V-Augmented
556 *but the option to do so exists* should an Implementor choose to do so.
557 This is unlike `EXT300-363` which may **never** be Simple-V-Augmented
558 under any circumstances.
559 * **`SVP64-Single:{EXT200-263}`** - Major opcodes 200-263 with
560 Single-Augmentation, providing a one-bit predicate mask, element-width
561 overrides on source and destination, and the option to extend the Scalar
562 Register numbering (r0-32 extends to r0-127). **Placing of alternative
563 instruction encodings other than those exactly defined in EXT200-263
564 is prohibited**.
565 * **`SVP64-Single:{EXT000-063}`** - Major opcodes 000-063 with
566 Single-Augmentation, just like SVP64-Single on EXT200-263, these are
567 in effect Single-Augmented-Prefixed variants of the v3.0 32-bit Power ISA.
568 Alternative instruction encodings other than the exact same 32-bit word
569 from EXT000-EXT063 are likewise prohibited.
570 * **`SVP64:{EXT000-063}`** and **`SVP64:{EXT200-263}`** - Full Vectorisation
571 of EXT000-063 and EXT200-263 respectively, these Prefixed instructions
572 are likewise prohibited from being a different encoding from their
573 32-bit scalar versions.
574
575 Limitations of this scheme is that new 32-bit Scalar operations have to have
576 a 32-bit "prefix pattern" in front of them. If commonly-used this could
577 increase binary size. Thus the Encodings EXT300-363 and EXT200-263 should
578 only be allocated for less-popular operations. However the scheme does
579 have the strong advantage of *tripling* the available number of Major
580 Opcodes in the Power ISA, caveat being that care on allocation is needed
581 because EXT200-EXT263 may be SVP64-Augmented whilst EXT300-EXT363 may **not**.
582 The issues of allocation for bitmanip etc. from Libre-SOC is therefore
583 overwhelmingly made moot. The only downside is that there is no
584 `SVP64-Reserved` which will have to be achieved with SPRs (PCR or MSR).
585
586 \newpage{}
587 **EXT000-EXT063**
588
589 These are Scalar word-encodings. Often termed "v3.0 Scalar" in this document
590 Power ISA v3.1 Section 1.6.3 Book I calls it a "defined word".
591
592 | 0-5 | 6-31 |
593 |--------|--------|
594 | PO | EXT000-063 Scalar (v3.0 or v3.1) operation |
595
596 **RESERVED2 / EXT300-363** bit6=old bit7=scalar
597
598 This is entirely at the discretion of the ISA WG. Libre-SOC is *not*
599 proposing the addition of EXT300-363: it is merely a possibility for
600 future. The reason the space is not needed is because this is within
601 the realm of Scalar-extended (SVP64Single), and with the 24-bit prefix
602 area being all-zero (bits 8-31) this is defined as "having no augmentation"
603 (in the Simple-V Specification it is termed `Scalar Identity Behaviour`).
604 This in turn makes this prefix a *degenerate duplicate* so may be allocated
605 for other purposes.
606
607 | 0-5 | 6 | 7 | 8-31 | 32-63 |
608 |--------|---|---|-------|---------|
609 | PO (9)?| 1 | 0 | 0000 | EXT300-363 or `RESERVED1` |
610
611 **{EXT200-263}** bit6=new bit7=scalar
612
613 This encoding represents the opportunity to introduce EXT200-263.
614 It is a Scalar-word encoding, and does not require implementing
615 SVP64 or SVP64-Single.
616 PO2 is in the range 0b00000 to 0b11111 to represent EXT200-263 respectively.
617
618 | 0-5 | 6 | 7 | 8-31 | 32-37 | 38-63 |
619 |--------|---|---|-------|--------|---------|
620 | PO (9)?| 0 | 0 | 0000 | PO2 | {EXT200-263} |
621
622 **SVP64Single:{EXT200-263}** bit6=new bit7=scalar
623
624 This encoding, which is effectively "implicit VL=1"
625 and comprising (from bits 8-31)
626 *at least some* form of Augmentation, it represents the opportunity
627 to Augment EXT200-263 with the SVP64Single capabilities.
628 Instructions may not be placed in this category without also being
629 implemented as pure Scalar.
630
631 | 0-5 | 6 | 7 | 8-31 | 32-37 | 38-63 |
632 |--------|---|---|-------|--------|---------|
633 | PO (9)?| 0 | 0 | !zero | PO2 | SVP64Single:{EXT200-263} |
634
635 **SVP64Single:{EXT000-063}** bit6=old bit7=scalar
636
637 This encoding, identical to SVP64Single:{EXT200-263},
638 introduces SVP64Single Augmentation of v3.0 Scalar word instructions.
639 All meanings must be identical to EXT000 to EXT063, and is is likewise
640 prohibited to add an instruction in this area without also adding
641 the exact same (non-Augmented) instruction in EXT000-063 with the
642 exact same Scalar word.
643 PO2 is in the range 0b00000 to 0b11111 to represent EXT000-063 respectively.
644 Augmenting EXT001 is prohibited.
645
646 | 0-5 | 6 | 7 | 8-31 | 32-37 | 38-63 |
647 |--------|---|---|-------|--------|---------|
648 | PO (9)?| 1 | 0 | !zero | PO2 | SVP64Single:{EXT000-063} |
649
650 **SVP64:{EXT200-263}** bit6=new bit7=vector
651
652 This encoding, which permits VL to be dynamic (settable from GPR or CTR)
653 is the Vectorisation of EXT200-263.
654 Instructions may not be placed in this category without also being
655 implemented as pure Scalar *and* SVP64Single. Unlike SVP64Single
656 however, there is **no reserved encoding** (bits 8-24 zero).
657 VL=1 may occur dynamically
658 at runtime, even when bits 8-31 are zero.
659
660 | 0-5 | 6 | 7 | 8-31 | 32-37 | 38-63 |
661 |--------|---|---|-------|--------|---------|
662 | PO (9)?| 0 | 1 | nnnn | PO2 | SVP64:{EXT200-263} |
663
664 **SVP64:{EXT000-063}** bit6=old bit7=vector
665
666 This encoding is identical to **SVP64:{EXT200-263}** except it
667 is the Vectorisation of existing v3.0/3.1 Scalar-words, EXT000-063.
668 All the same rules apply with the addition that
669 Vectorisation of EXT001 is prohibited.
670
671 | 0-5 | 6 | 7 | 8-31 | 32-37 | 38-63 |
672 |--------|---|---|-------|--------|---------|
673 | PO (9)?| 1 | 1 | nnnn | PO2 | SVP64:{EXT000-063} |
674
675 \newpage{}
676 # Use cases
677
678 In the following examples the programs are fully executable under the
679 Libre-SOC Simple-V-augmented Power ISA Simulator. Reproducible
680 (scripted) Installation instructions:
681 <https://libre-soc.org/HDL_workflow/devscripts/>
682
683 ## LD/ST-Multi
684
685 Context-switching saving and restoring of registers on the stack often
686 requires explicit loop-unrolling to achieve effectively. In SVP64 it
687 is possible to use a Predicate Mask to "compact" or "expand" a swathe
688 of desired registers, dynamically. Known as "VCOMPRESS" and "VEXPAND",
689 runtime-configurable LD/ST-Multi is achievable with 2 instructions.
690
691 ```
692 # load 64 registers off the stack, in-order, skipping unneeded ones
693 # by using CR0-CR63's "EQ" bits to select only those needed.
694 setvli 64
695 sv.ld/sm=EQ *rt,0(ra)
696 ```
697
698 ## Twin-Predication, re-entrant
699
700 This example demonstrates two key concepts: firstly Twin-Predication
701 (separate source predicate mask from destination predicate mask) and
702 that sufficient state is stored within the Vector Context SPR, SVSTATE,
703 for full re-entrancy on a Context Switch or function call *even if
704 in the middle of executing a loop*. Also demonstrates that it is
705 permissible for a programmer to write **directly** to the SVSTATE
706 SPR, and still expect Deterministic Behaviour. It's not exactly recommended
707 (performance may be impacted by direct SVSTATE access), but it is not
708 prohibited either.
709
710 ```
711 292 # checks that we are able to resume in the middle of a VL loop,
712 293 # after an interrupt, or after the user has updated src/dst step
713 294 # let's assume the user has prepared src/dst step before running this
714 295 # vector instruction
715 296 # test_intpred_reentrant
716 297 # reg num 0 1 2 3 4 5 6 7 8 9 10 11 12
717 298 # srcstep=1 v
718 299 # src r3=0b0101 Y N Y N
719 300 # : |
720 301 # + - - + |
721 302 # : +-------+
722 303 # : |
723 304 # dest ~r3=0b1010 N Y N Y
724 305 # dststep=2 ^
725 306
726 307 sv.extsb/sm=r3/dm=~r3 *5, *9
727 ```
728
729 <https://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=src/openpower/decoder/isa/test_caller_svp64_predication.py;hb=HEAD>
730
731 ## 3D GPU style "Branch Conditional"
732
733 (*Note: Specification is ready, Simulator still under development of
734 full specification capabilities*)
735 This example demonstrates a 2-long Vector Branch-Conditional only
736 succeeding if *all* elements in the Vector are successful. This
737 avoids the need for additional instructions that would need to
738 perform a Parallel Reduction of a Vector of Condition Register
739 tests down to a single value, on which a Scalar Branch-Conditional
740 could then be performed. Full Rationale at
741 <https://libre-soc.org/openpower/sv/branches/>
742
743 ```
744 80 # test_sv_branch_cond_all
745 81 for i in [7, 8, 9]:
746 83 addi 1, 0, i+1 # set r1 to i
747 84 addi 2, 0, i # set r2 to i
748 85 cmpi cr0, 1, 1, 8 # compare r1 with 10 and store to cr0
749 86 cmpi cr1, 1, 2, 8 # compare r2 with 10 and store to cr1
750 87 sv.bc/all 12, *1, 0xc # bgt 0xc - branch if BOTH
751 88 # r1 AND r2 greater 8 to the nop below
752 89 addi 3, 0, 0x1234, # if tests fail this shouldn't execute
753 90 or 0, 0, 0 # branch target
754 ```
755
756 <https://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=src/openpower/decoder/isa/test_caller_svp64_bc.py;hb=HEAD>
757
758 \newpage{}
759 ## DCT
760
761 DCT has dozens of uses in Audio-Visual processing and CODECs.
762 A full 8-wide in-place triple-loop Inverse DCT may be achieved
763 in 8 instructions. Expanding this to 16-wide is a matter of setting
764 `svshape 16` **and the same instructions used**.
765 Lee Composition may be deployed to construct non-power-two DCTs.
766 The cosine table may be computed (once) with 18 Vector instructions
767 (one of them `fcos`)
768
769 ```
770 1014 # test_sv_remap_fpmadds_ldbrev_idct_8_mode_4
771 1015 # LOAD bit-reversed with half-swap
772 1016 svshape 8, 1, 1, 14, 0
773 1017 svremap 1, 0, 0, 0, 0, 0, 0
774 1018 sv.lfs/els *0, 4(1)
775 1019 # Outer butterfly, iterative sum
776 1020 svremap 31, 0, 1, 2, 1, 0, 1
777 1021 svshape 8, 1, 1, 11, 0
778 1022 sv.fadds *0, *0, *0
779 1023 # Inner butterfly, twin +/- MUL-ADD-SUB
780 1024 svshape 8, 1, 1, 10, 0
781 1025 sv.ffmadds *0, *0, *0, *8
782 ```
783
784 <https://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=src/openpower/decoder/isa/test_caller_svp64_dct.py;hb=HEAD>
785
786 ## Matrix Multiply
787
788 Matrix Multiply of any size (non-power-2) up to a total of 127 operations
789 is achievable with only three instructions. Normally in any other SIMD
790 ISA at least one source requires Transposition and often massive rolling
791 repetition of data is required. These 3 instructions may be used as the
792 "inner triple-loop kernel" of the usual 6-loop Massive Matrix Multiply.
793
794 ```
795 28 # test_sv_remap1 5x4 by 4x3 matrix multiply
796 29 svshape 5, 4, 3, 0, 0
797 30 svremap 31, 1, 2, 3, 0, 0, 0
798 31 sv.fmadds *0, *8, *16, *0
799 ```
800
801 <https://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=src/openpower/decoder/isa/test_caller_svp64_matrix.py;hb=HEAD>
802
803 ## Parallel Reduction
804
805 Parallel (Horizontal) Reduction is often deeply problematic in SIMD and
806 Vector ISAs. Parallel Reduction is Fully Deterministic in Simple-V and
807 thus may even usefully be deployed on non-associative and non-commutative
808 operations.
809
810 ```
811 75 # test_sv_remap2
812 76 svshape 7, 0, 0, 7, 0
813 77 svremap 31, 1, 0, 0, 0, 0, 0 # different order
814 78 sv.subf *0, *8, *16
815 79
816 80 REMAP sv.subf RT,RA,RB - inverted application of RA/RB
817 81 left/right due to subf
818 ```
819
820 <https://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=src/openpower/decoder/isa/test_caller_svp64_parallel_reduce.py;hb=HEAD>
821
822 [[!tag opf_rfc]]
823
824 [^msr]: an MSR bit or bits, conceptually equivalent to `MSR.SF` and added for the same reasons, would suffice perfectly.
825 [^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
826 [^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.
827 [^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
828 [^only2]: reminder that this proposal only needs 75% of two POs for Scalar instructions. The rest of EXT200-263 is for general use.
829 [^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
830 [^futurevsx]: A future version or other Stakeholder *may* wish to drop Simple-V onto VSX: this would be a separate RFC
831 [^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.