Add a single-precision FPU (the F extension)
rtl/rv32_fpu.v: IEEE 754 single precision with all five rounding modes, subnormals, the exception flags and the canonical NaN. Multiply-add (DSPs, exact product, 77-bit sum) with add, subtract and multiply as its special cases; divide and square root a bit a clock; one normalise-and- round back end. 12 clocks for add/mul/fma, 36 for div/sqrt. About 3000 LUTs and 2 DSPs; the system still meets 90 MHz. rv32_cpu.v: float registers, FLW/FSW, OP-FP and the R4 instructions, fflags/frm/fcsr, mstatus.FS (Initial at reset), misa F. tools/f32.py is an exact model (checked against x86 hardware) used by scripts/fputest.sh (random vectors, every instruction and rounding mode) and by tools/rv32emu.py, which now runs RV32IMF. cputest.sh adds rv32uf. BASIC and the games are built for rv32imf/ilp32f (BASIC 36.4 -> 28.7 KB, SIN about twice as fast); setjmp saves fs0-fs11; sqrtf is FSQRT.S. The monitor saves and restores f0-f31 and fcsr, shows them (F), sets them (R F1=...), and its disassembler and assembler know every F instruction (checked against objdump and GNU as). Docs updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
19278d1d74
commit
71fd403294
31 files changed
+9143
-7638
No files matched your search
@@ -20,7 +20,9 @@ covers it.
|
||||
|
||||
## The processor (`rtl/rv32_cpu.v`)
|
||||
|
||||
RV32IM in machine mode: the base integer set, multiply/divide, CSRs, counters
|
||||
RV32IMF in machine mode: the base integer set, multiply/divide,
|
||||
single-precision floating point (`rtl/rv32_fpu.v`: IEEE 754 with all five
|
||||
rounding modes, subnormals and the exception flags), CSRs, counters
|
||||
(`cycle`, `time`, `instret`), `fence.i`, `ecall`/`ebreak`/`mret`/`wfi`, traps
|
||||
and interrupts (`mtvec`, `mepc`, `mcause`, `mtval`; software, timer, external
|
||||
and 16 local interrupt lines), two hardware triggers for execute, load and
|
||||
@@ -29,9 +31,11 @@ store breakpoints, and a resumable NMI (after the Smrnmi extension: `mnepc`,
|
||||
|
||||
It is a multi-cycle design with the next instruction fetched while the current
|
||||
one decodes: 2 clocks for most instructions, 3 for taken branches, jumps, loads
|
||||
and stores, 4 for multiplies, 35 for divides; BASIC averages about 2.5. It
|
||||
runs at 90 MHz (the Z-80's clock) and takes about 2,100 LUTs, 900 flip-flops
|
||||
and 4 DSP slices.
|
||||
and stores, 4 for multiplies, 35 for divides; BASIC averages about 2.5.
|
||||
Floating-point add, subtract, multiply and the fused multiply-adds take 12
|
||||
clocks, divide and square root 36. It runs at 90 MHz (the Z-80's clock) and
|
||||
takes about 5,300 LUTs (3,000 of them the FPU), 1,900 flip-flops and 6 DSP
|
||||
slices.
|
||||
|
||||
## The machine (`rtl/rv32_system.v`)
|
||||
|
||||
@@ -61,9 +65,10 @@ All in C (plus a little assembly), compiled with GCC for `rv32im`:
|
||||
- `basic/` — BASIC, ported from the Z-80 version: the same language, the same
|
||||
manual. `lib/` has the few C library functions it needs (small string
|
||||
functions, `setjmp`, and single-precision `sinf` … `sqrtf`), since newlib's
|
||||
bring in its stdio and malloc. Floating point is IEEE single precision from
|
||||
libgcc, correctly rounded (the Z-80's SDCC library wasn't, so the last digit
|
||||
of a result can differ).
|
||||
bring in its stdio and malloc. BASIC and the games are compiled for the FPU
|
||||
(`rv32imf`, `ilp32f`); its arithmetic is IEEE single precision, correctly
|
||||
rounded (the Z-80's SDCC library wasn't, so the last digit of a result can
|
||||
differ).
|
||||
- `monitor/` — the machine-code monitor, with a RISC-V disassembler and a
|
||||
two-pass assembler in place of the Z-80 ones.
|
||||
- `games/` — The Iron Keep, Bastion Raid, Star Warden, Star Swarm and Crystal
|
||||
@@ -94,10 +99,11 @@ games/keep/keep.bas` and `SAVE "KEEP"` in BASIC.
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| `scripts/cputest.sh` | the official [riscv-tests](https://github.com/riscv-software-src/riscv-tests) (`rv32ui`, `rv32um`, `rv32mi`, fetched into `third_party/`) and `tests/` (interrupts, the NMI and single step) on `rv32_cpu.v` in xsim, with random wait states on the data bus. Two riscv-tests don't apply: `ma_data` expects misaligned loads and stores to work (here they trap, as the spec allows) and `pmpaddr` needs PMP. |
|
||||
| `scripts/fputest.sh` | `rtl/rv32_fpu.v` against `tools/f32.py`, an exact model of RISC-V's single precision (itself checked against the PC's FPU), on random vectors: every F instruction, every rounding mode, special values, subnormals and near-cancellations |
|
||||
| `scripts/cputest.sh` | the official [riscv-tests](https://github.com/riscv-software-src/riscv-tests) (`rv32ui`, `rv32um`, `rv32uf`, `rv32mi`, fetched into `third_party/`) and `tests/` (interrupts, the NMI and single step) on `rv32_cpu.v` in xsim, with random wait states on the data bus. Two riscv-tests don't apply: `ma_data` expects misaligned loads and stores to work (here they trap, as the spec allows) and `pmpaddr` needs PMP. |
|
||||
| `scripts/sim.sh` | the whole design in xsim: the terminal, BASIC, graphics, sprites, scrolling, flash files, the monitor (step, breakpoint, Pause, memory files, the assembler, Intel HEX), 3 Mbaud. `scripts/sim.sh quick` skips the terminal and the monitor. |
|
||||
| `monitor/test-disasm.py`, `test-asm.py` | the disassembler against GNU objdump on thousands of random instructions, and the assembler against GNU as |
|
||||
| `basic/test-*.py`, `games/*/test-*.py` | BASIC's line editor, RENUM and string arrays, and each game, on `tools/rv32emu.py` (a Python RV32IM emulator of the machine; `tools/boardemu.py` models the game hardware). They need `pyte` and Pillow. |
|
||||
| `basic/test-*.py`, `games/*/test-*.py` | BASIC's line editor, RENUM and string arrays, and each game, on `tools/rv32emu.py` (a Python RV32IMF emulator of the machine; `tools/boardemu.py` models the game hardware). They need `pyte` and Pillow. |
|
||||
| `bench/` | the processor alone with 64 KB of RAM, for timing |
|
||||
|
||||
## Toolchain
|
||||
|
||||
Reference in new issue
Block a user