(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 * Augments ("tags") existing instructions, providing Vectorisation
40 "context" rather than adding new instructions.
41 * Strictly does not interfere with or alter the non-Scalable Power ISA
42 in any way
43 * In the Prefix space, does not modify or deviate from the underlying
44 scalar Power ISA
45 unless it provides significant performance or other advantage to do so
46 in the Vector space (dropping the "sticky" characteristics
47 of XER.SO and CR0.SO for example)
48 * Designed for Supercomputing: avoids creating significant sequential
49 dependency hazards, allowing standard
50 high performance superscalar multi-issue
51 micro-architectures to be leveraged.
52 * Divided into Compliancy Levels to reduce cost of implementation for
53 specific needs.
54
55 Advantages of these design principles:
56
57 * Simplicity of introduction and implementation on top of
58 the existing Power ISA without disruption.
59 * It is therefore easy to create a first (and sometimes only)
60 implementation as literally a for-loop in hardware, simulators, and
61 compilers.
62 * Hardware Architects may understand and implement SV as being an
63 extra pipeline stage, inserted between decode and issue, that is
64 a simple for-loop issuing element-level sub-instructions.
65 * More complex HDL can be done by repeating existing scalar ALUs and
66 pipelines as blocks and leveraging existing Multi-Issue Infrastructure
67 * As (mostly) a high-level "context" that does not (significantly) deviate
68 from scalar Power ISA and, in its purest form being "a for loop around
69 scalar instructions", it is minimally-disruptive and consequently stands
70 a reasonable chance of broad community adoption and acceptance
71 * Completely wipes not just SIMD opcode proliferation off the
72 map (SIMD is O(N^6) opcode proliferation)
73 but off of Vectorisation ISAs as well. No more separate Vector
74 instructions.
75
76 Comparative instruction count:
77
78 * ARM NEON SIMD: around 2,000 instructions, prerequisite: ARM Scalar.
79 * ARM SVE: around 4,000 instructions, prerequisite: NEON.
80 * ARM SVE2: around 1,000 instructions, prerequisite: SVE
81 * Intel AVX-512: around 4,000 instructions, prerequisite AVX, AVX2,
82 AVX-128 and AVX-256 which in turn critically rely on the rest of
83 x86, for a grand total of well over 10,000 instructions.
84 * RISV-V RVV: 192 instructions, prerequisite 96 Scalar RV64GC instructions
85 * SVP64: **five** instructions, 24-bit prefixing of
86 prerequisite SFS (150) or
87 SFFS (214) Compliancy Subsets
88
89 SV comprises several [[sv/compliancy_levels]] suited to Embedded, Energy
90 efficient High-Performance Compute, Distributed Computing and Advanced
91 Computational Supercomputing. The Compliancy Levels are arranged such
92 that even at the bare minimum Level, full Soft-Emulation of all
93 optional and future features is possible.
94
95 # Sub-pages
96
97 Pages being developed and examples
98
99 * [[sv/overview]] explaining the basics.
100 * [[sv/compliancy_levels]] for minimum subsets through to Advanced
101 Supercomputing.
102 * [[sv/implementation]] implementation planning and coordination
103 * [[sv/svp64]] contains the packet-format *only*, the [[svp64/appendix]]
104 contains explanations and further details
105 * [[sv/svp64_quirks]] things in SVP64 that slightly break the rules
106 or are not immediately apparent despite the RISC paradigm
107 * [[opcode_regs_deduped]] autogenerated table of SVP64 decoder augmentation
108 * [[sv/sprs]] SPRs
109
110 SVP64 "Modes":
111
112 * For condition register operations see [[sv/cr_ops]] - SVP64 Condition
113 Register ops: Guidelines
114 on Vectorisation of any v3.0B base operations which return
115 or modify a Condition Register bit or field.
116 * For LD/ST Modes, see [[sv/ldst]].
117 * For Branch modes, see [[sv/branches]] - SVP64 Conditional Branch
118 behaviour: All/Some Vector CRs
119 * For arithmetic and logical, see [[sv/normal]]
120 * [[sv/mv.vec]] pack/unpack move to and from vec2/3/4,
121 actually an RM.EXTRA Mode and a [[sv/remap]] mode
122
123 Core SVP64 instructions:
124
125 * [[sv/setvl]] the Cray-style "Vector Length" instruction
126 * [[sv/remap]] "Remapping" for Matrix Multiply, DCT/FFT
127 and RGB-style "Structure Packing"
128 as well as Indexing. Describes svindex, svremap and svshape and
129 associated SPRs.
130 * [[sv/svstep]] Key stepping instruction, primarily for
131 Vertical-First Mode and also providing traditional "Vector Iota"
132 capability.
133
134 *Please note: there are only five instructions in the whole of SV.
135 Beyond this point are additional **Scalar** instructions related to
136 specific workloads that have nothing to do with the SV Specification*
137
138 # Optional Scalar instructions
139
140 **Additional Instructions for specific purposes (not SVP64)**
141
142 All of these instructions below have nothing to do with SV.
143 They are all entirely designed as Scalar instructions that, as
144 Scalar instructions, stand on their own merit. Considerable
145 lengths have been made to provide justifications for each of these
146 *Scalar* instructions.
147
148 Some of these Scalar instructions are specifically designed to make
149 Scalable Vector binaries more efficient, such
150 as the crweird group. Others are to bring the Scalar Power ISA
151 up-to-date within specific workloads,
152 such as a Javascript Rounding instruction
153 (which saves 35 instructions includibg 5 branches). None of them are strictly
154 necessary but performance and power consumption may be (or, is already)
155 compromised
156 in certain workloads and use-cases without them.
157
158 Vector-related but still Scalar:
159
160 * [[sv/mv.swizzle]] vec2/3/4 Swizzles (RGBA, XYZW) for 3D and CUDA.
161 designed as a Scalar instruction.
162 * [[sv/vector_ops]] scalar operations needed for supporting vectors
163 * [[sv/cr_int_predication]] scalar instructions needed for
164 effective predication
165
166 Stand-alone Scalar Instructions:
167
168 * [[sv/bitmanip]]
169 * [[sv/fcvt]] FP Conversion (due to OpenPOWER Scalar FP32)
170 * [[sv/fclass]] detect class of FP numbers
171 * [[sv/int_fp_mv]] Move and convert GPR <-> FPR, needed for !VSX
172 * [[sv/av_opcodes]] scalar opcodes for Audio/Video
173 * TODO: OpenPOWER adaptation [[openpower/transcendentals]]
174
175 Twin targetted instructions (two registers out, one implicit, just like
176 Load-with-Update).
177
178 * [[isa/svfixedarith]]
179 * [[isa/svfparith]]
180 * [[sv/biginteger]] Operations that help with big arithmetic
181
182 Explanation of the rules for twin register targets
183 (implicit RS, FRS) explained in SVP64 [[svp64/appendix]]
184
185 # Other Scalable Vector ISAs
186
187 These Scalable Vector ISAs are listed to aid in understanding and
188 context of what is involved.
189
190 * Original Cray ISA
191 <http://www.bitsavers.org/pdf/cray/CRAY_Y-MP/HR-04001-0C_Cray_Y-MP_Computer_Systems_Functional_Description_Jun90.pdf>
192 * NEC SX Aurora (still in production, inspired by Cray)
193 <https://www.hpc.nec/documents/guide/pdfs/Aurora_ISA_guide.pdf>
194 * RISC-V RVV (inspired by Cray)
195 <https://github.com/riscv/riscv-v-spec>
196 * MRISC32 ISA Manual (under active development)
197 <https://github.com/mrisc32/mrisc32/tree/master/isa-manual>
198 * Mitch Alsup's MyISA 66000 Vector Processor ISA Manual is available from
199 Mitch on request.
200
201 A comprehensive list of 3D GPU, Packed SIMD, Predicated-SIMD and true Scalable
202 Vector ISAs may be found at the [[sv/vector_isa_comparison]] page.
203 Note: AVX-512 and SVE2 are *not Vector ISAs*, they are Predicated-SIMD.
204 *Public discussions have taken place at Conferences attended by both Intel
205 and ARM on adding a `setvl` instruction which would easily make both
206 AVX-512 and SVE2 truly "Scalable".*
207
208 # Major opcodes summary
209
210 Simple-V itself only requires five instructions with 6-bit Minor XO
211 (bits 26-31), and the SVP64 Prefix Encoding requires
212 25% space of the EXT001 Major Opcode.
213 There are **no** Vector Instructions and consequently **no further
214 opcode space is required**. Even though they are currently
215 placed in the EXT022 Sandbox, the "Management" instructions
216 (setvl, svstep, svremap, svshape, svindex) are designed to fit
217 cleanly into EXT019 (like `addpcis`) or other 5/6-bit Minor
218 XO area that has space for Rc=1.
219
220 That said: for the target workloads for which Scalable Vectors are typically
221 used, the Scalar ISA on which those workloads critically rely
222 is somewhat anaemic.
223 The Libre-SOC Team has therefore been addressing that by developing
224 a number of Scalar instructions in specialist areas (Big Integer,
225 Cryptography, 3D, Audio/Video, DSP) and it is these which require
226 considerable Scalar opcode space.
227
228 Please be advised that even though SV is entirely DRAFT status, there
229 is considerable concern that because there is not yet any two-way
230 day-to-day communication established with the OPF ISA WG, we have
231 no idea if any of these are conflicting with future plans by any OPF
232 Members. **The External ISA WG RFC Process is yet to be ratified
233 and Libre-SOC may not join the OPF as an entity because it does
234 not exist except in name. Even if it existed it would be a conflict
235 of interest to join the OPF, due to our funding remit from NLnet**.
236 We therefore proceed on the basis of making public the intention to
237 submit RFCs once the External ISA WG RFC Process is in place and,
238 in a wholly unsatisfactory manner have to *hope and trust* that
239 OPF ISA WG Members are reading this and take it into consideration.
240
241 **Scalar Summary**
242
243 As in above sections, it is emphasised strongly that Simple-V in no
244 way critically depends on the 100 or so *Scalar* instructions also
245 being developed by Libre-SOC.
246
247 **None of these Draft opcodes are intended for private custom
248 secret proprietary usage. They are all intended for entirely
249 public, upstream, high-profile mass-volume day-to-day usage at the
250 same level as add, popcnt and fld**
251
252 * bitmanip requires two major opcodes (due to 16+ bit immediates)
253 those are currently EXT022 and EXT05.
254 * brownfield encoding in one of those two major opcodes still
255 requires multiple VA-Form operations (in greater numbers
256 than EXT04 has spare)
257 * space in EXT019 next to addpcis and crops is recommended
258 (or any other 5-6 bit Minor XO areas)
259 * many X-Form opcodes currently in EXT022 have no preference
260 for a location at all, and may be moved to EXT059, EXT019,
261 EXT031 or other much more suitable location.
262 * even if ratified and even if the majority (mostly X-Form)
263 is moved to other locations, the large immediate sizes of
264 the remaining bitmanip instructions means
265 it would be highly likely these remaining instructions would need two
266 major opcodes. Fortuitously the v3.1 Spec states that
267 both EXT005 and EXT009 are
268 available.
269
270 **Additional observations**
271
272 Note that there is no Sandbox allocation in the published ISA Spec for
273 v3.1 EXT01 usage, and because SVP64 is already 64-bit Prefixed,
274 Prefixed-Prefixed-instructions (SVP64 Prefixed v3.1 Prefixed)
275 would become a whopping 96-bit long instruction. Avoiding this
276 situation is a high priority which in turn by necessity puts pressure
277 on the 32-bit Major Opcode space.
278
279 SVP64 itself is already under pressure, being only 24 bits. If it is
280 not permitted to take up 25% of EXT001 then it would have to be proposed
281 in its own Major Opcode, which on first consideration would be beneficial
282 for SVP64 due to the availability of 2 extra bits.
283 However when combined with the bitmanip scalar instructions
284 requiring two Major opcodes this would come to a grand total of 3 precious
285 Major opcodes. On balance, then, sacrificing 25% of EXT001 is the "least
286 difficult" choice.
287
288 Note also that EXT022, the Official Architectural Sandbox area
289 available for "Custom non-approved purposes" according to the Power
290 ISA Spec,
291 is under severe design pressure as it is insufficient to hold
292 the full extent of the instruction additions required to create
293 a Hybrid 3D CPU-VPU-GPU.
294
295 **Whilst SVP64 is only 5 instructions
296 the heavy focus on VSX for the past 12 years has left the SFFS Level
297 anaemic and out-of-date compared to ARM and x86.**
298 This is very much
299 a blessing, as the Scalar ISA has remained clean, making it
300 highly suited to RISC-paradigm Scalable Vector Prefixing. Approximately
301 100 additional (optional) Scalar Instructions are up for proposal to bring SFFS
302 up-to-date. None of them require or depend on PackedSIMD VSX (or VMX).
303
304 # Other
305
306 Examples experiments future ideas discussion:
307
308 * [[sv/propagation]] Context propagation including svp64, swizzle and remap
309 * [[sv/masked_vector_chaining]]
310 * [[sv/discussion]]
311 * [[sv/example_dep_matrices]]
312 * [[sv/major_opcode_allocation]]
313 * [[sv/byteswap]]
314 * [[sv/16_bit_compressed]] experimental
315 * [[sv/toc_data_pointer]] experimental
316 * [[sv/predication]] discussion on predication concepts
317 * [[sv/register_type_tags]]
318 * [[sv/mv.x]] deprecated in favour of Indexed REMAP
319
320 Additional links:
321
322 * <https://www.sigarch.org/simd-instructions-considered-harmful/>
323 * [[sv/vector_isa_comparison]] - a list of Packed SIMD, GPU,
324 and other Scalable Vector ISAs
325 * [[simple_v_extension]] old (deprecated) version
326 * [[openpower/sv/llvm]]
327