add notes on example Function Unit allocation
[libreriscv.git] / 3d_gpu / architecture / 6600scoreboard.mdwn
1 # 6600-style Scoreboards
2
3 Images reproduced with kind permission from Mitch Alsup
4
5 # Notes and insights on Scoreboard design
6
7 btw one thing that's not obvious - at all - about scoreboards is: there's nothing that seems to "control" how instructions "know" to read, write, or complete.  it's very... weird.  i'll probably put this on the discussion page.
8
9 the reason i feel that the weirdness exists is for a few reasons:
10
11 * firstly, the Matrices create a Directed Acyclic Graph, using single-bit
12 SR-Latches.  for a software engineer, being able to express a DAG using
13 a matrix is itself.. .weird :)
14 * secondly: those Matrices preserve time *order* (instruction
15 dependent order actually), they are not themselves dependent *on* time
16 itself.  this is especially weird if one is used to an in-order system,
17 which is very much critically dependent on "time" and on strict observance
18 of how long results are going to take to get through a pipeline.  we
19 could do the entire design based around low-gate-count FSMs and it would
20 still be absolutely fine.
21 * thirdly, it's the *absence* of blocks that allows a unit to
22 proceed.  unlike an in-order system, there's nothing saying "you go now,
23 you go now": it's the opposite.  the unit is told instead, "here's the
24 resources you need to WAIT for: go when those resources are available".
25 * fourth (clarifying 3): it's reads that block writes, and writes
26 that block reads.  although obvious when thought through from first
27 principles, it can get particularly confusing that it is the *absence*
28 of read hazards that allow writes to proceed, and the *absence* of write
29 hazards that allow reads to proceed.
30 * fifth: the ComputationUnits still need to "manage" the input and output
31 of those resources to actual pipelines (or FSMs).
32 - (a) the CUs are *not* permitted to blithely say, if there is an
33 expected output that also needs managing "ok i got the inputs, now throw
34 them at the pipeline, i'm done".  they *must* wait for that result.  of
35 course if there is no result to wait for, they're permitted to indicate
36 "done" without waiting (this actually happens in the case of STORE).
37 - (b) there's an apparent disconnect between "fetching of registers"
38 and "Computational Unit progress".  surely, one feels, there should
39 be something that, again, "orders the CU to proceed in a set, orderly
40 progressive fashion?".  instead, because the progress is from the
41 *absence* of hazards, the CU's FSMs likewise make forward progress from
42 the "acknowledgement" of each blockage being dropped.
43 * sixth: one of the incredible but puzzling things is that register
44 renaming is *automatically* built-in to the design.  the Function Unit's
45 input and output latches are effectively "nameless" registers.
46 - (a) the more Function Units you have, the more nameless registers
47 exist.  the more nameless registers exist, the further ahead that
48 in-flight execution can progress, speculatively.
49 - (b) whilst the Function Units are devoid of register "name"
50 information, the FU-Regs Dependency Matrix is *not* devoid of that
51 information, having latched the read/write register numbers in an unary
52 form, as a "row", one bit in each row representing which register(s)
53 the instruction originally contained.
54 - (c) by virtue of the direct Operand Port connectivity between the FU
55 and its corresponding FU-Regs DM "row", the Function Unit requesting for
56 example Operand1 results in the FU-Regs DM *row* triggering a register
57 file read-enable line, *NOT* the Function Unit itself.
58 * seventh: the PriorityPickers manage resource contention between the FUs
59 and the row-information from the FU-Regs Matrix.  the port bandwidth
60 by nature has to be limited (we cannot have 200 read/write ports on
61 the regfile).  therefore the connection between the FU and the FU-Regs
62 "row" in which the actual reg numbers is stored (in unary) is even *less*
63 direct than it is in an in-order system.
64
65 ultimately then, there is:
66
67 * an FU-Regs Matrix that, on a per-row basis, captures the instruction's
68 register numbering (in unary, one SR-Latch raised per register per row)
69 on a per-operand basis
70 * an FU-FU Matrix that preserves, as a Directed Acyclic Graph (DAG),
71 the instruction order.  again, this is a bit-based system (SR Latches)
72 that record which *read port* of the Function Unit needs a write result
73 (when available).
74 * a suite of Function Units with input *and* output latches where the
75 register information is *removed* (that being back in the FU-Regs row
76 associated with a given FU)
77 * a PriorityPicker system that acknowledges the desire for access to the
78 register file, and, due to the regfile ports being a contended resource,
79 *only* permits one and only one FunctionUnit at a time to gain access to
80 that regfile port.  where the FunctionUnit knows the Operand number it
81 requires the input (or output) to come from (or to), it is the FU-Regs
82 *row* that knows, on a per-operand-number basis, what the actual register
83 file number is.
84
85 # Example allocation of Function Units
86
87 This is the key diagram showing the relationship between Function Units
88 and the Register File(s).
89
90 The Dependency Matrices manage the DAG of read-write relationships:
91 each Function Unit indicates which registers it requires for read
92 and which it needs permission to write to.
93
94 NOTE: **AT NO TIME** is **any** Function Unit permitted "direct" access to
95 global resources by way of any form of "unmanaged" path. Each Function
96 Unit may **only** receive incoming data and may **only** pass that data
97 out via the set determined path, as controlled by the Dependency Matrices.
98
99 An augmentation of this arrangement, for a modern processor using pipelines,
100 is to "double up" (or triple, or quadruple etc.) the number of Function
101 Units, but to *share the same pipeline*. See "Concurrent Computation Unit"
102 section below for details.
103
104 [[!img multiple_function_units.png size="600x"]]
105
106 # Modifications needed to Computation Unit and Group Picker
107
108 The scoreboard uses two big NOR gates respectively to determine when there
109 are no read/write hazards. These two NOR gates are permanently active
110 (per Function Unit) even if the Function Unit is idle.
111
112 In the case of the Write path, these "permanently-on" signals are gated
113 by a Write-Release-Request signal that would otherwise leave the Priority
114 Picker permanently selecting one of the Function Units (the highest priority).
115 However the same thing has to be done for the read path, as well.
116
117 Below are the modifications required to add a read-release path that
118 will prevent a Function Unit from requesting a GoRead signal when it
119 has no need to read registers. Note that once both the Busy and GoRead
120 signals combined are dropped, the ReadRelease is dropped.
121
122 Note that this is a loop: GoRead (ANDed with Busy) goes through
123 to the priority picker, which generates GoRead, so it is critical
124 (in a modern design) to use a clock-sync'd latch in this path.
125 The original 6600 used rising-edge and falling-edge of the clock
126 to avoid this issue.
127
128 [[!img comp_unit_req_rel.jpg]]
129 [[!img group_pick_rd_rel.jpg]]
130
131 [[!img priority_picker_16_yosys.png size="400x"]]
132
133 Source:
134
135 * [Priority Pickers](https://git.libre-riscv.org/?p=nmutil.git;a=blob;f=src/nmutil/picker.py;hb=HEAD)
136 * [ALU Comp Units](https://git.libre-riscv.org/?p=soc.git;a=blob;f=src/soc/experiment/compalu.py;h=f7b5e411a739e770777ceb71d7bd09fe4e70e8c0;hb=b08dee1c3e8cf0d635820693fe50cd0518caeed2)
137
138 # Concurrent Computational Unit
139
140 With the original 6600 having only a 2-stage pipelined FPU (which took
141 many years to notice from examining the now-archaic notation from James
142 Thornton's book, "Design of a Computer"), there is no actual use of this
143 pipeline capability at the front-end Function Unit. Instead it is
144 treated effectively as a Finite State Machine, only one result to be
145 computed at a time.
146
147 Mitch Alsup recommends, when using pipelines, to allow multiple
148 Function Unit "front-ends", each one having inputs that were pushed
149 into a particular stage of the pipeline, and, therefore, those multiple
150 Function Units also track and store the result as it comes out.
151
152 The trick then is to have a method that ensures that FU front-end #1
153 can get result #1 when it pops out the end of the (serial) pipeline.
154 Mitch recommends using timing chains, here.
155
156 Note in this diagram that there are *multiple* ISSUE, GO\_READ and GO\_WRITE
157 signals. These link up to the Function Unit's ISSUE, GO\_RD and GO\_WR,
158 where the latches are, that will (on an available slot) feed the pipeline
159 with incoming data.
160
161 [[!img concurrent_comp_unit.png size="600x"]]
162
163 The actual design being used is slightly different, in the following
164 ways:
165
166 * Due to micro-coding and thus external contention, the pipelines
167 have a ready/valid signalling arrangement that can result in
168 a stall cascading back down the pipeline. Thus a timing chain
169 is not appropriate.
170 * A decision was therefore made to pass a "context" alongside the
171 operands, which is the "Function Unit Index". It is *this* information
172 that is used to "reassociate" the result with the correct FU, when
173 the result is produced.
174 * With "Shadow cancellation" being in effect, *additional* global
175 context is passed (combinatorially) to every single stage of the
176 pipeline, as an unary bitmask. If any Function Unit's "GO_DIE"
177 signal is asserted, the corresponding bit in the unary mask is
178 asserted, terminating effective immediate the intermediary data
179 anywhere in the pipeline from progressing further, thus saving power.
180
181
182 # Multi-in cascading Priority Picker
183
184 Using the Group Picker as a fundamental unit, a cascading chain is created,
185 with each output "masking" an output from being selected in all down-chain
186 Pickers. Whilst the input is a single unary array of bits, the output is
187 *multiple* unary arrays where only one bit in each is set.
188
189 This can be used for "port selection", for example when there are multiple
190 Register File ports or multiple LOAD/STORE cache "ways", and there are many
191 more devices seeking access to those "ports" than there are actual ports.
192 (If the number of devices seeking access to ports were equal to the number
193 of ports, each device could be allocated its own dedicated port).
194
195 Click on image to see full-sized version:
196
197 [[!img multi_priority_picker.png size="800x"]]
198
199 Links:
200
201 * [Priority Pickers](https://git.libre-riscv.org/?p=nmutil.git;a=blob;f=src/nmutil/picker.py;hb=HEAD)
202 * <http://lists.libre-riscv.org/pipermail/libre-riscv-dev/2020-March/005204.html>
203
204 # Modifications to Dependency Cell
205
206 Note: this version still requires CLK to operate on a HI-LO cycle.
207 Further modifications are needed to create an ISSUE-GORD-PAUSE ISSUE-GORD-PAUSE
208 sequence. For now however it is easier to stick with the original
209 diagrams produced by Mitch Alsup.
210
211 The dependency cell is responsible for recording that a Function Unit
212 requires the use of a dest or src register, which is given in UNARY.
213 It is also responsible for "defending" that unary register bit for
214 read and write hazards, and for also, on request (GoRead/GoWrite)
215 generating a "Register File Select" signal.
216
217 The sequence of operations for determining hazards is as follows:
218
219 * Issue goes HI when CLK is HI. If any of Dest / Oper1 / Oper2 are also HI,
220 the relevant SRLatch will go HI to indicate that this Function Unit requires
221 the use of this dest/src register
222 * Bear in mind that this cell works in conjunction with the FU-FU cells
223 * Issue is LOW when CLK is HI. This is where the "defending" comes into
224 play. There will be *another* Function Unit somewhere that has had
225 its Issue line raised. This cell needs to know if there is a conflict
226 (Read Hazard or Write Hazard).
227 * Therefore, *this* cell must, if either of the Oper1/Oper2 signals are
228 HI, output a "Read after Write" (RaW) hazard if its Dest Latch (Dest-Q) is HI.
229 This is the *Read_Pending* signal.
230 * Likewise, if either of the two SRC Latches (Oper1-Q or Oper2-Q) are HI,
231 this cell must output a "Write after Read" (WaR) hazard if the (other)
232 instruction has raised the unary Dest line.
233
234 The sequence for determining register select is as follows:
235
236 * After the Issue+CLK-HI has resulted in the relevant (unary) latches for
237 dest and src (unary) latches being set, at some point a GoRead (or GoWrite)
238 signal needs to be asserted
239 * The GoRead (or GoWrite) is asserted when *CLK is LOW*. The AND gate
240 on Reset ensures that the SRLatch *remains ENABLED*.
241 * This gives an opportunity for the Latch Q to be ANDed with the GoRead
242 (or GoWrite), raising an indicator flag that the register is being
243 "selected" by this Function Unit.
244 * The "select" outputs from the entire column (all Function Units for this
245 unary Register) are ORed together. Given that only one GoRead (or GoWrite)
246 is guaranteed to be ASSERTed (because that is the Priority Picker's job),
247 the ORing is acceptable.
248 * Whilst the GoRead (or GoWrite) signal is still asserted HI, the *CLK*
249 line goes *LOW*. With the Reset-AND-gate now being HI, this *clears* the
250 latch. This is the desired outcome because in the previous cycle (which
251 happened to be when CLK was LOW), the register file was read (or written)
252
253 The release of the latch happens to have a by-product of releasing the
254 "reservation", such that future instructions, if they ever test for
255 Read/Write hazards, will find that this Cell no longer responds: the
256 hazard has already passed as this Cell already indicated that it was
257 safe to read (or write) the register file, freeing up future instructions
258 from hazards in the process.
259
260 [[!img dependence_cell_pending.jpg]]
261
262 # Shadowing
263
264 Shadowing is important as it is the fundamental basis of:
265
266 * Precise exceptions
267 * Write-after-write hazard avoidance
268 * Correct multi-issue instruction sequencing
269 * Branch speculation
270
271 Modifications to the shadow circuit below allow the shadow flip-flops
272 to be automatically reset after a Function Unit "dies". Without these
273 modifications, the shadow unit may spuriously fire on subsequent re-use
274 due to some of the latches being left in a previous state.
275
276 Note that only "success" will cause the latch to reset. Note also
277 that the introduction of the NOT gate causes the latch to be more like
278 a DFF (register).
279
280 [[!img shadow.jpg]]
281
282 # LD/ST Computation Unit
283
284 Discussions:
285
286 * <http://lists.libre-riscv.org/pipermail/libre-riscv-dev/2020-April/006167.html>
287 * <https://groups.google.com/forum/#!topic/comp.arch/qeMsE7UxvlI>
288
289 Walk-through Videos:
290
291 * <https://www.youtube.com/watch?v=idDn1norNl0>
292 * <https://www.youtube.com/watch?v=ipOe0cLOJWc>
293
294 The Load/Store Computation Unit is a little more complex, involving
295 three functions: LOAD, STORE, and LOAD-UPDATE. The SR Latches create
296 a forward-progressing Finite State Machine, with three possible paths:
297
298 * LD Mode will activate Issue, GoRead1, GoAddr then finally GoWrite1
299 * LD-UPDATE Mode will *additionally* activate GoWrite2.
300 * ST Mode will activate Issue, GoRead1, GoRead2, GoAddr then GoStore.
301 ST-UPDATE Mode will *additionally* activate GoWrite2.
302
303 These signals will be allowed to activate when the correct "Req" lines
304 are active. Minor complications are involved (extra latches) that respond
305 to an external API interface that has a more "traditional" valid/ready
306 signalling interface, with single-clock responses.
307
308 Source:
309
310 * [LD/ST Comp Units](https://git.libre-riscv.org/?p=soc.git;a=blob;f=src/soc/experiment/compldst.py)
311
312 [[!img ld_st_comp_unit.jpg]]
313
314 # Memory-Memory Dependency Matrix
315
316 Due to the possibility of more than on LD/ST being in flight, it is necessary
317 to determine which memory operations are conflicting, and to preserve a
318 semblance of order. It turns out that as long as there is no *possibility*
319 of overlaps (note this wording carefully), and that LOADs are done separately
320 from STOREs, this is sufficient.
321
322 The first step then is to ensure that only a mutually-exclusive batch of LDs
323 *or* STs (not both) is detected, with the order between such batches being
324 preserved. This is what the memory-memory dependency matrix does.
325
326 "WAR" stands for "Write After Read" and is an SR Latch. "RAW" stands for
327 "Read After Write" and likewise is an SR Latch. Any LD which comes in
328 when a ST is pending will result in the relevant RAW SR Latch going active.
329 Likewise, any ST which comes in when a LD is pending results in the
330 relevant WAR SR Latch going active.
331
332 LDs can thus be prevented when it has any dependent RAW hazards active,
333 and likewise STs can be prevented when any dependent WAR hazards are active.
334 The matrix also ensures that ordering is preserved.
335
336 Note however that this is the equivalent of an ALU "FU-FU" Matrix. A
337 separate Register-Mem Dependency Matrix is *still needed* in order to
338 preserve the **register** read/write dependencies that occur between
339 instructions, where the Mem-Mem Matrix simply protects against memory
340 hazards.
341
342 Note also that it does not detect address clashes: that is the responsibility
343 of the Address Match Matrix.
344
345 Source:
346
347 * [Memory-Dependency Row](https://git.libre-riscv.org/?p=soc.git;a=blob;f=src/soc/scoreboard/mem_dependence_cell.py;h=2958d864cec75480b97a0725d9b3c44f53d2e7a0;hb=a0e1af6c5dab5c324a8bf3a7ce6eb665d26a65c1)
348 * [Memory-Dependency Matrix](https://git.libre-riscv.org/?p=soc.git;a=blob;f=src/soc/scoreboard/mem_fu_matrix.py;h=6b9ce140312290a26babe2e3e3d821ae3036e3ab;hb=a0e1af6c5dab5c324a8bf3a7ce6eb665d26a65c1)
349
350 [[!img ld_st_dep_matrix.png size="600x"]]
351
352 # Address Match Matrix
353
354 This is an important adjunct to the Memory Dependency Matrices: it ensures
355 that no LDs or STs overlap, because if they did it could result in memory
356 corruption. Example: a 64-bit ST at address 0x0001 comes in at the
357 same time as a 64-bit ST to address 0x0002: the second write will overwrite
358 all writes to bytes in memory 0x0002 thru 0x0008 of the first write,
359 and consequently the order of these two writes absolutely has to be
360 preserved.
361
362 The suggestion from Mitch Alsup was to use a match system based on bits
363 4 thru 10/11 of the address. The idea being: we don't care if the matching
364 is "too inclusive", i.e. we don't care if it includes addresses that don't
365 actually overlap, because this just means "oh dear some LD/STs do not
366 happen concurrently, they happen a few cycles later" (translation: Big Deal)
367
368 What we care about is if it were to **miss** some addresses that **do**
369 actually overlap. Therefore it is perfectly acceptable to use only a few
370 bits of the address. This is fortunate because the matching has to be
371 done in a huge NxN Pascal's Triangle, and if we were to compare against
372 the entirety of the address it would consume vast amounts of power and gates.
373
374 An enhancement of this idea is to turn the length of the operation
375 (LD/ST 1 byte, 2 bytes, 4 or 8 bytes) into a byte-map "mask", using the
376 bottom 4 bits of the address to offset this mask and "line up" with
377 the Memory byte read/write enable wires on the underlying Memory used
378 in the L1 Cache.
379
380 Then, the bottom 4 bits and the LD/ST length, now turned into a 16-bit unary
381 mask, can be "matched" using simple AND gate logic (instead of XOR for
382 binary address matching), with the advantage that it is both trivial to
383 use these masks as L1 Cache byte read/write enable lines, and furthermore
384 it is straightforward to detect misaligned LD/STs crossing cache line
385 boundaries.
386
387 Crossing over cache line boundaries is trivial in that the creation of
388 the byte-map mask is permitted to be 24 bits in length (actually, only
389 23 needed). When the bottom 4 bits of the address are 0b1111 and the
390 LD/ST is an 8-byte operation, 0b1111 1111 (representing the 64-bit LD/ST)
391 will be shifted up by 15 bits. This can then be chopped into two
392 segments:
393
394 * First segment is 0b1000 0000 0000 0000 and indicates that the
395 first byte of the LD/ST is to go into byte 15 of the cache line
396 * Second segment is 0b0111 1111 and indicates that bytes 2 through
397 8 of the LD/ST must go into bytes 0 thru 7 of the **second**
398 cache line at an address offset by 16 bytes from the first.
399
400 Thus we have actually split the LD/ST operation into two. The AddrSplit
401 class takes care of synchronising the two, by issuing two *separate*
402 sets of LD/ST requests, waiting for both of them to complete (or indicate
403 an error), and (in the case of a LD) merging the two.
404
405 The big advantage of this approach is that at no time does the L1 Cache
406 need to know anything about the offsets from which the LD/ST came. All
407 it needs to know is: which bytes to read/write into which positions
408 in the cache line(s).
409
410 Source:
411
412 * [Address Matcher](https://git.libre-riscv.org/?p=soc.git;a=blob;f=src/soc/scoreboard/addr_match.py;h=a47f635f4e9c56a7a13329810855576358110339;hb=a0e1af6c5dab5c324a8bf3a7ce6eb665d26a65c1)
413 * [Address Splitter](https://git.libre-riscv.org/?p=soc.git;a=blob;f=src/soc/scoreboard/addr_split.py;h=bf89e0970e9a8b44c76018660114172f5a3061f4;hb=a0e1af6c5dab5c324a8bf3a7ce6eb665d26a65c1)
414
415 [[!img ld_st_splitter.png size="600x"]]
416
417 # L0 Cache/Buffer
418
419 See:
420
421 * <https://bugs.libre-soc.org/show_bug.cgi?id=216>
422 * <https://bugs.libre-soc.org/show_bug.cgi?id=257>
423 * <http://lists.libre-riscv.org/pipermail/libre-riscv-dev/2020-April/006118.html>
424
425 The L0 cache/buffer needs to be kept extremely small due to it having
426 significant extra CAM functionality than a normal L1 cache. However,
427 crucially, the Memory Dependency Matrices and address-matching
428 [take care of certain things](https://bugs.libre-soc.org/show_bug.cgi?id=216#c20)
429 that greatly simplify its role.
430
431 The problem is that a standard "queue" in a multi-issue environment would
432 need to be massively-ported: 8-way read and 8-way write. However that's not
433 the only problem: the major problem is caused by the fact that we are
434 overloading "vectorisation" on top of multi-issue execution, where a
435 "normal" vector system would have a Vector LD/ST operation where sequences
436 of consecutive LDs/STs are part of the same operation, and thus a "full
437 cache line" worth of reads/writes is near-trivial to perform and detect.
438
439 Thus with the "element" LD/STs being farmed out to *individual* LD/ST
440 Computation Units, a batch of consecutive LD/ST operations arrive at the
441 LD/ST Buffer which could - hypothetically - be merged into a single
442 cache line, prior to passing them on to the L1 cache.
443
444 This is the primary task of the L0 Cache/Buffer: to resolve multiple
445 (potentially misaligned) 1/2/4/8 LD/ST operations (per cycle) into one
446 **single** L1 16-byte LD/ST operation.
447
448 The amount of wiring involved however is so enormous (3,000+ wires if
449 "only" 4-in 4-out multiplexing is done from the LD/ST Function Units) that
450 considerable care has to be taken to not massively overload the ASIC
451 layout.
452
453 To help with this, a recommendation from
454 [comp.arch](https://groups.google.com/forum/#!topic/comp.arch/cbGAlcCjiZE)
455 came to do a split odd-even double-L1-cache system: have *two* L1 caches,
456 one dealing with even-numbered 16-byte cache lines (addressed by bit 4 == 0)
457 and one dealing with odd-numbered 16-byte cache lines (addr[4] == 1).
458 This trick doubles the sequential throughput whilst halving the bandwidth
459 of a drastically-overloaded multiplexer bus.
460 Thus, we can also have two L0 LD/ST Cache/Buffers (one each looking after
461 its corresponding L1 cache).
462
463 The next phase - task - of the L0 Cache/Buffer - is to identify and merge
464 any requests with the same top 5 bits. This becomes a trivial task (under
465 certain conditions, already satisfied by other components), by simply
466 picking the first request, and using that row's address as a search
467 pattern to match against all upper bits (5 onwards). When such a match
468 is located, then due to the job(s) carried out by prior components, the
469 byte-mask for all requests with the same upper address bits may simply be
470 ORed together.
471
472 This requires a little back-tracking to explain. The prerequisite
473 conditions are as follows:
474
475 * Mask, in each row of the L0 Cache/Buffer, encodes the bottom 4 LSBs
476 of the address **and** the length of the LD/ST operation (1/2/4/8 bytes),
477 in a "bitmap" form.
478 * These "Masks" have already been analysed for overlaps by the Address
479 Match Matrix: we **know** therefore that there are no overlaps (hence why
480 addresses with the same MSBs from bits 5 and above may have their
481 masks ORed together)
482
483 [[!img mem_l0_to_l1_bridge.png size="600x"]]
484
485 ## Twin L0 cache/buffer design
486
487 See <https://groups.google.com/d/msg/comp.arch/cbGAlcCjiZE/OPNAvWSHAQAJ>.
488 [Flaws](https://bugs.libre-soc.org/show_bug.cgi?id=216#c24)
489 in the above were detected, and needed correction.
490
491 Notes:
492
493 * The flaw detected above is that for each pair of LD/ST operations
494 coming from the Function Unit (to cover mis-aligned requests),
495 the Addr[4] bit is **mutually-exclusive**. i.e. it is **guaranteed**
496 that Addr[4] for the first FU port's LD/ST request will **never**
497 equal that of the second.
498 * Therefore, if the two requests are split into left/right separate L0
499 Cache/Buffers, the advantages and optimisations for XOR-comparison
500 of bits 12-48 of the address **may not take place**.
501 * Solution: merge both L0-left and L0-right into one L0 Cache/Buffer,
502 with twin left/right banks in the same L0 Cache/Buffer
503 * This then means that the number of rows may be reduced to 8
504 * It also means that Addr[12-48] may be stored (and compared) only once
505 * It does however mean that the reservation on the row has to wait for
506 *both* ports (left and right) to clear out their LD/ST operation(s).
507 * Addr[4] still selects whether the request is to go into left or right bank
508 * When the misaligned address bits 4-11 are all 0b11111111, this is not
509 a case that can be handled, because it implies that Addr[12:48] will
510 be **different** in the row. This case throws a misaligned exception.
511
512 Other than that, the design remains the same, as does the algorithm to
513 merge the bytemasks. This remains as follows:
514
515 * PriorityPicker selects one row
516 * For all rows greater than the selected row, if Addr[5:48] matches
517 then the bytemask is "merged" into the output-bytemask-selector
518 * The output-bytemask-selector is used as a "byte-enable" line on
519 a single 128-bit byte-level read-or-write (never both).
520
521 Twin 128-bit requests (read-or-write) are then passed directly through
522 to a pair of L1 Caches.
523
524 [[!img twin_l0_cache_buffer.jpg size="600x"]]
525
526 # Multi-input/output Dependency Cell and Computation Unit
527
528 * <https://www.youtube.com/watch?v=ohHbWRLDCfs>
529 * <https://youtu.be/H0Le4ZF0cd0>
530
531 apologies that this is best done using images rather than text.
532 i'm doing a redesign of the (augmented) 6600 engine because there
533 are a couple of design criteria/assumptions that do not fit our
534 requirements:
535
536 1. operations are only 2-in, 1-out
537 2. simultaneous register port read (and write) availability is guaranteed.
538
539 we require:
540
541 1. operations with up to *four* in and up to *three* out
542 2. sporadic availability of far less than 4 Reg-Read ports and 3 Reg-Write
543
544 here are the two associated diagrams which describe the *original*
545 6600 computational unit and FU-to-Regs Dependency Cell:
546
547 1. comp unit https://libre-soc.org/3d_gpu/comp_unit_req_rel.jpg
548 2. dep cell https://libre-soc.org/3d_gpu/dependence_cell_pending.jpg
549
550 as described here https://libre-soc.org/3d_gpu/architecture/6600scoreboard/
551 we found a signal missing from Mitch's book chapters, and tracked it down
552 from the original Thornton "Design of a Computer": Read_Release. this
553 is a synchronisation / acknowledgement signal for Go_Read which is directly
554 analogous to Req_Rel for Go_Write.
555
556 also in the dependency cell, we found that it is necessary to OR the
557 two "Read" Oper1 and Oper2 signals together and to AND that with the
558 Write_Pending Latch (top latch in diagram 2.) as shown in the wonderfully
559 hand-drawn orange OR gate.
560
561 thus, Read-After-Write hazard occurs if there is a Write_Pending *AND*
562 any Read (oper1 *OR* oper2) is requested.
563
564
565 now onto the additional modifications.
566
567 3. comp unit https://libre-soc.org/3d_gpu/compunit_multi_rw.jpg
568 4. dep cell https://libre-soc.org/3d_gpu/dependence_cell_multi_pending.jpg
569
570 firstly, the computation unit modifications:
571
572 * multiple Go_Read signals are present, GoRD1-3
573 * multiple incoming operands are present, Op1-3
574 * multiple Go_Write signals are present, GoWR1-3
575 * multiple outgoing results are present, Out1-2
576
577 note that these are *NOT* necessarily 64-bit registers: they are in fact
578 Carry Flags because we are implementing POWER9. however (as mentioned
579 yesterday in the huge 250+ discussion, as far as the Dep Matrices are
580 concerned you still have to treat Carry-In and Carry-out as Read/Write
581 Hazard-protected *actual* Registers)
582
583 in the original 6600 comp unit diagram (1), because the "Go_Read" assumes
584 that *both* registers will be read (and supplied) simultaneously from
585 the Register File, the sequence - the Finite State Machine - is real
586 simple:
587
588 * ISSUE -> BUSY (latched)
589 * RD-REQ -> GO_RD
590 * WR-REQ -> GO_WR
591 * repeat
592
593 [aside: there is a protective "revolving door" loop where the SR latch for
594 each state in the FSM is guaranteed stable (never reaches "unknown") ]
595
596 in *this* diagram (3), we instead need:
597
598 * ISSUE -> BUSY (latched)
599 * RD-REQ1 -> GO_RD1 (may occur independent of RD2/3)
600 * RD-REQ2 -> GO_RD2 (may occur independent of RD1/3)
601 * RD-REQ3 -> GO_RD3 (may occur independent of RD1/2)
602 * when all 3 of GO_RD1-3 have been asserted,
603 ONLY THEN raise WR-REQ1-2
604 * WR-REQ1 -> GO_WR1 (may occur independent of WR2)
605 * WR-REQ2 -> GO_WR2 (may occur independent of WR1)
606 * when all (2) of GO_WR1-2 have been asserted,
607 ONLY THEN reset back to the beginning.
608
609 note the crucial difference is that read request and acknowledge (GO_RD)
610 are *all independent* and may occur:
611
612 * in any order
613 * in any combination
614 * all at the same time
615
616 likewise for write-request/go-write.
617
618 thus, if there is only one spare READ Register File port available
619 (because this particular Computation Unit is a low priority, but
620 the other operations need only two Regfile Ports and the Regfile
621 happens to be 3R1W), at least one of OP1-3 may get its operation.
622
623 thus, if we have three 2-operand operations and a 3R1W regfile:
624
625 * clock cycle 1: the first may grab 2 ports and the second grabs 1 (Oper1)
626 * clock cycle 2: the second grabs one more (Oper2) and the third grabs 2
627
628 compare this to the *original* 6600: if there are three 2-operand
629 operations outstanding, they MUST go:
630
631 * clock cycle 1: the first may grab 2 ports, NEITHER the 2nd nor 3rd proceed
632 * clock cycle 2: the second may grab 2 ports, 3rd may NOT proceed
633 * clock cycle 3: the 3rd grabs 2 ports
634
635 this because the Comp Unit - and associated Dependency Matrices - *FORCE*
636 the Comp Unit to only proceed when *ALL* necessary Register Read Ports
637 are available (because there is only the one Go_Read signal).
638
639
640 so my questions are:
641
642 * does the above look reasonable? both in terms of the DM changes
643 and CompUnit changes.
644
645 * the use of the three SR latches looks a little weird to me
646 (bottom right corner of (3) which is a rewrite of the middle
647 of the page.
648
649 it looks a little weird to have an SR Latch looped back
650 "onto itself". namely that when the inversion of both
651 WR_REQ1 and WR_REQ2 going low triggers that AND gate
652 (the one with the input from Q of an SR Latch), it *resets*
653 that very same SR-Latch, which will cause a mini "blip"
654 on Reset, doesn't it?
655
656 argh. that doesn't feel right. what should it be replaced with?
657
658 [[!img compunit_multi_rw.jpg size="600x"]]
659
660 [[!img dependence_cell_multi_pending.jpg size="600x"]]
661
662 # Corresponding FU-FU (Function-to-Function) Dependency Cell Modifications
663
664 * Video <https://youtu.be/_5fmPpInJ7U>
665
666 Original 6600 FU-FU Cell diagram:
667
668 [[!img fu_dep_cell_6600.jpg size="600x"]]
669
670 Augmented multi-GORD/GOWR 6600 FU-FU Cell diagram:
671
672 [[!img fu_dep_cell_multi_6600.jpg size="600x"]]
673
674 # FU-Regs Vectors
675
676 There are two FU-Regs Vectors. The first is an accumulation of
677 all row information. This indicates that (on a per-Operand basis
678 in the Libre-SOC design) there is *a* write pending for that Operand
679 (note that this is not per **register**, it is per **operand**).
680 Likewise, the OR-accumulation of every unary-encoded register SR-Latch
681 bit in the row, for reading for each FU's Operand, indicates a
682 desire of that Function Unit's need to *read* from a given port.
683
684 These accumulated signals, coming out on a per-row basis for each
685 Operand port, are sent straight to every cell in the corresponding
686 FU-FU Matrix row.
687
688 [[!img fu_regs_row_pending_vec.png size="600x"]]
689
690 The second vector set accumulates the **column** information. With the
691 FU-Regs Cells capturing the instruction operand read/write register
692 numbers (in unary form), the ORing per column of those bits creates
693 a "global picture", per register, of the fact that *any* Function Unit
694 needs to read (or write) a particular Operand latch port.
695
696 [[!img fu_regs_global_pending_vec.png size="500x"]]
697
698 # FU-FU Vectors
699
700 Two vectors exist that accumulate row and column information. With the
701 FU-FU Cell recording whether the Function Unit *wants* to read (or write)
702 the per-cell information is not so crucial as the *accumulation* of that
703 information. When all other Function Units in that column no longer
704 indicate that they were waiting for a read, that FU is clear to **write**.
705 Correspondingly, when all FUs in the column no longer indicate waiting
706 for a write, that FU is clear to **read**. With a full NxN matrix of
707 cells, this inversion preserves Read-after-Write and Write-after-Read
708 hazard information relationships between **all** Function Units and all
709 other Function Units.
710
711 [[!img fu_fu_readable_writeable.png size="500x"]]
712