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
+35
-2
@@ -4,13 +4,20 @@
|
||||
# instruction, a misaligned access, ebreak, ecall, an unhandled interrupt).
|
||||
# The program's registers go to u (struct regs in monitor.c), the monitor runs,
|
||||
# and mnret takes the program back to u.pc with its registers as u has them.
|
||||
.equ U, 0x29F00 # struct regs, below RAM's last 256 bytes
|
||||
# The float registers and fcsr are saved too, when mstatus.FS is on (Off: the
|
||||
# F instructions would trap), and FS is put back as it was.
|
||||
.option arch, +f
|
||||
.option norelax
|
||||
.equ U, 0x29E80 # struct regs, below RAM's last 384 bytes
|
||||
.equ INITED, 0x29FFC # C data is set up once, then kept
|
||||
.equ U_PC, 128
|
||||
.equ U_HOW, 132 # 0 NMI, 1 trap
|
||||
.equ U_CAUSE, 136
|
||||
.equ U_TVAL, 140
|
||||
.equ U_STATUS, 144
|
||||
.equ U_F, 148 # f0-f31
|
||||
.equ U_FCSR, 276
|
||||
.equ U_FS, 280 # mstatus.FS on entry; 0: f not saved
|
||||
|
||||
.section .text.start, "ax"
|
||||
.globl _start, u
|
||||
@@ -56,6 +63,21 @@ trap_entry:
|
||||
|
||||
common:
|
||||
li sp, U # the monitor's stack, below u
|
||||
.option push
|
||||
.option norelax
|
||||
la gp, __global_pointer$ # the monitor's (the program's is in u)
|
||||
.option pop
|
||||
csrr t0, mstatus
|
||||
srli t0, t0, 13
|
||||
andi t0, t0, 3
|
||||
sw t0, U_FS(sp)
|
||||
beqz t0, 5f
|
||||
.irp n, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
|
||||
fsw f\n, U_F+4*\n(sp)
|
||||
.endr
|
||||
csrr t0, fcsr
|
||||
sw t0, U_FCSR(sp)
|
||||
5:
|
||||
li t0, INITED
|
||||
lw t1, 0(t0)
|
||||
li t2, 0xA5A5
|
||||
@@ -79,7 +101,18 @@ common:
|
||||
3: call mon_main
|
||||
|
||||
li sp, U
|
||||
lw t0, U_PC(sp)
|
||||
lw t0, U_FS(sp)
|
||||
beqz t0, 6f
|
||||
.irp n, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
|
||||
flw f\n, U_F+4*\n(sp)
|
||||
.endr
|
||||
lw t1, U_FCSR(sp)
|
||||
csrw fcsr, t1
|
||||
li t1, 0x6000 # FS as it was (loading f made it Dirty)
|
||||
csrc mstatus, t1
|
||||
slli t0, t0, 13
|
||||
csrs mstatus, t0
|
||||
6: lw t0, U_PC(sp)
|
||||
csrw 0x741, t0 # mnepc
|
||||
lw t0, U_HOW(sp)
|
||||
beqz t0, 4f
|
||||
|
||||
Reference in new issue
Block a user