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 Zmmul #122

Merged
merged 1 commit into from
Jan 19, 2022
Merged

Add Support for Zmmul #122

merged 1 commit into from
Jan 19, 2022

Conversation

bilalsakhawat
Copy link
Contributor

RISC-V Zmmul extension includes following instructions:

  • mul
  • mulh
  • mulhsu
  • mulhu
  • mulw (RV64 only)
    The opcode encodings and instruction semantics are identical to those in the M-extension.
    The ISA string is Zmmul.
    8.3 Zmmul Extension, Version 0.1 (riscv unpriv spec)

@scottj97
Copy link
Contributor

scottj97 commented Nov 3, 2021

Should the new if haveMulDiv() qualifiers have been there all along? If so, can you make a separate commit with only that change, then a second commit to add Zmmul?

@bilalsakhawat
Copy link
Contributor Author

Should the new if haveMulDiv() qualifiers have been there all along? If so, can you make a separate commit with only that change, then a second commit to add Zmmul?

Yes! haveMulDiv() qualifier has been there. Sure, I'll make two separate commits.

@bilalsakhawat
Copy link
Contributor Author

@scottj97 Actually haveMulDiv() checks were already there. My bad, I added some extra checks. Now I have removed those extra checks.

@scottj97
Copy link
Contributor

scottj97 commented Nov 3, 2021

It's nice that this is much simplified, but please squash the two commits back into one.

It first appeared that the one commit was doing two things (adding missing haveMulDiv(), and adding Zmmul) which is why I asked for two commits. Since it turns out that was not the case, this PR is only doing one thing (adding Zmmul) so it only needs one commit.

@bilalsakhawat
Copy link
Contributor Author

bilalsakhawat commented Nov 3, 2021

When it will merge it will squash merge into the master i.e., will go as one commit. Do I need to squash commits anyway ?

@scottj97
Copy link
Contributor

scottj97 commented Nov 3, 2021

You're assuming the admin who clicks the Merge button chooses the Squash option. I don't think that's a safe assumption.

@jrtc27
Copy link
Collaborator

jrtc27 commented Nov 3, 2021

Does M not imply Zmmul, and thus only the latter needs checking?

@@ -180,6 +180,8 @@ function haveUsrMode() -> bool = misa.U() == 0b1
function haveNExt() -> bool = misa.N() == 0b1
/* see below for F and D extension tests */

function haveZmmul() -> bool = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

As with the bitmanip PR, keep the lists of dummy Z* extension checks sorted, i.e put Zm* below Zk*

Copy link
Contributor Author

@bilalsakhawat bilalsakhawat Nov 3, 2021

Choose a reason for hiding this comment

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

Does M not imply Zmmul, and thus only the latter needs checking?

Yes, M does not imply Zmmul. You can read the discussion on this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As with the bitmanip PR, keep the lists of dummy Z* extension checks sorted, i.e put Zm* below Zk*

Sure :)

Copy link
Collaborator

@jrtc27 jrtc27 Nov 3, 2021

Choose a reason for hiding this comment

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

Does M not imply Zmmul, and thus only the latter needs checking?

Yes, M does not imply Zmmul. You can read the discussion on this PR

This contradicts riscv/riscv-isa-manual#648 (comment), which is as close to an authoritative source as I can find. Pointing at someone's own comments on their own Spike pull request is hardly authoritative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's put it in this way. An implementation can have both extensions as a time. When I said does not imply I meant to say If misa.M() ==1 it does not mean that Zmmul extension is there as well. if Either or both of them are in implementation the Mul instructions will work. That's why there is a or between haveMulDiv and haveZmmul.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I understand. The benefit of Zmmul is, as it supports only MUL instructions (Not DIV/REM), it will save hardware in those implementations where DIV/REM instructions are not needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

One difference between M and Zmmul is that the latter is not controlled by misa.M. If you have Zmmul then the multiply instructions are always enabled. If you have M then the multiply instructions are enabled iff misa.M==1. That's why saying "M implies Zmmul" is inaccurate -- because that would mean that misa.M only controls divide and not multiply.

This Sail model doesn't support modifying misa.M so this is moot here -- but that might change in the future so I think it's better to keep them separate here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah indeed that is an important but subtle difference. I believe modifying misa.M should work if sys_enable_writable_misa is true.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this code supports modifying bits C/D/F only. And reading it, I see a bug, which I'll file separately.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, right, I skimmed it and thought it was mostly fixing up v, but it's just using v to fix up the existing m.

@bilalsakhawat
Copy link
Contributor Author

You're assuming the admin who clicks the Merge button chooses the Squash option. I don't think that's a safe assumption.

Sure. I'll squash commits.

@scottj97
Copy link
Contributor

scottj97 commented Nov 3, 2021

@bilalsakhawat-10xe can you please fix the Git commit message. It doesn't make sense to include "Removed extra haveMulDiv() checks" because it doesn't do that anymore.

@jrtc27
Copy link
Collaborator

jrtc27 commented Nov 4, 2021

