XS2 Dual Issue inline assembly

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
Junior Member
Posts: 7
Joined: Wed Dec 11, 2013 1:53 pm

XS2 Dual Issue inline assembly

Postby Malcolm » Wed Jun 28, 2017 5:21 pm

In a loop I'm attempting to implement an indexed memory access with the index post decremented.
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.)
Junior Member
Posts: 7
Joined: Wed Dec 11, 2013 1:53 pm

Postby Malcolm » Wed Jun 28, 2017 6:47 pm

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

Postby robertxmos » Thu Jun 29, 2017 9:41 am

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
XCore Legend
Posts: 1124
Joined: Thu May 27, 2010 10:08 am

Postby infiniteimprobability » Thu Jun 29, 2017 9:43 am

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
Respected Member
Posts: 377
Joined: Thu Nov 26, 2015 11:47 pm

Postby akp » Tue Nov 19, 2019 2:38 pm

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

asm volatile("{instr 1a; instr 1b}");
asm volatile("instr 1a\n"
	"instr 1b");
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

Who is online

Users browsing this forum: No registered users and 1 guest