⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ivec.h

📁 C语言库函数的原型,有用的拿去
💻 H
📖 第 1 页 / 共 3 页
字号:
{
public:
        Is8vec8() { }
        Is8vec8(__m64 mm) : I8vec8(mm) { }
        Is8vec8(signed char s0,signed char s1,signed char s2,signed char s3,signed char s4,signed char s5,signed char s6,signed char s7)
         {
                _MM_8B(0,vec) = s7;
                _MM_8B(1,vec) = s6;
                _MM_8B(2,vec) = s5;
                _MM_8B(3,vec) = s4;
                _MM_8B(4,vec) = s3;
                _MM_8B(5,vec) = s2;
                _MM_8B(6,vec) = s1;
                _MM_8B(7,vec) = s0;
        }

        explicit Is8vec8(__int64 i) : I8vec8 (i) { }
        explicit Is8vec8(int i) : I8vec8 (i) { }

        /* Assignment Operator */
        Is8vec8& operator= (const M64 &a)               { return *this = (Is8vec8) a; }

        /* Logical Assignment Operators */
        Is8vec8& operator&=(const M64 &a)               { return *this = (Is8vec8) _m_pand(vec,a); }
        Is8vec8& operator|=(const M64 &a)               { return *this = (Is8vec8) _m_por(vec,a); }
        Is8vec8& operator^=(const M64 &a)               { return *this = (Is8vec8) _m_pxor(vec,a); }

        /* Addition & Subtraction Assignment Operators */
        Is8vec8& operator +=(const I8vec8 &a)   { return *this = (Is8vec8) _m_paddb(vec,a); }
        Is8vec8& operator -=(const I8vec8 &a)   { return *this = (Is8vec8) _m_psubb(vec,a); }

#if defined (_ENABLE_VEC_DEBUG)
        /* Output for Debug */
        friend std::ostream& operator<< (std::ostream &os, const Is8vec8 &a)
        {
                os << "[7]:" << short(_MM_8B(7,a))
                        << " [6]:" << short(_MM_8B(6,a))
                        << " [5]:" << short(_MM_8B(5,a))
                        << " [4]:" << short(_MM_8B(4,a))
                        << " [3]:" << short(_MM_8B(3,a))
                        << " [2]:" << short(_MM_8B(2,a))
                        << " [1]:" << short(_MM_8B(1,a))
                        << " [0]:" << short(_MM_8B(0,a));
                return os;
        }
#endif  /* defined (_ENABLE_VEC_DEBUG) */

        /* Element Access for Debug, No data modified */
        const signed char& operator[](int i)const
        {
                _VEC_ASSERT(static_cast<unsigned int>(i) < 8);  /* Only 8 elements to access */
                return _MM_8B(i,vec);
        }

        /* Element Access and Assignment for Debug */
        signed char& operator[](int i)
        {
                _VEC_ASSERT(static_cast<unsigned int>(i) < 8);  /* Only 8 elements to access */
                return _MM_8B(i,vec);
        }
};

/* Additional Is8vec8 functions: compares, unpacks, sat add/sub */
inline Is8vec8 cmpeq(const Is8vec8 &a, const Is8vec8 &b)                { return _m_pcmpeqb(a,b); }
inline Is8vec8 cmpneq(const Is8vec8 &a, const Is8vec8 &b)               { return _m_pandn(_m_pcmpeqb(a,b), M64(0xffffffffffffffffi64)); }
inline Is8vec8 cmpgt(const Is8vec8 &a, const Is8vec8 &b)                { return _m_pcmpgtb(a,b); }
inline Is8vec8 cmplt(const Is8vec8 &a, const Is8vec8 &b)                { return _m_pcmpgtb(b,a); }
inline Is8vec8 cmple(const Is8vec8 &a, const Is8vec8 &b)                { return _m_pandn(_m_pcmpgtb(a,b), M64(0xffffffffffffffffi64)); }
inline Is8vec8 cmpge(const Is8vec8 &a, const Is8vec8 &b)                { return _m_pandn(_m_pcmpgtb(b,a), M64(0xffffffffffffffffi64)); }

