/*
 * SYNOPSYS CONFIDENTIAL - This is an unpublished, proprietary work of Synopsys,
 * Inc., and is fully protected under copyright and trade secret laws. You may
 * not view, use, disclose, copy, or distribute this file or any information
 * contained herein except pursuant to a valid written license from Synopsys.
 */

//
//	The purpose of this file is to define SSE2 data types to abstacr from the compiler 
//	specific constructs. Currently the target compilers are GCC and the MS VC 2005.
//

#ifndef _SSE2_CMPL_ABSTRACTION_MSC_PCKINT32_H_
#define _SSE2_CMPL_ABSTRACTION_MSC_PCKINT32_H_

//
//	Namespace sse2
//
namespace sse2
{

//
///	class epi64 (packed single precision)
//
class epi64
{
public:

//
///	The type.
//
typedef rxmm128l my_rxmm;

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//
///	Packed integer arithmetic
//

/*!
	r0 := a0 + b0
	r1 := a1 + b1
	r2 := a2 + b2
	r3 := a3 + b3 
*/
static inline rxmm128l add( rxmm128l a, rxmm128l b )
{
	return _mm_add_epi32( a, b );
}

/*!
	r0 := a0 - b0
	r1 := a1 - b1
	r2 := a2 - b2
	r3 := a3 - b3
*/
static inline rxmm128l sub( rxmm128l a, rxmm128l b )
{
	return _mm_sub_epi32( a, b );
}

/*!
	r0 := a0 * b0
	r1 := a1 * b1
	r2 := a2 * b2
	r3 := a3 * b3 
	\note Emulating through float. May be precision loss.
*/
static inline rxmm128l mul( rxmm128l a, rxmm128l b )
{
	register rxmm128s t = _mm_cvtepi32_ps( a );
	register rxmm128s u = _mm_cvtepi32_ps( b );
	register rxmm128s v = _mm_mul_ps( t, u );
	return _mm_cvtps_epi32( v );
}

/*!
	r0 := a0 / b0
	r1 := a1 / b1
	r2 := a2 / b2
	r3 := a3 / b3 
	\note Emulating through float. May be precision loss.
*/
static inline rxmm128l div( rxmm128l a, rxmm128l b )
{
	register rxmm128s t = _mm_cvtepi32_ps( a );
	register rxmm128s u = _mm_cvtepi32_ps( b );
	register rxmm128s v = _mm_div_ps( t, u );
	return _mm_cvtps_epi32( v );
}

/*!
	r0 := max(a0, b0)
	r1 := max(a1, b1)
	r2 := max(a2, b2)
	r3 := max(a3, b3) 
*/
static inline rxmm128l max( rxmm128l a, rxmm128l b )
{
	register rxmm128l t = _mm_cmplt_epi32( a, b );
	int mask = _mm_movemask_epi8( t );
	_mm_shuffle_epi32
	BOOST_STATIC_ASSERT( false );
	return 0;
}

/*!
	r0 := min(a0, b0)
	r1 := min(a1, b1)
	r2 := min(a2, b2)
	r3 := min(a3, b3)
*/
static inline rxmm128l min( rxmm128l a, rxmm128l b )
{
	BOOST_STATIC_ASSERT( false );
	return 0;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//
///	Packed double logic
//

/*!
	r0 := ~a0
	r1 := ~a1
	r2 := ~a2
	r3 := ~a3
*/
static inline rxmm128l not( rxmm128l a )
{
	BOOST_STATIC_ASSERT( false );
	return _mm_andnot_si128( a, b );
}

/*!
	r0 := ~a0 & b0
	r1 := ~a1 & b1
	r2 := ~a2 & b2
	r3 := ~a3 & b3 
*/
static inline rxmm128l andnot( rxmm128l a, rxmm128l b )
{
	return _mm_andnot_si128( a, b );
}

/*!
	r0 := a0 & b0 
	r1 := a1 & b1 
*/
static inline XMM_TYPE and( rxmm128l a, rxmm128l b )
{
	return _mm_and_si128( a, b );
}

/*!
	r0 := a0 | b0 
	r1 := a1 | b1 
*/
static inline XMM_TYPE or( rxmm128l a, rxmm128l b )
{
	return _mm_or_si128( a, b );
}

/*!
	r0 := a0 ^ b0
	r1 := a1 ^ b1
	r2 := a2 ^ b2
	r3 := a3 ^ b3
*/
static inline XMM_TYPE xor( rxmm128l a, rxmm128l b )
{
	return _mm_xor_si128( a, b );
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//
///	Packed double comparision
//

/*!
	r0 := (a0 == b0) ? 0xffffffff : 0x0
	r1 := (a1 == b1) ? 0xffffffff : 0x0
	r2 := (a2 == b2) ? 0xffffffff : 0x0
	r3 := (a3 == b3) ? 0xffffffff : 0x0
*/
static inline rxmm128l cmp_eq( rxmm128l a, rxmm128l b )
{
	return _mm_cmpeq_epi32( a, b );
}

/*!
	r0 := (a0 != b0) ? 0xffffffff : 0x0
	r1 := (a1 != b1) ? 0xffffffff : 0x0
	r2 := (a2 != b2) ? 0xffffffff : 0x0
	r3 := (a3 != b3) ? 0xffffffff : 0x0
*/
static inline rxmm128l cmp_neq( rxmm128l a, rxmm128l b )
{
	rxmm128l t = _mm_cmplt_epi32( a, b );
	rxmm128l u = _mm_cmpgt_epi32( a, b );
	return _mm_cmpor_si128( t, u );
}

/*!
	r0 := (a0 < b0) ? 0xffffffff : 0x0
	r1 := (a1 < b1) ? 0xffffffff : 0x0
	r2 := (a2 < b2) ? 0xffffffff : 0x0
	r3 := (a3 < b3) ? 0xffffffff : 0x0
*/
static inline rxmm128l cmp_lt( rxmm128l a, rxmm128l b )
{
	return _mm_cmplt_epi32( a, b );
}

/*!
	r0 := (a0 <= b0) ? 0xffffffff : 0x0
	r1 := (a1 <= b1) ? 0xffffffff : 0x0
	r2 := (a2 <= b2) ? 0xffffffff : 0x0
	r3 := (a3 <= b3) ? 0xffffffff : 0x0
*/
static inline rxmm128l cmp_le( rxmm128l a, rxmm128l b )
{
	rxmm128l t = _mm_cmplt_epi32( a, b );
	rxmm128l u = _mm_cmpeq_epi32( a, b );
	return _mm_cmpor_si128( t, u );
}

/*!
	r0 := (a0 > b0) ? 0xffffffff : 0x0
	r1 := (a1 > b1) ? 0xffffffff : 0x0
	r2 := (a2 > b2) ? 0xffffffff : 0x0
	r3 := (a3 > b3) ? 0xffffffff : 0x0
*/
static inline rxmm128l cmp_gt( rxmm128l a, rxmm128l b )
{
	return _mm_cmpgt_epi32( a, b );
}

/*!
	r0 := (a0 >= b0) ? 0xffffffff : 0x0
	r1 := (a1 >= b1) ? 0xffffffff : 0x0
	r2 := (a2 >= b2) ? 0xffffffff : 0x0
	r3 := (a3 >= b3) ? 0xffffffff : 0x0
*/
static inline rxmm128l cmp_ge( rxmm128l a, rxmm128l b )
{
	rxmm128l t = _mm_cmpgt_epi32( a, b );
	rxmm128l u = _mm_cmpeq_epi32( a, b );
	return _mm_cmpor_si128( t, u );
}

/*!
	r0 := (a0 ord b0) ? 0xffffffff : 0x0
	r1 := (a1 ord b1) ? 0xffffffff : 0x0
	r2 := (a2 ord b2) ? 0xffffffff : 0x0
	r3 := (a3 ord b3) ? 0xffffffff : 0x0
*/
static inline rxmm128l cmp_ord( rxmm128l a, rxmm128l b )
{
	return _mm_cmpord_epi32( a, b );
}

/*!
	r0 := (a0 unord b0) ? 0xffffffff : 0x0
	r1 := (a1 unord b1) ? 0xffffffff : 0x0
	r2 := (a2 unord b2) ? 0xffffffff : 0x0
	r3 := (a3 unord b3) ? 0xffffffff : 0x0
*/
static inline rxmm128l cmp_unord( rxmm128l a, rxmm128l b )
{
	return _mm_cmpunord_epi32( a, b );
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//
///	Packed integer load
//

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//	Misc

/*!
	r0 := a1
	r1 := b2
	r2 := a3
	r3 := b3
*/
static inline rxmm128l unpckh( rxmm128l a, rxmm128l b )
{
	BOOST_STATIC_ASSERT( false );
	return _mm_unpackhi_epi32( a, b );
}

/*!
	r0 := a0
	r1 := b0
	r2 := a1
	r3 := b1
*/
static inline rxmm128l unpckl( rxmm128l a, rxmm128l b )
{
	BOOST_STATIC_ASSERT( false );
	return _mm_unpacklo_epi32( a, b );
}

/*!
	r := sign(a3)<<3 | sign(a2)<<2 | sign(a1)<<1 | sign(a0)
*/
static inline int movmsk( rxmm128l a, rxmm128l b )
{
	BOOST_STATIC_ASSERT( false );
	return _mm_movemask_epi32( a, b );
}

/*!
	r0 := (i0 == 1) ? b0 : a0 
	r1 := (i1 == 1) ? b1 : a1
	r2 := (i2 == 1) ? b2 : a2
	r3 := (i3 == 1) ? b3 : a3
	\sa movmsk
*/
static inline int shuffle( rxmm128l a, rxmm128l b, int i )
{
	BOOST_STATIC_ASSERT( false );
	return _mm_shuffle_epi32( a, b, i );
}

/*!
	r3 := a3
	r2 := a2
	r1 := b3
	r0 := b2
*/
static inline rxmm128l move_hl( rxmm128l a, rxmm128l b )
{
	BOOST_STATIC_ASSERT( false );
	return mm_movehl_epi32( a0 );
}

/*!
	r3 := b1
	r2 := b0
	r1 := a1
	r0 := a0
*/
static inline rxmm128l move_lh( rxmm128l a, rxmm128l b )
{
	BOOST_STATIC_ASSERT( false );
	return _mm_movelh_epi32( a0 );
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//	Memory load

/*!
	The address \arg p must be 16-byte aligned.
	r0 := p[0] 
	r1 := p[1] 
	r2 := p[2] 
	r3 := p[3] 
*/
static inline rxmm128l load( int * p )
{
	return _mm_load_epi32( reinterpret_cast<__m128i*>(p) );
}

/*!
	The address \arg p must be 16-byte aligned.
	r0 := p[3] 
	r1 := p[2] 
	r2 := p[1] 
	r3 := p[0]
*/
static inline rxmm128l load_reverse( int * p )
{
	BOOST_STATIC_ASSERT( false );
	rxmm128l t = _mm_loadr_epi32( reinterpret_cast<__m128i*>(p) )
	return _mm_loadr_epi32( reinterpret_cast<__m128i*>(p) );
}

/*!
	The address \arg p does not need to be 16-byte aligned.
	r0 := p[0] 
	r1 := p[1] 
	r2 := p[2] 
	r3 := p[3] 
*/
static inline rxmm128l load_unaligned( int * p )
{
	return _mm_loadu_epi32( reinterpret_cast<__m128i*>(p) );
}

/*!
	The address \arg p does not need to be 16-byte aligned.
	r0 := *p 
	r1 := *p 
	r2 := *p 
	r3 := *p 
*/
static inline rxmm128l load_both( int * p )
{
	BOOST_STATIC_ASSERT( false );
	return _mm_load1_epi32( p );
}

/*!
	The address \arg p does not need to be 16-byte aligned.
	r0 := *p
	r1 := 0.0
	r2 := 0.0
	r3 := 0.0
*/
static inline rxmm128l load_s( int * p )
{
	BOOST_STATIC_ASSERT( false );
	return _mm_load_ss( p );
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//	Memory store

/*!
	The address \arg p must be 16-byte aligned.
	p[0] := a0
	p[1] := a1
	p[2] := a2
	p[3] := a3 
*/
static inline void store( int * p, rxmm128l a )
{
	_mm_store_si128( reinterpret_cast<__m128i*>(p), a );
}

/*!
	The address \arg p must be 16-byte aligned.
	p[0] := a3
	p[1] := a2
	p[2] := a1
	p[3] := a0 
*/
static inline void store_reverse( int * p, rxmm128l a )
{
	BOOST_STATIC_ASSERT( false );
	_mm_storer_epi32( p, a );
}

/*!
	The address \arg p does not need to be 16-byte aligned.
	p[0] := a0
	p[1] := a1
	p[2] := a2
	p[3] := a3 
*/
static inline void store_unaligned(int * p, rxmm128l a )
{
	_mm_storeu_si128( p, a );
}

/*!
	The address \arg p does not need to be 16-byte aligned.
	p[0] := a0
	p[1] := a0
*/
static inline void store_both( int * p, rxmm128l a )
{
	BOOST_STATIC_ASSERT( false );
	return _mm_store1_epi32( p );
}

/*!
	The address \arg p does not need to be 16-byte aligned.
	*p := a0
*/
static inline void store_s( int * p, rxmm128l a )
{
	BOOST_STATIC_ASSERT( false );
	return _mm_store_ss( p );
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//	Memory set

/*!
	r0 := a0
	r1 := a1
	r2 := a2
	r3 := a3
*/
static inline rxmm128l set( int a3, int a2, int a1, int a0 )
{
	return _mm_set_epi32( a3, a2, a1, a0 );
}

/*!
	r0 := 0.0
	r1 := 0.0
	r2 := 0.0
	r3 := 0.0
*/
static inline rxmm128l set_zero()
{
	return _mm_setzero_si32( a0 );
}

/*!
	r0 := a0
	r1 := a0
	r2 := a0
	r3 := a0
*/
static inline rxmm128l set_both( int a0 )
{
	return _mm_set1_epi32( a0 );
}

/*!
	The address \arg p does not need to be 16-byte aligned.
	r0 := a0
	r1 := 0.0
	r2 := 0.0
	r3 := 0.0
*/
static inline rxmm128l set_s( int a0 )
{
	BOOST_STATIC_ASSERT( false );
	return _mm_set_ss( a0 );
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//
///	Packed double convertion
//

/*!
	r0 := (float) a0
	r1 := (float) a1
	r2 := 0.0
	r3 := 0.0
*/
static inline rxmm128l cvtpd2ps( rxmm128l a )
{
	return _mm_cvtpd_epi32( a );
}

/*!
	r0 := (double) a0
	r1 := (double) a1
*/
static inline rxmm128l cvtps2pd( rxmm128l a )
{
	return _mm_cvtps_epi32( a );
}

/*!
	r0 := (int) a0
	r1 := (int) a1
	r2 := 0.0
	r3 := 0.0
*/
static inline rxmm128l cvtpd2dq( rxmm128l a )
{
	return _mm_cvtpd_epi32( a );
}

/*!
	r0 := (double) a0
	r1 := (double) a1
*/
static inline rxmm128l cvtdq2pd( rxmm128l a )
{
	return _mm_cvtepi32_epi32( a );
}

/*!
	r := (int) a0
*/
static inline int cvtsd2si( rxmm128l a )
{
	return _mm_cvtsd_si32( a );
}

/*!
	r0 := (float) b0
	r1 := a1
	r2 := a2
	r3 := a3
*/
static inline rxmm128l cvtsd2ss( rxmm128l a, rxmm128l b )
{
	return _mm_cvtsd_ss( a, b );
}

/*!
	r0 := (double) b
	r1 := a1
*/
static inline rxmm128l cvtsi2sd( rxmm128l a, int b )
{
	return _mm_cvtsi32_sd( a, b );
}

/*!
	r0 := (double) b0
	r1 := a1
*/
static inline rxmm128l cvtss2sd( rxmm128l a, rxmm128l b )
{
	return _mm_cvtss_sd( a, b );
}

/*!
	using truncate
	r0 := (int) a0
	r1 := (int) a1
	r2 := 0x0
	r3 := 0x0
*/
static inline rxmm128l cvttpd2dq( rxmm128l a )
{
	return _mm_cvttpd_epi32( a );
}

/*!
	using truncate
	r := (int) a0
*/
static inline int cvttsd2si( rxmm128l a )
{
	return _mm_cvttsd_si32( a );
}

/*!
	r0 := (float) a0
	r1 := (float) a1
	r2 := (float) a2
	r3 := (float) a3
*/
static inline rxmm128l cvtdq2ps( rxmm128l a )
{
	return _mm_cvtepi32_epi32( a );
}

/*!
	r0 := (int) a0
	r1 := (int) a1
	r2 := (int) a2
	r3 := (int) a3
*/
static inline rxmm128l cvtps2dq( rxmm128l a )
{
	return _mm_cvtps_epi32( a );
}

/*!
	uses trancate
	r0 := (int) a0
	r1 := (int) a1
	r2 := (int) a2
	r3 := (int) a3
*/
static inline rxmm128l cvttps2dq( rxmm128l a )
{
	return _mm_cvttps_epi32( a );
}

//
//	class epi64
//
};

//
//	Namespace sse2
//
}

#endif/*_SSE2_CMPL_ABSTRACTION_MSC_PCKINT32_H_*/
