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

Chisel decoder #2836

Merged
merged 12 commits into from
May 17, 2022
Merged

Chisel decoder #2836

merged 12 commits into from
May 17, 2022

Conversation

sequencer
Copy link
Member

@sequencer sequencer commented May 12, 2021

This PR use new chisel API to replace original RocketChip Decoder.
Chisel Decoder depends on the explicit width, so I adds explicit width for most usages. This will be a breaking change to RC.
Related issue:

Type of change: new feature

Impact: no functional change

Development Phase: implementation

Release Notes
Switch to Chisel Decoder

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 12, 2021

CLA Signed

The committers are authorized under a signed CLA.

@sequencer
Copy link
Member Author

@jackkoenig Ask to merge this.

@jackkoenig
Copy link
Contributor

I bumped to 3.5-SNAPSHOT to show that this is still failing (at least for me locally)

@sequencer
Copy link
Member Author

sequencer commented Feb 1, 2022

This is really weird:

  BitPat(0000001??????????000?????0110011) -> BitPat(1000001101001???100?????00000110000000)
  BitPat(0000001??????????001?????0110011) -> BitPat(1000001101001???110?????00000110000000)
  BitPat(0000001??????????011?????0110011) -> BitPat(1000001101001???1110?????00000110000000)
  BitPat(0000001??????????010?????0110011) -> BitPat(1000001101001???1100?????00000110000000)
  BitPat(0000001??????????100?????0110011) -> BitPat(1000001101001???11000?????00000110000000)
  BitPat(0000001??????????101?????0110011) -> BitPat(1000001101001???11010?????00000110000000)
  BitPat(0000001??????????110?????0110011) -> BitPat(1000001101001???11100?????00000110000000)
  BitPat(0000001??????????111?????0110011) -> BitPat(1000001101001???11110?????00000110000000)
  BitPat(00000????????????010?????0101111) -> BitPat(1000001100001???101100000000010000010)
  BitPat(00100????????????010?????0101111) -> BitPat(1000001100001???101100100000010000010)
  BitPat(00001????????????010?????0101111) -> BitPat(1000001100001???10110000000010000010)
  BitPat(01100????????????010?????0101111) -> BitPat(1000001100001???101101100000010000010)
  BitPat(01000????????????010?????0101111) -> BitPat(1000001100001???101101000000010000010)
  BitPat(10000????????????010?????0101111) -> BitPat(1000001100001???101110000000010000010)
  BitPat(11000????????????010?????0101111) -> BitPat(1000001100001???101111000000010000010)
  BitPat(10100????????????010?????0101111) -> BitPat(1000001100001???101110100000010000010)
  BitPat(11100????????????010?????0101111) -> BitPat(1000001100001???101111100000010000010)
  BitPat(00010??00000?????010?????0101111) -> BitPat(1000001100001???10111000000010000010)
  BitPat(00011????????????010?????0101111) -> BitPat(1000001100001???10111100000010000010)
  BitPat(0010000??????????000?????1010011) -> BitPat(110000000????????????0?????11010000000000)
  BitPat(0010000??????????010?????1010011) -> BitPat(110000000????????????0?????11010000000000)
  BitPat(0010000??????????001?????1010011) -> BitPat(110000000????????????0?????11010000000000)
  BitPat(0010100??????????000?????1010011) -> BitPat(110000000????????????0?????11010000000000)
  BitPat(0010100??????????001?????1010011) -> BitPat(110000000????????????0?????11010000000000)
  BitPat(0000000??????????????????1010011) -> BitPat(110000000????????????0?????11010000000000)
  BitPat(0000100??????????????????1010011) -> BitPat(110000000????????????0?????11010000000000)
  BitPat(0001000??????????????????1010011) -> BitPat(110000000????????????0?????11010000000000)
  BitPat(?????00??????????????????1000011) -> BitPat(110000000????????????0?????11110000000000)
  BitPat(?????00??????????????????1000111) -> BitPat(110000000????????????0?????11110000000000)
  BitPat(?????00??????????????????1001111) -> BitPat(110000000????????????0?????11110000000000)
  BitPat(?????00??????????????????1001011) -> BitPat(110000000????????????0?????11110000000000)
  BitPat(111000000000?????001?????1010011) -> BitPat(110000000????????????0?????10000010000000)
  BitPat(111000000000?????000?????1010011) -> BitPat(110000000????????????0?????10000010000000)
  BitPat(110000000000?????????????1010011) -> BitPat(110000000????????????0?????10000010000000)
  BitPat(110000000001?????????????1010011) -> BitPat(110000000????????????0?????10000010000000)
  BitPat(1010000??????????010?????1010011) -> BitPat(110000000????????????0?????11000010000000)
  BitPat(1010000??????????001?????1010011) -> BitPat(110000000????????????0?????11000010000000)
  BitPat(1010000??????????000?????1010011) -> BitPat(110000000????????????0?????11000010000000)
  BitPat(111100000000?????000?????1010011) -> BitPat(110000010??01????????0?????00010000000000)
  BitPat(110100000000?????????????1010011) -> BitPat(110000010??01????????0?????00010000000000)
  BitPat(110100000001?????????????1010011) -> BitPat(110000010??01????????0?????00010000000000)
  BitPat(?????????????????010?????0000111) -> BitPat(1100000101101100101000010000000000)
  BitPat(?????????????????010?????0100111) -> BitPat(1100000101101000101101000000000000)
  BitPat(0001100??????????????????1010011) -> BitPat(110000000????????????0?????11010000000000)
  BitPat(010110000000?????????????1010011) -> BitPat(110000000????????????0?????11010000000000)
  BitPat(0000000??????????001?????0010011) -> BitPat(1000000101101100110?????00000010000000)
  BitPat(0000000??????????101?????0010011) -> BitPat(100000010110110011010?????00000010000000)
  BitPat(0100000??????????101?????0010011) -> BitPat(1000000101101100110110?????00000010000000)
  BitPat(0001001??????????000000001110011) -> BitPat(1000001100001???1011010000000001000000)
  BitPat(00010000001000000000000001110011) -> BitPat(1000000?0????????????0?????00000001000000)
  BitPat(01111011001000000000000001110011) -> BitPat(1000000?0????????????0?????00000001000000)
  BitPat(?????????????????001?????0001111) -> BitPat(100000000????????????0?????00000000001100)
  BitPat(?????????????????001?????1100011) -> BitPat(1001001101001001?110?????00000000000000)
  BitPat(?????????????????000?????1100011) -> BitPat(1001001101001001?100?????00000000000000)
  BitPat(?????????????????100?????1100011) -> BitPat(1001001101001001?11000?????00000000000000)
  BitPat(?????????????????110?????1100011) -> BitPat(1001001101001001?11100?????00000000000000)
  BitPat(?????????????????101?????1100011) -> BitPat(1001001101001001?11010?????00000000000000)
  BitPat(?????????????????111?????1100011) -> BitPat(1001001101001001?11110?????00000000000000)
  BitPat(?????????????????????????1101111) -> BitPat(1000100000110011100?????00000010000000)
  BitPat(?????????????????000?????1100111) -> BitPat(1000010101101100100?????00000010000000)
  BitPat(?????????????????????????0010111) -> BitPat(1000000001110010100?????00000010000000)
  BitPat(?????????????????000?????0000011) -> BitPat(1000000101101100101000000010000000)
  BitPat(?????????????????001?????0000011) -> BitPat(1000000101101100101000000010000000)
  BitPat(?????????????????010?????0000011) -> BitPat(1000000101101100101000000010000000)
  BitPat(?????????????????100?????0000011) -> BitPat(1000000101101100101000000010000000)
  BitPat(?????????????????101?????0000011) -> BitPat(1000000101101100101000000010000000)
  BitPat(?????????????????000?????0100011) -> BitPat(1000001101101000101100000000000000)
  BitPat(?????????????????001?????0100011) -> BitPat(1000001101101000101100000000000000)
  BitPat(?????????????????010?????0100011) -> BitPat(1000001101101000101100000000000000)
  BitPat(?????????????????????????0110111) -> BitPat(1000000001100010100?????00000010000000)
  BitPat(?????????????????000?????0010011) -> BitPat(1000000101101100100?????00000010000000)
  BitPat(?????????????????010?????0010011) -> BitPat(1000000101101100111000?????00000010000000)
  BitPat(?????????????????011?????0010011) -> BitPat(1000000101101100111100?????00000010000000)
  BitPat(?????????????????111?????0010011) -> BitPat(100000010110110011110?????00000010000000)
  BitPat(?????????????????110?????0010011) -> BitPat(100000010110110011100?????00000010000000)
  BitPat(?????????????????100?????0010011) -> BitPat(100000010110110011000?????00000010000000)
  BitPat(0000000??????????000?????0110011) -> BitPat(1000001101001???100?????00000010000000)
  BitPat(0100000??????????000?????0110011) -> BitPat(1000001101001???110100?????00000010000000)
  BitPat(0000000??????????010?????0110011) -> BitPat(1000001101001???111000?????00000010000000)
  BitPat(0000000??????????011?????0110011) -> BitPat(1000001101001???111100?????00000010000000)
  BitPat(0000000??????????111?????0110011) -> BitPat(1000001101001???11110?????00000010000000)
  BitPat(0000000??????????110?????0110011) -> BitPat(1000001101001???11100?????00000010000000)
  BitPat(0000000??????????100?????0110011) -> BitPat(1000001101001???11000?????00000010000000)
  BitPat(0000000??????????001?????0110011) -> BitPat(1000001101001???110?????00000010000000)
  BitPat(0000000??????????101?????0110011) -> BitPat(1000001101001???11010?????00000010000000)
  BitPat(0100000??????????101?????0110011) -> BitPat(1000001101001???110110?????00000010000000)
  BitPat(?????????????????000?????0001111) -> BitPat(100000000????????????0?????00000000000100)
  BitPat(00000000000000000000000001110011) -> BitPat(1000000?0????????????0?????00000001000000)
  BitPat(00000000000100000000000001110011) -> BitPat(1000000?0????????????0?????00000001000000)
  BitPat(00110000001000000000000001110011) -> BitPat(1000000?0????????????0?????00000001000000)
  BitPat(00010000010100000000000001110011) -> BitPat(1000000?0????????????0?????00000001000000)
  BitPat(00110000010100000000000001110011) -> BitPat(1000000?0????????????0?????00000001000000)
  BitPat(?????????????????001?????1110011) -> BitPat(1000000100001???100?????00000011010000)
  BitPat(?????????????????010?????1110011) -> BitPat(1000000100001???100?????00000011100000)
  BitPat(?????????????????011?????1110011) -> BitPat(1000000100001???100?????00000011110000)
  BitPat(?????????????????101?????1110011) -> BitPat(1000000001100101100?????00000011010000)
  BitPat(?????????????????110?????1110011) -> BitPat(1000000001100101100?????00000011100000)
  BitPat(?????????????????111?????1110011) -> BitPat(1000000001100101100?????00000011110000)

