Skip to content

[hardware] Qualify MaskB operand capture in MASKU - #540

Open
lionelZhaowy wants to merge 2 commits into
pulp-platform:mainfrom
lionelZhaowy:fix-masku-maskb-capture
Open

lionelZhaowy wants to merge 2 commits into
pulp-platform:mainfrom
lionelZhaowy:fix-masku-maskb-capture

Conversation

@lionelZhaowy

@lionelZhaowy lionelZhaowy commented Oct 26, 2026 •

Copy link
Copy Markdown

MASKU can capture scalar-move data while idle and later use it as a comparison's old destination. This can corrupt a masked comparison even when the scalar move itself returns the correct value.

For e32/m1 with VL=3:

  • The old destination has low bits 101, and v0 has 110.
  • All comparison sources are positive.
  • After vmv.x.s returns the expected value 0x3f800000, vmslt.vx vd, src, zero, v0.t must produce 001.
  • The original RTL produces 000. It loses masked-off bit 0.

MaskB supplies both CPU scalar moves and MASKU's buffer for the old destination (vd spill). MASKU currently accepts data without a valid consumer. This patch qualifies input valid and upstream ready with the instruction's issue-valid. The instruction must target MASKU and read old vd or a gather/compress source. An internal input carries issue-valid. Top-level interfaces, state and buffers stay unchanged.

The existing vmslt test adds 12 sequences: integer/FP scalar moves × VL=3/1/4 × two rounds. CSR reads use this baseline's WAIT_IDLE behavior between operations. The test checks only active mask bits, with mask-undisturbed enabled. Controls for old-vd comparison, masked FMA, gather and all-selected compress run first.

This changes the MASKU consumer without including #475, #479, #480 or #539. The first three address requests or broadcasts.

Validation

Base: main 34bd3bc152421b4601a7bf3d6e8e91ffb545c99e, with unchanged Bender.lock and pinned CVA6 HPDcache.

Configuration: official ara_tb, real CVA6, 2 lanes / VLEN=2048. Tools: VCS W-2024.09-SP1, host g++ 13.3.1 and LLVM 20.1.0 with matching newlib/compiler-rt.

Test Original RTL Patched RTL
Same vmslt ELF 47/48 pass. Case 26 fails, tohost=1. 48/48 pass, tohost=0.
Unchanged vmvxs — 7/7 pass, tohost=0.
Unchanged vfmvfs — 6/6 pass, tohost=0.

A read-only observer traces the scalar word through the idle MASKU buffer into the failing comparison. The patched run eliminates unqualified captures and retains legitimate old-vd, gather and compress reads.

Validation covers the configuration and directed tests above. The full suite and synthesis were not run. The patch adds no data tags, so ownership in other concurrent cases remains unverified.

Test details and limits

Both RTL versions return all 12 sequences. Only the first original comparison fails, after 14 original checks and 10 positive controls pass. Later observations do not establish independent causes after contamination.

The first faulty word enters an empty buffer at cycle 43848, with issue/commit invalid and the same value returning to the CPU. VMSLT consumes it at cycle 43885. Unqualified captures/acknowledgements decrease from 23/23 to 0/0. Only two original captures coincide with CPU scalar responses.

The patched run accepts 78 old-vd, six gather and six compress words. It records 374 lane-cycles of output waiting without hold errors. Eight cycles contain a non-MASKU instruction with use_vd_op=1. No valid MASKU issue exercises the category without old-vd or gather/compress reads.

Gather/compress sources finish loading first. VID and compress termination edge cases remain outside this test.

All runs reach the ELF entry and main and finish through the official testbench. Checks include software results, tohost, completion and assertions. VCS returns process status 0 even for the original failure. Existing vmvxs shift-overflow and non-allocatable .comment linker warnings remain.

Reproduction and local VCS commands

Use the same PR-built ELF for both RTL versions. Give each version a fresh absolute BUILD_DIR. SPIKE_ROOT supplies headers only, here from /opt/spike-5cf439b2.

timeout 600 sets a 600-second timeout. It does not report elapsed runtime.

# Build the test sources once from this PR's checkout.
LLVM_ROOT=/opt/llvm-20.1.0
make -C apps config=2_lanes LLVM_INSTALL_DIR="$LLVM_ROOT" \
  LLVM_FLAGS="--target=riscv64-unknown-elf --sysroot=$LLVM_ROOT/riscv64-unknown-elf -isystem $LLVM_ROOT/riscv64-unknown-elf/include -march=rv64gcv_zfh_zvfh -mabi=lp64d -mno-relax -fuse-ld=lld --rtlib=compiler-rt -L$LLVM_ROOT/riscv64-unknown-elf/lib" \
  LLVM_V_FLAGS="-fno-vectorize -fno-slp-vectorize -mno-implicit-float" \
  bin/rv64uv-ara-vmslt bin/rv64uv-ara-vmvxs bin/rv64uv-ara-vfmvfs
ELF_DIR="$PWD/apps/bin"

