code wiki / _hdl_build / rv64im_min_decoder.nx

rv64im_min_decoder.nx

buildroot/runtime/_hdl_build/rv64im_min_decoder.nx

11360 B291 linesdepth 3pulls 3 transitivereach 53 importersview sourcekind librarytopic rv64im
docsdependenciesstructsconstsfunctions

about

rv64im_min_decoder.nx -- first concrete use of the NishiHDL DSL. Decodes RV64I + M instructions into a sealed-enum opcode kind + operand-extracted fields (rd, rs1, rs2, immediate). This is the fetch-decode stage of the Tier A FPGA target (see hdl/rv64im_min_target_spec.md for the silicon contract). Status: SEED. 2026-05-26. Decoder logic only; execute / mem / writeback land in follow-on commits. Why decoder first: 1. Smallest standalone module that exercises every NishiHDL primitive (wires, modules, connect, sealed enums). 2. Verifiable against ANY known RV64IM-binary -- correctness can be ground-truthed before any execute logic exists. 3. Decoder shape is identical across single-cycle, 5-stage, and out-of-order pipelines; so this module survives any future pipeline-style change. RV64I instruction format (per riscv-spec): bits 31..25 funct7 bits 24..20 rs2 bits 19..15 rs1 bits 14..12 funct3 bits 11..7 rd bits 6..0 opcode The seven base RV64I opcodes (low 7 bits): 0110011 R-type add/sub/sll/slt/sltu/xor/srl/sra/or/and (also M ext) 0010011 I-type addi/slti/sltiu/xori/ori/andi/slli/srli/srai 0000011 Load lb/lh/lw/ld/lbu/lhu/lwu 0100011 Store sb/sh/sw/sd 1100011 Branch beq/bne/blt/bge/bltu/bgeu 1101111 jal pc-relative jump-and-link 1100111 jalr reg-indirect jump-and-link 0110111 lui load upper immediate 0010111 auipc add upper immediate to pc 1110011 System ecall/ebreak/csrrw/csrrs/csrrc/csrrwi/csrrsi/csrrci 0001111 Fence fence/fence.i

dependencies 2 imports · 40 importers

nx_syscalls.nx nishi_hdl_primitives.nx rv64im_min_decoder.nx nx_decode_kind.nx nx_decoder_fields_mem_test.nx nx_decoder_imm_mem_test.nx nx_decoder_kind_mem_test.nx nx_emu_bench.nx nx_evo_isa_sov.nx nx_geneal_energy_sov.nx nx_isa_cf_sov.nx nx_isa_equiv_sov.nx nx_isa_loop_sov.nx

diagram shows first 10 each side; +0 more imports, +30 more importers in the complete lists below.

imports: nx_syscalls.nxnishi_hdl_primitives.nx

imported by: nx_decode_kind.nxnx_decoder_fields_mem_test.nxnx_decoder_imm_mem_test.nxnx_decoder_kind_mem_test.nxnx_emu_bench.nxnx_evo_isa_sov.nxnx_geneal_energy_sov.nxnx_isa_cf_sov.nxnx_isa_equiv_sov.nxnx_isa_loop_sov.nxnx_isa_run_sov.nxnx_isa_synth_sov.nxnx_mulh_diag.nxnx_nxc_baremetal.nxnx_nxc_run.nxnx_rv64_amo_gate.nxnx_rv64_csr_trap_oracle.nxnx_rv64_fast_dev_gate.nxnx_rv64_fast_gate.nxnx_rv64_kernel_gate.nxnx_rv64_mmu_oracle.nxnx_rv64_qemu_fuzz.nxnx_rv64_qemu_oracle.nxnx_rv64_realc_gate.nxnx_rv64_run_bin.nxnx_rv64_sdeleg_oracle.nxnx_rv64_snapshot_gate.nxnx_rv64_timer_oracle.nxnx_rv64im_cpu_crosscheck.nxnx_rv64im_decoder_dump.nxnx_simtcore.nxnx_simtcore_gate.nxrv64im_min_cpu_crosscheck.nxrv64im_min_decoder_proof.nxrv64im_min_elf_loader.nxrv64im_min_gfx_gate.nxrv64im_min_hot_report.nxrv64im_min_kernel_boot_smoke.nxrv64im_min_sim.nxrv64im_min_sim_smoke.nx

structs

249struct NxRv64imDecoderPorts

consts

58const NX_RV64IM_OP_INVALID: i64 = 0 // illegal instruction (raises exc)
61const NX_RV64IM_OP_LUI: i64 = 1
62const NX_RV64IM_OP_AUIPC: i64 = 2
63const NX_RV64IM_OP_JAL: i64 = 3
64const NX_RV64IM_OP_JALR: i64 = 4
65const NX_RV64IM_OP_BRANCH: i64 = 5 // beq/bne/blt/bge/bltu/bgeu (funct3 disambiguates)
66const NX_RV64IM_OP_LOAD: i64 = 6 // lb/lh/lw/ld/lbu/lhu/lwu
67const NX_RV64IM_OP_STORE: i64 = 7 // sb/sh/sw/sd
68const NX_RV64IM_OP_OP_IMM: i64 = 8 // addi/slti/sltiu/xori/ori/andi/slli/srli/srai
69const NX_RV64IM_OP_OP: i64 = 9 // add/sub/sll/slt/sltu/xor/srl/sra/or/and
70const NX_RV64IM_OP_OP_IMM_32: i64 = 10 // addiw/slliw/srliw/sraiw
71const NX_RV64IM_OP_OP_32: i64 = 11 // addw/subw/sllw/srlw/sraw
72const NX_RV64IM_OP_FENCE: i64 = 12
73const NX_RV64IM_OP_SYSTEM: i64 = 13 // ecall/ebreak/csrrw/...
76const NX_RV64IM_OP_M_MUL: i64 = 14 // mul/mulh/mulhsu/mulhu
77const NX_RV64IM_OP_M_DIV: i64 = 15 // div/divu/rem/remu
78const NX_RV64IM_OP_M_MUL_32: i64 = 16 // mulw
79const NX_RV64IM_OP_M_DIV_32: i64 = 17 // divw/divuw/remw/remuw
83const NX_RV64IM_OP_AMO: i64 = 18
85const NX_RV64IM_OP_N: i64 = 19
242const NX_RV64IM_DECODER_WIDTH_INST: i64 = 32 // input instruction
243const NX_RV64IM_DECODER_WIDTH_OPKIND: i64 = 8 // sealed enum (fits 18 values)
244const NX_RV64IM_DECODER_WIDTH_REG: i64 = 5 // rs1/rs2/rd index
245const NX_RV64IM_DECODER_WIDTH_IMM: i64 = 64 // sign-extended

functions

87func nx_rv64im_op_is_valid(op: i64) -> i64
98func nx_rv64im_opcode(inst: i64) -> i64
102func nx_rv64im_rd(inst: i64) -> i64
106func nx_rv64im_funct3(inst: i64) -> i64
110func nx_rv64im_rs1(inst: i64) -> i64
114func nx_rv64im_rs2(inst: i64) -> i64
118func nx_rv64im_funct7(inst: i64) -> i64
129func nx_rv64im_imm_i(inst: i64) -> i64
138func nx_rv64im_imm_s(inst: i64) -> i64
149func nx_rv64im_imm_b(inst: i64) -> i64
162func nx_rv64im_imm_u(inst: i64) -> i64
172func nx_rv64im_imm_j(inst: i64) -> i64
191func nx_rv64im_decode_kind(inst: i64) -> i64
258func nx_rv64im_decoder_build(m: *NxHdlModule, ports: *NxRv64imDecoderPorts) -> i64