The Rocket Decoder do have different output width...
However that should be impossible...

When using new API, io.rw.addr << 20 would not match any entry in
decode_table.

e.g. When io.rw.addr[11:0] == "h102", after left shift 20 it would
become "h10200000", which wont match SRET ("h10200073") as defined
in Instructions.scala. Note, SRET is not defined with DontCare.

Magically, old API can work with this case, which should not.

In this fix the least significant 20 bits of decode_table keys
are dropped to match addr.
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 21, 2022

CLA Signed

The committers are authorized under a signed CLA.

@sequencer
Copy link
Member Author

ae002f5 fixed a legacy bug from original QMC decoder in RocketChip. Thanks debugging by @ZenithalHourlyRate

@sequencer
Copy link
Member Author

@jackkoenig Ask for merge.

@sequencer
Copy link
Member Author

It works with 3.5.1 now. After review, I'll rebase it.

Copy link
Contributor

@jackkoenig jackkoenig left a comment

Choose a reason for hiding this comment

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

Speaking with rocket-chip folks, it would be better to not need the explicit widths, let's get 3.5.2 released and bump to that which will make this work better.

This involves ensuring all BitPats that correspond to a particular
portion of the decoded result are of the same width. BitPats with no
"don't cares" can be zero padded to the common width. BitPats with "don't
cares" that are too small are an error.
@jackkoenig
Copy link
Contributor

