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