Mill Computing, Inc. Forums The Mill Architecture switches Reply To: switches

goldbug
Participant
Post count: 52

That is cool that you can use the pick results in the calltr. In the documentation it sounds like the pick phase is after the call phase so I was not sure.

The chain of less than is a great approach if you have a bunch of returns or branches, but it is not great when you have a bunch of calls. Consider this example:


int foo(int x)
{
   switch(x) {
      case 0:
      case 1:
      case 2:
         return bar();
      case 3:
      case 4:
      case 5:
         return baz();
      default:
         return 0;
   }
}

Since calls don’t stop execution, if you try to do a chain of lsss, you will end up calling bar multiple times. You can do this in one instruction if you checked ranges instead. Like this:

F("foo") %0;
    rd     (w(0ul))     %1,
    geqs   (%0, 0)      %2,
    leqs   (%0, 2)      %3,
    leqs   (%0, 5)      %4,
    pick   (%2, %3, %1) %5,    // range check x>=0 && x <= 2
    pick   (%3, %1, %4) %6,    // range check !(x<=2) && x <= 5   same as  x>=3 && x <=5
    calltr1 (%5, "bar") %7,    // call function only if in range a simple lsss would not be enough
    calltr1 (%6, "baz") %8,    // call function only if in range a simple lsss would not be enough
    retntr (%5, %7),
    retntr (%6, %8),
    retn (%1);

I would think that switching function calls is common, perhaps not with ranges though, so maybe I am overthinking it.