I have been working with xc for a while now but due to bugs in the xmos compiler I cannot use a par statement for use inside a stage 2 loader.
It has been suggested that I implement the par statement using inline assembly, but I have never used it before, so can someone please provide an example or point me in the right direction as to where to start with this.
Thanks
Inline Assembly replacement for par
-
- New User
- Posts: 3
- Joined: Tue Jul 08, 2014 6:54 am
-
- XCore Expert
- Posts: 754
- Joined: Thu Dec 10, 2009 6:56 pm
Code: Select all
getr r4, 3 // get a thread synchroniser, store in r4
getst r11, res[r4] // get synchronised thread, bound on the thread synchroniser in r4
init t[r11]:sp, r1 // set stack pointer of new thread
init t[r11]:pc, r0 // set PC of new thread
set t[r11]:r0, r2 // set r0, argument of new thread
set t[r11]:r1, r3 // set r1, chanend of new thread
ldaw r0, dp[0] // load value of data pointer in r0
init t[r11]:dp, r0 // set data pointer of new thread
add r1, r11, 0 // copy thread resource id to r1
ldaw r11, cp[0] // load value of constant pointer in r11
init t[r1]:cp, r11 // set constant pointer of new thread
msync res[r4] // start new thread
-
- New User
- Posts: 3
- Joined: Tue Jul 08, 2014 6:54 am
Great, thanks for the example. I actually got my code to work so I hope some else will benefit from you help.Bianco wrote:Something like this should get you started, it's a copy paste of another project of mine, so you may want to make changes to suite your needs. In this case one new thread is started. It needs some additional code and modifications to start multiple threads at the same time and wait for them to complete. Try to make a program with par statement and study the generated assembly code to figure out that.Code: Select all
getr r4, 3 // get a thread synchroniser, store in r4 getst r11, res[r4] // get synchronised thread, bound on the thread synchroniser in r4 init t[r11]:sp, r1 // set stack pointer of new thread init t[r11]:pc, r0 // set PC of new thread set t[r11]:r0, r2 // set r0, argument of new thread set t[r11]:r1, r3 // set r1, chanend of new thread ldaw r0, dp[0] // load value of data pointer in r0 init t[r11]:dp, r0 // set data pointer of new thread add r1, r11, 0 // copy thread resource id to r1 ldaw r11, cp[0] // load value of constant pointer in r11 init t[r1]:cp, r11 // set constant pointer of new thread msync res[r4] // start new thread