Skip to content

Add explicit PC metadata for instructions (#1825)#1827

Open
amkr6207 wants to merge 2 commits intoriscv:mainfrom
amkr6207:fix/1825-pc-metadata
Open

Add explicit PC metadata for instructions (#1825)#1827
amkr6207 wants to merge 2 commits intoriscv:mainfrom
amkr6207:fix/1825-pc-metadata

Conversation

@amkr6207
Copy link
Copy Markdown
Contributor

@amkr6207 amkr6207 commented May 5, 2026

Fixes #1825.

Add explicit instruction-level metadata for whether an instruction references and/or changes the PC, rather than inferring that from operation() IDL.

This change:

  • adds optional pc.references / pc.changes fields to the instruction schema
  • makes the metadata available through the Ruby instruction model
  • adds a small test for the new metadata
  • documents the new metadata
  • annotates representative instructions:
    • auipc
    • jalr
    • mret

Signed-off-by: Aman <amkr6207@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.19%. Comparing base (7259e0e) to head (f011b75).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1827      +/-   ##
==========================================
- Coverage   72.21%   72.19%   -0.03%     
==========================================
  Files          52       52              
  Lines       27740    27746       +6     
  Branches     6012     6002      -10     
==========================================
- Hits        20033    20030       -3     
- Misses       7707     7716       +9     
Flag Coverage Δ
idlc 76.11% <ø> (-0.05%) ⬇️
udb 66.25% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Collaborator

@ThinkOpenly ThinkOpenly left a comment

Choose a reason for hiding this comment

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

Neat! I think this is a good addition. @dhower-qc ? @lenary ?

If adopted, we need to annotate many other instructions, of course:

$ grep -l -E -i 'jump\(|jump_halfword\(|\$pc' $(find gen/resolved_spec/_/inst -type f)
gen/resolved_spec/_/inst/Smrnmi/mnret.yaml
gen/resolved_spec/_/inst/Zcmt/cm.jalt.yaml
gen/resolved_spec/_/inst/Zcmt/cm.jt.yaml
gen/resolved_spec/_/inst/Zcmp/cm.popret.yaml
gen/resolved_spec/_/inst/Zcmp/cm.popretz.yaml
gen/resolved_spec/_/inst/C/c.ebreak.yaml
gen/resolved_spec/_/inst/C/c.j.yaml
gen/resolved_spec/_/inst/C/c.bnez.yaml
gen/resolved_spec/_/inst/C/c.jr.yaml
gen/resolved_spec/_/inst/C/c.jal.yaml
gen/resolved_spec/_/inst/C/c.beqz.yaml
gen/resolved_spec/_/inst/C/c.jalr.yaml
gen/resolved_spec/_/inst/S/sret.yaml
gen/resolved_spec/_/inst/I/bne.yaml
gen/resolved_spec/_/inst/I/bge.yaml
gen/resolved_spec/_/inst/I/bgeu.yaml
gen/resolved_spec/_/inst/I/jalr.yaml
gen/resolved_spec/_/inst/I/blt.yaml
gen/resolved_spec/_/inst/I/beq.yaml
gen/resolved_spec/_/inst/I/ebreak.yaml
gen/resolved_spec/_/inst/I/jal.yaml
gen/resolved_spec/_/inst/I/auipc.yaml
gen/resolved_spec/_/inst/I/bltu.yaml
gen/resolved_spec/_/inst/I/mret.yaml

Comment thread doc/data-templates.adoc Outdated
vs: always # VS-mode access
vu: always # VU-mode access
data_independent_timing: true # For cryptographic extensions
pc:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pc:
pc: # program counter

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated. Thanks!

Comment thread doc/data-templates.adoc
Comment on lines +101 to +102
references: true # Optional: instruction semantics reference the current PC
changes: false # Optional: instruction semantics update the PC
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Subjective, but these might be better as read/write:

Suggested change
references: true # Optional: instruction semantics reference the current PC
changes: false # Optional: instruction semantics update the PC
reads: true # Optional: instruction semantics reference the PC
writes: false # Optional: instruction semantics update the PC

If adopted here, these changes would be needed throughout this PR, of course.

Comment thread spec/schemas/inst_schema.json Outdated
},
"pc": {
"type": "object",
"description": "Explicit metadata describing whether the instruction reads and/or writes the program counter",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For consistency with other definitions here:

Suggested change
"description": "Explicit metadata describing whether the instruction reads and/or writes the program counter",
"description": "Whether the instruction reads and/or writes the program counter",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated. Thanks!

@ThinkOpenly
Copy link
Copy Markdown
Collaborator

I'm also not sure how a really weird instruction like qc.cm.ilut should be annotated, since as part of its semantics, it executes other instructions which may or may not reference/update the PC.

@ThinkOpenly
Copy link
Copy Markdown
Collaborator

I'm also not sure how a really weird instruction like qc.cm.ilut should be annotated, since as part of its semantics, it executes other instructions which may or may not reference/update the PC.

Maybe nevermind on that concern. That instruction does not permit executing PC-relative instructions .

@ThinkOpenly
Copy link
Copy Markdown
Collaborator

Another way of implementing this would be adding an implicit operand to the instructions. The operand definitions are emerging in #1527. One nice thing that's already present there is the concept of "source" (read) and "destination" (write). Not yet present there, but probably needs to be is "implicit" operands. Program counter is certainly one. Stack pointer is another.

Copy link
Copy Markdown
Collaborator

@dhower-qc dhower-qc left a comment

Choose a reason for hiding this comment

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

Not opposed to this, but would like to see a regression test that ensures IDL and the YAML annotation agree.

Signed-off-by: Aman <amkr6207@gmail.com>
@amkr6207 amkr6207 requested review from ThinkOpenly and dhower-qc May 6, 2026 02:21
@amkr6207
Copy link
Copy Markdown
Contributor Author

amkr6207 commented May 6, 2026

@ThinkOpenly @dhower-qc

Addressed the requested changes.

I added the regression test, the doc comment, and the schema wording update. I left references / changes unchanged since the reads / writes suggestion seemed optional.

Thanks!

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.

Add a means to indicate instruction references/changes PC

3 participants