(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
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/svp64]] contains the packet-format *only*, the [[svp64/appendix]]
136 contains explanations and further details
137 * [[sv/svp64_quirks]] things in SVP64 that slightly break the rules
138 or are not immediately apparent despite the RISC paradigm
139 * [[opcode_regs_deduped]] autogenerated table of SVP64 decoder augmentation
140 * [[sv/sprs]] SPRs
141 * [[sv/rfc]] RFCs to the [OPF ISA WG](https://openpower.foundation/isarfc/)
142
143 SVP64 "Modes":
144
145 * For condition register operations see [[sv/cr_ops]] - SVP64 Condition
146 Register ops: Guidelines
147 on Vectorisation of any v3.0B base operations which return
148 or modify a Condition Register bit or field.
149 * For LD/ST Modes, see [[sv/ldst]].
150 * For Branch modes, see [[sv/branches]] - SVP64 Conditional Branch
151 behaviour: All/Some Vector CRs
152 * For arithmetic and logical, see [[sv/normal]]
153 * [[sv/mv.vec]] pack/unpack move to and from vec2/3/4,
154 actually an RM.EXTRA Mode and a [[sv/remap]] mode
155
156 Core SVP64 instructions:
157
158 * [[sv/setvl]] the Cray-style "Vector Length" instruction
159 * svremap, svindex and svshape: part of [[sv/remap]] "Remapping" for
160 Matrix Multiply, DCT/FFT and RGB-style "Structure Packing"
161 as well as general-purpose Indexing. Also describes associated SPRs.
162 * [[sv/svstep]] Key stepping instruction, primarily for
163 Vertical-First Mode and also providing traditional "Vector Iota"
164 capability.
165
166 *Please note: there are only six instructions in the whole of SV.
167 Beyond this point are additional **Scalar** instructions related to
168 specific workloads that have nothing to do with the SV Specification*
169
170 # Stability Guarantees in Simple-V
171
172 Providing long-term stability in an ISA is extremely challenging
173 but critically important.
174 It requires certain guarantees to be provided.
175
176 * Firstly: that instructions will never be ambiguously-defined.
177 * Secondly, that no instruction shall change meaning to produce
178 different results on different hardware (present or future).
179 * Thirdly, that Scalar "defined words" (32 bit instruction
180 encodings) if Vwctorised will also always be implemented as
181 identical Scalar instructions (the sole semi-exception being
182 Vevtorised Branch-Conditional)
183 * Fourthly, that implementors are not permitted to either add
184 arbitrary features nor implement features in an incompatible
185 way. *(Performance may differ, but differing results are
186 not permitted)*.
187 * Fifthly, that any part of Simple-V not implemented by
188 a lower Compliancy Level is *required* to raise an illegal
189 instruction trap (allowing soft-emulation), including if
190 Simple-V is not implemented at all.
191 * Sixthly, that any `UNDEFINED` behaviour for practical implementation
192 reasons is clearly documented for both programmers and hardware
193 implementors.
194
195 In particular, given the strong recent emphasis and interest in
196 "Scalable Vector" ISAs, it is most unfortunate that both ARM SVE
197 and RISC-V RVV permit the exact same instruction to produce
198 different results on different hardware depending on a
199 "Silicon Partner" hardware choice. This choice catastrophically
200 and irrevocably causes binary non-interoperability *despite being
201 a "feature"*. Explained in <https://m.youtube.com/watch?v=HNEm8zmkjBU>
202
203 It is therefore *guaranteed* that extensions to the register file
204 width and quantity in Simple-V shall only be made in future by
205 explicit means, ensuring binary compatibility.
206
207
208 # Optional Scalar instructions
209
210 **Additional Instructions for specific purposes (not SVP64)**
211
212 All of these instructions below have nothing to do with SV.
213 They are all entirely designed as Scalar instructions that, as
214 Scalar instructions, stand on their own merit. Considerable
215 lengths have been made to provide justifications for each of these
216 *Scalar* instructions in a *Scalar* context, completely independently
217 of SVP64.
218
219 Some of these Scalar instructions happen also designed to make
220 Scalable Vector binaries more efficient, such
221 as the crweird group. Others are to bring the Scalar Power ISA
222 up-to-date within specific workloads,
223 such as a Javascript Rounding instruction
224 (which saves 35 instructions including 5 branches). None of them are strictly
225 necessary but performance and power consumption may be (or, is already)
226 compromised
227 in certain workloads and use-cases without them.
228
229 Vector-related but still Scalar:
230
231 * [[sv/mv.swizzle]] vec2/3/4 Swizzles (RGBA, XYZW) for 3D and CUDA.
232 designed as a Scalar instruction.
233 * [[sv/vector_ops]] scalar operations needed for supporting vectors
234 * [[sv/cr_int_predication]] scalar instructions needed for
235 effective predication
236
237 Stand-alone Scalar Instructions:
238
239 * [[sv/bitmanip]]
240 * [[sv/fcvt]] FP Conversion (due to OpenPOWER Scalar FP32)
241 * [[sv/fclass]] detect class of FP numbers
242 * [[sv/int_fp_mv]] Move and convert GPR <-> FPR, needed for !VSX
243 * [[sv/av_opcodes]] scalar opcodes for Audio/Video
244 * TODO: OpenPOWER adaptation [[openpower/transcendentals]]
245
246 Twin targetted instructions (two registers out, one implicit, just like
247 Load-with-Update).
248
249 * [[isa/svfixedarith]]
250 * [[isa/svfparith]]
251 * [[sv/biginteger]] Operations that help with big arithmetic
252
253 Explanation of the rules for twin register targets
254 (implicit RS, FRS) explained in SVP64 [[svp64/appendix]]
255
256 # Architectural Note
257
258 This section is primarily for the ISA Working Group and for IBM
259 in their capacity and responsibility for allocating "Architectural
260 Resources" (opcodes), but it is also useful for general understanding
261 of Simple-V.
262
263 Simple-V is effectively a type of "Zero-Overhead Loop Control" to which
264 an entire 24 bits are exclusively dedicated in a fully RISC-abstracted
265 manner. This is why there are no Vector operations: *all* suitable
266 Scalar Operations are Vectorised or not at all. This has some extremely
267 important implications when considering adding new instructions, and
268 especially when allocating the Opcode Space for them.
269 To protect SVP64 from damage, a "Hard Rule" has to be set:
270
271 Scalar Instructions must be simultaneously added in the corresponding
272 SVP64 opcode space with the exact same 32-bit "Defined Word" or they
273 must not be added at all. Likewise instructions planned for addition
274 in what is considered (wrongly) to be the exclusive "Vector" domain
275 must correspondingly be added in the Scalar space with the exact same
276 32-bit "Defined Word" or not at all.
277
278
279
280 # Other Scalable Vector ISAs
281
282 These Scalable Vector ISAs are listed to aid in understanding and
283 context of what is involved.
284
285 * Original Cray ISA
286 <http://www.bitsavers.org/pdf/cray/CRAY_Y-MP/HR-04001-0C_Cray_Y-MP_Computer_Systems_Functional_Description_Jun90.pdf>
287 * NEC SX Aurora (still in production, inspired by Cray)
288 <https://www.hpc.nec/documents/guide/pdfs/Aurora_ISA_guide.pdf>
289 * RISC-V RVV (inspired by Cray)
290 <https://github.com/riscv/riscv-v-spec>
291 * MRISC32 ISA Manual (under active development)
292 <https://github.com/mrisc32/mrisc32/tree/master/isa-manual>
293 * Mitch Alsup's MyISA 66000 Vector Processor ISA Manual is available from
294 Mitch on request.
295
296 A comprehensive list of 3D GPU, Packed SIMD, Predicated-SIMD and true Scalable
297 Vector ISAs may be found at the [[sv/vector_isa_comparison]] page.
298 Note: AVX-512 and SVE2 are *not Vector ISAs*, they are Predicated-SIMD.
299 *Public discussions have taken place at Conferences attended by both Intel
300 and ARM on adding a `setvl` instruction which would easily make both
301 AVX-512 and SVE2 truly "Scalable".* [[sv/comparison_table]] in tabular
302 form.
303
304 # Major opcodes summary <a name="major_op_summary"> </a>
305
306 Simple-V itself only requires six instructions with 6-bit Minor XO
307 (bits 26-31), and the SVP64 Prefix Encoding requires
308 25% space of the EXT001 Major Opcode.
309 There are **no** Vector Instructions and consequently **no further
310 opcode space is required**. Even though they are currently
311 placed in the EXT022 Sandbox, the "Management" instructions
312 (setvl, svstep, svremap, svshape, svindex) are designed to fit
313 cleanly into EXT019 (exactly like `addpcis`) or other 5/6-bit Minor
314 XO area (bits 25-31) that has space for Rc=1.
315
316 That said: for the target workloads for which Scalable Vectors are typically
317 used, the Scalar ISA on which those workloads critically rely
318 is somewhat anaemic.
319 The Libre-SOC Team has therefore been addressing that by developing
320 a number of Scalar instructions in specialist areas (Big Integer,
321 Cryptography, 3D, Audio/Video, DSP) and it is these which require
322 considerable Scalar opcode space.
323
324 Please be advised that even though SV is entirely DRAFT status, there
325 is considerable concern that because there is not yet any two-way
326 day-to-day communication established with the OPF ISA WG, we have
327 no idea if any of these are conflicting with future plans by any OPF
328 Members. **The External ISA WG RFC Process has now been ratified
329 but Libre-SOC may not join the OPF as an entity because it does
330 not exist except in name. Even if it existed it would be a conflict
331 of interest to join the OPF, due to our funding remit from NLnet**.
332 We therefore proceed on the basis of making public the intention to
333 submit RFCs once the External ISA WG RFC Process is in place and,
334 in a wholly unsatisfactory manner have to *hope and trust* that
335 OPF ISA WG Members are reading this and take it into consideration.
336
337 **Scalar Summary**
338
339 As in above sections, it is emphasised strongly that Simple-V in no
340 way critically depends on the 100 or so *Scalar* instructions also
341 being developed by Libre-SOC.
342
343 **None of these Draft opcodes are intended for private custom
344 secret proprietary usage. They are all intended for entirely
345 public, upstream, high-profile mass-volume day-to-day usage at the
346 same level as add, popcnt and fld**
347
348 * bitmanip requires two major opcodes (due to 16+ bit immediates)
349 those are currently EXT022 and EXT05.
350 * brownfield encoding in one of those two major opcodes still
351 requires multiple VA-Form operations (in greater numbers
352 than EXT04 has spare)
353 * space in EXT019 next to addpcis and crops is recommended
354 (or any other 5-6 bit Minor XO areas)
355 * many X-Form opcodes currently in EXT022 have no preference
356 for a location at all, and may be moved to EXT059, EXT019,
357 EXT031 or other much more suitable location.
358 * even if ratified and even if the majority (mostly X-Form)
359 is moved to other locations, the large immediate sizes of
360 the remaining bitmanip instructions means
361 it would be highly likely these remaining instructions would need two
362 major opcodes. Fortuitously the v3.1 Spec states that
363 both EXT005 and EXT009 are
364 available.
365
366 **Additional observations**
367
368 Note that there is no Sandbox allocation in the published ISA Spec for
369 v3.1 EXT01 usage, and because SVP64 is already 64-bit Prefixed,
370 Prefixed-Prefixed-instructions (SVP64 Prefixed v3.1 Prefixed)
371 would become a whopping 96-bit long instruction. Avoiding this
372 situation is a high priority which in turn by necessity puts pressure
373 on the 32-bit Major Opcode space.
374
375 SVP64 itself is already under pressure, being only 24 bits. If it is
376 not permitted to take up 25% of EXT001 then it would have to be proposed
377 in its own Major Opcode, which on first consideration would be beneficial
378 for SVP64 due to the availability of 2 extra bits.
379 However when combined with the bitmanip scalar instructions
380 requiring two Major opcodes this would come to a grand total of 3 precious
381 Major opcodes. On balance, then, sacrificing 25% of EXT001 is the "least
382 difficult" choice.
383 Alternative locations for SVP64
384 Prefixing include EXT006 and EXT017, with EXT006 being most favourable
385 as there is room for future expansion.
386
387 Note also that EXT022, the Official Architectural Sandbox area
388 available for "Custom non-approved purposes" according to the Power
389 ISA Spec,
390 is under severe design pressure as it is insufficient to hold
391 the full extent of the instruction additions required to create
392 a Hybrid 3D CPU-VPU-GPU. Although the wording of the Power ISA
393 Specification leaves open the *possibility* of not needing to
394 propose ISA Extensions to the ISA WG, it is clear that EXT022
395 is an inappropriate location for a large high-profile Extension
396 intended for mass-volume product deployment. Every in-good-faith effort will
397 therefore be made to work with the OPF ISA WG to
398 submit SVP64 via the External RFC Process.
399
400 **Whilst SVP64 is only 6 instructions
401 the heavy focus on VSX for the past 12 years has left the SFFS Level
402 anaemic and out-of-date compared to ARM and x86.**
403 This is very much
404 a blessing, as the Scalar ISA has remained clean, making it
405 highly suited to RISC-paradigm Scalable Vector Prefixing. Approximately
406 100 additional (optional) Scalar Instructions are up for proposal to bring SFFS
407 up-to-date. None of them require or depend on PackedSIMD VSX (or VMX).
408
409 # Other
410
411 Examples experiments future ideas discussion:
412
413 * [Scalar register access](https://bugs.libre-soc.org/show_bug.cgi?id=905)
414 above r31 and CR7.
415 * [[sv/propagation]] Context propagation including svp64, swizzle and remap
416 * [[sv/masked_vector_chaining]]
417 * [[sv/discussion]]
418 * [[sv/example_dep_matrices]]
419 * [[sv/major_opcode_allocation]]
420 * [[sv/byteswap]]
421 * [[sv/16_bit_compressed]] experimental
422 * [[sv/toc_data_pointer]] experimental
423 * [[sv/predication]] discussion on predication concepts
424 * [[sv/register_type_tags]]
425 * [[sv/mv.x]] deprecated in favour of Indexed REMAP
426
427 Additional links:
428
429 * <https://www.sigarch.org/simd-instructions-considered-harmful/>
430 * [[sv/vector_isa_comparison]] - a list of Packed SIMD, GPU,
431 and other Scalable Vector ISAs
432 * [[sv/comparison_table]] - a one-off (experimental) table comparing ISAs
433 * [[simple_v_extension]] old (deprecated) version
434 * [[openpower/sv/llvm]]
435