add SIMD comparison section
[libreriscv.git] / simple_v_extension.mdwn
1 # Variable-width Variable-packed SIMD / Simple-V / Parallelism Extension Proposal
2
3 [[!toc ]]
4
5 # Summary
6
7 Key insight: Simple-V is intended as an abstraction layer to provide
8 a consistent "API" to parallelisation of existing *and future* operations.
9 *Actual* internal hardware-level parallelism is *not* required, such
10 that Simple-V may be viewed as providing a "compact" or "consolidated"
11 means of issuing multiple near-identical arithmetic instructions to an
12 instruction queue (FILO), pending execution.
13
14 *Actual* parallelism, if added independently of Simple-V in the form
15 of Out-of-order restructuring (including parallel ALU lanes) or VLIW
16 implementations, or SIMD, or anything else, would then benefit *if*
17 Simple-V was added on top.
18
19 # Introduction
20
21 This proposal exists so as to be able to satisfy several disparate
22 requirements: power-conscious, area-conscious, and performance-conscious
23 designs all pull an ISA and its implementation in different conflicting
24 directions, as do the specific intended uses for any given implementation.
25
26 Additionally, the existing P (SIMD) proposal and the V (Vector) proposals,
27 whilst each extremely powerful in their own right and clearly desirable,
28 are also:
29
30 * Clearly independent in their origins (Cray and AndesStar v3 respectively)
31 so need work to adapt to the RISC-V ethos and paradigm
32 * Are sufficiently large so as to make adoption (and exploration for
33 analysis and review purposes) prohibitively expensive
34 * Both contain partial duplication of pre-existing RISC-V instructions
35 (an undesirable characteristic)
36 * Both have independent and disparate methods for introducing parallelism
37 at the instruction level.
38 * Both require that their respective parallelism paradigm be implemented
39 along-side and integral to their respective functionality *or not at all*.
40 * Both independently have methods for introducing parallelism that
41 could, if separated, benefit
42 *other areas of RISC-V not just DSP or Floating-point respectively*.
43
44 Therefore it makes a huge amount of sense to have a means and method
45 of introducing instruction parallelism in a flexible way that provides
46 implementors with the option to choose exactly where they wish to offer
47 performance improvements and where they wish to optimise for power
48 and/or area (and if that can be offered even on a per-operation basis that
49 would provide even more flexibility).
50
51 Additionally it makes sense to *split out* the parallelism inherent within
52 each of P and V, and to see if each of P and V then, in *combination* with
53 a "best-of-both" parallelism extension, could be added on *on top* of
54 this proposal, to topologically provide the exact same functionality of
55 each of P and V.
56
57 Furthermore, an additional goal of this proposal is to reduce the number
58 of opcodes utilised by each of P and V as they currently stand, leveraging
59 existing RISC-V opcodes where possible, and also potentially allowing
60 P and V to make use of Compressed Instructions as a result.
61
62 **TODO**: reword this to better suit this document:
63
64 Having looked at both P and V as they stand, they're _both_ very much
65 "separate engines" that, despite both their respective merits and
66 extremely powerful features, don't really cleanly fit into the RV design
67 ethos (or the flexible extensibility) and, as such, are both in danger
68 of not being widely adopted. I'm inclined towards recommending:
69
70 * splitting out the DSP aspects of P-SIMD to create a single-issue DSP
71 * splitting out the polymorphism, esoteric data types (GF, complex
72 numbers) and unusual operations of V to create a single-issue "Esoteric
73 Floating-Point" extension
74 * splitting out the loop-aspects, vector aspects and data-width aspects
75 of both P and V to a *new* "P-SIMD / Simple-V" and requiring that they
76 apply across *all* Extensions, whether those be DSP, M, Base, V, P -
77 everything.
78
79 **TODO**: propose overflow registers be actually one of the integer regs
80 (flowing to multiple regs).
81
82 **TODO**: propose "mask" (predication) registers likewise. combination with
83 standard RV instructions and overflow registers extremely powerful
84
85 ## CSRs marking registers as Vector
86
87 A 32-bit CSR would be needed (1 bit per integer register) to indicate
88 whether a register was, if referred to, implicitly to be treated as
89 a vector.
90
91 A second 32-bit CSR would be needed (1 bit per floating-point register)
92 to indicate whether a floating-point register was to be treated as a
93 vector.
94
95 In this way any standard (current or future) operation involving
96 register operands may detect if the operation is to be vector-vector,
97 vector-scalar or scalar-scalar (standard) simply through a single
98 bit test.
99
100 ## CSR vector-length and CSR SIMD packed-bitwidth
101
102 **TODO** analyse each of these:
103
104 * splitting out the loop-aspects, vector aspects and data-width aspects
105 * integer reg 0 *and* fp reg0 share CSR vlen 0 *and* CSR packed-bitwidth 0
106 * integer reg 1 *and* fp reg1 share CSR vlen 1 *and* CSR packed-bitwidth 1
107 * ....
108 * .... 
109
110 instead:
111
112 * CSR vlen 0 *and* CSR packed-bitwidth 0 register contain extra bits
113 specifying an *INDEX* of WHICH int/fp register they refer to
114 * CSR vlen 1 *and* CSR packed-bitwidth 1 register contain extra bits
115 specifying an *INDEX* of WHICH int/fp register they refer to
116 * ...
117 * ...
118
119 Have to be very *very* careful about not implementing too few of those
120 (or too many). Assess implementation impact on decode latency. Is it
121 worth it?
122
123 Implementation of the latter:
124
125 Operation involving (referring to) register M:
126
127 bitwidth = default # default for opcode?
128 vectorlen = 1 # scalar
129
130 for (o = 0, o < 2, o++)
131   if (CSR-Vector_registernum[o] == M)
132       bitwidth = CSR-Vector_bitwidth[o]
133       vectorlen = CSR-Vector_len[o]
134       break
135
136 and for the former it would simply be:
137
138 bitwidth = CSR-Vector_bitwidth[M]
139 vectorlen = CSR-Vector_len[M]
140
141 Alternatives:
142
143 * One single "global" vector-length CSR
144
145 ## Stride
146
147 **TODO**: propose two LOAD/STORE offset CSRs, which mark a particular
148 register as being "if you use this reg in LOAD/STORE, use the offset
149 amount CSRoffsN (N=0,1) instead of treating LOAD/STORE as contiguous".
150 can be used for matrix spanning.
151
152 > For LOAD/STORE, could a better option be to interpret the offset in the
153 > opcode as a stride instead, so "LOAD t3, 12(t2)" would, if t3 is
154 > configured as a length-4 vector base, result in t3 = *t2, t4 = *(t2+12),
155 > t5 = *(t2+24), t6 = *(t2+32)?  Perhaps include a bit in the
156 > vector-control CSRs to select between offset-as-stride and unit-stride
157 > memory accesses?
158
159 So there would be an instruction like this:
160
161 | SETOFF | On=rN | OBank={float|int} | Smode={offs|unit} | OFFn=rM |
162 | opcode | 5 bit | 1 bit | 1 bit | 5 bit, OFFn=XLEN |
163
164
165 which would mean:
166
167 * CSR-Offset register n <= (float|int) register number N
168 * CSR-Offset Stride-mode = offset or unit
169 * CSR-Offset amount register n = contents of register M
170
171 LOAD rN, ldoffs(rM) would then be (assuming packed bit-width not set):
172
173 offs = 0
174 stride = 1
175 vector-len = CSR-Vector-length register N
176
177 for (o = 0, o < 2, o++)
178 if (CSR-Offset register o == M)
179 offs = CSR-Offset amount register o
180 if CSR-Offset Stride-mode == offset:
181 stride = ldoffs
182 break
183
184 for (i = 0, i < vector-len; i++)
185 r[N+i] = mem[(offs*i + r[M+i])*stride]
186
187 # Analysis and discussion of Vector vs SIMD
188
189 There are four combined areas between the two proposals that help with
190 parallelism without over-burdening the ISA with a huge proliferation of
191 instructions:
192
193 * Fixed vs variable parallelism (fixed or variable "M" in SIMD)
194 * Implicit vs fixed instruction bit-width (integral to instruction or not)
195 * Implicit vs explicit type-conversion (compounded on bit-width)
196 * Implicit vs explicit inner loops.
197 * Masks / tagging (selecting/preventing certain indexed elements from execution)
198
199 The pros and cons of each are discussed and analysed below.
200
201 ## Fixed vs variable parallelism length
202
203 In David Patterson and Andrew Waterman's analysis of SIMD and Vector
204 ISAs, the analysis comes out clearly in favour of (effectively) variable
205 length SIMD. As SIMD is a fixed width, typically 4, 8 or in extreme cases
206 16 or 32 simultaneous operations, the setup, teardown and corner-cases of SIMD
207 are extremely burdensome except for applications whose requirements
208 *specifically* match the *precise and exact* depth of the SIMD engine.
209
210 Thus, SIMD, no matter what width is chosen, is never going to be acceptable
211 for general-purpose computation, and in the context of developing a
212 general-purpose ISA, is never going to satisfy 100 percent of implementors.
213
214 That basically leaves "variable-length vector" as the clear *general-purpose*
215 winner, at least in terms of greatly simplifying the instruction set,
216 reducing the number of instructions required for any given task, and thus
217 reducing power consumption for the same.
218
219 ## Implicit vs fixed instruction bit-width
220
221 SIMD again has a severe disadvantage here, over Vector: huge proliferation
222 of specialist instructions that target 8-bit, 16-bit, 32-bit, 64-bit, and
223 have to then have operations *for each and between each*. It gets very
224 messy, very quickly.
225
226 The V-Extension on the other hand proposes to set the bit-width of
227 future instructions on a per-register basis, such that subsequent instructions
228 involving that register are *implicitly* of that particular bit-width until
229 otherwise changed or reset.
230
231 This has some extremely useful properties, without being particularly
232 burdensome to implementations, given that instruction decode already has
233 to direct the operation to a correctly-sized width ALU engine, anyway.
234
235 Not least: in places where an ISA was previously constrained (due for
236 whatever reason, including limitations of the available operand spcace),
237 implicit bit-width allows the meaning of certain operations to be
238 type-overloaded *without* pollution or alteration of frozen and immutable
239 instructions, in a fully backwards-compatible fashion.
240
241 ## Implicit and explicit type-conversion
242
243 The Draft 2.3 V-extension proposal has (deprecated) polymorphism to help
244 deal with over-population of instructions, such that type-casting from
245 integer (and floating point) of various sizes is automatically inferred
246 due to "type tagging" that is set with a special instruction. A register
247 will be *specifically* marked as "16-bit Floating-Point" and, if added
248 to an operand that is specifically tagged as "32-bit Integer" an implicit
249 type-conversion will take placce *without* requiring that type-conversion
250 to be explicitly done with its own separate instruction.
251
252 However, implicit type-conversion is not only quite burdensome to
253 implement (explosion of inferred type-to-type conversion) but also is
254 never really going to be complete. It gets even worse when bit-widths
255 also have to be taken into consideration.
256
257 Overall, type-conversion is generally best to leave to explicit
258 type-conversion instructions, or in definite specific use-cases left to
259 be part of an actual instruction (DSP or FP)
260
261 ## Zero-overhead loops vs explicit loops
262
263 The initial Draft P-SIMD Proposal by Chuanhua Chang of Andes Technology
264 contains an extremely interesting feature: zero-overhead loops. This
265 proposal would basically allow an inner loop of instructions to be
266 repeated indefinitely, a fixed number of times.
267
268 Its specific advantage over explicit loops is that the pipeline in a DSP
269 can potentially be kept completely full *even in an in-order single-issue
270 implementation*. Normally, it requires a superscalar architecture and
271 out-of-order execution capabilities to "pre-process" instructions in
272 order to keep ALU pipelines 100% occupied.
273
274 By bringing that capability in, this proposal could offer a way to increase
275 pipeline activity even in simpler implementations in the one key area
276 which really matters: the inner loop.
277
278 However when looking at much more comprehensive schemes
279 "A portable specification of zero-overhead loop control hardware
280 applied to embedded processors" (ZOLC), optimising only the single
281 inner loop seems inadequate, tending to suggest that ZOLC may be
282 better off being proposed as an entirely separate Extension.
283
284 ## Mask and Tagging (Predication)
285
286 Tagging (aka Masks aka Predication) is a pseudo-method of implementing
287 simplistic branching in a parallel fashion, by allowing execution on
288 elements of a vector to be switched on or off depending on the results
289 of prior operations in the same array position.
290
291 The reason for considering this is simple: by *definition* it
292 is not possible to perform individual parallel branches in a SIMD
293 (Single-Instruction, **Multiple**-Data) context. Branches (modifying
294 of the Program Counter) will result in *all* parallel data having
295 a different instruction executed on it: that's just the definition of
296 SIMD, and it is simply unavoidable.
297
298 So these are the ways in which conditional execution may be implemented:
299
300 * explicit compare and branch: BNE x, y -> offs would jump offs
301 instructions if x was not equal to y
302 * explicit store of tag condition: CMP x, y -> tagbit
303 * implicit (condition-code) ADD results in a carry, carry bit implicitly
304 (or sometimes explicitly) goes into a "tag" (mask) register
305
306 The first of these is a "normal" branch method, which is flat-out impossible
307 to parallelise without look-ahead and effectively rewriting instructions.
308 This would defeat the purpose of RISC.
309
310 The latter two are where parallelism becomes easy to do without complexity:
311 every operation is modified to be "conditionally executed" (in an explicit
312 way directly in the instruction format *or* implicitly).
313
314 RVV (Vector-Extension) proposes to have *explicit* storing of the compare
315 in a tag/mask register, and to *explicitly* have every vector operation
316 *require* that its operation be "predicated" on the bits within an
317 explicitly-named tag/mask register.
318
319 SIMD (P-Extension) has not yet published precise documentation on what its
320 schema is to be: there is however verbal indication at the time of writing
321 that:
322
323 > The "compare" instructions in the DSP/SIMD ISA proposed by Andes will
324 > be executed using the same compare ALU logic for the base ISA with some
325 > minor modifications to handle smaller data types. The function will not
326 > be duplicated.
327
328 This is an *implicit* form of predication as the base RV ISA does not have
329 condition-codes or predication. By adding a CSR it becomes possible
330 to also tag certain registers as "predicated if referenced as a destination".
331 Example:
332
333 // in future operations if r0 is the destination use r5 as
334 // the PREDICATION register
335 IMPLICICSRPREDICATE r0, r5
336 // store the compares in r5 as the PREDICATION register
337 CMPEQ8 r5, r1, r2
338 // r0 is used here. ah ha! that means it's predicated using r5!
339 ADD8 r0, r1, r3
340
341 With enough registers (and there are enough registers) some fairly
342 complex predication can be set up and yet still execute without significant
343 stalling, even in a simple non-superscalar architecture.
344
345 ### Retro-fitting Predication into branch-explicit ISA
346
347 One of the goals of this parallelism proposal is to avoid instruction
348 duplication. However, with the base ISA having been designed explictly
349 to *avoid* condition-codes entirely, shoe-horning predication into it
350 bcomes quite challenging.
351
352 However what if all branch instructions, if referencing a vectorised
353 register, were instead given *completely new analogous meanings* that
354 resulted in a parallel bit-wise predication register being set? This
355 would have to be done for both C.BEQZ and C.BNEZ, as well as BEQ, BNE,
356 BLT and BGE.
357
358 We might imagine that FEQ, FLT and FLT would also need to be converted,
359 however these are effectively *already* in the precise form needed and
360 do not need to be converted *at all*! The difference is that FEQ, FLT
361 and FLE *specifically* write a 1 to an integer register if the condition
362 holds, and 0 if not. All that needs to be done here is to say, "if
363 the integer register is tagged with a bit that says it is a predication
364 register, the **bit** in the integer register is set based on the
365 current vector index" instead.
366
367 There is, in the standard Conditional Branch instruction, more than
368 adequate space to interpret it in a similar fashion:
369
370 [[!table data="""
371 31 |30 ..... 25 |24 ... 20 | 19 ... 15 | 14 ...... 12 | 11 ....... 8 | 7 | 6 ....... 0 |
372 imm[12] | imm[10:5] | rs2 | rs1 | funct3 | imm[4:1] | imm[11] | opcode |
373 1 | 6 | 5 | 5 | 3 | 4 | 1 | 7 |
374 offset[12,10:5] || src2 | src1 | BEQ | offset[11,4:1] || BRANCH |
375 """]]
376
377 This would become:
378
379 [[!table data="""
380 31 |30 ..... 25 |24 ... 20 | 19 ... 15 | 14 ...... 12 | 11 ....... 8 | 7 | 6 ....... 0 |
381 imm[12] | imm[10:5] | rs2 | rs1 | funct3 | imm[4:1] | imm[11] | opcode |
382 1 | 6 | 5 | 5 | 3 | 4 | 1 | 7 |
383 reserved || src2 | src1 | BEQ | predicate rs3 || BRANCH |
384 """]]
385
386 Similarly the C.BEQZ and C.BNEZ instruction format may be retro-fitted,
387 with the interesting side-effect that there is space within what is presently
388 the "immediate offset" field to reinterpret that to add in not only a bit
389 field to distinguish between floating-point compare and integer compare,
390 not only to add in a second source register, but also use some of the bits as
391 a predication target as well.
392
393 [[!table data="""
394 15 ...... 13 | 12 ........... 10 | 9..... 7 | 6 ................. 2 | 1 .. 0 |
395 funct3 | imm | rs10 | imm | op |
396 3 | 3 | 3 | 5 | 2 |
397 C.BEQZ | offset[8,4:3] | src | offset[7:6,2:1,5] | C1 |
398 """]]
399
400 Now uses the CS format:
401
402 [[!table data="""
403 15 ...... 13 | 12 ........... 10 | 9..... 7 | 6 .. 5 | 4......... 2 | 1 .. 0 |
404 funct3 | imm | rs10 | imm | | op |
405 3 | 3 | 3 | 2 | 3 | 2 |
406 C.BEQZ | predicate rs3 | src1 | I/F B | src2 | C1 |
407 """]]
408
409 Bit 6 would be decoded as "operation refers to Integer or Float" including
410 interpreting src1 and src2 accordingly as outlined in Table 12.2 of the
411 "C" Standard, version 2.0,
412 whilst Bit 5 would allow the operation to be extended, in combination with
413 funct3 = 110 or 111: a combination of four distinct comparison operators.
414
415 ## Conclusions
416
417 In the above sections the five different ways where parallel instruction
418 execution has closely and loosely inter-related implications for the ISA and
419 for implementors, were outlined. The pluses and minuses came out as
420 follows:
421
422 * Fixed vs variable parallelism: <b>variable</b>
423 * Implicit (indirect) vs fixed (integral) instruction bit-width: <b>indirect</b>
424 * Implicit vs explicit type-conversion: <b>explicit</b>
425 * Implicit vs explicit inner loops: <b>implicit but best done separately</b>
426 * Tag or no-tag: <b>Complex but highly beneficial</b>
427
428 In particular:
429
430 * variable-length vectors came out on top because of the high setup, teardown
431 and corner-cases associated with the fixed width of SIMD.
432 * Implicit bit-width helps to extend the ISA to escape from
433 former limitations and restrictions (in a backwards-compatible fashion),
434 whilst also leaving implementors free to simmplify implementations
435 by using actual explicit internal parallelism.
436 * Implicit (zero-overhead) loops provide a means to keep pipelines
437 potentially 100% occupied in a single-issue in-order implementation
438 i.e. *without* requiring a super-scalar or out-of-order architecture,
439 but doing a proper, full job (ZOLC) is an entirely different matter.
440
441 Constructing a SIMD/Simple-Vector proposal based around four of these five
442 requirements would therefore seem to be a logical thing to do.
443
444 # Instruction Format
445
446 **TODO** *basically borrow from both P and V, which should be quite simple
447 to do, with the exception of Tag/no-tag, which needs a bit more
448 thought. V's Section 17.19 of Draft V2.3 spec is reminiscent of B's BGS
449 gather-scatterer, and, if implemented, could actually be a really useful
450 way to span 8-bit up to 64-bit groups of data, where BGS as it stands
451 and described by Clifford does **bits** of up to 16 width. Lots to
452 look at and investigate!*
453
454 # Note on implementation of parallelism
455
456 One extremely important aspect of this proposal is to respect and support
457 implementors desire to focus on power, area or performance. In that regard,
458 it is proposed that implementors be free to choose whether to implement
459 the Vector (or variable-width SIMD) parallelism as sequential operations
460 with a single ALU, fully parallel (if practical) with multiple ALUs, or
461 a hybrid combination of both.
462
463 In Broadcom's Videocore-IV, they chose hybrid, and called it "Virtual
464 Parallelism". They achieve a 16-way SIMD at an **instruction** level
465 by providing a combination of a 4-way parallel ALU *and* an externally
466 transparent loop that feeds 4 sequential sets of data into each of the
467 4 ALUs.
468
469 Also in the same core, it is worth noting that particularly uncommon
470 but essential operations (Reciprocal-Square-Root for example) are
471 *not* part of the 4-way parallel ALU but instead have a *single* ALU.
472 Under the proposed Vector (varible-width SIMD) implementors would
473 be free to do precisely that: i.e. free to choose *on a per operation
474 basis* whether and how much "Virtual Parallelism" to deploy.
475
476 It is absolutely critical to note that it is proposed that such choices MUST
477 be **entirely transparent** to the end-user and the compiler. Whilst
478 a Vector (varible-width SIM) may not precisely match the width of the
479 parallelism within the implementation, the end-user **should not care**
480 and in this way the performance benefits are gained but the ISA remains
481 straightforward. All that happens at the end of an instruction run is: some
482 parallel units (if there are any) would remain offline, completely
483 transparently to the ISA, the program, and the compiler.
484
485 The "SIMD considered harmful" trap of having huge complexity and extra
486 instructions to deal with corner-cases is thus avoided, and implementors
487 get to choose precisely where to focus and target the benefits of their
488 implementation efforts, without "extra baggage".
489
490 # Example of vector / vector, vector / scalar, scalar / scalar => vector add
491
492 register CSRvectorlen[XLEN][4]; # not quite decided yet about this one...
493 register CSRpredicate[XLEN][4]; # 2^4 is max vector length
494 register CSRreg_is_vectorised[XLEN]; # just for fun support scalars as well
495 register x[32][XLEN];
496
497 function op_add(rd, rs1, rs2, predr)
498 {
499    /* note that this is ADD, not PADD */
500    int i, id, irs1, irs2;
501    # checks CSRvectorlen[rd] == CSRvectorlen[rs] etc. ignored
502    # also destination makes no sense as a scalar but what the hell...
503    for (i = 0, id=0, irs1=0, irs2=0; i<CSRvectorlen[rd]; i++)
504       if (CSRpredicate[predr][i]) # i *think* this is right...
505          x[rd+id] <= x[rs1+irs1] + x[rs2+irs2];
506       # now increment the idxs
507       if (CSRreg_is_vectorised[rd]) # bitfield check rd, scalar/vector?
508          id += 1;
509       if (CSRreg_is_vectorised[rs1]) # bitfield check rs1, scalar/vector?
510          irs1 += 1;
511       if (CSRreg_is_vectorised[rs2]) # bitfield check rs2, scalar/vector?
512          irs2 += 1;
513 }
514
515 # V-Extension to Simple-V Comparative Analysis
516
517 This section covers the ways in which Simple-V is comparable
518 to, or more flexible than, V-Extension (V2.3-draft). Also covered is
519 one major weak-point (register files are fixed size, where V is
520 arbitrary length), and how best to deal with that, should V be adapted
521 to be on top of Simple-V.
522
523 The first stages of this section go over each of the sections of V2.3-draft V
524 where appropriate
525
526 ## 17.3 Shape Encoding
527
528 Simple-V's proposed means of expressing whether a register (from the
529 standard integer or the standard floating-point file) is a scalar or
530 a vector is to simply set the vector length to 1. The instruction
531 would however have to specify which register file (integer or FP) that
532 the vector-length was to be applied to.
533
534 Extended shapes (2-D etc) would not be part of Simple-V at all.
535
536 ## 17.4 Representation Encoding
537
538 Simple-V would not have representation-encoding. This is part of
539 polymorphism, which is considered too complex to implement (TODO: confirm?)
540
541 ## 17.5 Element Bitwidth
542
543 This is directly equivalent to Simple-V's "Packed", and implies that
544 integer (or floating-point) are divided down into vector-indexable
545 chunks of size Bitwidth.
546
547 In this way it becomes possible to have ADD effectively and implicitly
548 turn into ADDb (8-bit add), ADDw (16-bit add) and so on, and where
549 vector-length has been set to greater than 1, it becomes a "Packed"
550 (SIMD) instruction.
551
552 It remains to be decided what should be done when RV32 / RV64 ADD (sized)
553 opcodes are used. One useful idea would be, on an RV64 system where
554 a 32-bit-sized ADD was performed, to simply use the least significant
555 32-bits of the register (exactly as is currently done) but at the same
556 time to *respect the packed bitwidth as well*.
557
558 The extended encoding (Table 17.6) would not be part of Simple-V.
559
560 ## 17.6 Base Vector Extension Supported Types
561
562 TODO: analyse. probably exactly the same.
563
564 ## 17.7 Maximum Vector Element Width
565
566 No equivalent in Simple-V
567
568 ## 17.8 Vector Configuration Registers
569
570 TODO: analyse.
571
572 ## 17.9 Legal Vector Unit Configurations
573
574 TODO: analyse
575
576 ## 17.10 Vector Unit CSRs
577
578 TODO: analyse
579
580 > Ok so this is an aspect of Simple-V that I hadn't thought through,
581 > yet (proposal / idea only a few days old!).  in V2.3-Draft ISA Section
582 > 17.10 the CSRs are listed.  I note that there's some general-purpose
583 > CSRs (including a global/active vector-length) and 16 vcfgN CSRs.  i
584 > don't precisely know what those are for.
585
586 >  In the Simple-V proposal, *every* register in both the integer
587 > register-file *and* the floating-point register-file would have at
588 > least a 2-bit "data-width" CSR and probably something like an 8-bit
589 > "vector-length" CSR (less in RV32E, by exactly one bit).
590
591 >  What I *don't* know is whether that would be considered perfectly
592 > reasonable or completely insane.  If it turns out that the proposed
593 > Simple-V CSRs can indeed be stored in SRAM then I would imagine that
594 > adding somewhere in the region of 10 bits per register would be... okay? 
595 > I really don't honestly know.
596
597 >  Would these proposed 10-or-so-bit per-register Simple-V CSRs need to
598 > be multi-ported? No I don't believe they would.
599
600 ## 17.11 Maximum Vector Length (MVL)
601
602 Basically implicitly this is set to the maximum size of the register
603 file multiplied by the number of 8-bit packed ints that can fit into
604 a register (4 for RV32, 8 for RV64 and 16 for RV128).
605
606 ## !7.12 Vector Instruction Formats
607
608 No equivalent in Simple-V because *all* instructions of *all* Extensions
609 are implicitly parallelised (and packed).
610
611 ## 17.13 Polymorphic Vector Instructions
612
613 Polymorphism (implicit type-casting) is deliberately not supported
614 in Simple-V.
615
616 ## 17.14 Rapid Configuration Instructions
617
618 TODO: analyse if this is useful to have an equivalent in Simple-V
619
620 ## 17.15 Vector-Type-Change Instructions
621
622 TODO: analyse if this is useful to have an equivalent in Simple-V
623
624 ## 17.16 Vector Length
625
626 Has a direct corresponding equivalent.
627
628 ## 17.17 Predicated Execution
629
630 Predicated Execution is another name for "masking" or "tagging". Masked
631 (or tagged) implies that there is a bit field which is indexed, and each
632 bit associated with the corresponding indexed offset register within
633 the "Vector". If the tag / mask bit is 1, when a parallel operation is
634 issued, the indexed element of the vector has the operation carried out.
635 However if the tag / mask bit is *zero*, that particular indexed element
636 of the vector does *not* have the requested operation carried out.
637
638 In V2.3-draft V, there is a significant (not recommended) difference:
639 the zero-tagged elements are *set to zero*. This loses a *significant*
640 advantage of mask / tagging, particularly if the entire mask register
641 is itself a general-purpose register, as that general-purpose register
642 can be inverted, shifted, and'ed, or'ed and so on. In other words
643 it becomes possible, especially if Carry/Overflow from each vector
644 operation is also accessible, to do conditional (step-by-step) vector
645 operations including things like turn vectors into 1024-bit or greater
646 operands with very few instructions, by treating the "carry" from
647 one instruction as a way to do "Conditional add of 1 to the register
648 next door". If V2.3-draft V sets zero-tagged elements to zero, such
649 extremely powerful techniques are simply not possible.
650
651 It is noted that there is no mention of an equivalent to BEXT (element
652 skipping) which would be particularly fascinating and powerful to have.
653 In this mode, the "mask" would skip elements where its mask bit was zero
654 in either the source or the destination operand.
655
656 Lots to be discussed.
657
658 ## 17.18 Vector Load/Store Instructions
659
660 The Vector Load/Store instructions as proposed in V are extremely powerful
661 and can be used for reordering and regular restructuring.
662
663 Vector Load:
664
665 if (unit-strided) stride = elsize;
666 else stride = areg[as2]; // constant-strided
667 for (int i=0; i<vl; ++i)
668 if ([!]preg[p][i])
669 for (int j=0; j<seglen+1; j++)
670 vreg[vd+j][i] = mem[areg[as1] + (i*(seglen+1)+j)*stride];
671
672 Store:
673
674 if (unit-strided) stride = elsize;
675 else stride = areg[as2]; // constant-strided
676 for (int i=0; i<vl; ++i)
677 if ([!]preg[p][i])
678 for (int j=0; j<seglen+1; j++)
679 mem[areg[base] + (i*(seglen+1)+j)*stride] = vreg[vd+j][i];
680
681 Indexed Load:
682
683 for (int i=0; i<vl; ++i)
684 if ([!]preg[p][i])
685 for (int j=0; j<seglen+1; j++)
686 vreg[vd+j][i] = mem[sreg[base] + vreg[vs2][i] + j*elsize];
687
688 Indexed Store:
689
690 for (int i=0; i<vl; ++i)
691 if ([!]preg[p][i])
692 for (int j=0; j<seglen+1; j++)
693 mem[sreg[base] + vreg[vs2][i] + j*elsize] = vreg[vd+j][i];
694
695 Keeping these instructions as-is for Simple-V is highly recommended.
696 However: one of the goals of this Extension is to retro-fit (re-use)
697 existing RV Load/Store:
698
699 [[!table data="""
700 31 20 | 19 15 | 14 12 | 11 7 | 6 0 |
701 imm[11:0] | rs1 | funct3 | rd | opcode |
702 12 | 5 | 3 | 5 | 7 |
703 offset[11:0] | base | width | dest | LOAD |
704 """]]
705
706 [[!table data="""
707 31 25 | 24 20 | 19 15 | 14 12 | 11 7 | 6 0 |
708 imm[11:5] | rs2 | rs1 | funct3 | imm[4:0] | opcode |
709 7 | 5 | 5 | 3 | 5 | 7 |
710 offset[11:5] | src | base | width | offset[4:0] | STORE |
711 """]]
712
713
714 ## 17.19 Vector Register Gather
715
716 TODO
717
718 ## TODO, sort
719
720 > However, there are also several features that go beyond simply attaching VL
721 > to a scalar operation and are crucial to being able to vectorize a lot of
722 > code. To name a few:
723 > - Conditional execution (i.e., predicated operations)
724 > - Inter-lane data movement (e.g. SLIDE, SELECT)
725 > - Reductions (e.g., VADD with a scalar destination)
726
727 Ok so the Conditional and also the Reductions is one of the reasons
728 why as part of SimpleV / variable-SIMD / parallelism (gah gotta think
729 of a decent name) i proposed that it be implemented as "if you say r0
730 is to be a vector / SIMD that means operations actually take place on
731 r0,r1,r2... r(N-1)".
732
733 Consequently any parallel operation could be paused (or... more
734 specifically: vectors disabled by resetting it back to a default /
735 scalar / vector-length=1) yet the results would actually be in the
736 *main register file* (integer or float) and so anything that wasn't
737 possible to easily do in "simple" parallel terms could be done *out*
738 of parallel "mode" instead.
739
740 I do appreciate that the above does imply that there is a limit to the
741 length that SimpleV (whatever) can be parallelised, namely that you
742 run out of registers! my thought there was, "leave space for the main
743 V-Ext proposal to extend it to the length that V currently supports".
744 Honestly i had not thought through precisely how that would work.
745
746 Inter-lane (SELECT) i saw 17.19 in V2.3-Draft p117, I liked that,
747 it reminds me of the discussion with Clifford on bit-manipulation
748 (gather-scatter except not Bit Gather Scatter, *data* gather scatter): if
749 applied "globally and outside of V and P" SLIDE and SELECT might become
750 an extremely powerful way to do fast memory copy and reordering [2[.
751
752 However I haven't quite got my head round how that would work: i am
753 used to the concept of register "tags" (the modern term is "masks")
754 and i *think* if "masks" were applied to a Simple-V-enhanced LOAD /
755 STORE you would get the exact same thing as SELECT.
756
757 SLIDE you could do simply by setting say r0 vector-length to say 16
758 (meaning that if referred to in any operation it would be an implicit
759 parallel operation on *all* registers r0 through r15), and temporarily
760 set say.... r7 vector-length to say... 5. Do a LOAD on r7 and it would
761 implicitly mean "load from memory into r7 through r11". Then you go
762 back and do an operation on r0 and ta-daa, you're actually doing an
763 operation on a SLID {SLIDED?) vector.
764
765 The advantage of Simple-V (whatever) over V would be that you could
766 actually do *operations* in the middle of vectors (not just SLIDEs)
767 simply by (as above) setting r0 vector-length to 16 and r7 vector-length
768 to 5. There would be nothing preventing you from doing an ADD on r0
769 (which meant do an ADD on r0 through r15) followed *immediately in the
770 next instruction with no setup cost* a MUL on r7 (which actually meant
771 "do a parallel MUL on r7 through r11").
772
773 btw it's worth mentioning that you'd get scalar-vector and vector-scalar
774 implicitly by having one of the source register be vector-length 1
775 (the default) and one being N > 1. but without having special opcodes
776 to do it. i *believe* (or more like "logically infer or deduce" as
777 i haven't got access to the spec) that that would result in a further
778 opcode reduction when comparing [draft] V-Ext to [proposed] Simple-V.
779
780 Also, Reduction *might* be possible by specifying that the destination be
781 a scalar (vector-length=1) whilst the source be a vector. However... it
782 would be an awful lot of work to go through *every single instruction*
783 in *every* Extension, working out which ones could be parallelised (ADD,
784 MUL, XOR) and those that definitely could not (DIV, SUB). Is that worth
785 the effort? maybe. Would it result in huge complexity? probably.
786 Could an implementor just go "I ain't doing *that* as parallel!
787 let's make it virtual-parallelism (sequential reduction) instead"?
788 absolutely. So, now that I think it through, Simple-V (whatever)
789 covers Reduction as well. huh, that's a surprise.
790
791
792 > - Vector-length speculation (making it possible to vectorize some loops with
793 > unknown trip count) - I don't think this part of the proposal is written
794 > down yet.
795
796 Now that _is_ an interesting concept. A little scary, i imagine, with
797 the possibility of putting a processor into a hard infinite execution
798 loop... :)
799
800
801 > Also, note the vector ISA consumes relatively little opcode space (all the
802 > arithmetic fits in 7/8ths of a major opcode). This is mainly because data
803 > type and size is a function of runtime configuration, rather than of opcode.
804
805 yes. i love that aspect of V, i am a huge fan of polymorphism [1]
806 which is why i am keen to advocate that the same runtime principle be
807 extended to the rest of the RISC-V ISA [3]
808
809 Yikes that's a lot. I'm going to need to pull this into the wiki to
810 make sure it's not lost.
811
812 [1] inherent data type conversion: 25 years ago i designed a hypothetical
813 hyper-hyper-hyper-escape-code-sequencing ISA based around 2-bit
814 (escape-extended) opcodes and 2-bit (escape-extended) operands that
815 only required a fixed 8-bit instruction length. that relied heavily
816 on polymorphism and runtime size configurations as well. At the time
817 I thought it would have meant one HELL of a lot of CSRs... but then I
818 met RISC-V and was cured instantly of that delusion^Wmisapprehension :)
819
820 [2] Interestingly if you then also add in the other aspect of Simple-V
821 (the data-size, which is effectively functionally orthogonal / identical
822 to "Packed" of Packed-SIMD), masked and packed *and* vectored LOAD / STORE
823 operations become byte / half-word / word augmenters of B-Ext's proposed
824 "BGS" i.e. where B-Ext's BGS dealt with bits, masked-packed-vectored
825 LOAD / STORE would deal with 8 / 16 / 32 bits at a time. Where it
826 would get really REALLY interesting would be masked-packed-vectored
827 B-Ext BGS instructions. I can't even get my head fully round that,
828 which is a good sign that the combination would be *really* powerful :)
829
830 [3] ok sadly maybe not the polymorphism, it's too complicated and I
831 think would be much too hard for implementors to easily "slide in" to an
832 existing non-Simple-V implementation.  i say that despite really *really*
833 wanting IEEE 704 FP Half-precision to end up somewhere in RISC-V in some
834 fashion, for optimising 3D Graphics.  *sigh*.
835
836 ## TODO: analyse, auto-increment on unit-stride and constant-stride
837
838 so i thought about that for a day or so, and wondered if it would be
839 possible to propose a variant of zero-overhead loop that included
840 auto-incrementing the two address registers a2 and a3, as well as
841 providing a means to interact between the zero-overhead loop and the
842 vsetvl instruction. a sort-of pseudo-assembly of that would look like:
843
844 # a2 to be auto-incremented by t0 times 4
845 zero-overhead-set-auto-increment a2, t0, 4
846 # a2 to be auto-incremented by t0 times 4
847 zero-overhead-set-auto-increment a3, t0, 4
848 zero-overhead-set-loop-terminator-condition a0 zero
849 zero-overhead-set-start-end stripmine, stripmine+endoffset
850 stripmine:
851 vsetvl t0,a0
852 vlw v0, a2
853 vlw v1, a3
854 vfma v1, a1, v0, v1
855 vsw v1, a3
856 sub a0, a0, t0
857 stripmine+endoffset:
858
859 the question is: would something like this even be desirable? it's a
860 variant of auto-increment [1]. last time i saw any hint of auto-increment
861 register opcodes was in the 1980s... 68000 if i recall correctly... yep
862 see [1]
863
864 [1] http://fourier.eng.hmc.edu/e85_old/lectures/instruction/node6.html
865
866 Reply:
867
868 Another option for auto-increment is for vector-memory-access instructions
869 to support post-increment addressing for unit-stride and constant-stride
870 modes. This can be implemented by the scalar unit passing the operation
871 to the vector unit while itself executing an appropriate multiply-and-add
872 to produce the incremented address. This does *not* require additional
873 ports on the scalar register file, unlike scalar post-increment addressing
874 modes.
875
876 ## TODO: instructions (based on Hwacha) V-Ext duplication analysis
877
878 This is partly speculative due to lack of access to an up-to-date
879 V-Ext Spec (V2.3-draft RVV 0.4-Draft at the time of writing). However
880 basin an analysis instead on Hwacha, a cursory examination shows over
881 an **85%** duplication of V-Ext operand-related instructions when
882 compared to Simple-V on a standard RG64G base. Even Vector Fetch
883 is analogous to "zero-overhead loop".
884
885 Exceptions are:
886
887 * Vector Indexed Memory Instructions (non-contiguous)
888 * Vector Atomic Memory Instructions.
889 * Some of the Vector Misc ops: VEIDX, VFIRST, VCLASS, VPOPC
890 and potentially more.
891 * Consensual Jump
892
893 Table of RV32V Instructions
894
895 | RV32V | RV Equivalent (FP) | RV Equivalent (Int) | Notes |
896 | ----- | --- | | |
897 | VADD | FADD | ADD | |
898 | VSUB | FSUB | SUB | |
899 | VSL | | SLL | |
900 | VSR | | SRL | |
901 | VAND | | AND | |
902 | VOR | | OR | |
903 | VXOR | | XOR | |
904 | VSEQ | FEQ | BEQ | {1} |
905 | VSNE | !FEQ | BNE | {1} |
906 | VSLT | FLT | BLT | {1} |
907 | VSGE | !FLE | BGE | {1} |
908 | VCLIP | | | |
909 | VCVT | FCVT | | |
910 | VMPOP | | | |
911 | VMFIRST | | | |
912 | VEXTRACT | | | |
913 | VINSERT | | | |
914 | VMERGE | | | |
915 | VSELECT | | | |
916 | VSLIDE | | | |
917 | VDIV | FDIV | DIV | |
918 | VREM | | REM | |
919 | VMUL | FMUL | MUL | |
920 | VMULH | | | |
921 | VMIN | FMIN | | |
922 | VMAX | FMUX | | |
923 | VSGNJ | FSGNJ | | |
924 | VSGNJN | FSGNJN | | |
925 | VSGNJX | FSNGJX | | |
926 | VSQRT | FSQRT | | |
927 | VCLASS | | | |
928 | VPOPC | | | |
929 | VADDI | | ADDI | |
930 | VSLI | | SLI | |
931 | VSRI | | SRI | |
932 | VANDI | | ANDI | |
933 | VORI | | ORI | |
934 | VXORI | | XORI | |
935 | VCLIPI | | | |
936 | VMADD | FMADD | | |
937 | VMSUB | FMSUB | | |
938 | VNMADD | FNMSUB | | |
939 | VNMSUB | FNMADD | | |
940 | VLD | FLD | LD | |
941 | VLDS | | LW | |
942 | VLDX | | LWU | |
943 | VST | FST | ST | |
944 | VSTS | | | |
945 | VSTX | | | |
946 | VAMOSWAP | | AMOSWAP | |
947 | VAMOADD | | AMOADD | |
948 | VAMOAND | | AMOAND | |
949 | VAMOOR | | AMOOR | |
950 | VAMOXOR | | AMOXOR | |
951 | VAMOMIN | | AMOMIN | |
952 | VAMOMAX | | AMOMAX | |
953
954 Notes:
955
956 * {1} retro-fit predication variants into branch instructions (base and C),
957 decoding triggered by CSR bit marking register as "Vector type".
958
959 ## TODO: sort
960
961 > I suspect that the "hardware loop" in question is actually a zero-overhead
962 > loop unit that diverts execution from address X to address Y if a certain
963 > condition is met.
964
965  not quite.  The zero-overhead loop unit interestingly would be at
966 an [independent] level above vector-length.  The distinctions are
967 as follows:
968
969 * Vector-length issues *virtual* instructions where the register
970 operands are *specifically* altered (to cover a range of registers),
971 whereas zero-overhead loops *specifically* do *NOT* alter the operands
972 in *ANY* way.
973
974 * Vector-length-driven "virtual" instructions are driven by *one*
975 and *only* one instruction (whether it be a LOAD, STORE, or pure
976 one/two/three-operand opcode) whereas zero-overhead loop units
977 specifically apply to *multiple* instructions.
978
979 Where vector-length-driven "virtual" instructions might get conceptually
980 blurred with zero-overhead loops is LOAD / STORE.  In the case of LOAD /
981 STORE, to actually be useful, vector-length-driven LOAD / STORE should
982 increment the LOAD / STORE memory address to correspondingly match the
983 increment in the register bank.  example:
984
985 * set vector-length for r0 to 4
986 * issue RV32 LOAD from addr 0x1230 to r0
987
988 translates effectively to:
989
990 * RV32 LOAD from addr 0x1230 to r0
991 * ...
992 * ...
993 * RV32 LOAD from addr 0x123B to r3
994
995 # P-Ext ISA
996
997 ## 16-bit Arithmetic
998
999 | Mnemonic | 16-bit Instruction | Simple-V Equivalent |
1000 | ------------------ | ------------------------- | ------------------- |
1001 | ADD16 rt, ra, rb | add | RV ADD (bitwidth=16) |
1002 | RADD16 rt, ra, rb | Signed Halving add | |
1003 | URADD16 rt, ra, rb | Unsigned Halving add | |
1004 | KADD16 rt, ra, rb | Signed Saturating add | |
1005 | UKADD16 rt, ra, rb | Unsigned Saturating add | |
1006 | SUB16 rt, ra, rb | sub | RV SUB (bitwidth=16) |
1007 | RSUB16 rt, ra, rb | Signed Halving sub | |
1008 | URSUB16 rt, ra, rb | Unsigned Halving sub | |
1009 | KSUB16 rt, ra, rb | Signed Saturating sub | |
1010 | UKSUB16 rt, ra, rb | Unsigned Saturating sub | |
1011 | CRAS16 rt, ra, rb | Cross Add & Sub | |
1012 | RCRAS16 rt, ra, rb | Signed Halving Cross Add & Sub | |
1013 | URCRAS16 rt, ra, rb| Unsigned Halving Cross Add & Sub | |
1014 | KCRAS16 rt, ra, rb | Signed Saturating Cross Add & Sub | |
1015 | UKCRAS16 rt, ra, rb| Unsigned Saturating Cross Add & Sub | |
1016 | CRSA16 rt, ra, rb | Cross Sub & Add | |
1017 | RCRSA16 rt, ra, rb | Signed Halving Cross Sub & Add | |
1018 | URCRSA16 rt, ra, rb| Unsigned Halving Cross Sub & Add | |
1019 | KCRSA16 rt, ra, rb | Signed Saturating Cross Sub & Add | |
1020 | UKCRSA16 rt, ra, rb| Unsigned Saturating Cross Sub & Add | |
1021
1022 ## 8-bit Arithmetic
1023
1024 | Mnemonic | 16-bit Instruction | Simple-V Equivalent |
1025 | ------------------ | ------------------------- | ------------------- |
1026 | ADD8 rt, ra, rb | add | RV ADD (bitwidth=8)|
1027 | RADD8 rt, ra, rb | Signed Halving add | |
1028 | URADD8 rt, ra, rb | Unsigned Halving add | |
1029 | KADD8 rt, ra, rb | Signed Saturating add | |
1030 | UKADD8 rt, ra, rb | Unsigned Saturating add | |
1031 | SUB8 rt, ra, rb | sub | RV SUB (bitwidth=8)|
1032 | RSUB8 rt, ra, rb | Signed Halving sub | |
1033 | URSUB8 rt, ra, rb | Unsigned Halving sub | |
1034
1035 # Exceptions
1036
1037 > What does an ADD of two different-sized vectors do in simple-V?
1038
1039 * if the two source operands are not the same, throw an exception.
1040 * if the destination operand is also a vector, and the source is longer
1041 than the destination, throw an exception.
1042
1043 > And what about instructions like JALR? 
1044 > What does jumping to a vector do?
1045
1046 * Throw an exception. Whether that actually results in spawning threads
1047 as part of the trap-handling remains to be seen.
1048
1049 # Comparison of "Traditional" SIMD, Alt-RVP, Simple-V and RVV Proposals <a name="parallelism_comparisons"></a>
1050
1051 This section compares the various parallelism proposals as they stand,
1052 including traditional SIMD, in terms of features, ease of implementation,
1053 complexity, flexibility, and die area.
1054
1055 ## [[alt_rvp]]
1056
1057 Primary benefit of Alt-RVP is the simplicity with which parallelism
1058 may be introduced (effective multiplication of regfiles and associated ALUs).
1059
1060 * plus: the simplicity of the lanes (combined with the regularity of
1061 allocating identical opcodes multiple independent registers) meaning
1062 that SRAM or 2R1W can be used for entire regfile (potentially).
1063 * minus: a more complex instruction set where the parallelism is much
1064 more explicitly directly specified in the instruction and
1065 * minus: if you *don't* have an explicit instruction (opcode) and you
1066 need one, the only place it can be added is... in the vector unit and
1067 * minus: opcode functions (and associated ALUs) duplicated in Alt-RVP are
1068 not useable or accessible in other Extensions.
1069 * plus-and-minus: Lanes may be utilised for high-speed context-switching
1070 but with the down-side that they're an all-or-nothing part of the Extension.
1071 No Alt-RVP: no fast register-bank switching.
1072 * plus: Lane-switching would mean that complex operations not suited to
1073 parallelisation can be carried out, followed by further parallel Lane-based
1074 work, without moving register contents down to memory (and back)
1075 * minus: Access to registers across multiple lanes is challenging. "Solution"
1076 is to drop data into memory and immediately back in again (like MMX).
1077
1078 ## Simple-V
1079
1080 Primary benefit of Simple-V is the OO abstraction of parallel principles
1081 from actual hardware. It's an API in effect that's designed to be
1082 slotted in to an existing implementation (just after instruction decode)
1083 with minimum disruption and effort.
1084
1085 * minus: the complexity of having to use register renames, OoO, VLIW,
1086 register file cacheing, all of which has been done before but is a
1087 pain
1088 * plus: transparent re-use of existing opcodes as-is just indirectly
1089 saying "this register's now a vector" which
1090 * plus: means that future instructions also get to be inherently
1091 parallelised because there's no "separate vector opcodes"
1092 * plus: Compressed instructions may also be (indirectly) parallelised
1093 * minus: the indirect nature of Simple-V means that setup (setting
1094 a CSR register to indicate vector length, a separate one to indicate
1095 that it is a predicate register and so on) means a little more setup
1096 time than Alt-RVP or RVV's "direct and within the (longer) instruction"
1097 approach.
1098 * plus: shared register file meaning that, like Alt-RVP, complex
1099 operations not suited to parallelisation may be carried out interleaved
1100 between parallelised instructions *without* requiring data to be dropped
1101 down to memory and back (into a separate vectorised register engine).
1102 * plus-and-maybe-minus: re-use of integer and floating-point 32-wide register
1103 files means that huge parallel workloads would use up considerable
1104 chunks of the register file. However in the case of RV64 and 32-bit
1105 operations, that effectively means 64 slots are available for parallel
1106 operations.
1107 * plus: inherent parallelism (actual parallel ALUs) doesn't actually need to
1108 be added, yet the instruction opcodes remain unchanged (and still appear
1109 to be parallel). consistent "API" regardless of actual internal parallelism:
1110 even an in-order single-issue implementation with a single ALU would still
1111 appear to have parallel vectoristion.
1112 * hard-to-judge: if actual inherent underlying ALU parallelism is added it's
1113 hard to say if there would be pluses or minuses (on die area). At worse it
1114 would be "no worse" than existing register renaming, OoO, VLIW and register
1115 file cacheing schemes.
1116
1117 ## RVV (as it stands, Draft 0.4 Section 17, RISC-V ISA V2.3-Draft)
1118
1119 RVV is extremely well-designed and has some amazing features, including
1120 2D reorganisation of memory through LOAD/STORE "strides".
1121
1122 * plus: regular predictable workload means that implmentations may
1123 streamline effects on L1/L2 Cache.
1124 * plus: regular and clear parallel workload also means that lanes
1125 (similar to Alt-RVP) may be used as an implementation detail,
1126 using either SRAM or 2R1W registers.
1127 * plus: separate engine with no impact on the rest of an implementation
1128 * minus: separate *complex* engine with no RTL (ALUs, Pipeline stages) reuse
1129 really feasible.
1130 * minus: no ISA abstraction or re-use either: additions to other Extensions
1131 do not gain parallelism, resulting in prolific duplication of functionality
1132 inside RVV *and out*.
1133 * minus: when operations require a different approach (scalar operations
1134 using the standard integer or FP regfile) an entire vector must be
1135 transferred out to memory, into standard regfiles, then back to memory,
1136 then back to the vector unit, this to occur potentially multiple times.
1137 * minus: will never fit into Compressed instruction space (as-is. May
1138 be able to do so if "indirect" features of Simple-V are partially adopted).
1139 * plus-and-slight-minus: extended variants may address up to 256
1140 vectorised registers (requires 48/64-bit opcodes to do it).
1141 * minus-and-partial-plus: separate engine plus complexity increases
1142 implementation time and die area, meaning that adoption is likely only
1143 to be in high-performance specialist supercomputing (where it will
1144 be absolutely superb).
1145
1146 ## Traditional SIMD
1147
1148 The only really good things about SIMD are how easy it is to implement and
1149 get good performance. Unfortunately that makes it quite seductive...
1150
1151 * plus: really straightforward, ALU basically does several packed operations
1152 at once. Parallelism is inherent at the ALU, making the addition of
1153 SIMD-style parallelism an easy decision that has zero significant impact
1154 on the rest of any given architectural design and layout.
1155 * plus (continuation): SIMD in simple in-order single-issue designs can
1156 therefore result in superb throughput, easily achieved even with a very
1157 simple execution model.
1158 * minus: ridiculously complex setup and corner-cases that disproportionately
1159 increase instruction count on what would otherwise be a "simple loop",
1160 should the number of elements in an array not happen to exactly match
1161 the SIMD group width.
1162 * minus: getting data usefully out of registers (if separate regfiles
1163 are used) means outputting to memory and back.
1164 * minus: quite a lot of supplementary instructions for bit-level manipulation
1165 are needed in order to efficiently extract (or prepare) SIMD operands.
1166 * minus: MASSIVE proliferation of ISA both in terms of opcodes in one
1167 dimension and parallelism (width): an at least O(N^2) and quite probably
1168 O(N^3) ISA proliferation that often results in several thousand
1169 separate instructions. all requiring separate and distinct corner-case
1170 algorithms!
1171 * minus: EVEN BIGGER proliferation of SIMD ISA if the functionality of
1172 8, 16, 32 or 64-bit reordering is built-in to the SIMD instruction.
1173 For example: add (high|low) 16-bits of r1 to (low|high) of r2 requires
1174 four separate and distinct instructions: one for (r1:low r2:high),
1175 one for (r1:high r2:low), one for (r1:high r2:high) and one for
1176 (r1:low r2:low) *per function*.
1177 * minus: EVEN BIGGER proliferation of SIMD ISA if there is a mismatch
1178 between operand and result bit-widths. In combination with high/low
1179 proliferation the situation is made even worse.
1180 * minor-saving-grace: some implementations *may* have predication masks
1181 that allow control over individual elements within the SIMD block.
1182
1183 # Comparison *to* Traditional SIMD: Alt-RVP, Simple-V and RVV Proposals <a name="simd_comparison"></a>
1184
1185 This section compares the various parallelism proposals as they stand,
1186 *against* traditional SIMD as opposed to *alongside* SIMD. In other words,
1187 the question is asked "How can each of the proposals effectively implement
1188 (or replace) SIMD"?
1189
1190 ## [[alt_rvp]]
1191
1192 * Alt-RVP would not actually replace SIMD but would augment it: just as with
1193 a SIMD architecture where the ALU becomes responsible for the parallelism,
1194 Alt-RVP ALUs would likewise be so responsible... with *additional*
1195 (lane-based) parallelism on top.
1196 * Thus at least some of the downsides of SIMD are avoided (architectural
1197 upgrades introducing 128-bit then 256-bit then 512-bit variants of the
1198 exact same 64-bit SIMD block)
1199 * Thus, unfortunately, Alt-RVP would suffer the same inherent proliferation
1200 of instructions as SIMD, albeit not quite as badly (due to Lanes).
1201 * In the same discussion for Alt-RVP, an additional proposal was made to
1202 be able to subdivide the bits of each register lane (columns) down into
1203 arbitrary bit-lengths (RGB 565 for example).
1204 * A recommendation was given instead to make the subdivisions down to 32-bit,
1205 16-bit or even 8-bit, effectively dividing the registerfile into
1206 Lane0(H), Lane0(L), Lane1(H) ... LaneN(L) or further. If inter-lane
1207 "swapping" instructions were then introduced, some of the disadvantages
1208 of SIMD could be mitigated.
1209
1210 ## RVV
1211
1212 * RVV is designed to replace SIMD with a better paradigm: arbitrary-length
1213 parallelism.
1214 * However whilst SIMD is usually designed for single-issue in-order simple
1215 DSPs with a focus on Multimedia (Audio, Video and Image processing),
1216 RVV's primary focus appears to be on Supercomputing: optimisation of
1217 mathematical operations that fit into the OpenCL space.
1218 * Adding functions (operations) that would normally fit (in parallel)
1219 into a SIMD instruction requires an equivalent to be added to the
1220 RVV Extension, if one does not exist. Given the specialist nature of
1221 some SIMD instructions (8-bit or 16-bit saturated or halving add),
1222 this possibility seems extremely unlikely to occur, even if the
1223 implementation overhead of RVV were acceptable (compared to
1224 normal SIMD/DSP-style single-issue in-order simplicity).
1225
1226 ## Simple-V
1227
1228 * Simple-V borrows hugely from RVV as it is intended to be easy to
1229 topologically transplant every single instruction from RVV (as
1230 designed) into Simple-V equivalents, with *zero loss of functionality
1231 or capability*.
1232 * With the "parallelism" abstracted out, a hypothetical SIMD-less "DSP"
1233 Extension which contained the basic primitives (non-parallelised
1234 8, 16 or 32-bit SIMD operations) inherently *become* parallel,
1235 automatically.
1236 * Additionally, standard operations (ADD, MUL) that would normally have
1237 to have special SIMD-parallel opcodes added need no longer have *any*
1238 of the length-dependent variants (2of 32-bit ADDs in a 64-bit register,
1239 4of 32-bit ADDs in a 128-bit register) because Simple-V takes the
1240 *standard* RV opcodes (present and future) and automatically parallelises
1241 them.
1242 * By inheriting the RVV feature of arbitrary vector-length, then just as
1243 with RVV the corner-cases and ISA proliferation of SIMD is avoided.
1244 * Whilst not entirely finalised, registers are expected to be
1245 capable of being subdivided down to an implementor-chosen bitwidth
1246 in the underlying hardware (r1 becomes r1[31..24] r1[23..16] r1[15..8]
1247 and r1[7..0], or just r1[31..16] r1[15..0]) where implementors can
1248 choose to have separate independent 8-bit ALUs or dual-SIMD 16-bit
1249 ALUs that perform twin 8-bit operations as they see fit, or anything
1250 else including no subdivisions at all.
1251 * Even though implementors have that choice even to have full 64-bit
1252 (with RV64) SIMD, they *must* provide predication that transparently
1253 switches off appropriate units on the last loop, thus neatly fitting
1254 underlying SIMD ALU implementations *into* the arbitrary vector-length
1255 RVV paradigm, keeping the uniform consistent API that is a key strategic
1256 feature of Simple-V.
1257 * With Simple-V fitting into the standard register files, certain classes
1258 of SIMD operations such as High/Low arithmetic (r1[31..16] + r2[15..0])
1259 can be done by applying *Parallelised* Bit-manipulation operations
1260 followed by parallelised *straight* versions of element-to-element
1261 arithmetic operations, even if the bit-manipulation operations require
1262 changing the bitwidth of the "vectors" to do so. Predication can
1263 be utilised to skip high words (or low words) in source or destination.
1264 * In essence, the key downside of SIMD - massive duplication of
1265 identical functions over time as an architecture evolves from 32-bit
1266 wide SIMD all the way up to 512-bit, is avoided with Simple-V, through
1267 vector-style parallelism being dropped on top of 8-bit or 16-bit
1268 operations, all the while keeping a consistent ISA-level "API" irrespective
1269 of implementor design choices (or indeed actual implementations).
1270
1271 # Impementing V on top of Simple-V
1272
1273 * Number of Offset CSRs extends from 2
1274 * Extra register file: vector-file
1275 * Setup of Vector length and bitwidth CSRs now can specify vector-file
1276 as well as integer or float file.
1277 * TODO
1278
1279 # Implementing P (renamed to DSP) on top of Simple-V
1280
1281 * Implementors indicate chosen bitwidth support in Vector-bitwidth CSR
1282 (caveat: anything not specified drops through to software-emulation / traps)
1283 * TODO
1284
1285 # Register reordering <a name="register_reordering"></a>
1286
1287 ## Register File
1288
1289 | Reg Num | Bits |
1290 | ------- | ---- |
1291 | r0 | (32..0) |
1292 | r1 | (32..0) |
1293 | r2 | (32..0) |
1294 | r3 | (32..0) |
1295 | r4 | (32..0) |
1296 | r5 | (32..0) |
1297 | r6 | (32..0) |
1298 | r7 | (32..0) |
1299
1300 ## Vectorised CSR
1301
1302 May not be an actual CSR: may be generated from Vector Length CSR:
1303 single-bit is less burdensome on instruction decode phase.
1304
1305 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
1306 | - | - | - | - | - | - | - | - |
1307 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 |
1308
1309 ## Vector Length CSR
1310
1311 | Reg Num | (3..0) |
1312 | ------- | ---- |
1313 | r0 | 2 |
1314 | r1 | 0 |
1315 | r2 | 1 |
1316 | r3 | 1 |
1317 | r4 | 3 |
1318 | r5 | 0 |
1319 | r6 | 0 |
1320 | r7 | 1 |
1321
1322 ## Virtual Register Reordering:
1323
1324 | Reg Num | Bits (0) | Bits (1) | Bits (2) |
1325 | ------- | -------- | -------- | -------- |
1326 | r0 | (32..0) | (32..0) |
1327 | r2 | (32..0) |
1328 | r3 | (32..0) |
1329 | r4 | (32..0) | (32..0) | (32..0) |
1330 | r7 | (32..0) |
1331
1332 ## Example Instruction translation: <a name="example_translation"></a>
1333
1334 Instructions "ADD r2 r4 r4" would result in three instructions being
1335 generated and placed into the FILO:
1336
1337 * ADD r2 r4 r4
1338 * ADD r2 r5 r5
1339 * ADD r2 r6 r6
1340
1341 ## Insights
1342
1343 SIMD register file splitting still to consider. For RV64, benefits of doubling
1344 (quadrupling in the case of Half-Precision IEEE754 FP) the apparent
1345 size of the floating point register file to 64 (128 in the case of HP)
1346 seem pretty clear and worth the complexity.
1347
1348 64 virtual 32-bit F.P. registers and given that 32-bit FP operations are
1349 done on 64-bit registers it's not so conceptually difficult.  May even
1350 be achieved by *actually* splitting the regfile into 64 virtual 32-bit
1351 registers such that a 64-bit FP scalar operation is dropped into (r0.H
1352 r0.L) tuples.  Implementation therefore hidden through register renaming.
1353
1354 Implementations intending to introduce VLIW, OoO and parallelism
1355 (even without Simple-V) would then find that the instructions are
1356 generated quicker (or in a more compact fashion that is less heavy
1357 on caches). Interestingly we observe then that Simple-V is about
1358 "consolidation of instruction generation", where actual parallelism
1359 of underlying hardware is an implementor-choice that could just as
1360 equally be applied *without* Simple-V even being implemented.
1361
1362 # Analysis of CSR decoding on latency <a name="csr_decoding_analysis"></a>
1363
1364 It could indeed have been logically deduced (or expected), that there
1365 would be additional decode latency in this proposal, because if
1366 overloading the opcodes to have different meanings, there is guaranteed
1367 to be some state, some-where, directly related to registers.
1368
1369 There are several cases:
1370
1371 * All operands vector-length=1 (scalars), all operands
1372 packed-bitwidth="default": instructions are passed through direct as if
1373 Simple-V did not exist.  Simple-V is, in effect, completely disabled.
1374 * At least one operand vector-length > 1, all operands
1375 packed-bitwidth="default": any parallel vector ALUs placed on "alert",
1376 virtual parallelism looping may be activated.
1377 * All operands vector-length=1 (scalars), at least one
1378 operand packed-bitwidth != default: degenerate case of SIMD,
1379 implementation-specific complexity here (packed decode before ALUs or
1380 *IN* ALUs)
1381 * At least one operand vector-length > 1, at least one operand
1382 packed-bitwidth != default: parallel vector ALUs (if any)
1383 placed on "alert", virtual parallelsim looping may be activated,
1384 implementation-specific SIMD complexity kicks in (packed decode before
1385 ALUs or *IN* ALUs).
1386
1387 Bear in mind that the proposal includes that the decision whether
1388 to parallelise in hardware or whether to virtual-parallelise (to
1389 dramatically simplify compilers and also not to run into the SIMD
1390 instruction proliferation nightmare) *or* a transprent combination
1391 of both, be done on a *per-operand basis*, so that implementors can
1392 specifically choose to create an application-optimised implementation
1393 that they believe (or know) will sell extremely well, without having
1394 "Extra Standards-Mandated Baggage" that would otherwise blow their area
1395 or power budget completely out the window.
1396
1397 Additionally, two possible CSR schemes have been proposed, in order to
1398 greatly reduce CSR space:
1399
1400 * per-register CSRs (vector-length and packed-bitwidth)
1401 * a smaller number of CSRs with the same information but with an *INDEX*
1402 specifying WHICH register in one of three regfiles (vector, fp, int)
1403 the length and bitwidth applies to.
1404
1405 (See "CSR vector-length and CSR SIMD packed-bitwidth" section for details)
1406
1407 In addition, LOAD/STORE has its own associated proposed CSRs that
1408 mirror the STRIDE (but not yet STRIDE-SEGMENT?) functionality of
1409 V (and Hwacha).
1410
1411 Also bear in mind that, for reasons of simplicity for implementors,
1412 I was coming round to the idea of permitting implementors to choose
1413 exactly which bitwidths they would like to support in hardware and which
1414 to allow to fall through to software-trap emulation.
1415
1416 So the question boils down to:
1417
1418 * whether either (or both) of those two CSR schemes have significant
1419 latency that could even potentially require an extra pipeline decode stage
1420 * whether there are implementations that can be thought of which do *not*
1421 introduce significant latency
1422 * whether it is possible to explicitly (through quite simply
1423 disabling Simple-V-Ext) or implicitly (detect the case all-vlens=1,
1424 all-simd-bitwidths=default) switch OFF any decoding, perhaps even to
1425 the extreme of skipping an entire pipeline stage (if one is needed)
1426 * whether packed bitwidth and associated regfile splitting is so complex
1427 that it should definitely, definitely be made mandatory that implementors
1428 move regfile splitting into the ALU, and what are the implications of that
1429 * whether even if that *is* made mandatory, is software-trapped
1430 "unsupported bitwidths" still desirable, on the basis that SIMD is such
1431 a complete nightmare that *even* having a software implementation is
1432 better, making Simple-V have more in common with a software API than
1433 anything else.
1434
1435 Whilst the above may seem to be severe minuses, there are some strong
1436 pluses:
1437
1438 * Significant reduction of V's opcode space: over 85%.
1439 * Smaller reduction of P's opcode space: around 10%.
1440 * The potential to use Compressed instructions in both Vector and SIMD
1441 due to the overloading of register meaning (implicit vectorisation,
1442 implicit packing)
1443 * Not only present but also future extensions automatically gain parallelism.
1444 * Already mentioned but worth emphasising: the simplification to compiler
1445 writers and assembly-level writers of having the same consistent ISA
1446 regardless of whether the internal level of parallelism (number of
1447 parallel ALUs) is only equal to one ("virtual" parallelism), or is
1448 greater than one, should not be underestimated.
1449
1450 # Appendix
1451
1452 # Reducing Register Bank porting
1453
1454 This looks quite reasonable.
1455 <https://www.princeton.edu/~rblee/ELE572Papers/MultiBankRegFile_ISCA2000.pdf>
1456
1457 The main details are outlined on page 4.  They propose a 2-level register
1458 cache hierarchy, note that registers are typically only read once, that
1459 you never write back from upper to lower cache level but always go in a
1460 cycle lower -> upper -> ALU -> lower, and at the top of page 5 propose
1461 a scheme where you look ahead by only 2 instructions to determine which
1462 registers to bring into the cache.
1463
1464 The nice thing about a vector architecture is that you *know* that
1465 *even more* registers are going to be pulled in: Hwacha uses this fact
1466 to optimise L1/L2 cache-line usage (avoid thrashing), strangely enough
1467 by *introducing* deliberate latency into the execution phase.
1468
1469
1470
1471 # References
1472
1473 * SIMD considered harmful <https://www.sigarch.org/simd-instructions-considered-harmful/>
1474 * Link to first proposal <https://groups.google.com/a/groups.riscv.org/forum/#!topic/isa-dev/GuukrSjgBH8>
1475 * Recommendation by Jacob Bachmeyer to make zero-overhead loop an
1476 "implicit program-counter" <https://groups.google.com/a/groups.riscv.org/d/msg/isa-dev/vYVi95gF2Mo/SHz6a4_lAgAJ>
1477 * Re-continuing P-Extension proposal <https://groups.google.com/a/groups.riscv.org/forum/#!msg/isa-dev/IkLkQn3HvXQ/SEMyC9IlAgAJ>
1478 * First Draft P-SIMD (DSP) proposal <https://groups.google.com/a/groups.riscv.org/forum/#!topic/isa-dev/vYVi95gF2Mo>
1479 * B-Extension discussion <https://groups.google.com/a/groups.riscv.org/forum/#!topic/isa-dev/zi_7B15kj6s>
1480 * Broadcom VideoCore-IV <https://docs.broadcom.com/docs/12358545>
1481 Figure 2 P17 and Section 3 on P16.
1482 * Hwacha <https://www2.eecs.berkeley.edu/Pubs/TechRpts/2015/EECS-2015-262.html>
1483 * Hwacha <https://www2.eecs.berkeley.edu/Pubs/TechRpts/2015/EECS-2015-263.html>
1484 * Vector Workshop <http://riscv.org/wp-content/uploads/2015/06/riscv-vector-workshop-june2015.pdf>
1485 * Predication <https://groups.google.com/a/groups.riscv.org/forum/#!topic/isa-dev/XoP4BfYSLXA>
1486 * Branch Divergence <https://jbush001.github.io/2014/12/07/branch-divergence-in-parallel-kernels.html>
1487 * Life of Triangles (3D) <https://jbush001.github.io/2016/02/27/life-of-triangle.html>
1488 * Videocore-IV <https://github.com/hermanhermitage/videocoreiv/wiki/VideoCore-IV-3d-Graphics-Pipeline>
1489 * Discussion proposing CSRs that change ISA definition
1490 <https://groups.google.com/a/groups.riscv.org/forum/#!topic/isa-dev/InzQ1wr_3Ak>
1491 * Zero-overhead loops <https://pdfs.semanticscholar.org/dbaa/66985cc730d4b44d79f519e96ec9c43ab5b7.pdf>
1492 * Multi-ported VLIW Register File Implementation <https://ce-publications.et.tudelft.nl/publications/1517_multiple_contexts_in_a_multiported_vliw_register_file_impl.pdf>
1493 * Fast context save/restore proposal <https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/57F823FA.6030701%40gmail.com>
1494 * Register File Bank Cacheing <https://www.princeton.edu/~rblee/ELE572Papers/MultiBankRegFile_ISCA2000.pdf>