Skip to content

Vector Self-Checking#1038

Open
georgiatai wants to merge 48 commits intoriscv:act4from
georgiatai:selfcheck
Open

Vector Self-Checking#1038
georgiatai wants to merge 48 commits intoriscv:act4from
georgiatai:selfcheck

Conversation

@georgiatai
Copy link
Contributor

  • Vector self-checking implementation
    • need more testing on all instructions (passing basic arithmatics (e.g. vadd, vsub, etc.) and mask producing (e.g. vmand, etc.)
    • added _INST_PTR for new failure code
  • moved std_vec into custom coverpoints

@georgiatai
Copy link
Contributor Author

georgiatai commented Mar 4, 2026

Received feedback in meeting, will implement and fix:

  • Add comments (especially assumptions for base suite and each instruction)

  • Check if instructions before failedtest are needed considering new failure code

  • Store vtype in the beginning

  • Change VTMP2 to MTMP2, make all VTMP/MTMP -> VT1/MT1

  • See if _MASK_REG can be eliminated (try li inside the macro)

  • vmseq.vi not applicable for mask producing instructions, change to something similar to _CMP

  • Change non-selfcheck to nop

  • Mention assumption that sail has to be preserving the old values

Copy link
Collaborator

@davidharrishmc davidharrishmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verbal review with Georgia yesterday.
Generally looks good.
Replace unused code with nops in signature generation mode
Comment principles of operation much more closely.

@georgiatai
Copy link
Contributor Author

Implemented feedback in meeting. Still testing different instructions but could start reviewing:

  • Add comments (especially assumptions for base suite and each instruction)
    • done
  • Check if instructions before failedtest are needed considering new failure code
    • still there, did not change
  • Store vtype in the beginning
    • done
  • Change VTMP2 to MTMP2, make all VTMP/MTMP -> VT1/MT1
    • changed VTMP2 to MTMP2 but decided to keep the TMP naming
  • See if _MASK_REG can be eliminated (try li inside the macro)
    • changed to li inside the macro
  • vmseq.vi not applicable for mask producing instructions, change to something similar to _CMP
    • implement branching and took out _CMP (pass MASKPROD_FLAG instead)
  • Change non-selfcheck to nop
    • done
  • Mention assumption that sail has to be preserving the old values
    • done in top level comment

will add target later after more testing!

@georgiatai
Copy link
Contributor Author

Refer to PR #924 for the changes on RISCV_coverage_common.svh.
Somehow this was reverted in #1012 by @jacassidy. I'm not sure if there's something in this reverting that will break Vls/Vf (don't think this affects Vf but not that sure about Vls).
But for the demo on Vx, if these changes are not in the state which they are in in #924, then some coverage, e.g. widening instructions, will be missing.
In conclusion, they should be in the state of #924 for now.

@jacassidy
Copy link
Contributor

Those changes were made because @jordancarlin said that non-vector supporting suites were failing to run coverage with hardcoded SEW support. Please fix the implementation to run with widening instructions instead of hardcoding a temporary solution and pushing it to main.

@jordancarlin jordancarlin requested a review from Copilot March 6, 2026 07:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces vector “self-checking” support by adding signature-compare macros for vector results and updating the vector test generator to emit per-test labels/coverpoint identifiers, alongside refactoring coverage templates to include std_vec locally.

Changes:

  • Add new RVTEST_SIGUPD_V / RVTEST_SIGUPD_V_LEN macros intended to support SELFCHECK vector comparisons and richer failure reporting.
  • Update vector test generation to pass _INST_PTR-style labels and coverpoint IDs (cp) through to signature update sites; add some length-suite handling.
  • Move std_vec into multiple custom vector coverage templates and adjust coverage common macros for supported SEWs.

Reviewed changes

Copilot reviewed 3 out of 43 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
tests/env/signature.h Adds new vector SIGUPD macros for SELFCHECK/non-SELFCHECK behavior and length-suite comparisons.
generators/testgen/scripts/vector_testgen_common.py Updates vector signature update emission and test labeling (inst_ptr), plus length-suite preload logic.
generators/testgen/scripts/vector-testgen-unpriv.py Threads new cp argument through test generation; changes XLEN coverage and edge sets.
generators/coverage/templates/vector/*.sv Adds std_vec coverpoint to many custom coverpoint templates (and updates headers).
framework/src/act/fcov/coverage/RISCV_coverage_common.svh Changes how supported SEW/ELEN/LMUL capability macros are defined for coverage compilation.
Comments suppressed due to low confidence (1)

generators/testgen/scripts/vector_testgen_common.py:1673

  • writeVecTest emits vsetivli ... m{sig_lmul} in the priv path, but sig_lmul is now computed as lmul * size_multiplier and can be fractional (e.g., 0.5/0.25/0.125). This will generate invalid assembly like m0.5. Use getLmulFlag(sig_lmul) (or keep sig_lmul as an encoded string like f2/f4/f8) when formatting LMUL in vsetivli, and ensure callers only pass a legal LMUL encoding.

Comment on lines +294 to +297
LREG _TEMP_REG, 0(_SIG_PTR) ;\
beq _TEMP_REG, _TEMP_REG, 1f ;\
1: ;\
jal _LINK_REG, failedtest_##_LINK_REG##_##_TEMP_REG ;\
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The beq immediately before the jal is beq _TEMP_REG, _TEMP_REG, 1f, which forces the integer failure decoder to treat the same register as both expected and actual. failure_code.h extracts failing_reg from rs2 of this beq and then reads failing_value from the saved state of that register, so the report will misleadingly show failing_value == expected_value. Consider making this beq compare an actual scalar derived from the vector result (e.g., element 0 via vmv.x.s / vfirst result) against the expected scalar loaded from the signature, so failure reports are actionable.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more so related to error report so skipping for this PR. will fix and is on to-do

Comment on lines +1186 to 1187
redgesv = [0, 1, 2, 2**xlen-1, 2**xlen-2, 2**(xlen-1), 2**(xlen-1)+1, 2**(xlen-1)-1, 2**(xlen-1)-2]
if (xlen == 32):
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redgesv in unpriv generator was trimmed to remove the alternating-bit patterns and other stress values that were previously included (e.g., walk-odd/even masks). This reduces scalar edge coverage and can hide issues in shift/logic instructions. If the intent is to limit runtime, consider keeping the patterns behind a flag (fast vs thorough) rather than removing them unconditionally.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reduced ones are listed later, repetitive values cause multiple definitions and test to fail

Comment on lines 2551 to 2555
if (arch == "Vls"):
for effew in ["8", "16", "32", "64"]:
testplans["Vls" + effew] = tp
# for effew in ["8", "16", "32", "64"]:
# testplans["Vls" + effew] = tp
del testplans["Vls"]
if (arch == "Vf"):
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readTestplans() now deletes the Vls testplan entry without creating per-EEW variants (Vls8/16/32/64). This effectively drops all VLS-directed test generation unless those covergroups are handled elsewhere, and is a significant behavioral change that isn’t mentioned in the PR description. If VLS should still be generated, restore the per-EEW expansion or otherwise keep Vls in the returned testplans map.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deliberate choice for now

Comment on lines +381 to +386
/* Save architecture state of instruction under test (vl and vtype) */ \
csrr _TEMP_REG, vl ; \
csrr _TEMP_REG2, vtype ; \
/* Set vl = VLMAX for full-register comparison*/ \
vsetvli _LINK_REG, x0, e ## _SEW ##, m ## _LMUL ##, ta, ma ; \
/* Load reference from signature and compute mismatch mask */ \
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RVTEST_SIGUPD_V_LEN saves the original vl and vtype (csrr into _TEMP_REG/_TEMP_REG2) and then overwrites vtype/vl with vsetvli ... vlmax, but never restores the saved state before exiting the macro. That will leak a modified vl/vtype into subsequent test code and can cause widespread false failures. Add a restore step near the PASS/FAIL join (e.g., vsetvl using the saved vl and vtype) before incrementing _SIG_PTR / returning.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think it needs to be restored since each test sets its own

@georgiatai
Copy link
Contributor Author

georgiatai commented Mar 6, 2026

Running tests in /home/gtai/cvw/addins/riscv-arch-test-cvw/work/spike-rv32-max/elfs with command: spike --isa=rv32imafdcbv_zicbom_zicboz_zicbop_zicfilp_zicond_zicsr_zicntr_zicclsm_zifencei_zihintntl_zihintpause_zihpm_zimop_zabha_zacas_zawrs_zfa_zfbfmin_zfh_zcb_zcmop_zbc_zkn_zks_zkr_zvfbfmin_zvfbfwma_zvfh_zvbb_zvbc_zvkg_zvkned_zvknha_zvknhb_zvksed_zvksh_zvkt_sscofpmf_smcntrpmf_sstc_svinval:
        All 211 tests passed.

Implemented all copilot comments other than the ones I don't agree with (explanation provided), and all tests should pass now for Vx32... I didn't get to test the other extensions.

The only change I made in makefile is to make EXTENSIONS = Vx32. Run the following commands:

make clean
make vector-tests
make spike-rv32 --jobs

make vector-tests is set to generate only RV32 Vx tests. The whole run shouldn't take more than a few minutes.

One thing that I would be slightly concerned is regarding the changes on RISCV_common_coverage.svh. According to comments above something was breaking, but I am not sure what broke so I couldn't do more testing. If anything though, I would just revert that file when not running vector. Sorry if that's a hassle.

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.

5 participants