Inline Assembly
From XCore Exchange
Example of Streaming Channel Inline Assembly functions
This is an example of a header (.h) file that allows interaction with streaming channels.
NOTE: The reason it is in a header file is that the compiler will not inline the function if it is used across modules. Putting it in a .h file gives the compiler every chance inline it!
#ifndef STREAMING_CHANS_H_
#define STREAMING_CHANS_H_
#include <xs1.h>
#include <xccompat.h>
#ifdef __XC__
inline static unsigned streaming_chan_inuint(streaming chanend c)
#else
inline static unsigned streaming_chan_inuint(chanend c)
#endif
{
unsigned value;
__asm__ __volatile__ (
"in %0, res[%1]" :
"=r"(value) :
"r"(c)
);
return value;
}
#ifdef __XC__
inline static void streaming_chan_outuint(streaming chanend c, unsigned value)
#else
inline static void streaming_chan_outuint(chanend c, unsigned value)
#endif
{
__asm__ __volatile__ (
"out res[%0], %1" :
/* no outputs */ :
"r"(c), "r"(value)
);
}
#ifdef __XC__
inline static unsigned char streaming_chan_inuchar(streaming chanend c)
#else
inline static unsigned char streaming_chan_inuchar(chanend c)
#endif
{
unsigned value;
__asm__ __volatile__ (
"int %0, res[%1]" :
"=r"(value) :
"r"(c)
);
return value;
}
#ifdef __XC__
inline static void streaming_chan_outuchar(streaming chanend c, unsigned char value)
#else
inline static void streaming_chan_outuchar(chanend c, unsigned char value)
#endif
{
__asm__ __volatile__ (
"outt res[%0], %1" :
/* no outputs */ :
"r"(c), "r"(value)
);
}
#endif /*STREAMING_CHANS_H_*/
