Neat visualization of improved synthesis

117 views
Skip to first unread message

Øyvind Harboe

unread,
Mar 27, 2020, 3:04:20 AM3/27/20
to chisel-users
There's no question here... just some sharing...

I hear a lot that Chisel has too high a level of abstraction and doesn't allow precise control of synthesis. This complaint reminds me of the game Doom in the '90s.  It was the first game that blew the idea that you could only write state of the art games in machine code and that C was too abstract. Doom had two machine code loops and the rest was in C.

I implemented a left rotate by n * 8 bits, a tiny simple module. No clock, just combinatorial. The guts of the module is below. The trick here is that a normal shift shifts by n bits and I need to rotate by n * 8 bits.

The RTL generated was initially(visualized by Quartus):



With a bit of rewriting of the Chisel, I ended got the below. Synthesis now "gets" that I'm trying to do a rotate left.



Finally, cleaned up a bit: 



It takes a bit of practice to read the below, but my colleague who doesn't know Chisel or FPGAs, but is quite adept at Haskell could read the code below without explanation.

To someone well versed in Verilog only, the code below is humiliating. Especially considering that when it comes to quality of synthesis, it's the end of the line...


io.result := VecInit(
leftRotateValue
.map(_.asBools)
.transpose
.map(VecInit(_).asUInt)
.map(
value =>
((value | (value << (resultWidth / symbolSize))) << io.leftRotate)(
2 * resultWidth / symbolSize - 1,
resultWidth / symbolSize
)
)
.map(_.asBools)
.transpose
.map(VecInit(_).asUInt)
).asUInt

Jack Koenig

unread,
Mar 27, 2020, 1:35:48 PM3/27/20
to chisel...@googlegroups.com
This is really cool Øyvind.

I think it's really useful to have this kind of stuff on the mailing list. In particular, I think it helps newer users real examples of the power of the approach.

Thanks for sharing!

--
You received this message because you are subscribed to the Google Groups "chisel-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chisel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chisel-users/aa7fd693-55d1-4b37-9641-d9c1b62118a0%40googlegroups.com.

Øyvind Harboe

unread,
Mar 27, 2020, 2:26:34 PM3/27/20
to chisel-users
Thanks!

I try to write to mailing lists with a thought to that Google will be indexing the content. This as a way to pay back for all the useful information I find when googling myself....

Claford Lawrence

unread,
Apr 2, 2020, 10:32:17 PM4/2/20
to chisel-users
This is really cool. Is there any chance you can elaborate on how you tuned your code into the final state? That would be really great! 

Øyvind Harboe

unread,
Apr 3, 2020, 1:23:27 AM4/3/20
to chisel-users

It takes a bit of practice to read the below, but my colleague who doesn't know Chisel or FPGAs, but is quite adept at Haskell could read the code below without explanation.

To someone well versed in Verilog only, the code below is humiliating. Especially considering that when it comes to quality of synthesis, it's the end of the line...


io.result := VecInit(
leftRotateValue
.map(_.asBools)
.transpose
.map(VecInit(_).asUInt)
.map(
value =>
((value | (value << (resultWidth / symbolSize))) << io.leftRotate)(
2 * resultWidth / symbolSize - 1,
resultWidth / symbolSize
)
)
.map(_.asBools)
.transpose
.map(VecInit(_).asUInt)
).asUInt
This is really cool. Is there any chance you can elaborate on how you tuned your code into the final state? That would be really great! 


The "how" was that I used the Intel Quartus TimeQuest tool to find the critical timing path in my design. It takes a lot of practice to read those tea-leaves... In my case, the path that failed timing was not the problem, the problem was the rotate mess that "used up" all the good placement and resources, so that something else didn't fit.

I wandered around the design looking in Intel Quartus RTL Viewer and I had a huch that this rotate was a problem and it was.

In custom silicon, this sort of rotate is a well studied problem. If this was in the critical path of a custom silicon design, I would expect it to be a black box(using pass transistors and whatnot to implement a barrel rotate).

However, as I'm currently targeting an FPGA, I had to think about what sort of resouces the FPGA had and how I could rewrite the problem into the resources that the FPGA has.

I want to rotate left by 8 bits at the time (one byte), but FPGA synthesis doesn't have that sort of resource. What it does have is a regular left shift where all the bits are contiguous.

If I have some bits I want to rotate in steps of 4, then I do as follows:

Below I label 16 bits using 0-f as an UInt.

fedcba9876543210

Transform to a vector of bits, rewrite bits to groups of 4 (least significant bit first):

leftRotateValue = io.value.asTypeOf(Vec(valueWidth / symbolSize, UInt(symbolSize.W)))


3210
7654
ba98
fedc

Now transpose:

37bf
26ae
159d
048c

Convert the vector of bits to an UInt:

048c159d26ae37bf

Left rotate one bit:

f048c159d26ae37b

Convert back to vector of groups of 4:

e37b
d26a
c159
f048

