#ifndef PRL_TI_INTRINSICS
#define PRL_TI_INTRINSICS

#ifdef __ARM_ARCH
/* 6.8.1 CPSR Register and Interrupt Intrinsics */
void _call_swi(unsigned int src);
unsigned int _disable_FIQ(void);
unsigned int _disable_interrupts(void);
unsigned int _disable_IRQ(void);
unsigned int _enable_FIQ(void);
unsigned int _enable_interrupts(void);
unsigned int _enable_IRQ(void);
unsigned int _get_CPSR(void);
void _restore_interrupts(unsigned int src);
void _set_CPSR(unsigned int src);
void _set_CPSR_flg(unsigned int src);
unsigned int _set_interrupt_priority(unsigned int src);

/* 6.9 Built-In Functions */
void * _curpc(void);
int _run_address_check(void);

#elif defined(__TMS320C6X__)
typedef struct { int a, b, c, d; } __x128_t;
#define __int40_t long long
typedef struct { float a, b; } __float2_t;

/*
The intrinsics listed in Table 8-5 can be used on all C6000 devices.
They correspond to the indicated C6000 assembly language instruction(s).
See the TMS320C6000 CPU and Instruction Set Reference Guide
for more information.
*/
int _abs (int src);
int _labs (__int40_t src);
int _abs2 (int src);
int _add2 (int src1, int src2);
int _add4 (int src1, int src2);
long long _addsub (int src1, int src2);
long long _addsub2 (int src1, int src2);
unsigned short */* & */ _amem2 (void *ptr);
const unsigned short */* & */ _amem2_const (const void *ptr);
unsigned */* & */ _amem4 (void *ptr);
const unsigned */* & */ _amem4_const (const void *ptr);
long long */* & */ _amem8 (void *ptr);
const long long */* & */ _amem8_const (const void *ptr);
__float2_t */* & */ _amem8_f2(void * ptr);
const __float2_t */* & */ _amem8_f2_const(void * ptr);
double */* & */ _amemd8 (void *ptr);
const double */* & */ _amemd8_const (const void *ptr);
int _avg2 (int src1, int src2);
unsigned _avgu4 (unsigned, unsigned);
unsigned _bitc4 (unsigned src);
unsigned _bitr (unsigned src);
unsigned _clr (unsigned src2, unsigned csta, unsigned cstb);
unsigned _clrr (unsigned src2, int src1);
int _cmpeq2 (int src1, int src2);
int _cmpeq4 (int src1, int src2);
int _cmpgt2 (int src1, int src2);
unsigned _cmpgtu4 (unsigned src1, unsigned src2);
int _cmplt2 (int src1, int src2);
unsigned _cmpltu4 (unsigned src1, unsigned src2);
long long _cmpy (unsigned src1, unsigned src2);
unsigned _cmpyr (unsigned src1, unsigned src2);
unsigned _cmpyr1 (unsigned src1, unsigned src2 );
long long _ddotp4 (unsigned src1, unsigned src2);
long long _ddotph2 (long long src1, unsigned src2);
long long _ddotpl2 (long long src1, unsigned src2);
unsigned _ddotph2r (long long src1, unsigned src2);
unsigned _ddotpl2r (long long src1, unsigned src2);
unsigned _deal (unsigned src );
long long _dmv (int src1, int src2);
int _dotp2 (int src1, int src2);
__int40_t _ldotp2 (int src1, int src2);
int _dotpn2 (int src1, int src2);
int _dotpnrsu2 (int src1, unsigned src2);
int _dotpnrus2 (unsigned src1, int src2);
int _dotprsu2 (int src1, unsigned src2);
int _dotpsu4 (int src1, unsigned src2);
int _dotpus4 (unsigned src1, int src2);
unsigned _dotpu4 (unsigned src1, unsigned src2);
long long _dpack2 (unsigned src1, unsigned src2);
long long _dpackx2 (unsigned src1, unsigned src2);
__int40_t _dtol (double src);
long long _dtoll (double src);
int _ext (int src2, unsigned csta, unsigned cstb);
int _extr (int src2, int src1);
unsigned _extu (unsigned src2, unsigned csta , unsigned cstb);
unsigned _extur (unsigned src2, int src1);
__float2_t _fdmv_f2(float src1, float src2);
unsigned _ftoi (float src);
unsigned _gmpy (unsigned src1, unsigned src2);
int _gmpy4 (int src1, int src2);
unsigned _hi (double src);
unsigned _hill (long long src);
double _itod (unsigned src2, unsigned src1);
float _itof (unsigned src);
long long _itoll (unsigned src2, unsigned src1);
unsigned _lmbd (unsigned src1, unsigned src2);
unsigned _lo (double src);
unsigned _loll (long long src);
double _ltod (__int40_t src);
double _lltod (long long src);
int _max2 (int src1, int src2);
int _min2 (int src1, int src2);
unsigned _maxu4 (unsigned src1, unsigned src2);
unsigned _minu4 (unsigned src1, unsigned src2);
unsigned short */* & */ _mem2 (void * ptr);
const unsigned short */* & */ _mem2_const (const void * ptr);
unsigned */* & */ _mem4 (void * ptr);
const unsigned */* & */ _mem4_const (const void * ptr);
long long */* & */ _mem8 (void * ptr);
const long long */* & */ _mem8_const (const void * ptr);
double */* & */ _memd8 (void * ptr);
const double */* & */ _memd8_const (const void * ptr);
int _mpy (int src1, int src2);
int _mpyus (unsigned src1, int src2);
int _mpysu (int src1, unsigned src2);
unsigned _mpyu (unsigned src1, unsigned src2);
long long _mpy2ir (int src1, int src2);
long long _mpy2ll (int src1, int src2);
int _mpy32 (int src1, int src2);
long long _mpy32ll (int src1, int src2);
long long _mpy32su (int src1, int src2);
long long _mpy32us (unsigned src1, int src2);
long long _mpy32u (unsigned src1, unsigned src2);
int _mpyh (int src1, int src2);
int _mpyhus (unsigned src1, int src2);
int _mpyhsu (int src1, unsigned src2);
unsigned _mpyhu (unsigned src1, unsigned src2);
long long _mpyhill (int src1, int src2);
long long _mpylill (int src1, int src2);
int _mpyhir (int src1, int src2);
int _mpylir (int src1, int src2);
int _mpyhl (int src1, int src2);
int _mpyhuls (unsigned src1, int src2);
int _mpyhslu (int src1, unsigned src2);
unsigned _mpyhlu (unsigned src1, unsigned src2);
long long _mpyihll (int src1, int src2);
long long _mpyilll (int src1, int src2);
int _mpyihr (int src1, int src2);
int _mpyilr (int src1, int src2);
int _mpylh (int src1, int src2);
int _mpyluhs (unsigned src1, int src2);
int _mpylshu (int src1, unsigned src2);
unsigned _mpylhu (unsigned src1, unsigned src2);
long long _mpysu4ll (int src1, unsigned src2);
long long _mpyus4ll (unsigned src1, int src2);
long long _mpyu4ll (unsigned src1, unsigned src2);
int _mvd (int src2 );
void _nassert (int src);
unsigned _norm (int src);
unsigned _lnorm (__int40_t src);
unsigned _pack2 (unsigned src1, unsigned src2);
unsigned _packh2 (unsigned src1, unsigned src2);
unsigned _packh4 (unsigned src1, unsigned src2);
unsigned _packl4 (unsigned src1, unsigned src2);
unsigned _packhl2 (unsigned src1, unsigned src2);
unsigned _packlh2 (unsigned src1, unsigned src2);
unsigned _rotl (unsigned src1, unsigned src2);
int _rpack2 (int src1, int src2);
int _sadd (int src1, int src2);
long _lsadd (int src1, __int40_t src2);
int _sadd2 (int src1, int src2);
int _saddus2 (unsigned src1, int src2);
int _saddsu2 (int src1, unsigned src2);
long long _saddsub (unsigned src1, unsigned src2);
long long _saddsub2 (unsigned src1, unsigned src2);
unsigned _saddu4 (unsigned src1, unsigned src2);
int _sat (__int40_t src2);
unsigned _set (unsigned src2, unsigned csta , unsigned cstb);
unsigned _setr (unsigned src2, int src1);
unsigned _shfl (unsigned src2);
long long _shfl3 (unsigned src1, unsigned src2);
unsigned _shlmb (unsigned src1, unsigned src2);
unsigned _shrmb (unsigned src1, unsigned src2);
int _shr2 (int src1, unsigned src2);
unsigned _shru2 (unsigned src1, unsigned src2);
int _smpy (int src1, int src2);
int _smpyh (int src1, int src2);
int _smpyhl (int src1, int src2);
int _smpylh (int src1, int src2);
long long _smpy2ll (int src1, int src2);
int _smpy32 (int src1, int src2);
int _spack2 (int src1, int src2);
unsigned _spacku4 (int src1 , int src2);
int _sshl (int src2, unsigned src1);
int _sshvl (int src2, int src1);
int _sshvr (int src2, int src1);
int _ssub (int src1, int src2);
__int40_t _lssub (int src1, __int40_t src2);
int _ssub2 (unsigned src1, unsigned src2);
int _sub4 (int src1, int src2);
int _subabs4 (int src1, int src2);
unsigned _subc (unsigned src1, unsigned src2);
int _sub2 (int src1, int src2);
unsigned _swap4 (unsigned src);
unsigned _swap2 (unsigned src);
unsigned _unpkhu4 (unsigned src);
unsigned _unpklu4 (unsigned src);
unsigned _xormpy (unsigned src1, unsigned src2);
unsigned _xpnd2 (unsigned src);
unsigned _xpnd4 (unsigned src);

