Skip to content

Building an efficient router in core

March 6, 2012
tags:

Building a 1->M Router in core is a relatively simple task, yet one that I see implemented in a rather inefficient manner on a regular basis. Today I’ll go over a few simple designs and explain their strengths and  weaknesses. When I first started working in core I built a router that looked like this:

Inefficient router

The P input controls the position, and the Clk input is the signal to be routed. For pretty much any purpose I can think of, this is the worst possible router in core. If you look at the diagram you can see that for every new value at input Clk, the input is sent thru 8 if-then statements, every single time, no matter what. Thankfully, there is a very simple way to make this more efficient, and it looks like this:

Slightly better...

This method cuts out any unnecessary if-then statements from the previous example. In some cases this is the best router to use (mainly when P is usually equal to 0, since only one if-then statement is evaluated in this case).  I use a router like this in Optimus Prime to control which effects are active – since P = 0 whenever the user is not pressing buttons, it’s a very good choice to use. There is a problem with this router though – as the value of P increases, it becomes less and less efficient, and at P = 7, it is no more efficient than the first router. Also, if you want a large number of outputs (say, 32) there will be a very noticeable difference in CPU when P = 32 than when P = 0. In other words, this design does not scale well.

Fortunately there is another way which solves the problems with the second example. It looks like this:

Tree Router

This is called a tree router and it is extremely efficient and scales very well. If you path the chart of the In signal for any P value, you’ll see that there are never more (or less) than 3 if-then statements performed, regardless of the value of P. On top of this, you can double the amount of outputs at the cost of only one more if-then statement – you can get up to 2^x outputs for each if-then statement. So for the same amount of calculations in the first example (which requires 8 if-then statements) you can get 2^8 = 256 outputs out of a tree router.

Let me know in the comments if you have any questions!

Advertisements
2 Comments leave one →
  1. March 6, 2012 11:26 am

    Thanks, this is a great walkthrough of routing in general, with a handy example to boot!

  2. l_m permalink
    March 6, 2012 11:53 am

    awesomeness, indeed. while not hc dsp or anything, this is a nice and inspiring example of creative technical thinking.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: