📄 dvec.h
字号:
Is32vec4& operator -=(const I32vec4 &a) { return *this = (Is32vec4)_mm_sub_epi32(vec,a); }
/* Shift Logical Operators */
Is32vec4 operator<<(const M128 &a) { return _mm_sll_epi32(vec,a); }
Is32vec4 operator<<(int count) { return _mm_slli_epi32(vec,count); }
Is32vec4& operator<<=(const M128 &a) { return *this = (Is32vec4)_mm_sll_epi32(vec,a); }
Is32vec4& operator<<=(int count) { return *this = (Is32vec4)_mm_slli_epi32(vec,count); }
/* Shift Arithmetic Operations */
Is32vec4 operator>>(const M128 &a) { return _mm_sra_epi32(vec,a); }
Is32vec4 operator>>(int count) { return _mm_srai_epi32(vec,count); }
Is32vec4& operator>>=(const M128 &a) { return *this = (Is32vec4) _mm_sra_epi32(vec,a); }
Is32vec4& operator>>=(int count) { return *this = (Is32vec4) _mm_srai_epi32(vec,count); }
#if defined (_ENABLE_VEC_DEBUG)
/* Output for Debug */
friend std::ostream& operator<< (std::ostream &os, const Is32vec4 &a)
{
os << "[3]:" << _MM_4DW(3,a)
<< " [2]:" << _MM_4DW(2,a)
<< " [1]:" << _MM_4DW(1,a)
<< " [0]:" << _MM_4DW(0,a);
return os;
}
#endif /* defined (_ENABLE_VEC_DEBUG) */
/* Element Access for Debug, No data modified */
const int& operator[](int i)const
{
_VEC_ASSERT(static_cast<unsigned int>(i) < 4); /* Only 4 elements to access */
return _MM_4DW(i,vec);
}
/* Element Access for Debug */
int& operator[](int i)
{
_VEC_ASSERT(static_cast<unsigned int>(i) < 4); /* Only 4 elements to access */
return _MM_4DW(i,vec);
}
};
/* Compares */
inline Is32vec4 cmpeq(const Is32vec4 &a, const Is32vec4 &b) { return _mm_cmpeq_epi32(a,b); }
inline Is32vec4 cmpneq(const Is32vec4 &a, const Is32vec4 &b) { return _mm_andnot_si128(_mm_cmpeq_epi32(a,b), get_mask128()); }
inline Is32vec4 cmpgt(const Is32vec4 &a, const Is32vec4 &b) { return _mm_cmpgt_epi32(a,b); }
inline Is32vec4 cmplt(const Is32vec4 &a, const Is32vec4 &b) { return _mm_cmpgt_epi32(b,a); }
/* Unpacks */
inline Is32vec4 unpack_low(const Is32vec4 &a, const Is32vec4 &b) { return _mm_unpacklo_epi32(a,b); }
inline Is32vec4 unpack_high(const Is32vec4 &a, const Is32vec4 &b) { return _mm_unpackhi_epi32(a,b); }
/* Iu32vec4 Class:
* 4 elements, each element unsigned int
*/
class Iu32vec4 : public I32vec4
{
public:
Iu32vec4() { }
Iu32vec4(__m128i mm) : I32vec4(mm) { }
Iu32vec4(unsigned int ui3, unsigned int ui2, unsigned int ui1, unsigned int ui0)
{
_MM_4UDW(0,vec) = ui0;
_MM_4UDW(1,vec) = ui1;
_MM_4UDW(2,vec) = ui2;
_MM_4UDW(3,vec) = ui3;
}
/* Assignment Operator */
Iu32vec4& operator= (const M128 &a) { return *this = (Iu32vec4) a; }
/* Logical Assignment Operators */
Iu32vec4& operator&=(const M128 &a) { return *this = (Iu32vec4) _mm_and_si128(vec,a); }
Iu32vec4& operator|=(const M128 &a) { return *this = (Iu32vec4) _mm_or_si128(vec,a); }
Iu32vec4& operator^=(const M128 &a) { return *this = (Iu32vec4) _mm_xor_si128(vec,a); }
/* Addition & Subtraction Assignment Operators */
Iu32vec4& operator +=(const I32vec4 &a) { return *this = (Iu32vec4)_mm_add_epi32(vec,a); }
Iu32vec4& operator -=(const I32vec4 &a) { return *this = (Iu32vec4)_mm_sub_epi32(vec,a); }
/* Shift Logical Operators */
Iu32vec4 operator<<(const M128 &a) { return _mm_sll_epi32(vec,a); }
Iu32vec4 operator<<(int count) { return _mm_slli_epi32(vec,count); }
Iu32vec4& operator<<=(const M128 &a) { return *this = (Iu32vec4)_mm_sll_epi32(vec,a); }
Iu32vec4& operator<<=(int count) { return *this = (Iu32vec4)_mm_slli_epi32(vec,count); }
Iu32vec4 operator>>(const M128 &a) { return _mm_srl_epi32(vec,a); }
Iu32vec4 operator>>(int count) { return _mm_srli_epi32(vec,count); }
Iu32vec4& operator>>=(const M128 &a) { return *this = (Iu32vec4) _mm_srl_epi32(vec,a); }
Iu32vec4& operator>>=(int count) { return *this = (Iu32vec4) _mm_srli_epi32(vec,count); }
#if defined (_ENABLE_VEC_DEBUG)
/* Output for Debug */
friend std::ostream& operator<< (std::ostream &os, const Iu32vec4 &a)
{
os << "[3]:" << _MM_4UDW(3,a)
<< " [2]:" << _MM_4UDW(2,a)
<< " [1]:" << _MM_4UDW(1,a)
<< " [0]:" << _MM_4UDW(0,a);
return os;
}
#endif /* defined (_ENABLE_VEC_DEBUG) */
/* Element Access for Debug, No data modified */
const unsigned int& operator[](int i)const
{
_VEC_ASSERT(static_cast<unsigned int>(i) < 4); /* Only 4 elements to access */
return _MM_4UDW(i,vec);
}
/* Element Access and Assignment for Debug */
unsigned int& operator[](int i)
{
_VEC_ASSERT(static_cast<unsigned int>(i) < 4); /* Only 4 elements to access */
return _MM_4UDW(i,vec);
}
};
inline I64vec2 operator*(const Iu32vec4 &a, const Iu32vec4 &b) { return _mm_mul_epu32(a,b); }
inline Iu32vec4 cmpeq(const Iu32vec4 &a, const Iu32vec4 &b) { return _mm_cmpeq_epi32(a,b); }
inline Iu32vec4 cmpneq(const Iu32vec4 &a, const Iu32vec4 &b) { return _mm_andnot_si128(_mm_cmpeq_epi32(a,b), get_mask128()); }
inline Iu32vec4 unpack_low(const Iu32vec4 &a, const Iu32vec4 &b) { return _mm_unpacklo_epi32(a,b); }
inline Iu32vec4 unpack_high(const Iu32vec4 &a, const Iu32vec4 &b) { return _mm_unpackhi_epi32(a,b); }
/* I16vec8 Class:
* 8 elements, each element either unsigned or signed short
*/
class I16vec8 : public M128
{
public:
I16vec8() { }
I16vec8(__m128i mm) : M128(mm) { }
/* Assignment Operator */
I16vec8& operator= (const M128 &a) { return *this = (I16vec8) a; }
/* Logical Assignment Operators */
I16vec8& operator&=(const M128 &a) { return *this = (I16vec8) _mm_and_si128(vec,a); }
I16vec8& operator|=(const M128 &a) { return *this = (I16vec8) _mm_or_si128(vec,a); }
I16vec8& operator^=(const M128 &a) { return *this = (I16vec8) _mm_xor_si128(vec,a); }
/* Addition & Subtraction Assignment Operators */
I16vec8& operator +=(const I16vec8 &a) { return *this = (I16vec8) _mm_add_epi16(vec,a); }
I16vec8& operator -=(const I16vec8 &a) { return *this = (I16vec8) _mm_sub_epi16(vec,a); }
I16vec8& operator *=(const I16vec8 &a) { return *this = (I16vec8) _mm_mullo_epi16(vec,a); }
/* Shift Logical Operators */
I16vec8 operator<<(const M128 &a) { return _mm_sll_epi16(vec,a); }
I16vec8 operator<<(int count) { return _mm_slli_epi16(vec,count); }
I16vec8& operator<<=(const M128 &a) { return *this = (I16vec8)_mm_sll_epi16(vec,a); }
I16vec8& operator<<=(int count) { return *this = (I16vec8)_mm_slli_epi16(vec,count); }
};
inline I16vec8 operator*(const I16vec8 &a, const I16vec8 &b) { return _mm_mullo_epi16(a,b); }
inline I16vec8 cmpeq(const I16vec8 &a, const I16vec8 &b) { return _mm_cmpeq_epi16(a,b); }
inline I16vec8 cmpneq(const I16vec8 &a, const I16vec8 &b) { return _mm_andnot_si128(_mm_cmpeq_epi16(a,b), get_mask128()); }
inline I16vec8 unpack_low(const I16vec8 &a, const I16vec8 &b) { return _mm_unpacklo_epi16(a,b); }
inline I16vec8 unpack_high(const I16vec8 &a, const I16vec8 &b) { return _mm_unpackhi_epi16(a,b); }
/* Is16vec8 Class:
* 8 elements, each element signed short
*/
class Is16vec8 : public I16vec8
{
public:
Is16vec8() { }
Is16vec8(__m128i mm) : I16vec8(mm) { }
Is16vec8(signed short s7,signed short s6,signed short s5,signed short s4,signed short s3,signed short s2,signed short s1,signed short s0)
{
_MM_8W(0,vec) = s0;
_MM_8W(1,vec) = s1;
_MM_8W(2,vec) = s2;
_MM_8W(3,vec) = s3;
_MM_8W(4,vec) = s4;
_MM_8W(5,vec) = s5;
_MM_8W(6,vec) = s6;
_MM_8W(7,vec) = s7;
}
/* Assignment Operator */
Is16vec8& operator= (const M128 &a) { return *this = (Is16vec8) a; }
/* Logical Assignment Operators */
Is16vec8& operator&=(const M128 &a) { return *this = (Is16vec8) _mm_and_si128(vec,a); }
Is16vec8& operator|=(const M128 &a) { return *this = (Is16vec8) _mm_or_si128(vec,a); }
Is16vec8& operator^=(const M128 &a) { return *this = (Is16vec8) _mm_xor_si128(vec,a); }
/* Addition & Subtraction Assignment Operators */
Is16vec8& operator +=(const I16vec8 &a) { return *this = (Is16vec8) _mm_add_epi16(vec,a); }
Is16vec8& operator -=(const I16vec8 &a) { return *this = (Is16vec8) _mm_sub_epi16(vec,a); }
Is16vec8& operator *=(const I16vec8 &a) { return *this = (Is16vec8) _mm_mullo_epi16(vec,a); }
/* Shift Logical Operators */
Is16vec8 operator<<(const M128 &a) { return _mm_sll_epi16(vec,a); }
Is16vec8 operator<<(int count) { return _mm_slli_epi16(vec,count); }
Is16vec8& operator<<=(const M128 &a) { return *this = (Is16vec8)_mm_sll_epi16(vec,a); }
Is16vec8& operator<<=(int count) { return *this = (Is16vec8)_mm_slli_epi16(vec,count); }
/* Shift Arithmetic Operators */
Is16vec8 operator>>(const M128 &a) { return _mm_sra_epi16(vec,a); }
Is16vec8 operator>>(int count) { return _mm_srai_epi16(vec,count); }
Is16vec8& operator>>=(const M128 &a) { return *this = (Is16vec8)_mm_sra_epi16(vec,a); }
Is16vec8& operator>>=(int count) { return *this = (Is16vec8)_mm_srai_epi16(vec,count); }
#if defined (_ENABLE_VEC_DEBUG)
/* Output for Debug */
friend std::ostream& operator<< (std::ostream &os, const Is16vec8 &a)
{
os << "[7]:" << _MM_8W(7,a)
<< " [6]:" << _MM_8W(6,a)
<< " [5]:" << _MM_8W(5,a)
<< " [4]:" << _MM_8W(4,a)
<< " [3]:" << _MM_8W(3,a)
<< " [2]:" << _MM_8W(2,a)
<< " [1]:" << _MM_8W(1,a)
<< " [0]:" << _MM_8W(0,a);
return os;
}
#endif /* defined (_ENABLE_VEC_DEBUG) */
/* Element Access for Debug, No data modified */
const signed short& operator[](int i)const
{
_VEC_ASSERT(static_cast<unsigned int>(i) < 8); /* Only 8 elements to access */
return _MM_8W(i,vec);
}
/* Element Access and Assignment for Debug */
signed short& operator[](int i)
{
_VEC_ASSERT(static_cast<unsigned int>(i) < 8); /* Only 8 elements to access */
return _MM_8W(i,vec);
}
};
inline Is16vec8 operator*(const Is16vec8 &a, const Is16vec8 &b) { return _mm_mullo_epi16(a,b); }
/* Additional Is16vec8 functions: compares, unpacks, sat add/sub */
inline Is16vec8 cmpeq(const Is16vec8 &a, const Is16vec8 &b) { return _mm_cmpeq_epi16(a,b); }
inline Is16vec8 cmpneq(const Is16vec8 &a, const Is16vec8 &b) { return _mm_andnot_si128(_mm_cmpeq_epi16(a,b), get_mask128()); }
inline Is16vec8 cmpgt(const Is16vec8 &a, const Is16vec8 &b) { return _mm_cmpgt_epi16(a,b); }
inline Is16vec8 cmplt(const Is16vec8 &a, const Is16vec8 &b) { return _mm_cmpgt_epi16(b,a); }
inline Is16vec8 unpack_low(const Is16vec8 &a, const Is16vec8 &b) { return _mm_unpacklo_epi16(a,b); }
inline Is16vec8 unpack_high(const Is16vec8 &a, const Is16vec8 &b) { return _mm_unpackhi_epi16(a,b); }
inline Is16vec8 mul_high(const Is16vec8 &a, const Is16vec8 &b) { return _mm_mulhi_epi16(a,b); }
inline Is32vec4 mul_add(const Is16vec8 &a, const Is16vec8 &b) { return _mm_madd_epi16(a,b);}
inline Is16vec8 sat_add(const Is16vec8 &a, const Is16vec8 &b) { return _mm_adds_epi16(a,b); }
inline Is16vec8 sat_sub(const Is16vec8 &a, const Is16vec8 &b) { return _mm_subs_epi16(a,b); }
inline Is16vec8 simd_max(const Is16vec8 &a, const Is16vec8 &b) { return _mm_max_epi16(a,b); }
inline Is16vec8 simd_min(const Is16vec8 &a, const Is16vec8 &b) { return _mm_min_epi16(a,b); }
/* Iu16vec8 Class:
* 8 elements, each element unsigned short
*/
class Iu16vec8 : public I16vec8
{
public:
Iu16vec8() { }
Iu16vec8(__m128i mm) : I16vec8(mm) { }
Iu16vec8(unsigned short s7,unsigned short s6,unsigned short s5,unsigned short s4, unsigned short s3,unsigned short s2,unsigned short s1,unsigned short s0)
{
_MM_8UW(0,vec) = s0;
_MM_8UW(1,vec) = s1;
_MM_8UW(2,vec) = s2;
_MM_8UW(3,vec) = s3;
_MM_8UW(4,vec) = s4;
_MM_8UW(5,vec) = s5;
_MM_8UW(6,vec) = s6;
_MM_8UW(7,vec) = s7;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -