Skip to content

Add initial Golang generation support. - #526

Merged
Afonso Oliveira (AFOliveira) merged 15 commits into
mainfrom
AFOliveira/GoSupport
Mar 28, 2025
Merged

Add initial Golang generation support.#526
Afonso Oliveira (AFOliveira) merged 15 commits into
mainfrom
AFOliveira/GoSupport

Conversation

@AFOliveira

Copy link
Copy Markdown
Member

This PR aims to generate inst.go - currently checked out for reviewing purposes. It doesn't yet allow for subsets of the ISA, but serves as an example that it is much easier to generate the outputs than the riscv-opcodes.

Also, I think I found some CSRs that we are missing, I'll open a issue on that.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>
@AFOliveira

Copy link
Copy Markdown
Member Author

Mark Ryan (@markdryan) I'll tag you like this since I can't ask for review in any other way. This is still only "All" the RV64 ISA, I'll make compartimentalized on Monday

@markdryan Mark Ryan (markdryan) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I've had a quick look. Note my comments are based on the version of inst.go generated by the first commit. It doesn't look like you re-generated inst.go when pushing the second commit, so the comments might not all be relevant.

Comment thread backends/generators/Go/inst.go Outdated
Comment thread backends/generators/Go/inst.go Outdated
Comment thread backends/generators/Go/inst.go Outdated
Comment thread backends/generators/Go/inst.go Outdated
@AFOliveira

Copy link
Copy Markdown
Member Author

I've had a quick look. Note my comments are based on the version of inst.go generated by the first commit. It doesn't look like you re-generated inst.go when pushing the second commit, so the comments might not all be relevant.

They are, I did not change much other than filtering yet, thanks!

Afonso Oliveira added 3 commits March 24, 2025 11:19
…ne set of extensions that GO currently supports.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>
Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>
…generator.py may be used to generate.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>
@ThinkOpenly

Copy link
Copy Markdown
Collaborator

I don't have any particular concerns after quickly looking at the code. Is the generated artifact for inst.go match the target?

For Spike, same question. I don't think there's a relationship between Golang and Spike... should this be a separate PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think my answers did not show because I did not comment here, can you see them Mark Ryan (@markdryan)?

Comment thread backends/generators/Go/inst.go Outdated
Comment thread backends/generators/Go/inst.go Outdated
Comment thread backends/generators/Go/inst.go Outdated
Comment thread backends/generators/Go/inst.go Outdated
Comment thread backends/generators/Go/inst.go Outdated
@AFOliveira

Copy link
Copy Markdown
Member Author

I don't have any particular concerns after quickly looking at the code. Is the generated artifact for inst.go match the target?

For Spike, same question. I don't think there's a relationship between Golang and Spike... should this be a separate PR?

So, for Golang I think we are there or, at least super close (some order may be changed, but that is it). Same for Spike, but I agree, I will remove Spike out of the branch since it just adds confusion, wait for this to be merged and then get Spike on board as well.

@dhower-qc Derek Hower (dhower-qc) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add a tasks.rake in backends/generators/Go with a task that will be displayed with ./do --tasks?

@AFOliveira

Copy link
Copy Markdown
Member Author

Can you add a tasks.rake in backends/generators/Go with a task that will be displayed with ./do --tasks?

I already did locally actually :) Let me just remove Spike, and solve the commit history and I will change this PR from draft to ready to review. Unfortunately, it seems CSRs information in the UDB is the weak-point ATM, although I think we will change this in a matter of weeks

Afonso Oliveira added 2 commits March 26, 2025 16:32
Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>
Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>
@dhower-qc

Copy link
Copy Markdown
Contributor

Derek Hower (@dhower-qc) @kbroch-rivosinc Do you guys have any clue on why the tests are failing? https://github.com/riscv-software-src/riscv-unified-db/actions/runs/14088608154/job/39459215925?pr=526#step:6:142

It looks like you are stuck in the middle here. GitHub thinks it needs to check for C# files, which is true in main. But your branch doesn't have any C# files, which is why I think it's failing. Hopefully after you merge with main the error will resolve.

Afonso Oliveira added 2 commits March 26, 2025 16:47
Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>
Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>
@AFOliveira
Afonso Oliveira (AFOliveira) marked this pull request as ready for review March 26, 2025 16:50
@AFOliveira

Afonso Oliveira (AFOliveira) commented Mar 26, 2025

Copy link
Copy Markdown
Member Author

I think this is ready to merge - only problems are:

  1. Inherently some instructions order is different than riscv-opcodes generated inst.go, I don't think there is a way to solve this. (also, tiny scope, I think it only happens once in the whole inst.go)
  2. We are missing some essential CSRs, so we can not officially propose this to the Go community, I propose just relying on an issue to track this and merge this PR into main as is. Whenever, we have the same CSRs as RISC-V Opcodes I'll just update everyone.

