(no commit message)
[libreriscv.git] / openpower / sv / rfc / ls012.mdwn
1 # External RFC ls012: Discuss priorities of Libre-SOC Scalar(Vector) ops
2
3 ** Date: 2023apr10. v1**
4
5 * <https://git.openpower.foundation/isa/PowerISA/issues/121>
6 * <https://bugs.libre-soc.org/show_bug.cgi?id=1051>
7 * <https://bugs.libre-soc.org/show_bug.cgi?id=1052>
8
9 The purpose of this RFC is:
10
11 * to give a full list of the upcoming Scalar opcodes developed by Libre-SOC
12 (respecting and being cognisant that *all* of them are Vectorisable)
13 * to give OPF Members and non-Members alike the opportunity to comment and get
14 involved early in RFC submission
15 * formally agree a priority order on an iterative basis with new versions
16 of this RFC,
17 * which ones should be EXT022 Sandbox, which in EXT0xx, which in EXT2xx,
18 * keep readers summarily informed of ongoing RFC submissions, with new versions
19 of this RFC,
20 * and for IBM (in their capacity as Allocator of Opcode resources)
21 to get a clear overall advance picture of the Opcode Allocation needs
22 *prior* to actual RFC submission
23
24 As this is a Formal ISA RFC the evaluation shall ultimatly define
25 (in advance of the actual submission of the instructions themselves)
26 which instructions will be submitted over the next 8-18 months.
27
28 *It is expected that readers visit and interact with the Libre-SOC
29 resources in order to do due-diligence on the prioritisation
30 evaluation. Otherwise the ISA WG is overwhelmed by "drip-fed" RFCs
31 that may turn out not to be useful, against a background of having
32 no guiding overview or pre-filtering, and everybody's precious time
33 is wasted. Also note that the Libre-SOC Team, being funded by NLnet
34 under Privacy and Enhanced Trust Grants, are **prohibited** from signing
35 Commercial-Confidentiality NDAs, as doing so is a direct conflict of
36 interest with their funding body's Charitable Foundation Status and
37 remit, and therefore the **entire** set of almost 150 new SFFS instructions
38 can only go via the External RFC Process. Also be advised and aware
39 that "Libre-SOC" != "RED Semiconductor Ltd". The two are completely **separate**
40 organisations*.
41
42 Worth bearing in mind during evaluation that every "Defined Word" may
43 or may not be Vectoriseable, but that every "Defined Word" should have
44 merits on its own, not just when Vectorised. An example of a borderline
45 Vectoriseable Defined Word is `mv.swizzle` which only really becomes
46 high-priority for Audio/Video, Vector GPU and HPC Workloads, but has
47 less merit as a Scalar-only operation.
48
49 Although one of the top world-class ISAs,
50 Power ISA Scalar (SFFS) has not been significantly advanced in 12
51 years: IBM's primary focus has understandably been on PackedSIMD VSX.
52 Unfortunately, with VSX being 914 instructions and 128-bit it is far too
53 much for any new team to consider (10 years development effort) and far
54 outside of Embedded or Tablet/Desktop/Laptop power budgets. Thus bringing
55 Power Scalar up-to-date to modern standards *and on its own merits*
56 is a reasonable goal, and the advantages of the reduced focus is that
57 SFFS remains RISC-paradigm, and that lessons can be learned from other
58 ISAs from the intervening years. Good examples here include `bmask`.
59
60 SVP64 Prefixing - also known by the terms "Zero-Overhead-Loop-Prefixing"
61 as well as "True-Scalable-Vector Prefixing" - also literally brings new
62 dimensions to the Power ISA. Thus when adding new Scalar "Defined Words"
63 it has to unavoidably and simultaneously be taken into consideration
64 their value when Vector-Prefixed, *as well as* SVP64Single-Prefixed.
65
66 **Target areas**
67
68 Whilst entirely general-purpose there are some categories that these
69 instructions are targetting: Bitmanipulation, Big-integer, cryptography,
70 Audio/Visual, High-Performance Compute, GPU workloads and DSP.
71
72 **Instruction count guide and approximate priority order**
73
74 * 6 - SVP64 Management [[ls008]] [[ls009]] [[ls010]]
75 * 5 - CR weirds [[sv/cr_int_predication]]
76 * 4 - INT<->FP mv [[ls006]]
77 * 19 - GPR LD/ST-PostIncrement-Update (saves hugely in hot-loops) [[ls011]]
78 * ~12 - FPR LD/ST-PostIncrement-Update (ditto) [[ls011]]
79 * 2 - Float-Load-Immediate (always saves one LD L1/2/3 D-Cache op) [[ls002]]
80 * 5 - Big-Integer Chained 3-in 2-out (64-bit Carry) [[sv/biginteger]]
81 * 6 - Bitmanip LUT2/3 operations. high cost high reward [[sv/bitmanip]]
82 * 1 - fclass (Scalar variant of xvtstdcsp) [[sv/fclass]]
83 * 5 - Audio-Video [[sv/av_opcodes]]
84 * 2 - Shift-and-Add (mitigates LD-ST-Shift; Cryptography e.g. twofish) [[ls004]]
85 * 2 - BMI group [[sv/vector_ops]]
86 * 2 - GPU swizzle [[sv/mv.swizzle]]
87 * 9 - FP DCT/FFT Butterfly (2/3-in 2-out)
88 * ~9 Integer DCT/FFT Butterfly <https://bugs.libre-soc.org/show_bug.cgi?id=1028>
89 * 18 - Trigonometric (1-arg) [[openpower/transcendentals]]
90 * 15 - Transcendentals (1-arg) [[openpower/transcendentals]]
91 * 25 - Transcendentals (2-arg) [[openpower/transcendentals]]
92
93 Summary tables are created below by different sort categories. Additional
94 columns (and tables) as necessary can be requested to be added as part of update revisions
95 to this RFC.
96
97 # Target Area summaries
98
99 Please note that there are some instructions developed thanks to NLnet
100 funding that have not been included here for assessment. Examples
101 include `pcdec` and the Galois Field arithmetic operations. From a purely
102 practical perspective due to the quantity the lower-priority instructions
103 were simply left out. However they remain in the Libre-SOC resources.
104
105 ## SVP64 Management instructions
106
107 These without question have to go in EXT0xx. Future extended variants,
108 bringing even more powerful capabilities, can be followed up later with
109 EXT1xx prefixed variants, which is not possible if placed in EXT2xx.
110 *Only `svstep` is actually Vectoriseable*, all other Management
111 instructions are UnVectoriseable. PO1-Prefixed examples include adding
112 psvshape in order to support both Inner and Outer Product Matrix
113 Schedules, by providing the option to directly reverse the order of the
114 triple loops. Outer is used for standard Matrix Multiply (on top
115 of a standard MAC or FMAC instruction), but Inner is
116 required for Warshall Transitive Closure (on top of a cumulatively-applied
117 max instruction).
118
119 The Management Instructions themselves are all Scalar Operations, so
120 PO1-Prefixing is perfecly reasonable. SVP64 Management instructions of
121 which there are only 6 are all 5 or 6 bit XO, meaning that the opcode
122 space they take up in EXT0xx is not alarmingly high for their intrinsic
123 strategic value.
124
125 ## Transcendentals
126
127 Found at [[openpower/transcendentals]] these subdivide into high
128 priority for accelerating general-purpose and High-Performance Compute,
129 specialist 3D GPU operations suited to 3D visualisation, and low-priority
130 less common instructions where IEEE754 full bit-accuracy is paramount.
131 In 3D GPU scenarios for example even 12-bit accuracy can be overkill,
132 but for HPC Scientific scenarios 12-bit would be disastrous.
133
134 There are a **lot** of operations here, and they also bring Power
135 ISA up-to-date to IEEE754-2019. Fortunately the number of critical
136 instructions is quite low, but the caveat is that if those operations
137 are utilised to synthesise other IEEE754 operations (divide by `pi` for
138 example) full bitlevel accuracy (a hard requirement for IEEE754) is lost.
139
140 Also worth noting that the Khronos Group defines minimum acceptable
141 bit-accuracy levels for 3D Graphics: these are **nowhere near** the full
142 accuracy demanded by IEEE754, the reason for the Khronos definitions is
143 a massive reduction often four-fold in power consumption and gate count
144 when 3D Graphics simply has no need for full accuracy.
145
146 *For 3D GPU markets this definitely needs addressing*
147
148 ## Audio/Video
149
150 Found at [[sv/av_opcodes]] these do not require Saturated variants
151 because Saturation is added via [[sv/svp64]] (Vector Prefixing) and via
152 [[sv/svp64_single]] Scalar Prefixing. This is important to note for
153 Opcode Allocation because placing these operations in the UnVectoriseble
154 areas would irrediemably damage their value. Unlike PackedSIMD ISAs
155 the actual number of AV Opcodes is remarkably small once the usual
156 cascading-option-multipliers (SIMD width, bitwidth, saturation,
157 HI/LO) are abstracted out to RISC-paradigm Prefixing, leaving just
158 absolute-diff-accumulate, min-max, average-add etc. as "basic primitives".
159
160 ## Twin-Butterfly FFT/DCT/DFT for DSP/HPC/AI/AV
161
162 The number of uses in Computer Science for DCT, NTT, FFT and DFT,
163 is astonishing. The wikipedia page lists over a hundred separate and
164 distinct areas: Audio, Video, Radar, Baseband processing, AI, Solomon-Reed
165 Error Correction, the list goes on and on. ARM has special dedicated
166 Integer Twin-butterfly instructions. TI's MSP Series DSPs have had FFT
167 Inner loop support for over 30 years. Qualcomm's Hexagon VLIW Baseband
168 DSP can do full FFT triple loops in one VLIW group.
169
170 It should be pretty clear this is high priority.
171
172 With SVP64 [[sv/remap]] providing the Loop Schedules it falls to
173 the Scalar side of the ISA to add the prerequisite "Twin Butterfly"
174 operations, typically performing for example one multiply but in-place
175 subtracting that product from one operand and adding it to the other.
176 The *in-place* aspect is strategically extremely important for significant
177 reductions in Vectorised register usage, particularly for DCT.
178
179 ## CR Weird group
180
181 Outlined in [[sv/cr_int_predication]] these instructions massively save
182 on CR-Field instruction count. Multi-bit to single-bit and vice-versa
183 normally requiring several CR-ops (crand, crxor) are done in one single
184 instruction. The reason for their addition is down to SVP64 overloading
185 CR Fields as Vector Predicate Masks. Reducing instruction count in
186 hot-loops is considered high priority.
187
188 An additional need is to do popcount on CR Field bit vectors but adding
189 such instructions to the *Condition Register* side was deemed to be far
190 too much. Therefore, priority was given instead to transferring several
191 CR Field bits into GPRs, whereupon the full set of tandard Scalar GPR
192 Logical Operations may be used. This strategy has the side-effect of
193 keeping the CRweird group down to only five instructions.
194
195 ## Big-integer Math
196
197 [[sv/biginteger]] has always been a high priority area for commercial
198 applications, privacy, Banking, as well as HPC Numerical Accuracy:
199 libgmp as well as cryptographic uses in Asymmetric Ciphers. poly1305
200 and ec25519 are finding their way into everyday use via OpenSSL.
201
202 A very early variant of the Power ISA had a 32-bit Carry-in Carry-out
203 SPR. Its removal from subsequent revisions is regrettable. An alternative
204 concept is to add six explicit 3-in 2-out operations that, on close
205 inspection, always turn out to be supersets of *existing Scalar
206 operations* that discard upper or lower DWords, or parts thereof.
207
208 *Thus it is critical to note that not one single one of these operations
209 expands the bitwidth of any existing Scalar pipelines*.
210
211 The `dsld` instruction for example merely places additional LSBs into the
212 64-bit shift (64-bit carry-in), and then places the (normally discarded)
213 MSBs into the second output register (64-bit carry-out). It does **not**
214 require a 128-bit shifter to replace the existing Scalar Power ISA
215 64-bit shifters.
216
217 The reduction in instruction count these operations bring, in critical
218 hotloops, is remarkably high, to the extent where a Scalar-to-Vector
219 operation of *arbitrary length* becomes just the one Vector-Prefixed
220 instruction.
221
222 Whilst these are 5-6 bit XO their utility is considered high strategic
223 value and as such are strongly advocated to be in EXT04. The alternative
224 is to bring back a 64-bit Carry SPR but how it is retrospectively
225 applicable to pre-existing Scalar Power ISA mutiply, divide, and shift
226 operations at this late stage of maturity of the Power ISA is an entire
227 area of research on its own deemed unlikely to be achievable.
228
229 ## fclass and GPR-FPR moves
230
231 [[sv/fclass]] - just one instruction. With SFFS being locked down to
232 exclude VSX, and there being no desire within the nascent OpenPOWER
233 ecosystem outside of IBM to implement the VSX PackedSIMD paradigm, it
234 becomes necessary to upgrade SFFS such that it is stand-alone capable. One
235 omission based on the assumption that VSX would always be present is an
236 equivalent to `xvtstdcsp`.
237
238 Similar arguments apply to the GPR-INT move operations, proposed in
239 [[ls006]], with the opportunity taken to add rounding modes present
240 in other ISAs that Power ISA VSX PackedSIMD does not have. Javascript
241 rounding, one of the worst offenders of Computer Science, requires a
242 phenomental 35 instructions with *six branches* to emulate in Power
243 ISA! For desktop as well as Server HTML/JS back-end execution of
244 javascript this becomes an obvious priority, recognised already by ARM
245 as just one example.
246
247 ## Bitmanip LUT2/3
248
249 These LUT2/3 operations are high cost high reward. Outlined in
250 [[sv/bitmanip]], the simplest ones already exist in PackedSIMD VSX:
251 `xxeval`. The same reasoning applies as to fclass: SFFS needs to be
252 stand-alone on its own merits and should an implementor
253 choose not to implement any aspect of PackedSIMD VSX the performance
254 of their product should not be penalised for making that decision.
255
256 With Predication being such a high priority in GPUs and HPC, CR Field
257 variants of Ternary and Binary LUT instructions were considered high
258 priority, and again just like in the CRweird group the opportunity was
259 taken to work on *all* bits of a CR Field rather than just one bit as
260 is done with the existing CR operations crand, cror etc.
261
262 The other high strategic value instruction is `grevlut` (and `grevluti`
263 which can generate a remarkably large number of regular-patterned magic
264 constants). The grevlut set require of the order of 20,000 gates but
265 provide an astonishing plethora of innovative bit-permuting instructions
266 never seen in any other ISA.
267
268 The downside of all of these instructions is the extremely low XO bit
269 requirements: 2-3 bit XO due to the large immediates *and* the number of
270 operands required. The LUT3 instructions are already compacted down to
271 "Overwrite" variants. (By contrast the Float-Load-Immediate instructions
272 are a much larger XO because despite having 16-bit immediate only one
273 Register Operand is needed).
274
275 Realistically these high-value instructions should be proposed in EXT2xx
276 where their XO cost does not overwhelm EXT0xx.
277
278
279 ## (f)mv.swizzle
280
281 [[sv/mv.swizzle]] is dicey. It is a 2-in 2-out operation whose value
282 as a Scalar instruction is limited *except* if combined with `cmpi` and
283 SVP64Single Predication, whereupon the end result is the RISC-synthesis
284 of Compare-and-Swap, in two instructions.
285
286 Where this instruction comes into its full value is when Vectorised.
287 3D GPU and HPC numerical workloads astonishingly contain between 10 to 15%
288 swizzle operations: access to YYZ, XY, of an XYZW Quaternion, performing
289 balancing of ARGB pixel data. The usage is so high that 3D GPU ISAs make
290 Swizzle a first-class priority in their VLIW words. Even 64-bit Embedded
291 GPU ISAs have a staggering 24-bits dedicated to 2-operand Swizzle.
292
293 So as not to radicalise the Power ISA the Libre-SOC team decided to
294 introduce mv Swizzle operations, which can always be Macro-op fused
295 in exactly the same way that ARM SVE predicated-move extends 3-operand
296 "overwrite" opcodes to full independent 3-in 1-out.
297
298 # BMI (bitmanipulation) group.
299
300 Whilst the [[sv/vector_ops]] instructions are only two in number, in
301 reality the `bmask` instruction has a Mode field allowing it to cover
302 **24** instructions, more than have been added to any other CPUs by
303 ARM, Intel or AMD. Analyis of the BMI sets of these CPUs shows simple
304 patterns that can greatly simplify both Decode and implementation. These
305 are sufficiently commonly used, saving instruction count regularly,
306 that they justify going into EXT0xx.
307
308 The other instruction is `cprop` - Carry-Propagation - which takes
309 the P and Q from carry-propagation algorithms and generates carry
310 look-ahead. Greatly increases the efficiency of arbitrary-precision
311 integer arithmetic by combining what would otherwise be half a dozen
312 instructions into one. However it is still not a huge priority unlike
313 `bmask` so is probably best placed in EXT2xx.
314
315 ## Float-Load-Immediate
316
317 Very easily justified. As explained in [[ls002]] these always saves one
318 LD L1/2/3 D-Cache memory-lookup operation, by virtue of the Immediate
319 FP value being in the I-Cache side. It is such a high priority that
320 these instuctions are easily justifiable adding into EXT0xx, despite
321 requiring a 16-bit immediate. By designing the second-half instruction
322 as a Read-Modify-Write it saves on XO bitlength (only 5 bits), and can be
323 macro-op fused with its first-half to store a full IEEE754 FP32 immediate
324 into a register.
325
326 There is little point in putting these instructions into EXT2xx. Their
327 very benefit and inherent value *is* as 32-bit instructions, not 64-bit
328 ones. Likewise there is less value in taking up EXT1xx Enoding space
329 because EXT1xx only brings an additional 16 bits (approx) to the table,
330 and that is provided already by the second-half instuction.
331
332 Thus they qualify as both high priority and also EXT0xx candidates.
333
334 ## FPR/GPR LD/ST-PostIncrement-Update
335
336 These instruction, outlined in [[ls011]], save hugely in hot-loops.
337 Early ISAs such as PDP-8, PDP-11, which inspired the iconic Motorola
338 68000, 88100, Mitch Alsup's MyISA 66000, and can even be traced back to
339 the iconic ultra-RISC CDC 6600, all had both pre- and post- increment
340 Addressing Modes.
341
342 The reason is very simple: it is a direct recognition of the practice
343 in c to frequently utilise both `*p++` and `*++p` which itself stems
344 from common need in Computer Science algorithms.
345
346 The problem for the Power ISA is - was - that the opcode space needed
347 to support both was far too great, and the decision was made to go with
348 pre-increment, on the basis that outside the loop a "pre-subtraction"
349 may be performed.
350
351 Whilst this is a "solution" it is less than ideal, and the opportunity
352 exists now with the EXT2xx Primary Opcodes to correct this and bring
353 Power ISA up a level.
354
355 ## Shift-and-add
356
357 Shift-and-Add are proposed in [[ls004]]. They mitigate the need to add
358 LD-ST-Shift instructions which are a high-priority aspect of both x86
359 and ARM. LD-ST-Shift is normally just the one instruction: Shift-and-add
360 brings that down to two, where Power ISA presently requires three.
361 Cryptography e.g. twofish also makes use of Integer double-and-add,
362 so the value of these instructions is not limited to Effective Address
363 computation. They will also have value in Audio DSP.
364
365 Being a 10-bit XO it would be somewhat punitive to place these in EXT2xx
366 when their whole purpose and value is to reduce binary size in Address
367 offset computation, thus they are best placed in EXT0xx.
368
369
370 # Tables
371
372 The original tables are available publicly as as CSV file at
373 <https://git.libre-soc.org/?p=libreriscv.git;a=blob;f=openpower/sv/rfc/ls012/optable.csv;hb=HEAD>.
374 A python program auto-generates the tables in the following sections
375 by sorting into different useful priorities.
376
377 The key to headings and sections are as follows:
378
379 * **Area** - Target Area as described in above sections
380 * **XO Cost** - the number of bits required in the XO Field. whilst not
381 the full picture it is a good indicator as to how costly in terms
382 of Opcode Allocation a given instruction will be. Lower number is
383 a higher cost for the Power ISA's precious remaining Opcode space.
384 "PO" indicates that an entire Primary Opcode is required.
385 * **rfc** the Libre-SOC External RFC resource,
386 <https://libre-soc.org/openpower/sv/rfc/> where advance notice of
387 upcoming RFCs in development may be found.
388 *Reading advance Draft RFCs and providing feedback strongly advised*,
389 it saves time and effort for the OPF ISA Workgroup.
390 * **SVP64** - Vectoriseable (SVP64-Prefixable) - also implies that
391 SVP64Single is also permitted (required).
392 * **page** - Libre-SOC wiki page at which further information can
393 be found. Again: **advance reading strongly advised due to the
394 sheer volume of information**.
395 * **PO1** - the instruction is capable of being PO1-Prefixed
396 (given an EXT1xx Opcode Allocation). Bear in mind that this option
397 is **mutually exclusively incompatible** with Vectorisation.
398 * **group** - the Primary Opcode Group recommended for this instruction.
399 Options are EXT0xx (EXT000-EXT063), EXT1xx and EXT2xx. A third area
400 (UnVectoriseable),
401 EXT3xx, was available in an early Draft RFC but has been made "RESERVED"
402 instead. see [[sv/po9_encoding]].
403 * **regs** - a guide to register usage, to how costly Hazard Management
404 will be, in hardware:
405 - 1R: reads one GPR/FPR/SPR/CR.
406 - 1W: writes one GPR/FPR/SPR/CR.
407 - 1r: reads one CR *Field*.
408 - 1w: writes one CR *Field*
409
410 [[!inline pages="openpower/sv/rfc/ls012/areas.mdwn" raw=yes ]]
411 [[!inline pages="openpower/sv/rfc/ls012/xo_cost.mdwn" raw=yes ]]
412
413 [[!tag opf_rfc]]