From aa5df4030fc52a90a14db56dd62ab2bca1a07fca Mon Sep 17 00:00:00 2001 From: zeeshanrafique23 Date: Sat, 25 Sep 2021 16:38:17 +0500 Subject: [PATCH 01/31] added trace for Floating Point extension --- .../simple_system/ibex_simple_system.core | 9 + .../simple_system/rtl/ibex_simple_system.sv | 6 + hw/vendor/lowrisc_ibex/rtl/ibex_core.sv | 96 +++++++++- .../lowrisc_ibex/rtl/ibex_core_tracing.sv | 26 ++- hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv | 45 ++++- hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv | 6 + hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv | 180 +++++++++++++++++- hw/vendor/lowrisc_ibex/rtl/ibex_tracer_pkg.sv | 35 ++++ 8 files changed, 396 insertions(+), 7 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/examples/simple_system/ibex_simple_system.core b/hw/vendor/lowrisc_ibex/examples/simple_system/ibex_simple_system.core index 6634e1dc..bd4eb0bb 100644 --- a/hw/vendor/lowrisc_ibex/examples/simple_system/ibex_simple_system.core +++ b/hw/vendor/lowrisc_ibex/examples/simple_system/ibex_simple_system.core @@ -109,6 +109,12 @@ parameters: default: 4 paramtype: vlogparam description: "Number of PMP regions" + + RVF: + datatype: str + default: ibex_pkg::RV32FSingle + paramtype: vlogdefine + description: "Used to enable the F or D extension with ibex, possible values: ibex_pkg::RV32FDNone, ibex_pkg::RV32FSingle, ibex_pkg::RV32DDouble" targets: default: &default_target @@ -122,6 +128,7 @@ targets: - RV32M - RV32B - RegFile + - RVF - ICache - ICacheECC - BranchTargetALU @@ -176,3 +183,5 @@ targets: - '-Wno-UNOPTFLAT' - '-Wno-INCABSPATH' - "-Wno-IMPERFECTSCH" + - "-Wno-LATCH" + - "-Wno-LITENDIAN" diff --git a/hw/vendor/lowrisc_ibex/examples/simple_system/rtl/ibex_simple_system.sv b/hw/vendor/lowrisc_ibex/examples/simple_system/rtl/ibex_simple_system.sv index 1949a781..92be495e 100644 --- a/hw/vendor/lowrisc_ibex/examples/simple_system/rtl/ibex_simple_system.sv +++ b/hw/vendor/lowrisc_ibex/examples/simple_system/rtl/ibex_simple_system.sv @@ -18,6 +18,10 @@ `define RegFile ibex_pkg::RegFileFF `endif +`ifndef RVF + `define RVF ibex_pkg::RV32FSingle +`endif + /** * Ibex simple system * @@ -43,6 +47,7 @@ module ibex_simple_system ( parameter ibex_pkg::rv32m_e RV32M = `RV32M; parameter ibex_pkg::rv32b_e RV32B = `RV32B; parameter ibex_pkg::regfile_e RegFile = `RegFile; + parameter ibex_pkg::rvfloat_e RVF = `RVF; parameter bit BranchTargetALU = 1'b0; parameter bit WritebackStage = 1'b0; parameter bit ICache = 1'b0; @@ -170,6 +175,7 @@ module ibex_simple_system ( .RV32E ( RV32E ), .RV32M ( RV32M ), .RV32B ( RV32B ), + .RVF ( RVF ), .RegFile ( RegFile ), .BranchTargetALU ( BranchTargetALU ), .ICache ( ICache ), diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv index ec15e924..2b69e2da 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv @@ -99,6 +99,22 @@ module ibex_core #( output logic [ 3:0] rvfi_mem_wmask, output logic [31:0] rvfi_mem_rdata, output logic [31:0] rvfi_mem_wdata, + output logic [ 4:0] rvfi_frs1_addr, + output logic [ 4:0] rvfi_frs2_addr, + output logic [ 4:0] rvfi_frs3_addr, + output logic [ 4:0] rvfi_frd_addr, + output logic [31:0] rvfi_frs1_rdata, + output logic [31:0] rvfi_frs2_rdata, + output logic [31:0] rvfi_frs3_rdata, + output logic [31:0] rvfi_frd_wdata, + // output logic rvfi_frs1_rvalid, + // output logic rvfi_frs2_rvalid, + // output logic rvfi_frs3_rvalid, + // output logic rvfi_frd_wvalid, + // output logic [31:0] rvfi_csr_fcsr_rmask, + // output logic [31:0] rvfi_csr_fcsr_wmask, + // output logic [31:0] rvfi_csr_fcsr_rdata, + // output logic [31:0] rvfi_csr_fcsr_wdata, `endif // CPU Control Signals @@ -133,7 +149,10 @@ module ibex_core #( logic out_valid_fpu2c; // valid - from core to FPU logic valid_id_fpu; // select which valid signal will go to dec logic fp_rm_dynamic; - logic fp_alu_op_mod; + logic fp_alu_op_mod; + logic fp_rf_ren_a; + logic fp_rf_ren_b; + logic fp_rf_ren_c; logic [4:0] fp_rf_raddr_a; logic [4:0] fp_rf_raddr_b; logic [4:0] fp_rf_raddr_c; @@ -398,6 +417,13 @@ module ibex_core #( logic [31:0] rvfi_mem_wdata_q; logic [31:0] rvfi_mem_addr_d; logic [31:0] rvfi_mem_addr_q; + logic [ 4:0] rvfi_frd_addr_wb; + logic [31:0] rvfi_frd_wdata_wb; + logic rvfi_frd_we_wb; + logic [31:0] rvfi_frd_wdata_d; + logic [31:0] rvfi_frd_wdata_q; + logic [ 4:0] rvfi_frd_addr_d; + logic [ 4:0] rvfi_frd_addr_q; `endif ////////////////////// @@ -691,6 +717,9 @@ module ibex_core #( .fp_rf_raddr_a_o ( fp_rf_raddr_a ), .fp_rf_raddr_b_o ( fp_rf_raddr_b ), .fp_rf_raddr_c_o ( fp_rf_raddr_c ), + .fp_rf_ren_a_o ( fp_rf_ren_a ), + .fp_rf_ren_b_o ( fp_rf_ren_b ), + .fp_rf_ren_c_o ( fp_rf_ren_c ), .fp_rf_waddr_o ( fp_rf_waddr_id ), .fp_rf_we_o ( fp_rf_wen_id ), .fp_alu_operator_o ( fp_alu_operator ), @@ -1109,6 +1138,10 @@ module ibex_core #( assign rvfi_rd_addr_wb = rf_waddr_wb; assign rvfi_rd_wdata_wb = rf_we_wb ? rf_wdata_wb : rf_wdata_lsu; assign rvfi_rd_we_wb = rf_we_wb | rf_we_lsu; + + assign rvfi_frd_addr_wb = fp_rf_waddr_wb; + assign rvfi_frd_wdata_wb = fp_rf_wen_wb ? fp_rf_wdata_wb : rf_wdata_lsu; + assign rvfi_frd_we_wb = fp_rf_wen_wb | rf_we_lsu; `endif @@ -1310,6 +1343,19 @@ module ibex_core #( logic [31:0] rvfi_stage_mem_rdata [RVFI_STAGES]; logic [31:0] rvfi_stage_mem_wdata [RVFI_STAGES]; + logic rvfi_stage_frs1_rvalid [RVFI_STAGES]; + logic rvfi_stage_frs2_rvalid [RVFI_STAGES]; + logic rvfi_stage_frs3_rvalid [RVFI_STAGES]; + logic rvfi_stage_frd_wvalid [RVFI_STAGES]; + logic [ 4:0] rvfi_stage_frs1_addr [RVFI_STAGES]; + logic [ 4:0] rvfi_stage_frs2_addr [RVFI_STAGES]; + logic [ 4:0] rvfi_stage_frs3_addr [RVFI_STAGES]; + logic [31:0] rvfi_stage_frs1_rdata [RVFI_STAGES]; + logic [31:0] rvfi_stage_frs2_rdata [RVFI_STAGES]; + logic [31:0] rvfi_stage_frs3_rdata [RVFI_STAGES]; + logic [ 4:0] rvfi_stage_frd_addr [RVFI_STAGES]; + logic [31:0] rvfi_stage_frd_wdata [RVFI_STAGES]; + logic rvfi_stage_valid_d [RVFI_STAGES]; assign rvfi_valid = rvfi_stage_valid [RVFI_STAGES-1]; @@ -1336,6 +1382,15 @@ module ibex_core #( assign rvfi_mem_rdata = rvfi_stage_mem_rdata[RVFI_STAGES-1]; assign rvfi_mem_wdata = rvfi_stage_mem_wdata[RVFI_STAGES-1]; + assign rvfi_frs1_addr = rvfi_stage_frs1_addr [RVFI_STAGES-1]; + assign rvfi_frs2_addr = rvfi_stage_frs2_addr [RVFI_STAGES-1]; + assign rvfi_frs3_addr = rvfi_stage_frs3_addr [RVFI_STAGES-1]; + assign rvfi_frs1_rdata = rvfi_stage_frs1_rdata[RVFI_STAGES-1]; + assign rvfi_frs2_rdata = rvfi_stage_frs2_rdata[RVFI_STAGES-1]; + assign rvfi_frs3_rdata = rvfi_stage_frs3_rdata[RVFI_STAGES-1]; + assign rvfi_frd_addr = rvfi_stage_frd_addr [RVFI_STAGES-1]; + assign rvfi_frd_wdata = rvfi_stage_frd_wdata [RVFI_STAGES-1]; + if (WritebackStage) begin : gen_rvfi_wb_stage logic unused_instr_new_id; @@ -1398,6 +1453,15 @@ module ibex_core #( rvfi_stage_mem_rdata[i] <= '0; rvfi_stage_mem_wdata[i] <= '0; rvfi_stage_mem_addr[i] <= '0; + + rvfi_stage_frs1_addr[i] <= '0; + rvfi_stage_frs2_addr[i] <= '0; + rvfi_stage_frs3_addr[i] <= '0; + rvfi_stage_frs1_rdata[i] <= '0; + rvfi_stage_frs2_rdata[i] <= '0; + rvfi_stage_frs3_rdata[i] <= '0; + rvfi_stage_frd_addr[i] <= '0; + rvfi_stage_frd_wdata[i] <= '0; end else begin rvfi_stage_valid[i] <= rvfi_stage_valid_d[i]; @@ -1425,6 +1489,15 @@ module ibex_core #( rvfi_stage_mem_rdata[i] <= rvfi_mem_rdata_d; rvfi_stage_mem_wdata[i] <= rvfi_mem_wdata_d; rvfi_stage_mem_addr[i] <= rvfi_mem_addr_d; + + rvfi_stage_frs1_addr[i] <= fp_rf_ren_a ? fp_rf_raddr_a : '0; + rvfi_stage_frs2_addr[i] <= fp_rf_ren_b ? fp_rf_raddr_b : '0; + rvfi_stage_frs3_addr[i] <= fp_rf_ren_c ? fp_rf_raddr_c : '0; + rvfi_stage_frs1_rdata[i] <= fp_rf_ren_a ? fp_operands[0]: '0; + rvfi_stage_frs2_rdata[i] <= fp_rf_ren_b ? fp_operands[1]: '0; + rvfi_stage_frs3_rdata[i] <= fp_rf_ren_c ? fp_operands[2]: '0; + rvfi_stage_frd_addr[i] <= rvfi_frd_addr_d; + rvfi_stage_frd_wdata[i] <= rvfi_frd_wdata_d; end end else begin if(instr_done_wb) begin @@ -1448,12 +1521,21 @@ module ibex_core #( rvfi_stage_mem_wdata[i] <= rvfi_stage_mem_wdata[i-1]; rvfi_stage_mem_addr[i] <= rvfi_stage_mem_addr[i-1]; + rvfi_stage_frs1_addr[i] <= rvfi_stage_frs1_addr[i-1]; + rvfi_stage_frs2_addr[i] <= rvfi_stage_frs2_addr[i-1]; + rvfi_stage_frs3_addr[i] <= rvfi_stage_frs3_addr[i-1]; + rvfi_stage_frs1_rdata[i] <= rvfi_stage_frs1_rdata[i-1]; + rvfi_stage_frs2_rdata[i] <= rvfi_stage_frs2_rdata[i-1]; + rvfi_stage_frs3_rdata[i] <= rvfi_stage_frs3_rdata[i-1]; + // For 2 RVFI_STAGES/Writeback Stage ignore first stage flops for rd_addr, rd_wdata and // mem_rdata. For RF write addr/data actual write happens in writeback so capture // address/data there. For mem_rdata that is only available from the writeback stage. // Previous stage flops still exist in RTL as they are used by the non writeback config rvfi_stage_rd_addr[i] <= rvfi_rd_addr_d; rvfi_stage_rd_wdata[i] <= rvfi_rd_wdata_d; + rvfi_stage_frd_addr[i] <= rvfi_frd_addr_d; + rvfi_stage_frd_wdata[i] <= rvfi_frd_wdata_d; rvfi_stage_mem_rdata[i] <= rvfi_mem_rdata_d; end end @@ -1546,9 +1628,11 @@ module ibex_core #( end always_comb begin - if(rvfi_rd_we_wb) begin + if(rvfi_rd_we_wb | rvfi_frd_we_wb) begin // Capture address/data of write to register file rvfi_rd_addr_d = rvfi_rd_addr_wb; + rvfi_frd_addr_d = rvfi_frd_addr_wb; + rvfi_frd_wdata_d = rvfi_frd_wdata_wb; // f0 is not zero // If writing to x0 zero write data as required by RVFI specification if(rvfi_rd_addr_wb == 5'b0) begin rvfi_rd_wdata_d = '0; @@ -1560,10 +1644,14 @@ module ibex_core #( // stage present) then zero RF write address/data as required by RVFI specification rvfi_rd_addr_d = '0; rvfi_rd_wdata_d = '0; + rvfi_frd_addr_d = '0; + rvfi_frd_wdata_d = '0; end else begin // Otherwise maintain previous value rvfi_rd_addr_d = rvfi_rd_addr_q; rvfi_rd_wdata_d = rvfi_rd_wdata_q; + rvfi_frd_addr_d = rvfi_frd_addr_q; + rvfi_frd_wdata_d = rvfi_frd_wdata_q; end end @@ -1573,9 +1661,13 @@ module ibex_core #( if (!rst_ni) begin rvfi_rd_addr_q <= '0; rvfi_rd_wdata_q <= '0; + rvfi_frd_addr_q <= '0; + rvfi_frd_wdata_q <= '0; end else begin rvfi_rd_addr_q <= rvfi_rd_addr_d; rvfi_rd_wdata_q <= rvfi_rd_wdata_d; + rvfi_frd_addr_q <= rvfi_frd_addr_d; + rvfi_frd_wdata_q <= rvfi_frd_wdata_d; end end diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_core_tracing.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_core_tracing.sv index 29a2ac44..657f0084 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_core_tracing.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_core_tracing.sv @@ -104,6 +104,14 @@ module ibex_core_tracing #( logic [ 3:0] rvfi_mem_wmask; logic [31:0] rvfi_mem_rdata; logic [31:0] rvfi_mem_wdata; + logic [ 4:0] rvfi_frs1_addr; + logic [ 4:0] rvfi_frs2_addr; + logic [ 4:0] rvfi_frs3_addr; + logic [ 4:0] rvfi_frd_addr; + logic [31:0] rvfi_frs1_rdata; + logic [31:0] rvfi_frs2_rdata; + logic [31:0] rvfi_frs3_rdata; + logic [31:0] rvfi_frd_wdata; ibex_core #( .PMPEnable ( PMPEnable ), @@ -183,6 +191,14 @@ module ibex_core_tracing #( .rvfi_mem_wmask, .rvfi_mem_rdata, .rvfi_mem_wdata, + .rvfi_frs1_addr, + .rvfi_frs2_addr, + .rvfi_frs3_addr, + .rvfi_frd_addr, + .rvfi_frs1_rdata, + .rvfi_frs2_rdata, + .rvfi_frs3_rdata, + .rvfi_frd_wdata, .fetch_enable_i, .alert_minor_o, @@ -219,7 +235,15 @@ module ibex_core_tracing #( .rvfi_mem_rmask, .rvfi_mem_wmask, .rvfi_mem_rdata, - .rvfi_mem_wdata + .rvfi_mem_wdata, + .rvfi_frs1_addr, + .rvfi_frs2_addr, + .rvfi_frs3_addr, + .rvfi_frd_addr, + .rvfi_frs1_rdata, + .rvfi_frs2_rdata, + .rvfi_frs3_rdata, + .rvfi_frd_wdata ); endmodule diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv index ee6a135f..6520e869 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv @@ -103,6 +103,9 @@ module ibex_decoder #( output logic [4:0] fp_rf_raddr_a_o, output logic [4:0] fp_rf_raddr_b_o, output logic [4:0] fp_rf_raddr_c_o, + output logic fp_rf_ren_a_o, + output logic fp_rf_ren_b_o, + output logic fp_rf_ren_c_o, output logic [4:0] fp_rf_waddr_o, output logic fp_rf_we_o, @@ -280,6 +283,9 @@ module ibex_decoder #( fp_dst_fmt_o = FP32; fp_swap_oprnds_o = 1'b0; mv_instr_o = 1'b0; + fp_rf_ren_a_o = 1'b0; + fp_rf_ren_b_o = 1'b0; + fp_rf_ren_c_o = 1'b0; opcode = opcode_e'(instr[6:0]); @@ -681,6 +687,7 @@ module ibex_decoder #( data_req_o = 1'b1; data_we_o = 1'b1; data_type_o = 2'b00; + fp_rf_ren_a_o = 1'b1; use_fp_rs2_o = 1'b1; @@ -701,6 +708,8 @@ module ibex_decoder #( data_req_o = 1'b1; data_type_o = 2'b00; fp_load_o = 1'b1; + fp_rf_ren_a_o = 1'b1; + fp_rf_ren_b_o = 1'b1; use_fp_rd_o = 1'b1; @@ -724,6 +733,9 @@ module ibex_decoder #( fp_rf_we_o = 1'b1; fp_src_fmt_o = FP32; is_fp_instr_o = 1'b1; + fp_rf_ren_a_o = 1'b1; + fp_rf_ren_b_o = 1'b1; + fp_rf_ren_c_o = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rs2_o = 1'b1; @@ -750,6 +762,8 @@ module ibex_decoder #( unique case (instr[31:25]) 7'b0000001, // FADD.D 7'b0000101: begin // FSUB.D + fp_rf_ren_a_o = 1'b1; + fp_rf_ren_b_o = 1'b1; fp_rf_we_o = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rs2_o = 1'b1; @@ -760,6 +774,8 @@ module ibex_decoder #( end 7'b0001001, // FMUL.D 7'b0001101:begin // FDIV.D + fp_rf_ren_a_o = 1'b1; + fp_rf_ren_b_o = 1'b1; fp_rf_we_o = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rs2_o = 1'b1; @@ -769,6 +785,8 @@ module ibex_decoder #( end 7'b0000000, // FADD.S 7'b0000100: begin // FSUB.S + fp_rf_ren_a_o = 1'b1; + fp_rf_ren_b_o = 1'b1; fp_rf_we_o = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rs2_o = 1'b1; @@ -777,8 +795,10 @@ module ibex_decoder #( illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; end - 7'b0001000, // FMUL.S + 7'b0001000, // FMUL.S 7'b0001100: begin // FDIV.S + fp_rf_ren_a_o = 1'b1; + fp_rf_ren_b_o = 1'b1; fp_rf_we_o = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rs2_o = 1'b1; @@ -790,6 +810,7 @@ module ibex_decoder #( fp_rf_we_o = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rd_o = 1'b1; + fp_rf_ren_a_o = 1'b1; if (~|instr[24:20]) begin //FSQRT.D illegal_insn = ((RVF == RV32DDouble) & (fp_invalid_rm)) ? 1'b0 : 1'b1; fp_src_fmt_o = FP64; @@ -799,6 +820,7 @@ module ibex_decoder #( fp_rf_we_o = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rd_o = 1'b1; + fp_rf_ren_a_o = 1'b1; if (~|instr[24:20]) begin illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; @@ -809,6 +831,8 @@ module ibex_decoder #( use_fp_rs1_o = 1'b1; use_fp_rs2_o = 1'b1; use_fp_rd_o = 1'b1; + fp_rf_ren_a_o = 1'b1; + fp_rf_ren_b_o = 1'b1; if (~(instr[14] | (&instr[13:12]))) begin illegal_insn = ((RVF == RV32DDouble) & (fp_invalid_rm)) ? 1'b0 : 1'b1; fp_src_fmt_o = FP64; @@ -819,6 +843,8 @@ module ibex_decoder #( use_fp_rs1_o = 1'b1; use_fp_rs2_o = 1'b1; use_fp_rd_o = 1'b1; + fp_rf_ren_a_o = 1'b1; + fp_rf_ren_b_o = 1'b1; if (~(instr[14] | (&instr[13:12]))) begin illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; @@ -829,6 +855,8 @@ module ibex_decoder #( use_fp_rs1_o = 1'b1; use_fp_rs2_o = 1'b1; use_fp_rd_o = 1'b1; + fp_rf_ren_a_o = 1'b1; + fp_rf_ren_b_o = 1'b1; if (~|instr[14:13]) begin illegal_insn = ((RVF == RV32DDouble) & (fp_invalid_rm)) ? 1'b0 : 1'b1; fp_src_fmt_o = FP64; @@ -839,6 +867,8 @@ module ibex_decoder #( use_fp_rs1_o = 1'b1; use_fp_rs2_o = 1'b1; use_fp_rd_o = 1'b1; + fp_rf_ren_a_o = 1'b1; + fp_rf_ren_b_o = 1'b1; if (~|instr[14:13]) begin illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; @@ -848,6 +878,7 @@ module ibex_decoder #( fp_rf_we_o = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rd_o = 1'b1; + fp_rf_ren_a_o = 1'b1; if (~(|instr[24:21] | (~instr[20]))) begin illegal_insn = ((RVF == RV32DDouble) & (fp_invalid_rm)) ? 1'b0 : 1'b1; fp_src_fmt_o = FP64; @@ -856,6 +887,7 @@ module ibex_decoder #( 7'b1100000: begin // FCVT.W.S, FCVT.WU.S rf_we = 1'b1; // write back in int_regfile use_fp_rs1_o = 1'b1; + fp_rf_ren_a_o = 1'b1; if (~|instr[24:21]) begin illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; @@ -865,6 +897,7 @@ module ibex_decoder #( fp_rf_we_o = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rd_o = 1'b1; + fp_rf_ren_a_o = 1'b1; if (~|instr[24:20]) begin illegal_insn = ((RVF == RV32DDouble) & (fp_invalid_rm)) ? 1'b0 : 1'b1; fp_src_fmt_o = FP64; @@ -872,6 +905,7 @@ module ibex_decoder #( end 7'b1110000: begin // FMV.X.W , FCLASS.S rf_we = 1'b1; // write back in int_regfile + fp_rf_ren_a_o = 1'b1; unique case ({instr[24:20],instr[14:12]}) {5'b00000,3'b000}: begin use_fp_rs1_o = 1'b1; @@ -893,6 +927,8 @@ module ibex_decoder #( rf_we = 1'b1; // write back in int_regfile use_fp_rs1_o = 1'b1; use_fp_rs2_o = 1'b1; + fp_rf_ren_a_o = 1'b1; + fp_rf_ren_b_o = 1'b1; if (~(instr[14]) | (&instr[13:12])) begin illegal_insn = ((RVF == RV32DDouble) & (fp_invalid_rm)) ? 1'b0 : 1'b1; fp_src_fmt_o = FP64; @@ -902,6 +938,8 @@ module ibex_decoder #( rf_we = 1'b1; // write back in int_regfile use_fp_rs1_o = 1'b1; use_fp_rs2_o = 1'b1; + fp_rf_ren_a_o = 1'b1; + fp_rf_ren_b_o = 1'b1; if (~(instr[14]) | (&instr[13:12])) begin illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; @@ -910,6 +948,7 @@ module ibex_decoder #( 7'b1110001: begin // FCLASS.D rf_we = 1'b1; // write back in int_regfile use_fp_rs1_o = 1'b1; + fp_rf_ren_a_o = 1'b1; unique case ({instr[24:20],instr[14:12]}) {5'b00000,3'b001}: begin illegal_insn = ((RVF == RV32DDouble) & (fp_invalid_rm)) ? 1'b0 : 1'b1; @@ -923,6 +962,7 @@ module ibex_decoder #( 7'b1100001: begin // // FCVT.W.D, FCVT.WU.D rf_we = 1'b1; // write back in int_regfile use_fp_rs1_o = 1'b1; + fp_rf_ren_a_o = 1'b1; if (~|instr[24:21]) begin illegal_insn = ((RVF == RV32DDouble) & (fp_invalid_rm)) ? 1'b0 : 1'b1; fp_src_fmt_o = FP64; @@ -931,6 +971,7 @@ module ibex_decoder #( 7'b1101000: begin // FCVT.S.W, FCVT.S.WU fp_rf_we_o = 1'b1; use_fp_rd_o = 1'b1; + fp_rf_ren_a_o = 1'b1; if (~|instr[24:21]) begin illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; @@ -939,6 +980,7 @@ module ibex_decoder #( 7'b1111001: begin // FCVT.D.W, FCVT.D.WU rf_we = 1'b1; // write back in int_regfile use_fp_rd_o = 1'b1; + fp_rf_ren_a_o = 1'b1; if (~|instr[24:21]) begin illegal_insn = ((RVF == RV32DDouble) & (fp_invalid_rm)) ? 1'b0 : 1'b1; fp_src_fmt_o = FP64; @@ -948,6 +990,7 @@ module ibex_decoder #( fp_rf_we_o = 1'b1; use_fp_rd_o = 1'b1; mv_instr_o = 1'b1; + fp_rf_ren_a_o = 1'b1; if (~(|instr[24:20]) | (|instr[14:12])) begin illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv index 27a0291d..5c9dc55f 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv @@ -193,6 +193,9 @@ module ibex_id_stage #( output logic [4:0] fp_rf_raddr_a_o, output logic [4:0] fp_rf_raddr_b_o, output logic [4:0] fp_rf_raddr_c_o, + output logic fp_rf_ren_a_o, + output logic fp_rf_ren_b_o, + output logic fp_rf_ren_c_o, output logic [4:0] fp_rf_waddr_o, output logic fp_rf_we_o, @@ -550,6 +553,9 @@ module ibex_id_stage #( .fp_rf_raddr_a_o ( fp_rf_raddr_a_o ), .fp_rf_raddr_b_o ( fp_rf_raddr_b_o ), .fp_rf_raddr_c_o ( fp_rf_raddr_c_o ), + .fp_rf_ren_a_o ( fp_rf_ren_a_o ), + .fp_rf_ren_b_o ( fp_rf_ren_b_o ), + .fp_rf_ren_c_o ( fp_rf_ren_c_o ), .fp_rf_waddr_o ( fp_rf_waddr_o ), .fp_rf_we_o ( fp_rf_we_o ), .fp_alu_operator_o ( fp_alu_operator_o ), diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv index 78204982..d6e2dc76 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv @@ -65,7 +65,15 @@ module ibex_tracer ( input logic [ 3:0] rvfi_mem_rmask, input logic [ 3:0] rvfi_mem_wmask, input logic [31:0] rvfi_mem_rdata, - input logic [31:0] rvfi_mem_wdata + input logic [31:0] rvfi_mem_wdata, + input logic [ 4:0] rvfi_frs1_addr, + input logic [ 4:0] rvfi_frs2_addr, + input logic [ 4:0] rvfi_frs3_addr, + input logic [ 4:0] rvfi_frd_addr, + input logic [31:0] rvfi_frs1_rdata, + input logic [31:0] rvfi_frs2_rdata, + input logic [31:0] rvfi_frs3_rdata, + input logic [31:0] rvfi_frd_wdata ); // These signals are part of RVFI, but not used in this module currently. @@ -87,6 +95,7 @@ module ibex_tracer ( int unsigned cycle; string decoded_str; logic insn_is_compressed; + logic insn_is_float; // Data items accessed during this instruction localparam logic [4:0] RS1 = (1 << 0); @@ -160,9 +169,15 @@ module ibex_tracer ( // Format register address with "x" prefix, left-aligned to a fixed width of 3 characters. function automatic string reg_addr_to_str(input logic [4:0] addr); if (addr < 10) begin - return $sformatf(" x%0d", addr); + if (insn_is_float) + return $sformatf(" f%0d", addr); + else + return $sformatf(" x%0d", addr); end else begin - return $sformatf("x%0d", addr); + if (insn_is_float) + return $sformatf("f%0d", addr); + else + return $sformatf("x%0d", addr); end endfunction @@ -727,6 +742,117 @@ module ibex_tracer ( decoded_str = $sformatf("fence\t%s,%s", predecessor, successor); endfunction + function automatic void decode_fused_ma(input string mnemonic); + insn_is_float = 1'b1; + data_accessed = RS1 | RS2 | RS3 | RD; + decoded_str = $sformatf("%s\tf%0d,f%0d,f%0d,f%0d", mnemonic, rvfi_frd_addr, rvfi_frs1_addr, + rvfi_frs2_addr, rvfi_frs2_addr); + endfunction + + function automatic void decode_fr_insn(input string mnemonic); + insn_is_float = 1'b1; + data_accessed = RS1 | RS2 | RD; + decoded_str = $sformatf("%s\tf%0d,f%0d,f%0d", mnemonic, rvfi_frd_addr, rvfi_frs1_addr, + rvfi_frs2_addr); + endfunction + + function automatic void decode_fsqrt(input string mnemonic); + insn_is_float = 1'b1; + data_accessed = RS1 | RD; + decoded_str = $sformatf("%s\tx%0d,f%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr); + endfunction + + function automatic void decode_fcvt_f2i(input string mnemonic); + insn_is_float = 1'b1; + data_accessed = RS1 | RD; + decoded_str = $sformatf("%s\tx%0d,f%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr); + endfunction + + function automatic void decode_fcvt_i2f(input string mnemonic); + insn_is_float = 1'b1; + data_accessed = RS1 | RD; + decoded_str = $sformatf("%s\tf%0d,x%0d", mnemonic, rvfi_frd_addr, rvfi_rs1_addr); + endfunction + + function automatic void decode_fcomp(input string mnemonic); + insn_is_float = 1'b1; + data_accessed = RS2 | RS1 | RD; + decoded_str = $sformatf("%s\tx%0d,f%0d,f%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr, + rvfi_frs2_addr); + endfunction + + function automatic void decode_fmin_max(input string mnemonic); + insn_is_float = 1'b1; + data_accessed = RS2 | RS1 | RD; + decoded_str = $sformatf("%s\tf%0d,f%0d,f%0d", mnemonic, rvfi_frd_addr, rvfi_frs1_addr, + rvfi_frs2_addr); + endfunction + + function automatic void decode_fsgnj(input string mnemonic); + insn_is_float = 1'b1; + data_accessed = RS2 | RS1 | RD; + decoded_str = $sformatf("%s\tf%0d,f%0d,f%0d", mnemonic, rvfi_frd_addr, rvfi_frs1_addr, + rvfi_frs2_addr); + endfunction + + function automatic void decode_fmv_xw(input string mnemonic); + insn_is_float = 1'b1; + data_accessed = RS1 | RD; + decoded_str = $sformatf("%s\tf%0d,x%0d", mnemonic, rvfi_frd_addr, rvfi_rs1_addr); + endfunction + + function automatic void decode_fmv_wx(input string mnemonic); + insn_is_float = 1'b1; + data_accessed = RS1 | RD; + decoded_str = $sformatf("%s\tx%0d,f%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr); + endfunction + + function automatic void decode_fclass(input string mnemonic); + insn_is_float = 1'b1; + data_accessed = RS1 | RD; + decoded_str = $sformatf("%s\tx%0d,f%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr); + endfunction + + function automatic void decode_fload_insn(); + string mnemonic; + logic [2:0] size; + size = rvfi_insn[14:12]; + insn_is_float = 1'b1; + + if (size == 3'b010) begin + mnemonic = "flw"; + end else begin + decode_mnemonic("INVALID"); + return; + end + + data_accessed = RD | RS1 | MEM; + decoded_str = $sformatf("%s\tf%0d,%0d(x%0d)", mnemonic, rvfi_frd_addr, + $signed({{20 {rvfi_insn[31]}}, rvfi_insn[31:20]}), rvfi_rs1_addr); + endfunction + + function automatic void decode_fstore_insn(); + string mnemonic; + insn_is_float = 1'b1; + + unique case (rvfi_insn[13:12]) + 2'b10: mnemonic = "fsw"; + default: begin + decode_mnemonic("INVALID"); + return; + end + endcase + + if (!rvfi_insn[14]) begin + // floating point store + data_accessed = RS1 | RS2 | MEM; + decoded_str = $sformatf("%s\tf%0d,%0d(x%0d)", mnemonic, rvfi_frs2_addr, + $signed({ {20 {rvfi_insn[31]}}, rvfi_insn[31:25], rvfi_insn[11:7] }), rvfi_rs1_addr); + end else begin + decode_mnemonic("INVALID"); + end + endfunction + // cycle counter always_ff @(posedge clk_i or negedge rst_ni) begin if (!rst_ni) begin @@ -754,6 +880,7 @@ module ibex_tracer ( decoded_str = ""; data_accessed = 5'h0; insn_is_compressed = 0; + insn_is_float = 0; // Check for compressed instructions if (rvfi_insn[1:0] != 2'b11) begin @@ -1042,6 +1169,53 @@ module ibex_tracer ( INSN_CRC32C_H: decode_r1_insn("crc32c.h"); INSN_CRC32C_W: decode_r1_insn("crc32c.w"); + // Single Precision Floating Point + // Floating Load & Store + INSN_FLOAD: decode_fload_insn(); + INSN_FSTORE: decode_fstore_insn(); + + // Fused Multiply & Add Instructions + INSN_FMADD: decode_fused_ma("fmadd.s"); + INSN_FMSUB: decode_fused_ma("fmsub.s"); + INSN_FNMADD: decode_fused_ma("fnmadd.s"); + INSN_FNMSUB: decode_fused_ma("fnmsub.s"); + + // Arithmetic + INSN_FADD: decode_fr_insn("fadd.s"); + INSN_FSUB: decode_fr_insn("fsub.s"); + INSN_FMUL: decode_fr_insn("fmul.s"); + INSN_FDIV: decode_fr_insn("fdiv.s"); + + // Sqaure root + INSN_FSQRT: decode_fsqrt("fsqrt.s"); + + // Conversion + INSN_FCVTWS: decode_fcvt_f2i("fcvt.w.s"); + INSN_FCVTWUS: decode_fcvt_f2i("fcvt.wu.s"); + INSN_FCVTSW: decode_fcvt_i2f("fcvt.s.w"); + INSN_FCVTSWU: decode_fcvt_i2f("fcvt.s.wu"); + + // Comparison + INSN_FEQ: decode_fcomp("feq.s"); + INSN_FLT: decode_fcomp("flt.s"); + INSN_FLE: decode_fcomp("fle.s"); + + // Min & Max + INSN_FMIN: decode_fmin_max("fmin.s"); + INSN_FMAX: decode_fmin_max("fmax.s"); + + // Sign Injection + INSN_FSGNJ: decode_fsgnj("fsgnj.s"); + INSN_FSGNJN: decode_fsgnj("fsgnjn.s"); + INSN_FSGNJX: decode_fsgnj("fsgnjx.s"); + + // Move + INSN_FMVXW: decode_fmv_xw("fmv.x.w"); + INSN_FMVWX: decode_fmv_wx("fmv.w.x"); + + // Determine class of FP result + INSN_FCLASS: decode_fclass("fclass.s"); + default: decode_mnemonic("INVALID"); endcase end diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer_pkg.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer_pkg.sv index d42d4c94..5816c958 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer_pkg.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer_pkg.sv @@ -71,6 +71,41 @@ parameter logic [31:0] INSN_PMUH = { 7'b0000001, 10'h?, 3'b001, 5'h?, {OPCODE parameter logic [31:0] INSN_PMULHSU = { 7'b0000001, 10'h?, 3'b010, 5'h?, {OPCODE_OP} }; parameter logic [31:0] INSN_PMULHU = { 7'b0000001, 10'h?, 3'b011, 5'h?, {OPCODE_OP} }; +// RV32F +// Floating Load & Store +parameter logic [31:0] INSN_FLOAD = { 17'h?, 3'b010, 5'h?, {OPCODE_LOAD_FP } }; +parameter logic [31:0] INSN_FSTORE = { 17'h?, 3'b010, 5'h?, {OPCODE_STORE_FP} }; +// Fused Multiply & Add Instructions +parameter logic [31:0] INSN_FMADD = { 5'h?, 2'b00, 18'h?, {OPCODE_MADD_FP} }; +parameter logic [31:0] INSN_FMSUB = { 5'h?, 2'b00, 18'h?, {OPCODE_MSUB_FP} }; +parameter logic [31:0] INSN_FNMADD = { 5'h?, 2'b00, 18'h?, {OPCODE_NMADD_FP} }; +parameter logic [31:0] INSN_FNMSUB = { 5'h?, 2'b00, 18'h?, {OPCODE_NMSUB_FP} }; +// Arithmetic +parameter logic [31:0] INSN_FADD = { 7'b0000000, 18'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FSUB = { 7'b0000100, 18'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FMUL = { 7'b0001000, 18'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FDIV = { 7'b0001100, 18'h?, {OPCODE_OP_FP} }; +// SQRT & Conversion +parameter logic [31:0] INSN_FSQRT = { 7'b0101100, 5'b00000, 13'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FCVTWS = { 7'b1100000, 5'b00000, 13'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FCVTWUS = { 7'b1100000, 5'b00001, 13'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FCVTSW = { 7'b1101000, 5'b00000, 13'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FCVTSWU = { 7'b1101000, 5'b00001, 13'h?, {OPCODE_OP_FP} }; +// Comparison +parameter logic [31:0] INSN_FEQ = { 7'b1010000, 10'h?, 3'b010, 5'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FLT = { 7'b1010000, 10'h?, 3'b001, 5'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FLE = { 7'b1010000, 10'h?, 3'b000, 5'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FMIN = { 7'b0010100, 10'h?, 3'b000, 5'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FMAX = { 7'b0010100, 10'h?, 3'b001, 5'h?, {OPCODE_OP_FP} }; +// Sign Injection +parameter logic [31:0] INSN_FSGNJ = { 7'b0010000, 10'h?, 3'b000, 5'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FSGNJN = { 7'b0010000, 10'h?, 3'b001, 5'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FSGNJX = { 7'b0010000, 10'h?, 3'b010, 5'h?, {OPCODE_OP_FP} }; +// Move & Class +parameter logic [31:0] INSN_FMVXW = { 7'b1110000, 5'b00000, 5'h?, 3'b000, 5'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FMVWX = { 7'b1111000, 5'b00000, 5'h?, 3'b000, 5'h?, {OPCODE_OP_FP} }; +parameter logic [31:0] INSN_FCLASS = { 7'b1110000, 5'b00000, 5'h?, 3'b001, 5'h?, {OPCODE_OP_FP} }; + // RV32B // ZBB parameter logic [31:0] INSN_SLOI = { 5'b00100 , 12'h?, 3'b001, 5'h?, {OPCODE_OP_IMM} }; From 26e2b902ce7a85342b060d3dbbd1ad2728962455 Mon Sep 17 00:00:00 2001 From: zeeshanrafique23 Date: Thu, 30 Sep 2021 00:58:04 +0500 Subject: [PATCH 02/31] updated target to resolve sim warnings Signed-off-by: zeeshanrafique23 --- hw/ip/prim/fpv/prim_esc_rxtx_fpv.core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ip/prim/fpv/prim_esc_rxtx_fpv.core b/hw/ip/prim/fpv/prim_esc_rxtx_fpv.core index 3aa4c5a7..7c0b97bb 100644 --- a/hw/ip/prim/fpv/prim_esc_rxtx_fpv.core +++ b/hw/ip/prim/fpv/prim_esc_rxtx_fpv.core @@ -18,7 +18,7 @@ targets: default: &default_target # note, this setting is just used # to generate a file list for jg - formal: icarus + default_tool: icarus filesets: - files_formal toplevel: From 78729b18e48175b05353a2bfaf609875e29dbddb Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Thu, 30 Sep 2021 01:00:09 +0500 Subject: [PATCH 03/31] enable the 3rd stage pipeline Signed-off-by: Zeeshan Rafique --- .../examples/simple_system/rtl/ibex_simple_system.sv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/vendor/lowrisc_ibex/examples/simple_system/rtl/ibex_simple_system.sv b/hw/vendor/lowrisc_ibex/examples/simple_system/rtl/ibex_simple_system.sv index 92be495e..7589fadc 100644 --- a/hw/vendor/lowrisc_ibex/examples/simple_system/rtl/ibex_simple_system.sv +++ b/hw/vendor/lowrisc_ibex/examples/simple_system/rtl/ibex_simple_system.sv @@ -49,7 +49,7 @@ module ibex_simple_system ( parameter ibex_pkg::regfile_e RegFile = `RegFile; parameter ibex_pkg::rvfloat_e RVF = `RVF; parameter bit BranchTargetALU = 1'b0; - parameter bit WritebackStage = 1'b0; + parameter bit WritebackStage = 1'b1; parameter bit ICache = 1'b0; parameter bit ICacheECC = 1'b0; parameter bit BranchPredictor = 1'b0; From 6c7db2676e7b649bac52f00cca51b326f927f80d Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Thu, 30 Sep 2021 01:01:11 +0500 Subject: [PATCH 04/31] added .vscode Signed-off-by: Zeeshan Rafique --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dd5a42fe..bda19d1e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ build/ *.vcd fusesoc.conf html -Bender.lock \ No newline at end of file +Bender.lock +.vscode/ \ No newline at end of file From 5ac2c1c17770eca735921c5153730da7e0fce89c Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Thu, 30 Sep 2021 01:02:55 +0500 Subject: [PATCH 05/31] resolve bug in fcsr: illg dyn mode Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv index 1f249266..a1c1ce3e 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv @@ -305,14 +305,14 @@ module ibex_cs_registers #( // Floating point always_comb begin - unique case (frm_q) - 000, - 001, - 010, - 011, - 100: illegal_dyn_mod = 1'b0; - default: illegal_dyn_mod = 1'b1; - endcase + if (frm_d == 3'b111) begin + unique case (frm_q) + 101, + 110, + 111: illegal_dyn_mod = 1'b1; + default: illegal_dyn_mod = 1'b0; + endcase + end fp_frm_o = frm_q; end From 0cb1ce3d511fa089cd085c27fb757335d0fbf909 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Fri, 1 Oct 2021 23:40:18 +0500 Subject: [PATCH 06/31] corrected rd/rs1 in floating mv insn Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv index d6e2dc76..fe7eeba5 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv @@ -798,13 +798,13 @@ module ibex_tracer ( function automatic void decode_fmv_xw(input string mnemonic); insn_is_float = 1'b1; data_accessed = RS1 | RD; - decoded_str = $sformatf("%s\tf%0d,x%0d", mnemonic, rvfi_frd_addr, rvfi_rs1_addr); + decoded_str = $sformatf("%s\tx%0d,f%0d", mnemonic, rvfi_frd_addr, rvfi_rs1_addr); endfunction function automatic void decode_fmv_wx(input string mnemonic); insn_is_float = 1'b1; data_accessed = RS1 | RD; - decoded_str = $sformatf("%s\tx%0d,f%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr); + decoded_str = $sformatf("%s\tf%0d,x%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr); endfunction function automatic void decode_fclass(input string mnemonic); From a33022fcf46532c68809c937bf17503eee736535 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Mon, 4 Oct 2021 17:04:06 +0500 Subject: [PATCH 07/31] handle cvt/mv/lw operands and rd Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv | 104 +++++++++++++++++----- 1 file changed, 83 insertions(+), 21 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv index fe7eeba5..ee3bfb74 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv @@ -96,6 +96,9 @@ module ibex_tracer ( string decoded_str; logic insn_is_compressed; logic insn_is_float; + logic float_wx; + logic float_xw; + logic float_lw; // Data items accessed during this instruction localparam logic [4:0] RS1 = (1 << 0); @@ -139,17 +142,38 @@ module ibex_tracer ( $fwrite(file_handle, "%15t\t%d\t%h\t%s\t%s\t", $time, cycle, rvfi_pc_rdata, rvfi_insn_str, decoded_str); - if ((data_accessed & RS1) != 0) begin - $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_rs1_addr), rvfi_rs1_rdata); - end - if ((data_accessed & RS2) != 0) begin - $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_rs2_addr), rvfi_rs2_rdata); - end - if ((data_accessed & RS3) != 0) begin - $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_rs3_addr), rvfi_rs3_rdata); - end - if ((data_accessed & RD) != 0) begin - $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str(rvfi_rd_addr), rvfi_rd_wdata); + if (insn_is_float) begin + if ((data_accessed & RS1) != 0) begin + if (float_wx) + $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_rs1_addr), rvfi_rs1_rdata); + else + $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_frs1_addr), rvfi_frs1_rdata); + end + if ((data_accessed & RS2)) begin + $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_frs2_addr), rvfi_frs2_rdata); + end + if ((data_accessed & RS3)) begin + $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_frs3_addr), rvfi_frs3_rdata); + end + if ((data_accessed & RD) != 0) begin + if (float_xw) + $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str_rd(rvfi_rd_addr), rvfi_rd_wdata); + else + $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str_rd(rvfi_frd_addr), rvfi_frd_wdata); + end + end else begin + if ((data_accessed & RS1) != 0) begin + $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_rs1_addr), rvfi_rs1_rdata); + end + if ((data_accessed & RS2) != 0) begin + $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_rs2_addr), rvfi_rs2_rdata); + end + if ((data_accessed & RS3) != 0) begin + $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_rs3_addr), rvfi_rs3_rdata); + end + if ((data_accessed & RD) != 0) begin + $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str(rvfi_rd_addr), rvfi_rd_wdata); + end end if ((data_accessed & MEM) != 0) begin $fwrite(file_handle, " PA:0x%08x", rvfi_mem_addr); @@ -165,19 +189,49 @@ module ibex_tracer ( $fwrite(file_handle, "\n"); endfunction - - // Format register address with "x" prefix, left-aligned to a fixed width of 3 characters. + // Format register address with "x" or "f" prefix, left-aligned to a fixed width of 3 characters. function automatic string reg_addr_to_str(input logic [4:0] addr); if (addr < 10) begin - if (insn_is_float) - return $sformatf(" f%0d", addr); - else + if (insn_is_float) begin + if (float_wx | float_lw) + return $sformatf(" x%0d", addr); + else + return $sformatf(" f%0d", addr); + end else begin + return $sformatf(" x%0d", addr); + end + end else begin + if (insn_is_float) begin + if (float_wx | float_lw) + return $sformatf("x%0d", addr); + else + return $sformatf("f%0d", addr); + end else begin + return $sformatf("x%0d", addr); + end + end + endfunction + + // Format register address with "x" or "f" prefix, left-aligned to a fixed width of 3 characters. + function automatic string reg_addr_to_str_rd(input logic [4:0] addr); + if (addr < 10) begin + if (insn_is_float) begin + if (float_xw) + return $sformatf(" x%0d", addr); + else + return $sformatf(" f%0d", addr); + end else begin return $sformatf(" x%0d", addr); + end end else begin - if (insn_is_float) - return $sformatf("f%0d", addr); - else + if (insn_is_float) begin + if (float_xw) + return $sformatf("x%0d", addr); + else + return $sformatf("f%0d", addr); + end else begin return $sformatf("x%0d", addr); + end end endfunction @@ -764,12 +818,14 @@ module ibex_tracer ( function automatic void decode_fcvt_f2i(input string mnemonic); insn_is_float = 1'b1; + float_xw = 1; data_accessed = RS1 | RD; decoded_str = $sformatf("%s\tx%0d,f%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr); endfunction function automatic void decode_fcvt_i2f(input string mnemonic); insn_is_float = 1'b1; + float_wx = 1; data_accessed = RS1 | RD; decoded_str = $sformatf("%s\tf%0d,x%0d", mnemonic, rvfi_frd_addr, rvfi_rs1_addr); endfunction @@ -797,14 +853,16 @@ module ibex_tracer ( function automatic void decode_fmv_xw(input string mnemonic); insn_is_float = 1'b1; + float_xw = 1'b1; data_accessed = RS1 | RD; - decoded_str = $sformatf("%s\tx%0d,f%0d", mnemonic, rvfi_frd_addr, rvfi_rs1_addr); + decoded_str = $sformatf("%s\tx%0d,f%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr); endfunction function automatic void decode_fmv_wx(input string mnemonic); insn_is_float = 1'b1; + float_wx = 1'b1; data_accessed = RS1 | RD; - decoded_str = $sformatf("%s\tf%0d,x%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr); + decoded_str = $sformatf("%s\tf%0d,x%0d", mnemonic, rvfi_frd_addr, rvfi_rs1_addr); endfunction function automatic void decode_fclass(input string mnemonic); @@ -816,6 +874,7 @@ module ibex_tracer ( function automatic void decode_fload_insn(); string mnemonic; logic [2:0] size; + float_lw = 1; size = rvfi_insn[14:12]; insn_is_float = 1'b1; @@ -881,6 +940,9 @@ module ibex_tracer ( data_accessed = 5'h0; insn_is_compressed = 0; insn_is_float = 0; + float_wx = 0; + float_xw = 0; + float_lw = 0; // Check for compressed instructions if (rvfi_insn[1:0] != 2'b11) begin From 955fa30ac9d1eeb79e532a62303cc0838169b11a Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Thu, 7 Oct 2021 23:58:15 +0500 Subject: [PATCH 08/31] updated the swap logic Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv | 36 +++++++-------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv index 5c9dc55f..33d2649e 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv @@ -215,7 +215,8 @@ module ibex_id_stage #( input logic [FPU_WIDTH-1:0] fp_rf_wdata_fwd_wb_i, output logic [FPU_WIDTH-1:0] fp_rf_wdata_id_o, output logic [2:0][FPU_WIDTH-1:0] fp_operands_o, - output logic fp_load_o + output logic fp_load_o, + output logic fp_swap_oprnds_o ); import ibex_pkg::*; @@ -313,37 +314,24 @@ module ibex_id_stage #( /* FPU Limits STARTS */ logic mv_instr; - logic fp_swap_oprnds; logic [FPU_WIDTH-1:0] fp_rf_rdata_a_fwd; logic [FPU_WIDTH-1:0] fp_rf_rdata_b_fwd; logic [FPU_WIDTH-1:0] fp_rf_rdata_c_fwd; logic [FPU_WIDTH-1:0] temp; logic [FPU_WIDTH-1:0] fpu_op_a; - logic [31:0] fpu_op_b; + logic [FPU_WIDTH:0] fpu_op_b; logic [FPU_WIDTH-1:0] fpu_op_c; logic [FPU_WIDTH-1:0] result_wb; - logic [FPU_WIDTH-1:0] fpu_a; - logic [FPU_WIDTH-1:0] fpu_b; - logic [FPU_WIDTH-1:0] fpu_c; if (RVF == RV32FSingle || RVF == RV32DDouble) begin - assign fpu_a = use_fp_rs1_o ? fp_rf_rdata_a_fwd : rf_rdata_a_fwd; - assign fpu_b = use_fp_rs2_o ? fp_rf_rdata_b_fwd : rf_rdata_b_fwd; - assign fpu_c = fp_rf_rdata_c_fwd; - - /* Swap operands */ - always_comb begin : swapping - if (fp_swap_oprnds) begin - temp = fpu_c; - fpu_op_c = fpu_a; - fpu_op_a = temp; - end else begin - fpu_op_a = fpu_a; - fpu_op_b = fpu_b; - fpu_op_c = fpu_c; - end - fp_operands_o = {fpu_op_c , fpu_op_b , fpu_op_a}; - end + assign fpu_op_a = use_fp_rs1_o ? fp_rf_rdata_a_fwd : rf_rdata_a_fwd; + assign fpu_op_b = use_fp_rs2_o ? fp_rf_rdata_b_fwd : rf_rdata_b_fwd; + assign fpu_op_c = fp_rf_rdata_c_fwd; + + /* Swap operands for FADD/FSUB */ + assign fp_operands_o = fp_swap_oprnds_o ? {fpu_op_b, fpu_op_a, fpu_op_c} : + {fpu_op_c, fpu_op_b, fpu_op_a}; + assign result_wb = mv_instr ? fpu_op_a : result_ex_i; end else begin assign fpu_op_b = rf_rdata_b_fwd; @@ -568,7 +556,7 @@ module ibex_id_stage #( .use_fp_rs2_o ( use_fp_rs2_o ), .use_fp_rs3_o ( use_fp_rs3_o ), .use_fp_rd_o ( use_fp_rd_o ), - .fp_swap_oprnds_o ( fp_swap_oprnds ), + .fp_swap_oprnds_o ( fp_swap_oprnds_o ), .fp_load_o ( fp_load_o ), .mv_instr_o ( mv_instr ) ); From 37fcb5c7ee3c201e6fbbe838fc75e64234c94bf4 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Fri, 8 Oct 2021 00:10:22 +0500 Subject: [PATCH 09/31] resolved fadd & fmv.w.x inst issues Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_core.sv | 9 ++++++--- hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv | 11 ++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv index 2b69e2da..60af24a5 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv @@ -738,7 +738,8 @@ module ibex_core #( .fp_rf_wdata_fwd_wb_i ( fp_rf_wdata_wb ), .fp_rf_wdata_id_o ( fp_rf_wdata_id ), .fp_operands_o ( fp_operands ), - .fp_load_o ( fp_load ) + .fp_load_o ( fp_load ), + .fp_swap_oprnds_o ( fp_swap_oprnds ) ); // for RVFI only @@ -1493,8 +1494,10 @@ module ibex_core #( rvfi_stage_frs1_addr[i] <= fp_rf_ren_a ? fp_rf_raddr_a : '0; rvfi_stage_frs2_addr[i] <= fp_rf_ren_b ? fp_rf_raddr_b : '0; rvfi_stage_frs3_addr[i] <= fp_rf_ren_c ? fp_rf_raddr_c : '0; - rvfi_stage_frs1_rdata[i] <= fp_rf_ren_a ? fp_operands[0]: '0; - rvfi_stage_frs2_rdata[i] <= fp_rf_ren_b ? fp_operands[1]: '0; + rvfi_stage_frs1_rdata[i] <= fp_rf_ren_a ? fp_swap_oprnds ? + fp_operands[1]: fp_operands[0]: '0; + rvfi_stage_frs2_rdata[i] <= fp_rf_ren_b ? fp_swap_oprnds ? + fp_operands[2]: fp_operands[1]: '0; rvfi_stage_frs3_rdata[i] <= fp_rf_ren_c ? fp_operands[2]: '0; rvfi_stage_frd_addr[i] <= rvfi_frd_addr_d; rvfi_stage_frd_wdata[i] <= rvfi_frd_wdata_d; diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv index b564dbcf..ed4e84e1 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv @@ -990,6 +990,7 @@ module ibex_decoder #( use_fp_rd_o = 1'b1; mv_instr_o = 1'b1; fp_rf_ren_a_o = 1'b1; + rf_ren_a_o = 1'b1; if (~(|instr[24:20]) | (|instr[14:12])) begin illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; @@ -1737,11 +1738,11 @@ module ibex_decoder #( fp_alu_op_mod_o = 1'b1; end end - // 7'b1111000: begin // FMV.W.X - // if ((|instr[24:20]) | (|instr[14:12])) begin - // fp_alu_operator_o = FMADD; // to be decided - // end - // end + 7'b1111000: begin // FMV.W.X + if (~(|instr[24:20]) | (|instr[14:12])) begin + fp_alu_operator_o = I2F; + end + end default: ; endcase end From a258aec4384afc2209d5bfbe90c95a9a9d914ab5 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Fri, 8 Oct 2021 11:36:01 +0500 Subject: [PATCH 10/31] [ibex_id_stage] fixed width issue for fpu_op_b Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv index 33d2649e..15b94609 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv @@ -319,7 +319,7 @@ module ibex_id_stage #( logic [FPU_WIDTH-1:0] fp_rf_rdata_c_fwd; logic [FPU_WIDTH-1:0] temp; logic [FPU_WIDTH-1:0] fpu_op_a; - logic [FPU_WIDTH:0] fpu_op_b; + logic [FPU_WIDTH-1:0] fpu_op_b; logic [FPU_WIDTH-1:0] fpu_op_c; logic [FPU_WIDTH-1:0] result_wb; From 0e1a29b058864ee4b345b93a702e02d8907e40bb Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sat, 9 Oct 2021 17:04:49 +0500 Subject: [PATCH 11/31] [ibex_core] optimize datapath for fpu Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_core.sv | 16 ++++------- hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv | 18 ++++++------ hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv | 32 ++++++++++++--------- hw/vendor/lowrisc_ibex/rtl/ibex_wb_stage.sv | 7 +++-- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv index 60af24a5..bbcfcaef 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv @@ -165,8 +165,6 @@ module ibex_core #( logic fp_busy; logic fpu_busy_idu; logic [FPU_WIDTH-1:0] fp_result; - logic [31:0] data_wb; - logic [31:0] rf_int_fp_lsu; logic [4:0] fp_rf_waddr_id; logic [4:0] fp_rf_waddr_wb; logic fp_rf_we; @@ -181,6 +179,7 @@ module ibex_core #( logic fp_load; logic [FPU_WIDTH-1:0] fp_rf_wdata_wb; logic [FPU_WIDTH-1:0] fp_rf_wdata_id; + logic [FPU_WIDTH-1:0] fp_result_ex; fpnew_pkg::status_t fp_status; fpnew_pkg::operation_e fp_operation; fpnew_pkg::roundmode_e fp_rounding_mode; @@ -673,14 +672,13 @@ module ibex_core #( .trigger_match_i ( trigger_match ), // write data to commit in the register file - .result_ex_i ( data_wb ), // changed by zeeshan from result_ex - // to data_wb for FVCT, FMV.WX ins + .result_ex_i ( result_ex ), .csr_rdata_i ( csr_rdata ), .rf_raddr_a_o ( rf_raddr_a ), .rf_rdata_a_i ( rf_rdata_a ), .rf_raddr_b_o ( rf_raddr_b ), - .rf_rdata_b_i ( rf_int_fp_lsu ), + .rf_rdata_b_i ( rf_rdata_b ), .rf_ren_a_o ( rf_ren_a ), .rf_ren_b_o ( rf_ren_b ), .rf_waddr_id_o ( rf_waddr_id ), @@ -738,6 +736,7 @@ module ibex_core #( .fp_rf_wdata_fwd_wb_i ( fp_rf_wdata_wb ), .fp_rf_wdata_id_o ( fp_rf_wdata_id ), .fp_operands_o ( fp_operands ), + .fp_result_ex_i ( fp_result_ex ), .fp_load_o ( fp_load ), .fp_swap_oprnds_o ( fp_swap_oprnds ) ); @@ -1060,23 +1059,18 @@ module ibex_core #( .wdata_a_i ( fp_rf_wdata_wb ), .we_a_i ( fp_rf_wen_wb ) ); - assign rf_int_fp_lsu = (is_fp_instr & use_fp_rs2) ? fp_rf_rdata_b : rf_rdata_b; assign fp_frm_fpnew = fp_rm_dynamic ? fp_frm_csr : fp_rounding_mode; - assign in_ready_c2fpu = id_in_ready; //multdiv_ready_id; + assign in_ready_c2fpu = id_in_ready; assign in_valid_c2fpu = (instr_valid_id & is_fp_instr); - // assign ready_id_fpu = id_in_ready; // (is_fp_instr) ? out_ready_fpu2c : id_in_ready; assign valid_id_fpu = (is_fp_instr) ? out_valid_fpu2c : ex_valid; assign fpu_busy_idu = fp_busy & (~out_valid_fpu2c); - assign data_wb = is_fp_instr ? fp_result : result_ex; assign core_busy_d = ctrl_busy | if_busy | lsu_busy | fp_busy; end else begin // Before going to sleep, wait for I- and D-side // interfaces to finish ongoing operations. assign core_busy_d = ctrl_busy | if_busy | lsu_busy; - assign data_wb = result_ex; assign valid_id_fpu = ex_valid; - assign rf_int_fp_lsu = rf_rdata_b; end /////////////////// diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv index ed4e84e1..e50d54ae 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv @@ -122,7 +122,8 @@ module ibex_decoder #( output logic use_fp_rd_o, output logic fp_swap_oprnds_o, output logic fp_load_o, - output logic mv_instr_o + output logic mv_instn_xw_o, + output logic mv_instn_wx_o ); import ibex_pkg::*; @@ -281,7 +282,8 @@ module ibex_decoder #( fp_src_fmt_o = FP32; fp_dst_fmt_o = FP32; fp_swap_oprnds_o = 1'b0; - mv_instr_o = 1'b0; + mv_instn_xw_o = 1'b0; + mv_instn_wx_o = 1'b0; fp_rf_ren_a_o = 1'b0; fp_rf_ren_b_o = 1'b0; fp_rf_ren_c_o = 1'b0; @@ -910,7 +912,7 @@ module ibex_decoder #( use_fp_rs1_o = 1'b1; illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; - mv_instr_o = 1'b1; + mv_instn_xw_o = 1'b1; end {5'b00000,3'b001}: begin use_fp_rs1_o = 1'b1; @@ -988,7 +990,7 @@ module ibex_decoder #( 7'b1111000: begin // FMV.W.X fp_rf_we_o = 1'b1; use_fp_rd_o = 1'b1; - mv_instr_o = 1'b1; + mv_instn_wx_o = 1'b1; fp_rf_ren_a_o = 1'b1; rf_ren_a_o = 1'b1; if (~(|instr[24:20]) | (|instr[14:12])) begin @@ -1687,9 +1689,9 @@ module ibex_decoder #( end 7'b1110000: begin // FMV.X.W , FCLASS.S unique case ({instr[24:20],instr[14:12]}) - // {3'b0000000,3'b000}: begin - // fp_alu_operator_o = ADD; // to be decided YET - // end + {3'b0000000,3'b000}: begin + fp_alu_operator_o = ADD; // we want move, so the result is not relavent + end {3'b000,3'b001}: begin fp_alu_operator_o = CLASSIFY; end @@ -1740,7 +1742,7 @@ module ibex_decoder #( end 7'b1111000: begin // FMV.W.X if (~(|instr[24:20]) | (|instr[14:12])) begin - fp_alu_operator_o = I2F; + fp_alu_operator_o = ADD; // we want move, so the result is not relavent end end default: ; diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv index 15b94609..15bbbd02 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv @@ -215,6 +215,7 @@ module ibex_id_stage #( input logic [FPU_WIDTH-1:0] fp_rf_wdata_fwd_wb_i, output logic [FPU_WIDTH-1:0] fp_rf_wdata_id_o, output logic [2:0][FPU_WIDTH-1:0] fp_operands_o, + input logic [FPU_WIDTH-1:0] fp_result_ex_i, output logic fp_load_o, output logic fp_swap_oprnds_o ); @@ -276,6 +277,7 @@ module ibex_id_stage #( logic [31:0] rf_rdata_a_fwd; logic [31:0] rf_rdata_b_fwd; + logic [31:0] result_wb; // ALU Control alu_op_e alu_operator; @@ -312,8 +314,9 @@ module ibex_id_stage #( logic [31:0] alu_operand_a; logic [31:0] alu_operand_b; - /* FPU Limits STARTS */ - logic mv_instr; + /* FPU limit start */ + logic mv_instn_xw; + logic mv_instn_wx; logic [FPU_WIDTH-1:0] fp_rf_rdata_a_fwd; logic [FPU_WIDTH-1:0] fp_rf_rdata_b_fwd; logic [FPU_WIDTH-1:0] fp_rf_rdata_c_fwd; @@ -321,7 +324,7 @@ module ibex_id_stage #( logic [FPU_WIDTH-1:0] fpu_op_a; logic [FPU_WIDTH-1:0] fpu_op_b; logic [FPU_WIDTH-1:0] fpu_op_c; - logic [FPU_WIDTH-1:0] result_wb; + logic [FPU_WIDTH-1:0] fp_result_wb; if (RVF == RV32FSingle || RVF == RV32DDouble) begin assign fpu_op_a = use_fp_rs1_o ? fp_rf_rdata_a_fwd : rf_rdata_a_fwd; @@ -332,11 +335,13 @@ module ibex_id_stage #( assign fp_operands_o = fp_swap_oprnds_o ? {fpu_op_b, fpu_op_a, fpu_op_c} : {fpu_op_c, fpu_op_b, fpu_op_a}; - assign result_wb = mv_instr ? fpu_op_a : result_ex_i; + assign result_wb = mv_instn_xw ? fpu_op_a : result_ex_i; + assign fp_result_wb = mv_instn_wx ? rf_rdata_a_fwd : fp_result_ex_i; end else begin - assign fpu_op_b = rf_rdata_b_fwd; + logic unused_fp_result_ex; + assign unused_fp_result_ex = &{ 1'b0, fp_result_ex_i, 1'b0}; end - /* FPU Limits ENDS */ + /* FPU limit end */ ///////////// // LSU Mux // @@ -558,7 +563,8 @@ module ibex_id_stage #( .use_fp_rd_o ( use_fp_rd_o ), .fp_swap_oprnds_o ( fp_swap_oprnds_o ), .fp_load_o ( fp_load_o ), - .mv_instr_o ( mv_instr ) + .mv_instn_xw_o ( mv_instn_xw ), + .mv_instn_wx_o ( mv_instn_wx ) ); /////////////////////// @@ -571,18 +577,18 @@ module ibex_id_stage #( // Register file write data mux always_comb begin : rf_wdata_id_mux unique case (rf_wdata_sel) - RF_WD_EX: rf_wdata_id_o = result_ex_i; + RF_WD_EX: rf_wdata_id_o = result_wb; RF_WD_CSR: rf_wdata_id_o = csr_rdata_i; - default: rf_wdata_id_o = result_ex_i; + default: rf_wdata_id_o = result_wb; endcase end - // Register file write data mux + // Floating point register file write data mux always_comb begin : fp_rf_wdata_id_mux unique case (rf_wdata_sel) - RF_WD_EX: fp_rf_wdata_id_o = result_wb; + RF_WD_EX: fp_rf_wdata_id_o = fp_result_wb; RF_WD_CSR: fp_rf_wdata_id_o = csr_rdata_i; - default: fp_rf_wdata_id_o = result_wb; + default: fp_rf_wdata_id_o = fp_result_wb; endcase end @@ -723,7 +729,7 @@ module ibex_id_stage #( assign lsu_we_o = lsu_we; assign lsu_type_o = lsu_type; assign lsu_sign_ext_o = lsu_sign_ext; - assign lsu_wdata_o = fpu_op_b; //rf_rdata_b_fwd; + assign lsu_wdata_o = is_fp_instr_o ? fp_rf_rdata_b_fwd : rf_rdata_b_fwd; // csr_op_en_o is set when CSR access should actually happen. // csv_access_o is set when CSR access instruction is present and is used to compute whether a CSR // access is illegal. A combinational loop would be created if csr_op_en_o was used along (as diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_wb_stage.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_wb_stage.sv index 3c7319b5..fac995a7 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_wb_stage.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_wb_stage.sv @@ -150,19 +150,21 @@ module ibex_wb_stage #( // floating point if (RVF == RV32FSingle || RVF == RV32DDouble) begin logic [FPU_WIDTH-1:0] fp_rf_wdata_wb_q; + logic [4:0] fp_rf_waddr_wb_q; logic fp_rf_we_wb_q; logic fp_load_q; always_ff @(posedge clk_i) begin if(en_wb_i) begin fp_rf_we_wb_q <= fp_rf_wen_id_i; + fp_rf_waddr_wb_q <= fp_rf_waddr_id_i; fp_rf_wdata_wb_q <= fp_rf_wdata_id_i; fp_load_q <= fp_load_i; end end - assign fp_rf_waddr_wb_o = rf_waddr_wb_q; // no seperate datapath for rd address - assign fp_rf_wdata_wb_mux[0] = rf_wdata_wb_q; // no seperate datapath for data bus + assign fp_rf_waddr_wb_o = fp_rf_waddr_wb_q; + assign fp_rf_wdata_wb_mux[0] = fp_rf_wdata_wb_q; assign fp_rf_wdata_wb_mux_we[0] = fp_rf_we_wb_q & wb_valid_q; // Instruction in writeback will be writing to register file if either rf_we is set or writeback @@ -177,6 +179,7 @@ module ibex_wb_stage #( assign rf_wdata_wb_mux_we[1] = rf_we_lsu_i; assign unused_fpu_wires = &{1'b0, fp_rf_wen_id_i, + fp_rf_waddr_id_i, fp_rf_wdata_id_i, fp_load_i, 1'b0}; From 6a8ada793c3e9ba6de9bb3ff7e2ed10dfc04890f Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sat, 9 Oct 2021 20:13:04 +0500 Subject: [PATCH 12/31] [ibex_compressed_decoder] amend floating point single precision compressed instructions Signed-off-by: Zeeshan Rafique --- .../rtl/ibex_compressed_decoder.sv | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_compressed_decoder.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_compressed_decoder.sv index 12a487fe..0e740927 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_compressed_decoder.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_compressed_decoder.sv @@ -56,6 +56,12 @@ module ibex_compressed_decoder ( 2'b00, 2'b01, instr_i[9:7], 3'b010, 2'b01, instr_i[4:2], {OPCODE_LOAD}}; end + 3'b011: begin + // c.flw -> flw frd`, imm(rs1) + instr_o = {5'b0, instr_i[5], instr_i[12:10], instr_i[6], + 2'b00, 2'b01, instr_i[9:7], 3'b010, 2'b01, instr_i[4:2], {OPCODE_LOAD_FP}}; + end + 3'b110: begin // c.sw -> sw rs2', imm(rs1') instr_o = {5'b0, instr_i[5], instr_i[12], 2'b01, instr_i[4:2], @@ -63,11 +69,16 @@ module ibex_compressed_decoder ( 2'b00, {OPCODE_STORE}}; end + 3'b111: begin + // c.fsw -> fsw frs2`, imm(rs1`) + instr_o = {5'b0, instr_i[5], instr_i[12], 2'b01, instr_i[4:2], + 2'b01, instr_i[9:7], 3'b010, instr_i[11:10], instr_i[6], + 2'b00, {OPCODE_STORE_FP}}; + end + 3'b001, - 3'b011, 3'b100, - 3'b101, - 3'b111: begin + 3'b101: begin illegal_instr_o = 1'b1; end @@ -220,6 +231,12 @@ module ibex_compressed_decoder ( if (instr_i[11:7] == 5'b0) illegal_instr_o = 1'b1; end + 3'b011: begin + // c.flwsp -> flw frd, imm(x2) + instr_o = {4'b0, instr_i[3:2], instr_i[12], instr_i[6:4], 2'b00, 5'h02, + 3'b010, instr_i[11:7], OPCODE_LOAD_FP}; + end + 3'b100: begin if (instr_i[12] == 1'b0) begin if (instr_i[6:2] != 5'b0) begin @@ -254,10 +271,14 @@ module ibex_compressed_decoder ( instr_i[11:9], 2'b00, {OPCODE_STORE}}; end - 3'b001, - 3'b011, - 3'b101, 3'b111: begin + // c.fswsp -> fsw frs2, imm(x2) + instr_o = {4'b0, instr_i[8:7], instr_i[12], instr_i[6:2], 5'h02, 3'b010, + instr_i[11:9], 2'b00, {OPCODE_STORE_FP}}; + end + + 3'b001, + 3'b101: begin illegal_instr_o = 1'b1; end From 429564e3f99d0d93fc6780254311d624cabdc37f Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sat, 9 Oct 2021 23:36:20 +0500 Subject: [PATCH 13/31] [ibex_tracer] update for fsw Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv | 26 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv index ee3bfb74..5f8441f4 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv @@ -99,6 +99,7 @@ module ibex_tracer ( logic float_wx; logic float_xw; logic float_lw; + logic float_sw; // Data items accessed during this instruction localparam logic [4:0] RS1 = (1 << 0); @@ -144,13 +145,16 @@ module ibex_tracer ( if (insn_is_float) begin if ((data_accessed & RS1) != 0) begin - if (float_wx) + if (float_wx | float_sw) $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_rs1_addr), rvfi_rs1_rdata); else $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_frs1_addr), rvfi_frs1_rdata); end if ((data_accessed & RS2)) begin - $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_frs2_addr), rvfi_frs2_rdata); + if (float_sw) + $fwrite(file_handle, " %s:0x%08x", $sformatf("f%0d", rvfi_frs2_addr), rvfi_frs2_rdata); + else + $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_frs2_addr), rvfi_frs2_rdata); end if ((data_accessed & RS3)) begin $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_frs3_addr), rvfi_frs3_rdata); @@ -161,6 +165,16 @@ module ibex_tracer ( else $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str_rd(rvfi_frd_addr), rvfi_frd_wdata); end + if ((data_accessed & MEM) != 0) begin + $fwrite(file_handle, " PA:0x%08x", rvfi_mem_addr); + + if (rvfi_mem_rmask != 4'b0000) begin + $fwrite(file_handle, " store:0x%08x", rvfi_mem_wdata); + end + if (rvfi_mem_wmask != 4'b0000) begin + $fwrite(file_handle, " load:0x%08x", rvfi_mem_rdata); + end + end end else begin if ((data_accessed & RS1) != 0) begin $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_rs1_addr), rvfi_rs1_rdata); @@ -174,8 +188,7 @@ module ibex_tracer ( if ((data_accessed & RD) != 0) begin $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str(rvfi_rd_addr), rvfi_rd_wdata); end - end - if ((data_accessed & MEM) != 0) begin + if ((data_accessed & MEM) != 0) begin $fwrite(file_handle, " PA:0x%08x", rvfi_mem_addr); if (rvfi_mem_rmask != 4'b0000) begin @@ -185,6 +198,7 @@ module ibex_tracer ( $fwrite(file_handle, " load:0x%08x", rvfi_mem_rdata); end end + end $fwrite(file_handle, "\n"); endfunction @@ -193,7 +207,7 @@ module ibex_tracer ( function automatic string reg_addr_to_str(input logic [4:0] addr); if (addr < 10) begin if (insn_is_float) begin - if (float_wx | float_lw) + if (float_wx | float_lw | float_sw) return $sformatf(" x%0d", addr); else return $sformatf(" f%0d", addr); @@ -904,6 +918,7 @@ module ibex_tracer ( if (!rvfi_insn[14]) begin // floating point store + float_sw = 1; data_accessed = RS1 | RS2 | MEM; decoded_str = $sformatf("%s\tf%0d,%0d(x%0d)", mnemonic, rvfi_frs2_addr, $signed({ {20 {rvfi_insn[31]}}, rvfi_insn[31:25], rvfi_insn[11:7] }), rvfi_rs1_addr); @@ -943,6 +958,7 @@ module ibex_tracer ( float_wx = 0; float_xw = 0; float_lw = 0; + float_sw = 0; // Check for compressed instructions if (rvfi_insn[1:0] != 2'b11) begin From 87830d2895fa348453f02c8ba98d81de299023f1 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sat, 9 Oct 2021 23:37:15 +0500 Subject: [PATCH 14/31] [core] fpu handling bug fix Signed-off-by: Zeeshan Rafique --- .../examples/simple_system/ibex_simple_system.core | 2 +- hw/vendor/lowrisc_ibex/rtl/ibex_core.sv | 3 +-- hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv | 5 +++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/examples/simple_system/ibex_simple_system.core b/hw/vendor/lowrisc_ibex/examples/simple_system/ibex_simple_system.core index bd4eb0bb..6582d012 100644 --- a/hw/vendor/lowrisc_ibex/examples/simple_system/ibex_simple_system.core +++ b/hw/vendor/lowrisc_ibex/examples/simple_system/ibex_simple_system.core @@ -77,7 +77,7 @@ parameters: WritebackStage: datatype: int paramtype: vlogparam - default: 0 + default: 1 description: "Enables third pipeline stage (EXPERIMENTAL)" SecureIbex: diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv index bbcfcaef..6738e225 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv @@ -164,7 +164,6 @@ module ibex_core #( logic [2:0][FPU_WIDTH-1:0] fp_operands; // three operands in fpu logic fp_busy; logic fpu_busy_idu; - logic [FPU_WIDTH-1:0] fp_result; logic [4:0] fp_rf_waddr_id; logic [4:0] fp_rf_waddr_wb; logic fp_rf_we; @@ -1032,7 +1031,7 @@ module ibex_core #( .in_valid_i ( in_valid_c2fpu ), .in_ready_o ( out_ready_fpu2c ), .flush_i ( fp_flush ), - .result_o ( fp_result ), + .result_o ( fp_result_ex ), .status_o ( fp_status ), .tag_o ( ), .out_valid_o ( out_valid_fpu2c ), diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv index e50d54ae..08d0eb3d 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv @@ -688,7 +688,8 @@ module ibex_decoder #( data_req_o = 1'b1; data_we_o = 1'b1; data_type_o = 2'b00; - fp_rf_ren_a_o = 1'b1; + rf_ren_a_o = 1'b1; + fp_rf_ren_b_o = 1'b1; use_fp_rs2_o = 1'b1; @@ -709,7 +710,7 @@ module ibex_decoder #( data_req_o = 1'b1; data_type_o = 2'b00; fp_load_o = 1'b1; - fp_rf_ren_a_o = 1'b1; + rf_ren_a_o = 1'b1; fp_rf_ren_b_o = 1'b1; use_fp_rd_o = 1'b1; From c1cd2786811649580d353b824534111851a48e48 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sun, 10 Oct 2021 00:04:54 +0500 Subject: [PATCH 15/31] [ibex_tracer] set common write func for lw/sw Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv index 5f8441f4..a680ee81 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv @@ -165,16 +165,6 @@ module ibex_tracer ( else $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str_rd(rvfi_frd_addr), rvfi_frd_wdata); end - if ((data_accessed & MEM) != 0) begin - $fwrite(file_handle, " PA:0x%08x", rvfi_mem_addr); - - if (rvfi_mem_rmask != 4'b0000) begin - $fwrite(file_handle, " store:0x%08x", rvfi_mem_wdata); - end - if (rvfi_mem_wmask != 4'b0000) begin - $fwrite(file_handle, " load:0x%08x", rvfi_mem_rdata); - end - end end else begin if ((data_accessed & RS1) != 0) begin $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_rs1_addr), rvfi_rs1_rdata); @@ -188,7 +178,9 @@ module ibex_tracer ( if ((data_accessed & RD) != 0) begin $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str(rvfi_rd_addr), rvfi_rd_wdata); end - if ((data_accessed & MEM) != 0) begin + end + + if ((data_accessed & MEM) != 0) begin $fwrite(file_handle, " PA:0x%08x", rvfi_mem_addr); if (rvfi_mem_rmask != 4'b0000) begin @@ -198,7 +190,6 @@ module ibex_tracer ( $fwrite(file_handle, " load:0x%08x", rvfi_mem_rdata); end end - end $fwrite(file_handle, "\n"); endfunction From 1b1e9e6eb1b1c8a44bc0bd9b16b795060bc79c43 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sun, 10 Oct 2021 11:49:33 +0500 Subject: [PATCH 16/31] [decoder] fix fsw bug Signed-off-by: Zeeshan Rafique --- .../lowrisc_ibex/dv/riscv_compliance/ibex_riscv_compliance.core | 1 + hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv | 1 + 2 files changed, 2 insertions(+) diff --git a/hw/vendor/lowrisc_ibex/dv/riscv_compliance/ibex_riscv_compliance.core b/hw/vendor/lowrisc_ibex/dv/riscv_compliance/ibex_riscv_compliance.core index cf5ef71b..41b3afef 100644 --- a/hw/vendor/lowrisc_ibex/dv/riscv_compliance/ibex_riscv_compliance.core +++ b/hw/vendor/lowrisc_ibex/dv/riscv_compliance/ibex_riscv_compliance.core @@ -145,3 +145,4 @@ targets: - '-Wno-INCABSPATH' - "-Wno-IMPERFECTSCH" - "-Wno-LITENDIAN" + - "-Wno-LATCH" diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv index 08d0eb3d..f0c1a704 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv @@ -690,6 +690,7 @@ module ibex_decoder #( data_type_o = 2'b00; rf_ren_a_o = 1'b1; fp_rf_ren_b_o = 1'b1; + is_fp_instr_o = 1'b1; use_fp_rs2_o = 1'b1; From 30d0c134ace78163c4f286a8e7efc8ee2ebcb94b Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sun, 10 Oct 2021 15:03:43 +0500 Subject: [PATCH 17/31] [ibex/rtl] fix bug related to fpu to int rf Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv | 10 ++++++++-- hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv index f0c1a704..e46d19ef 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv @@ -123,7 +123,8 @@ module ibex_decoder #( output logic fp_swap_oprnds_o, output logic fp_load_o, output logic mv_instn_xw_o, - output logic mv_instn_wx_o + output logic mv_instn_wx_o, + output logic fpu_to_int_rf_o ); import ibex_pkg::*; @@ -284,6 +285,7 @@ module ibex_decoder #( fp_swap_oprnds_o = 1'b0; mv_instn_xw_o = 1'b0; mv_instn_wx_o = 1'b0; + fpu_to_int_rf_o = 1'b0; fp_rf_ren_a_o = 1'b0; fp_rf_ren_b_o = 1'b0; fp_rf_ren_c_o = 1'b0; @@ -824,6 +826,7 @@ module ibex_decoder #( use_fp_rs1_o = 1'b1; use_fp_rd_o = 1'b1; fp_rf_ren_a_o = 1'b1; + fpu_to_int_rf_o = 1'b1; if (~|instr[24:20]) begin illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; @@ -890,7 +893,8 @@ module ibex_decoder #( 7'b1100000: begin // FCVT.W.S, FCVT.WU.S rf_we = 1'b1; // write back in int_regfile use_fp_rs1_o = 1'b1; - fp_rf_ren_a_o = 1'b1; + fp_rf_ren_a_o = 1'b1; + fpu_to_int_rf_o = 1'b1; if (~|instr[24:21]) begin illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; @@ -920,6 +924,7 @@ module ibex_decoder #( use_fp_rs1_o = 1'b1; illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; + fpu_to_int_rf_o = 1'b1; end default: begin illegal_insn =1'b1; @@ -943,6 +948,7 @@ module ibex_decoder #( use_fp_rs2_o = 1'b1; fp_rf_ren_a_o = 1'b1; fp_rf_ren_b_o = 1'b1; + fpu_to_int_rf_o = 1'b1; if (~(instr[14]) | (&instr[13:12])) begin illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv index 15bbbd02..5496d8b7 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv @@ -315,6 +315,7 @@ module ibex_id_stage #( logic [31:0] alu_operand_b; /* FPU limit start */ + logic fpu_to_int_rf; logic mv_instn_xw; logic mv_instn_wx; logic [FPU_WIDTH-1:0] fp_rf_rdata_a_fwd; @@ -335,7 +336,11 @@ module ibex_id_stage #( assign fp_operands_o = fp_swap_oprnds_o ? {fpu_op_b, fpu_op_a, fpu_op_c} : {fpu_op_c, fpu_op_b, fpu_op_a}; - assign result_wb = mv_instn_xw ? fpu_op_a : result_ex_i; + logic [FPU_WIDTH-1:0] fpu_wb_rf_int; + + assign fpu_wb_rf_int = mv_instn_xw ? fpu_op_a : fp_result_ex_i; + + assign result_wb = fpu_to_int_rf ? fpu_wb_rf_int : result_ex_i; assign fp_result_wb = mv_instn_wx ? rf_rdata_a_fwd : fp_result_ex_i; end else begin logic unused_fp_result_ex; @@ -564,7 +569,8 @@ module ibex_id_stage #( .fp_swap_oprnds_o ( fp_swap_oprnds_o ), .fp_load_o ( fp_load_o ), .mv_instn_xw_o ( mv_instn_xw ), - .mv_instn_wx_o ( mv_instn_wx ) + .mv_instn_wx_o ( mv_instn_wx ), + .fpu_to_int_rf_o ( fpu_to_int_rf ) ); /////////////////////// From 51ef41377381de5fcb5e0a1003957bd1e88ecfff Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sun, 10 Oct 2021 19:21:16 +0500 Subject: [PATCH 18/31] [rtl/ibex_decoder] Fix bug FMV.X.W Signed-off-by: Zeeshan Rafique --- .../lowrisc_ibex/dv/riscv_compliance/ibex_riscv_compliance.core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/vendor/lowrisc_ibex/dv/riscv_compliance/ibex_riscv_compliance.core b/hw/vendor/lowrisc_ibex/dv/riscv_compliance/ibex_riscv_compliance.core index 41b3afef..880b9005 100644 --- a/hw/vendor/lowrisc_ibex/dv/riscv_compliance/ibex_riscv_compliance.core +++ b/hw/vendor/lowrisc_ibex/dv/riscv_compliance/ibex_riscv_compliance.core @@ -69,7 +69,7 @@ parameters: WritebackStage: datatype: int paramtype: vlogparam - default: 0 + default: 1 description: "Enables third pipeline stage (EXPERIMENTAL)" BranchPredictor: From 2c605c1ff07edf844749fd82a63811a10a50d240 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sun, 10 Oct 2021 19:21:48 +0500 Subject: [PATCH 19/31] [rtl/ibex_decoder] Fix bug FMV.X.W Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv index e46d19ef..b3c77903 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv @@ -913,6 +913,7 @@ module ibex_decoder #( 7'b1110000: begin // FMV.X.W , FCLASS.S rf_we = 1'b1; // write back in int_regfile fp_rf_ren_a_o = 1'b1; + fpu_to_int_rf_o = 1'b1; unique case ({instr[24:20],instr[14:12]}) {5'b00000,3'b000}: begin use_fp_rs1_o = 1'b1; @@ -924,7 +925,6 @@ module ibex_decoder #( use_fp_rs1_o = 1'b1; illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; - fpu_to_int_rf_o = 1'b1; end default: begin illegal_insn =1'b1; From 9191465835505886ec5fc8568be31fe997b26e37 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Tue, 12 Oct 2021 16:44:37 +0500 Subject: [PATCH 20/31] [ibex/ibex_core] update fpu busy logic --- hw/vendor/lowrisc_ibex/rtl/ibex_core.sv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv index 6738e225..042ab7cb 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv @@ -1064,7 +1064,7 @@ module ibex_core #( assign valid_id_fpu = (is_fp_instr) ? out_valid_fpu2c : ex_valid; assign fpu_busy_idu = fp_busy & (~out_valid_fpu2c); - assign core_busy_d = ctrl_busy | if_busy | lsu_busy | fp_busy; + assign core_busy_d = ctrl_busy | if_busy | lsu_busy | fpu_busy_idu; end else begin // Before going to sleep, wait for I- and D-side // interfaces to finish ongoing operations. From 9a6afdb4415181251318ac599a6608b8ac2d53c4 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Thu, 14 Oct 2021 17:02:03 +0500 Subject: [PATCH 21/31] resolved floating point csr error Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv index a1c1ce3e..50e0a4a9 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv @@ -323,14 +323,14 @@ module ibex_cs_registers #( unique case (csr_addr_i) // fcsr: floating-point control and status register (frm+fflags) - CSR_FCSR: csr_rdata_int = {24'b0 , frm_q, fflags_q}; + CSR_FCSR: csr_rdata_int = {24'b0 , frm_d, fflags_d}; // fflags: floating-point accrued exception - CSR_FFLAG: csr_rdata_int = {27'b0 , fflags_q}; + CSR_FFLAG: csr_rdata_int = {27'b0 , fflags_d}; // frm: floating-point dynamic rounding mode CSR_FRM: begin - csr_rdata_int = {29'b0 , frm_q}; + csr_rdata_int = {29'b0 , frm_d}; end // mhartid: unique hardware thread id From e80c76a8af886f15001c2dac1b30c6fd0b6878a9 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Fri, 15 Oct 2021 15:10:38 +0500 Subject: [PATCH 22/31] update fflags csr logic Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_core.sv | 6 +++-- .../lowrisc_ibex/rtl/ibex_cs_registers.sv | 25 +++++++++---------- hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv | 6 ++++- hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv | 6 +++-- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv index 042ab7cb..c49180d0 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_core.sv @@ -176,6 +176,7 @@ module ibex_core #( logic fp_swap_oprnds; logic fpu_is_busy; logic fp_load; + logic fflags_en_id; logic [FPU_WIDTH-1:0] fp_rf_wdata_wb; logic [FPU_WIDTH-1:0] fp_rf_wdata_id; logic [FPU_WIDTH-1:0] fp_result_ex; @@ -737,7 +738,8 @@ module ibex_core #( .fp_operands_o ( fp_operands ), .fp_result_ex_i ( fp_result_ex ), .fp_load_o ( fp_load ), - .fp_swap_oprnds_o ( fp_swap_oprnds ) + .fp_swap_oprnds_o ( fp_swap_oprnds ), + .fflags_en_id_o ( fflags_en_id ) ); // for RVFI only @@ -1249,7 +1251,7 @@ module ibex_core #( .fp_rm_dynamic_i ( fp_rm_dynamic ), .fp_frm_o ( fp_frm_csr ), .fp_status_i ( fp_status ), - .is_fp_instr_i ( is_fp_instr ) + .fflags_en_id_i ( fflags_en_id ) ); // These assertions are in top-level as instr_valid_id required as the enable term diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv index 50e0a4a9..f42576c4 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv @@ -121,7 +121,7 @@ module ibex_cs_registers #( input logic fp_rm_dynamic_i, output fpnew_pkg::roundmode_e fp_frm_o, input fpnew_pkg::status_t fp_status_i, - input logic is_fp_instr_i + input logic fflags_en_id_i ); import ibex_pkg::*; @@ -305,7 +305,7 @@ module ibex_cs_registers #( // Floating point always_comb begin - if (frm_d == 3'b111) begin + if (fflags_en_id_i & frm_d == 3'b111) begin unique case (frm_q) 101, 110, @@ -323,14 +323,14 @@ module ibex_cs_registers #( unique case (csr_addr_i) // fcsr: floating-point control and status register (frm+fflags) - CSR_FCSR: csr_rdata_int = {24'b0 , frm_d, fflags_d}; + CSR_FCSR: csr_rdata_int = {24'b0 , frm_q, fflags_q}; // fflags: floating-point accrued exception - CSR_FFLAG: csr_rdata_int = {27'b0 , fflags_d}; + CSR_FFLAG: csr_rdata_int = {27'b0 , fflags_q}; // frm: floating-point dynamic rounding mode CSR_FRM: begin - csr_rdata_int = {29'b0 , frm_d}; + csr_rdata_int = {29'b0 , frm_q}; end // mhartid: unique hardware thread id @@ -510,11 +510,10 @@ module ibex_cs_registers #( exception_pc = pc_id_i; // Floating point - fflags_d = fflags_q; - fflags_en = 1'b0; - - frm_d = frm_q; - frm_en = 1'b0; + fflags_en = 1'b0; + fflags_d = fflags_q; + frm_en = 1'b0; + frm_d = frm_q; priv_lvl_d = priv_lvl_q; mstatus_en = 1'b0; @@ -558,7 +557,7 @@ module ibex_cs_registers #( fflags_en = 1'b1; frm_en = 1'b1; fflags_d = csr_wdata_int[4:0]; - frm_d = csr_wdata_int[7:5]; + frm_d = csr_wdata_int[7:5]; end CSR_FFLAG : begin @@ -821,7 +820,7 @@ module ibex_cs_registers #( .rd_error_o (mstatus_err) ); - assign fflag_wdata = is_fp_instr_i ? fp_status_i : fflags_d; + assign fflag_wdata = fflags_en_id_i ? fp_status_i : fflags_d; // FFLAGS ibex_csr #( .Width (5), @@ -831,7 +830,7 @@ module ibex_cs_registers #( .clk_i (clk_i), .rst_ni (rst_ni), .wr_data_i (fflag_wdata), - .wr_en_i (fflags_en | is_fp_instr_i), + .wr_en_i (fflags_en | fflags_en_id_i), .rd_data_o (fflags_q), .rd_error_o () ); diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv index b3c77903..7906a373 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv @@ -124,7 +124,8 @@ module ibex_decoder #( output logic fp_load_o, output logic mv_instn_xw_o, output logic mv_instn_wx_o, - output logic fpu_to_int_rf_o + output logic fpu_to_int_rf_o, + output logic fflags_en_id_o ); import ibex_pkg::*; @@ -289,6 +290,7 @@ module ibex_decoder #( fp_rf_ren_a_o = 1'b0; fp_rf_ren_b_o = 1'b0; fp_rf_ren_c_o = 1'b0; + fflags_en_id_o = 1'b0; opcode = opcode_e'(instr[6:0]); @@ -746,6 +748,7 @@ module ibex_decoder #( use_fp_rs2_o = 1'b1; use_fp_rs3_o = 1'b1; use_fp_rd_o = 1'b1; + fflags_en_id_o = 1'b1; unique case (instr[26:25]) 01: begin @@ -763,6 +766,7 @@ module ibex_decoder #( OPCODE_OP_FP: begin fp_src_fmt_o = FP32; is_fp_instr_o = 1'b1; + fflags_en_id_o = 1'b0; unique case (instr[31:25]) 7'b0000001, // FADD.D diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv index 5496d8b7..f751bd7f 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_id_stage.sv @@ -217,7 +217,8 @@ module ibex_id_stage #( output logic [2:0][FPU_WIDTH-1:0] fp_operands_o, input logic [FPU_WIDTH-1:0] fp_result_ex_i, output logic fp_load_o, - output logic fp_swap_oprnds_o + output logic fp_swap_oprnds_o, + output logic fflags_en_id_o ); import ibex_pkg::*; @@ -570,7 +571,8 @@ module ibex_id_stage #( .fp_load_o ( fp_load_o ), .mv_instn_xw_o ( mv_instn_xw ), .mv_instn_wx_o ( mv_instn_wx ), - .fpu_to_int_rf_o ( fpu_to_int_rf ) + .fpu_to_int_rf_o ( fpu_to_int_rf ), + .fflags_en_id_o ( fflags_en_id_o ) ); /////////////////////// From 76129cc6e6ec65f0103229884b5fbd52d6c4ce75 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sat, 16 Oct 2021 17:36:39 +0500 Subject: [PATCH 23/31] update for flw Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv | 2 +- hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv index f42576c4..3af5fe73 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv @@ -305,7 +305,7 @@ module ibex_cs_registers #( // Floating point always_comb begin - if (fflags_en_id_i & frm_d == 3'b111) begin + if (frm_d == 3'b111) begin unique case (frm_q) 101, 110, diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv index 7906a373..25ce90e5 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv @@ -766,7 +766,7 @@ module ibex_decoder #( OPCODE_OP_FP: begin fp_src_fmt_o = FP32; is_fp_instr_o = 1'b1; - fflags_en_id_o = 1'b0; + fflags_en_id_o = 1'b1; unique case (instr[31:25]) 7'b0000001, // FADD.D @@ -816,7 +816,7 @@ module ibex_decoder #( fp_src_fmt_o = FP32; end 7'b0101101: begin - fp_rf_we_o = 1'b1; + rf_we_o = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rd_o = 1'b1; fp_rf_ren_a_o = 1'b1; @@ -826,7 +826,7 @@ module ibex_decoder #( end end 7'b0101100: begin // FSQRT.S - fp_rf_we_o = 1'b1; + rf_we_o = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rd_o = 1'b1; fp_rf_ren_a_o = 1'b1; @@ -924,6 +924,7 @@ module ibex_decoder #( illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; mv_instn_xw_o = 1'b1; + fflags_en_id_o = 1'b0; end {5'b00000,3'b001}: begin use_fp_rs1_o = 1'b1; @@ -1008,6 +1009,7 @@ module ibex_decoder #( if (~(|instr[24:20]) | (|instr[14:12])) begin illegal_insn = ((RVF == RV32FDNone) & (~fp_invalid_rm)) ? 1'b1 : 1'b0; fp_src_fmt_o = FP32; + fflags_en_id_o = 1'b0; end end default: illegal_insn = 1'b1; From d49da57b6aee48efba2c37a43c4f92f53f3cdfde Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sat, 16 Oct 2021 17:41:59 +0500 Subject: [PATCH 24/31] [tracer] update tracer for fsqrt Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv index a680ee81..1140496d 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv @@ -100,6 +100,7 @@ module ibex_tracer ( logic float_xw; logic float_lw; logic float_sw; + logic float_sqrt; // Data items accessed during this instruction localparam logic [4:0] RS1 = (1 << 0); @@ -160,7 +161,7 @@ module ibex_tracer ( $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_frs3_addr), rvfi_frs3_rdata); end if ((data_accessed & RD) != 0) begin - if (float_xw) + if (float_xw | float_sqrt) $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str_rd(rvfi_rd_addr), rvfi_rd_wdata); else $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str_rd(rvfi_frd_addr), rvfi_frd_wdata); @@ -221,7 +222,7 @@ module ibex_tracer ( function automatic string reg_addr_to_str_rd(input logic [4:0] addr); if (addr < 10) begin if (insn_is_float) begin - if (float_xw) + if (float_xw | float_sqrt) return $sformatf(" x%0d", addr); else return $sformatf(" f%0d", addr); @@ -230,7 +231,7 @@ module ibex_tracer ( end end else begin if (insn_is_float) begin - if (float_xw) + if (float_xw | float_sqrt) return $sformatf("x%0d", addr); else return $sformatf("f%0d", addr); @@ -817,6 +818,7 @@ module ibex_tracer ( function automatic void decode_fsqrt(input string mnemonic); insn_is_float = 1'b1; + float_sqrt = 1'b1; data_accessed = RS1 | RD; decoded_str = $sformatf("%s\tx%0d,f%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr); endfunction @@ -946,10 +948,11 @@ module ibex_tracer ( data_accessed = 5'h0; insn_is_compressed = 0; insn_is_float = 0; - float_wx = 0; - float_xw = 0; - float_lw = 0; - float_sw = 0; + float_wx = 0; + float_xw = 0; + float_lw = 0; + float_sw = 0; + float_sqrt = 0; // Check for compressed instructions if (rvfi_insn[1:0] != 2'b11) begin From fd1b31a93de8dcbdd66bf0be7b0b5ad858444ce1 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Mon, 18 Oct 2021 13:32:03 +0500 Subject: [PATCH 25/31] [ibex_decoder] resolve bug integer rf_we_o signal Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv index 25ce90e5..178e9dd8 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv @@ -816,7 +816,7 @@ module ibex_decoder #( fp_src_fmt_o = FP32; end 7'b0101101: begin - rf_we_o = 1'b1; + rf_we = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rd_o = 1'b1; fp_rf_ren_a_o = 1'b1; @@ -826,7 +826,7 @@ module ibex_decoder #( end end 7'b0101100: begin // FSQRT.S - rf_we_o = 1'b1; + rf_we = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rd_o = 1'b1; fp_rf_ren_a_o = 1'b1; From 04e0bcbfc9c0e4bad276b214969fb072478156fe Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Wed, 27 Oct 2021 11:27:18 +0500 Subject: [PATCH 26/31] [ibex_cs_registers] fixed x-propgation error Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv index 3af5fe73..1c90074c 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_cs_registers.sv @@ -305,6 +305,7 @@ module ibex_cs_registers #( // Floating point always_comb begin + illegal_dyn_mod = 1'b0; if (frm_d == 3'b111) begin unique case (frm_q) 101, From 17265f2100858f65da8a9e99d590e7f7097b0f22 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Thu, 11 Nov 2021 19:56:19 +0500 Subject: [PATCH 27/31] [tracer] fix floating rd on comp instr Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv index 1140496d..c902a0b2 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv @@ -100,6 +100,8 @@ module ibex_tracer ( logic float_xw; logic float_lw; logic float_sw; + logic float_class; + logic float_comp; logic float_sqrt; // Data items accessed during this instruction @@ -161,7 +163,7 @@ module ibex_tracer ( $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_frs3_addr), rvfi_frs3_rdata); end if ((data_accessed & RD) != 0) begin - if (float_xw | float_sqrt) + if (float_xw | float_sqrt | float_class | float_comp) $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str_rd(rvfi_rd_addr), rvfi_rd_wdata); else $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str_rd(rvfi_frd_addr), rvfi_frd_wdata); @@ -208,7 +210,7 @@ module ibex_tracer ( end end else begin if (insn_is_float) begin - if (float_wx | float_lw) + if (float_wx | float_lw | float_sw) return $sformatf("x%0d", addr); else return $sformatf("f%0d", addr); @@ -222,7 +224,7 @@ module ibex_tracer ( function automatic string reg_addr_to_str_rd(input logic [4:0] addr); if (addr < 10) begin if (insn_is_float) begin - if (float_xw | float_sqrt) + if (float_xw | float_sqrt | float_sw | float_class | float_comp) return $sformatf(" x%0d", addr); else return $sformatf(" f%0d", addr); @@ -231,7 +233,7 @@ module ibex_tracer ( end end else begin if (insn_is_float) begin - if (float_xw | float_sqrt) + if (float_xw | float_sqrt | float_sw | float_class | float_comp) return $sformatf("x%0d", addr); else return $sformatf("f%0d", addr); @@ -839,6 +841,7 @@ module ibex_tracer ( function automatic void decode_fcomp(input string mnemonic); insn_is_float = 1'b1; + float_comp = 1'b1; data_accessed = RS2 | RS1 | RD; decoded_str = $sformatf("%s\tx%0d,f%0d,f%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr, rvfi_frs2_addr); @@ -874,6 +877,7 @@ module ibex_tracer ( function automatic void decode_fclass(input string mnemonic); insn_is_float = 1'b1; + float_class = 1'b1; data_accessed = RS1 | RD; decoded_str = $sformatf("%s\tx%0d,f%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr); endfunction @@ -953,6 +957,8 @@ module ibex_tracer ( float_lw = 0; float_sw = 0; float_sqrt = 0; + float_comp = 0; + float_class = 0; // Check for compressed instructions if (rvfi_insn[1:0] != 2'b11) begin From c70af1ecdcfc6e5946677d8c2a8c166caca376a7 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sun, 14 Nov 2021 15:04:52 +0500 Subject: [PATCH 28/31] [fpnew] Fix multiplication bug Signed-off-by: Zeeshan Rafique --- hw/vendor/pulp_fpnew/src/fpnew_cast_multi.sv | 3 ++- hw/vendor/pulp_fpnew/src/fpnew_fma.sv | 3 ++- hw/vendor/pulp_fpnew/src/fpnew_fma_multi.sv | 3 ++- hw/vendor/pulp_fpnew/src/fpnew_rounding.sv | 6 ++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/hw/vendor/pulp_fpnew/src/fpnew_cast_multi.sv b/hw/vendor/pulp_fpnew/src/fpnew_cast_multi.sv index 9d54c79e..8db2ee95 100644 --- a/hw/vendor/pulp_fpnew/src/fpnew_cast_multi.sv +++ b/hw/vendor/pulp_fpnew/src/fpnew_cast_multi.sv @@ -542,7 +542,8 @@ module fpnew_cast_multi #( .effective_subtraction_i ( 1'b0 ), // no operation happened .abs_rounded_o ( rounded_abs ), .sign_o ( rounded_sign ), - .exact_zero_o ( result_true_zero ) + .exact_zero_o ( result_true_zero ), + .op_i ( op_i ) ); logic [NUM_FORMATS-1:0][WIDTH-1:0] fmt_result; diff --git a/hw/vendor/pulp_fpnew/src/fpnew_fma.sv b/hw/vendor/pulp_fpnew/src/fpnew_fma.sv index f9fa813b..7947835c 100644 --- a/hw/vendor/pulp_fpnew/src/fpnew_fma.sv +++ b/hw/vendor/pulp_fpnew/src/fpnew_fma.sv @@ -593,7 +593,8 @@ module fpnew_fma #( .effective_subtraction_i ( effective_subtraction_q ), .abs_rounded_o ( rounded_abs ), .sign_o ( rounded_sign ), - .exact_zero_o ( result_zero ) + .exact_zero_o ( result_zero ), + .op_i ( op_i ) ); // Classification after rounding diff --git a/hw/vendor/pulp_fpnew/src/fpnew_fma_multi.sv b/hw/vendor/pulp_fpnew/src/fpnew_fma_multi.sv index 712dfcd9..12cc12ac 100644 --- a/hw/vendor/pulp_fpnew/src/fpnew_fma_multi.sv +++ b/hw/vendor/pulp_fpnew/src/fpnew_fma_multi.sv @@ -716,7 +716,8 @@ module fpnew_fma_multi #( .effective_subtraction_i ( effective_subtraction_q ), .abs_rounded_o ( rounded_abs ), .sign_o ( rounded_sign ), - .exact_zero_o ( result_zero ) + .exact_zero_o ( result_zero ), + .op_i ( op_i ) ); logic [NUM_FORMATS-1:0][WIDTH-1:0] fmt_result; diff --git a/hw/vendor/pulp_fpnew/src/fpnew_rounding.sv b/hw/vendor/pulp_fpnew/src/fpnew_rounding.sv index 60f63bb7..899eb849 100644 --- a/hw/vendor/pulp_fpnew/src/fpnew_rounding.sv +++ b/hw/vendor/pulp_fpnew/src/fpnew_rounding.sv @@ -25,7 +25,9 @@ module fpnew_rounding #( output logic [AbsWidth-1:0] abs_rounded_o, // absolute value without sign output logic sign_o, // Output classification - output logic exact_zero_o // output is an exact zero + output logic exact_zero_o, // output is an exact zero + // Testing input + input fpnew_pkg::operation_e op_i ); logic round_up; // Rounding decision @@ -66,7 +68,7 @@ module fpnew_rounding #( // In case of effective subtraction (thus signs of addition operands must have differed) and a // true zero result, the result sign is '-' in case of RDN and '+' for other modes. assign sign_o = (exact_zero_o && effective_subtraction_i) - ? (rnd_mode_i == fpnew_pkg::RDN) + ? ((rnd_mode_i == fpnew_pkg::RDN) & (op_i != fpnew_pkg::MUL)) : sign_i; endmodule From bfe104f2cb2c8af361675ed3cb0b6cd934268210 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sun, 14 Nov 2021 16:33:41 +0500 Subject: [PATCH 29/31] [fdivsqrt] Fix div/sqrt busy Signed-off-by: Zeeshan Rafique --- hw/vendor/pulp_fpnew/src/fpnew_divsqrt_multi.sv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/vendor/pulp_fpnew/src/fpnew_divsqrt_multi.sv b/hw/vendor/pulp_fpnew/src/fpnew_divsqrt_multi.sv index 1331f5fe..2573ddef 100644 --- a/hw/vendor/pulp_fpnew/src/fpnew_divsqrt_multi.sv +++ b/hw/vendor/pulp_fpnew/src/fpnew_divsqrt_multi.sv @@ -198,11 +198,11 @@ module fpnew_divsqrt_multi #( out_valid = 1'b1; // try to commit result downstream // If downstream accepts our result if (out_ready) begin - state_d = IDLE; // we anticipate going back to idling.. if (in_valid_q && unit_ready) begin // ..unless new work comes in in_ready = 1'b1; // we acknowledge the instruction state_d = BUSY; // and stay busy with it end + state_d = IDLE; // we anticipate going back to idling.. // Otherwise if downstream is not ready for the result end else begin hold_result = 1'b1; // activate the hold register From bf10604ddd0386c7eb3dd761100335dac3622946 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Sun, 14 Nov 2021 16:40:25 +0500 Subject: [PATCH 30/31] [ibex/decoder,tracer] Fix sqrt RD Signed-off-by: Zeeshan Rafique --- hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv | 4 ++-- hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv index 178e9dd8..8ae55828 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_decoder.sv @@ -816,7 +816,7 @@ module ibex_decoder #( fp_src_fmt_o = FP32; end 7'b0101101: begin - rf_we = 1'b1; + fp_rf_we_o = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rd_o = 1'b1; fp_rf_ren_a_o = 1'b1; @@ -826,7 +826,7 @@ module ibex_decoder #( end end 7'b0101100: begin // FSQRT.S - rf_we = 1'b1; + fp_rf_we_o = 1'b1; use_fp_rs1_o = 1'b1; use_fp_rd_o = 1'b1; fp_rf_ren_a_o = 1'b1; diff --git a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv index c902a0b2..167fc4a4 100644 --- a/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv +++ b/hw/vendor/lowrisc_ibex/rtl/ibex_tracer.sv @@ -102,7 +102,6 @@ module ibex_tracer ( logic float_sw; logic float_class; logic float_comp; - logic float_sqrt; // Data items accessed during this instruction localparam logic [4:0] RS1 = (1 << 0); @@ -163,7 +162,7 @@ module ibex_tracer ( $fwrite(file_handle, " %s:0x%08x", reg_addr_to_str(rvfi_frs3_addr), rvfi_frs3_rdata); end if ((data_accessed & RD) != 0) begin - if (float_xw | float_sqrt | float_class | float_comp) + if (float_xw | float_class | float_comp) $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str_rd(rvfi_rd_addr), rvfi_rd_wdata); else $fwrite(file_handle, " %s=0x%08x", reg_addr_to_str_rd(rvfi_frd_addr), rvfi_frd_wdata); @@ -224,7 +223,7 @@ module ibex_tracer ( function automatic string reg_addr_to_str_rd(input logic [4:0] addr); if (addr < 10) begin if (insn_is_float) begin - if (float_xw | float_sqrt | float_sw | float_class | float_comp) + if (float_xw | float_sw | float_class | float_comp) return $sformatf(" x%0d", addr); else return $sformatf(" f%0d", addr); @@ -233,7 +232,7 @@ module ibex_tracer ( end end else begin if (insn_is_float) begin - if (float_xw | float_sqrt | float_sw | float_class | float_comp) + if (float_xw | float_sw | float_class | float_comp) return $sformatf("x%0d", addr); else return $sformatf("f%0d", addr); @@ -820,7 +819,6 @@ module ibex_tracer ( function automatic void decode_fsqrt(input string mnemonic); insn_is_float = 1'b1; - float_sqrt = 1'b1; data_accessed = RS1 | RD; decoded_str = $sformatf("%s\tx%0d,f%0d", mnemonic, rvfi_rd_addr, rvfi_frs1_addr); endfunction @@ -956,7 +954,6 @@ module ibex_tracer ( float_xw = 0; float_lw = 0; float_sw = 0; - float_sqrt = 0; float_comp = 0; float_class = 0; From eb063c62ebdfd0ff9c172da01e0246ded96a0131 Mon Sep 17 00:00:00 2001 From: Zeeshan Rafique Date: Wed, 17 Nov 2021 18:59:01 +0500 Subject: [PATCH 31/31] [divsqrt_multi] change state in state mach. Signed-off-by: Zeeshan Rafique --- hw/vendor/pulp_fpnew/src/fpnew_divsqrt_multi.sv | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/vendor/pulp_fpnew/src/fpnew_divsqrt_multi.sv b/hw/vendor/pulp_fpnew/src/fpnew_divsqrt_multi.sv index 2573ddef..929c0351 100644 --- a/hw/vendor/pulp_fpnew/src/fpnew_divsqrt_multi.sv +++ b/hw/vendor/pulp_fpnew/src/fpnew_divsqrt_multi.sv @@ -200,9 +200,10 @@ module fpnew_divsqrt_multi #( if (out_ready) begin if (in_valid_q && unit_ready) begin // ..unless new work comes in in_ready = 1'b1; // we acknowledge the instruction - state_d = BUSY; // and stay busy with it + // state_d = BUSY; // and stay busy with it + state_d = IDLE; end - state_d = IDLE; // we anticipate going back to idling.. + // state_d = IDLE; // we anticipate going back to idling.. // Otherwise if downstream is not ready for the result end else begin hold_result = 1'b1; // activate the hold register