jackkoenig commented May 16, 2022

@sequencer I've pushed some substantial changes that remove the need for any explicit widths. Now DecodeLogic is safe to differing widths from the BitPats (and will zero pad them so long as they have no don't cares). Since I've now contributed substantially to this, I'm going to dismiss my review and request review from @aswaterman

@jackkoenig jackkoenig dismissed their stale review May 16, 2022 22:24

I am now a contributor to this PR

@jackkoenig jackkoenig requested a review from aswaterman May 16, 2022 22:24
@chipsalliance chipsalliance deleted a comment from jackkoenig May 16, 2022
@michael-etzkorn
Copy link
Contributor

michael-etzkorn commented May 16, 2022

Ignore my review / deleted comments, the build.sbt commit changes aren't relevant to the overall PR

@jackkoenig
Copy link
Contributor

For posterity who may hit the requirement about a BitPat having don't cares and needing padding, see #2949 for an example of the general approach.

aswaterman
aswaterman previously approved these changes May 17, 2022
Copy link
Member

@aswaterman aswaterman left a comment

Choose a reason for hiding this comment

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

Ship it!

@sequencer
Copy link
Member Author

opps, I doubt this may blames to CSR addresses decoding.

@jackkoenig
Copy link
Contributor

opps, I doubt this may blames to CSR addresses decoding.