# Repeat this block in the base and PR checkouts, using fresh BUILD_DIR values.
# Both checkouts need the unchanged locked dependencies, including CVA6's
# HPDcache gitlink. ELF_DIR must point to the same PR-built test binaries.
# SPIKE_ROOT supplies the fesvr headers for the official ELF loader.
ARA_ROOT=$PWD
mkdir -p "$BUILD_DIR"
bender --local --git-submodules false script vcs \
  -t rtl -t cv64a6_imafdcv_sv39 \
  -t tech_cells_generic_include_tc_sram -t tech_cells_generic_include_tc_clk \
  -t exclude_first_pass_decoder -t ara_test -t cva6_test \
  -D NR_LANES=2 -D VLEN=2048 -D ARIANE_ACCELERATOR_PORT=1 \
  --vlogan-args="-full64 -assert svaext +v2k -timescale=1ns/1ps" \
  > "$BUILD_DIR/compile.sh"
cd "$BUILD_DIR"
bash compile.sh
vcs -full64 -sverilog -timescale=1ns/1ps -assert svaext -top ara_tb \
  "$ARA_ROOT/hardware/tb/dpi/elfloader.cc" \
  -CFLAGS "-I$SPIKE_ROOT/include" -o simv
timeout 600 ./simv +PRELOAD="$ELF_DIR/rv64uv-ara-vmslt"

# Also run the two unchanged scalar-move tests with the patched RTL.
timeout 600 ./simv +PRELOAD="$ELF_DIR/rv64uv-ara-vmvxs"
timeout 600 ./simv +PRELOAD="$ELF_DIR/rv64uv-ara-vfmvfs"

Local builds reused the official Bender-generated list for the same base and locked dependencies. Only the checkout path changed. They also compiled this optional observer and added -top maskb_capture_observer. The observer only reads DUT signals.

Save the observer at an absolute OBSERVER path. Compile it before elaboration:

vlogan -full64 -sverilog -timescale=1ns/1ps -assert svaext "$OBSERVER"
vcs -full64 -sverilog -timescale=1ns/1ps -assert svaext \
  -top ara_tb -top maskb_capture_observer \
  "$ARA_ROOT/hardware/tb/dpi/elfloader.cc" \
  -CFLAGS "-I$SPIKE_ROOT/include" -o simv

Check case IDs 1–48 and [MASKB_DONE] completed=12. Also check for Core Test *** SUCCESS *** (tohost = 0). The completion count alone does not indicate a pass. This observer requires this hierarchy and two lanes.