Transpose again:

edcf
3210
7654
ba98

Convert from sequence of bits back to UInt, voila! Rotated left by:

ba9876543210edcf


Functional programming shines w.r.t. expressiveness for these sort of transformations...


Claford Lawrence

unread,
Apr 4, 2020, 11:35:09 AM4/4/20
to chisel-users
Wow, that is an excellent piece of writeup! Thanks for directing me ( and possibly others ) on an efficient track! 

Øyvind Harboe

unread,
Apr 4, 2020, 1:00:22 PM4/4/20
to chisel-users
Glad you like it.

I wonder how someone might come across this information though :-)

Erling Jellum

unread,
Apr 4, 2020, 2:01:56 PM4/4/20
to chisel...@googlegroups.com
I have bookmarked it for later study. I think you should consider writing a Chisel blog? I think it would be greatly appreciated and would get alot of interest.

--
Erling Rennemo Jellum

P: +47 465 15 653



--
You received this message because you are subscribed to the Google Groups "chisel-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chisel-users...@googlegroups.com.

Øyvind Harboe

unread,
Apr 4, 2020, 2:10:39 PM4/4/20
to chisel...@googlegroups.com
Where? I'm not on Facebook, I'm waiting for that fad to blow over :-)

You received this message because you are subscribed to a topic in the Google Groups "chisel-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/chisel-users/eZy2zQyvojE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to chisel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chisel-users/CA%2BViiWd_nJ8dm4x5twtMe_gr26raZA1nJN0J%3D_Gzz6YS3YSCxg%40mail.gmail.com.


--
Øyvind Harboe
+4791786146

Kevin Laeufer

unread,
Apr 4, 2020, 2:13:15 PM4/4/20
to chisel...@googlegroups.com, Schuyler Eldridge
If you write a blog post the Chisel twitter account could promote it
(Schuyler is running that account).

On 04/04/2020 11:10, Øyvind Harboe wrote:
> Where? I'm not on Facebook, I'm waiting for that fad to blow over :-)
>
> On Sat, Apr 4, 2020 at 8:01 PM Erling Jellum <erling...@gmail.com
> <mailto:erling...@gmail.com>> wrote:
>
> I have bookmarked it for later study. I think you should consider
> writing a Chisel blog? I think it would be greatly appreciated and
> would get alot of interest.
>
> --
> Erling Rennemo Jellum
> E: erling...@gmail.com <mailto:erling...@gmail.com>
> P: +47 465 15 653
>
>
>
> lør. 4. apr. 2020 kl. 19:00 skrev Øyvind Harboe
> <oyvind...@gmail.com <mailto:oyvind...@gmail.com>>:
> <mailto:chisel-users...@googlegroups.com>.
> <https://groups.google.com/d/msgid/chisel-users/d23cca23-c47e-4522-bc96-9e61c8c7f95d%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "chisel-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/chisel-users/eZy2zQyvojE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> chisel-users...@googlegroups.com
> <mailto:chisel-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/chisel-users/CA%2BViiWd_nJ8dm4x5twtMe_gr26raZA1nJN0J%3D_Gzz6YS3YSCxg%40mail.gmail.com
> <https://groups.google.com/d/msgid/chisel-users/CA%2BViiWd_nJ8dm4x5twtMe_gr26raZA1nJN0J%3D_Gzz6YS3YSCxg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
>
>
> --
> Øyvind Harboe
> +4791786146
>
> --
> You received this message because you are subscribed to the Google
> Groups "chisel-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to chisel-users...@googlegroups.com
> <mailto:chisel-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/chisel-users/CACELUGdjCmg%2BoeRu%3DcsS4p33XT9sVxgpFwe6FFaGhi-oND29xA%40mail.gmail.com
> <https://groups.google.com/d/msgid/chisel-users/CACELUGdjCmg%2BoeRu%3DcsS4p33XT9sVxgpFwe6FFaGhi-oND29xA%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Øyvind Harboe

unread,
Apr 4, 2020, 2:15:53 PM4/4/20
to chisel...@googlegroups.com, Schuyler Eldridge
Thanks... I still need to figure out where to write a blog post. LinkedIn doesn't seem like the right place...

To unsubscribe from this group and all its topics, send an email to chisel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chisel-users/98b576f8-fe65-e332-e050-27cb74f4051c%40berkeley.edu.


--
Øyvind Harboe
+4791786146

Kevin Laeufer

unread,
Apr 4, 2020, 2:17:03 PM4/4/20
to chisel...@googlegroups.com
Currently github pages seem to be a thing people to use:
https://pages.github.com/