/*
The intrinsics listed in Table 8-6 can be used for C6740 and C6600 devices,
but not C6400+ devices.
The intrinsics listed correspond to
the indicated C6000 assembly language instruction(s).
*/
int _dpint (double src);
__int40_t _f2tol(__float2_t src);
__float2_t _f2toll(__float2_t src);
double _fabs (double src);
float _fabsf (float src);
__float2_t _lltof2(long long src);
__float2_t _ltof2(__int40_t src);
__float2_t */* & */ _mem8_f2(void * ptr);
const __float2_t */* & */ _mem8_f2_const(void * ptr);
long long _mpyidll (int src1, int src2);
double_mpysp2dp (float src1, float src2);
double_mpyspdp (float src1, double src2);
double _rcpdp (double src);
float _rcpsp (float src);
double _rsqrdp (double src);
float _rsqrsp (float src);
int _spint (float);

/*
The intrinsics listed in Table 8-7 are supported only for C6600 devices.
These intrinsics are in addition to those listed in Table 8-5 and Table 8-6.
The intrinsics listed correspond to the
indicated assembly language instruction(s).
See the TMS320C6000 CPU and Instruction Set Reference Guide
for more information.
*/
__x128_t _ccmatmpy (long long src1, __x128_t src2);
long long _ccmatmpyr1 (long long src1, __x128_t src2);
long long _ccmpy32r1 (long long src1, long long src2);
__x128_t _cmatmpy (long long src1, __x128_t src2);
long long _cmatmpyr1 (long long src1, __x128_t src2);
long long _cmpy32r1 (long long src1, long long src2);
__x128_t _cmpysp (__float2_t src1, __float2_t src2);
double _complex_conjugate_mpysp (double src1, double src2);
int _crot90 (int src);
int _crot270 (int src);
long long _dadd (long long src1, long long src2);
long long _dadd2 (long long src1, long long src2);
__float2_t _daddsp (__float2_t src1, __float2_t src2);
long long _dadd_c (long long src1, long long src2);
long long _dapys2 (long long src1, long long src2);
long long _davg2 (long long src1, long long src2);
long long _davgnr2 (long long src1, long long src2);
long long _davgnru4 (long long src1, long long src2);
long long _davgu4 (long long src1, long long src2);
long long _dccmpyr1 (long long src1, long long src2);
unsigned _dcmpeq2 (long long src1, long long src2);
unsigned _dcmpeq4 (long long src1, long long src2);
unsigned _dcmpgt2 (long long src1, long long src2);
unsigned _dcmpgtu4 (long long src1, long long src2);
__x128_t _dccmpy (long long src1, long long src2);
__x128_t _dcmpy (long long src1, long long src2);
long long _dcmpyr1 (long long src1, long long src2);
long long _dcrot90 (long long src);
long long _dcrot270 (long long src);
long long _ddotp4h (__x128_t src1, __x128_t src2 );
long long _ddotpsu4h (__x128_t src1, __x128_t src2 );
__float2_t _dinthsp (int src);
__float2_t _dinthspu (unsigned src);
__float2_t _dintsp(long long src);
__float2_t _dintspu(long long src);
long long _dmax2 (long long src1, long long src2);
long long _dmaxu4 (long long src1, long long src2);
long long _dmin2 (long long src1, long long src2);
long long _dminu4 (long long src1, long long src2);
__x128_t _dmpy2 (long long src1, long long src2);
__float2_t _dmpysp (__float2_t src1, __float2_t src2);
__x128_t _dmpysu4 (long long src1, long long src2);
__x128_t _dmpyu2 (long long src1, long long src2);
__x128_t _dmpyu4 (long long src1, long long src2);
long long _dmvd (long long src1, unsigned src2 );
int _dotp4h (long long src1, long long src2 );
long long _dotp4hll (long long src1, long long src2 );
int _dotpsu4h (long long src1, long long src2);
long long _dotpsu4hll (long long src1, long long src2);
long long _dpackh2 (long long src1, long long src2);
long long _dpackh4 (long long src1, long long src2);
long long _dpacklh2 (long long src1, long long src2);
long long _dpacklh4 (unsigned src1, unsigned src2);
long long _dpackl2 (long long src1, long long src2);
long long _dpackl4 (long long src1, long long src2);
long long _dsadd (long long src1, long long src2);
long long _dsadd2 (long long src1, long long src2);
long long _dshl (long long src1, unsigned src2);
long long _dshl2 (long long src1, unsigned src2);
long long _dshr (long long src1, unsigned src2);
long long _dshr2 (long long src1, unsigned src2);
long long _dshru (long long src1, unsigned src2);
long long _dshru2 (long long src1, unsigned src2);
__x128_t _dsmpy2 (long long src1, long long src2);
long long _dspacku4 (long long src1, long long src2);
long long _dspint (__float2_t src);
unsigned _dspinth (__float2_t src);
long long _dssub (long long src1, long long src2);
long long _dssub2 (long long src1, long long src2);
long long _dsub (long long src1, long long src2);
long long _dsub2 (long long src1, long long src2);
__float2_t _dsubsp (__float2_t src1, __float2_t src2);
long long _dxpnd2 (unsigned src);
long long _dxpnd4 (unsigned src);
__float2_t _fdmvd_f2(float src1, float src2);
int _land (int src1, int src2);
int _landn (int src1, int src2);
int _lor (int src1, int src2);
void _mfence(void);
long long _mpyu2 (unsigned src1, unsigned src2 );
__x128_t _qmpy32 (__x128_t src1, __x128_t src2);
__x128_t _qmpysp (__x128_t src1, __x128_t src2);
__x128_t _qsmpy32r1 (__x128_t src1, __x128_t src2);
unsigned _shl2 (unsigned src1, unsigned src2);
long long _unpkbu4 (unsigned src);
long long _unpkh2 (unsigned src);
long long _unpkhu2 (unsigned src);
long long _xorll_c (long long src1, long long src2);

