Course: Computer Architectures
Laboratory: 0x02
Date measured: 12 October 2026
Deadline: 13 October 2026
Status: Program, experiments, report and ZIP complete; university submission not performed
Objective
Implement a single-precision neuron computation in RISC-V, measure its memory footprint and execution cost, compare forwarding settings, and evaluate independent FP latency improvements using Amdahl’s law.
The final program and every current result below use the corrected 268-instruction computation. Earlier 267- and 269-instruction versions have different sources and must not be mixed with these results.
Related concepts and lectures
- RISC-V, Registers and Immediates, Memory Addressing, Branches
- Pipelining, Multicycle Operations, Instruction Dependencies
- Latency and Initiation Interval, Structural Hazards in Multicycle Pipelines
- Amdahl Law and Pipeline Speedup
- Lecture 04 - Pipelining, Lecture 05 - Multicycle Operations, Lecture 07 - Instruction-Level Parallelism
Assignment and submission
The original assignment requires a program_1 project and completed lab_02.pdf in a ZIP named SURNAME_NAME_MATRICOLA_lab_02.zip. The user supplied a concrete filename ending in lab02.zip; the prepared archive retains that requested spelling. No upload to the university was authorized or performed.
Personalized deliverables and the unchanged assignment are stored under 40 Projects/Computer Architectures/Lab 02 Submission/, outside the study website’s published folders. See that folder’s README for the exact files and archive contents. The source and study evidence are indexed in Lab 02 - Program Sources.
Setup
Local ASE Studio project: lab_02_program_1. Existing Lab 01 projects program_1 and program_2 were preserved. The report/package source is named program_1.s inside its own program_1 folder.
| Setting | Initial value |
|---|---|
| Integer ALU / multiply / divide | 1 / 3 / 8 cycles |
| FP ALU / multiply / divide | 4 / 6 / 30 cycles |
| FP precision | Single, 32 bits |
| Arithmetic pipelining | Enabled except FP division |
| Compressed instructions | Off |
| Out-of-order execution | On |
| Memory | Direct memory |
| Instruction / read / write memory latency | 1 / 1 / 1 cycles |
| Forwarding for Table 2 | Off |
| Forwarding for Tables 3 and 5 | On |
The assignment’s prose says in-order, while its configuration image checks out-of-order execution. The user explicitly chose out-of-order on. This is a documented experiment choice; the recorded results do not establish an in-order result. The pipeline UI still labels fetch and issue as in-order.
The assignment’s 15 MHz is used to convert cycles to CPU time. It is not a claim about wall-clock simulation duration or an independently verified simulator clock.
Program and expected output
Inputs and weights each contain 30 copies of 1.0. Bias 0xAB is interpreted numerically as 171 and stored as .float 171.0.
The program accumulates the dot product from zero, then adds the bias. Thus x = 30 + 171 = 201. The raw biased IEEE-754 exponent of 201 is 0x86, so the normal path computes y = 1/201.
| Observation | Verified value |
|---|---|
f0 and stored x | 201.0 |
f6 and stored y | 0.0049751243 |
Bias register f7 | 171.0 |
Loop counter t2 | 0 |
| Extracted normal-path exponent | 134 = 0x86 |
Every final performance run showed the expected f0 and f6. The last forwarding-on baseline also verified both output memory writes.
Memory footprint
| Data | Bytes |
|---|---|
| Inputs | 120 |
| Weights | 120 |
| b | 4 |
| x | 4 |
| y | 4 |
| one | 4 |
| Total declared data | 256 |
The assignment’s five named entries total 252 bytes; the reciprocal numerator constant one adds four. The final memory map has no extra data padding.
Final memory map: data 0x11134 through 0x11233; x at 0x11228, y at 0x1122c. Text occupies 160 bytes: 148 pipeline-visible bytes plus a protected 12-byte End block (0x10128 through 0x10133). Addresses belong to this assembled version and can change when code changes.
Counting scope
All current timing tables cover 268 executed computation instructions, excluding the protected End block (li a0,0, li a7,93, ecall). Wrong-path fetched instructions that never execute and the skipped set_zero move are excluded. The UI log’s completion message supplies no separately established full-run cycle total.
Pseudo-instructions expand before counting: each la becomes auipc plus addi; li, bnez, beqz and j use their executed machine instructions in the CSV.
| Machine instruction | Executed count | Initial EX cycles each |
|---|---|---|
| auipc | 6 | 1 |
| addi | 98 | 1 |
| flw | 62 | 1 |
| fmul.s | 30 | 6 |
| fadd.s | 31 | 4 |
| bne | 30 | 1 |
| beq | 2 | 1 |
| fsw | 2 | 1 |
| fmv.w.x | 1 | 4 |
| fmv.x.w | 1 | 4 |
| slli / srli / andi | 1 each | 1 |
| fdiv.s | 1 | 30 |
| jal | 1 | 1 |
| Total | 268 |
CSV rows with no E stage are not executed instructions. Counting all displayed rows would also count discarded wrong-path work. The two FP moves use the configured FP ALU latency, verified from their E cells.
Table 1 Manual EX timing
The assignment defines each instruction’s CPI as its functional-unit EX latency. This produces a sum of EX work, not elapsed pipeline time.
There are 33 FP ALU operations (31 adds and two moves), 30 FP multiplications, one division and 204 remaining instructions with one EX cycle each.
| Independent configuration | EX cycles | Time at 15 MHz (µs) |
|---|---|---|
| Initial 4 / 6 / 30 | 546 | 36.4000 |
| Faster MUL 4 / 2 / 30 | 426 | 28.4000 |
| Faster DIV 4 / 6 / 10 | 526 | 35.0667 |
Loads and stores use one EX cycle for address calculation here; MEM stages and pipeline waits are not added. Including the three protected exit instructions under a one-EX-cycle-each convention would give 549 / 429 / 529, but these are optional estimates, not the table’s scope. OS syscall handling is outside that manual model.
Table 2 Simulator with forwarding off
Each case changes only the named latency and resets the other FP units to initial values. Out-of-order remains on. All runs execute 268 computation instructions and show the correct normal numerical results.
| FP ALU / MUL / DIV | Measured cycles | CPI | IPC | Time at 15 MHz (µs) |
|---|---|---|---|---|
| 4 / 6 / 30 | 720 | 2.686567 | 0.372222 | 48.0000 |
| 4 / 2 / 30 | 600 | 2.238806 | 0.446667 | 40.0000 |
| 4 / 6 / 10 | 700 | 2.611940 | 0.382857 | 46.6667 |
The net measured-minus-EX difference is 174 cycles in all three runs. It combines stages, filling/draining, memory, dependencies and overlap; 174 is not a raw sum of independent stalls. Faster multiply saves 30 × (6 − 2) = 120 cycles. Faster divide saves 30 − 10 = 20 cycles.
The baseline CSV is retained. Faster-MUL and faster-DIV values were read directly from completed UI runs; those two final runs have no retained CSV snapshot. Do not describe every measurement as backed by an export.
Table 3 Forwarding enabled
Restoring 4 / 6 / 30 and enabling forwarding gives:
| Metric | Result |
|---|---|
| Cycles | 574 |
| Instructions | 268 |
| CPI | 2.141791 |
| IPC | 0.466899 |
| Time at 15 MHz | 38.2667 µs |
| Cycles saved versus forwarding off | 146 |
| Execution-time reduction | 20.2778% |
| Speedup | 720/574 = 1.254355 |
Forwarding bypasses register writeback for available results. It does not eliminate the multiply-to-add dependency, the running-sum dependency, finite execution latency, load-use waits or pipeline resource conflicts. No exact stall-category partition was established.
Table 5 Amdahl prediction and experiment
With forwarding on, start every case independently from 4 / 6 / 30. The manual baseline is 546 summed EX cycles; the measured baseline is 574 elapsed cycles.
Here s is the unit speedup and f must describe the fraction of the same baseline cost being modeled. Manual fractions below describe EX work, not measured elapsed time.
| Configuration | Manual fraction f | Unit speedup s | New EX sum | Manual speedup | Measured cycles | Measured speedup |
|---|---|---|---|---|---|---|
| FP ALU 4 → 3 | 132/546 | 4/3 | 513 | 1.064327 | 575 | 0.998261 |
| FP MUL 6 → 4 | 180/546 | 6/4 | 486 | 1.123457 | 514 | 1.116732 |
| FP DIV 30 → 10 | 30/546 | 3 | 526 | 1.038023 | 554 | 1.036101 |
Configuration 1 was repeated and again took 575 cycles. The nominal 33-cycle reduction in summed EX work does not become an elapsed-time saving. In the baseline export, the initial FP move reaches M at cycle 12 and the second load reaches M at cycle 11. With FP ALU latency 3, the move reaches M at 11 and the load waits until 12; the dependent multiply starts one cycle later. Subsequent resource waits and overlap lead to the final store completing at 575 instead of 574.
This is an observed scheduling effect. Amdahl’s fixed unaffected-time assumption does not describe this whole pipeline change, so a speedup below one does not refute the law. The exports establish the stage shift, but not a complete internal simulator-cause analysis.
For multiply and divide, measured savings are 60 and 20 cycles. A fixed-remainder elapsed-time model with fractions 180/574 and 30/574 reproduces these two measurements. This agreement is specific to the observed runs; it does not justify treating overlapping EX occupancy as disjoint elapsed-time fractions in general.
Activation diagnostics and zero-branch workaround
The earlier version used:
fmv.w.x f4, zero
feq.s t4, f0, f4
bnez t4, set_zeroThis is valid RISC-V code. However, with bias -30 and all products equal to one, the simulator produced x = 0 and fell through to division, giving Infinity. The behavior reproduced with forwarding on and off. An additional diagnostic preserved the comparison’s destination register and showed t4 = 1 despite the fallthrough. The exact simulator implementation cause remains unresolved.
The final source checks the magnitude bits using integer dependencies:
fmv.x.w t3, f0
slli t4, t3, 1
beqz t4, set_zeroIn RV32, shifting left discards the sign bit. Both signed zeros therefore produce zero; every nonzero binary32 magnitude remains nonzero. The unshifted raw word in t3 remains available for exponent extraction.
| Separate diagnostic | Changed bias | Verified stored x | Verified stored y | Forwarding |
|---|---|---|---|---|
| Zero activation | -30.0 | 0 | 0 | Passed off and on |
| Exponent 0x7F | -29.0 | 1 | 0 | Passed on |
The negative-zero bit pattern is handled by inspection of the RV32 shift logic; no separate negative-zero simulator run is claimed. Diagnostic inputs and timings are excluded from the performance tables. Normal data/settings were restored afterward.
Comparison with the other report
See Lab 02 - Comparison with Alternate Implementation for the supplied 267-instruction source, its report’s assumptions, and why its timings cannot be substituted for the final 268-instruction program.
Superseded measurements
The earlier bias-after-loop program with feq.s executed 269 instructions. It measured 730 / 610 / 710 cycles with forwarding off; forwarding on gave 582 initially and 581 / 522 / 562 for the three Table 5 changes. Normal numerical outputs were correct, but the zero diagnostic motivated the correction. These values are historical and are not current report results.
What I learned
- Validate every activation condition separately; a correct normal result does not prove branch correctness.
- Record source, input, settings and counting scope together with each performance result.
- Read actual functional-unit stage counts instead of assuming all move instructions cost one EX cycle.
- A latency reduction may expose a different resource conflict; fewer summed EX cycles do not guarantee fewer elapsed cycles.
- Preserve original assignment material and separate diagnostic runs from required performance runs.
Completion checklist
- Final source and normal output checked
- Memory footprint and manual timing calculated
- Tables 2, 3 and 5 measured using the final source
- Both zero-output conditions checked in separate diagnostics
- Final PDF exported and all six pages visually inspected
- ZIP contents and integrity checked
- Source, evidence and comparison documented
- Upload the ZIP to the university
Sources and limits
Assignment: supplied lab_02_2026-27.docx, retained unchanged in the non-published submission folder. Results: local ASE Studio observations from 12 October 2026, five retained final pipeline CSV exports, and the final checked PDF. The peer comparison is based on a separately supplied PDF and pasted assembly, not independently repeated peer runs. Temporary browser access restrictions affected earlier work; current final experiments were subsequently completed through the supported browser UI.