"Dynamic select" for interpreter

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
User avatar
Ruben
Member
Posts: 15
Joined: Sun Mar 07, 2010 9:58 pm
Contact:

"Dynamic select" for interpreter

Post by Ruben »

As some of you might already know, I'm working on a Scheme interpreter for XMOS devices.

One of the things I still need to implement is the "select" statement. The problem there is that the exact select statement (number of cases, etc..) is not known at compile time.

So I need to make some "dynamic select". I'm not sure what's the best way to do that properly.
  • Peek seems to be for ports only, so that's a no-go.
  • Make some function containing a select.
    Something like the one below and call it for every case in the (Scheme) select:

    Code: Select all

    int xc_select(chanend c, int value)
    {
      select
      {
         case c :> value:
           return 1;
      }
      return 0;
    }
    
    However, this code does not guarantee the CSP fairness rule :(.

    How does the hardware guarantees the fairness (as I want to stay as close as possible to the HW) and is there some way to use the hardware functionality?
  • Other suggestions are welcome too ;)


User avatar
dave
Member++
Posts: 31
Joined: Thu Dec 10, 2009 10:11 pm
Contact:

Post by dave »

The instruction set of the XCore can implement selects where the number of cases is not known at compile time. There are instructions to initialise the sources (channels, ports or timers) of events, enable and disable events from specific sources, and an instruction to disable all enabled events associated with a thread. These are described in section 16 of the XS1 Architecture manual - especially pages 36, 37 and 38. It should be possible to construct an assembly language procedure that would perform a select on a list of cases.

I'm not sure exactly what semantics you are trying to provide - can you clarify? I may be able to suggest a good way to use the instructions.

Also, CSP (and XC) only guarantee that a select will make progress when at least one of the cases is ready; they do not guarantee fairness. For example, if one of the cases is always ready it is possible that other cases will be ignored indefinitely.
User avatar
Ruben
Member
Posts: 15
Joined: Sun Mar 07, 2010 9:58 pm
Contact:

Post by Ruben »

I'm trying to make something like this (very similar to the scheme "cond"), but providing the functionality of an XC "select":

Code: Select all

(select
  ((pinnotequal pin 2) ....)
  ((timeafter x) ....)
  (else .....)
)
Thanks for the help already, as I'm not really familiar with the XCore instruction set.

I've checked the CSP paper about the fairness and indeed it does not mentions it. It only says that one case is arbitrarily chosen and the implementation should ensure efficient execution etc...
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

You can use a select case replicator to wait for events on an array of resources. For example:

Code: Select all

void f(chanend c[], unsigned size) {
  select {
  case (unsigned i = 0; i < size; i++) c[i] :> int:
    break;
  }
}
You would need a different array and case for each type of resource and each condition. While you might not want to use this directly as you would need to copy resources into arrays you might want to look at the code that is generated by the XC compiler.
Post Reply