/* Table 8-8. Vector-in-Scalar Support C/C++ Compiler v7.2 Intrinsics */
__x128_t _ito128 (unsigned src1, unsigned src2, unsigned src3, unsigned src4);
__x128_t _fto128 (float src1, float src2, float src3, float src4);
__x128_t _llto128 (long long src1, long long src2);
__x128_t _dto128 (double src1, double src2);
__x128_t _f2to128(__float2_t src1, __float2_t src2);
__x128_t _dup32_128 (int src);
__float2_t _ftof2(float src1, float src2);
float _hif (double src);
float _lof (double src);
float _hif2(__float2_t src);
float _lof2(__float2_t src);
long long _hi128 (__x128_t src);
double _hid128 (__x128_t src);
__float2_t _hif2_128(__x128_t src);
long long _lo128 (__x128_t src);
double _lod128 (__x128_t src);
__float2_t _lof2_128(__x128_t src);
unsigned _get32_128 (__x128_t src, int n);
float _get32f_128 (__x128_t src, int n);

/* 8.6.9 Using Intrinsics for Interrupt Control and Atomic Sections */
unsigned int _disable_interrupts (void);
unsigned int _enable_interrupts (void);
void _restore_interrupts (unsigned int);

#elif defined(__TMS320C2000__)
/* 7.5.6 Using Intrinsics to Access Assembly Language Statements */
int __abs16_sat( int src );
void __add( int *m, int b );
void __addl( long *m, long b );
void __and( int *m, int b );
int *__byte( int *array, unsigned int byte_index );
unsigned long *__byte_peripheral_32(unsigned long *x);
void __dec( int *m );
void __dmac( long *src1, long *src2, long *accum1, long *accum2, int shift);
void __eallow( void );
void __edis( void );
unsigned int __enable_interrupts(void);
long __euclidean_div_i32byu32(long numerator, unsigned long denominator, unsigned long *remainder);
int __flip16(int src);
long __flip32(long src);
long long __flip64(long long src);
void __inc( int *m );
long __IQ( long double A , int N );
long __IQmpy( long A, long B , int N );
long __IQsat( long A, long max, long min );
long __IQxmpy(long A , long B, int N);
long long __llmax(long long dst, long long src);
long long __llmin(long long dst, long long src);
long __lmax(long dst, long src);
long __lmin(long dst, long src);
int __max(int dst, int src);
int __min(int dst, int src);
int __mov_byte( int *src, unsigned int n );
long __mpy( int src1, int src2 );
long __mpyb( int src1, unsigned int src2 );
long __mpy_mov_t( int src1, int src2, int * dst2 );
unsigned long __mpyu(unsigned int src2, unsigned int srt2);
long __mpyxu( int src1, unsigned int src2 );
long __norm32(long src, int * shift );
long long __norm64(long long src, int * shift );
void __or( int * m , int b );
long __qmpy32( long src32a, long src32b, int q );
long __qmpy32by16(long src32, int src16, int q);
void __restore_interrupts(unsigned int val );
long __rol( long src );
long __ror( long src );
void * __rpt_mov_imm(void * dst , int src , int count );
int __rpt_norm_inc( long src, int dst, int count );
int __rpt_norm_dec(long src, int dst, int count);
long __rpt_rol(long src, int count);
long __rpt_ror(long src, int count);
long __rpt_subcu(long dst, int src, int count);
unsigned long __rpt_subcul(unsigned long num, unsigned long den, unsigned long *remainder, int count);
long __sat( long src );
long __sat32( long src, long limit );
long __sathigh16(long src, int limit);
long __sbbu( long src1 , unsigned int src2 );
void __sub( int * m, int b );
long __subcu( long src1, int src2 );
unsigned long __subcul(unsigned long num, unsigned long den, unsigned long *remainder);
void __subl( long * m, long b );
void __subr( int * m , int b );
void __subrl( long * m , long b );
void __xor( int * m, int b );
double __einvf32( double x );
double __eisqrtf32( double x );
void __f32_max_idx( double *dst, double src, double *idx_dst, double idx_src );
void __f32_min_idx( double *dst, double src, double *idx_dst, double idx_src );
int __f32toi16r(double src );
unsigned int __f32toui16r(double src );
float __fmax( float x, float y );
float __fmin( float x, float y );
double __fracf32(double src );
double __fsat(double val, double max, double min );
void __swapf( double *a, double *b );
void __swapff( float *a, float *b );
double __divf32( double num , double denom );
double __sqrt( double src );
double __sin( double src );
double __cos( double src );
double __atan( double src );
double __atan2( double y , double x );
double __mpy2pif32( double src );
double __div2pif32( double src );
double __sinpuf32( double src );
double __cospuf32( double src );
double __atanpuf32( double src );
double __atan2puf32( double x, double y );
double __quadf32( double ratio, double y, double x );