inline Is8vec8 unpack_low(const Is8vec8 &a, const Is8vec8 &b)   { return _m_punpcklbw(a,b); }
inline Is8vec8 unpack_high(const Is8vec8 &a, const Is8vec8 &b)  { return _m_punpckhbw(a,b); }

inline Is8vec8 sat_add(const Is8vec8 &a, const Is8vec8 &b)              { return _m_paddsb(a,b); }
inline Is8vec8 sat_sub(const Is8vec8 &a, const Is8vec8 &b)              { return _m_psubsb(a,b); }

/* Iu8vec8 Class:
 * 8 elements, each element unsigned char
 */
class Iu8vec8 : public I8vec8
{
public:
        Iu8vec8() { }
        Iu8vec8(__m64 mm) : I8vec8(mm) { }
        Iu8vec8(unsigned char s0,unsigned char s1,unsigned char s2,unsigned char s3,unsigned char s4,unsigned char s5,unsigned char s6,unsigned char s7)
        {
                _MM_8UB(0,vec) = s7;
                _MM_8UB(1,vec) = s6;
                _MM_8UB(2,vec) = s5;
                _MM_8UB(3,vec) = s4;
                _MM_8UB(4,vec) = s3;
                _MM_8UB(5,vec) = s2;
                _MM_8UB(6,vec) = s1;
                _MM_8UB(7,vec) = s0;
        }
        explicit Iu8vec8(__int64 i) : I8vec8 (i) { }
        explicit Iu8vec8(int i) : I8vec8 (i) { }

        /* Assignment Operator */
        Iu8vec8& operator= (const M64 &a)               { return *this = (Iu8vec8) a; }
        /* Logical Assignment Operators */
        Iu8vec8& operator&=(const M64 &a)               { return *this = (Iu8vec8) _m_pand(vec,a); }
        Iu8vec8& operator|=(const M64 &a)               { return *this = (Iu8vec8) _m_por(vec,a); }
        Iu8vec8& operator^=(const M64 &a)               { return *this = (Iu8vec8) _m_pxor(vec,a); }
        /* Addition & Subtraction Assignment Operators */
        Iu8vec8& operator +=(const I8vec8 &a)   { return *this = (Iu8vec8) _m_paddb(vec,a); }
        Iu8vec8& operator -=(const I8vec8 &a)   { return *this = (Iu8vec8) _m_psubb(vec,a); }

#if defined (_ENABLE_VEC_DEBUG)
        /* Output for Debug */
        friend std::ostream& operator << (std::ostream &os, const Iu8vec8 &a)
        {
                 os << "[7]:"  << unsigned short(_MM_8UB(7,a))
                        << " [6]:" << unsigned short(_MM_8UB(6,a))
                        << " [5]:" << unsigned short(_MM_8UB(5,a))
                        << " [4]:" << unsigned short(_MM_8UB(4,a))
                        << " [3]:" << unsigned short(_MM_8UB(3,a))
                        << " [2]:" << unsigned short(_MM_8UB(2,a))
                        << " [1]:" << unsigned short(_MM_8UB(1,a))
                        << " [0]:" << unsigned short(_MM_8UB(0,a));
                return os;
        }
#endif  /* defined (_ENABLE_VEC_DEBUG) */

        /* Element Access for Debug, No data modified */
        const unsigned char& operator[](int i)const
        {
                _VEC_ASSERT(static_cast<unsigned int>(i) < 8);  /* Only 8 elements to access */
                return _MM_8UB(i,vec);
        }

        /* Element Access for Debug */
        unsigned char& operator[](int i)
        {
                _VEC_ASSERT(static_cast<unsigned int>(i) < 8);  /* Only 8 elements to access */
                return _MM_8UB(i,vec);
        }
};

/* Additional Iu8vec8 functions: cmpeq,cmpneq, unpacks, sat add/sub */
inline Iu8vec8 cmpeq(const Iu8vec8 &a, const Iu8vec8 &b)                { return _m_pcmpeqb(a,b); }
inline Iu8vec8 cmpneq(const Iu8vec8 &a, const Iu8vec8 &b)               { return _m_pandn(_m_pcmpeqb(a,b), M64(0xffffffffffffffffi64)); }

