XS2 Dual Issue inline assembly

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
Malcolm
Junior Member
Posts: 7
Joined: Wed Dec 11, 2013 1:53 pm

XS2 Dual Issue inline assembly

Post by Malcolm »

In a loop I'm attempting to implement an indexed memory access with the index post decremented.
ie
int32_t x = ptr[index--];
and hoping to see something like
sub r2, r2, 0x1
ldw r0, r1[r2]
as a dual issued pair.

The compiler isn't hitting the right code for me, but attempting to turn to inline assembly:

asm volatile ("sub %1, %1, 1\n"\
"ldw %0, %2[%1]\n"
: "=r"(x), "+r"(index) : "r"(ptr)
);
I actually get
0x01000b1c: 01 99: sub (2rus) r4, r4, 0x1
0x01000b1e: ff 17: nop (0r)
0x01000b20: ff 17: nop (0r)
0x01000b22: d4 4a: ldw (3r) r9, r1[r4]

How do I tell the inline assembler that I want to execute the two instructions in parallel and not get nops inserted? (And it would also be good to know where I can find this in the documentation.)


Malcolm
Junior Member
Posts: 7
Joined: Wed Dec 11, 2013 1:53 pm

Post by Malcolm »

Found the syntax
asm volatile ("{ ldw %0, %2[%1] ; sub %1, %1, 1 }" : "=r"(x), "+r"(index) : "r"(ptr));
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

Glad you found it.
For those asking the same question, searching for "xmos instruction bundle" will bring up documentation viz: wrap the pair in {}.
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

Thanks for posting the answer for the benefit of others. There are a few nice examples (well commented) of dual issue ASM in more recent IP which may be useful:

https://github.com/xmos/lib_ethernet/bl ... i_tx_lld.S
https://github.com/xmos/lib_ethernet/bl ... i_rx_lld.S
User avatar
akp
XCore Expert
Posts: 578
Joined: Thu Nov 26, 2015 11:47 pm

Post by akp »

Sorry to bring up an old topic. Is there a method to determine at compile time if the inline assembly will be executed in single issue or dual issue mode? e.g. if the compiler has __XS2A__ defined I don't know what issue mode it's in when it hits the inline assembly (e.g. it could have been invoked with -Os or -mno-dual-issue). Ideally I'd like to do something like

Code: Select all

#if DUAL_ISSUE
asm volatile("{instr 1a; instr 1b}");
#else
asm volatile("instr 1a\n"
	"instr 1b");
#endif
What I'm doing now is just writing inline assembly without instruction bundles so it doesn't error out if the compiler is invoked with -mno-dual-issue
Post Reply