Skip to content

Conversation

@nap32
Copy link

@nap32 nap32 commented Feb 3, 2026

The language support files are duplicated -
galangriscv.{cpp|h} and galangriscv32.{cpp|h}.
This is with the intention of follow-up work
to add galangriscv64.{cpp|h}, which the RISCV
spec identifies as a distinct base ISA.

To suppport or streamline compressed instruction
extension encoding, a new feature was added
to goodasm.cpp for rejectWhenZero constraint
matching. This makes it easier to differentiate
between some compressed instructions against c.nop or each other. There may be ways to resolve and
improve the bitmask / match() without this,
but did not appear to impact performance.

(An alternative path is to generalize
rejectWhenZero so that you can support
arbitrary constraint matching - this
might help with other languages with
funky edge-cases in the future.)

A large number of test cases were added to
riscv/tests - including an instruction
generation python script that attempted to
bruteforce every possible valid instruction.
The general testing approach was reflexive -
encode .asm to binary, decode that binary
to .disasm. If .asm and .disasm match,
it increases confidence of the correct
encoding. Formatting need{s/ed} to be accounted
for and the possibility of incorrect
binary representations remain - more robust
testing would include QEMU virtualization.
All tests are currently passing.

Various AI coding assistants were used in
combination with manual effort in an attempt
to explore LLM capabilities; this contribution
is "spec-driven development" by definition.
There is a chance errors slipped through despite
best efforts to manually audit and refine.

The language support files are duplicated -
galangriscv.{cpp|h} and galangriscv32.{cpp|h}.
This is with the intention of follow-up work
to add galangriscv64.{cpp|h}, which the RISCV
spec identifies as a distinct base ISA.

To suppport or streamline compressed instruction
extension encoding, a new feature was added
to goodasm.cpp for rejectWhenZero constraint
matching. This makes it easier to differentiate
between some compressed instructions against c.nop
or each other. There may be ways to resolve and
improve the bitmask / match() without this,
but did not appear to impact performance.

(An alternative path is to generalize
rejectWhenZero so that you can support
arbitrary constraint matching - this
might help with other languages with
funky edge-cases in the future.)

A large number of test cases were added to
riscv/tests - including an instruction
generation python script that attempted to
bruteforce every possible valid instruction.
The general testing approach was reflexive -
encode .asm to binary, decode that binary
to .disasm. If .asm and .disasm match,
it increases confidence of the correct
encoding. Formatting need{s/ed} to be accounted
for and the possibility of incorrect
binary representations remain - more robust
testing would include QEMU virtualization.

Various AI coding assistants were used in
combination with manual effort in an attempt
to explore LLM capabilities; this contribution
is "spec-driven development" by definition.
There is a chance errors slipped through despite
best efforts to manually audit and refine.
@travisgoodspeed
Copy link
Owner

Took a quick pass before dinner.

galangriscv32.cpp is included but duplicates the contents of galangriscv.cpp. If we're going to make a meta class that supports both 32 and 64 bit code, it should be done through class inheritance rather than duplication.

forum% diff galangriscv.cpp galangriscv32.cpp 
3c3
< #include "galangriscv.h"
---
> #include "galangriscv32.h"
15c15
<     name = "riscv";
---
>     name = "riscv32";
forum% 

There are some colliding definitions like this one that can be listed with goodasm --riscv32 --test.

riscv32> c.xor a0, a1
Colliding matches:  "c.xor c.mv "
1:  "c.xor a0, a1"
2:  "c.mv a0, a1"
Colliding matches:  "c.xor c.mv "
1:  "c.xor a0, a1"
2:  "c.mv a0, a1"
0000:   2e 8d                   c.xor a0, a1
riscv32> 

@nap32
Copy link
Author

nap32 commented Feb 6, 2026

Hey! Just acknowledging this feedback. I also spotted a couple of failing test cases that popped up as regressions that I'm sorting out - c.mv, c.sub, fsw, and fsd. I'll work on the refactor/eliminating the duplication and fix the test cases.

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.

2 participants