(no commit message)
[libreriscv.git] / openpower / sv.mdwn
1 [[!tag standards]]
2
3 Obligatory Dilbert:
4
5 <img src="https://assets.amuniversal.com/7fada35026ca01393d3d005056a9545d" width="600" />
6
7 Links:
8
9 * <https://bugs.libre-soc.org/show_bug.cgi?id=213>
10 * <https://youtu.be/ZQ5hw9AwO1U> walkthrough video (19jun2022)
11 * <https://ftp.libre-soc.org/simple_v_spec.pdf>
12 PDF version of this DRAFT specification
13
14 **SV is in DRAFT STATUS**. SV has not yet been submitted to the OpenPOWER Foundation ISA WG for review.
15
16 ===
17
18 # Scalable Vectors for the Power ISA
19
20 SV is designed as a strict RISC-paradigm
21 Scalable Vector ISA for Hybrid 3D CPU GPU VPU workloads.
22 As such it brings features normally only found in Cray Supercomputers
23 (Cray-1, NEC SX-Aurora)
24 and in GPUs, but keeps strictly to a *Simple* RISC principle of leveraging
25 a *Scalar* ISA, exclusively using "Prefixing". **Not one single actual
26 explicit Vector opcode exists in SV, at all**. It is suitable for
27 low-power Embedded and DSP Workloads as much as it is for power-efficient
28 Supercomputing.
29
30 Fundamental design principles:
31
32 * Taking the simplicity of the RISC paradigm and applying it strictly and
33 uniformly to create a Scalable Vector ISA.
34 * Effectively a hardware for-loop, pausing PC, issuing multiple scalar
35 operations
36 * Preserving the underlying scalar execution dependencies as if the
37 for-loop had been expanded as actual scalar instructions
38 (termed "preserving Program Order")
39 * Specifically designed to be Precise-Interruptible at all times
40 (many Vector ISAs have operations which, due to higher internal
41 accuracy or other complexity, must be effectively atomic only for
42 the full Vector operation's duration, adversely affecting interrupt
43 response latency, or be abandoned and started again)
44 * Augments ("tags") existing instructions, providing Vectorisation
45 "context" rather than adding new instructions.
46 * Strictly does not interfere with or alter the non-Scalable Power ISA
47 in any way
48 * In the Prefix space, does not modify or deviate from the underlying
49 scalar Power ISA
50 unless it provides significant performance or other advantage to do so
51 in the Vector space (dropping the "sticky" characteristics
52 of XER.SO and CR0.SO for example)
53 * Designed for Supercomputing: avoids creating significant sequential
54 dependency hazards, allowing standard
55 high performance superscalar multi-issue
56 micro-architectures to be leveraged.
57 * Divided into Compliancy Levels to reduce cost of implementation for
58 specific needs.
59
60 Advantages of these design principles:
61
62 * Simplicity of introduction and implementation on top of
63 the existing Power ISA without disruption.
64 * It is therefore easy to create a first (and sometimes only)
65 implementation as literally a for-loop in hardware, simulators, and
66 compilers.
67 * Hardware Architects may understand and implement SV as being an
68 extra pipeline stage, inserted between decode and issue, that is
69 a simple for-loop issuing element-level sub-instructions.
70 * More complex HDL can be done by repeating existing scalar ALUs and
71 pipelines as blocks and leveraging existing Multi-Issue Infrastructure
72 * As (mostly) a high-level "context" that does not (significantly) deviate
73 from scalar Power ISA and, in its purest form being "a for loop around
74 scalar instructions", it is minimally-disruptive and consequently stands
75 a reasonable chance of broad community adoption and acceptance
76 * Completely wipes not just SIMD opcode proliferation off the
77 map (SIMD is O(N^6) opcode proliferation)
78 but off of Vectorisation ISAs as well. No more separate Vector
79 instructions.
80
81 Comparative instruction count:
82
83 * ARM NEON SIMD: around 2,000 instructions, prerequisite: ARM Scalar.
84 * ARM SVE: around 4,000 instructions, prerequisite: NEON and ARM Scalar
85 * ARM SVE2: around 1,000 instructions, prerequisite: SVE, NEON, and
86 ARM Scalar for a grand total of well over 7,000 instructions.
87 * Intel AVX-512: around 4,000 instructions, prerequisite AVX, AVX2,
88 AVX-128 and AVX-256 which in turn critically rely on the rest of
89 x86, for a grand total of well over 10,000 instructions.
90 * RISV-V RVV: 192 instructions, prerequisite 96 Scalar RV64GC instructions
91 * SVP64: **six** instructions, two of which are in the same space
92 (svshape, svshape2), with 24-bit prefixing of
93 prerequisite SFS (150) or
94 SFFS (214) Compliancy Subsets.
95 **There are no dedicated Vector instructions, only Scalar-prefixed**.
96
97 Comparative Basic Design Principle:
98
99 * ARM NEON and VSX: PackedSIMD. No instruction-overloaded meaning
100 (every instruction is unique for a given register bitwidth,
101 guaranteeing binary interoperability)
102 * Intel AVX-512 (and below): Hybrid Packed-Predicated SIMD with no
103 instruction-overloading, guaranteeing binary interoperability
104 but at the same time penalising the ISA with runaway
105 opcode proliferation.
106 * ARM SVE/SVE2: Hybrid Packed-Predicated SIMD with instruction-overloading
107 that destroys binary interoperability. This is hidden behind the
108 misuse of the word "Scalable" and is **permitted under License**
109 by "Silicon Partners".
110 * RISC-V RVV: Cray-style Scalable Vector but with instruction-overloading
111 **permitted by the specification** that destroys binary interoperability.
112 * SVP64: Cray-style Scalable Vector with no instruction-overloaded
113 meanings. The regfile numbers and bitwidths shall **not** change
114 in a future revision (for the same instruction encoding):
115 "Silicon Partner" Scaling is prohibited,
116 in order to guarantee binary interoperability. Future revisions
117 of SVP64 may extend VSX instructions to achieve larger regfiles, and
118 non-interoperability on the same will likewise be prohibited.
119
120 SV comprises several [[sv/compliancy_levels]] suited to Embedded, Energy
121 efficient High-Performance Compute, Distributed Computing and Advanced
122 Computational Supercomputing. The Compliancy Levels are arranged such
123 that even at the bare minimum Level, full Soft-Emulation of all
124 optional and future features is possible.
125
126 # Sub-pages
127
128 Pages being developed and examples
129
130 * [[sv/executive_summary]]
131 * [[sv/overview]] explaining the basics.
132 * [[sv/compliancy_levels]] for minimum subsets through to Advanced
133 Supercomputing.
134 * [[sv/implementation]] implementation planning and coordination
135 * [[sv/po9_encoding]] a new DRAFT 64-bit space similar to EXT1xx,
136 introducing new areas EXT232-63 and EXT300-363
137 * [[sv/svp64]] contains the packet-format *only*, the [[svp64/appendix]]
138 contains explanations and further details
139 * [[sv/svp64_quirks]] things in SVP64 that slightly break the rules
140 or are not immediately apparent despite the RISC paradigm
141 * [[opcode_regs_deduped]] autogenerated table of SVP64 decoder augmentation
142 * [[sv/sprs]] SPRs
143 * [[sv/rfc]] RFCs to the [OPF ISA WG](https://openpower.foundation/isarfc/)
144
145 SVP64 "Modes":
146
147 * For condition register operations see [[sv/cr_ops]] - SVP64 Condition
148 Register ops: Guidelines
149 on Vectorisation of any v3.0B base operations which return
150 or modify a Condition Register bit or field.
151 * For LD/ST Modes, see [[sv/ldst]].
152 * For Branch modes, see [[sv/branches]] - SVP64 Conditional Branch
153 behaviour: All/Some Vector CRs
154 * For arithmetic and logical, see [[sv/normal]]
155 * [[sv/mv.vec]] pack/unpack move to and from vec2/3/4,
156 actually an RM.EXTRA Mode and a [[sv/remap]] mode
157
158 Core SVP64 instructions:
159
160 * [[sv/setvl]] the Cray-style "Vector Length" instruction
161 * svremap, svindex and svshape: part of [[sv/remap]] "Remapping" for
162 Matrix Multiply, DCT/FFT and RGB-style "Structure Packing"
163 as well as general-purpose Indexing. Also describes associated SPRs.
164 * [[sv/svstep]] Key stepping instruction, primarily for
165 Vertical-First Mode and also providing traditional "Vector Iota"
166 capability.
167
168 *Please note: there are only six instructions in the whole of SV.
169 Beyond this point are additional **Scalar** instructions related to
170 specific workloads that have nothing to do with the SV Specification*
171
172 # Stability Guarantees in Simple-V
173
174 Providing long-term stability in an ISA is extremely challenging
175 but critically important.
176 It requires certain guarantees to be provided.
177
178 * Firstly: that instructions will never be ambiguously-defined.
179 * Secondly, that no instruction shall change meaning to produce
180 different results on different hardware (present or future).
181 * Thirdly, that Scalar "defined words" (32 bit instruction
182 encodings) if Vectorised will also always be implemented as
183 identical Scalar instructions (the sole semi-exception being
184 Vectorised Branch-Conditional)
185 * Fourthly, that implementors are not permitted to either add
186 arbitrary features nor implement features in an incompatible
187 way. *(Performance may differ, but differing results are
188 not permitted)*.
189 * Fifthly, that any part of Simple-V not implemented by
190 a lower Compliancy Level is *required* to raise an illegal
191 instruction trap (allowing soft-emulation), including if
192 Simple-V is not implemented at all.
193 * Sixthly, that any `UNDEFINED` behaviour for practical implementation
194 reasons is clearly documented for both programmers and hardware
195 implementors.
196
197 In particular, given the strong recent emphasis and interest in
198 "Scalable Vector" ISAs, it is most unfortunate that both ARM SVE
199 and RISC-V RVV permit the exact same instruction to produce
200 different results on different hardware depending on a
201 "Silicon Partner" hardware choice. This choice catastrophically
202 and irrevocably causes binary non-interoperability *despite being
203 a "feature"*. Explained in <https://m.youtube.com/watch?v=HNEm8zmkjBU>
204 it is the exact same binary-incompatibility issue faced by Power ISA
205 on its 32- to 64-bit transition: 32-bit hardware was **unable** to
206 trap-and-emulate 64-bit binaries because the opcodes were (are) the same.
207
208 It is therefore *guaranteed* that extensions to the register file
209 width and quantity in Simple-V shall only be made in future by
210 explicit means, ensuring binary compatibility.
211
212 # Optional Scalar instructions
213
214 **Additional Instructions for specific purposes (not SVP64)**
215
216 All of these instructions below have nothing to do with SV.
217 They are all entirely designed as Scalar instructions that, as
218 Scalar instructions, stand on their own merit. Considerable
219 lengths have been made to provide justifications for each of these
220 *Scalar* instructions in a *Scalar* context, completely independently
221 of SVP64.
222
223 Some of these Scalar instructions happen also designed to make
224 Scalable Vector binaries more efficient, such
225 as the crweird group. Others are to bring the Scalar Power ISA
226 up-to-date within specific workloads,
227 such as a JavaScript Rounding instruction
228 (which saves 32 scalar instructions including seven branch instructions).
229 None of them are strictly necessary but performance and power consumption may
230 be (or, is already) compromised
231 in certain workloads and use-cases without them.
232
233 Vector-related but still Scalar:
234
235 * [[sv/mv.swizzle]] vec2/3/4 Swizzles (RGBA, XYZW) for 3D and CUDA.
236 designed as a Scalar instruction.
237 * [[sv/vector_ops]] scalar operations needed for supporting vectors
238 * [[sv/cr_int_predication]] scalar instructions needed for
239 effective predication
240
241 Stand-alone Scalar Instructions:
242
243 * [[sv/bitmanip]]
244 * [[sv/fcvt]] FP Conversion (due to OpenPOWER Scalar FP32)
245 * [[sv/fclass]] detect class of FP numbers
246 * [[sv/int_fp_mv]] Move and convert GPR <-> FPR, needed for !VSX
247 * [[sv/av_opcodes]] scalar opcodes for Audio/Video
248 * [[prefix_codes]] Decode/encode prefix-codes, used by JPEG, DEFLATE, etc.
249 * TODO: OpenPOWER adaptation [[openpower/transcendentals]]
250
251 Twin targetted instructions (two registers out, one implicit, just like
252 Load-with-Update).
253
254 * [[isa/svfixedarith]]
255 * [[isa/svfparith]]
256 * [[sv/biginteger]] Operations that help with big arithmetic
257
258 Explanation of the rules for twin register targets
259 (implicit RS, FRS) explained in SVP64 [[svp64/appendix]]
260
261 # Architectural Note
262
263 This section is primarily for the ISA Working Group and for IBM
264 in their capacity and responsibility for allocating "Architectural
265 Resources" (opcodes), but it is also useful for general understanding
266 of Simple-V.
267
268 Simple-V is effectively a type of "Zero-Overhead Loop Control" to which
269 an entire 24 bits are exclusively dedicated in a fully RISC-abstracted
270 manner. Within those 24-bits there are no Scalar instructions, and
271 no Vector instructions: there is *only* "Loop Control".
272
273 This is why there are no actual Vector operations in Simple-V: *all* suitable
274 Scalar Operations are Vectorised or not at all. This has some extremely
275 important implications when considering adding new instructions, and
276 especially when allocating the Opcode Space for them.
277 To protect SVP64 from damage, a "Hard Rule" has to be set:
278
279 Scalar Instructions must be simultaneously added in the corresponding
280 SVP64 opcode space with the exact same 32-bit "Defined Word" or they
281 must not be added at all. Likewise, instructions planned for addition
282 in what is considered (wrongly) to be the exclusive "Vector" domain
283 must correspondingly be added in the Scalar space with the exact same
284 32-bit "Defined Word", or they must not be added at all.
285
286 Some explanation of the above is needed. Firstly, "Defined Word" is a term
287 used in Section 1.6.3 of the Power ISA v3 1 Book I: it means, in short,
288 "a 32 bit instruction", which can then be Prefixed by EXT001 to extend it
289 to 64-bit (named EXT100-163).
290 Prefixed-Prefixed (96-bit Variable-Length) encodings are
291 prohibited in v3.1 and they are just as prohibited in Simple-V: it's too
292 complex in hardware. This means that **only** 32-bit "Defined Words"
293 may be Vectorised, and in particular it means that no 64-bit instruction
294 (EXT100-163) may **ever** be Vectorised.
295
296 Secondly, the term "Vectoriseable" was used. This refers to "instructions
297 which if SVP64-Prefixed are actually meaningful". `sc` is meaningless
298 to Vectorise, for example, as is `sync` and `mtmsr` (there is only ever
299 going to be one MSR).
300
301 The problem comes if the rationale is applied, "if unused,
302 Unvectoriseable opcodes
303 can therefore be allocated to alternative instructions mixing inside
304 the SVP64
305 Opcode space",
306 which unfortunately results in huge inadviseable complexity in HDL at the
307 Decode Phase, attempting to discern between the two types. Worse than that,
308 if the alternate 64-bit instruction is Vectoriseable but the 32-bit Scalar
309 "Defined Word" is already allocated, how can there ever be a Scalar version
310 of the alternate instruction? It would have to be added as a **completely
311 different** 32-bit "Defined Word", and things go rapidly downhill in the
312 Decoder as well as the ISA from there.
313
314 Therefore to avoid risk and long-term damage to the Power ISA:
315
316 * *even Unvectoriseable* "Defined Words" (`mtmsr`) must have the
317 corresponding SVP64 Prefixed Space `RESERVED`, permanently requiring
318 Illegal Instruction to be raised (the 64-bit encoding corresponding
319 to an illegal `sv.mtmsr` if ever incorrectly attempted must be
320 **defined** to raise an Exception)
321 * *Even instructions that may not be Scalar* (although for various
322 practical reasons this is extremely rare if not impossible,
323 if not just generally "strongly discouraged")
324 which have no meaning or use as a 32-bit Scalar "Defined Word", **must**
325 still have the Scalar "Defined Word" `RESERVED` in the scalar
326 opcode space, as an Illegal Instruction.
327
328 A good example of the former is `mtmsr` because there is only one
329 MSR register (`sv.mtmsr` is meaningless, as is `sv.sc`),
330 and a good example of the latter is [[sv/mv.x]]
331 which is so deeply problematic to add to any Scalar ISA that it was
332 rejected outright and an alternative route taken (Indexed REMAP).
333
334 Another good example would be Cross Product which has no meaning
335 at all in a Scalar ISA (Cross Product as a concept only applies
336 to Mathematical Vectors). If any such Vector operation were ever added,
337 it would be **critically** important to reserve the exact same *Scalar*
338 opcode with the exact same "Defined Word" in the *Scalar* Power ISA
339 opcode space, as an Illegal Instruction. There are
340 good reasons why Cross Product has not been proposed, but it serves
341 to illustrate the point as far as Architectural Resource Allocation is
342 concerned.
343
344 Bottom line is that whilst this seems wasteful the alternatives are a
345 destabilisation of the Power ISA and impractically-complex Hardware
346 Decoders. With the Scalar Power ISA (v3.0, v3.1) already being comprehensive
347 in the number of instructions, keeping further Decode complexity down is a
348 high priority.
349
350 # Other Scalable Vector ISAs
351
352 These Scalable Vector ISAs are listed to aid in understanding and
353 context of what is involved.
354
355 * Original Cray ISA
356 <http://www.bitsavers.org/pdf/cray/CRAY_Y-MP/HR-04001-0C_Cray_Y-MP_Computer_Systems_Functional_Description_Jun90.pdf>
357 * NEC SX Aurora (still in production, inspired by Cray)
358 <https://www.hpc.nec/documents/guide/pdfs/Aurora_ISA_guide.pdf>
359 * RISC-V RVV (inspired by Cray)
360 <https://github.com/riscv/riscv-v-spec>
361 * MRISC32 ISA Manual (under active development)
362 <https://github.com/mrisc32/mrisc32/tree/master/isa-manual>
363 * Mitch Alsup's MyISA 66000 Vector Processor ISA Manual is available from
364 Mitch on request.
365
366 A comprehensive list of 3D GPU, Packed SIMD, Predicated-SIMD and true Scalable
367 Vector ISAs may be found at the [[sv/vector_isa_comparison]] page.
368 Note: AVX-512 and SVE2 are *not Vector ISAs*, they are Predicated-SIMD.
369 *Public discussions have taken place at Conferences attended by both Intel
370 and ARM on adding a `setvl` instruction which would easily make both
371 AVX-512 and SVE2 truly "Scalable".* [[sv/comparison_table]] in tabular
372 form.
373
374 # Major opcodes summary <a name="major_op_summary"> </a>
375
376 Simple-V itself only requires six instructions with 6-bit Minor XO
377 (bits 26-31), and the SVP64 Prefix Encoding requires
378 25% space of the EXT001 Major Opcode.
379 There are **no** Vector Instructions and consequently **no further
380 opcode space is required**. Even though they are currently
381 placed in the EXT022 Sandbox, the "Management" instructions
382 (setvl, svstep, svremap, svshape, svindex) are designed to fit
383 cleanly into EXT019 (exactly like `addpcis`) or other 5/6-bit Minor
384 XO area (bits 25-31) that has space for Rc=1.
385
386 That said: for the target workloads for which Scalable Vectors are typically
387 used, the Scalar ISA on which those workloads critically rely
388 is somewhat anaemic.
389 The Libre-SOC Team has therefore been addressing that by developing
390 a number of Scalar instructions in specialist areas (Big Integer,
391 Cryptography, 3D, Audio/Video, DSP) and it is these which require
392 considerable Scalar opcode space.
393
394 Please be advised that even though SV is entirely DRAFT status, there
395 is considerable concern that because there is not yet any two-way
396 day-to-day communication established with the OPF ISA WG, we have
397 no idea if any of these are conflicting with future plans by any OPF
398 Members. **The External ISA WG RFC Process has now been ratified
399 but Libre-SOC may not join the OPF as an entity because it does
400 not exist except in name. Even if it existed it would be a conflict
401 of interest to join the OPF, due to our funding remit from NLnet**.
402 We therefore proceed on the basis of making public the intention to
403 submit RFCs once the External ISA WG RFC Process is in place and,
404 in a wholly unsatisfactory manner have to *hope and trust* that
405 OPF ISA WG Members are reading this and take it into consideration.
406
407 **Scalar Summary**
408
409 As in above sections, it is emphasised strongly that Simple-V in no
410 way critically depends on the 100 or so *Scalar* instructions also
411 being developed by Libre-SOC.
412
413 **None of these Draft opcodes are intended for private custom
414 secret proprietary usage. They are all intended for entirely
415 public, upstream, high-profile mass-volume day-to-day usage at the
416 same level as add, popcnt and fld**
417
418 * bitmanip requires two major opcodes (due to 16+ bit immediates)
419 those are currently EXT022 and EXT05.
420 * brownfield encoding in one of those two major opcodes still
421 requires multiple VA-Form operations (in greater numbers
422 than EXT04 has spare)
423 * space in EXT019 next to addpcis and crops is recommended
424 (or any other 5-6 bit Minor XO areas)
425 * many X-Form opcodes currently in EXT022 have no preference
426 for a location at all, and may be moved to EXT059, EXT019,
427 EXT031 or other much more suitable location.
428 * even if ratified and even if the majority (mostly X-Form)
429 is moved to other locations, the large immediate sizes of
430 the remaining bitmanip instructions means
431 it would be highly likely these remaining instructions would need two
432 major opcodes. Fortuitously the v3.1 Spec states that
433 both EXT005 and EXT009 are
434 available.
435
436 **Additional observations**
437
438 Note that there is no Sandbox allocation in the published ISA Spec for
439 v3.1 EXT01 usage, and because SVP64 is already 64-bit Prefixed,
440 Prefixed-Prefixed-instructions (SVP64 Prefixed v3.1 Prefixed)
441 would become a whopping 96-bit long instruction. Avoiding this
442 situation is a high priority which in turn by necessity puts pressure
443 on the 32-bit Major Opcode space.
444
445 Note also that EXT022, the Official Architectural Sandbox area
446 available for "Custom non-approved purposes" according to the Power
447 ISA Spec,
448 is under severe design pressure as it is insufficient to hold
449 the full extent of the instruction additions required to create
450 a Hybrid 3D CPU-VPU-GPU. Although the wording of the Power ISA
451 Specification leaves open the *possibility* of not needing to
452 propose ISA Extensions to the ISA WG, it is clear that EXT022
453 is an inappropriate location for a large high-profile Extension
454 intended for mass-volume product deployment. Every in-good-faith effort will
455 therefore be made to work with the OPF ISA WG to
456 submit SVP64 via the External RFC Process.
457
458 **Whilst SVP64 is only 6 instructions
459 the heavy focus on VSX for the past 12 years has left the SFFS Level
460 anaemic and out-of-date compared to ARM and x86.**
461 This is very much
462 a blessing, as the Scalar ISA has remained clean, making it
463 highly suited to RISC-paradigm Scalable Vector Prefixing. Approximately
464 100 additional (optional) Scalar Instructions are up for proposal to bring SFFS
465 up-to-date. None of them require or depend on PackedSIMD VSX (or VMX).
466
467 # Other
468
469 Examples experiments future ideas discussion:
470
471 * [Scalar register access](https://bugs.libre-soc.org/show_bug.cgi?id=905)
472 above r31 and CR7.
473 * [[sv/propagation]] Context propagation including svp64, swizzle and remap
474 * [[sv/masked_vector_chaining]]
475 * [[sv/discussion]]
476 * [[sv/example_dep_matrices]]
477 * [[sv/major_opcode_allocation]]
478 * [[sv/byteswap]]
479 * [[sv/16_bit_compressed]] experimental
480 * [[sv/toc_data_pointer]] experimental
481 * [[sv/predication]] discussion on predication concepts
482 * [[sv/register_type_tags]]
483 * [[sv/mv.x]] deprecated in favour of Indexed REMAP
484
485 Additional links:
486
487 * <https://www.sigarch.org/simd-instructions-considered-harmful/>
488 * [[sv/vector_isa_comparison]] - a list of Packed SIMD, GPU,
489 and other Scalable Vector ISAs
490 * [[sv/comparison_table]] - a one-off (experimental) table comparing ISAs
491 * [[simple_v_extension]] old (deprecated) version
492 * [[openpower/sv/llvm]]
493