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
-1
@@ -66,6 +66,27 @@ def words():
|
||||
ws.append(0x13 | r() << 7 | 0 << 15 | imm << 20) # li
|
||||
ws.append(0x13 | r() << 7 | r() << 15) # mv
|
||||
ws.append(0x00008067) # ret
|
||||
# F
|
||||
rms = [0, 1, 2, 3, 4, 7]
|
||||
for _ in range(N):
|
||||
imm = random.randrange(4096)
|
||||
ws.append(0x07 | 2 << 12 | r() << 7 | r() << 15 | imm << 20) # flw
|
||||
ws.append(0x27 | 2 << 12 | (imm & 31) << 7 | r() << 15 | r() << 20 | (imm >> 5) << 25)
|
||||
ws.append(random.choice([0x43, 0x47, 0x4B, 0x4F]) | random.choice(rms) << 12 | r() << 7 |
|
||||
r() << 15 | r() << 20 | r() << 27)
|
||||
f5, f3 = random.choice([(0, None), (1, None), (2, None), (3, None), (4, 0), (4, 1), (4, 2),
|
||||
(5, 0), (5, 1), (0x14, 0), (0x14, 1), (0x14, 2)])
|
||||
ws.append(0x53 | f5 << 27 | (random.choice(rms) if f3 is None else f3) << 12 | r() << 7 |
|
||||
r() << 15 | r() << 20)
|
||||
rr = r()
|
||||
ws.append(0x53 | 4 << 27 | random.randrange(3) << 12 | r() << 7 | rr << 15 | rr << 20) # fmv.s ...
|
||||
ws.append(0x53 | 0x0B << 27 | random.choice(rms) << 12 | r() << 7 | r() << 15) # fsqrt
|
||||
ws.append(0x53 | random.choice([0x18, 0x1A]) << 27 | random.randrange(2) << 20 |
|
||||
random.choice(rms) << 12 | r() << 7 | r() << 15) # fcvt
|
||||
ws.append(0x53 | 0x1C << 27 | random.randrange(2) << 12 | r() << 7 | r() << 15) # fmv.x.w fclass
|
||||
ws.append(0x53 | 0x1E << 27 | r() << 7 | r() << 15) # fmv.w.x
|
||||
ws.append(0x73 | random.choice([1, 2, 3, 5, 6, 7]) << 12 | r() << 7 | r() << 15 |
|
||||
random.choice([1, 2, 3]) << 20) # fcsr
|
||||
ws += [0x13, 0x73, 0x00100073, 0x30200073, 0x70200073, 0x10500073, 0x0FF0000F, 0x100F]
|
||||
return ws
|
||||
|
||||
@@ -95,7 +116,12 @@ CSRN = {"MSTATUS": 0x300, "MISA": 0x301, "MIE": 0x304, "MTVEC": 0x305, "MSCRATCH
|
||||
"MNEPC": 0x741, "MNCAUSE": 0x742, "MNSTATUS": 0x744, "TSELECT": 0x7A0, "TDATA1": 0x7A1,
|
||||
"TDATA2": 0x7A2, "TCONTROL": 0x7A5, "MCYCLE": 0xB00, "MINSTRET": 0xB02, "MCYCLEH": 0xB80,
|
||||
"MINSTRETH": 0xB82, "CYCLE": 0xC00, "TIME": 0xC01, "INSTRET": 0xC02, "CYCLEH": 0xC80,
|
||||
"TIMEH": 0xC81, "INSTRETH": 0xC82, "MHARTID": 0xF14}
|
||||
"TIMEH": 0xC81, "INSTRETH": 0xC82, "MHARTID": 0xF14,
|
||||
"FFLAGS": 1, "FRM": 2, "FCSR": 3}
|
||||
# objdump's short forms for the float CSRs: read, write, write immediate
|
||||
FCSR_ALIAS = {"FRCSR": ("FCSR", "R"), "FRRM": ("FRM", "R"), "FRFLAGS": ("FFLAGS", "R"),
|
||||
"FSCSR": ("FCSR", ""), "FSRM": ("FRM", ""), "FSFLAGS": ("FFLAGS", ""),
|
||||
"FSRMI": ("FRM", "I"), "FSFLAGSI": ("FFLAGS", "I")}
|
||||
|
||||
|
||||
def same(gnu_mn, gnu_ops, our):
|
||||
@@ -109,6 +135,14 @@ def same(gnu_mn, gnu_ops, our):
|
||||
gnu_ops = ["RA"] + gnu_ops
|
||||
elif gnu_mn.startswith("RD") and gnu_mn[2:] in CSRN:
|
||||
gnu_mn, gnu_ops = "CSRR", gnu_ops + [gnu_mn[2:]]
|
||||
elif gnu_mn in FCSR_ALIAS:
|
||||
csr, kind = FCSR_ALIAS[gnu_mn]
|
||||
if kind == "R":
|
||||
gnu_mn, gnu_ops = "CSRR", gnu_ops + [csr]
|
||||
elif len(gnu_ops) == 2:
|
||||
gnu_mn, gnu_ops = "CSRRW" + kind, [gnu_ops[0], csr, gnu_ops[1]]
|
||||
else:
|
||||
gnu_mn, gnu_ops = "CSRW" + kind, [csr] + gnu_ops
|
||||
gnu_ops = [str(CSRN[o]) if o in CSRN else o for o in gnu_ops]
|
||||
ops = [str(CSRN[o]) if o in CSRN else o for o in ops]
|
||||
alias = {"FENCE.I": "FENCE.I", "UNIMP": "DW"}
|
||||
|
||||
Reference in new issue
Block a user