chiselv icon indicating copy to clipboard operation
chiselv copied to clipboard

chisel decoder.

Open sequencer opened this issue 3 years ago • 10 comments

switch to decoder, recode InstructionType uop to OneHot, improve dispatch timing by removing useless Mux. (just a prototype, not guarantee the correctness ;p)

sequencer avatar Nov 24 '21 01:11 sequencer

I tried it out but got the error:

[info] - should Decode an ADD instruction (type R) *** FAILED ***
[info]   java.util.NoSuchElementException: None.get
[info]   at ... ()
[info]   at chiselv.Decoder.$anonfun$signals$2(Decoder.scala:46)
[info]   at chisel3.internal.prefix$.apply(prefix.scala:49)
[info]   at chiselv.Decoder.$anonfun$signals$1(Decoder.scala:108)
[info]   at chisel3.internal.plugin.package$.autoNameRecursively(package.scala:33)
[info]   at chiselv.Decoder.<init>(Decoder.scala:38)
[info]   at chiselv.DecoderSpec.$anonfun$new$2(DecoderSpec.scala:15)
[info]   at ... ()
[info]   at ... (Stack trace trimmed to user code only. Rerun with --full-stacktrace to see the full stack trace)
[info]   ...

Any idea what cou be wrong?

carlosedp avatar Nov 25 '21 00:11 carlosedp

I tried it out but got the error:

[info] - should Decode an ADD instruction (type R) *** FAILED ***
[info]   java.util.NoSuchElementException: None.get
[info]   at ... ()
[info]   at chiselv.Decoder.$anonfun$signals$2(Decoder.scala:46)
[info]   at chisel3.internal.prefix$.apply(prefix.scala:49)
[info]   at chiselv.Decoder.$anonfun$signals$1(Decoder.scala:108)
[info]   at chisel3.internal.plugin.package$.autoNameRecursively(package.scala:33)
[info]   at chiselv.Decoder.<init>(Decoder.scala:38)
[info]   at chiselv.DecoderSpec.$anonfun$new$2(DecoderSpec.scala:15)
[info]   at ... ()
[info]   at ... (Stack trace trimmed to user code only. Rerun with --full-stacktrace to see the full stack trace)
[info]   ...

Any idea what cou be wrong?

This is a strange bug: https://github.com/chipsalliance/chisel3/issues/2268 I will try to fix this in Chisel

sequencer avatar Nov 30 '21 15:11 sequencer

Hey @sequencer ... just a reminder to catch-up on this whenever we can :) Would be awesome then to have it as a recipe in the Chisel cookbook :)

carlosedp avatar Dec 28 '21 19:12 carlosedp

Sorry for the delay again! I did some fix ups, but seems there is a bug in your decode table which was figured by Decoder.

sequencer avatar Jan 03 '22 17:01 sequencer

Hey Jiuyang, I've rebased and fixed my decode pattern but now I'm getting:

[info] - should Decode an ADD instruction (type R) *** FAILED ***
[info]   chisel3.internal.ChiselException: Connection between sink (Decoder.io.DecoderPort.inst: IO[Instruction]) and source (Decoder.signals.inst: Wire[UInt<6>]) failed @: Sink (Instruction) and Source (UInt<6>) have different types.
[info]   at ... ()
[info]   at chiselv.Decoder.<init>(Decoder.scala:127)
[info]   at chiselv.DecoderSpec.$anonfun$new$2(DecoderSpec.scala:15)
[info]   at ... ()
[info]   at ... (Stack trace trimmed to user code only. Rerun with --full-stacktrace to see the full stack trace)
[info]   ...

I expect the Instruction type in the output but currently it's a UInt.

Also I'm seeing lots of debug messages looking for "espresso" in my path.

carlosedp avatar Jan 03 '22 19:01 carlosedp

I expect the Instruction type in the output but currently it's a UInt.

Just cast it(I know it's dirty, we should have a better name in the future)

Also I'm seeing lots of debug messages looking for "espresso" in my path.

It's available from https://github.com/chipsalliance/espresso

sequencer avatar Jan 03 '22 19:01 sequencer

Thanks Jiuyang! It worked perfectly :D

I've cast like: io.DecoderPort.inst := signals.inst.asTypeOf(new Instruction.Type)

But I'm getting:

[warn] Decoder.scala:127: Casting non-literal UInt to chiselv.Instruction. You can use chiselv.Instruction.safe to cast without this warning. in class chiselv.Decoder

What's the right way to do without the warning?

Other than that... I think we need some nicer way to avoid all casts and etc... :) It's a kinda complex and hard to remember pattern :)

carlosedp avatar Jan 03 '22 22:01 carlosedp

This is pretty neat, as an example I synthesized for ECP5 FPGA:

Without decoder (switch/is and MuxLookup)

Info: Device utilisation:
Info: 	       TRELLIS_SLICE:  3939/41820     9%
Info: 	          TRELLIS_IO:    13/  365     3%
Info: Max frequency for clock '$glbnet$SOC_clock': 16.02 MHz (PASS at 9.00 MHz)

With decoder/mux1H:

Info: 	       TRELLIS_SLICE:  3684/41820     8%
Info: 	          TRELLIS_IO:    13/  365     3%
Info: Max frequency for clock '$glbnet$SOC_clock': 19.43 MHz (PASS at 9.00 MHz)

Saved about 300 LEs and gained about 3.5Mhz!

carlosedp avatar Jan 03 '22 22:01 carlosedp

Would you mind benchmark QMC vs espresso. I'm also curious to this. I thought PPA of QMC should be better, while slower than espresso. But for this case, I think it will as fast as espresso.

sequencer avatar Jan 04 '22 05:01 sequencer

You mean by having espresso or not right? In terms of execution time for my core, the difference is not noticeable... all runs around 32-38 seconds... there is a difference tho in synthesis... without using the espresso compiler I get:

Info: Device utilisation:
Info: 	       TRELLIS_SLICE:  3762/41820     8%
Info: 	          TRELLIS_IO:    13/  365     3%

Info: Max frequency for clock '$glbnet$SOC_clock': 20.34 MHz (PASS at 9.00 MHz)

A bit more LEs but faster clock.

carlosedp avatar Jan 04 '22 13:01 carlosedp