@sequencer I've restored one of your changes to the CSR in f2cbe12, do you think this is the issue?

@sequencer
Copy link
Member Author

sequencer commented May 17, 2022

Yes, I have been thinking, I thought it used to be a bug, but I can't understand, why it worked before...

@sequencer
Copy link
Member Author

I just greped code usage from public dependencies(UCB/SiFive/Xiangshan): I think only CSR need to be tweaked.
But I think this need more carefully debugging to figure the reason, in case of any subtle bugs.

@jackkoenig jackkoenig dismissed aswaterman’s stale review May 17, 2022 17:56

in light of possible bug with CSR decoding

@sequencer
Copy link
Member Author

In chipsalliance/chisel#2387, I pad 0 to LHS, since I think it is intuitive.
In

cache.getOrElseUpdate(t, (if (t.mask == 0) addr else addr & Bits(BigInt(2).pow(addrWidth)-(t.mask+1), addrWidth)) === Bits(t.value, addrWidth))

It seems to pad RHS?

Copy link
Member

@aswaterman aswaterman left a comment

Choose a reason for hiding this comment

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

This is fine with me. I was relying on QM doing the optimal thing (there should be no dependence on input bits 19..0 in an optimized circuit).

@jackkoenig jackkoenig enabled auto-merge (squash) May 17, 2022 19:20
@jackkoenig jackkoenig merged commit e8b8efd into master May 17, 2022
@jackkoenig jackkoenig deleted the chisel_decoder branch May 17, 2022 19:27
aswaterman added a commit that referenced this pull request Jun 4, 2022
Partially reverts #2836, but in such a way that it works with the new QMC.
aswaterman added a commit that referenced this pull request Jun 4, 2022
Partially reverts #2836, but in such a way that it works with the new QMC.
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