Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

837 lines
32 KiB

  1. /**
  2. *** Copyright (C) 1985-1999 Intel Corporation. All rights reserved.
  3. ***
  4. *** The information and source code contained herein is the exclusive
  5. *** property of Intel Corporation and may not be disclosed, examined
  6. *** or reproduced in whole or in part without explicit written authorization
  7. *** from the company.
  8. ***
  9. **/
  10. /*
  11. * Definition of a C++ class interface to MMX(TM) instruction intrinsics.
  12. *
  13. */
  14. #ifndef IVEC_H_INCLUDED
  15. #define IVEC_H_INCLUDED
  16. #if !defined __cplusplus
  17. #error ERROR: This file is only supported in C++ compilations!
  18. #endif /* !__cplusplus */
  19. #include <mmintrin.h>
  20. #include <assert.h>
  21. /*
  22. * Define _SILENCE_IVEC_C4799 to disable warning C4799 inside this header.
  23. * Be careful that any code that uses these functions properly executes EMMS
  24. * or _m_empty() after using any MMX instruction and before using the x87 NDP.
  25. */
  26. #if defined(_SILENCE_IVEC_C4799)
  27. #pragma warning(push)
  28. #pragma warning(disable: 4799)
  29. #endif
  30. /*
  31. * Define _ENABLE_VEC_DEBUG to enable std::ostream inserters for debug output
  32. */
  33. #if defined(_ENABLE_VEC_DEBUG)
  34. #include <iostream>
  35. #endif
  36. /* If using MSVC5.0, explicit keyword should be used */
  37. #if (_MSC_VER >= 1100)
  38. #define EXPLICIT explicit
  39. #else
  40. #if (__ICL)
  41. #define EXPLICIT __explicit /* If MSVC4.x & ICL, use __explicit */
  42. #else
  43. #define EXPLICIT /* nothing */
  44. #pragma message( "explicit keyword not recognized")
  45. #endif
  46. #endif
  47. class I8vec8; /* 8 elements, each element a signed or unsigned char data type */
  48. class Is8vec8; /* 8 elements, each element a signed char data type */
  49. class Iu8vec8; /* 8 elements, each element an unsigned char data type */
  50. class I16vec4; /* 4 elements, each element a signed or unsigned short */
  51. class Is16vec4; /* 4 elements, each element a signed short */
  52. class Iu16vec4; /* 4 elements, each element an unsigned short */
  53. class I32vec2; /* 2 elements, each element a signed or unsigned long */
  54. class Is32vec2; /* 2 elements, each element a signed long */
  55. class Iu32vec2; /* 2 elements, each element a unsigned long */
  56. class I64vec1; /* 1 element, a __m64 data type - Base I64vec1 class */
  57. #define _MM_8UB(element,vector) (*((unsigned char*)&##vector + ##element))
  58. #define _MM_8B(element,vector) (*((signed char*)&##vector + ##element))
  59. #define _MM_4UW(element,vector) (*((unsigned short*)&##vector + ##element))
  60. #define _MM_4W(element,vector) (*((short*)&##vector + ##element))
  61. #define _MM_2UDW(element,vector) (*((unsigned int*)&##vector + ##element))
  62. #define _MM_2DW(element,vector) (*((int*)&##vector + ##element))
  63. #define _MM_QW (*((__int64*)&vec))
  64. /* M64 Class:
  65. * 1 element, a __m64 data type
  66. * Contructors & Logical Operations
  67. */
  68. class M64
  69. {
  70. protected:
  71. __m64 vec;
  72. public:
  73. M64() { }
  74. M64(__m64 mm) { vec = mm; }
  75. M64(__int64 mm) { _MM_QW = mm; }
  76. M64(int i) { vec = _m_from_int(i); }
  77. operator __m64() const { return vec; }
  78. /* Logical Operations */
  79. M64& operator&=(const M64 &a) { return *this = (M64) _m_pand(vec,a); }
  80. M64& operator|=(const M64 &a) { return *this = (M64) _m_por(vec,a); }
  81. M64& operator^=(const M64 &a) { return *this = (M64) _m_pxor(vec,a); }
  82. };
  83. inline M64 operator&(const M64 &a, const M64 &b) { return _m_pand( a,b); }
  84. inline M64 operator|(const M64 &a, const M64 &b) { return _m_por(a,b); }
  85. inline M64 operator^(const M64 &a, const M64 &b) { return _m_pxor(a,b); }
  86. inline M64 andnot(const M64 &a, const M64 &b) { return _m_pandn(a,b); }
  87. /* I64vec1 Class:
  88. * 1 element, a __m64 data type
  89. * Contains Operations which can operate on any __m64 data type
  90. */
  91. class I64vec1 : public M64
  92. {
  93. public:
  94. I64vec1() { }
  95. I64vec1(__m64 mm) : M64(mm) { }
  96. EXPLICIT I64vec1(int i) : M64(i) { }
  97. EXPLICIT I64vec1(__int64 mm) : M64(mm) { }
  98. I64vec1& operator= (const M64 &a) { return *this = (I64vec1) a; }
  99. I64vec1& operator&=(const M64 &a) { return *this = (I64vec1) _m_pand(vec,a); }
  100. I64vec1& operator|=(const M64 &a) { return *this = (I64vec1) _m_por(vec,a); }
  101. I64vec1& operator^=(const M64 &a) { return *this = (I64vec1) _m_pxor(vec,a); }
  102. /* Shift Logical Operations */
  103. I64vec1 operator<<(const M64 &a) { return _m_psllq(vec, a); }
  104. I64vec1 operator<<(int count) { return _m_psllqi(vec, count); }
  105. I64vec1& operator<<=(const M64 &a) { return *this = (I64vec1) _m_psllq(vec, a); }
  106. I64vec1& operator<<=(int count) { return *this = (I64vec1) _m_psllqi(vec, count); }
  107. I64vec1 operator>>(const M64 &a) { return _m_psrlq(vec, a); }
  108. I64vec1 operator>>(int count) { return _m_psrlqi(vec, count); }
  109. I64vec1& operator>>=(const M64 &a) { return *this = (I64vec1) _m_psrlq(vec, a); }
  110. I64vec1& operator>>=(int count) { return *this = (I64vec1) _m_psrlqi(vec, count); }
  111. };
  112. /* I32vec2 Class:
  113. * 2 elements, each element either a signed or unsigned int
  114. */
  115. class I32vec2 : public M64
  116. {
  117. public:
  118. I32vec2() { }
  119. I32vec2(__m64 mm) : M64(mm) { }
  120. EXPLICIT I32vec2(int i) : M64 (i) { }
  121. EXPLICIT I32vec2(__int64 i): M64(i) {}
  122. /* Assignment Operator */
  123. I32vec2& operator= (const M64 &a) { return *this = (I32vec2) a; }
  124. /* Logical Assignment Operators */
  125. I32vec2& operator&=(const M64 &a) { return *this = (I32vec2) _m_pand(vec,a); }
  126. I32vec2& operator|=(const M64 &a) { return *this = (I32vec2) _m_por(vec,a); }
  127. I32vec2& operator^=(const M64 &a) { return *this = (I32vec2) _m_pxor(vec,a); }
  128. /* Addition & Subtraction Assignment Operators */
  129. I32vec2& operator +=(const I32vec2 &a) { return *this = (I32vec2) _m_paddd(vec,a); }
  130. I32vec2& operator -=(const I32vec2 &a) { return *this = (I32vec2) _m_psubd(vec,a); }
  131. /* Shift Logical Operators */
  132. I32vec2 operator<<(const I32vec2 &a) { return _m_pslld(vec,a); }
  133. I32vec2 operator<<(int count) { return _m_pslldi(vec,count); }
  134. I32vec2& operator<<=(const I32vec2 &a) { return *this = (I32vec2) _m_pslld(vec,a); }
  135. I32vec2& operator<<=(int count) { return *this = (I32vec2) _m_pslldi(vec,count); }
  136. };
  137. /* Compare For Equality */
  138. inline I32vec2 cmpeq(const I32vec2 &a, const I32vec2 &b) { return _m_pcmpeqd(a,b); }
  139. inline I32vec2 cmpneq(const I32vec2 &a, const I32vec2 &b) { return _m_pandn(_m_pcmpeqd(a,b), M64(0xffffffffffffffffi64)); }
  140. /* Unpacks */
  141. inline I32vec2 unpack_low(const I32vec2 &a, const I32vec2 &b) {return _m_punpckldq(a,b); }
  142. inline I32vec2 unpack_high(const I32vec2 &a, const I32vec2 &b) {return _m_punpckhdq(a,b); }
  143. /* Is32vec2 Class:
  144. * 2 elements, each element a signed int
  145. */
  146. class Is32vec2 : public I32vec2
  147. {
  148. public:
  149. Is32vec2() { }
  150. Is32vec2(__m64 mm) : I32vec2(mm) { }
  151. Is32vec2(signed int i0, signed int i1)
  152. {
  153. _MM_2DW(0,vec) = i1;
  154. _MM_2DW(1,vec) = i0;
  155. }
  156. EXPLICIT Is32vec2(int i) : I32vec2 (i) {}
  157. EXPLICIT Is32vec2(__int64 i): I32vec2(i) {}
  158. /* Assignment Operator */
  159. Is32vec2& operator= (const M64 &a) { return *this = (Is32vec2) a; }
  160. /* Logical Assignment Operators */
  161. Is32vec2& operator&=(const M64 &a) { return *this = (Is32vec2) _m_pand(vec,a); }
  162. Is32vec2& operator|=(const M64 &a) { return *this = (Is32vec2) _m_por(vec,a); }
  163. Is32vec2& operator^=(const M64 &a) { return *this = (Is32vec2) _m_pxor(vec,a); }
  164. /* Addition & Subtraction Assignment Operators */
  165. Is32vec2& operator +=(const I32vec2 &a) { return *this = (Is32vec2) _m_paddd(vec,a); }
  166. Is32vec2& operator -=(const I32vec2 &a) { return *this = (Is32vec2) _m_psubd(vec,a); }
  167. /* Shift Logical Operators */
  168. Is32vec2 operator<<(const M64 &a) { return _m_pslld(vec,a); }
  169. Is32vec2 operator<<(int count) { return _m_pslldi(vec,count); }
  170. Is32vec2& operator<<=(const M64 &a) { return *this = (Is32vec2) _m_pslld(vec,a); }
  171. Is32vec2& operator<<=(int count) { return *this = (Is32vec2) _m_pslldi(vec,count); }
  172. /* Shift Arithmetic Operations */
  173. Is32vec2 operator>>(const M64 &a) { return _m_psrad(vec, a); }
  174. Is32vec2 operator>>(int count) { return _m_psradi(vec, count); }
  175. Is32vec2& operator>>=(const M64 &a) { return *this = (Is32vec2) _m_psrad(vec, a); }
  176. Is32vec2& operator>>=(int count) { return *this = (Is32vec2) _m_psradi(vec, count); }
  177. #if defined(_ENABLE_VEC_DEBUG)
  178. /* Output for Debug */
  179. friend std::ostream& operator<< (std::ostream &os, const Is32vec2 &a)
  180. {
  181. os << " [1]:" << _MM_2DW(1,a)
  182. << " [0]:" << _MM_2DW(0,a);
  183. return os;
  184. }
  185. #endif
  186. /* Element Access for Debug, No data modified */
  187. const int& operator[](int i)const
  188. {
  189. assert(static_cast<unsigned int>(i) < 2); /* Only 2 elements to access */
  190. return _MM_2DW(i,vec);
  191. }
  192. /* Element Access and Assignment for Debug */
  193. int& operator[](int i)
  194. {
  195. assert(static_cast<unsigned int>(i) < 2); /* Only 2 elements to access */
  196. return _MM_2DW(i,vec);
  197. }
  198. };
  199. /* Compares */
  200. inline Is32vec2 cmpeq(const Is32vec2 &a, const Is32vec2 &b) { return _m_pcmpeqd(a,b); }
  201. inline Is32vec2 cmpneq(const Is32vec2 &a, const Is32vec2 &b) { return _m_pandn(_m_pcmpeqd(a,b), M64(0xffffffffffffffffi64)); }
  202. inline Is32vec2 cmpgt(const Is32vec2 &a, const Is32vec2 &b) { return _m_pcmpgtd(a,b); }
  203. inline Is32vec2 cmplt(const Is32vec2 &a, const Is32vec2 &b) { return _m_pcmpgtd(b,a); }
  204. inline Is32vec2 cmple(const Is32vec2 &a, const Is32vec2 &b) { return _m_pandn(_m_pcmpgtd(a,b), M64(0xffffffffffffffffi64)); }
  205. inline Is32vec2 cmpge(const Is32vec2 &a, const Is32vec2 &b) { return _m_pandn(_m_pcmpgtd(b,a), M64(0xffffffffffffffffi64)); }
  206. /* Unpacks & Pack */
  207. inline Is32vec2 unpack_low(const Is32vec2 &a, const Is32vec2 &b) { return _m_punpckldq(a,b); }
  208. inline Is32vec2 unpack_high(const Is32vec2 &a, const Is32vec2 &b) { return _m_punpckhdq(a,b); }
  209. /* Iu32vec2 Class:
  210. * 2 elements, each element unsigned int
  211. */
  212. class Iu32vec2 : public I32vec2
  213. {
  214. public:
  215. Iu32vec2() { }
  216. Iu32vec2(__m64 mm) : I32vec2(mm) { }
  217. Iu32vec2(unsigned int ui0, unsigned int ui1)
  218. {
  219. _MM_2UDW(0,vec) = ui1;
  220. _MM_2UDW(1,vec) = ui0;
  221. }
  222. EXPLICIT Iu32vec2(int i) : I32vec2 (i) { }
  223. EXPLICIT Iu32vec2(__int64 i) : I32vec2 (i) { }
  224. /* Assignment Operator */
  225. Iu32vec2& operator= (const M64 &a) { return *this = (Iu32vec2) a; }
  226. /* Logical Assignment Operators */
  227. Iu32vec2& operator&=(const M64 &a) { return *this = (Iu32vec2) _m_pand(vec,a); }
  228. Iu32vec2& operator|=(const M64 &a) { return *this = (Iu32vec2) _m_por(vec,a); }
  229. Iu32vec2& operator^=(const M64 &a) { return *this = (Iu32vec2) _m_pxor(vec,a); }
  230. /* Addition & Subtraction Assignment Operators */
  231. Iu32vec2& operator +=(const I32vec2 &a) { return *this = (Iu32vec2) _m_paddd(vec,a); }
  232. Iu32vec2& operator -=(const I32vec2 &a) { return *this = (Iu32vec2) _m_psubd(vec,a); }
  233. /* Shift Logical Operators */
  234. Iu32vec2 operator<<(const M64 &a) { return _m_pslld(vec,a); }
  235. Iu32vec2 operator<<(int count) { return _m_pslldi(vec,count); }
  236. Iu32vec2& operator<<=(const M64 &a) { return *this = (Iu32vec2) _m_pslld(vec,a); }
  237. Iu32vec2& operator<<=(int count) { return *this = (Iu32vec2) _m_pslldi(vec,count); }
  238. Iu32vec2 operator>>(const M64 &a) { return _m_psrld(vec,a); }
  239. Iu32vec2 operator>>(int count) { return _m_psrldi(vec,count); }
  240. Iu32vec2& operator>>=(const M64 &a) { return *this = (Iu32vec2) _m_psrld(vec,a); }
  241. Iu32vec2& operator>>=(int count) { return *this = (Iu32vec2) _m_psrldi(vec,count); }
  242. #if defined(_ENABLE_VEC_DEBUG)
  243. /* Output for Debug */
  244. friend std::ostream& operator<< (std::ostream &os, const Iu32vec2 &a)
  245. {
  246. os << " [1]:" << _MM_2UDW(1,a)
  247. << " [0]:" << _MM_2UDW(0,a);
  248. return os;
  249. }
  250. #endif
  251. /* Element Access for Debug, No data modified */
  252. const unsigned int& operator[](int i)const
  253. {
  254. assert(static_cast<unsigned int>(i) < 2); /* Only 2 elements to access */
  255. return _MM_2UDW(i,vec);
  256. }
  257. /* Element Access and Assignment for Debug */
  258. unsigned int& operator[](int i)
  259. {
  260. assert(static_cast<unsigned int>(i) < 2); /* Only 2 elements to access */
  261. return _MM_2UDW(i,vec);
  262. }
  263. };
  264. /* Compares For Equality / Inequality */
  265. inline Iu32vec2 cmpeq(const Iu32vec2 &a, const Iu32vec2 &b) { return _m_pcmpeqd(a,b); }
  266. inline Iu32vec2 cmpneq(const Iu32vec2 &a, const Iu32vec2 &b) { return _m_pandn(_m_pcmpeqd(a,b), M64(0xffffffffffffffffi64)); }
  267. /* Unpacks */
  268. inline Iu32vec2 unpack_low(const Iu32vec2 &a, const Iu32vec2 &b) {return _m_punpckldq(a,b); }
  269. inline Iu32vec2 unpack_high(const Iu32vec2 &a, const Iu32vec2 &b) {return _m_punpckhdq(a,b); }
  270. /* I16vec4 Class:
  271. * 4 elements, each element either a signed or unsigned short
  272. */
  273. class I16vec4 : public M64
  274. {
  275. public:
  276. I16vec4() { }
  277. I16vec4(__m64 mm) : M64(mm) { }
  278. EXPLICIT I16vec4(__int64 i) : M64 (i) { }
  279. EXPLICIT I16vec4(int i) : M64 (i) { }
  280. /* Assignment Operator */
  281. I16vec4& operator= (const M64 &a) { return *this = (I16vec4) a; }
  282. /* Addition & Subtraction Assignment Operators */
  283. I16vec4& operator&=(const M64 &a) { return *this = (I16vec4) _m_pand(vec,a); }
  284. I16vec4& operator|=(const M64 &a) { return *this = (I16vec4) _m_por(vec,a); }
  285. I16vec4& operator^=(const M64 &a) { return *this = (I16vec4) _m_pxor(vec,a); }
  286. /* Addition & Subtraction Assignment Operators */
  287. I16vec4& operator +=(const I16vec4 &a) { return *this = (I16vec4)_m_paddw(vec,a); }
  288. I16vec4& operator -=(const I16vec4 &a) { return *this = (I16vec4)_m_psubw(vec,a); }
  289. I16vec4& operator *=(const I16vec4 &a) { return *this = (I16vec4)_m_pmullw(vec,a); }
  290. /* Shift Logical Operators */
  291. I16vec4 operator<<(const I16vec4 &a) { return _m_psllw(vec,a); }
  292. I16vec4 operator<<(int count) { return _m_psllwi(vec,count); }
  293. I16vec4& operator<<=(const I16vec4 &a) { return *this = (I16vec4)_m_psllw(vec,a); }
  294. I16vec4& operator<<=(int count) { return *this = (I16vec4)_m_psllwi(vec,count); }
  295. };
  296. inline I16vec4 operator*(const I16vec4 &a, const I16vec4 &b) { return _m_pmullw(a,b); }
  297. inline I16vec4 cmpeq(const I16vec4 &a, const I16vec4 &b) { return _m_pcmpeqw(a,b); }
  298. inline I16vec4 cmpneq(const I16vec4 &a, const I16vec4 &b) { return _m_pandn(_m_pcmpeqw(a,b), M64(0xffffffffffffffffi64)); }
  299. inline I16vec4 unpack_low(const I16vec4 &a, const I16vec4 &b) { return _m_punpcklwd(a,b); }
  300. inline I16vec4 unpack_high(const I16vec4 &a, const I16vec4 &b) { return _m_punpckhwd(a,b); }
  301. /* Is16vec4 Class:
  302. * 4 elements, each element signed short
  303. */
  304. class Is16vec4 : public I16vec4
  305. {
  306. public:
  307. Is16vec4() { }
  308. Is16vec4(__m64 mm) : I16vec4(mm) { }
  309. Is16vec4(short i0, short i1, short i2, short i3)
  310. {
  311. _MM_4W(0,vec) = i3;
  312. _MM_4W(1,vec) = i2;
  313. _MM_4W(2,vec) = i1;
  314. _MM_4W(3,vec) = i0;
  315. }
  316. EXPLICIT Is16vec4(__int64 i) : I16vec4 (i) { }
  317. EXPLICIT Is16vec4(int i) : I16vec4 (i) { }
  318. /* Assignment Operator */
  319. Is16vec4& operator= (const M64 &a) { return *this = (Is16vec4) a; }
  320. /* Addition & Subtraction Assignment Operators */
  321. Is16vec4& operator&=(const M64 &a) { return *this = (Is16vec4) _m_pand(vec,a); }
  322. Is16vec4& operator|=(const M64 &a) { return *this = (Is16vec4) _m_por(vec,a); }
  323. Is16vec4& operator^=(const M64 &a) { return *this = (Is16vec4) _m_pxor(vec,a); }
  324. /* Addition & Subtraction Assignment Operators */
  325. Is16vec4& operator +=(const I16vec4 &a) { return *this = (Is16vec4)_m_paddw(vec,a); }
  326. Is16vec4& operator -=(const I16vec4 &a) { return *this = (Is16vec4)_m_psubw(vec,a); }
  327. Is16vec4& operator *=(const I16vec4 &a) { return *this = (Is16vec4)_m_pmullw(vec,a); }
  328. /* Shift Logical Operators */
  329. Is16vec4 operator<<(const M64 &a) { return _m_psllw(vec,a); }
  330. Is16vec4 operator<<(int count) { return _m_psllwi(vec,count); }
  331. Is16vec4& operator<<=(const M64 &a) { return *this = (Is16vec4)_m_psllw(vec,a); }
  332. Is16vec4& operator<<=(int count) { return *this = (Is16vec4)_m_psllwi(vec,count); }
  333. /* Shift Arithmetic Operations */
  334. Is16vec4 operator>>(const M64 &a) { return _m_psraw(vec,a); }
  335. Is16vec4 operator>>(int count) { return _m_psrawi(vec,count); }
  336. Is16vec4& operator>>=(const M64 &a) { return *this = (Is16vec4) _m_psraw(vec,a); }
  337. Is16vec4& operator>>=(int count) { return *this = (Is16vec4) _m_psrawi(vec,count); }
  338. #if defined(_ENABLE_VEC_DEBUG)
  339. /* Output for Debug */
  340. friend std::ostream& operator<< (std::ostream &os, const Is16vec4 &a)
  341. {
  342. os << "[3]:" << _MM_4W(3,a)
  343. << " [2]:" << _MM_4W(2,a)
  344. << " [1]:" << _MM_4W(1,a)
  345. << " [0]:" << _MM_4W(0,a);
  346. return os;
  347. }
  348. #endif
  349. /* Element Access for Debug, No data modified */
  350. const short& operator[](int i)const
  351. {
  352. assert(static_cast<unsigned int>(i) < 4); /* Only 4 elements to access */
  353. return _MM_4W(i,vec);
  354. }
  355. /* Element Access for Debug */
  356. short& operator[](int i)
  357. {
  358. assert(static_cast<unsigned int>(i) < 4); /* Only 4 elements to access */
  359. return _MM_4W(i,vec);
  360. }
  361. };
  362. inline Is16vec4 operator*(const Is16vec4 &a, const Is16vec4 &b) { return _m_pmullw(a,b); }
  363. /* Compares */
  364. inline Is16vec4 cmpeq(const Is16vec4 &a, const Is16vec4 &b) { return _m_pcmpeqw(a,b); }
  365. inline Is16vec4 cmpneq(const Is16vec4 &a, const Is16vec4 &b) { return _m_pandn(_m_pcmpeqw(a,b), M64(0xffffffffffffffffi64)); }
  366. inline Is16vec4 cmpgt(const Is16vec4 &a, const Is16vec4 &b) { return _m_pcmpgtw(a,b); }
  367. inline Is16vec4 cmplt(const Is16vec4 &a, const Is16vec4 &b) { return _m_pcmpgtw(b,a); }
  368. inline Is16vec4 cmple(const Is16vec4 &a, const Is16vec4 &b) { return _m_pandn(_m_pcmpgtw(a,b), M64(0xffffffffffffffffi64)); }
  369. inline Is16vec4 cmpge(const Is16vec4 &a, const Is16vec4 &b) { return _m_pandn(_m_pcmpgtw(b,a), M64(0xffffffffffffffffi64)); }
  370. /* Unpacks */
  371. inline Is16vec4 unpack_low(const Is16vec4 &a, const Is16vec4 &b) { return _m_punpcklwd(a,b); }
  372. inline Is16vec4 unpack_high(const Is16vec4 &a, const Is16vec4 &b) { return _m_punpckhwd(a,b); }
  373. inline Is16vec4 sat_add(const Is16vec4 &a, const Is16vec4 &b) { return _m_paddsw(a,b); }
  374. inline Is16vec4 sat_sub(const Is16vec4 &a, const Is16vec4 &b) { return _m_psubsw(a,b); }
  375. inline Is16vec4 mul_high(const Is16vec4 &a, const Is16vec4 &b) { return _m_pmulhw(a,b); }
  376. inline Is32vec2 mul_add(const Is16vec4 &a, const Is16vec4 &b) { return _m_pmaddwd(a,b);}
  377. /* Iu16vec4 Class:
  378. * 4 elements, each element unsigned short
  379. */
  380. class Iu16vec4 : public I16vec4
  381. {
  382. public:
  383. Iu16vec4() { }
  384. Iu16vec4(__m64 mm) : I16vec4(mm) { }
  385. Iu16vec4(unsigned short ui0, unsigned short ui1, unsigned short ui2, unsigned short ui3)
  386. {
  387. _MM_4UW(0,vec) = ui3;
  388. _MM_4UW(1,vec) = ui2;
  389. _MM_4UW(2,vec) = ui1;
  390. _MM_4UW(3,vec) = ui0;
  391. }
  392. EXPLICIT Iu16vec4(__int64 i) : I16vec4 (i) { }
  393. EXPLICIT Iu16vec4(int i) : I16vec4 (i) { }
  394. /* Assignment Operator */
  395. Iu16vec4& operator= (const M64 &a) { return *this = (Iu16vec4) a; }
  396. /* Logical Assignment Operators */
  397. Iu16vec4& operator&=(const M64 &a) { return *this = (Iu16vec4) _m_pand(vec,a); }
  398. Iu16vec4& operator|=(const M64 &a) { return *this = (Iu16vec4) _m_por(vec,a); }
  399. Iu16vec4& operator^=(const M64 &a) { return *this = (Iu16vec4) _m_pxor(vec,a); }
  400. /* Addition & Subtraction Assignment Operators */
  401. Iu16vec4& operator +=(const I16vec4 &a) { return *this = (Iu16vec4)_m_paddw(vec,a); }
  402. Iu16vec4& operator -=(const I16vec4 &a) { return *this = (Iu16vec4)_m_psubw(vec,a); }
  403. Iu16vec4& operator *=(const I16vec4 &a) { return *this = (Iu16vec4)_m_pmullw(vec,a); }
  404. /* Shift Logical Operators */
  405. Iu16vec4 operator<<(const M64 &a) { return _m_psllw(vec,a); }
  406. Iu16vec4 operator<<(int count) { return _m_psllwi(vec,count); }
  407. Iu16vec4& operator<<=(const M64 &a) { return *this = (Iu16vec4)_m_psllw(vec,a); }
  408. Iu16vec4& operator<<=(int count) { return *this = (Iu16vec4)_m_psllwi(vec,count); }
  409. Iu16vec4 operator>>(const M64 &a) { return _m_psrlw(vec,a); }
  410. Iu16vec4 operator>>(int count) { return _m_psrlwi(vec,count); }
  411. Iu16vec4& operator>>=(const M64 &a) { return *this = (Iu16vec4) _m_psrlw(vec,a); }
  412. Iu16vec4& operator>>=(int count) { return *this = (Iu16vec4) _m_psrlwi(vec,count); }
  413. #if defined(_ENABLE_VEC_DEBUG)
  414. /* Output for Debug */
  415. friend std::ostream& operator<< (std::ostream &os, const Iu16vec4 &a)
  416. {
  417. os << "[3]:" << _MM_4UW(3,a)
  418. << " [2]:" << _MM_4UW(2,a)
  419. << " [1]:" << _MM_4UW(1,a)
  420. << " [0]:" << _MM_4UW(0,a);
  421. return os;
  422. }
  423. #endif
  424. /* Element Access for Debug, No data modified */
  425. const unsigned short& operator[](int i)const
  426. {
  427. assert(static_cast<unsigned int>(i) < 4); /* Only 4 elements to access */
  428. return _MM_4UW(i,vec);
  429. }
  430. /* Element Access and Assignment for Debug */
  431. unsigned short& operator[](int i)
  432. {
  433. assert(static_cast<unsigned int>(i) < 4); /* Only 4 elements to access */
  434. return _MM_4UW(i,vec);
  435. }
  436. };
  437. inline Iu16vec4 operator*(const Iu16vec4 &a, const Iu16vec4 &b) { return _m_pmullw(a,b); }
  438. inline Iu16vec4 cmpeq(const Iu16vec4 &a, const Iu16vec4 &b) { return _m_pcmpeqw(a,b); }
  439. inline Iu16vec4 cmpneq(const Iu16vec4 &a, const Iu16vec4 &b) { return _m_pandn(_m_pcmpeqw(a,b), M64(0xffffffffffffffffi64)); }
  440. inline Iu16vec4 sat_add(const Iu16vec4 &a, const Iu16vec4 &b) { return _m_paddusw(a,b); }
  441. inline Iu16vec4 sat_sub(const Iu16vec4 &a, const Iu16vec4 &b) { return _m_psubusw(a,b); }
  442. inline Iu16vec4 unpack_low(const Iu16vec4 &a, const Iu16vec4 &b) { return _m_punpcklwd(a,b); }
  443. inline Iu16vec4 unpack_high(const Iu16vec4 &a, const Iu16vec4 &b) { return _m_punpckhwd(a,b); }
  444. /* I8vec8 Class:
  445. * 8 elements, each element either unsigned or signed char
  446. */
  447. class I8vec8 : public M64
  448. {
  449. public:
  450. I8vec8() { }
  451. I8vec8(__m64 mm) : M64(mm) { }
  452. EXPLICIT I8vec8(__int64 i) : M64 (i) { }
  453. EXPLICIT I8vec8(int i) : M64 (i) { }
  454. /* Assignment Operator */
  455. I8vec8& operator= (const M64 &a) { return *this = (I8vec8) a; }
  456. /* Logical Assignment Operators */
  457. I8vec8& operator&=(const M64 &a) { return *this = (I8vec8) _m_pand(vec,a); }
  458. I8vec8& operator|=(const M64 &a) { return *this = (I8vec8) _m_por(vec,a); }
  459. I8vec8& operator^=(const M64 &a) { return *this = (I8vec8) _m_pxor(vec,a); }
  460. /* Addition & Subtraction Assignment Operators */
  461. I8vec8& operator +=(const I8vec8 &a) { return *this = (I8vec8) _m_paddb(vec,a); }
  462. I8vec8& operator -=(const I8vec8 &a) { return *this = (I8vec8) _m_psubb(vec,a); }
  463. };
  464. inline I8vec8 cmpeq(const I8vec8 &a, const I8vec8 &b) { return _m_pcmpeqb(a,b); }
  465. inline I8vec8 cmpneq(const I8vec8 &a, const I8vec8 &b) { return _m_pandn(_m_pcmpeqb(a,b), M64(0xffffffffffffffffi64)); }
  466. inline I8vec8 unpack_low(const I8vec8 &a, const I8vec8 &b) { return _m_punpcklbw(a,b); }
  467. inline I8vec8 unpack_high(const I8vec8 &a, const I8vec8 &b) { return _m_punpckhbw(a,b); }
  468. /* Is8vec8 Class:
  469. * 8 elements, each element signed char
  470. */
  471. class Is8vec8 : public I8vec8
  472. {
  473. public:
  474. Is8vec8() { }
  475. Is8vec8(__m64 mm) : I8vec8(mm) { }
  476. 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)
  477. {
  478. _MM_8B(0,vec) = s7;
  479. _MM_8B(1,vec) = s6;
  480. _MM_8B(2,vec) = s5;
  481. _MM_8B(3,vec) = s4;
  482. _MM_8B(4,vec) = s3;
  483. _MM_8B(5,vec) = s2;
  484. _MM_8B(6,vec) = s1;
  485. _MM_8B(7,vec) = s0;
  486. }
  487. EXPLICIT Is8vec8(__int64 i) : I8vec8 (i) { }
  488. EXPLICIT Is8vec8(int i) : I8vec8 (i) { }
  489. /* Assignment Operator */
  490. Is8vec8& operator= (const M64 &a) { return *this = (Is8vec8) a; }
  491. /* Logical Assignment Operators */
  492. Is8vec8& operator&=(const M64 &a) { return *this = (Is8vec8) _m_pand(vec,a); }
  493. Is8vec8& operator|=(const M64 &a) { return *this = (Is8vec8) _m_por(vec,a); }
  494. Is8vec8& operator^=(const M64 &a) { return *this = (Is8vec8) _m_pxor(vec,a); }
  495. /* Addition & Subtraction Assignment Operators */
  496. Is8vec8& operator +=(const I8vec8 &a) { return *this = (Is8vec8) _m_paddb(vec,a); }
  497. Is8vec8& operator -=(const I8vec8 &a) { return *this = (Is8vec8) _m_psubb(vec,a); }
  498. #if defined(_ENABLE_VEC_DEBUG)
  499. /* Output for Debug */
  500. friend std::ostream& operator<< (std::ostream &os, const Is8vec8 &a)
  501. {
  502. os << "[7]:" << short(_MM_8B(7,a))
  503. << " [6]:" << short(_MM_8B(6,a))
  504. << " [5]:" << short(_MM_8B(5,a))
  505. << " [4]:" << short(_MM_8B(4,a))
  506. << " [3]:" << short(_MM_8B(3,a))
  507. << " [2]:" << short(_MM_8B(2,a))
  508. << " [1]:" << short(_MM_8B(1,a))
  509. << " [0]:" << short(_MM_8B(0,a));
  510. return os;
  511. }
  512. #endif
  513. /* Element Access for Debug, No data modified */
  514. const signed char& operator[](int i)const
  515. {
  516. assert(static_cast<unsigned int>(i) < 8); /* Only 8 elements to access */
  517. return _MM_8B(i,vec);
  518. }
  519. /* Element Access and Assignment for Debug */
  520. signed char& operator[](int i)
  521. {
  522. assert(static_cast<unsigned int>(i) < 8); /* Only 8 elements to access */
  523. return _MM_8B(i,vec);
  524. }
  525. };
  526. /* Additional Is8vec8 functions: compares, unpacks, sat add/sub */
  527. inline Is8vec8 cmpeq(const Is8vec8 &a, const Is8vec8 &b) { return _m_pcmpeqb(a,b); }
  528. inline Is8vec8 cmpneq(const Is8vec8 &a, const Is8vec8 &b) { return _m_pandn(_m_pcmpeqb(a,b), M64(0xffffffffffffffffi64)); }
  529. inline Is8vec8 cmpgt(const Is8vec8 &a, const Is8vec8 &b) { return _m_pcmpgtb(a,b); }
  530. inline Is8vec8 cmplt(const Is8vec8 &a, const Is8vec8 &b) { return _m_pcmpgtb(b,a); }
  531. inline Is8vec8 cmple(const Is8vec8 &a, const Is8vec8 &b) { return _m_pandn(_m_pcmpgtb(a,b), M64(0xffffffffffffffffi64)); }
  532. inline Is8vec8 cmpge(const Is8vec8 &a, const Is8vec8 &b) { return _m_pandn(_m_pcmpgtb(b,a), M64(0xffffffffffffffffi64)); }
  533. inline Is8vec8 unpack_low(const Is8vec8 &a, const Is8vec8 &b) { return _m_punpcklbw(a,b); }
  534. inline Is8vec8 unpack_high(const Is8vec8 &a, const Is8vec8 &b) { return _m_punpckhbw(a,b); }
  535. inline Is8vec8 sat_add(const Is8vec8 &a, const Is8vec8 &b) { return _m_paddsb(a,b); }
  536. inline Is8vec8 sat_sub(const Is8vec8 &a, const Is8vec8 &b) { return _m_psubsb(a,b); }
  537. /* Iu8vec8 Class:
  538. * 8 elements, each element unsigned char
  539. */
  540. class Iu8vec8 : public I8vec8
  541. {
  542. public:
  543. Iu8vec8() { }
  544. Iu8vec8(__m64 mm) : I8vec8(mm) { }
  545. 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)
  546. {
  547. _MM_8UB(0,vec) = s7;
  548. _MM_8UB(1,vec) = s6;
  549. _MM_8UB(2,vec) = s5;
  550. _MM_8UB(3,vec) = s4;
  551. _MM_8UB(4,vec) = s3;
  552. _MM_8UB(5,vec) = s2;
  553. _MM_8UB(6,vec) = s1;
  554. _MM_8UB(7,vec) = s0;
  555. }
  556. EXPLICIT Iu8vec8(__int64 i) : I8vec8 (i) { }
  557. EXPLICIT Iu8vec8(int i) : I8vec8 (i) { }
  558. /* Assignment Operator */
  559. Iu8vec8& operator= (const M64 &a) { return *this = (Iu8vec8) a; }
  560. /* Logical Assignment Operators */
  561. Iu8vec8& operator&=(const M64 &a) { return *this = (Iu8vec8) _m_pand(vec,a); }
  562. Iu8vec8& operator|=(const M64 &a) { return *this = (Iu8vec8) _m_por(vec,a); }
  563. Iu8vec8& operator^=(const M64 &a) { return *this = (Iu8vec8) _m_pxor(vec,a); }
  564. /* Addition & Subtraction Assignment Operators */
  565. Iu8vec8& operator +=(const I8vec8 &a) { return *this = (Iu8vec8) _m_paddb(vec,a); }
  566. Iu8vec8& operator -=(const I8vec8 &a) { return *this = (Iu8vec8) _m_psubb(vec,a); }
  567. #if defined(_ENABLE_VEC_DEBUG)
  568. /* Output for Debug */
  569. friend std::ostream& operator << (std::ostream &os, const Iu8vec8 &a)
  570. {
  571. os << "[7]:" << unsigned short(_MM_8UB(7,a))
  572. << " [6]:" << unsigned short(_MM_8UB(6,a))
  573. << " [5]:" << unsigned short(_MM_8UB(5,a))
  574. << " [4]:" << unsigned short(_MM_8UB(4,a))
  575. << " [3]:" << unsigned short(_MM_8UB(3,a))
  576. << " [2]:" << unsigned short(_MM_8UB(2,a))
  577. << " [1]:" << unsigned short(_MM_8UB(1,a))
  578. << " [0]:" << unsigned short(_MM_8UB(0,a));
  579. return os;
  580. }
  581. #endif
  582. /* Element Access for Debug, No data modified */
  583. const unsigned char& operator[](int i)const
  584. {
  585. assert(static_cast<unsigned int>(i) < 8); /* Only 8 elements to access */
  586. return _MM_8UB(i,vec);
  587. }
  588. /* Element Access for Debug */
  589. unsigned char& operator[](int i)
  590. {
  591. assert(static_cast<unsigned int>(i) < 8); /* Only 8 elements to access */
  592. return _MM_8UB(i,vec);
  593. }
  594. };
  595. /* Additional Iu8vec8 functions: cmpeq,cmpneq, unpacks, sat add/sub */
  596. inline Iu8vec8 cmpeq(const Iu8vec8 &a, const Iu8vec8 &b) { return _m_pcmpeqb(a,b); }
  597. inline Iu8vec8 cmpneq(const Iu8vec8 &a, const Iu8vec8 &b) { return _m_pandn(_m_pcmpeqb(a,b), M64(0xffffffffffffffffi64)); }
  598. inline Iu8vec8 unpack_low(const Iu8vec8 &a, const Iu8vec8 &b) { return _m_punpcklbw(a,b); }
  599. inline Iu8vec8 unpack_high(const Iu8vec8 &a, const Iu8vec8 &b) { return _m_punpckhbw(a,b); }
  600. inline Iu8vec8 sat_add(const Iu8vec8 &a, const Iu8vec8 &b) { return _m_paddusb(a,b); }
  601. inline Iu8vec8 sat_sub(const Iu8vec8 &a, const Iu8vec8 &b) { return _m_psubusb(a,b); }
  602. inline Is16vec4 pack_sat(const Is32vec2 &a, const Is32vec2 &b) { return _m_packssdw(a,b); }
  603. inline Is8vec8 pack_sat(const Is16vec4 &a, const Is16vec4 &b) { return _m_packsswb(a,b); }
  604. inline Iu8vec8 packu_sat(const Is16vec4 &a, const Is16vec4 &b) { return _m_packuswb(a,b); }
  605. /********************************* Logicals ****************************************/
  606. #define IVEC_LOGICALS(vect,element) \
  607. inline I##vect##vec##element operator& (const I##vect##vec##element &a, const I##vect##vec##element &b) \
  608. { return _m_pand( a,b); } \
  609. inline I##vect##vec##element operator| (const I##vect##vec##element &a, const I##vect##vec##element &b) \
  610. { return _m_por( a,b); } \
  611. inline I##vect##vec##element operator^ (const I##vect##vec##element &a, const I##vect##vec##element &b) \
  612. { return _m_pxor( a,b); } \
  613. inline I##vect##vec##element andnot (const I##vect##vec##element &a, const I##vect##vec##element &b) \
  614. { return _m_pandn( a,b); }
  615. IVEC_LOGICALS(8,8)
  616. IVEC_LOGICALS(u8,8)
  617. IVEC_LOGICALS(s8,8)
  618. IVEC_LOGICALS(16,4)
  619. IVEC_LOGICALS(u16,4)
  620. IVEC_LOGICALS(s16,4)
  621. IVEC_LOGICALS(32,2)
  622. IVEC_LOGICALS(u32,2)
  623. IVEC_LOGICALS(s32,2)
  624. IVEC_LOGICALS(64,1)
  625. #undef IVEC_LOGICALS
  626. /********************************* Add & Sub ****************************************/
  627. #define IVEC_ADD_SUB(vect,element,opsize) \
  628. inline I##vect##vec##element operator+ (const I##vect##vec##element &a, const I##vect##vec##element &b) \
  629. { return _m_padd##opsize( a,b); } \
  630. inline I##vect##vec##element operator- (const I##vect##vec##element &a, const I##vect##vec##element &b) \
  631. { return _m_psub##opsize( a,b); }
  632. IVEC_ADD_SUB(8,8, b)
  633. IVEC_ADD_SUB(u8,8, b)
  634. IVEC_ADD_SUB(s8,8, b)
  635. IVEC_ADD_SUB(16,4, w)
  636. IVEC_ADD_SUB(u16,4, w)
  637. IVEC_ADD_SUB(s16,4, w)
  638. IVEC_ADD_SUB(32,2, d)
  639. IVEC_ADD_SUB(u32,2, d)
  640. IVEC_ADD_SUB(s32,2, d)
  641. #undef IVEC_ADD_SUB
  642. /********************************* Conditional Select ****************************************/
  643. /* version of: retval = (a OP b)? c : d; *
  644. * Where OP is one of the possible comparision operators. *
  645. * Example: r = select_eq(a,b,c,d); *
  646. * if "member at position x of the vector a" == "member at position x of vector b" *
  647. * assign the corresponding member in r from c, else assign from d. *
  648. ********************************* Conditional Select ****************************************/
  649. #define IVEC_SELECT(vect12,vect34,element,selop,arg1,arg2) \
  650. 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) \
  651. { \
  652. I##vect12##vec##element mask = cmp##selop(a,b); \
  653. return( I##vect34##vec##element ((mask & arg1 ) | I##vect12##vec##element ((_m_pandn(mask, arg2 ))))); \
  654. }
  655. IVEC_SELECT(8,s8,8,eq,c,d)
  656. IVEC_SELECT(8,u8,8,eq,c,d)
  657. IVEC_SELECT(8,8,8,eq,c,d)
  658. IVEC_SELECT(8,s8,8,neq,c,d)
  659. IVEC_SELECT(8,u8,8,neq,c,d)
  660. IVEC_SELECT(8,8,8,neq,c,d)
  661. IVEC_SELECT(16,s16,4,eq,c,d)
  662. IVEC_SELECT(16,u16,4,eq,c,d)
  663. IVEC_SELECT(16,16,4,eq,c,d)
  664. IVEC_SELECT(16,s16,4,neq,c,d)
  665. IVEC_SELECT(16,u16,4,neq,c,d)
  666. IVEC_SELECT(16,16,4,neq,c,d)
  667. IVEC_SELECT(32,s32,2,eq,c,d)
  668. IVEC_SELECT(32,u32,2,eq,c,d)
  669. IVEC_SELECT(32,32,2,eq,c,d)
  670. IVEC_SELECT(32,s32,2,neq,c,d)
  671. IVEC_SELECT(32,u32,2,neq,c,d)
  672. IVEC_SELECT(32,32,2,neq,c,d)
  673. IVEC_SELECT(s8,s8,8,gt,c,d)
  674. IVEC_SELECT(s8,u8,8,gt,c,d)
  675. IVEC_SELECT(s8,8,8,gt,c,d)
  676. IVEC_SELECT(s8,s8,8,lt,c,d)
  677. IVEC_SELECT(s8,u8,8,lt,c,d)
  678. IVEC_SELECT(s8,8,8,lt,c,d)
  679. IVEC_SELECT(s8,s8,8,le,c,d)
  680. IVEC_SELECT(s8,u8,8,le,c,d)
  681. IVEC_SELECT(s8,8,8,le,c,d)
  682. IVEC_SELECT(s8,s8,8,ge,c,d)
  683. IVEC_SELECT(s8,u8,8,ge,c,d)
  684. IVEC_SELECT(s8,8,8,ge,c,d)
  685. IVEC_SELECT(s16,s16,4,gt,c,d)
  686. IVEC_SELECT(s16,u16,4,gt,c,d)
  687. IVEC_SELECT(s16,16,4,gt,c,d)
  688. IVEC_SELECT(s16,s16,4,lt,c,d)
  689. IVEC_SELECT(s16,u16,4,lt,c,d)
  690. IVEC_SELECT(s16,16,4,lt,c,d)
  691. IVEC_SELECT(s16,s16,4,le,c,d)
  692. IVEC_SELECT(s16,u16,4,le,c,d)
  693. IVEC_SELECT(s16,16,4,le,c,d)
  694. IVEC_SELECT(s16,s16,4,ge,c,d)
  695. IVEC_SELECT(s16,u16,4,ge,c,d)
  696. IVEC_SELECT(s16,16,4,ge,c,d)
  697. IVEC_SELECT(s32,s32,2,gt,c,d)
  698. IVEC_SELECT(s32,u32,2,gt,c,d)
  699. IVEC_SELECT(s32,32,2,gt,c,d)
  700. IVEC_SELECT(s32,s32,2,lt,c,d)
  701. IVEC_SELECT(s32,u32,2,lt,c,d)
  702. IVEC_SELECT(s32,32,2,lt,c,d)
  703. IVEC_SELECT(s32,s32,2,le,c,d)
  704. IVEC_SELECT(s32,u32,2,le,c,d)
  705. IVEC_SELECT(s32,32,2,le,c,d)
  706. IVEC_SELECT(s32,s32,2,ge,c,d)
  707. IVEC_SELECT(s32,u32,2,ge,c,d)
  708. IVEC_SELECT(s32,32,2,ge,c,d)
  709. #undef IVEC_SELECT
  710. inline static void empty(void) { _m_empty(); }
  711. #if defined(_SILENCE_IVEC_C4799)
  712. #pragma warning(pop)
  713. #endif
  714. #endif // IVEC_H_INCLUDED