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 decodeAs API to output decoded signals directly to a Bundle #2328

Closed
wants to merge 3 commits into from

Conversation

carlosedp
Copy link
Contributor

@carlosedp carlosedp commented Jan 6, 2022

Contributor Checklist

  • Did you add Scaladoc to every public function/method?
  • Did you add at least one test demonstrating the PR?
  • Did you delete any extraneous printlns/debugging code?
  • Did you specify the type of improvement?
  • Did you add appropriate documentation in docs/src?
  • Did you state the API impact?
  • Did you specify the code generation impact?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • new feature/API

API Impact

This PR adds a new decodeAs function to decoder allowing the signal decode output to go directly to a Bundle.

Backend Code Generation Impact

No Verilog output impact.

Desired Merge Strategy

  • Squash: The PR will be squashed and merged (choose this if you have no preference.

Release Notes

Added a new decodeAs function to decoder allowing the signal decode output to go directly to a Bundle.

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels?
  • Did you mark the proper milestone (Bug fix: 3.3.x, [small] API extension: 3.4.x, API modification or big change: 3.5.0)?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you mark as Please Merge?

@carlosedp carlosedp changed the title Add decodeAs API to output decoded signals directly to a Bundle Add decodeAs API to output decoded signals directly to a Bundle Jan 6, 2022
@carlosedp carlosedp mentioned this pull request Jan 6, 2022
14 tasks
@ekiwi
Copy link
Contributor

ekiwi commented Jan 6, 2022

Thanks carlos! Could you add a example/test please?

@carlosedp
Copy link
Contributor Author

carlosedp commented Jan 6, 2022

Sure, will add to the PR and below:

  class DecType extends Bundle {
    val inst_type = UInt(InstructionType.getWidth.W)
    val inst      = UInt(Instruction.getWidth.W)
    val to_alu    = Bool()
    val branch    = Bool()
    val use_imm   = Bool()
    val jump      = Bool()
    val is_load   = Bool()
    val is_store  = Bool()
  }
  val signals = decode.decodeAs(
    (new DecType),
    io.DecoderPort.op,
    decode.TruthTable(
        // format: off
        Array(
        /*                                                inst_type,   ##    inst        ##  to_alu    ##  branch    ##  use_imm   ##   jump     ##  is_load   ## is_store */
        // Arithmetic
        BitPat("b0000000??????????000?????0110011")  -> BitPat(INST_R) ## BitPat(ADD)    ## BitPat.Y() ## BitPat.N() ## BitPat.N() ## BitPat.N() ## BitPat.N() ## BitPat.N(),
        BitPat("b?????????????????000?????0010011")  -> BitPat(INST_I) ## BitPat(ADDI)   ## BitPat.Y() ## BitPat.N() ## BitPat.Y() ## BitPat.N() ## BitPat.N() ## BitPat.N(),
      ),                                                BitPat(IN_ERR) ## BitPat(ERR)    ## BitPat.dontCare(6) // Default values
      // format: on
    )
  )

@ekiwi so per your comment on the other PR, having (new DecType) is the correct way right?

@carlosedp
Copy link
Contributor Author

I'm trying to write a test case but it complains it's not in a Builder context:

class DecoderSpec extends AnyFlatSpec {
  "decoder" should "decodeAs to an existing bundle" in {
    class OutputBundle extends Bundle {
      val s1 = UInt(2.W)
      val s2 = UInt(2.W)
      val s3 = Bool()
    }
    val selector = "b001".U
    val signals = decodeAs(
      (new OutputBundle),
      selector,
      TruthTable(
        Array(
        BitPat("b001")  -> BitPat(1.U(2.W)) ## BitPat(1.U(2.W))   ## BitPat.Y(),
        BitPat("b?11")  -> BitPat(2.U(2.W)) ## BitPat(2.U(2.W))   ## BitPat.N(),
        ),                 BitPat(0.U(2.W)) ## BitPat(0.U(2.W))   ## BitPat.dontCare(1) // Default values
      )
    )

    assert(signals.s1 === true)
    assert(signals.s2 === true)
    assert(signals.s3 === true)
  }
}

Cc. @sequencer

@ekiwi
Copy link
Contributor

ekiwi commented Jan 6, 2022

I'm trying to write a test case but it complains it's not in a Builder context:

You need to put your code into a chisel Module. Unfortunately most chisel constructs are only supported in that context.

@carlosedp
Copy link
Contributor Author

Added a test spec for it!

@carlosedp
Copy link
Contributor Author

In cases where my Bundle has Enums, I'm getting a cast warning like Decoder.scala:44: Casting non-literal UInt to chiselv.Instruction. You can use chiselv.Instruction.safe to cast without this warning. in class chiselv.Decoder.

I believe in the return of decodeAs, I might need to go thru each element and if it's an Enum, I need to Type.safe it.
Right?

My Bundle:

  class DecType extends Bundle {
    val inst_type = InstructionType()
    val inst      = Instruction()
    val to_alu   = Bool()
    val branch   = Bool()
    val use_imm  = Bool()
    val jump     = Bool()
    val is_load  = Bool()
    val is_store = Bool()
  }

Where inst and inst_type are ChiselEnum and ChiselEnum1H.

@sequencer
Copy link
Member

I'd like to have provide a BundleLit API for this usage. Working on a small example.

@carlosedp
Copy link
Contributor Author

I think this is the last missing piece to have a nice API for decode (1H enum + Mux1H + decodeAs + Bitpat accepting enums) :)

@sequencer
Copy link
Member

sequencer commented Jan 10, 2022

I agree, Mux1H taking enum is a necessary feature that we have benign missing.
As for decodeAs or similar API, I'd like have a API like this:

                                                    instr, term, default
def decode[T <: Data](input: UInt, truthTable: (Seq[(BitPat, T)], T)): T

However the BundleLiterals doesn't support BitPat(since it is not a Data).
I'm trying to give a simple work around.

@sequencer
Copy link
Member

Happy new year, and hopefully resolved in #2924

@sequencer sequencer closed this Jan 10, 2023
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.

3 participants