compiler bug??- select order with notification functions

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
CousinItt
Respected Member
Posts: 361
Joined: Wed May 31, 2017 6:55 pm

compiler bug??- select order with notification functions

Post by CousinItt »

Hi all,

I've just run up against a problem - a notification function in a select block which isn't responding. I can fix it just by changing the order of cases.

Here's the offending block, in the working state:

Code: Select all

      select
      {
         case rx_if.data_ready():
            recv_flag = 1; // trigger action after transaction
            break;

         case hif.send(uint32_t buffer[n], unsigned n):
            for(int i = 0; i < n; i++)
            {
               tx_data[i] = buffer[i];
            }
            send_flag = 1; // trigger action after transaction
            break;

         case hif.receive(uint32_t buffer[n], unsigned n):
            for(int i = 0; i < n; i++)
            {
               buffer[i] = rx_data[i];
            }
            break;
      }
 
Here the data_ready function is a notification function, with the notification cleared by another interface function called later.

If I put the rx_if.data_ready case between hif.send and hif.receive, the data_ready notification isn't received. Is this a known problem, or could I be doing something wrong?

I've confirmed the select block isn't just spending time in one of the other cases, and of course checked that the rx_if server has sent the data_ready event.

Thanks.


Gothmag
XCore Addict
Posts: 129
Joined: Wed May 11, 2016 3:50 pm

Post by Gothmag »

I reported this a year or so ago so it should be a known bug. For some reason I wasn't able to get the notification working in my actual code no matter where I put it though, where as the known bug has a solution of re-ordering events.
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

Hi CousinItt
Could you upload a fuller example please.
robert
Gothmag
XCore Addict
Posts: 129
Joined: Wed May 11, 2016 3:50 pm

Post by Gothmag »

Code: Select all

#include <xs1.h>
#include <stdio.h>

interface i {
  void f();
  void g();
};

interface j {
  [[notification]] slave void n();
};

void T(server interface i i, client interface j j)
{
  while (1) {
    select {
      case i.f(): break;
      case j.n(): printf("Event received\n"); break;
      case i.g(): break;
    }
  }
}

int main()
{
  interface i i;
  interface j j;
  par {
    T(i, j);
    j.n();
  }
  return 0;
}
I believe this example shows what he is referring to. Just moving the g case up just after the f case makes the notification trigger. This is a bug I was working with for a while albeit without much time to do so, and larry ended up simplifying it to this.
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

I can confirm that the bug is present on 14.2 but has been fixed on 14.3
Can you confirm the tools version you are using?
I would advise moving to 14.3 for any active development.
User avatar
CousinItt
Respected Member
Posts: 361
Joined: Wed May 31, 2017 6:55 pm

Post by CousinItt »

Hi Gothmag, thanks for the confirmation.

Hi Robertxmos, I hope Gothmag's example (doesn't) work for you. I'm using V14.2.3. I'll upgrade and see if the problem is resolved.
Gothmag
XCore Addict
Posts: 129
Joined: Wed May 11, 2016 3:50 pm

Post by Gothmag »

I tried updating to 14.3 myself but it's a significant downgrade because I get a compiler error.

Code: Select all

xcc1: internal compiler error
Failed in ..\FrontEnd\Lowering\lower_combined_pars.cpp, line 187
	info->stateObj
This usually happens when trying to update so I'll probably be sticking to 14.2.4 where I'm at least familiar with most of the issues.
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

Hi Gothmag,
I can confirm that the compiler error above is still present in 14.3 (it is caused by circular dependencies injected by the '-staged' processing)
It is planned to be fixed for 14.3.1 but as the solution is not clear, the schedule is not definite.
The work around is to turn off staged builds - which reduces optimisation.
The bug is also present in 14.2.4
If you have a small sample program which triggers the error, I would be pleased to receive it.
robert
Gothmag
XCore Addict
Posts: 129
Joined: Wed May 11, 2016 3:50 pm

Post by Gothmag »

That's very interesting it's a 14.2.4 bug as well since I don't get it there. Something must have been done between 14.2.4 and 14.3, or maybe I'm just (un)lucky? My wife and I just had another baby so I don't have alot of time right now but if I get a chance I'll see if I can get a small program together causing the error.