Optimisation problems with xTimecomposer

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
ingbo
Junior Member
Posts: 5
Joined: Thu Jun 06, 2013 2:00 pm

Optimisation problems with xTimecomposer

Post by ingbo »

Hello,

why XMatt's code (sharing memory http://www.xcore.com/forum/viewtopic.php?f=26&t=1550) does work with IDE version 11.11, but not with version 12.xx?

Is it an optimisation problem? If it is, is there a work around without using .C ?
Usually one would use "volatile", but "volatile" is not possible with .XC.

main.xc

Code: Select all

#include <print.h>

extern int data_buffer[1024];
extern int data_buffer_[1024];

int main()
{
   par
   {
      {
         while(data_buffer[0]!=1);
         printstr("var read is 1\n");
      }
      {
         data_buffer_[0] = 1;
         printstr("var set to 1\n");
      }
   }

   return 0;
}
buffer.s

Code: Select all

.section .dp.bss, "awd", @nobits

.align 4

.globl data_buffer
.globl data_buffer_
data_buffer:
data_buffer_:
  .space 4096


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

Post by segher »

Hi ingbo,

Could you show the generated code for main()?
ingbo
Junior Member
Posts: 5
Joined: Thu Jun 06, 2013 2:00 pm

Post by ingbo »

Hi segher,

copied from disassembly window:

Code: Select all

main:
000100ac:   entsp (u6)      0x3
000100ae:   stw (ru6)       r10, sp[0x1]
000100b0:   ldaw (ru6)      r10, sp[0x0]
000100b2:   stw (2rus)      r4, r10[0x2]
000100b4:   getr (rus)      r4, 0x3
000100b6:   getst (2r)      r0, res[r4]
000100b8:   ldap (u10)      r11, 0x23
000100ba:   init (2r)       t[r0]:pc, r11
000100bc:   ldap (lu10)     r11, 0x2c
000100c0:   init (l2r)      t[r0]:lr, r11
000100c4:   ldc (lru6)      r1, 0x6
000100c8:   add (2rus)      r2, r1, 0x1
000100ca:   ldaw (ru6)      r3, sp[0x0]
000100cc:   ldaw (l3r)      r2, r3[-r2]
000100d0:   set (1r)        sp, r2
000100d2:   ldaw (l3r)      r1, r2[r1]
000100d6:   init (2r)       t[r0]:sp, r1
000100d8:   msync (1r)      res[r4] *
000100da:   ldw (lru6)      r0, dp[0xd]
000100de:   eq (2rus)       r0, r0, 0x1
000100e0:   bt (ru6)        r0, 0x1
000100e2:   bu (u6)         -0x1
000100e4:   extsp (u6)      0x1
000100e6:   ldaw (lru6)     r0, dp[0x5]
000100ea:   mkmsk (rus)     r1, 0x4
000100ec:   bl (lu10)       0x5b
000100f0:   ldaw (ru6)       sp, sp[0x1]
000100f2:   mjoin (1r)      res[r4] *
000100f4:   freer (1r)      res[r4] *
000100f6:   ldc (ru6)       r0, 0x0
000100f8:   ldw (2rus)      r4, r10[0x2]
000100fa:   set (1r)        sp, r10
000100fc:   ldw (ru6)       r10, sp[0x1]
000100fe:   retsp (u6)      0x3
I think the problem is this part:

Code: Select all

000100de:   eq (2rus)       r0, r0, 0x1
000100e0:   bt (ru6)        r0, 0x1
000100e2:   bu (u6)         -0x1
000100e4:   extsp (u6)      0x1
console output, endless loop

Code: Select all

........
tile[0]@0- -A-s-.----000100e2 (?                   +  0) : bu      -0x1 @56624
tile[0]@0- -A-s-.----000100e2 (?                   +  0) : bu      -0x1 @56628
tile[0]@0- -A-s-.----000100e2 (?                   +  0) : bu      -0x1 @56632
tile[0]@0- -A-s-.----000100e2 (?                   +  0) : bu      -0x1 @56636
..........
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am
Contact:

Post by segher »

ingbo wrote:I think the problem is this part:

Code: Select all

000100de:   eq (2rus)       r0, r0, 0x1
000100e0:   bt (ru6)        r0, 0x1
000100e2:   bu (u6)         -0x1
000100e4:   extsp (u6)      0x1
Yeah. So the new compiler assumes nothing else can modify the
memory, so you'd really need volatile, which isn't there in XC.

You can solve it by going to C or asm, but you said you don't want
this. I don't know a good way out without that though; maybe someone
else has a bright idea?

(You should of course not try to synchronise this way at all; use a
channel or similar. You don't need to push all data through the
channel, you can pass the address of the buffer through there, for
example).
ingbo
Junior Member
Posts: 5
Joined: Thu Jun 06, 2013 2:00 pm

Post by ingbo »

Thank you.
(You should of course not try to synchronise this way at all; use a
channel or similar. You don't need to push all data through the
channel, you can pass the address of the buffer through there, for
example).
Sure. I just wanted to point to the problem with this code.
Post Reply