Inline assembler constraints

Technical questions regarding the XTC tools and programming with XMOS.
MaxFlashrom
Experienced Member
Posts: 82
Joined: Fri Nov 05, 2010 2:59 pm

Inline assembler constraints

Post by MaxFlashrom »

Hi, I'm having trouble with inline assembly contraints. Specifically, nothing other than "r"(xxx) and "=r"(xxx) seem to work.
I am using the 11.2.1 tools. I want to do in-out paramters, and immediate values would be nice too.

Runes in other gcc manuals suggest that the likes of this works for tmp as an in-out variable, a common pattern on processors which don't have 3-reg RISC capability on most instructions, as XMOS does.

Code: Select all

asm("andnot %0, %2" : "=r"(tmp) : "0"(tmp), "r"(mask));
gives a syntax error.
With

Code: Select all

asm("andnot %0, %2" : "=r"(tmp) : "r"(tmp), "r"(mask));
the compiler just produces nonsense.

Some variants support the use of "+" for in-out, I read i.e.

Code: Select all

asm("andnot %0, %1" : "+r"(tmp) : "r"(mask));
gives a syntax error.

This also does not work

Code: Select all

asm("ldc r0, %0" :: "i"(0xf7));
It avoids the need for the likes of:

Code: Select all

#include <xs1.h>

#define stringify(x) stringify0(x)
#define stringify0(x) #x

asm("getr %0, " stringify(XS1_RES_TYPE_LOCK) : "=r"(lock));
Has anyone made in-out parameters work? The XMOS manual doesn't elaborate beyond simple "r" and "=r" examples.

Regards
Max.


richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

The XC compiler currently only supports the constraints listed in the tools user guide. Tied operands and immediate operands are not supported. If you need to use an instruction with a read / write operand then you will need to introduce a move. For example:

Code: Select all

asm("mov %0, %1; andnot %0, %2" : "=&r"(result) : "r"(x), "r"(mask));
Supporting tied operands would avoid the need for the move so its something we would like to support in future.

Edit: fix order of operands
Last edited by richard on Mon Jun 27, 2011 7:40 pm, edited 1 time in total.
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

I think you swapped the "mov" operands there? It's "mov dst,src" isn 't it?
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

segher wrote:I think you swapped the "mov" operands there? It's "mov dst,src" isn 't it?
Good spot, I've edited my post.