Please amend your commit message to include a verb ("Add support for Zmmul", "Implement Zmmul", etc., don't really care exactly what), it's good practice (otherwise it doesn't actually mean anything as it leaves one asking what are you doing to the zmmul support? adding it? removing it? refactoring it? all possibilities without looking at the changes themselves). Otherwise this looks ready.

@bilalsakhawat bilalsakhawat changed the title Support for Zmmul Add Support for Zmmul Nov 5, 2021
@jrtc27
Copy link
Collaborator

jrtc27 commented Nov 5, 2021

This was fine until you pushed that merge commit. Never merge into a pull request branch, always rebase the branch. But in this case there was no need to do either, the changes to master don't affect this PR whatsoever.

@jrtc27
Copy link
Collaborator

jrtc27 commented Nov 5, 2021

Yes, please rebase in order to lose the merge commit

@jrtc27
Copy link
Collaborator

jrtc27 commented Nov 5, 2021

(same goes for your bitmanip, and now scalar crypto, PRs)

@bilalsakhawat
Copy link
Contributor Author

Yes, please rebase in order to lose the merge commit

Steps I have in mind:

  • revert the merge commit
  • rebase with master
  • squash above two into one i.e., rebase with master

Is there a good way to do it?

@jrtc27
Copy link
Collaborator

jrtc27 commented Nov 5, 2021

Yes, please rebase in order to lose the merge commit

Steps I have in mind:

  • revert the merge commit
  • rebase with master
  • squash above two into one i.e., rebase with master

Is there a good way to do it?

Just git rebase master, should just work

@jrtc27
Copy link
Collaborator

jrtc27 commented Nov 5, 2021

(or git rebase origin/master if your local master branch is behind)

@scottj97
Copy link
Contributor

scottj97 commented Nov 8, 2021

I wonder if it's a good idea to haveZmmul==true as the default. We also haveMulDiv==true as the default, and it doesn't really make sense to have both of these at once. (As discussed above w.r.t. misa.M.) It seems the configuration system that the Arch Test SIG is working on should have a configuration knob with three choices: None, M, or Zmmul.

@bilalsakhawat
Copy link
Contributor Author

I wonder if it's a good idea to haveZmmul==true as the default. We also haveMulDiv==true as the default, and it doesn't really make sense to have both of these at once. (As discussed above w.r.t. misa.M.) It seems the configuration system that the Arch Test SIG is working on should have a configuration knob with three choices: None, M, or Zmmul.

@jrtc27 you may have a proper answer, why we are using haveZmmul==true as default for now.

@bilalsakhawat
Copy link
Contributor Author

bilalsakhawat commented Dec 4, 2021

I wonder if it's a good idea to haveZmmul==true as the default. We also haveMulDiv==true as the default, and it doesn't really make sense to have both of these at once. (As discussed above w.r.t. misa.M.) It seems the configuration system that the Arch Test SIG is working on should have a configuration knob with three choices: None, M, or Zmmul.

@jrtc27 you may have a proper answer, why we are using haveZmmul==true as default for now.

@jrtc27 some input from you will be great.

@allenjbaum
Copy link
Collaborator

I originally defined it such that Zmmul and M were incompatible, but I was told there weren't. Zmmul is redundant with M, but not disallowed. So, stupid, but not forbidden.

@jrtc27
Copy link
Collaborator

jrtc27 commented Dec 5, 2021

I originally defined it such that Zmmul and M were incompatible, but I was told there weren't. Zmmul is redundant with M, but not disallowed. So, stupid, but not forbidden.

Ok, thanks for the clarification.

Given we have all the Zb* and Zk* extensions on by default with no way to turn them off (currently), it does seem a bit odd to not provide Zmmul. I know it means setting misa.M to 0 no longer turns off MUL*, but does that actually matter? I don't personally mind either way all that much, just so far the philosophy's been to enable as much as we can by default for maximum utility.

@allenjbaum
Copy link
Collaborator

From the point of view of architectural tests: the fact that either are on doesn't matter.
If M-extension is unimplemented, we won't ever test DIV/REM ops, so it's irrelevant whether they actually correctly execute those ops
Similarly, if both M-extension and Zmmul are unimplemented, we won't test multiply instructions.

@scottj97
Copy link
Contributor

scottj97 commented Dec 5, 2021

From the point of view of architectural tests: the fact that either are on doesn't matter.

The misa CSR is part of the architectural spec too. Don't you want to test that it works properly, disabling or enabling instructions as required?

I don't care what the default is for Zmmul in this Sail model.

@allenjbaum
Copy link
Collaborator

If MISA.M is writable, we could, sort of, but it is a bit pointless. t boot, if M-ext is implemented, MISA.M will be set, and we will test that it works. IF MISA.M is writable, we can test that it can be cleared, and set again, but that is all.
If it is cleared, it is still legal for Mul ops to perform a multiply. On the other hand, if Zmmul and M-ext are both implemented, we could text that Mul ops still work with MISA.M cleared, because Zmmul can't be disabled.
I hadn't thought of that.
In fact, we probably should run all Zmmul tests that way. I need to figure out how to do that without having to re-write all the M tests, since we are just re-using them, running if either M-ext or Zmmul are implemented.

@bilalsakhawat
Copy link
Contributor Author

bilalsakhawat commented Dec 6, 2021

I know a way how we can run all Zmmul tests without having to re-write all the M tests. We just need to check if Zmmul is in the ISA string and if yes include mul, mulh, mulhsu, mulhu and mulw tests in the database.yaml (it contains the list of tests to be run on Ref and DUT). We just need to change 1-2 files in riscof env.

@allenjbaum
Copy link
Collaborator

I don't think it's that simple. We potentially have to run the tests twice; once if M-extension is supported (and MISA.M is set, which should be the case after reset. Hmm, our tests probably need to check that) and once if Zmmul is supported and either MISA.M is clear or M-ext isn't supported). I think that means those tests need to be replicated.
I thought we could avoid that, but we can't.

@bilalsakhawat
Copy link
Contributor Author

I don't think it's that simple. We potentially have to run the tests twice; once if M-extension is supported (and MISA.M is set, which should be the case after reset. Hmm, our tests probably need to check that) and once if Zmmul is supported and either MISA.M is clear or M-ext isn't supported). I think that means those tests need to be replicated. I thought we could avoid that, but we can't.

Running test twice is not an issue. We can do that for misa.M and zmmul. The issue will be when collecting coverage, we need to make changes in riscv-ctg as well. Even this is a simple task. But this is not a recommended solution to make changes riscof and riscv-ctg for just zmmul. Replicating the tests is the best solution.

@allenjbaum
Copy link
Collaborator

allenjbaum commented Dec 6, 2021 via email

@allenjbaum
Copy link
Collaborator

I think I've discussed this elsewhere, but the corner case only occurs when there is an implementation that has both M-extension and Zmmul, AND misa.M is read-write, so the M-extension can be disabled (which effectively disables only DIV/REM ops, since Zmmul can't be disabled).
This is an unlikely enough to be implemented that instead of burdening our test infrastructure with handling this, we will will require the vendor to run tests twice: once normally and once with boot code augmented to clear misa.M. The latter only needs to execute M-extension tests. Both m-extension tests reports should be submitted.

@bilalsakhawat
Copy link
Contributor Author

So I think, the changes I made in this PR are good enough for now. Later we may add a plusargs in sail '--isa=RVxxx' like we have in spike. Then for 64-bit we can have the cases like:

  • RV64IM (misa.M == true, Zmmul == false)
  • RV64IM_Zmmul (misa.M == true, Zmmul == true)
  • RV64I_Zmmul (misa.M == false, Zmmul == true)
  • And a case where we have neither for them enable (misa.M == false, Zmmul == false)
    depending on the plusargs '--isa' string.

@jrtc27
Copy link
Collaborator

jrtc27 commented Dec 8, 2021

Well, it's not a plusarg, those are specifically +foo and are so called due to the leading +, and are pretty specific to the hardware space (and thus spike's fesvr/htif/whatever stuff..). But yes, eventually all the Zfoo should be dynamically configurable via a command-line argument, ideally as an arch string that matches what toolchains use.

