Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions ci/testcases/regression.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,48 @@ tests:
- xrt
app: dogfood
args: -n1 -tbar
# The FPnew FPU backend. Its div/sqrt latency depends on the operands, so
# fdiv-special makes the lanes of a warp finish out of step; fflags-lanes checks
# the warp's flags across lanes, and fp-nanbox the 64-bit NaN-boxing.
- id: dogfood-fpnew
via: blackbox
drivers:
- rtlsim
app: dogfood
args: -n16 -xbar -xgbar
configs: -DVX_CFG_FPU_TYPE_FPNEW
# Fewer FPU lanes than threads: an instruction runs as several lane packets,
# and packets of different warps' instructions complete interleaved, so each
# must carry its flags to its own warp.
- id: dogfood-fflags-pbw-std
via: blackbox
drivers:
- rtlsim
app: dogfood
args: -n16 -tfflags-lanes
configs: -DVX_CFG_FPU_TYPE_STD -DVX_CFG_NUM_FPU_LANES=2
xlen:
- 32
- id: dogfood-fflags-pbw-fpnew
via: blackbox
drivers:
- rtlsim
app: dogfood
args: -n16 -tfflags-lanes
configs: -DVX_CFG_FPU_TYPE_FPNEW -DVX_CFG_NUM_FPU_LANES=2
xlen:
- 32
# NaN-boxing of single-precision operands on the DSP backend's FMA and
# div/sqrt inputs, with 64-bit FP registers.
- id: dogfood-nanbox-dsp
via: blackbox
drivers:
- rtlsim
app: dogfood
args: -tfp-nanbox
configs: -DVX_CFG_FPU_TYPE_DSP
xlen:
- 64
- id: gbar-phase-1
via: blackbox
drivers:
Expand Down
5 changes: 2 additions & 3 deletions docs/assets/img/fpu_architecture.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions docs/designs/floating_point_unit.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ wide (the SIMD width).
| `VX_lane_dispatch` | maps issue slots onto FPU blocks and SIMD lanes onto FPU lanes; an instruction wider than the lane count is split into packets |
| tag store (`VX_index_buffer`, `VX_CFG_FPU_QUEUE_SIZE`) | holds the instruction header while the operands are in the backend; bounds the operations in flight |
| rounding-mode resolve | a request with `frm = DYN` takes the issuing warp's rounding mode from `fcsr`; `MISC` operations reuse the `frm` field as a sub-operation and are left alone |
| flag accumulation | flags are OR-ed across the packets of one instruction and written to the warp's `fcsr` on the last packet, through a registered `VX_fpu_csr_if` |
| flag write | each packet's flags are OR-ed into the warp's `fcsr` as the packet returns, through a registered `VX_fpu_csr_if`; packets of different instructions can complete interleaved, so a per-block accumulator would hand one warp's flags to another |
| `VX_lane_gather` | reassembles the blocks onto the commit interface |

The header carries the decoded writeback bit through the tag store rather
Expand Down Expand Up @@ -132,10 +132,12 @@ build elaborates the F32-only RTL and carries **no** 64-bit datapath.

The active format is selected **per instruction from `dst_fmt`**, never from
the operand width. A single-precision value in a 64-bit lane is NaN-boxed —
upper 32 bits all ones. Every unit boxes its F32 results on the way out. The
arithmetic cores read the low 32 bits of an F32 operand; the
non-computational unit additionally checks the box and treats an unboxed F32
operand as the canonical quiet NaN, as the specification requires.
upper 32 bits all ones. Every unit boxes its F32 results on the way out. Every
unit also checks the box of an F32 operand and treats an unboxed one as the
canonical quiet NaN, as the specification requires: the conversion and
non-computational units in place, the FMA and div/sqrt inputs of the STD and
DSP backends through `fp_unbox_s`/`fp_unbox_fmt` in `VX_fpu_pkg`, and the
FPnew wrapper in front of the PULP divider, which ignores the box.

**Double precision requires `XLEN = 64`.** Operand lanes are `XLEN` wide, so
there is no place to carry a 64-bit value on a 32-bit build;
Expand Down
27 changes: 6 additions & 21 deletions hw/rtl/fpu/VX_fpu_block.sv
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

