Is XC a realistic choice for real world applications?

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
russf
XCore Addict
Posts: 146
Joined: Thu Dec 10, 2009 10:17 pm

Post by russf »

Just a brief comment to Folknology's point re Network stack as a tough example.

I've had some experience inside router code at big-name networking companies, trying to get high value out if cheap silicon. I have also done a lot with CSP approaches in different areas. I once combined the networking and CSP interested while worked on a 15 port Transputer-based Ethernet switch (10-Mbps- tells you how long ago).

Programming protocols is tricky in a CSP world. Usually moving data is the most expensive operation in a router. Once data has arrived in a buffer, typically it is interpreted by basing structures at certain offsets, reading those structures, and reacting. Sometimes several structures may be overlayed on a sequence of bytes as you move up the protocol layers, and back down again. Usually the payload data in the buffer has new top and tail added to it, and is then queued to send. Typically there would be hardware acceleration for moving data in and out. The payload is rarely copied.

Typically, in C, a control block would be created to describe an incoming packet, and added to a list of threads waiting to run. A dispatcher unlinks the control block, calls protocol layer processing passing the control block, and the control block may be requeued for further processing.

I have never seen a modular and realistic approach that is as efficient, using a CSP model.

BTW, as you can imagine, debugging this traditional approach is not easy, but in the end, in my experience, the emphasis on cleanly layered code fades fast in the face of reality.

I'm very interested to see how this discussion develops.


User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

I would also like to emphasise how important that this issue is, particularly with respect to the network stack. For me personally it represents whether or not I can build Amino on the Xmos platform, it is critical and core to its success. Sure I could just drop this and put Amino on another platform (I already have such a non Xmos fallback plan and architecture), but that wouldn't just mean compromise, it would also represent a loss of 18 months work invested into Xmos. Moreover I am tenacious son of a bitch and am unlikely to take this lying down I will pursue it to its natural conclusion before giving up my dreams of seeing Amino on Xmos.

regards
Al
User avatar
lilltroll
XCore Expert
Posts: 956
Joined: Fri Dec 11, 2009 3:53 am
Location: Sweden, Eskilstuna

Post by lilltroll »

You wan-to see if I understand what a "slice" is ; using MATLAB syntax here:

If A is a 1D vector with 10 elements with the values 0, 10 ,20 ... 90

Code: Select all

>> A=0:10:90

A =

     0    10    20    30    40    50    60    70    80    90

>> 
It would be beneficial to be able to access a portion of that vector without memcopy direct in XC, and the MATLAB syntax would be:

Code: Select all

>> A(3:7)

ans =

    20    30    40    50    60

Probably not the most confused programmer anymore on the XCORE forum.
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

Yes, that's what we're talking about.

If you have an array a[] of n elements, you can take a slice starting at offset b
of length n2, if and only if b < n and b+n2 < n (all numbers unsigned).
(This is not the same as just b+n2 < n since the addition can wrap!)
User avatar
lilltroll
XCore Expert
Posts: 956
Joined: Fri Dec 11, 2009 3:53 am
Location: Sweden, Eskilstuna

Post by lilltroll »

And the computational benefit is that you will use the stack less when calling a method in XC with several parameters??

Code: Select all

void calcvec(int A[],unsigned start,unsigned stop, {next parameter}...)
{

}

int main(){
int A[10];
calcvec(A,start,stop, {next parameter}...);
and use something like this instead ?

Code: Select all

void calcvec(int A[{slice}], {next parameter})
{
}

int main(){
int A[10];
calcvec(A(start:stop), {next parameter});
Probably not the most confused programmer anymore on the XCORE forum.
MuellerNick
Member++
Posts: 31
Joined: Fri Dec 11, 2009 9:33 am

Post by MuellerNick »

calcvec(A,start,stop, {next parameter}...);
calcvect(&A[start], numberOfElements, ...) would do it.
Just because you type less, doesn't mean the compiler generates less code.


Nick
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

The compiler already passes the number of elements for every array.

Slices are useful for when you parse text, or packets, or similar; it is
awkward to pass around the full buffer (and its length) and separate
start and end indices.