#elif defined(__MSP430__)
/* 6.8.1 MSP430 Intrinsics */
unsigned short __bcd_add_short(unsigned short op1, unsigned short op2);
unsigned long __bcd_add_long(unsigned long op1, unsigned long op2);
unsigned short __bic_SR_register(unsigned short mask);
unsigned short __bic_SR_register_on_exit(unsigned short mask);
unsigned short __bis_SR_register(unsigned short mask);
unsigned short __bis_SR_register_on_exit(unsigned short mask);
unsigned long __data16_read_addr(unsigned short addr);
void __data16_write_addr (unsigned short addr, unsigned long src);
unsigned char __data20_read_char(unsigned long addr);
unsigned long __data20_read_long(unsigned long addr);
unsigned short __data20_read_short(unsigned long addr);
void __data20_write_char(unsigned long addr, unsigned char src);
void __data20_write_long(unsigned long addr, unsigned long src);
void __data20_write_short(unsigned long addr, unsigned short src);
void __delay_cycles(unsigned long);
void __disable_interrupt(void);
void __disable_interrupts(void);
void __enable_interrupt(void);
void __enable_interrupts(void);
unsigned int __even_in_range(unsigned int, unsigned int);
unsigned short __get_interrupt_state(void);
unsigned short __get_R4_register(void); /* deprecated */
unsigned short __get_R5_register(void); /* deprecated */
unsigned short __get_SP_register(void);
unsigned short __get_SR_register(void);
unsigned short __get_SR_register_on_exit(void);
void __low_power_mode_0(void);
void __low_power_mode_1(void);
void __low_power_mode_2(void);
void __low_power_mode_3(void);
void __low_power_mode_4(void);
void __low_power_mode_off_on_exit(void);
void __never_executed(void);
void __no_operation(void);
void __op_code(unsigned short);
short __saturated_add_signed_short( short src1, short src2 );
long __saturated_add_signed_long( long src1, long src2 );
short __saturated_sub_signed_short( short src1, short src2 );
long __saturated_sub_signed_long( long src1, long src2 );
void __set_interrupt_state(unsigned short src);
void __set_R4_register(unsigned short src); /* deprecated */
void __set_R5_register(unsigned short src); /* deprecated */
void __set_SP_register(unsigned short src);
unsigned short __swap_bytes(unsigned short src);

#elif defined(__PRU__)
/* 5.11 PRU Instruction Intrinsics */
void __xin ( unsigned int device_id , unsigned int base_register , unsigned int use_remapping , void* object );
void __xout ( unsigned int device_id , unsigned int base_register , unsigned int use_remapping , void* object );
void __xchg ( unsigned int device_id , unsigned int base_register , unsigned int use_remapping , void* object );
void __sxin ( unsigned int device_id , unsigned int base_register , unsigned int use_remapping , void* object );
void __sxout( unsigned int device_id , unsigned int base_register , unsigned int use_remapping , void* object );
void __sxchg( unsigned int device_id , unsigned int base_register , unsigned int use_remapping , void* object );
unsigned int __lmbd( unsigned int src , unsigned int pattern );
void __delay_cycles( unsigned int cycles );
#endif

#endif
