Compiler Error or User Error?

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
Paolomio
Experienced Member
Posts: 64
Joined: Tue Oct 05, 2010 7:33 pm

Compiler Error or User Error?

Post by Paolomio »

The following code, in xc:

Code: Select all

#pragma loop unroll
void test(void)
{
	int j, x;
	while(1)
	{
		for(j = 5; j >= 1; j--)
		{
			x = j+1;
		}
	}
}
causes the following error from the compiler:
xcc1: terminated due to internal unrecoverable error
If I comment out the while(1) loop it compiles fine. Any ideas what's wrong?

Paul


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

Post by segher »

That's a compiler bug (it tells you it is).

Maybe it tries to unroll the infinite loop, like you asked it to :-)
User avatar
Paolomio
Experienced Member
Posts: 64
Joined: Tue Oct 05, 2010 7:33 pm

Post by Paolomio »

It may be a compiler bug, but to be clear my code is not asking it to unroll an infinitely long loop. It's asking it to unroll a finite loop and run it for an infinitely long time. There is some difference there.

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

Post by Folknology »

What happens if you move the pragma to the line above the For loop but below the while, does that make any difference?

regards
Al
User avatar
Paolomio
Experienced Member
Posts: 64
Joined: Tue Oct 05, 2010 7:33 pm

Post by Paolomio »

Folknology wrote:What happens if you move the pragma to the line above the For loop but below the while, does that make any difference?
The pragma is function-wide, and must appear above the affected function.

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

Post by Folknology »

What about something ugly like:

Code: Select all

#pragma loop unroll
void test(void)
{
   int j, x;
   asm("\n.loop:\n")
      for(j = 5; j >= 1; j--)
      {
         x = j+1;
      }
   asm("\n bu .loop \n");
}
User avatar
Paolomio
Experienced Member
Posts: 64
Joined: Tue Oct 05, 2010 7:33 pm

Post by Paolomio »

Folknology wrote:What about something ugly like:
I don't know, but the real problem is that this looks like a compiler bug. I'll submit a ticket to see what XMOS says...
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

Paolomio wrote:
Folknology wrote:What happens if you move the pragma to the line above the For loop but below the while, does that make any difference?
The pragma is function-wide, and must appear above the affected function.

No luck there...
Says who?
Tools User Guide 11.2 wrote: #pragma loop unroll (n) (XC only)

This pragma controls the number of times the next do, while or for loop in the
current function is unrolled. n specifies the number of iterations to unroll, and
unrolling is performed only at optimization level 01 and higher. Omitting the
(n ) parameter causes the compiler to try and fully unroll the loop. Outside of a
function the pragma is ignored.
The compiler produces a warning if unable to
perform the unrolling.

Code: Select all

void test(streaming chanend c)
{
   int j, x;
   while(1)
   {
      #pragma loop unroll
      for(j = 5; j >= 1; j--)
      {
         x = j+1;
         c <: x;
      }
   }
}
works fine here.
I added a chanend to avoid the while loop being optimized to nothing because nothing useful is done with x.

Code: Select all

test:
.L26:
.L12:
.L16:
.L17:
          ldc       r1, 0x6
.L64:
          out       res[r0], r1 
.L19:
          ldc       r1, 0x5
.L65:
          out       res[r0], r1 
          ldc       r1, 0x4
.L66:
          out       res[r0], r1 
          mkmsk     r1, 0x2
.L67:
          out       res[r0], r1 
          ldc       r1, 0x2
.L68:
          out       res[r0], r1 
          bu        .L12 
User avatar
Paolomio
Experienced Member
Posts: 64
Joined: Tue Oct 05, 2010 7:33 pm

Post by Paolomio »

[
Tools User Guide 11.2 wrote: Outside of a
function the pragma is ignored.
Well, I totally missed that. What's strange is that it appeared to unroll a loop in a different function (generating sine samples at 3Ms/s with the pragma, and 500Ks/s without). Huh.