inline Iu8vec8 unpack_low(const Iu8vec8 &a, const Iu8vec8 &b)   { return _m_punpcklbw(a,b); }
inline Iu8vec8 unpack_high(const Iu8vec8 &a, const Iu8vec8 &b)  { return _m_punpckhbw(a,b); }

inline Iu8vec8 sat_add(const Iu8vec8 &a, const Iu8vec8 &b)              { return _m_paddusb(a,b); }
inline Iu8vec8 sat_sub(const Iu8vec8 &a, const Iu8vec8 &b)              { return _m_psubusb(a,b); }

inline Is16vec4 pack_sat(const Is32vec2 &a, const Is32vec2 &b)          { return _m_packssdw(a,b); }
inline Is8vec8 pack_sat(const Is16vec4 &a, const Is16vec4 &b)           { return _m_packsswb(a,b); }
inline Iu8vec8 packu_sat(const Is16vec4 &a, const Is16vec4 &b)  { return _m_packuswb(a,b); }

 /********************************* Logicals ****************************************/
#define IVEC_LOGICALS(vect,element) \
inline I##vect##vec##element operator& (const I##vect##vec##element &a, const I##vect##vec##element &b) \
{ return _m_pand( a,b); } \
inline I##vect##vec##element operator| (const I##vect##vec##element &a, const I##vect##vec##element &b) \
{ return _m_por( a,b); } \
inline I##vect##vec##element operator^ (const I##vect##vec##element &a, const I##vect##vec##element &b) \
{ return _m_pxor( a,b); } \
inline I##vect##vec##element andnot (const I##vect##vec##element &a, const I##vect##vec##element &b) \
{ return _m_pandn( a,b); }

IVEC_LOGICALS(8,8)
IVEC_LOGICALS(u8,8)
IVEC_LOGICALS(s8,8)
IVEC_LOGICALS(16,4)
IVEC_LOGICALS(u16,4)
IVEC_LOGICALS(s16,4)
IVEC_LOGICALS(32,2)
IVEC_LOGICALS(u32,2)
IVEC_LOGICALS(s32,2)
IVEC_LOGICALS(64,1)
#undef IVEC_LOGICALS

 /********************************* Add & Sub ****************************************/
