-
Notifications
You must be signed in to change notification settings - Fork 169
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
Modularise the specification #572
base: master
Are you sure you want to change the base?
Conversation
First of all, I think this is a good idea and needs to be pursued.
However, as the model stands now, it would seem to be a bit difficult to
split up files based on extensions. I'm specifically referring to the CSRs.
They seem to be lumped together and not tied to an extension. For example,
the HPM CSRs are listed in the riscv_csr_begin.sail file. It seems like
they
should be put into an "hpm extension" file.
Also, the implementation of some individual CSRs is based on multiple
extensions. The simplest one I can think of is the misa CSR. As an
example, how would a vector module implement the V bit in the misa?
How can that functionality be scattered?
Bill Mc.
…On Thu, Oct 3, 2024 at 9:07 AM github-actions[bot] ***@***.***> wrote:
Test Results
396 tests ±0 396 ✅ ±0 0s ⏱️ ±0s
4 suites ±0 0 💤 ±0
1 files ±0 0 ❌ ±0
Results for commit e1082d2
<e1082d2>.
± Comparison against base commit 47380fa
<47380fa>
.
—
Reply to this email directly, view it on GitHub
<#572 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXROLOFN5YVVISH37OTGVM3ZZVTUXAVCNFSM6AAAAABPKC4BVGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJRG44TQNJTGE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Bill McSpadden
Formal Verification Engineer
RISC-V International
mobile: 503-807-9309
Join me at RISC-V Summit North America <http://www.riscvsummit.com/> in
October!
|
Everything in the When it comes to things like bits in the
(using an attribute just to avoid any concrete syntax for now) where you could push the definition of a field into another module without making it a scattered definition, but I'm not sure it's really needed. |
I have also considered adding a feature that would allow you to require a module in such a way that you can only use it in a guarded way, i.e. from the
The way that would work is it just combines Sail's existing flow-sensitive typing with the 'in_scope' check the type-system now does, and it means you can add functionality to the base model from an extension in a way where we can statically guarantee it gets compiled out when the extension doesn't exist. |
This looks like a huge improvement. I think even if it doesn't solve all the modularisation & organisation issues we should switch to it ASAP. Does the private keyword mean that no other modules can refer to that definition even if they say they depend on it? That sounds very useful too. I think when this is done we should work on improving the organisation of the modules and maybe reducing their size. There are a few places in the code where people have just kind of given up, e.g. this one:
|
Exactly, if you have
and another file
and link them like:
You'll get an error like
I think there are a few places in the virtual memory code where we have something like |
Seems like a great improvement. It might be worth thinking about how we nest the extensions though. |
What's the significance of the nested modules? Is it that Another question: is the intention that you can exclude modules from compilation? I mean I don't think we would want that for the C simulator use case (except maybe to exclude Vector for compilation time reasons), but I guess you might want that for the SV backend?
|
Currently the module namespace is flat, and the nesting just allows you to require a group of related modules, so the following
is equivalent to
so |
Yes, rather than giving Sail a list of files you can give it a list of module names and it just uses them. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you have any idea how this would work with the CHERI repo? I guess the simplest thing is to just copy & paste the whole file and then change all the riscv_
s to cheri_
s where appropriate.
Or maybe add a load of if $CHERI then
..? Hmm.
else | ||
error("ARCH variable must be either RV32 or RV64"), | ||
riscv_xlen.sail, | ||
riscv_flen_D.sail, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do with an option for riscv_flen_F.sail
too I guess?
The idea was you could have |
I am opening the PR primarily to get feedback on one of the main things I have been slowly working on w.r.t. the sail-riscv model.
Right now the model is (in my opinion) a bit unwieldy and hard to understand as it is not clear immediately what the high level structure of the model is, and the way we configure the model using the Makefile does not allow for extensions to easily be added and removed without hand-modifying the Makefile.
To solve this problem, I have added a basic module system to Sail, which allows for the structure of the specification to be specified as a collection of modules in a
.sail_project
file. The key ideas here are as follows:Each of these modules consists of a list of files (much like how you pass a list of files to Sail on the command line today), as well as a list of modules that module requires.
The module system ensures that if a module does not require another module, it cannot refer to any definitions contained within it. There is also a
private
keyword which can be used to encapsulate implementation details.Modules can specify other modules that must come before or after them, but without requiring them. This is to support the scattered definition feature.
The
.sail_project
file serves as an instant reference to the overall model structure, it isn't embedded in the files. You can also have multiple.sail_project
files, so you could passriscv.sail_project cheri.sail_project
to Sail, and it would be able to link them together in much the same way we do now.There is some basic support for conditional includes.
With this, building the model becomes as simple as:
I have included an updated Makefile in this PR, which you can invoke using
make -f Makefile.new csim
The initial splitting of the model is something that I would like feedback on. I have tried to split it roughly so each extension is its own module, or grouped collection of related modules. There are some improvements I could make if I modified the model source slightly to move things around, but for this PR you'll notice I haven't changed the model source at all.
Feedback on the structure of the
.sail_project
file is also appreciated - do you think it needs additional features, is it understandable what it means at a glance?Note there were some bugs I had to squash when putting this PR together, so it only builds with the development version of Sail - I expect this feature to be usable by the next release, taking into account any feedback I get here.