Skip to content

fix: update c.nop encoding and assembly to support HINTs (#1177)#1289

Draft
16srivarshitha wants to merge 7 commits intoriscv:mainfrom
16srivarshitha:issue-1177-cnop-fix
Draft

fix: update c.nop encoding and assembly to support HINTs (#1177)#1289
16srivarshitha wants to merge 7 commits intoriscv:mainfrom
16srivarshitha:issue-1177-cnop-fix

Conversation

@16srivarshitha
Copy link
Copy Markdown

Description

This PR resolves the encoding divergence for c.nop between the unified database and riscv-opcodes, as reported in issue #1177.

Changes

YAML (c.nop.yaml):

Updated the match pattern from the fully constrained value 0x0001 to 000-00000-----01, using wildcards for the immediate field
This change enables the database to correctly recognize c.addi x0, x0, imm (where imm ≠ 0) as c.nop HINT variants

Generator (template_helpers.rb):

Enhanced assembly_fmt and assembly_fmt_args to support dynamic formatting based on the immediate value:

When imm = 0: displays as c.nop
When imm ≠ 0 (HINT variant): displays as c.nop

Verification

  • Confirmed the match field correctly enforces the rd = x0 constraint (bits 11-7)
  • Verified the Ruby generator properly switches between assembly formats based on the immediate value

Fixes #1177

@16srivarshitha 16srivarshitha changed the title data: update c.nop encoding and assembly to support HINTs (#1177) fix: update c.nop encoding and assembly to support HINTs (#1177) Dec 27, 2025
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.

Thank you for this contribution. There are a few issues with it for which I've added comments.

A final implementation is perhaps not possible until optional operands are supported.

If you wish to address the addressable comments, please do. This PR will probably need to stay open for some time, though, and then it will need substantial further work. Shall we leave it open until then, or would it be easier to close it and revisit the issue later?

Comment thread spec/std/isa/inst/C/c.nop.yaml Outdated
Comment thread spec/std/isa/inst/C/c.nop.yaml Outdated
anyOf:
- C
- Zca
assembly: "c.nop imm"
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.

The "assembly" attribute does not include the instruction mnemonic, so this should be changed.

Suggested change
assembly: "c.nop imm"
assembly: imm

Also, this is redundant with the "assembly" attribute below. There can be only one.

Also, the "extension" below needs to be under the "definedBy" above, and this was inserted between them.

All that being said, this "imm" operand is optional, and UDB doesn't have a way to specify optional operands at present. Hopefully, this will come with #1527, but that might not be soon.

module Udb
class Instruction
def assembly_fmt(xlen)
if name == "c.nop"
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.

I'd really like to avoid adding special cases for specific instructions in the Ruby code. I suspect this will be easier when operands can be explicitly marked "optional" in the YAML when #1527 is merged.

@16srivarshitha
Copy link
Copy Markdown
Author

@ThinkOpenly Thanks! I understand we need to wait for #1527 to do this properly without special cases in Ruby.

I will remove the Ruby changes and clean up the YAML errors you pointed out. I'll leave this PR open as a draft until the optional operands feature is ready.

@16srivarshitha 16srivarshitha marked this pull request as draft February 11, 2026 15:35
Removed unnecessary definitions for C.NOP instruction.

Signed-off-by: Srivarshitha M <mvarshitha17874@gmail.com>
Refactor assembly_fmt and assembly_fmt_args methods in Instruction class to remove special case for 'c.nop'.

Signed-off-by: Srivarshitha M <mvarshitha17874@gmail.com>

module Udb
class Instruction
class Instruction
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.

I think these changes are inadvertent, and need to be reverted?

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.

c.nop encoding is different than riscv-opcodes

2 participants