add FP Co-Pro generator link
[libreriscv.git] / simple_v_extension.mdwn
1 # Variable-width Variable-packed SIMD / Simple-V / Parallelism Extension Proposal
2
3 Key insight: Simple-V is intended as an abstraction layer to provide
4 a consistent "API" to parallelisation of existing *and future* operations.
5 *Actual* internal hardware-level parallelism is *not* required, such
6 that Simple-V may be viewed as providing a "compact" or "consolidated"
7 means of issuing multiple near-identical arithmetic instructions to an
8 instruction queue (FIFO), pending execution.
9
10 *Actual* parallelism, if added independently of Simple-V in the form
11 of Out-of-order restructuring (including parallel ALU lanes) or VLIW
12 implementations, or SIMD, or anything else, would then benefit from
13 the uniformity of a consistent API.
14
15 **No arithmetic operations are added or required to be added.** SV is purely a parallelism API and consequentially is suitable for use even with RV32E.
16
17 * Talk slides: <http://hands.com/~lkcl/simple_v_chennai_2018.pdf>
18 * Specification: now move to its own page: [[specification]]
19
20 [[!toc ]]
21
22 # Introduction
23
24 This proposal exists so as to be able to satisfy several disparate
25 requirements: power-conscious, area-conscious, and performance-conscious
26 designs all pull an ISA and its implementation in different conflicting
27 directions, as do the specific intended uses for any given implementation.
28
29 The existing P (SIMD) proposal and the V (Vector) proposals,
30 whilst each extremely powerful in their own right and clearly desirable,
31 are also:
32
33 * Clearly independent in their origins (Cray and AndesStar v3 respectively)
34 so need work to adapt to the RISC-V ethos and paradigm
35 * Are sufficiently large so as to make adoption (and exploration for
36 analysis and review purposes) prohibitively expensive
37 * Both contain partial duplication of pre-existing RISC-V instructions
38 (an undesirable characteristic)
39 * Both have independent, incompatible and disparate methods for introducing
40 parallelism at the instruction level
41 * Both require that their respective parallelism paradigm be implemented
42 along-side and integral to their respective functionality *or not at all*.
43 * Both independently have methods for introducing parallelism that
44 could, if separated, benefit
45 *other areas of RISC-V not just DSP or Floating-point respectively*.
46
47 There are also key differences between Vectorisation and SIMD (full
48 details outlined in the Appendix), the key points being:
49
50 * SIMD has an extremely seductively compelling ease of implementation argument:
51 each operation is passed to the ALU, which is where the parallelism
52 lies. There is *negligeable* (if any) impact on the rest of the core
53 (with life instead being made hell for compiler writers and applications
54 writers due to extreme ISA proliferation).
55 * By contrast, Vectorisation has quite some complexity (for considerable
56 flexibility, reduction in opcode proliferation and much more).
57 * Vectorisation typically includes much more comprehensive memory load
58 and store schemes (unit stride, constant-stride and indexed), which
59 in turn have ramifications: virtual memory misses (TLB cache misses)
60 and even multiple page-faults... all caused by a *single instruction*,
61 yet with a clear benefit that the regularisation of LOAD/STOREs can
62 be optimised for minimal impact on caches and maximised throughput.
63 * By contrast, SIMD can use "standard" memory load/stores (32-bit aligned
64 to pages), and these load/stores have absolutely nothing to do with the
65 SIMD / ALU engine, no matter how wide the operand. Simplicity but with
66 more impact on instruction and data caches.
67
68 Overall it makes a huge amount of sense to have a means and method
69 of introducing instruction parallelism in a flexible way that provides
70 implementors with the option to choose exactly where they wish to offer
71 performance improvements and where they wish to optimise for power
72 and/or area (and if that can be offered even on a per-operation basis that
73 would provide even more flexibility).
74
75 Additionally it makes sense to *split out* the parallelism inherent within
76 each of P and V, and to see if each of P and V then, in *combination* with
77 a "best-of-both" parallelism extension, could be added on *on top* of
78 this proposal, to topologically provide the exact same functionality of
79 each of P and V. Each of P and V then can focus on providing the best
80 operations possible for their respective target areas, without being
81 hugely concerned about the actual parallelism.
82
83 Furthermore, an additional goal of this proposal is to reduce the number
84 of opcodes utilised by each of P and V as they currently stand, leveraging
85 existing RISC-V opcodes where possible, and also potentially allowing
86 P and V to make use of Compressed Instructions as a result.
87
88 # Analysis and discussion of Vector vs SIMD
89
90 There are six combined areas between the two proposals that help with
91 parallelism (increased performance, reduced power / area) without
92 over-burdening the ISA with a huge proliferation of
93 instructions:
94
95 * Fixed vs variable parallelism (fixed or variable "M" in SIMD)
96 * Implicit vs fixed instruction bit-width (integral to instruction or not)
97 * Implicit vs explicit type-conversion (compounded on bit-width)
98 * Implicit vs explicit inner loops.
99 * Single-instruction LOAD/STORE.
100 * Masks / tagging (selecting/preventing certain indexed elements from execution)
101
102 The pros and cons of each are discussed and analysed below.
103
104 ## Fixed vs variable parallelism length
105
106 In David Patterson and Andrew Waterman's analysis of SIMD and Vector
107 ISAs, the analysis comes out clearly in favour of (effectively) variable
108 length SIMD. As SIMD is a fixed width, typically 4, 8 or in extreme cases
109 16 or 32 simultaneous operations, the setup, teardown and corner-cases of SIMD
110 are extremely burdensome except for applications whose requirements
111 *specifically* match the *precise and exact* depth of the SIMD engine.
112
113 Thus, SIMD, no matter what width is chosen, is never going to be acceptable
114 for general-purpose computation, and in the context of developing a
115 general-purpose ISA, is never going to satisfy 100 percent of implementors.
116
117 To explain this further: for increased workloads over time, as the
118 performance requirements increase for new target markets, implementors
119 choose to extend the SIMD width (so as to again avoid mixing parallelism
120 into the instruction issue phases: the primary "simplicity" benefit of
121 SIMD in the first place), with the result that the entire opcode space
122 effectively doubles with each new SIMD width that's added to the ISA.
123
124 That basically leaves "variable-length vector" as the clear *general-purpose*
125 winner, at least in terms of greatly simplifying the instruction set,
126 reducing the number of instructions required for any given task, and thus
127 reducing power consumption for the same.
128
129 ## Implicit vs fixed instruction bit-width
130
131 SIMD again has a severe disadvantage here, over Vector: huge proliferation
132 of specialist instructions that target 8-bit, 16-bit, 32-bit, 64-bit, and
133 have to then have operations *for each and between each*. It gets very
134 messy, very quickly: *six* separate dimensions giving an O(N^6) instruction
135 proliferation profile.
136
137 The V-Extension on the other hand proposes to set the bit-width of
138 future instructions on a per-register basis, such that subsequent instructions
139 involving that register are *implicitly* of that particular bit-width until
140 otherwise changed or reset.
141
142 This has some extremely useful properties, without being particularly
143 burdensome to implementations, given that instruction decode already has
144 to direct the operation to a correctly-sized width ALU engine, anyway.
145
146 Not least: in places where an ISA was previously constrained (due for
147 whatever reason, including limitations of the available operand space),
148 implicit bit-width allows the meaning of certain operations to be
149 type-overloaded *without* pollution or alteration of frozen and immutable
150 instructions, in a fully backwards-compatible fashion.
151
152 ## Implicit and explicit type-conversion
153
154 The Draft 2.3 V-extension proposal has (deprecated) polymorphism to help
155 deal with over-population of instructions, such that type-casting from
156 integer (and floating point) of various sizes is automatically inferred
157 due to "type tagging" that is set with a special instruction. A register
158 will be *specifically* marked as "16-bit Floating-Point" and, if added
159 to an operand that is specifically tagged as "32-bit Integer" an implicit
160 type-conversion will take place *without* requiring that type-conversion
161 to be explicitly done with its own separate instruction.
162
163 However, implicit type-conversion is not only quite burdensome to
164 implement (explosion of inferred type-to-type conversion) but also is
165 never really going to be complete. It gets even worse when bit-widths
166 also have to be taken into consideration. Each new type results in
167 an increased O(N^2) conversion space that, as anyone who has examined
168 python's source code (which has built-in polymorphic type-conversion),
169 knows that the task is more complex than it first seems.
170
171 Overall, type-conversion is generally best to leave to explicit
172 type-conversion instructions, or in definite specific use-cases left to
173 be part of an actual instruction (DSP or FP)
174
175 ## Zero-overhead loops vs explicit loops
176
177 The initial Draft P-SIMD Proposal by Chuanhua Chang of Andes Technology
178 contains an extremely interesting feature: zero-overhead loops. This
179 proposal would basically allow an inner loop of instructions to be
180 repeated indefinitely, a fixed number of times.
181
182 Its specific advantage over explicit loops is that the pipeline in a DSP
183 can potentially be kept completely full *even in an in-order single-issue
184 implementation*. Normally, it requires a superscalar architecture and
185 out-of-order execution capabilities to "pre-process" instructions in
186 order to keep ALU pipelines 100% occupied.
187
188 By bringing that capability in, this proposal could offer a way to increase
189 pipeline activity even in simpler implementations in the one key area
190 which really matters: the inner loop.
191
192 However when looking at much more comprehensive schemes
193 "A portable specification of zero-overhead loop control hardware
194 applied to embedded processors" (ZOLC), optimising only the single
195 inner loop seems inadequate, tending to suggest that ZOLC may be
196 better off being proposed as an entirely separate Extension.
197
198 ## Single-instruction LOAD/STORE
199
200 In traditional Vector Architectures there are instructions which
201 result in multiple register-memory transfer operations resulting
202 from a single instruction. They're complicated to implement in hardware,
203 yet the benefits are a huge consistent regularisation of memory accesses
204 that can be highly optimised with respect to both actual memory and any
205 L1, L2 or other caches. In Hwacha EECS-2015-263 it is explicitly made
206 clear the consequences of getting this architecturally wrong:
207 L2 cache-thrashing at the very least.
208
209 Complications arise when Virtual Memory is involved: TLB cache misses
210 need to be dealt with, as do page faults. Some of the tradeoffs are
211 discussed in <http://people.eecs.berkeley.edu/~krste/thesis.pdf>, Section
212 4.6, and an article by Jeff Bush when faced with some of these issues
213 is particularly enlightening
214 <https://jbush001.github.io/2015/11/03/lost-in-translation.html>
215
216 Interestingly, none of this complexity is faced in SIMD architectures...
217 but then they do not get the opportunity to optimise for highly-streamlined
218 memory accesses either.
219
220 With the "bang-per-buck" ratio being so high and the indirect improvement
221 in L1 Instruction Cache usage (reduced instruction count), as well as
222 the opportunity to optimise L1 and L2 cache usage, the case for including
223 Vector LOAD/STORE is compelling.
224
225 ## Mask and Tagging (Predication)
226
227 Tagging (aka Masks aka Predication) is a pseudo-method of implementing
228 simplistic branching in a parallel fashion, by allowing execution on
229 elements of a vector to be switched on or off depending on the results
230 of prior operations in the same array position.
231
232 The reason for considering this is simple: by *definition* it
233 is not possible to perform individual parallel branches in a SIMD
234 (Single-Instruction, **Multiple**-Data) context. Branches (modifying
235 of the Program Counter) will result in *all* parallel data having
236 a different instruction executed on it: that's just the definition of
237 SIMD, and it is simply unavoidable.
238
239 So these are the ways in which conditional execution may be implemented:
240
241 * explicit compare and branch: BNE x, y -> offs would jump offs
242 instructions if x was not equal to y
243 * explicit store of tag condition: CMP x, y -> tagbit
244 * implicit (condition-code) such as ADD results in a carry, carry bit
245 implicitly (or sometimes explicitly) goes into a "tag" (mask) register
246
247 The first of these is a "normal" branch method, which is flat-out impossible
248 to parallelise without look-ahead and effectively rewriting instructions.
249 This would defeat the purpose of RISC.
250
251 The latter two are where parallelism becomes easy to do without complexity:
252 every operation is modified to be "conditionally executed" (in an explicit
253 way directly in the instruction format *or* implicitly).
254
255 RVV (Vector-Extension) proposes to have *explicit* storing of the compare
256 in a tag/mask register, and to *explicitly* have every vector operation
257 *require* that its operation be "predicated" on the bits within an
258 explicitly-named tag/mask register.
259
260 SIMD (P-Extension) has not yet published precise documentation on what its
261 schema is to be: there is however verbal indication at the time of writing
262 that:
263
264 > The "compare" instructions in the DSP/SIMD ISA proposed by Andes will
265 > be executed using the same compare ALU logic for the base ISA with some
266 > minor modifications to handle smaller data types. The function will not
267 > be duplicated.
268
269 This is an *implicit* form of predication as the base RV ISA does not have
270 condition-codes or predication. By adding a CSR it becomes possible
271 to also tag certain registers as "predicated if referenced as a destination".
272 Example:
273
274 // in future operations from now on, if r0 is the destination use r5 as
275 // the PREDICATION register
276 SET_IMPLICIT_CSRPREDICATE r0, r5
277 // store the compares in r5 as the PREDICATION register
278 CMPEQ8 r5, r1, r2
279 // r0 is used here. ah ha! that means it's predicated using r5!
280 ADD8 r0, r1, r3
281
282 With enough registers (and in RISC-V there are enough registers) some fairly
283 complex predication can be set up and yet still execute without significant
284 stalling, even in a simple non-superscalar architecture.
285
286 (For details on how Branch Instructions would be retro-fitted to indirectly
287 predicated equivalents, see Appendix)
288
289 ## Conclusions
290
291 In the above sections the five different ways where parallel instruction
292 execution has closely and loosely inter-related implications for the ISA and
293 for implementors, were outlined. The pluses and minuses came out as
294 follows:
295
296 * Fixed vs variable parallelism: <b>variable</b>
297 * Implicit (indirect) vs fixed (integral) instruction bit-width: <b>indirect</b>
298 * Implicit vs explicit type-conversion: <b>explicit</b>
299 * Implicit vs explicit inner loops: <b>implicit but best done separately</b>
300 * Single-instruction Vector LOAD/STORE: <b>Complex but highly beneficial</b>
301 * Tag or no-tag: <b>Complex but highly beneficial</b>
302
303 In particular:
304
305 * variable-length vectors came out on top because of the high setup, teardown
306 and corner-cases associated with the fixed width of SIMD.
307 * Implicit bit-width helps to extend the ISA to escape from
308 former limitations and restrictions (in a backwards-compatible fashion),
309 whilst also leaving implementors free to simmplify implementations
310 by using actual explicit internal parallelism.
311 * Implicit (zero-overhead) loops provide a means to keep pipelines
312 potentially 100% occupied in a single-issue in-order implementation
313 i.e. *without* requiring a super-scalar or out-of-order architecture,
314 but doing a proper, full job (ZOLC) is an entirely different matter.
315
316 Constructing a SIMD/Simple-Vector proposal based around four of these six
317 requirements would therefore seem to be a logical thing to do.
318
319 # Note on implementation of parallelism
320
321 One extremely important aspect of this proposal is to respect and support
322 implementors desire to focus on power, area or performance. In that regard,
323 it is proposed that implementors be free to choose whether to implement
324 the Vector (or variable-width SIMD) parallelism as sequential operations
325 with a single ALU, fully parallel (if practical) with multiple ALUs, or
326 a hybrid combination of both.
327
328 In Broadcom's Videocore-IV, they chose hybrid, and called it "Virtual
329 Parallelism". They achieve a 16-way SIMD at an **instruction** level
330 by providing a combination of a 4-way parallel ALU *and* an externally
331 transparent loop that feeds 4 sequential sets of data into each of the
332 4 ALUs.
333
334 Also in the same core, it is worth noting that particularly uncommon
335 but essential operations (Reciprocal-Square-Root for example) are
336 *not* part of the 4-way parallel ALU but instead have a *single* ALU.
337 Under the proposed Vector (varible-width SIMD) implementors would
338 be free to do precisely that: i.e. free to choose *on a per operation
339 basis* whether and how much "Virtual Parallelism" to deploy.
340
341 It is absolutely critical to note that it is proposed that such choices MUST
342 be **entirely transparent** to the end-user and the compiler. Whilst
343 a Vector (varible-width SIMD) may not precisely match the width of the
344 parallelism within the implementation, the end-user **should not care**
345 and in this way the performance benefits are gained but the ISA remains
346 straightforward. All that happens at the end of an instruction run is: some
347 parallel units (if there are any) would remain offline, completely
348 transparently to the ISA, the program, and the compiler.
349
350 To make that clear: should an implementor choose a particularly wide
351 SIMD-style ALU, each parallel unit *must* have predication so that
352 the parallel SIMD ALU may emulate variable-length parallel operations.
353 Thus the "SIMD considered harmful" trap of having huge complexity and extra
354 instructions to deal with corner-cases is thus avoided, and implementors
355 get to choose precisely where to focus and target the benefits of their
356 implementation efforts, without "extra baggage".
357
358 In addition, implementors will be free to choose whether to provide an
359 absolute bare minimum level of compliance with the "API" (software-traps
360 when vectorisation is detected), all the way up to full supercomputing
361 level all-hardware parallelism. Options are covered in the Appendix.
362
363
364 ### FMV, FNEG and FABS Instructions
365
366 These are identical in form to C.MV, except covering floating-point
367 register copying. The same double-predication rules also apply.
368 However when elwidth is not set to default the instruction is implicitly
369 and automatic converted to a (vectorised) floating-point type conversion
370 operation of the appropriate size covering the source and destination
371 register bitwidths.
372
373 (Note that FMV, FNEG and FABS are all actually pseudo-instructions)
374
375 ### FVCT Instructions
376
377 These are again identical in form to C.MV, except that they cover
378 floating-point to integer and integer to floating-point. When element
379 width in each vector is set to default, the instructions behave exactly
380 as they are defined for standard RV (scalar) operations, except vectorised
381 in exactly the same fashion as outlined in C.MV.
382
383 However when the source or destination element width is not set to default,
384 the opcode's explicit element widths are *over-ridden* to new definitions,
385 and the opcode's element width is taken as indicative of the SIMD width
386 (if applicable i.e. if packed SIMD is requested) instead.
387
388 For example FCVT.S.L would normally be used to convert a 64-bit
389 integer in register rs1 to a 64-bit floating-point number in rd.
390 If however the source rs1 is set to be a vector, where elwidth is set to
391 default/2 and "packed SIMD" is enabled, then the first 32 bits of
392 rs1 are converted to a floating-point number to be stored in rd's
393 first element and the higher 32-bits *also* converted to floating-point
394 and stored in the second. The 32 bit size comes from the fact that
395 FCVT.S.L's integer width is 64 bit, and with elwidth on rs1 set to
396 divide that by two it means that rs1 element width is to be taken as 32.
397
398 Similar rules apply to the destination register.
399
400 # Exceptions
401
402 > What does an ADD of two different-sized vectors do in simple-V?
403
404 * if the two source operands are not the same, throw an exception.
405 * if the destination operand is also a vector, and the source is longer
406 than the destination, throw an exception.
407
408 > And what about instructions like JALR? 
409 > What does jumping to a vector do?
410
411 * Throw an exception. Whether that actually results in spawning threads
412 as part of the trap-handling remains to be seen.
413
414 # Under consideration <a name="issues"></a>
415
416 From the Chennai 2018 slides the following issues were raised.
417 Efforts to analyse and answer these questions are below.
418
419 * Should future extra bank be included now?
420 * How many Register and Predication CSRs should there be?
421 (and how many in RV32E)
422 * How many in M-Mode (for doing context-switch)?
423 * Should use of registers be allowed to "wrap" (x30 x31 x1 x2)?
424 * Can CLIP be done as a CSR (mode, like elwidth)
425 * SIMD saturation (etc.) also set as a mode?
426 * Include src1/src2 predication on Comparison Ops?
427 (same arrangement as C.MV, with same flexibility/power)
428 * 8/16-bit ops is it worthwhile adding a "start offset"?
429 (a bit like misaligned addressing... for registers)
430 or just use predication to skip start?
431
432 ## Future (extra) bank be included (made mandatory)
433
434 The implications of expanding the *standard* register file from
435 32 entries per bank to 64 per bank is quite an extensive architectural
436 change. Also it has implications for context-switching.
437
438 Therefore, on balance, it is not recommended and certainly should
439 not be made a *mandatory* requirement for the use of SV. SV's design
440 ethos is to be minimally-disruptive for implementors to shoe-horn
441 into an existing design.
442
443 ## How large should the Register and Predication CSR key-value stores be?
444
445 This is something that definitely needs actual evaluation and for
446 code to be run and the results analysed. At the time of writing
447 (12jul2018) that is too early to tell. An approximate best-guess
448 however would be 16 entries.
449
450 RV32E however is a special case, given that it is highly unlikely
451 (but not outside the realm of possibility) that it would be used
452 for performance reasons but instead for reducing instruction count.
453 The number of CSR entries therefore has to be considered extremely
454 carefully.
455
456 ## How many CSR entries in M-Mode or S-Mode (for context-switching)?
457
458 The minimum required CSR entries would be 1 for each register-bank:
459 one for integer and one for floating-point. However, as shown
460 in the "Context Switch Example" section, for optimal efficiency
461 (minimal instructions in a low-latency situation) the CSRs for
462 the context-switch should be set up *and left alone*.
463
464 This means that it is not really a good idea to touch the CSRs
465 used for context-switching in the M-Mode (or S-Mode) trap, so
466 if there is ever demonstrated a need for vectors then there would
467 need to be *at least* one more free. However just one does not make
468 much sense (as it one only covers scalar-vector ops) so it is more
469 likely that at least two extra would be needed.
470
471 This *in addition* - in the RV32E case - if an RV32E implementation
472 happens also to support U/S/M modes. This would be considered quite
473 rare but not outside of the realm of possibility.
474
475 Conclusion: all needs careful analysis and future work.
476
477 ## Should use of registers be allowed to "wrap" (x30 x31 x1 x2)?
478
479 On balance it's a neat idea however it does seem to be one where the
480 benefits are not really clear. It would however obviate the need for
481 an exception to be raised if the VL runs out of registers to put
482 things in (gets to x31, tries a non-existent x32 and fails), however
483 the "fly in the ointment" is that x0 is hard-coded to "zero". The
484 increment therefore would need to be double-stepped to skip over x0.
485 Some microarchitectures could run into difficulties (SIMD-like ones
486 in particular) so it needs a lot more thought.
487
488 ## Can CLIP be done as a CSR (mode, like elwidth)
489
490 RVV appears to be going this way. At the time of writing (12jun2018)
491 it's noted that in V2.3-Draft V0.4 RVV Chapter, RVV intends to do
492 clip by way of exactly this method: setting a "clip mode" in a CSR.
493
494 No details are given however the most sensible thing to have would be
495 to extend the 16-bit Register CSR table to 24-bit (or 32-bit) and have
496 extra bits specifying the type of clipping to be carried out, on
497 a per-register basis. Other bits may be used for other purposes
498 (see SIMD saturation below)
499
500 ## SIMD saturation (etc.) also set as a mode?
501
502 Similar to "CLIP" as an extension to the CSR key-value store, "saturate"
503 may also need extra details (what the saturation maximum is for example).
504
505 ## Include src1/src2 predication on Comparison Ops?
506
507 In the C.MV (and other ops - see "C.MV Instruction"), the decision
508 was taken, unlike in ADD (etc.) which are 3-operand ops, to use
509 *both* the src *and* dest predication masks to give an extremely
510 powerful and flexible instruction that covers a huge number of
511 "traditional" vector opcodes.
512
513 The natural question therefore to ask is: where else could this
514 flexibility be deployed? What about comparison operations?
515
516 Unfortunately, C.MV is basically "regs[dest] = regs[src]" whilst
517 predicated comparison operations are actually a *three* operand
518 instruction:
519
520 regs[pred] |= 1<< (cmp(regs[src1], regs[src2]) ? 1 : 0)
521
522 Therefore at first glance it does not make sense to use src1 and src2
523 predication masks, as it breaks the rule of 3-operand instructions
524 to use the *destination* predication register.
525
526 In this case however, the destination *is* a predication register
527 as opposed to being a predication mask that is applied *to* the
528 (vectorised) operation, element-at-a-time on src1 and src2.
529
530 Thus the question is directly inter-related to whether the modification
531 of the predication mask should *itself* be predicated.
532
533 It is quite complex, in other words, and needs careful consideration.
534
535 ## 8/16-bit ops is it worthwhile adding a "start offset"?
536
537 The idea here is to make it possible, particularly in a "Packed SIMD"
538 case, to be able to avoid doing unaligned Load/Store operations
539 by specifying that operations, instead of being carried out
540 element-for-element, are offset by a fixed amount *even* in 8 and 16-bit
541 element Packed SIMD cases.
542
543 For example rather than take 2 32-bit registers divided into 4 8-bit
544 elements and have them ADDed element-for-element as follows:
545
546 r3[0] = add r4[0], r6[0]
547 r3[1] = add r4[1], r6[1]
548 r3[2] = add r4[2], r6[2]
549 r3[3] = add r4[3], r6[3]
550
551 an offset of 1 would result in four operations as follows, instead:
552
553 r3[0] = add r4[1], r6[0]
554 r3[1] = add r4[2], r6[1]
555 r3[2] = add r4[3], r6[2]
556 r3[3] = add r5[0], r6[3]
557
558 In non-packed-SIMD mode there is no benefit at all, as a vector may
559 be created using a different CSR that has the offset built-in. So this
560 leaves just the packed-SIMD case to consider.
561
562 Two ways in which this could be implemented / emulated (without special
563 hardware):
564
565 * bit-manipulation that shuffles the data along by one byte (or one word)
566 either prior to or as part of the operation requiring the offset.
567 * just use an unaligned Load/Store sequence, even if there are performance
568 penalties for doing so.
569
570 The question then is whether the performance hit is worth the extra hardware
571 involving byte-shuffling/shifting the data by an arbitrary offset. On
572 balance given that there are two reasonable instruction-based options, the
573 hardware-offset option should be left out for the initial version of SV,
574 with the option to consider it in an "advanced" version of the specification.
575
576 # Impementing V on top of Simple-V
577
578 With Simple-V converting the original RVV draft concept-for-concept
579 from explicit opcodes to implicit overloading of existing RV Standard
580 Extensions, certain features were (deliberately) excluded that need
581 to be added back in for RVV to reach its full potential. This is
582 made slightly complicated by the fact that RVV itself has two
583 levels: Base and reserved future functionality.
584
585 * Representation Encoding is entirely left out of Simple-V in favour of
586 implicitly taking the exact (explicit) meaning from RV Standard Extensions.
587 * VCLIP and VCLIPI do not have corresponding RV Standard Extension
588 opcodes (and are the only such operations).
589 * Extended Element bitwidths (1 through to 24576 bits) were left out
590 of Simple-V as, again, there is no corresponding RV Standard Extension
591 that covers anything even below 32-bit operands.
592 * Polymorphism was entirely left out of Simple-V due to the inherent
593 complexity of automatic type-conversion.
594 * Vector Register files were specifically left out of Simple-V in favour
595 of fitting on top of the integer and floating-point files. An
596 "RVV re-retro-fit" needs to be able to mark (implicitly marked)
597 registers as being actually in a separate *vector* register file.
598 * Fortunately in RVV (Draft 0.4, V2.3-Draft), the "base" vector
599 register file size is 5 bits (32 registers), whilst the "Extended"
600 variant of RVV specifies 8 bits (256 registers) and has yet to
601 be published.
602 * One big difference: Sections 17.12 and 17.17, there are only two possible
603 predication registers in RVV "Base". Through the "indirect" method,
604 Simple-V provides a key-value CSR table that allows (arbitrarily)
605 up to 16 (TBD) of either the floating-point or integer registers to
606 be marked as "predicated" (key), and if so, which integer register to
607 use as the predication mask (value).
608
609 **TODO**
610
611 # Implementing P (renamed to DSP) on top of Simple-V
612
613 * Implementors indicate chosen bitwidth support in Vector-bitwidth CSR
614 (caveat: anything not specified drops through to software-emulation / traps)
615 * TODO
616
617 # Appendix
618
619 ## V-Extension to Simple-V Comparative Analysis
620
621 This section has been moved to its own page [[v_comparative_analysis]]
622
623 ## P-Ext ISA
624
625 This section has been moved to its own page [[p_comparative_analysis]]
626
627 ## Comparison of "Traditional" SIMD, Alt-RVP, Simple-V and RVV Proposals <a name="parallelism_comparisons"></a>
628
629 This section compares the various parallelism proposals as they stand,
630 including traditional SIMD, in terms of features, ease of implementation,
631 complexity, flexibility, and die area.
632
633 ### [[harmonised_rvv_rvp]]
634
635 This is an interesting proposal under development to retro-fit the AndesStar
636 P-Ext into V-Ext.
637
638 ### [[alt_rvp]]
639
640 Primary benefit of Alt-RVP is the simplicity with which parallelism
641 may be introduced (effective multiplication of regfiles and associated ALUs).
642
643 * plus: the simplicity of the lanes (combined with the regularity of
644 allocating identical opcodes multiple independent registers) meaning
645 that SRAM or 2R1W can be used for entire regfile (potentially).
646 * minus: a more complex instruction set where the parallelism is much
647 more explicitly directly specified in the instruction and
648 * minus: if you *don't* have an explicit instruction (opcode) and you
649 need one, the only place it can be added is... in the vector unit and
650 * minus: opcode functions (and associated ALUs) duplicated in Alt-RVP are
651 not useable or accessible in other Extensions.
652 * plus-and-minus: Lanes may be utilised for high-speed context-switching
653 but with the down-side that they're an all-or-nothing part of the Extension.
654 No Alt-RVP: no fast register-bank switching.
655 * plus: Lane-switching would mean that complex operations not suited to
656 parallelisation can be carried out, followed by further parallel Lane-based
657 work, without moving register contents down to memory (and back)
658 * minus: Access to registers across multiple lanes is challenging. "Solution"
659 is to drop data into memory and immediately back in again (like MMX).
660
661 ### Simple-V
662
663 Primary benefit of Simple-V is the OO abstraction of parallel principles
664 from actual (internal) parallel hardware. It's an API in effect that's
665 designed to be slotted in to an existing implementation (just after
666 instruction decode) with minimum disruption and effort.
667
668 * minus: the complexity (if full parallelism is to be exploited)
669 of having to use register renames, OoO, VLIW, register file cacheing,
670 all of which has been done before but is a pain
671 * plus: transparent re-use of existing opcodes as-is just indirectly
672 saying "this register's now a vector" which
673 * plus: means that future instructions also get to be inherently
674 parallelised because there's no "separate vector opcodes"
675 * plus: Compressed instructions may also be (indirectly) parallelised
676 * minus: the indirect nature of Simple-V means that setup (setting
677 a CSR register to indicate vector length, a separate one to indicate
678 that it is a predicate register and so on) means a little more setup
679 time than Alt-RVP or RVV's "direct and within the (longer) instruction"
680 approach.
681 * plus: shared register file meaning that, like Alt-RVP, complex
682 operations not suited to parallelisation may be carried out interleaved
683 between parallelised instructions *without* requiring data to be dropped
684 down to memory and back (into a separate vectorised register engine).
685 * plus-and-maybe-minus: re-use of integer and floating-point 32-wide register
686 files means that huge parallel workloads would use up considerable
687 chunks of the register file. However in the case of RV64 and 32-bit
688 operations, that effectively means 64 slots are available for parallel
689 operations.
690 * plus: inherent parallelism (actual parallel ALUs) doesn't actually need to
691 be added, yet the instruction opcodes remain unchanged (and still appear
692 to be parallel). consistent "API" regardless of actual internal parallelism:
693 even an in-order single-issue implementation with a single ALU would still
694 appear to have parallel vectoristion.
695 * hard-to-judge: if actual inherent underlying ALU parallelism is added it's
696 hard to say if there would be pluses or minuses (on die area). At worse it
697 would be "no worse" than existing register renaming, OoO, VLIW and register
698 file cacheing schemes.
699
700 ### RVV (as it stands, Draft 0.4 Section 17, RISC-V ISA V2.3-Draft)
701
702 RVV is extremely well-designed and has some amazing features, including
703 2D reorganisation of memory through LOAD/STORE "strides".
704
705 * plus: regular predictable workload means that implementations may
706 streamline effects on L1/L2 Cache.
707 * plus: regular and clear parallel workload also means that lanes
708 (similar to Alt-RVP) may be used as an implementation detail,
709 using either SRAM or 2R1W registers.
710 * plus: separate engine with no impact on the rest of an implementation
711 * minus: separate *complex* engine with no RTL (ALUs, Pipeline stages) reuse
712 really feasible.
713 * minus: no ISA abstraction or re-use either: additions to other Extensions
714 do not gain parallelism, resulting in prolific duplication of functionality
715 inside RVV *and out*.
716 * minus: when operations require a different approach (scalar operations
717 using the standard integer or FP regfile) an entire vector must be
718 transferred out to memory, into standard regfiles, then back to memory,
719 then back to the vector unit, this to occur potentially multiple times.
720 * minus: will never fit into Compressed instruction space (as-is. May
721 be able to do so if "indirect" features of Simple-V are partially adopted).
722 * plus-and-slight-minus: extended variants may address up to 256
723 vectorised registers (requires 48/64-bit opcodes to do it).
724 * minus-and-partial-plus: separate engine plus complexity increases
725 implementation time and die area, meaning that adoption is likely only
726 to be in high-performance specialist supercomputing (where it will
727 be absolutely superb).
728
729 ### Traditional SIMD
730
731 The only really good things about SIMD are how easy it is to implement and
732 get good performance. Unfortunately that makes it quite seductive...
733
734 * plus: really straightforward, ALU basically does several packed operations
735 at once. Parallelism is inherent at the ALU, making the addition of
736 SIMD-style parallelism an easy decision that has zero significant impact
737 on the rest of any given architectural design and layout.
738 * plus (continuation): SIMD in simple in-order single-issue designs can
739 therefore result in superb throughput, easily achieved even with a very
740 simple execution model.
741 * minus: ridiculously complex setup and corner-cases that disproportionately
742 increase instruction count on what would otherwise be a "simple loop",
743 should the number of elements in an array not happen to exactly match
744 the SIMD group width.
745 * minus: getting data usefully out of registers (if separate regfiles
746 are used) means outputting to memory and back.
747 * minus: quite a lot of supplementary instructions for bit-level manipulation
748 are needed in order to efficiently extract (or prepare) SIMD operands.
749 * minus: MASSIVE proliferation of ISA both in terms of opcodes in one
750 dimension and parallelism (width): an at least O(N^2) and quite probably
751 O(N^3) ISA proliferation that often results in several thousand
752 separate instructions. all requiring separate and distinct corner-case
753 algorithms!
754 * minus: EVEN BIGGER proliferation of SIMD ISA if the functionality of
755 8, 16, 32 or 64-bit reordering is built-in to the SIMD instruction.
756 For example: add (high|low) 16-bits of r1 to (low|high) of r2 requires
757 four separate and distinct instructions: one for (r1:low r2:high),
758 one for (r1:high r2:low), one for (r1:high r2:high) and one for
759 (r1:low r2:low) *per function*.
760 * minus: EVEN BIGGER proliferation of SIMD ISA if there is a mismatch
761 between operand and result bit-widths. In combination with high/low
762 proliferation the situation is made even worse.
763 * minor-saving-grace: some implementations *may* have predication masks
764 that allow control over individual elements within the SIMD block.
765
766 ## Comparison *to* Traditional SIMD: Alt-RVP, Simple-V and RVV Proposals <a name="simd_comparison"></a>
767
768 This section compares the various parallelism proposals as they stand,
769 *against* traditional SIMD as opposed to *alongside* SIMD. In other words,
770 the question is asked "How can each of the proposals effectively implement
771 (or replace) SIMD, and how effective would they be"?
772
773 ### [[alt_rvp]]
774
775 * Alt-RVP would not actually replace SIMD but would augment it: just as with
776 a SIMD architecture where the ALU becomes responsible for the parallelism,
777 Alt-RVP ALUs would likewise be so responsible... with *additional*
778 (lane-based) parallelism on top.
779 * Thus at least some of the downsides of SIMD ISA O(N^5) proliferation by
780 at least one dimension are avoided (architectural upgrades introducing
781 128-bit then 256-bit then 512-bit variants of the exact same 64-bit
782 SIMD block)
783 * Thus, unfortunately, Alt-RVP would suffer the same inherent proliferation
784 of instructions as SIMD, albeit not quite as badly (due to Lanes).
785 * In the same discussion for Alt-RVP, an additional proposal was made to
786 be able to subdivide the bits of each register lane (columns) down into
787 arbitrary bit-lengths (RGB 565 for example).
788 * A recommendation was given instead to make the subdivisions down to 32-bit,
789 16-bit or even 8-bit, effectively dividing the registerfile into
790 Lane0(H), Lane0(L), Lane1(H) ... LaneN(L) or further. If inter-lane
791 "swapping" instructions were then introduced, some of the disadvantages
792 of SIMD could be mitigated.
793
794 ### RVV
795
796 * RVV is designed to replace SIMD with a better paradigm: arbitrary-length
797 parallelism.
798 * However whilst SIMD is usually designed for single-issue in-order simple
799 DSPs with a focus on Multimedia (Audio, Video and Image processing),
800 RVV's primary focus appears to be on Supercomputing: optimisation of
801 mathematical operations that fit into the OpenCL space.
802 * Adding functions (operations) that would normally fit (in parallel)
803 into a SIMD instruction requires an equivalent to be added to the
804 RVV Extension, if one does not exist. Given the specialist nature of
805 some SIMD instructions (8-bit or 16-bit saturated or halving add),
806 this possibility seems extremely unlikely to occur, even if the
807 implementation overhead of RVV were acceptable (compared to
808 normal SIMD/DSP-style single-issue in-order simplicity).
809
810 ### Simple-V
811
812 * Simple-V borrows hugely from RVV as it is intended to be easy to
813 topologically transplant every single instruction from RVV (as
814 designed) into Simple-V equivalents, with *zero loss of functionality
815 or capability*.
816 * With the "parallelism" abstracted out, a hypothetical SIMD-less "DSP"
817 Extension which contained the basic primitives (non-parallelised
818 8, 16 or 32-bit SIMD operations) inherently *become* parallel,
819 automatically.
820 * Additionally, standard operations (ADD, MUL) that would normally have
821 to have special SIMD-parallel opcodes added need no longer have *any*
822 of the length-dependent variants (2of 32-bit ADDs in a 64-bit register,
823 4of 32-bit ADDs in a 128-bit register) because Simple-V takes the
824 *standard* RV opcodes (present and future) and automatically parallelises
825 them.
826 * By inheriting the RVV feature of arbitrary vector-length, then just as
827 with RVV the corner-cases and ISA proliferation of SIMD is avoided.
828 * Whilst not entirely finalised, registers are expected to be
829 capable of being subdivided down to an implementor-chosen bitwidth
830 in the underlying hardware (r1 becomes r1[31..24] r1[23..16] r1[15..8]
831 and r1[7..0], or just r1[31..16] r1[15..0]) where implementors can
832 choose to have separate independent 8-bit ALUs or dual-SIMD 16-bit
833 ALUs that perform twin 8-bit operations as they see fit, or anything
834 else including no subdivisions at all.
835 * Even though implementors have that choice even to have full 64-bit
836 (with RV64) SIMD, they *must* provide predication that transparently
837 switches off appropriate units on the last loop, thus neatly fitting
838 underlying SIMD ALU implementations *into* the arbitrary vector-length
839 RVV paradigm, keeping the uniform consistent API that is a key strategic
840 feature of Simple-V.
841 * With Simple-V fitting into the standard register files, certain classes
842 of SIMD operations such as High/Low arithmetic (r1[31..16] + r2[15..0])
843 can be done by applying *Parallelised* Bit-manipulation operations
844 followed by parallelised *straight* versions of element-to-element
845 arithmetic operations, even if the bit-manipulation operations require
846 changing the bitwidth of the "vectors" to do so. Predication can
847 be utilised to skip high words (or low words) in source or destination.
848 * In essence, the key downside of SIMD - massive duplication of
849 identical functions over time as an architecture evolves from 32-bit
850 wide SIMD all the way up to 512-bit, is avoided with Simple-V, through
851 vector-style parallelism being dropped on top of 8-bit or 16-bit
852 operations, all the while keeping a consistent ISA-level "API" irrespective
853 of implementor design choices (or indeed actual implementations).
854
855 ### Example Instruction translation: <a name="example_translation"></a>
856
857 Instructions "ADD r7 r4 r4" would result in three instructions being
858 generated and placed into the FIFO. r7 and r4 are marked as "vectorised":
859
860 * ADD r7 r4 r4
861 * ADD r8 r5 r5
862 * ADD r9 r6 r6
863
864 Instructions "ADD r7 r4 r1" would result in three instructions being
865 generated and placed into the FIFO. r7 and r1 are marked as "vectorised"
866 whilst r4 is not:
867
868 * ADD r7 r4 r1
869 * ADD r8 r4 r2
870 * ADD r9 r4 r3
871
872 ## Example of vector / vector, vector / scalar, scalar / scalar => vector add
873
874 function op_add(rd, rs1, rs2) # add not VADD!
875  int i, id=0, irs1=0, irs2=0;
876  rd = int_vec[rd ].isvector ? int_vec[rd ].regidx : rd;
877  rs1 = int_vec[rs1].isvector ? int_vec[rs1].regidx : rs1;
878  rs2 = int_vec[rs2].isvector ? int_vec[rs2].regidx : rs2;
879  predval = get_pred_val(FALSE, rd);
880  for (i = 0; i < VL; i++)
881 if (predval & 1<<i) # predication uses intregs
882    ireg[rd+id] <= ireg[rs1+irs1] + ireg[rs2+irs2];
883 if (int_vec[rd ].isvector)  { id += 1; }
884 if (int_vec[rs1].isvector)  { irs1 += 1; }
885 if (int_vec[rs2].isvector)  { irs2 += 1; }
886
887 ## Retro-fitting Predication into branch-explicit ISA <a name="predication_retrofit"></a>
888
889 One of the goals of this parallelism proposal is to avoid instruction
890 duplication. However, with the base ISA having been designed explictly
891 to *avoid* condition-codes entirely, shoe-horning predication into it
892 bcomes quite challenging.
893
894 However what if all branch instructions, if referencing a vectorised
895 register, were instead given *completely new analogous meanings* that
896 resulted in a parallel bit-wise predication register being set? This
897 would have to be done for both C.BEQZ and C.BNEZ, as well as BEQ, BNE,
898 BLT and BGE.
899
900 We might imagine that FEQ, FLT and FLT would also need to be converted,
901 however these are effectively *already* in the precise form needed and
902 do not need to be converted *at all*! The difference is that FEQ, FLT
903 and FLE *specifically* write a 1 to an integer register if the condition
904 holds, and 0 if not. All that needs to be done here is to say, "if
905 the integer register is tagged with a bit that says it is a predication
906 register, the **bit** in the integer register is set based on the
907 current vector index" instead.
908
909 There is, in the standard Conditional Branch instruction, more than
910 adequate space to interpret it in a similar fashion:
911
912 [[!table data="""
913 31 |30 ..... 25 |24..20|19..15| 14...12| 11.....8 | 7 | 6....0 |
914 imm[12] | imm[10:5] |rs2 | rs1 | funct3 | imm[4:1] | imm[11] | opcode |
915 1 | 6 | 5 | 5 | 3 | 4 | 1 | 7 |
916 offset[12,10:5] || src2 | src1 | BEQ | offset[11,4:1] || BRANCH |
917 """]]
918
919 This would become:
920
921 [[!table data="""
922 31 | 30 .. 25 |24 ... 20 | 19 15 | 14 12 | 11 .. 8 | 7 | 6 ... 0 |
923 imm[12] | imm[10:5]| rs2 | rs1 | funct3 | imm[4:1] | imm[11] | opcode |
924 1 | 6 | 5 | 5 | 3 | 4 | 1 | 7 |
925 reserved || src2 | src1 | BEQ | predicate rs3 || BRANCH |
926 """]]
927
928 Similarly the C.BEQZ and C.BNEZ instruction format may be retro-fitted,
929 with the interesting side-effect that there is space within what is presently
930 the "immediate offset" field to reinterpret that to add in not only a bit
931 field to distinguish between floating-point compare and integer compare,
932 not only to add in a second source register, but also use some of the bits as
933 a predication target as well.
934
935 [[!table data="""
936 15..13 | 12 ....... 10 | 9...7 | 6 ......... 2 | 1 .. 0 |
937 funct3 | imm | rs10 | imm | op |
938 3 | 3 | 3 | 5 | 2 |
939 C.BEQZ | offset[8,4:3] | src | offset[7:6,2:1,5] | C1 |
940 """]]
941
942 Now uses the CS format:
943
944 [[!table data="""
945 15..13 | 12 . 10 | 9 .. 7 | 6 .. 5 | 4..2 | 1 .. 0 |
946 funct3 | imm | rs10 | imm | | op |
947 3 | 3 | 3 | 2 | 3 | 2 |
948 C.BEQZ | pred rs3 | src1 | I/F B | src2 | C1 |
949 """]]
950
951 Bit 6 would be decoded as "operation refers to Integer or Float" including
952 interpreting src1 and src2 accordingly as outlined in Table 12.2 of the
953 "C" Standard, version 2.0,
954 whilst Bit 5 would allow the operation to be extended, in combination with
955 funct3 = 110 or 111: a combination of four distinct (predicated) comparison
956 operators. In both floating-point and integer cases those could be
957 EQ/NEQ/LT/LE (with GT and GE being synthesised by inverting src1 and src2).
958
959 ## Register reordering <a name="register_reordering"></a>
960
961 ### Register File
962
963 | Reg Num | Bits |
964 | ------- | ---- |
965 | r0 | (32..0) |
966 | r1 | (32..0) |
967 | r2 | (32..0) |
968 | r3 | (32..0) |
969 | r4 | (32..0) |
970 | r5 | (32..0) |
971 | r6 | (32..0) |
972 | r7 | (32..0) |
973 | .. | (32..0) |
974 | r31| (32..0) |
975
976 ### Vectorised CSR
977
978 May not be an actual CSR: may be generated from Vector Length CSR:
979 single-bit is less burdensome on instruction decode phase.
980
981 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
982 | - | - | - | - | - | - | - | - |
983 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 |
984
985 ### Vector Length CSR
986
987 | Reg Num | (3..0) |
988 | ------- | ---- |
989 | r0 | 2 |
990 | r1 | 0 |
991 | r2 | 1 |
992 | r3 | 1 |
993 | r4 | 3 |
994 | r5 | 0 |
995 | r6 | 0 |
996 | r7 | 1 |
997
998 ### Virtual Register Reordering
999
1000 This example assumes the above Vector Length CSR table
1001
1002 | Reg Num | Bits (0) | Bits (1) | Bits (2) |
1003 | ------- | -------- | -------- | -------- |
1004 | r0 | (32..0) | (32..0) |
1005 | r2 | (32..0) |
1006 | r3 | (32..0) |
1007 | r4 | (32..0) | (32..0) | (32..0) |
1008 | r7 | (32..0) |
1009
1010 ### Bitwidth Virtual Register Reordering
1011
1012 This example goes a little further and illustrates the effect that a
1013 bitwidth CSR has been set on a register. Preconditions:
1014
1015 * RV32 assumed
1016 * CSRintbitwidth[2] = 010 # integer r2 is 16-bit
1017 * CSRintvlength[2] = 3 # integer r2 is a vector of length 3
1018 * vsetl rs1, 5 # set the vector length to 5
1019
1020 This is interpreted as follows:
1021
1022 * Given that the context is RV32, ELEN=32.
1023 * With ELEN=32 and bitwidth=16, the number of SIMD elements is 2
1024 * Therefore the actual vector length is up to *six* elements
1025 * However vsetl sets a length 5 therefore the last "element" is skipped
1026
1027 So when using an operation that uses r2 as a source (or destination)
1028 the operation is carried out as follows:
1029
1030 * 16-bit operation on r2(15..0) - vector element index 0
1031 * 16-bit operation on r2(31..16) - vector element index 1
1032 * 16-bit operation on r3(15..0) - vector element index 2
1033 * 16-bit operation on r3(31..16) - vector element index 3
1034 * 16-bit operation on r4(15..0) - vector element index 4
1035 * 16-bit operation on r4(31..16) **NOT** carried out due to length being 5
1036
1037 Predication has been left out of the above example for simplicity, however
1038 predication is ANDed with the latter stages (vsetl not equal to maximum
1039 capacity).
1040
1041 Note also that it is entirely an implementor's choice as to whether to have
1042 actual separate ALUs down to the minimum bitwidth, or whether to have something
1043 more akin to traditional SIMD (at any level of subdivision: 8-bit SIMD
1044 operations carried out 32-bits at a time is perfectly acceptable, as is
1045 8-bit SIMD operations carried out 16-bits at a time requiring two ALUs).
1046 Regardless of the internal parallelism choice, *predication must
1047 still be respected*, making Simple-V in effect the "consistent public API".
1048
1049 vew may be one of the following (giving a table "bytestable", used below):
1050
1051 | vew | bitwidth | bytestable |
1052 | --- | -------- | ---------- |
1053 | 000 | default | XLEN/8 |
1054 | 001 | 8 | 1 |
1055 | 010 | 16 | 2 |
1056 | 011 | 32 | 4 |
1057 | 100 | 64 | 8 |
1058 | 101 | 128 | 16 |
1059 | 110 | rsvd | rsvd |
1060 | 111 | rsvd | rsvd |
1061
1062 Pseudocode for vector length taking CSR SIMD-bitwidth into account:
1063
1064 vew = CSRbitwidth[rs1]
1065 if (vew == 0)
1066 bytesperreg = (XLEN/8) # or FLEN as appropriate
1067 else:
1068 bytesperreg = bytestable[vew] # 1 2 4 8 16
1069 simdmult = (XLEN/8) / bytesperreg # or FLEN as appropriate
1070 vlen = CSRvectorlen[rs1] * simdmult
1071
1072 To index an element in a register rnum where the vector element index is i:
1073
1074 function regoffs(rnum, i):
1075 regidx = floor(i / simdmult) # integer-div rounded down
1076 byteidx = i % simdmult # integer-remainder
1077 return rnum + regidx, # actual real register
1078 byteidx * 8, # low
1079 byteidx * 8 + (vew-1), # high
1080
1081 ### Insights
1082
1083 SIMD register file splitting still to consider. For RV64, benefits of doubling
1084 (quadrupling in the case of Half-Precision IEEE754 FP) the apparent
1085 size of the floating point register file to 64 (128 in the case of HP)
1086 seem pretty clear and worth the complexity.
1087
1088 64 virtual 32-bit F.P. registers and given that 32-bit FP operations are
1089 done on 64-bit registers it's not so conceptually difficult.  May even
1090 be achieved by *actually* splitting the regfile into 64 virtual 32-bit
1091 registers such that a 64-bit FP scalar operation is dropped into (r0.H
1092 r0.L) tuples.  Implementation therefore hidden through register renaming.
1093
1094 Implementations intending to introduce VLIW, OoO and parallelism
1095 (even without Simple-V) would then find that the instructions are
1096 generated quicker (or in a more compact fashion that is less heavy
1097 on caches). Interestingly we observe then that Simple-V is about
1098 "consolidation of instruction generation", where actual parallelism
1099 of underlying hardware is an implementor-choice that could just as
1100 equally be applied *without* Simple-V even being implemented.
1101
1102 ## Analysis of CSR decoding on latency <a name="csr_decoding_analysis"></a>
1103
1104 It could indeed have been logically deduced (or expected), that there
1105 would be additional decode latency in this proposal, because if
1106 overloading the opcodes to have different meanings, there is guaranteed
1107 to be some state, some-where, directly related to registers.
1108
1109 There are several cases:
1110
1111 * All operands vector-length=1 (scalars), all operands
1112 packed-bitwidth="default": instructions are passed through direct as if
1113 Simple-V did not exist.  Simple-V is, in effect, completely disabled.
1114 * At least one operand vector-length > 1, all operands
1115 packed-bitwidth="default": any parallel vector ALUs placed on "alert",
1116 virtual parallelism looping may be activated.
1117 * All operands vector-length=1 (scalars), at least one
1118 operand packed-bitwidth != default: degenerate case of SIMD,
1119 implementation-specific complexity here (packed decode before ALUs or
1120 *IN* ALUs)
1121 * At least one operand vector-length > 1, at least one operand
1122 packed-bitwidth != default: parallel vector ALUs (if any)
1123 placed on "alert", virtual parallelsim looping may be activated,
1124 implementation-specific SIMD complexity kicks in (packed decode before
1125 ALUs or *IN* ALUs).
1126
1127 Bear in mind that the proposal includes that the decision whether
1128 to parallelise in hardware or whether to virtual-parallelise (to
1129 dramatically simplify compilers and also not to run into the SIMD
1130 instruction proliferation nightmare) *or* a transprent combination
1131 of both, be done on a *per-operand basis*, so that implementors can
1132 specifically choose to create an application-optimised implementation
1133 that they believe (or know) will sell extremely well, without having
1134 "Extra Standards-Mandated Baggage" that would otherwise blow their area
1135 or power budget completely out the window.
1136
1137 Additionally, two possible CSR schemes have been proposed, in order to
1138 greatly reduce CSR space:
1139
1140 * per-register CSRs (vector-length and packed-bitwidth)
1141 * a smaller number of CSRs with the same information but with an *INDEX*
1142 specifying WHICH register in one of three regfiles (vector, fp, int)
1143 the length and bitwidth applies to.
1144
1145 (See "CSR vector-length and CSR SIMD packed-bitwidth" section for details)
1146
1147 In addition, LOAD/STORE has its own associated proposed CSRs that
1148 mirror the STRIDE (but not yet STRIDE-SEGMENT?) functionality of
1149 V (and Hwacha).
1150
1151 Also bear in mind that, for reasons of simplicity for implementors,
1152 I was coming round to the idea of permitting implementors to choose
1153 exactly which bitwidths they would like to support in hardware and which
1154 to allow to fall through to software-trap emulation.
1155
1156 So the question boils down to:
1157
1158 * whether either (or both) of those two CSR schemes have significant
1159 latency that could even potentially require an extra pipeline decode stage
1160 * whether there are implementations that can be thought of which do *not*
1161 introduce significant latency
1162 * whether it is possible to explicitly (through quite simply
1163 disabling Simple-V-Ext) or implicitly (detect the case all-vlens=1,
1164 all-simd-bitwidths=default) switch OFF any decoding, perhaps even to
1165 the extreme of skipping an entire pipeline stage (if one is needed)
1166 * whether packed bitwidth and associated regfile splitting is so complex
1167 that it should definitely, definitely be made mandatory that implementors
1168 move regfile splitting into the ALU, and what are the implications of that
1169 * whether even if that *is* made mandatory, is software-trapped
1170 "unsupported bitwidths" still desirable, on the basis that SIMD is such
1171 a complete nightmare that *even* having a software implementation is
1172 better, making Simple-V have more in common with a software API than
1173 anything else.
1174
1175 Whilst the above may seem to be severe minuses, there are some strong
1176 pluses:
1177
1178 * Significant reduction of V's opcode space: over 95%.
1179 * Smaller reduction of P's opcode space: around 10%.
1180 * The potential to use Compressed instructions in both Vector and SIMD
1181 due to the overloading of register meaning (implicit vectorisation,
1182 implicit packing)
1183 * Not only present but also future extensions automatically gain parallelism.
1184 * Already mentioned but worth emphasising: the simplification to compiler
1185 writers and assembly-level writers of having the same consistent ISA
1186 regardless of whether the internal level of parallelism (number of
1187 parallel ALUs) is only equal to one ("virtual" parallelism), or is
1188 greater than one, should not be underestimated.
1189
1190 ## Reducing Register Bank porting
1191
1192 This looks quite reasonable.
1193 <https://www.princeton.edu/~rblee/ELE572Papers/MultiBankRegFile_ISCA2000.pdf>
1194
1195 The main details are outlined on page 4.  They propose a 2-level register
1196 cache hierarchy, note that registers are typically only read once, that
1197 you never write back from upper to lower cache level but always go in a
1198 cycle lower -> upper -> ALU -> lower, and at the top of page 5 propose
1199 a scheme where you look ahead by only 2 instructions to determine which
1200 registers to bring into the cache.
1201
1202 The nice thing about a vector architecture is that you *know* that
1203 *even more* registers are going to be pulled in: Hwacha uses this fact
1204 to optimise L1/L2 cache-line usage (avoid thrashing), strangely enough
1205 by *introducing* deliberate latency into the execution phase.
1206
1207 ## Overflow registers in combination with predication
1208
1209 **TODO**: propose overflow registers be actually one of the integer regs
1210 (flowing to multiple regs).
1211
1212 **TODO**: propose "mask" (predication) registers likewise. combination with
1213 standard RV instructions and overflow registers extremely powerful, see
1214 Aspex ASP.
1215
1216 When integer overflow is stored in an easily-accessible bit (or another
1217 register), parallelisation turns this into a group of bits which can
1218 potentially be interacted with in predication, in interesting and powerful
1219 ways. For example, by taking the integer-overflow result as a predication
1220 field and shifting it by one, a predicated vectorised "add one" can emulate
1221 "carry" on arbitrary (unlimited) length addition.
1222
1223 However despite RVV having made room for floating-point exceptions, neither
1224 RVV nor base RV have taken integer-overflow (carry) into account, which
1225 makes proposing it quite challenging given that the relevant (Base) RV
1226 sections are frozen. Consequently it makes sense to forgo this feature.
1227
1228 ## Context Switch Example <a name="context_switch"></a>
1229
1230 An unusual side-effect of Simple-V mapping onto the standard register files
1231 is that LOAD-multiple and STORE-multiple are accidentally available, as long
1232 as it is acceptable that the register(s) to be loaded/stored are contiguous
1233 (per instruction). An additional accidental benefit is that Compressed LD/ST
1234 may also be used.
1235
1236 To illustrate how this works, here is some example code from FreeRTOS
1237 (GPLv2 licensed, portasm.S):
1238
1239 /* Macro for saving task context */
1240 .macro portSAVE_CONTEXT
1241 .global pxCurrentTCB
1242 /* make room in stack */
1243 addi sp, sp, -REGBYTES * 32
1244
1245 /* Save Context */
1246 STORE x1, 0x0(sp)
1247 STORE x2, 1 * REGBYTES(sp)
1248 STORE x3, 2 * REGBYTES(sp)
1249 ...
1250 ...
1251 STORE x30, 29 * REGBYTES(sp)
1252 STORE x31, 30 * REGBYTES(sp)
1253
1254 /* Store current stackpointer in task control block (TCB) */
1255 LOAD t0, pxCurrentTCB //pointer
1256 STORE sp, 0x0(t0)
1257 .endm
1258
1259 /* Saves current error program counter (EPC) as task program counter */
1260 .macro portSAVE_EPC
1261 csrr t0, mepc
1262 STORE t0, 31 * REGBYTES(sp)
1263 .endm
1264
1265 /* Saves current return adress (RA) as task program counter */
1266 .macro portSAVE_RA
1267 STORE ra, 31 * REGBYTES(sp)
1268 .endm
1269
1270 /* Macro for restoring task context */
1271 .macro portRESTORE_CONTEXT
1272
1273 .global pxCurrentTCB
1274 /* Load stack pointer from the current TCB */
1275 LOAD sp, pxCurrentTCB
1276 LOAD sp, 0x0(sp)
1277
1278 /* Load task program counter */
1279 LOAD t0, 31 * REGBYTES(sp)
1280 csrw mepc, t0
1281
1282 /* Run in machine mode */
1283 li t0, MSTATUS_PRV1
1284 csrs mstatus, t0
1285
1286 /* Restore registers,
1287 Skip global pointer because that does not change */
1288 LOAD x1, 0x0(sp)
1289 LOAD x4, 3 * REGBYTES(sp)
1290 LOAD x5, 4 * REGBYTES(sp)
1291 ...
1292 ...
1293 LOAD x30, 29 * REGBYTES(sp)
1294 LOAD x31, 30 * REGBYTES(sp)
1295
1296 addi sp, sp, REGBYTES * 32
1297 mret
1298 .endm
1299
1300 The important bits are the Load / Save context, which may be replaced
1301 with firstly setting up the Vectors and secondly using a *single* STORE
1302 (or LOAD) including using C.ST or C.LD, to indicate that the entire
1303 bank of registers is to be loaded/saved:
1304
1305 /* a few things are assumed here: (a) that when switching to
1306 M-Mode an entirely different set of CSRs is used from that
1307 which is used in U-Mode and (b) that the M-Mode x1 and x4
1308 vectors are also not used anywhere else in M-Mode, consequently
1309 only need to be set up just the once.
1310 */
1311 .macroVectorSetup
1312 MVECTORCSRx1 = 31, defaultlen
1313 MVECTORCSRx4 = 28, defaultlen
1314
1315 /* Save Context */
1316 SETVL x0, x0, 31 /* x0 ignored silently */
1317 STORE x1, 0x0(sp) // x1 marked as 31-long vector of default bitwidth
1318
1319 /* Restore registers,
1320 Skip global pointer because that does not change */
1321 LOAD x1, 0x0(sp)
1322 SETVL x0, x0, 28 /* x0 ignored silently */
1323 LOAD x4, 3 * REGBYTES(sp) // x4 marked as 28-long default bitwidth
1324
1325 Note that although it may just be a bug in portasm.S, x2 and x3 appear not
1326 to be being restored. If however this is a bug and they *do* need to be
1327 restored, then the SETVL call may be moved to *outside* the Save / Restore
1328 Context assembly code, into the macroVectorSetup, as long as vectors are
1329 never used anywhere else (i.e. VL is never altered by M-Mode).
1330
1331 In effect the entire bank of repeated LOAD / STORE instructions is replaced
1332 by one single (compressed if it is available) instruction.
1333
1334 ## Virtual Memory page-faults on LOAD/STORE
1335
1336
1337 ### Notes from conversations
1338
1339 > I was going through the C.LOAD / C.STORE section 12.3 of V2.3-Draft
1340 > riscv-isa-manual in order to work out how to re-map RVV onto the standard
1341 > ISA, and came across an interesting comments at the bottom of pages 75
1342 > and 76:
1343
1344 > " A common mechanism used in other ISAs to further reduce save/restore
1345 > code size is load- multiple and store-multiple instructions. "
1346
1347 > Fascinatingly, due to Simple-V proposing to use the *standard* register
1348 > file, both C.LOAD / C.STORE *and* LOAD / STORE would in effect be exactly
1349 > that: load-multiple and store-multiple instructions. Which brings us
1350 > on to this comment:
1351
1352 > "For virtual memory systems, some data accesses could be resident in
1353 > physical memory and
1354 > some could not, which requires a new restart mechanism for partially
1355 > executed instructions."
1356
1357 > Which then of course brings us to the interesting question: how does RVV
1358 > cope with the scenario when, particularly with LD.X (Indexed / indirect
1359 > loads), part-way through the loading a page fault occurs?
1360
1361 > Has this been noted or discussed before?
1362
1363 For applications-class platforms, the RVV exception model is
1364 element-precise (that is, if an exception occurs on element j of a
1365 vector instruction, elements 0..j-1 have completed execution and elements
1366 j+1..vl-1 have not executed).
1367
1368 Certain classes of embedded platforms where exceptions are always fatal
1369 might choose to offer resumable/swappable interrupts but not precise
1370 exceptions.
1371
1372
1373 > Is RVV designed in any way to be re-entrant?
1374
1375 Yes.
1376
1377
1378 > What would the implications be for instructions that were in a FIFO at
1379 > the time, in out-of-order and VLIW implementations, where partial decode
1380 > had taken place?
1381
1382 The usual bag of tricks for maintaining precise exceptions applies to
1383 vector machines as well. Register renaming makes the job easier, and
1384 it's relatively cheaper for vectors, since the control cost is amortized
1385 over longer registers.
1386
1387
1388 > Would it be reasonable at least to say *bypass* (and freeze) the
1389 > instruction FIFO (drop down to a single-issue execution model temporarily)
1390 > for the purposes of executing the instructions in the interrupt (whilst
1391 > setting up the VM page), then re-continue the instruction with all
1392 > state intact?
1393
1394 This approach has been done successfully, but it's desirable to be
1395 able to swap out the vector unit state to support context switches on
1396 exceptions that result in long-latency I/O.
1397
1398
1399 > Or would it be better to switch to an entirely separate secondary
1400 > hyperthread context?
1401
1402 > Does anyone have any ideas or know if there is any academic literature
1403 > on solutions to this problem?
1404
1405 The Vector VAX offered imprecise but restartable and swappable exceptions:
1406 http://mprc.pku.edu.cn/~liuxianhua/chn/corpus/Notes/articles/isca/1990/VAX%20vector%20architecture.pdf
1407
1408 Sec. 4.6 of Krste's dissertation assesses some of
1409 the tradeoffs and references a bunch of related work:
1410 http://people.eecs.berkeley.edu/~krste/thesis.pdf
1411
1412
1413 ----
1414
1415 Started reading section 4.6 of Krste's thesis, noted the "IEE85 F.P
1416 exceptions" and thought, "hmmm that could go into a CSR, must re-read
1417 the section on FP state CSRs in RVV 0.4-Draft again" then i suddenly
1418 thought, "ah ha! what if the memory exceptions were, instead of having
1419 an immediate exception thrown, were simply stored in a type of predication
1420 bit-field with a flag "error this element failed"?
1421
1422 Then, *after* the vector load (or store, or even operation) was
1423 performed, you could *then* raise an exception, at which point it
1424 would be possible (yes in software... I know....) to go "hmmm, these
1425 indexed operations didn't work, let's get them into memory by triggering
1426 page-loads", then *re-run the entire instruction* but this time with a
1427 "memory-predication CSR" that stops the already-performed operations
1428 (whether they be loads, stores or an arithmetic / FP operation) from
1429 being carried out a second time.
1430
1431 This theoretically could end up being done multiple times in an SMP
1432 environment, and also for LD.X there would be the remote outside annoying
1433 possibility that the indexed memory address could end up being modified.
1434
1435 The advantage would be that the order of execution need not be
1436 sequential, which potentially could have some big advantages.
1437 Am still thinking through the implications as any dependent operations
1438 (particularly ones already decoded and moved into the execution FIFO)
1439 would still be there (and stalled). hmmm.
1440
1441 ----
1442
1443 > > # assume internal parallelism of 8 and MAXVECTORLEN of 8
1444 > > VSETL r0, 8
1445 > > FADD x1, x2, x3
1446 >
1447 > > x3[0]: ok
1448 > > x3[1]: exception
1449 > > x3[2]: ok
1450 > > ...
1451 > > ...
1452 > > x3[7]: ok
1453 >
1454 > > what happens to result elements 2-7?  those may be *big* results
1455 > > (RV128)
1456 > > or in the RVV-Extended may be arbitrary bit-widths far greater.
1457 >
1458 >  (you replied:)
1459 >
1460 > Thrown away.
1461
1462 discussion then led to the question of OoO architectures
1463
1464 > The costs of the imprecise-exception model are greater than the benefit.
1465 > Software doesn't want to cope with it.  It's hard to debug.  You can't
1466 > migrate state between different microarchitectures--unless you force all
1467 > implementations to support the same imprecise-exception model, which would
1468 > greatly limit implementation flexibility.  (Less important, but still
1469 > relevant, is that the imprecise model increases the size of the context
1470 > structure, as the microarchitectural guts have to be spilled to memory.)
1471
1472 ## Zero/Non-zero Predication
1473
1474 >> >  it just occurred to me that there's another reason why the data
1475 >> > should be left instead of zeroed.  if the standard register file is
1476 >> > used, such that vectorised operations are translated to mean "please
1477 >> > insert multiple register-contiguous operations into the instruction
1478 >> > FIFO" and predication is used to *skip* some of those, then if the
1479 >> > next "vector" operation uses the (standard) registers that were masked
1480 >> > *out* of the previous operation it may proceed without blocking.
1481 >> >
1482 >> >  if however zeroing is made mandatory then that optimisation becomes
1483 >> > flat-out impossible to deploy.
1484 >> >
1485 >> >  whilst i haven't fully thought through the full implications, i
1486 >> > suspect RVV might also be able to benefit by being able to fit more
1487 >> > overlapping operations into the available SRAM by doing something
1488 >> > similar.
1489 >
1490 >
1491 > Luke, this is called density time masking. It doesn’t apply to only your
1492 > model with the “standard register file” is used. it applies to any
1493 > architecture that attempts to speed up by skipping computation and writeback
1494 > of masked elements.
1495 >
1496 > That said, the writing of zeros need not be explicit. It is possible to add
1497 > a “zero bit” per element that, when set, forces a zero to be read from the
1498 > vector (although the underlying storage may have old data). In this case,
1499 > there may be a way to implement DTM as well.
1500
1501
1502 ## Implementation detail for scalar-only op detection <a name="scalar_detection"></a>
1503
1504 Note 1: this idea is a pipeline-bypass concept, which may *or may not* be
1505 worthwhile.
1506
1507 Note 2: this is just one possible implementation. Another implementation
1508 may choose to treat *all* operations as vectorised (including treating
1509 scalars as vectors of length 1), choosing to add an extra pipeline stage
1510 dedicated to *all* instructions.
1511
1512 This section *specifically* covers the implementor's freedom to choose
1513 that they wish to minimise disruption to an existing design by detecting
1514 "scalar-only operations", bypassing the vectorisation phase (which may
1515 or may not require an additional pipeline stage)
1516
1517 [[scalardetect.png]]
1518
1519 >> For scalar ops an implementation may choose to compare 2-3 bits through an
1520 >> AND gate: are src & dest scalar? Yep, ok send straight to ALU  (or instr
1521 >> FIFO).
1522
1523 > Those bits cannot be known until after the registers are decoded from the
1524 > instruction and a lookup in the "vector length table" has completed.
1525 > Considering that one of the reasons RISC-V keeps registers in invariant
1526 > positions across all instructions is to simplify register decoding, I expect
1527 > that inserting an SRAM read would lengthen the critical path in most
1528 > implementations.
1529
1530 reply:
1531
1532 > briefly: the trick i mentioned about ANDing bits together to check if
1533 > an op was fully-scalar or not was to be read out of a single 32-bit
1534 > 3R1W SRAM (64-bit if FPU exists). the 32/64-bit SRAM contains 1 bit per
1535 > register indicating "is register vectorised yes no". 3R because you need
1536 > to check src1, src2 and dest simultaneously. the entries are *generated*
1537 > from the CSRs and are an optimisation that on slower embedded systems
1538 > would likely not be needed.
1539
1540 > is there anything unreasonable that anyone can foresee about that?
1541 > what are the down-sides?
1542
1543 ## C.MV predicated src, predicated dest
1544
1545 > Can this be usefully defined in such a way that it is
1546 > equivalent to vector gather-scatter on each source, followed by a
1547 > non-predicated vector-compare, followed by vector gather-scatter on the
1548 > result?
1549
1550 ## element width conversion: restrict or remove?
1551
1552 summary: don't restrict / remove. it's fine.
1553
1554 > > it has virtually no cost/overhead as long as you specify
1555 > > that inputs can only upconvert, and operations are always done at the
1556 > > largest size, and downconversion only happens at the output.
1557 >
1558 > okaaay.  so that's a really good piece of implementation advice.
1559 > algorithms do require data size conversion, so at some point you need to
1560 > introduce the feature of upconverting and downconverting.
1561 >
1562 > > for int and uint, this is dead simple and fits well within the RVV pipeline
1563 > > without any critical path, pipeline depth, or area implications.
1564
1565 <https://groups.google.com/a/groups.riscv.org/forum/#!topic/isa-dev/g3feFnAoKIM>
1566
1567 ## Under review / discussion: remove CSR vector length, use VSETVL <a name="vsetvl"></a>
1568
1569 **DECISION: 11jun2018 - CSR vector length removed, VSETVL determines
1570 length on all regs**. This section kept for historical reasons.
1571
1572 So the issue is as follows:
1573
1574 * CSRs are used to set the "span" of a vector (how many of the standard
1575 register file to contiguously use)
1576 * VSETVL in RVV works as follows: it sets the vector length (copy of which
1577 is placed in a dest register), and if the "required" length is longer
1578 than the *available* length, the dest reg is set to the MIN of those
1579 two.
1580 * **HOWEVER**... in SV, *EVERY* vector register has its own separate
1581 length and thus there is no way (at the time that VSETVL is called) to
1582 know what to set the vector length *to*.
1583 * At first glance it seems that it would be perfectly fine to just limit
1584 the vector operation to the length specified in the destination
1585 register's CSR, at the time that each instruction is issued...
1586 except that that cannot possibly be guaranteed to match
1587 with the value *already loaded into the target register from VSETVL*.
1588
1589 Therefore a different approach is needed.
1590
1591 Possible options include:
1592
1593 * Removing the CSR "Vector Length" and always using the value from
1594 VSETVL. "VSETVL destreg, counterreg, #lenimmed" will set VL *and*
1595 destreg equal to MIN(counterreg, lenimmed), with register-based
1596 variant "VSETVL destreg, counterreg, lenreg" doing the same.
1597 * Keeping the CSR "Vector Length" and having the lenreg version have
1598 a "twist": "if lengreg is vectorised, read the length from the CSR"
1599 * Other (TBD)
1600
1601 The first option (of the ones brainstormed so far) is a lot simpler.
1602 It does however mean that the length set in VSETVL will apply across-the-board
1603 to all src1, src2 and dest vectorised registers until it is otherwise changed
1604 (by another VSETVL call). This is probably desirable behaviour.
1605
1606 ## Implementation Paradigms <a name="implementation_paradigms"></a>
1607
1608 TODO: assess various implementation paradigms. These are listed roughly
1609 in order of simplicity (minimum compliance, for ultra-light-weight
1610 embedded systems or to reduce design complexity and the burden of
1611 design implementation and compliance, in non-critical areas), right the
1612 way to high-performance systems.
1613
1614 * Full (or partial) software-emulated (via traps): full support for CSRs
1615 required, however when a register is used that is detected (in hardware)
1616 to be vectorised, an exception is thrown.
1617 * Single-issue In-order, reduced pipeline depth (traditional SIMD / DSP)
1618 * In-order 5+ stage pipelines with instruction FIFOs and mild register-renaming
1619 * Out-of-order with instruction FIFOs and aggressive register-renaming
1620 * VLIW
1621
1622 Also to be taken into consideration:
1623
1624 * "Virtual" vectorisation: single-issue loop, no internal ALU parallelism
1625 * Comphrensive vectorisation: FIFOs and internal parallelism
1626 * Hybrid Parallelism
1627
1628 ### Full or partial software-emulation
1629
1630 The absolute, absolute minimal implementation is to provide the full
1631 set of CSRs and detection logic for when any of the source or destination
1632 registers are vectorised. On detection, a trap is thrown, whether it's
1633 a branch, LOAD, STORE, or an arithmetic operation.
1634
1635 Implementors are entirely free to choose whether to allow absolutely every
1636 single operation to be software-emulated, or whether to provide some emulation
1637 and some hardware support. In particular, for an RV32E implementation
1638 where fast context-switching is a requirement (see "Context Switch Example"),
1639 it makes no sense to allow Vectorised-LOAD/STORE to be implemented as an
1640 exception, as every context-switch will result in double-traps.
1641
1642 # TODO Research
1643
1644 > For great floating point DSPs check TI’s C3x, C4X, and C6xx DSPs
1645
1646 Idea: basic simple butterfly swap on a few element indices, primarily targetted
1647 at SIMD / DSP. High-byte low-byte swapping, high-word low-word swapping,
1648 perhaps allow reindexing of permutations up to 4 elements? 8? Reason:
1649 such operations are less costly than a full indexed-shuffle, which requires
1650 a separate instruction cycle.
1651
1652 Predication "all zeros" needs to be "leave alone". Detection of
1653 ADD r1, rs1, rs0 cases result in nop on predication index 0, whereas
1654 ADD r0, rs1, rs2 is actually a desirable copy from r2 into r0.
1655 Destruction of destination indices requires a copy of the entire vector
1656 in advance to avoid.
1657
1658 TBD: floating-point compare and other exception handling
1659
1660 ------
1661
1662 Multi-LR/SC
1663
1664 Please don't try to use the L1 itself.
1665
1666 Use the Load and Store buffers which capture instruction state prior
1667 to being accessed in the L1 (and prior to data arriving in the case of
1668 Store buffer).
1669
1670 Also, use the L1 Miss buffers as these already HAVE to be snooped by
1671 coherence traffic. These are used to monitor that all participating
1672 cache lines remain interference free, and amalgamate same into a CPU
1673 signal accessible ia branch or predicate.
1674
1675 The Load buffers manage inbound traffic
1676 The Store buffers manage outbound traffic.
1677
1678 Done properly, the participating cache lines can exceed the associativity
1679 of the L1 cache without architectural harm (may incur additional latency).
1680
1681 <https://groups.google.com/d/msg/comp.arch/QVl3c9vVDj0/ol_232-pAQAJ>
1682
1683 > > > so, let's say instead of another LR *cancelling* the load
1684 > > > reservation, the SMP core / hardware thread *blocks* for
1685 > > > up to 63 further instructions, waiting for the reservation
1686 > > > to clear.
1687 > >
1688 > > Can you explain what you mean by this paragraph?
1689 >
1690 > best put in sequential events, probably.
1691 >
1692 > <core1> LR <-- 64-instruction countdown starts here
1693 > <core1> ... 63
1694 > <core1> ... 62
1695 > <core2> LR same address <--- notes that core1 is on 61,
1696 > so pauses for **UP TO** 61 cycles
1697 > <core1> ... 32
1698 > <core1> SC <- core1 didn't reach zero, therefore valid, therefore
1699 > core2 is now **UNBLOCKED**, is granted the
1700 > load-reservation (and begins its **own** 64-cycle
1701 > LR instruction countdown)
1702 > <core2> ... 63
1703 > <core2> ... 62
1704 > <core2> ...
1705 > <core2> ...
1706 > <core2> SC <- also valid
1707
1708 Looks to me that you could effect the same functionality by simply
1709 holding onto the cache line in core 1 preventing core 2 from
1710 <architecturally> getting past the LR.
1711
1712 On the other hand, the freeze is similar to how the MP CRAYs did
1713 ATOMIC stuff.
1714
1715 # References
1716
1717 * SIMD considered harmful <https://www.sigarch.org/simd-instructions-considered-harmful/>
1718 * Link to first proposal <https://groups.google.com/a/groups.riscv.org/forum/#!topic/isa-dev/GuukrSjgBH8>
1719 * Recommendation by Jacob Bachmeyer to make zero-overhead loop an
1720 "implicit program-counter" <https://groups.google.com/a/groups.riscv.org/d/msg/isa-dev/vYVi95gF2Mo/SHz6a4_lAgAJ>
1721 * Re-continuing P-Extension proposal <https://groups.google.com/a/groups.riscv.org/forum/#!msg/isa-dev/IkLkQn3HvXQ/SEMyC9IlAgAJ>
1722 * First Draft P-SIMD (DSP) proposal <https://groups.google.com/a/groups.riscv.org/forum/#!topic/isa-dev/vYVi95gF2Mo>
1723 * B-Extension discussion <https://groups.google.com/a/groups.riscv.org/forum/#!topic/isa-dev/zi_7B15kj6s>
1724 * Broadcom VideoCore-IV <https://docs.broadcom.com/docs/12358545>
1725 Figure 2 P17 and Section 3 on P16.
1726 * Hwacha <https://www2.eecs.berkeley.edu/Pubs/TechRpts/2015/EECS-2015-262.html>
1727 * Hwacha <https://www2.eecs.berkeley.edu/Pubs/TechRpts/2015/EECS-2015-263.html>
1728 * Vector Workshop <http://riscv.org/wp-content/uploads/2015/06/riscv-vector-workshop-june2015.pdf>
1729 * Predication <https://groups.google.com/a/groups.riscv.org/forum/#!topic/isa-dev/XoP4BfYSLXA>
1730 * Branch Divergence <https://jbush001.github.io/2014/12/07/branch-divergence-in-parallel-kernels.html>
1731 * Life of Triangles (3D) <https://jbush001.github.io/2016/02/27/life-of-triangle.html>
1732 * Videocore-IV <https://github.com/hermanhermitage/videocoreiv/wiki/VideoCore-IV-3d-Graphics-Pipeline>
1733 * Discussion proposing CSRs that change ISA definition
1734 <https://groups.google.com/a/groups.riscv.org/forum/#!topic/isa-dev/InzQ1wr_3Ak>
1735 * Zero-overhead loops <https://pdfs.semanticscholar.org/dbaa/66985cc730d4b44d79f519e96ec9c43ab5b7.pdf>
1736 * Multi-ported VLIW Register File Implementation <https://ce-publications.et.tudelft.nl/publications/1517_multiple_contexts_in_a_multiported_vliw_register_file_impl.pdf>
1737 * Fast context save/restore proposal <https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/57F823FA.6030701%40gmail.com>
1738 * Register File Bank Cacheing <https://www.princeton.edu/~rblee/ELE572Papers/MultiBankRegFile_ISCA2000.pdf>
1739 * Expired Patent on Vector Virtual Memory solutions
1740 <https://patentimages.storage.googleapis.com/fc/f6/e2/2cbee92fcd8743/US5895501.pdf>
1741 * Discussion on RVV "re-entrant" capabilities allowing operations to be
1742 restarted if an exception occurs (VM page-table miss)
1743 <https://groups.google.com/a/groups.riscv.org/d/msg/isa-dev/IuNFitTw9fM/CCKBUlzsAAAJ>
1744 * Dot Product Vector <https://people.eecs.berkeley.edu/~biancolin/papers/arith17.pdf>
1745 * RVV slides 2017 <https://content.riscv.org/wp-content/uploads/2017/12/Wed-1330-RISCVRogerEspasaVEXT-v4.pdf>
1746 * Wavefront skipping using BRAMS <http://www.ece.ubc.ca/~lemieux/publications/severance-fpga2015.pdf>
1747 * Streaming Pipelines <http://www.ece.ubc.ca/~lemieux/publications/severance-fpga2014.pdf>
1748 * Barcelona SIMD Presentation <https://content.riscv.org/wp-content/uploads/2018/05/09.05.2018-9.15-9.30am-RISCV201805-Andes-proposed-P-extension.pdf>
1749 * <http://www.ece.ubc.ca/~lemieux/publications/severance-fpga2015.pdf>
1750 * Full Description (last page) of RVV instructions
1751 <https://inst.eecs.berkeley.edu/~cs152/sp18/handouts/lab4-1.0.pdf>
1752 * PULP Low-energy Cluster Vector Processor
1753 <http://iis-projects.ee.ethz.ch/index.php/Low-Energy_Cluster-Coupled_Vector_Coprocessor_for_Special-Purpose_PULP_Acceleration>