#define IVEC_ADD_SUB(vect,element,opsize) \
inline I##vect##vec##element operator+ (const I##vect##vec##element &a, const I##vect##vec##element &b) \
{ return _m_padd##opsize( a,b); } \
inline I##vect##vec##element operator- (const I##vect##vec##element &a, const I##vect##vec##element &b) \
{ return _m_psub##opsize( a,b); }

IVEC_ADD_SUB(8,8, b)
IVEC_ADD_SUB(u8,8, b)
IVEC_ADD_SUB(s8,8, b)
IVEC_ADD_SUB(16,4, w)
IVEC_ADD_SUB(u16,4, w)
IVEC_ADD_SUB(s16,4, w)
IVEC_ADD_SUB(32,2, d)
IVEC_ADD_SUB(u32,2, d)
IVEC_ADD_SUB(s32,2, d)
#undef IVEC_ADD_SUB

 /********************************* Conditional Select ****************************************/
/*      version of: retval = (a OP b)? c : d;                                                                                                    *
 *      Where OP is one of the possible comparision operators.                                                                   *
 *      Example: r = select_eq(a,b,c,d);                                                                                                                 *
 *      if "member at position x of the vector a" == "member at position x of vector b"                  *
 *      assign the corresponding member in r from c, else assign from d.                                                         *
 ********************************* Conditional Select ****************************************/

#define IVEC_SELECT(vect12,vect34,element,selop,arg1,arg2) \
        inline I##vect34##vec##element select_##selop (const I##vect12##vec##element &a, const I##vect12##vec##element &b, const I##vect34##vec##element &c, const I##vect34##vec##element &d)     \
{                                                                                                                               \
        I##vect12##vec##element mask = cmp##selop(a,b);                                         \
        return( I##vect34##vec##element ((mask & arg1 ) | I##vect12##vec##element ((_m_pandn(mask, arg2 )))));  \
}
IVEC_SELECT(8,s8,8,eq,c,d)
IVEC_SELECT(8,u8,8,eq,c,d)
IVEC_SELECT(8,8,8,eq,c,d)
IVEC_SELECT(8,s8,8,neq,c,d)
IVEC_SELECT(8,u8,8,neq,c,d)
IVEC_SELECT(8,8,8,neq,c,d)

IVEC_SELECT(16,s16,4,eq,c,d)
IVEC_SELECT(16,u16,4,eq,c,d)
IVEC_SELECT(16,16,4,eq,c,d)
IVEC_SELECT(16,s16,4,neq,c,d)
IVEC_SELECT(16,u16,4,neq,c,d)
IVEC_SELECT(16,16,4,neq,c,d)

IVEC_SELECT(32,s32,2,eq,c,d)
IVEC_SELECT(32,u32,2,eq,c,d)
IVEC_SELECT(32,32,2,eq,c,d)
IVEC_SELECT(32,s32,2,neq,c,d)
IVEC_SELECT(32,u32,2,neq,c,d)
IVEC_SELECT(32,32,2,neq,c,d)


IVEC_SELECT(s8,s8,8,gt,c,d)
IVEC_SELECT(s8,u8,8,gt,c,d)
IVEC_SELECT(s8,8,8,gt,c,d)
IVEC_SELECT(s8,s8,8,lt,c,d)
IVEC_SELECT(s8,u8,8,lt,c,d)
IVEC_SELECT(s8,8,8,lt,c,d)
IVEC_SELECT(s8,s8,8,le,c,d)
IVEC_SELECT(s8,u8,8,le,c,d)
IVEC_SELECT(s8,8,8,le,c,d)
IVEC_SELECT(s8,s8,8,ge,c,d)
IVEC_SELECT(s8,u8,8,ge,c,d)
IVEC_SELECT(s8,8,8,ge,c,d)

IVEC_SELECT(s16,s16,4,gt,c,d)
IVEC_SELECT(s16,u16,4,gt,c,d)
IVEC_SELECT(s16,16,4,gt,c,d)
IVEC_SELECT(s16,s16,4,lt,c,d)
IVEC_SELECT(s16,u16,4,lt,c,d)
IVEC_SELECT(s16,16,4,lt,c,d)
IVEC_SELECT(s16,s16,4,le,c,d)
IVEC_SELECT(s16,u16,4,le,c,d)
IVEC_SELECT(s16,16,4,le,c,d)
IVEC_SELECT(s16,s16,4,ge,c,d)
IVEC_SELECT(s16,u16,4,ge,c,d)
IVEC_SELECT(s16,16,4,ge,c,d)

IVEC_SELECT(s32,s32,2,gt,c,d)
IVEC_SELECT(s32,u32,2,gt,c,d)
IVEC_SELECT(s32,32,2,gt,c,d)
IVEC_SELECT(s32,s32,2,lt,c,d)
IVEC_SELECT(s32,u32,2,lt,c,d)
IVEC_SELECT(s32,32,2,lt,c,d)
IVEC_SELECT(s32,s32,2,le,c,d)
IVEC_SELECT(s32,u32,2,le,c,d)
IVEC_SELECT(s32,32,2,le,c,d)
IVEC_SELECT(s32,s32,2,ge,c,d)
IVEC_SELECT(s32,u32,2,ge,c,d)
IVEC_SELECT(s32,32,2,ge,c,d)


#undef IVEC_SELECT

inline static void empty(void)          { _m_empty(); }

#if defined (_SILENCE_IVEC_C4799)
        #pragma warning(pop)
#endif  /* defined (_SILENCE_IVEC_C4799) */

#endif  /* defined (_M_CEE_PURE) */

#endif  /* RC_INVOKED */
#endif  /* _IVEC_H_INCLUDED */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -