Files
FPGA-Core/Tutorial/phase-01-alu-m-unit/phase-01-01-combinational-alu.md
T
imple b008b37d49 Add phase-by-phase tutorial notes
Add a Tutorial tree that mirrors the roadmap from Phase 0 through Linux bring-up.
Each phase and subphase gets a short learning note with consistent sections for
context, goals, new concepts, mental model, learning tasks, pitfalls, tooling,
testing, and references.

The tutorial material is intentionally explanatory rather than implementation
code. It gives a systems-oriented learner enough FPGA, SystemVerilog, RISC-V,
firmware, and Linux bring-up context to approach each roadmap phase without
turning the notes into copy-paste RTL.
2026-04-28 12:11:23 +02:00

50 lines
1.8 KiB
Markdown

# Phase 1.1 - Combinational ALU
## Context
The ALU is the easiest place to learn the difference between software expressions and
hardware behavior. Every operation is hardware that exists in parallel behind a selector.
## Goals
- Implement RV32I arithmetic, logic, comparison, and shift operations.
- Verify every operation independently.
- Learn how signedness works in SystemVerilog.
## New Concepts
- Signedness: whether bits are interpreted as two's-complement signed values.
- Shift amount: RISC-V uses only the low 5 bits for RV32 shifts.
- Overflow: addition overflow is usually ignored for RV32I arithmetic results.
- Combinational completeness: every output is assigned for every input path.
## How To Think About It
The same 32-bit vector can be signed or unsigned depending on the operation. Make the
interpretation explicit in your design notes and tests.
## Learning Tasks
- Make a table of each ALU op, its operands, and expected result semantics.
- Hand-check edge cases such as `0`, `-1`, `INT_MIN`, and `INT_MAX`.
- Compare arithmetic right shift with logical right shift.
## Pitfalls
- Accidentally creating latches by not assigning outputs in every case.
- Using host-language intuition for signed comparisons.
- Forgetting that `slt` and `sltu` are different instructions.
## Tooling And Testing
- Use a small self-checking testbench before opening a waveform.
- Add waveform inspection for failing tests only; do not debug by staring first.
- Include cases where signed and unsigned answers differ.
## References
- RISC-V unprivileged ISA: https://riscv.org/technical/specifications/
- SystemVerilog signed arithmetic notes: https://www.chipverify.com/systemverilog/systemverilog-data-types
- Verilator warnings guide: https://verilator.org/guide/latest/warnings.html