`include "VX_fpu_define.vh"

// One FPU block: the FP datapath with its tag store and fflags accumulation.
// One FPU block: the FP datapath with its tag store and fflags writes.
module VX_fpu_block import VX_gpu_pkg::*, VX_fpu_pkg::*; #(
parameter `STRING INSTANCE_ID = "",
parameter NUM_LANES = 1,
Expand All @@ -29,7 +29,6 @@ module VX_fpu_block import VX_gpu_pkg::*, VX_fpu_pkg::*; #(
VX_fpu_csr_if.master fpu_csr_if
);
`UNUSED_SPARAM (INSTANCE_ID)
localparam PID_BITS = `CLOG2(`VX_CFG_NUM_THREADS / NUM_LANES);
localparam TAG_WIDTH = `LOG2UP(`VX_CFG_FPU_QUEUE_SIZE);

wire fpu_req_valid, fpu_req_ready;
Expand Down Expand Up @@ -219,27 +218,13 @@ module VX_fpu_block import VX_gpu_pkg::*, VX_fpu_pkg::*; #(

`endif

// handle CSR update
fflags_t fpu_rsp_fflags_q;

if (PID_BITS != 0) begin : g_fflags_pid
fflags_t fpu_rsp_fflags_r;
always @(posedge clk) begin
if (reset) begin
fpu_rsp_fflags_r <= '0;
end else if (fpu_rsp_fire) begin
fpu_rsp_fflags_r <= fpu_hdr.eop ? '0 : (fpu_rsp_fflags_r | fpu_rsp_fflags);
end
end
assign fpu_rsp_fflags_q = fpu_rsp_fflags_r | fpu_rsp_fflags;
end else begin : g_fflags_no_pid
assign fpu_rsp_fflags_q = fpu_rsp_fflags;
end

// handle CSR update: fflags accrue in the CSR, so each lane packet writes
// its own flags as it returns, in whatever order the packets of different
// instructions complete.
VX_fpu_csr_if fpu_csr_tmp_if();
assign fpu_csr_tmp_if.write_enable = fpu_rsp_fire && fpu_hdr.eop && fpu_rsp_has_fflags;
assign fpu_csr_tmp_if.write_enable = fpu_rsp_fire && fpu_rsp_has_fflags;
`ASSIGN_BLOCKED_WID (fpu_csr_tmp_if.write_wid, fpu_hdr.wid, block_idx, `VX_CFG_NUM_FPU_BLOCKS)
assign fpu_csr_tmp_if.write_fflags = fpu_rsp_fflags_q;
assign fpu_csr_tmp_if.write_fflags = fpu_rsp_fflags;

VX_pipe_register #(
.DATAW (1 + NW_WIDTH + $bits(fflags_t)),
Expand Down
16 changes: 10 additions & 6 deletions hw/rtl/fpu/VX_fpu_dsp.sv
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ module VX_fpu_dsp import VX_gpu_pkg::*, VX_fpu_pkg::*; #(
.op_type (pe_op),
.op_mod (pe_op_mod),
.frm (pe_frm),
.dataa (pe_data_in[i][0+:32]),
.datab (pe_data_in[i][`VX_CFG_XLEN+:32]),
.datac (pe_data_in[i][2*`VX_CFG_XLEN+:32]),
.dataa (fp_unbox_s(64'(pe_data_in[i][0+:`VX_CFG_XLEN]))),
.datab (fp_unbox_s(64'(pe_data_in[i][`VX_CFG_XLEN+:`VX_CFG_XLEN]))),
.datac (fp_unbox_s(64'(pe_data_in[i][2*`VX_CFG_XLEN+:`VX_CFG_XLEN]))),
.result (res32),
.fflags (ff32)
);
Expand Down Expand Up @@ -510,6 +510,8 @@ module VX_fpu_dsp import VX_gpu_pkg::*, VX_fpu_pkg::*; #(
wire [NUM_PES_DIV-1:0] div_pe_ce;
assign div_pe_ce = div_pe_enable;

wire div_pe_is_s = (div_pe_shared[INST_FRM_BITS+:INST_FMT_BITS] == INST_FMT_S);

for (genvar i = 0; i < NUM_PES_DIV; ++i) begin : g_div_units
if (`VX_CFG_XLEN > `VX_CFG_FLEN) begin : g_pad
assign div_pe_data_out[i][`VX_CFG_FLEN +: (`VX_CFG_XLEN-`VX_CFG_FLEN)] = '0;
Expand All @@ -526,8 +528,8 @@ module VX_fpu_dsp import VX_gpu_pkg::*, VX_fpu_pkg::*; #(
.mask (div_pe_mask_out[i]),
.fmt (div_pe_shared[INST_FRM_BITS+:INST_FMT_BITS]),
.frm (div_pe_shared[0+:INST_FRM_BITS]),
.dataa (div_pe_data_in[i][0+:`VX_CFG_FLEN]),
.datab (div_pe_data_in[i][`VX_CFG_XLEN+:`VX_CFG_FLEN]),
.dataa (fp_unbox_fmt(div_pe_data_in[i][0+:`VX_CFG_FLEN], div_pe_is_s)),
.datab (fp_unbox_fmt(div_pe_data_in[i][`VX_CFG_XLEN+:`VX_CFG_FLEN], div_pe_is_s)),
.result (div_pe_data_out[i][0+:`VX_CFG_FLEN]),
.fflags (div_pe_data_out[i][`VX_CFG_XLEN+:`FP_FLAGS_BITS])
);
Expand Down Expand Up @@ -598,6 +600,8 @@ module VX_fpu_dsp import VX_gpu_pkg::*, VX_fpu_pkg::*; #(
wire [NUM_PES_SQRT-1:0] sqrt_pe_ce;
assign sqrt_pe_ce = sqrt_pe_enable;

wire sqrt_pe_is_s = (sqrt_pe_shared[INST_FRM_BITS+:INST_FMT_BITS] == INST_FMT_S);

for (genvar i = 0; i < NUM_PES_SQRT; ++i) begin : g_sqrt_units
if (`VX_CFG_XLEN > `VX_CFG_FLEN) begin : g_pad
assign sqrt_pe_data_out[i][`VX_CFG_FLEN +: (`VX_CFG_XLEN-`VX_CFG_FLEN)] = '0;
Expand All @@ -614,7 +618,7 @@ module VX_fpu_dsp import VX_gpu_pkg::*, VX_fpu_pkg::*; #(
.mask (sqrt_pe_mask_out[i]),
.fmt (sqrt_pe_shared[INST_FRM_BITS+:INST_FMT_BITS]),
.frm (sqrt_pe_shared[0+:INST_FRM_BITS]),
.dataa (sqrt_pe_data_in[i][0+:`VX_CFG_FLEN]),
.dataa (fp_unbox_fmt(sqrt_pe_data_in[i][0+:`VX_CFG_FLEN], sqrt_pe_is_s)),
.result (sqrt_pe_data_out[i][0+:`VX_CFG_FLEN]),
.fflags (sqrt_pe_data_out[i][`VX_CFG_XLEN+:`FP_FLAGS_BITS])
);
Expand Down
Loading
Loading