On 04/04/2020 11:15, Øyvind Harboe wrote:
> Thanks... I still need to figure out where to write a blog post.
> LinkedIn doesn't seem like the right place...
>
> On Sat, Apr 4, 2020 at 8:13 PM Kevin Laeufer <lae...@berkeley.edu
> <mailto:lae...@berkeley.edu>> wrote:
>
> If you write a blog post the Chisel twitter account could promote it
> (Schuyler is running that account).
>
> On 04/04/2020 11:10, Øyvind Harboe wrote:
> > Where? I'm not on Facebook, I'm waiting for that fad to blow over :-)
> >
> > On Sat, Apr 4, 2020 at 8:01 PM Erling Jellum
> <erling...@gmail.com <mailto:erling...@gmail.com>
> > <mailto:erling...@gmail.com <mailto:erling...@gmail.com>>>
> wrote:
> >
> >     I have bookmarked it for later study. I think you should consider
> >     writing a Chisel blog? I think it would be greatly appreciated and
> >     would get alot of interest.
> >
> >     --
> >     Erling Rennemo Jellum
> >     E: erling...@gmail.com <mailto:erling...@gmail.com>
> <mailto:erling...@gmail.com <mailto:erling...@gmail.com>>
> >     P: +47 465 15 653
> >
> >
> >
> >     lør. 4. apr. 2020 kl. 19:00 skrev Øyvind Harboe
> >     <oyvind...@gmail.com <mailto:oyvind...@gmail.com>
> <mailto:oyvind...@gmail.com <mailto:oyvind...@gmail.com>>>:
> <mailto:chisel-users%2Bunsu...@googlegroups.com>
> >         <mailto:chisel-users...@googlegroups.com
> <mailto:chisel-users%2Bunsu...@googlegroups.com>>.
> >         To view this discussion on the web visit
> >       
>  https://groups.google.com/d/msgid/chisel-users/d23cca23-c47e-4522-bc96-9e61c8c7f95d%40googlegroups.com
> >       
>  <https://groups.google.com/d/msgid/chisel-users/d23cca23-c47e-4522-bc96-9e61c8c7f95d%40googlegroups.com?utm_medium=email&utm_source=footer>.
> >
> >     --
> >     You received this message because you are subscribed to a topic in
> >     the Google Groups "chisel-users" group.
> >     To unsubscribe from this topic, visit
> >   
>  https://groups.google.com/d/topic/chisel-users/eZy2zQyvojE/unsubscribe.
> >     To unsubscribe from this group and all its topics, send an
> email to
> >     chisel-users...@googlegroups.com
> <mailto:chisel-users%2Bunsu...@googlegroups.com>
> >     <mailto:chisel-users...@googlegroups.com
> <mailto:chisel-users%2Bunsu...@googlegroups.com>>.
> >     To view this discussion on the web visit
> >   
>  https://groups.google.com/d/msgid/chisel-users/CA%2BViiWd_nJ8dm4x5twtMe_gr26raZA1nJN0J%3D_Gzz6YS3YSCxg%40mail.gmail.com
> >   
>  <https://groups.google.com/d/msgid/chisel-users/CA%2BViiWd_nJ8dm4x5twtMe_gr26raZA1nJN0J%3D_Gzz6YS3YSCxg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> >
> >
> >
> > --
> > Øyvind Harboe
> > +4791786146
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "chisel-users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> > an email to chisel-users...@googlegroups.com
> <mailto:chisel-users%2Bunsu...@googlegroups.com>
> > <mailto:chisel-users...@googlegroups.com
> <mailto:chisel-users%2Bunsu...@googlegroups.com>>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/chisel-users/CACELUGdjCmg%2BoeRu%3DcsS4p33XT9sVxgpFwe6FFaGhi-oND29xA%40mail.gmail.com
> >
> <https://groups.google.com/d/msgid/chisel-users/CACELUGdjCmg%2BoeRu%3DcsS4p33XT9sVxgpFwe6FFaGhi-oND29xA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "chisel-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/chisel-users/eZy2zQyvojE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> chisel-users...@googlegroups.com
> <mailto:chisel-users%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> --
> You received this message because you are subscribed to the Google
> Groups "chisel-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to chisel-users...@googlegroups.com
> <mailto:chisel-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/chisel-users/CACELUGfGh%3DqwyPr09Rcohj9vMtjbjG_mH11aY8MW76OYCv%3DtgA%40mail.gmail.com
> <https://groups.google.com/d/msgid/chisel-users/CACELUGfGh%3DqwyPr09Rcohj9vMtjbjG_mH11aY8MW76OYCv%3DtgA%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Øyvind Harboe

unread,
Apr 4, 2020, 2:21:14 PM4/4/20
to chisel...@googlegroups.com
Seems appropriate and in the Zeitgeist... I need to read up on it.

I was the only user left using Google+ (a Facebook competitor) before they shut it down, posting mainly skiing pictures. There was no spam on Google+, not much else to speak of either. :-)

To unsubscribe from this group and all its topics, send an email to chisel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chisel-users/e4e4b772-6030-006f-fad4-d8bad8bc4429%40berkeley.edu.


--
Øyvind Harboe
+4791786146
Reply all
Reply to author
Forward
0 new messages