@ThinkOpenly

Copy link
Copy Markdown
Collaborator
  1. Inherently some instructions order is different than riscv-opcodes generated inst.go, I don't think there is a way to solve this. (also, tiny scope, I think it only happens once in the whole inst.go)

Could you post a diff here, so we have a reference?

  1. We are missing some essential CSRs, so we can not officially propose this to the Go community, I propose just relying on an issue to track this and merge this PR into main as is. Whenever, we have the same CSRs as RISC-V Opcodes I'll just update every one.

OK

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>
@AFOliveira

Copy link
Copy Markdown
Member Author

Could you post a diff here, so we have a reference?

https://www.diffchecker.com/srkhmI0D/
The left one is riscv-opcodes and the right is UDB generated.

  1. What I was mentioning as order change happens on line 921.
  2. There are other differences in instructions but this is a question of how riscv-opcodes describes data vs how UDB does, it may require discussions but has nothing to do with this PR.
  3. You may see the CSR diff in the end.

…all.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>
@dhower-qc

Copy link
Copy Markdown
Contributor

Cool. The instructions look pretty good.

We have pretty good issue coverage for the CSRs.

I notice that the riscv-opcodes version isn't correct for pmpcfgODD; if I understand correctly, this is supposed to be for RV64, and those CSRs don't exist in RV64.

I'd vote to approve this PR since the generation looks great. We can work on the missing data.

@AFOliveira

Copy link
Copy Markdown
Member Author

Cool. The instructions look pretty good.

We have pretty good issue coverage for the CSRs.

I notice that the riscv-opcodes version isn't correct for pmpcfgODD; if I understand correctly, this is supposed to be for RV64, and those CSRs don't exist in RV64.

I'd vote to approve this PR since the generation looks great. We can work on the missing data.

Nice, let me just add this to the regression test then, just to ensure it is not broken along the way

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>
Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>
Comment on lines +195 to +221
runs-on: ubuntu-latest
env:
SINGULARITY: 1
steps:
- name: Clone Github Repo Action
uses: actions/checkout@v4
- name: Setup apptainer
uses: eWaterCycle/setup-apptainer@v2.0.0
- name: Get container from cache
id: cache-sif
uses: actions/cache@v4
with:
path: .singularity/image.sif
key: ${{ hashFiles('container.def', 'bin/.container-tag') }}
- name: Get gems and node files from cache
id: cache-bundle-npm
uses: actions/cache@v4
with:
path: |
.home/.gems
node_modules
key: ${{ hashFiles('Gemfile.lock') }}-${{ hashFiles('package-lock.json') }}
- if: ${{ steps.cache-sif.outputs.cache-hit != 'true' }}
name: Build container
run: ./bin/build_container
- name: Generate Go code
run: ./do gen:go

Check warning

Code scanning / CodeQL

Workflow does not contain permissions

Actions Job or Workflow does not set permissions
@AFOliveira

Copy link
Copy Markdown
Member Author

Is there any dependency for this PR Derek Hower (@dhower-qc)? Or can we merge this and then I'll start the rest of riscv-opcodes outputs?

@dhower-qc Derek Hower (dhower-qc) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. We might want to eventually elevate the python interface into the db data to lib, but let's do that later

@AFOliveira
Afonso Oliveira (AFOliveira) added this pull request to the merge queue Mar 28, 2025
Merged via the queue into main with commit 3b854dc Mar 28, 2025
@AFOliveira
Afonso Oliveira (AFOliveira) deleted the AFOliveira/GoSupport branch March 28, 2025 10:17
Joseph Pak (jpak-qc) pushed a commit to jpak-qc/riscv-unified-db that referenced this pull request Jul 28, 2026
* Add initial Golang generation support.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>

* Enhance go generator to allow filtering by extensions

* Enhance Go CSR generation by filtering out unused extensions and define set of extensions that GO currently supports.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>

* update checked out version of inst.go changed by latest commits.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>

* Refactor to ensure reusable code, given the extensibility of outputs generator.py may be used to generate.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>

* Fix Go awkward struct spacing.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>

* Add rake task to generate Golang input - inst.go

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>

* Add CSR ordering to match riscv-opcodes.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>

* Remove checked out inst.go

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>

* Update all spacing to exactly match riscv-opcodes.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>

* Change check_requirement due to being out of scope for go_generator call.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>

* Add gen:go to CI regression.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>

* Add gen:go to local regression test.

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>

---------

Signed-off-by: Afonso Oliveira <Afonso.Oliveira@synopsys.com>
Co-authored-by: Your Name <your.email@example.com>
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