Optional read-only observer used for the reported measurements
// Read-only observer for the MASKU MaskB capture regression. No stimulus or force.
`define M ara_tb.dut.i_ara_soc.i_system.i_ara.i_masku
`define O `M.i_masku_operands
`define S ara_tb.dut.i_ara_soc.i_system.i_ara.i_sequencer
module maskb_capture_observer;
  import ara_pkg::*;
  longint unsigned cycles = 0;
  int unsigned captures = 0, acknowledgements = 0;
  int unsigned unowned_captures = 0, unowned_acknowledgements = 0;
  int unsigned idle_captures = 0, scalar_captures = 0, stale_consumes = 0;
  int unsigned old_vd_captures = 0, gather_captures = 0, compress_captures = 0;
  int unsigned nonmask_vd_cycles = 0, no_vd_cycles = 0;
  int unsigned output_stall_cycles = 0, hold_errors = 0, rows = 0;
  bit [1:0] pending_bad = '0, held_valid = '0, trace_started = '0;
  logic [1:0][63:0] bad_data, held_data;

  always @(posedge `M.clk_i) begin
    cycles++;
    if (!`M.rst_ni) begin
      pending_bad = '0;
      held_valid = '0;
      trace_started = '0;
    end else begin
      if (`M.vinsn_issue_valid && `M.vinsn_issue.vfu != VFU_MaskUnit &&
          `M.vinsn_issue.use_vd_op) nonmask_vd_cycles++;
      if (`M.vinsn_issue_valid && `M.vinsn_issue.vfu == VFU_MaskUnit &&
          !`M.vinsn_issue.use_vd_op &&
          !(`M.vinsn_issue.op inside {[VRGATHER:VCOMPRESS]})) no_vd_cycles++;

      for (int lane = 0; lane < 2; lane++) begin
        automatic bit eligible = `M.vinsn_issue_valid &&
            (`M.vinsn_issue.vfu == VFU_MaskUnit) &&
            (`M.vinsn_issue.use_vd_op ||
             (`M.vinsn_issue.op inside {[VRGATHER:VCOMPRESS]}));
        automatic bit capture = `O.masku_operand_vd_lane_valid[lane] &&
                                `O.masku_operand_vd_lane_ready[lane];
        automatic bit ack = `M.masku_operand_valid_i[lane][1] &&
                            `M.masku_operand_ready_o[lane][1];
        automatic bit consume = `O.masku_operand_vd_valid_o[lane] &&
                                `O.masku_operand_vd_ready_i[lane];

        if (held_valid[lane] &&
            (`O.masku_operand_vd_valid_o[lane] !== 1'b1 ||
             `O.masku_operand_vd_o[lane] !== held_data[lane])) begin
          hold_errors++;
          $display("[MASKB_HOLD_ERROR] cycle=%0d lane=%0d", cycles, lane);
        end
        held_valid[lane] = `O.masku_operand_vd_valid_o[lane] &&
                          !`O.masku_operand_vd_ready_i[lane];
        held_data[lane] = `O.masku_operand_vd_o[lane];
        if (held_valid[lane]) output_stall_cycles++;

        if (consume && pending_bad[lane]) begin
          if (`O.masku_operand_vd_o[lane] === bad_data[lane]) begin
            stale_consumes++;
            $display("[MASKB_STALE_CONSUME] cycle=%0d lane=%0d op=%0d data=%016h",
                     cycles, lane, `M.vinsn_issue.op, `O.masku_operand_vd_o[lane]);
          end
          pending_bad[lane] = 1'b0;
        end
        if (ack) begin
          acknowledgements++;
          if (!eligible) unowned_acknowledgements++;
        end
        if (capture) begin
          captures++;
          if (!eligible) begin
            unowned_captures++;
            if (!`M.vinsn_issue_valid) idle_captures++;
            if (lane == 0 && `S.ara_resp_valid_o && `S.pe_scalar_resp_valid_i &&
                (`S.pe_req_o.op inside {VMVXS, VFMVFS})) scalar_captures++;
            // Track only the first unowned word accepted into an empty spill.
            // This makes its next consumption unambiguous even with two entries.
            if (!trace_started[lane] && !`O.masku_operand_vd_valid_o[lane]) begin
              pending_bad[lane] = 1'b1;
              trace_started[lane] = 1'b1;
              bad_data[lane] = `O.masku_operand_vd_d[lane];
            end
            $display("[MASKB_UNOWNED_CAPTURE] cycle=%0d lane=%0d issue_valid=%b commit_valid=%b op=%0d scalar_op=%0d cpu_response=%b data=%016h",
                     cycles, lane, `M.vinsn_issue_valid, `M.vinsn_commit_valid,
                     `M.vinsn_issue.op, `S.pe_req_o.op, `S.ara_resp_valid_o,
                     `O.masku_operand_vd_d[lane]);
          end else begin
            if (`M.vinsn_issue.use_vd_op) old_vd_captures++;
            if (`M.vinsn_issue.op inside {VRGATHER, VRGATHEREI16}) gather_captures++;
            if (`M.vinsn_issue.op == VCOMPRESS) compress_captures++;
          end
        end
        if ((capture || consume) && rows < 48) begin
          rows++;
          $display("[MASKB_SAMPLE] cycle=%0d lane=%0d op=%0d eligible=%b capture=%b ack=%b consume=%b input=%016h buffered=%016h",
                   cycles, lane, `M.vinsn_issue.op, eligible, capture, ack, consume,
                   `O.masku_operand_vd_d[lane], `O.masku_operand_vd_o[lane]);
        end
      end
    end
  end
  final $display("[MASKB_CAPTURE_SUMMARY] cycles=%0d captures=%0d acknowledgements=%0d unowned_captures=%0d unowned_acknowledgements=%0d idle_captures=%0d scalar_captures=%0d stale_consumes=%0d old_vd_captures=%0d gather_captures=%0d compress_captures=%0d nonmask_vd_cycles=%0d no_vd_cycles=%0d output_stall_cycles=%0d hold_errors=%0d",
      cycles, captures, acknowledgements, unowned_captures, unowned_acknowledgements,
      idle_captures, scalar_captures, stale_consumes, old_vd_captures, gather_captures,
      compress_captures, nonmask_vd_cycles, no_vd_cycles, output_stall_cycles, hold_errors);
endmodule
`undef M
`undef O
`undef S

Changelog

Fixed

  • Qualify MASKU MaskB capture by the active instruction to avoid buffering scalar-move data.

Checklist

  • Automated tests pass (directed local tests pass, full CI is pending)
  • Changelog updated
  • Code style guideline is observed

OpenAI Codex assisted with the patch, regression and description. The reported builds and simulations ran. No separate human review was performed.

The affected original tests (vmand, vmor, and vmxor) and HelloWorld now pass through the official Verilator Make entry in all four configurations: 2/4/8/16 lanes. The applications use the locked LLVM 20.1.0/newlib sources, and Verilator is built from the locked commit 06263ec7. Each local run has a 10000000-cycle limit and finishes with tohost = 0, process exit 0 and no runtime assertion errors. The Make entry now accepts native simulator arguments so these runs can use that limit. License checks also pass. The RTL and dependency lock are unchanged by this test-entry update.

lionelZhaowy and others added 2 commits October 26, 2026 06:08
MaskB also feeds scalar moves, so an idle MASKU must not capture or
acknowledge those operands. Gate its vd spill input and upstream ready
with the current issue validity and actual use of the channel.

Keep gather/compress ad-hoc reads enabled. Extend the existing vmslt
test with scalar-move/old-mask sequences and valid-consumer controls.

On main 34bd3bc with real CVA6, 2 lanes and VLEN=2048, the same ELF
fails one of 48 checks before this fix and passes all 48 afterwards.
The unchanged scalar-move tests also pass 7 and 6 checks.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant