Skip to content
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

Add support for the RV32E variant #541

Merged
merged 4 commits into from
Jan 27, 2025
Merged

Conversation

eleanorLYJ
Copy link
Collaborator

@eleanorLYJ eleanorLYJ commented Jan 23, 2025

Key changes:
The RV32E variant, which reduces the general-purpose registers to 16, is optimizing the architecture for resource-constrained embedded microcontrollers.

  • Architecture tests have been enabled for RV32E, with appropriate handling of the reduced register set and ABI.
  • The CI pipeline has been updated to include RV32E tests, ensuring the stability and correctness of the new functionality.
  • Readme.md has been updated to reflect the addition of RV32E support.

Impact:
This enhancement broadens the compatibility of the emulator with the RISC-V specification, specifically targeting low-power, minimal-complexity systems. The addition of CI tests ensures that the new functionality is robust and reliable.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Benchmarks

Benchmark suite Current: 64ea138 Previous: d29f229 Ratio
Dhrystone 1324 Average DMIPS over 10 runs 1325 Average DMIPS over 10 runs 1.00
Coremark 969.943 Average iterations/sec over 10 runs 964.643 Average iterations/sec over 10 runs 0.99

This comment was automatically generated by workflow using github-action-benchmark.

@eleanorLYJ eleanorLYJ force-pushed the add-rv32e branch 4 times, most recently from e83fefe to 67ee41c Compare January 23, 2025 15:42
@eleanorLYJ
Copy link
Collaborator Author

Hi @ChinYikMing,

In GitHub Actions, I encountered the following error during arch-tests:

ERROR | make[1]: warning: -j1 forced in submake: resetting jobserver mode.

It seems related to $PARALLEL in .ci/riscv-tests.sh. Do you have any ideas about this?

Thanks!

@jserv jserv changed the title Add support for the RV32E base ISA variant Add support for the RV32E variant Jan 23, 2025
@ChinYikMing
Copy link
Collaborator

ChinYikMing commented Jan 24, 2025

In GitHub Actions, I encountered the following error during arch-tests:

ERROR | make[1]: warning: -j1 forced in submake: resetting jobserver mode.
It seems related to $PARALLEL in .ci/riscv-tests.sh. Do you have any ideas about this?

Can you paste the link of the failed CI?

@eleanorLYJ
Copy link
Collaborator Author

eleanorLYJ commented Jan 24, 2025

Can you paste the link of the failed CI?

Sure, Here's the link to the failed CI: https://github.com/sysprog21/rv32emu/actions/runs/12932773743/job/36080838856

@ChinYikMing
Copy link
Collaborator

ChinYikMing commented Jan 24, 2025

Here's the link to the failed CI: https://github.com/sysprog21/rv32emu/actions/runs/12932773743/job/36080838856

It seems like segmentation fault is occurred. To pass the arch-test, full4G is required for this moment. Could you confirm if the changes in this pull request still enable the full4G?

@eleanorLYJ
Copy link
Collaborator Author

eleanorLYJ commented Jan 24, 2025

It seems like segmentation fault is occurred. To pass the arch-test, full4G is required for this moment. Could you confirm if the changes in this pull request still enable the full4G?

Yes, this is indeed the issue. Thank you!

@jserv
Copy link
Contributor

jserv commented Jan 24, 2025

It seems like segmentation fault is occurred. To pass the arch-test, full4G is required for this moment. Could you confirm if the changes in this pull request still enable the full4G?

FULL4G was a hack done by me. Let's completely get rid of such kludge.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Rebase the latest master branch.

src/riscv.h Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@eleanorLYJ eleanorLYJ force-pushed the add-rv32e branch 2 times, most recently from 6268927 to 5321fc4 Compare January 25, 2025 01:35
Copy link
Collaborator

@visitorckw visitorckw left a comment

Choose a reason for hiding this comment

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

LGTM. Thx!

@ChinYikMing
Copy link
Collaborator

@eleanorLYJ Maybe adding the ENABLE_RV32E and description in customizations section also?

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Rebase the latest master branch to resolve Arm64 host breakage on CI.

src/riscv.h Outdated
Comment on lines 36 to 56
#define RV_REGS_LIST \
_(zero) /* hard-wired zero, ignoring any writes */ \
_(ra) /* return address */ \
_(sp) /* stack pointer */ \
_(gp) /* global pointer */ \
_(tp) /* thread pointer */ \
_(t0) /* temporary/alternate link register */ \
_(t1) /* temporaries */ \
_(t2) \
_(s0) /* saved register/frame pointer */ \
_(s1) \
_(a0) /* function arguments / return values */ \
_(a1) \
_(a2) /* function arguments */ \
_(a3) \
_(a4) \
_(a5) \
IIF(RV32_HAS(RV32E)(, _(a6) _(a7) _(s2) /* saved register */ \
_(s3) _(s4) _(s5) _(s6) _(s7) _(s8) _(s9) _(s10) \
_(s11) _(t3) /* temporary register */ \
_(t4) _(t5) _(t6)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Rewrite as following:

/* clang-format off */
#define RV_REGS_LIST                                    \
    _(zero) /* hard-wired zero, ignoring any writes */  \
    _(ra)   /* return address */                        \
    _(sp)   /* stack pointer */                         \
    _(gp)   /* global pointer */                        \
    _(tp)   /* thread pointer */                        \
    _(t0)   /* temporary/alternate link register */     \
    _(t1)   /* temporaries */                           \
    _(t2)                                               \
    _(s0) /* saved register/frame pointer */            \
    _(s1)                                               \
    _(a0) /* function arguments / return values */      \
    _(a1)                                               \
    _(a2) /* function arguments */                      \
    _(a3)                                               \
    _(a4)                                               \
    _(a5)                                               \
    IIF(!RV32_HAS(RV32E)(                               \
        _(a6)                                           \
        _(a7)                                           \
        _(s2) /* saved register */                      \
        _(s3)                                           \
        _(s4)                                           \
        _(s5)                                           \
        _(s6)                                           \
        _(s7)                                           \
        _(s8)                                           \
        _(s9)                                           \
        _(s10)                                          \
        _(s11)                                          \
        _(t3) /* temporary register */                  \
        _(t4)                                           \
        _(t5)                                           \
        _(t6)                                           \                                                                                                     
    )
/* clang-format on */

Copy link
Collaborator Author

@eleanorLYJ eleanorLYJ Jan 27, 2025

Choose a reason for hiding this comment

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

If we use ! in IIF() macro, the following errors occur:

./src/common.h:216:30: error: pasting "IIF_" and "!" does not give a valid preprocessing token
  216 | #define IIF(c) PRIMITIVE_CAT(IIF_, c)
      |                              ^~~~
      
src/riscv.h:54:9: error: expected ‘,’ or ‘}’ before ‘!’ token
   54 |     IIF(!RV32_HAS(RV32E))(                              \
      |         ^

Copy link
Contributor

Choose a reason for hiding this comment

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

If we use ! in IIF() macro, the following errors occurs:

Interesting! It means there is room to improve IIF macro.

Use the previous way for using IIF macro along with clang-format comments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there is a missing comma at the last line. i.e.

        ...
        _(t5)                                           \
        _(t6)                                           \                                                                                                     
    ,)

And the current IIF macro only accepts RV32_HAS(*) as its argument because it needs the expansion from IIF(RV32_HAS(*)) to IIF_0 or IIF_1.

@eleanorLYJ eleanorLYJ force-pushed the add-rv32e branch 2 times, most recently from d6914ee to d29f229 Compare January 27, 2025 15:15
src/riscv.h Outdated Show resolved Hide resolved
The RV32E variant reduces the general-purpose registers to 16, optimizing
the architecture for resource-constrained embedded microcontrollers.

This addition enhances compatibility with the RISC-V specification and
targets low-power, minimal-complexity systems.
Add RV32E to the list of supported features, customization options, and
riscv-arch-test progress in the README.
Enable architecture tests for RV32E with appropriate handling of the
reduced register set and ABI.

With this change, users can run tests for RV32E using the following
command:

make arch-test RISCV_DEVICE=E
Add testing for the RV32E to the CI pipeline to ensure automatic
validation during continuous integration.
@jserv jserv merged commit 418a9e6 into sysprog21:master Jan 27, 2025
9 checks passed
@jserv
Copy link
Contributor

jserv commented Jan 27, 2025

Thank @eleanorLYJ for contributing!

@jserv jserv added this to the release-2025.1 milestone Jan 27, 2025
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