Skip to content

Change XLEN and FLEN to be configure-time options #870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Timmmm
Copy link
Collaborator

@Timmmm Timmmm commented Apr 17, 2025

This means you only need to compile the emulator once in order to support RV32F, RV32D, RV64F and RV64D.

This compiles doesn't work yet due to some issues in Sail:

There are also various TODOs but I thought I'd push this to prevent duplicated effort in case someone else starts working on it.

@pmundkur
Copy link
Collaborator

This is awesome! It looks like the upstream issues are fixed. Are there any other issues preventing this coming out of draft?

@@ -3,19 +3,19 @@
# On success or failure they write to the `tohost` symbol. See this code:
# https://github.com/riscv/riscv-test-env/blob/4fabfb4e0d3eacc1dc791da70e342e4b68ea7e46/p/riscv_test.h#L200

file(GLOB elfs_rv32d CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/rv32*.elf")
file(GLOB elfs_rv64d CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/rv64*.elf")
# file(GLOB elfs_rv32d CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/rv32*.elf")
Copy link
Collaborator

Choose a reason for hiding this comment

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

So I guess here we would need to edit the json?

Maybe the easiest way would be to make it a template and use configure_file() to replace @XLEN_LOG2@, etc. to generate a config_rv32d.json, config_rv64d.json in the build dir?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. The first party tests already use jq to edit the JSON so maybe we just use that method here for now.

@@ -6,6 +6,10 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*=======================================================================================*/

type flen_bytes : Int = config base.flen_bytes

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to automatically set this based on if F or D are supported instead of adding flen as a configuration option?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, or the other way around. Not sure which is better. I agree we shouldn't have both.

@Timmmm Timmmm force-pushed the user/timh/xlen_flen branch from 11d975a to 336ba9f Compare April 22, 2025 10:59
@Timmmm
Copy link
Collaborator Author

Timmmm commented Apr 22, 2025

This is awesome! It looks like the upstream issues are fixed. Are there any other issues preventing this coming out of draft?

Getting closer but I hit another issue: rems-project/sail#1251

@Timmmm
Copy link
Collaborator Author

Timmmm commented Apr 22, 2025

Also I need to:

  1. Re-enable/fix the tests.
  2. Remove flen or F/D as @jordancarlin suggested.
  3. Maybe make the config option be xlen instead of log2_xlen_bytes which is not very intutive! Since there are only 2 options I think we can just go backwards like: type xlen_bytes : Int = if xlen == 32 then 4 else 8. Hopefully that will work.
  4. Update the readme.
  5. Ideally benchmark the performance hit. I suspect it will be relatively minor but it might not be.

And we'll need to wait for a new Sail compiler release after it's working.

@Timmmm
Copy link
Collaborator Author

Timmmm commented Apr 22, 2025

Ok I got the RV64 first party test passing! Still need to do all the todos I mentioned.

@Timmmm
Copy link
Collaborator Author

Timmmm commented Apr 23, 2025

I did have a crazy idea - what if we just take the xlen setting from the ELF file? :-D

On balance, probably a bad idea. Explicitness is good. Just thought I'd mention it!

@jordancarlin
Copy link
Collaborator

I did have a crazy idea - what if we just take the xlen setting from the ELF file? :-D

On balance, probably a bad idea. Explicitness is good. Just thought I'd mention it!

Something to think about down the road maybe. I think we can technically even find out which extensions an elf was compiled with if we really wanted to. Might be nice to be able to just run an elf without thinking about the config.

For verification purposes though (which I think is one of the primary uses of the Sail model), you want the model to exactly match an implementation no matter what the elf file being passed in is. Maybe there could be two different modes in the future: use the values from a config file if one is given and parse the elf if not.

@Timmmm
Copy link
Collaborator Author

Timmmm commented Apr 23, 2025

This basically works now. All the tests pass. Remaining todos:

  1. Benchmark.
  2. Come up with a better system for the config files than copy/pasting them. Though tbh if we only have 2/3 files that's maybe the best way anyway.
  3. Ideally get rid of the weird _rv suffix on riscv_sim_rv, but I think that might be best deferred until we merge the RVFI version so there's only a single emulator.
  4. Wait for new Sail compiler release.

This means you only need to compile the emulator once in order to support RV32F, RV32D, RV64F and RV64D.
@Timmmm Timmmm force-pushed the user/timh/xlen_flen branch from e3e76fa to 551e8f8 Compare April 28, 2025 15:36
@@ -167,8 +165,8 @@ endif()
include(CPack)

# Convenience targets.
add_custom_target(csim DEPENDS riscv_sim_rv32d riscv_sim_rv64d)
add_custom_target(check DEPENDS generated_model_rv32d generated_model_rv64d)
add_custom_target(csim DEPENDS riscv_sim_rv)
Copy link
Collaborator

Choose a reason for hiding this comment

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

One thing worth thinking about here is what we want the long term name of the simulator to be. I don't think we should change it more often than needed (it caused enough trouble when we added the d), so we should probably go with the new name now even though rvfi will need to be merged in later. The simplest answer would be to just go with riscv_sim, but I wonder if something like riscv_sail_sim might be better and less generic.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could also keep the old names around as scripts that run with a specific config file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we make the config json a template, we could install some common default config files such as config_rv32f.json, config_rv64d.json.
And we'd be able to use them for the tests without jq

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jordancarlin I agree, though it is a little awkward to do with how ${arch} currently works. If it is empty or something like _rvfi we'll get weird filenames in places, e.g. search for -o "${arch}".

If the simulator name could end with rv that would sneakily avoid the issue! sim_rv? :-D Probably not a name I would have chosen given a totally free choice tbf.

@arichardson Yeah... I dunno, it means you can't easily use them as starter configs.

Perhaps we could have a script that generates a wide variety of config files (like, 20 of them), and add them to the repository. CI can check they are up-to-date. Then it means they're easily visible in the source repo and users don't need whatever scripting thing we use to generate them.

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.

4 participants