@jrtc27
Copy link
Collaborator

jrtc27 commented Dec 8, 2021

So, if nobody has any strong opinions on this, I suggest we go ahead and merge it with Zmmul defaulting to enabled, given so far we've only disabled extensions by default if they conflict?

@bilalsakhawat
Copy link
Contributor Author

Well, it's not a plusarg, those are specifically +foo and are so called due to the leading +, and are pretty specific to the hardware space (and thus spike's fesvr/htif/whatever stuff..). But yes, eventually all the Zfoo should be dynamically configurable via a command-line argument, ideally as an arch string that matches what toolchains use.

Thanks for correction. I choose the wrong terms actually, I should have said command-line argument.

@allenjbaum
Copy link
Collaborator

From the point of view of ACTs - it is our intention that we don't execute tests for extensions that don't have support (or are disabled) because results are unpredictable. At reset, all extensions that implemented are enabled, regardless of whether it is possible to disable them. So, defaulting them to enabled seems just fine.

@martinberger
Copy link
Collaborator

@scottj97 @jrtc27 @allenjbaum @bilalsakhawat-10xe I would like to merge this PR this week. Any objections to that?

@allenjbaum
Copy link
Collaborator

allenjbaum commented Jan 18, 2022 via email

@jrtc27
Copy link
Collaborator

jrtc27 commented Jan 18, 2022

Nope, long overdue

@martinberger martinberger merged commit 56125e6 into riscv:master Jan 19, 2022
@martinberger
Copy link
Collaborator

Merged.

Thanks @bilalsakhawat-10xe @scottj97 @jrtc27 @allenjbaum

bilalsakhawat added a commit to bilalsakhawat/sail-riscv that referenced this pull request Jan 20, 2022
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