Nessuna descrizione
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.

Sse.cs 56KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. using System;
  2. using System.Diagnostics;
  3. namespace Unity.Burst.Intrinsics
  4. {
  5. public unsafe static partial class X86
  6. {
  7. /// <summary>
  8. /// SSE intrinsics
  9. /// </summary>
  10. public static class Sse
  11. {
  12. /// <summary>
  13. /// Evaluates to true at compile time if SSE intrinsics are supported.
  14. /// </summary>
  15. public static bool IsSseSupported { get { return false; } }
  16. /// <summary>
  17. /// Load 128-bits (composed of 4 packed single-precision (32-bit)
  18. /// floating-point elements) from memory into dst.
  19. /// </summary>
  20. /// <remarks>
  21. /// Burst will always generate unaligned loads.
  22. /// </remarks>
  23. /// <param name="ptr">Pointer</param>
  24. /// <returns>Vector</returns>
  25. [DebuggerStepThrough]
  26. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  27. public static v128 load_ps(void* ptr)
  28. {
  29. return GenericCSharpLoad(ptr);
  30. }
  31. /// <summary>
  32. /// Load 128-bits (composed of 4 packed single-precision (32-bit)
  33. /// floating-point elements) from memory into dst. mem_addr does
  34. /// not need to be aligned on any particular boundary.
  35. /// </summary>
  36. /// <param name="ptr">Pointer</param>
  37. /// <returns>Vector</returns>
  38. [DebuggerStepThrough]
  39. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  40. public static v128 loadu_ps(void* ptr)
  41. {
  42. return GenericCSharpLoad(ptr);
  43. }
  44. /// <summary>
  45. /// Store 128-bits (composed of 4 packed single-precision (32-bit)
  46. /// floating-point elements) from a into memory.
  47. /// </summary>
  48. /// <remarks>
  49. /// Burst will always generate unaligned stores.
  50. /// </remarks>
  51. /// <param name="ptr">Pointer</param>
  52. /// <param name="val">Value vector</param>
  53. [DebuggerStepThrough]
  54. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  55. public static void store_ps(void* ptr, v128 val)
  56. {
  57. GenericCSharpStore(ptr, val);
  58. }
  59. /// <summary>
  60. /// Store 128-bits (composed of 4 packed single-precision (32-bit)
  61. /// floating-point elements) from a into memory. mem_addr does not
  62. /// need to be aligned on any particular boundary.
  63. /// </summary>
  64. /// <param name="ptr">Pointer</param>
  65. /// <param name="val">Value vector</param>
  66. [DebuggerStepThrough]
  67. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  68. public static void storeu_ps(void* ptr, v128 val)
  69. {
  70. GenericCSharpStore(ptr, val);
  71. }
  72. /// <summary>
  73. /// Store 128-bits (composed of 4 packed single-precision (32-bit) floating-point elements) from "a" into memory using a non-temporal memory hint. "mem_addr" must be aligned on a 16-byte boundary or a general-protection exception will be generated.
  74. /// </summary>
  75. /// <param name="mem_addr">Memory address</param>
  76. /// <param name="a">Vector a</param>
  77. [DebuggerStepThrough]
  78. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  79. public static void stream_ps(void* mem_addr, v128 a)
  80. {
  81. GenericCSharpStore(mem_addr, a);
  82. }
  83. // _mm_cvtsi32_ss
  84. /// <summary> Convert the 32-bit integer "b" to a single-precision (32-bit) floating-point element, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  85. /// <param name="a">Vector a</param>
  86. /// <param name="b">32-bit integer</param>
  87. /// <returns>Vector</returns>
  88. [DebuggerStepThrough]
  89. public static v128 cvtsi32_ss(v128 a, int b)
  90. {
  91. v128 dst = a;
  92. dst.Float0 = b;
  93. return dst;
  94. }
  95. // _mm_cvtsi64_ss
  96. /// <summary> Convert the 64-bit integer "b" to a single-precision (32-bit) floating-point element, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  97. /// <param name="a">Vector a</param>
  98. /// <param name="b">64-bit integer</param>
  99. /// <returns>Vector</returns>
  100. [DebuggerStepThrough]
  101. public static v128 cvtsi64_ss(v128 a, long b)
  102. {
  103. v128 dst = a;
  104. dst.Float0 = b;
  105. return dst;
  106. }
  107. // _mm_add_ss
  108. /// <summary> Add the lower single-precision (32-bit) floating-point element in "a" and "b", store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  109. /// <param name="a">Vector a</param>
  110. /// <param name="b">Vector b</param>
  111. /// <returns>Vector</returns>
  112. [DebuggerStepThrough]
  113. public static v128 add_ss(v128 a, v128 b)
  114. {
  115. v128 dst = a;
  116. dst.Float0 = dst.Float0 + b.Float0;
  117. return dst;
  118. }
  119. // _mm_add_ps
  120. /// <summary> Add packed single-precision (32-bit) floating-point elements in "a" and "b", and store the results in "dst". </summary>
  121. /// <param name="a">Vector a</param>
  122. /// <param name="b">Vector b</param>
  123. /// <returns>Vector</returns>
  124. [DebuggerStepThrough]
  125. public static v128 add_ps(v128 a, v128 b)
  126. {
  127. v128 dst = a;
  128. dst.Float0 += b.Float0;
  129. dst.Float1 += b.Float1;
  130. dst.Float2 += b.Float2;
  131. dst.Float3 += b.Float3;
  132. return dst;
  133. }
  134. // _mm_sub_ss
  135. /// <summary> Subtract the lower single-precision (32-bit) floating-point element in "b" from the lower single-precision (32-bit) floating-point element in "a", store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  136. /// <param name="a">Vector a</param>
  137. /// <param name="b">Vector b</param>
  138. /// <returns>Vector</returns>
  139. [DebuggerStepThrough]
  140. public static v128 sub_ss(v128 a, v128 b)
  141. {
  142. v128 dst = a;
  143. dst.Float0 = a.Float0 - b.Float0;
  144. return dst;
  145. }
  146. // _mm_sub_ps
  147. /// <summary> Subtract packed single-precision (32-bit) floating-point elements in "b" from packed single-precision (32-bit) floating-point elements in "a", and store the results in "dst". </summary>
  148. /// <param name="a">Vector a</param>
  149. /// <param name="b">Vector b</param>
  150. /// <returns>Vector</returns>
  151. [DebuggerStepThrough]
  152. public static v128 sub_ps(v128 a, v128 b)
  153. {
  154. v128 dst = a;
  155. dst.Float0 -= b.Float0;
  156. dst.Float1 -= b.Float1;
  157. dst.Float2 -= b.Float2;
  158. dst.Float3 -= b.Float3;
  159. return dst;
  160. }
  161. // _mm_mul_ss
  162. /// <summary> Multiply the lower single-precision (32-bit) floating-point element in "a" and "b", store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  163. /// <param name="a">Vector a</param>
  164. /// <param name="b">Vector b</param>
  165. /// <returns>Vector</returns>
  166. [DebuggerStepThrough]
  167. public static v128 mul_ss(v128 a, v128 b)
  168. {
  169. v128 dst = a;
  170. dst.Float0 = a.Float0 * b.Float0;
  171. return dst;
  172. }
  173. // _mm_mul_ps
  174. /// <summary> Multiply packed single-precision (32-bit) floating-point elements in "a" and "b", and store the results in "dst". </summary>
  175. /// <param name="a">Vector a</param>
  176. /// <param name="b">Vector b</param>
  177. /// <returns>Vector</returns>
  178. [DebuggerStepThrough]
  179. public static v128 mul_ps(v128 a, v128 b)
  180. {
  181. v128 dst = a;
  182. dst.Float0 *= b.Float0;
  183. dst.Float1 *= b.Float1;
  184. dst.Float2 *= b.Float2;
  185. dst.Float3 *= b.Float3;
  186. return dst;
  187. }
  188. // _mm_div_ss
  189. /// <summary> Divide the lower single-precision (32-bit) floating-point element in "a" by the lower single-precision (32-bit) floating-point element in "b", store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  190. /// <param name="a">Vector a</param>
  191. /// <param name="b">Vector b</param>
  192. /// <returns>Vector</returns>
  193. [DebuggerStepThrough]
  194. public static v128 div_ss(v128 a, v128 b)
  195. {
  196. v128 dst = a;
  197. dst.Float0 = a.Float0 / b.Float0;
  198. return dst;
  199. }
  200. // _mm_div_ps
  201. /// <summary> Divide packed single-precision (32-bit) floating-point elements in "a" by packed elements in "b", and store the results in "dst". </summary>
  202. /// <param name="a">Vector a</param>
  203. /// <param name="b">Vector b</param>
  204. /// <returns>Vector</returns>
  205. [DebuggerStepThrough]
  206. public static v128 div_ps(v128 a, v128 b)
  207. {
  208. v128 dst = a;
  209. dst.Float0 /= b.Float0;
  210. dst.Float1 /= b.Float1;
  211. dst.Float2 /= b.Float2;
  212. dst.Float3 /= b.Float3;
  213. return dst;
  214. }
  215. // _mm_sqrt_ss
  216. /// <summary> Compute the square root of the lower single-precision (32-bit) floating-point element in "a", store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  217. /// <param name="a">Vector a</param>
  218. /// <returns>Vector</returns>
  219. [DebuggerStepThrough]
  220. public static v128 sqrt_ss(v128 a)
  221. {
  222. v128 dst = a;
  223. dst.Float0 = (float)Math.Sqrt(a.Float0);
  224. return dst;
  225. }
  226. // _mm_sqrt_ps
  227. /// <summary> Compute the square root of packed single-precision (32-bit) floating-point elements in "a", and store the results in "dst". </summary>
  228. /// <param name="a">Vector a</param>
  229. /// <returns>Vector</returns>
  230. [DebuggerStepThrough]
  231. public static v128 sqrt_ps(v128 a)
  232. {
  233. v128 dst = default(v128);
  234. dst.Float0 = (float)Math.Sqrt(a.Float0);
  235. dst.Float1 = (float)Math.Sqrt(a.Float1);
  236. dst.Float2 = (float)Math.Sqrt(a.Float2);
  237. dst.Float3 = (float)Math.Sqrt(a.Float3);
  238. return dst;
  239. }
  240. // _mm_rcp_ss
  241. /// <summary> Compute the approximate reciprocal of the lower single-precision (32-bit) floating-point element in "a", store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". The maximum relative error for this approximation is less than 1.5*2^-12. </summary>
  242. /// <param name="a">Vector a</param>
  243. /// <returns>Vector</returns>
  244. [DebuggerStepThrough]
  245. public static v128 rcp_ss(v128 a)
  246. {
  247. v128 dst = a;
  248. dst.Float0 = 1.0f / a.Float0;
  249. return dst;
  250. }
  251. // _mm_rcp_ps
  252. /// <summary> Compute the approximate reciprocal of packed single-precision (32-bit) floating-point elements in "a", and store the results in "dst". The maximum relative error for this approximation is less than 1.5*2^-12. </summary>
  253. /// <param name="a">Vector a</param>
  254. /// <returns>Vector</returns>
  255. [DebuggerStepThrough]
  256. public static v128 rcp_ps(v128 a)
  257. {
  258. v128 dst = default(v128);
  259. dst.Float0 = 1.0f / a.Float0;
  260. dst.Float1 = 1.0f / a.Float1;
  261. dst.Float2 = 1.0f / a.Float2;
  262. dst.Float3 = 1.0f / a.Float3;
  263. return dst;
  264. }
  265. // _mm_rsqrt_ss
  266. /// <summary> Compute the approximate reciprocal square root of the lower single-precision (32-bit) floating-point element in "a", store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". The maximum relative error for this approximation is less than 1.5*2^-12. </summary>
  267. /// <param name="a">Vector a</param>
  268. /// <returns>Vector</returns>
  269. [DebuggerStepThrough]
  270. public static v128 rsqrt_ss(v128 a)
  271. {
  272. v128 dst = a;
  273. dst.Float0 = 1.0f / (float)Math.Sqrt(a.Float0);
  274. return dst;
  275. }
  276. // _mm_rsqrt_ps
  277. /// <summary> Compute the approximate reciprocal square root of packed single-precision (32-bit) floating-point elements in "a", and store the results in "dst". The maximum relative error for this approximation is less than 1.5*2^-12. </summary>
  278. /// <param name="a">Vector a</param>
  279. /// <returns>Vector</returns>
  280. [DebuggerStepThrough]
  281. public static v128 rsqrt_ps(v128 a)
  282. {
  283. v128 dst = default(v128);
  284. dst.Float0 = 1.0f / (float)Math.Sqrt(a.Float0);
  285. dst.Float1 = 1.0f / (float)Math.Sqrt(a.Float1);
  286. dst.Float2 = 1.0f / (float)Math.Sqrt(a.Float2);
  287. dst.Float3 = 1.0f / (float)Math.Sqrt(a.Float3);
  288. return dst;
  289. }
  290. // _mm_min_ss
  291. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b", store the minimum value in the lower element of "dst", and copy the upper element from "a" to the upper element of "dst". </summary>
  292. /// <param name="a">Vector a</param>
  293. /// <param name="b">Vector b</param>
  294. /// <returns>Vector</returns>
  295. [DebuggerStepThrough]
  296. public static v128 min_ss(v128 a, v128 b)
  297. {
  298. v128 dst = a;
  299. dst.Float0 = Math.Min(a.Float0, b.Float0);
  300. return dst;
  301. }
  302. // _mm_min_ps
  303. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b", and store packed minimum values in "dst". </summary>
  304. /// <param name="a">Vector a</param>
  305. /// <param name="b">Vector b</param>
  306. /// <returns>Vector</returns>
  307. [DebuggerStepThrough]
  308. public static v128 min_ps(v128 a, v128 b)
  309. {
  310. v128 dst = default(v128);
  311. dst.Float0 = Math.Min(a.Float0, b.Float0);
  312. dst.Float1 = Math.Min(a.Float1, b.Float1);
  313. dst.Float2 = Math.Min(a.Float2, b.Float2);
  314. dst.Float3 = Math.Min(a.Float3, b.Float3);
  315. return dst;
  316. }
  317. // _mm_max_ss
  318. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b", store the maximum value in the lower element of "dst", and copy the upper element from "a" to the upper element of "dst". </summary>
  319. /// <param name="a">Vector a</param>
  320. /// <param name="b">Vector b</param>
  321. /// <returns>Vector</returns>
  322. [DebuggerStepThrough]
  323. public static v128 max_ss(v128 a, v128 b)
  324. {
  325. v128 dst = a;
  326. dst.Float0 = Math.Max(a.Float0, b.Float0);
  327. return dst;
  328. }
  329. // _mm_max_ps
  330. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b", and store packed maximum values in "dst". </summary>
  331. /// <param name="a">Vector a</param>
  332. /// <param name="b">Vector b</param>
  333. /// <returns>Vector</returns>
  334. [DebuggerStepThrough]
  335. public static v128 max_ps(v128 a, v128 b)
  336. {
  337. v128 dst = default(v128);
  338. dst.Float0 = Math.Max(a.Float0, b.Float0);
  339. dst.Float1 = Math.Max(a.Float1, b.Float1);
  340. dst.Float2 = Math.Max(a.Float2, b.Float2);
  341. dst.Float3 = Math.Max(a.Float3, b.Float3);
  342. return dst;
  343. }
  344. // _mm_and_ps
  345. /// <summary> Compute the bitwise AND of packed single-precision (32-bit) floating-point elements in "a" and "b", and store the results in "dst". </summary>
  346. /// <param name="a">Vector a</param>
  347. /// <param name="b">Vector b</param>
  348. /// <returns>Vector</returns>
  349. [DebuggerStepThrough]
  350. public static v128 and_ps(v128 a, v128 b)
  351. {
  352. v128 dst = a;
  353. dst.UInt0 &= b.UInt0;
  354. dst.UInt1 &= b.UInt1;
  355. dst.UInt2 &= b.UInt2;
  356. dst.UInt3 &= b.UInt3;
  357. return dst;
  358. }
  359. // _mm_andnot_ps
  360. /// <summary> Compute the bitwise NOT of packed single-precision (32-bit) floating-point elements in "a" and then AND with "b", and store the results in "dst". </summary>
  361. /// <param name="a">Vector a</param>
  362. /// <param name="b">Vector b</param>
  363. /// <returns>Vector</returns>
  364. [DebuggerStepThrough]
  365. public static v128 andnot_ps(v128 a, v128 b)
  366. {
  367. v128 dst = default(v128);
  368. dst.UInt0 = (~a.UInt0) & b.UInt0;
  369. dst.UInt1 = (~a.UInt1) & b.UInt1;
  370. dst.UInt2 = (~a.UInt2) & b.UInt2;
  371. dst.UInt3 = (~a.UInt3) & b.UInt3;
  372. return dst;
  373. }
  374. // _mm_or_ps
  375. /// <summary> Compute the bitwise OR of packed single-precision (32-bit) floating-point elements in "a" and "b", and store the results in "dst". </summary>
  376. /// <param name="a">Vector a</param>
  377. /// <param name="b">Vector b</param>
  378. /// <returns>Vector</returns>
  379. [DebuggerStepThrough]
  380. public static v128 or_ps(v128 a, v128 b)
  381. {
  382. v128 dst = default(v128);
  383. dst.UInt0 = a.UInt0 | b.UInt0;
  384. dst.UInt1 = a.UInt1 | b.UInt1;
  385. dst.UInt2 = a.UInt2 | b.UInt2;
  386. dst.UInt3 = a.UInt3 | b.UInt3;
  387. return dst;
  388. }
  389. // _mm_xor_ps
  390. /// <summary> Compute the bitwise XOR of packed single-precision (32-bit) floating-point elements in "a" and "b", and store the results in "dst". </summary>
  391. /// <param name="a">Vector a</param>
  392. /// <param name="b">Vector b</param>
  393. /// <returns>Vector</returns>
  394. [DebuggerStepThrough]
  395. public static v128 xor_ps(v128 a, v128 b)
  396. {
  397. v128 dst = default(v128);
  398. dst.UInt0 = a.UInt0 ^ b.UInt0;
  399. dst.UInt1 = a.UInt1 ^ b.UInt1;
  400. dst.UInt2 = a.UInt2 ^ b.UInt2;
  401. dst.UInt3 = a.UInt3 ^ b.UInt3;
  402. return dst;
  403. }
  404. // _mm_cmpeq_ss
  405. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b" for equality, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  406. /// <param name="a">Vector a</param>
  407. /// <param name="b">Vector b</param>
  408. /// <returns>Vector</returns>
  409. [DebuggerStepThrough]
  410. public static v128 cmpeq_ss(v128 a, v128 b)
  411. {
  412. v128 dst = a;
  413. dst.UInt0 = a.Float0 == b.Float0 ? ~0u : 0;
  414. return dst;
  415. }
  416. // _mm_cmpeq_ps
  417. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b" for equality, and store the results in "dst". </summary>
  418. /// <param name="a">Vector a</param>
  419. /// <param name="b">Vector b</param>
  420. /// <returns>Vector</returns>
  421. [DebuggerStepThrough]
  422. public static v128 cmpeq_ps(v128 a, v128 b)
  423. {
  424. v128 dst = default(v128);
  425. dst.UInt0 = a.Float0 == b.Float0 ? ~0u : 0;
  426. dst.UInt1 = a.Float1 == b.Float1 ? ~0u : 0;
  427. dst.UInt2 = a.Float2 == b.Float2 ? ~0u : 0;
  428. dst.UInt3 = a.Float3 == b.Float3 ? ~0u : 0;
  429. return dst;
  430. }
  431. // _mm_cmplt_ss
  432. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b" for less-than, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  433. /// <param name="a">Vector a</param>
  434. /// <param name="b">Vector b</param>
  435. /// <returns>Vector</returns>
  436. [DebuggerStepThrough]
  437. public static v128 cmplt_ss(v128 a, v128 b)
  438. {
  439. v128 dst = a;
  440. dst.UInt0 = a.Float0 < b.Float0 ? ~0u : 0u;
  441. return dst;
  442. }
  443. // _mm_cmplt_ps
  444. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b" for less-than, and store the results in "dst". </summary>
  445. /// <param name="a">Vector a</param>
  446. /// <param name="b">Vector b</param>
  447. /// <returns>Vector</returns>
  448. [DebuggerStepThrough]
  449. public static v128 cmplt_ps(v128 a, v128 b)
  450. {
  451. v128 dst = default(v128);
  452. dst.UInt0 = a.Float0 < b.Float0 ? ~0u : 0u;
  453. dst.UInt1 = a.Float1 < b.Float1 ? ~0u : 0u;
  454. dst.UInt2 = a.Float2 < b.Float2 ? ~0u : 0u;
  455. dst.UInt3 = a.Float3 < b.Float3 ? ~0u : 0u;
  456. return dst;
  457. }
  458. // _mm_cmple_ss
  459. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b" for less-than-or-equal, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  460. /// <param name="a">Vector a</param>
  461. /// <param name="b">Vector b</param>
  462. /// <returns>Vector</returns>
  463. [DebuggerStepThrough]
  464. public static v128 cmple_ss(v128 a, v128 b)
  465. {
  466. v128 dst = a;
  467. dst.UInt0 = a.Float0 <= b.Float0 ? ~0u : 0;
  468. return dst;
  469. }
  470. // _mm_cmple_ps
  471. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b" for less-than-or-equal, and store the results in "dst". </summary>
  472. /// <param name="a">Vector a</param>
  473. /// <param name="b">Vector b</param>
  474. /// <returns>Vector</returns>
  475. [DebuggerStepThrough]
  476. public static v128 cmple_ps(v128 a, v128 b)
  477. {
  478. v128 dst = default(v128);
  479. dst.UInt0 = a.Float0 <= b.Float0 ? ~0u : 0u;
  480. dst.UInt1 = a.Float1 <= b.Float1 ? ~0u : 0u;
  481. dst.UInt2 = a.Float2 <= b.Float2 ? ~0u : 0u;
  482. dst.UInt3 = a.Float3 <= b.Float3 ? ~0u : 0u;
  483. return dst;
  484. }
  485. // _mm_cmpgt_ss
  486. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b" for greater-than, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  487. /// <param name="a">Vector a</param>
  488. /// <param name="b">Vector b</param>
  489. /// <returns>Vector</returns>
  490. [DebuggerStepThrough]
  491. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  492. public static v128 cmpgt_ss(v128 a, v128 b)
  493. {
  494. return cmplt_ss(b, a);
  495. }
  496. // _mm_cmpgt_ps
  497. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b" for greater-than, and store the results in "dst". </summary>
  498. /// <param name="a">Vector a</param>
  499. /// <param name="b">Vector b</param>
  500. /// <returns>Vector</returns>
  501. [DebuggerStepThrough]
  502. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  503. public static v128 cmpgt_ps(v128 a, v128 b)
  504. {
  505. return cmplt_ps(b, a);
  506. }
  507. // _mm_cmpge_ss
  508. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b" for greater-than-or-equal, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  509. /// <param name="a">Vector a</param>
  510. /// <param name="b">Vector b</param>
  511. /// <returns>Vector</returns>
  512. [DebuggerStepThrough]
  513. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  514. public static v128 cmpge_ss(v128 a, v128 b)
  515. {
  516. return cmple_ss(b, a);
  517. }
  518. // _mm_cmpge_ps
  519. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b" for greater-than-or-equal, and store the results in "dst". </summary>
  520. /// <param name="a">Vector a</param>
  521. /// <param name="b">Vector b</param>
  522. /// <returns>Vector</returns>
  523. [DebuggerStepThrough]
  524. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  525. public static v128 cmpge_ps(v128 a, v128 b)
  526. {
  527. return cmple_ps(b, a);
  528. }
  529. // _mm_cmpneq_ss
  530. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b" for not-equal, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  531. /// <param name="a">Vector a</param>
  532. /// <param name="b">Vector b</param>
  533. /// <returns>Vector</returns>
  534. [DebuggerStepThrough]
  535. public static v128 cmpneq_ss(v128 a, v128 b)
  536. {
  537. v128 dst = a;
  538. dst.UInt0 = a.Float0 != b.Float0 ? ~0u : 0u;
  539. return dst;
  540. }
  541. // _mm_cmpneq_ps
  542. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b" for not-equal, and store the results in "dst". </summary>
  543. /// <param name="a">Vector a</param>
  544. /// <param name="b">Vector b</param>
  545. /// <returns>Vector</returns>
  546. [DebuggerStepThrough]
  547. public static v128 cmpneq_ps(v128 a, v128 b)
  548. {
  549. v128 dst = default(v128);
  550. dst.UInt0 = a.Float0 != b.Float0 ? ~0u : 0u;
  551. dst.UInt1 = a.Float1 != b.Float1 ? ~0u : 0u;
  552. dst.UInt2 = a.Float2 != b.Float2 ? ~0u : 0u;
  553. dst.UInt3 = a.Float3 != b.Float3 ? ~0u : 0u;
  554. return dst;
  555. }
  556. // _mm_cmpnlt_ss
  557. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b" for not-less-than, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  558. /// <param name="a">Vector a</param>
  559. /// <param name="b">Vector b</param>
  560. /// <returns>Vector</returns>
  561. [DebuggerStepThrough]
  562. public static v128 cmpnlt_ss(v128 a, v128 b)
  563. {
  564. v128 dst = a;
  565. dst.UInt0 = !(a.Float0 < b.Float0) ? ~0u : 0u;
  566. return dst;
  567. }
  568. // _mm_cmpnlt_ps
  569. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b" for not-less-than, and store the results in "dst". </summary>
  570. /// <param name="a">Vector a</param>
  571. /// <param name="b">Vector b</param>
  572. /// <returns>Vector</returns>
  573. [DebuggerStepThrough]
  574. public static v128 cmpnlt_ps(v128 a, v128 b)
  575. {
  576. v128 dst = default(v128);
  577. dst.UInt0 = !(a.Float0 < b.Float0) ? ~0u : 0u;
  578. dst.UInt1 = !(a.Float1 < b.Float1) ? ~0u : 0u;
  579. dst.UInt2 = !(a.Float2 < b.Float2) ? ~0u : 0u;
  580. dst.UInt3 = !(a.Float3 < b.Float3) ? ~0u : 0u;
  581. return dst;
  582. }
  583. // _mm_cmpnle_ss
  584. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b" for not-less-than-or-equal, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  585. /// <param name="a">Vector a</param>
  586. /// <param name="b">Vector b</param>
  587. /// <returns>Vector</returns>
  588. [DebuggerStepThrough]
  589. public static v128 cmpnle_ss(v128 a, v128 b)
  590. {
  591. v128 dst = a;
  592. dst.UInt0 = !(a.Float0 <= b.Float0) ? ~0u : 0u;
  593. return dst;
  594. }
  595. // _mm_cmpnle_ps
  596. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b" for not-less-than-or-equal, and store the results in "dst". </summary>
  597. /// <param name="a">Vector a</param>
  598. /// <param name="b">Vector b</param>
  599. /// <returns>Vector</returns>
  600. [DebuggerStepThrough]
  601. public static v128 cmpnle_ps(v128 a, v128 b)
  602. {
  603. v128 dst = default(v128);
  604. dst.UInt0 = !(a.Float0 <= b.Float0) ? ~0u : 0u;
  605. dst.UInt1 = !(a.Float1 <= b.Float1) ? ~0u : 0u;
  606. dst.UInt2 = !(a.Float2 <= b.Float2) ? ~0u : 0u;
  607. dst.UInt3 = !(a.Float3 <= b.Float3) ? ~0u : 0u;
  608. return dst;
  609. }
  610. // _mm_cmpngt_ss
  611. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b" for not-greater-than, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  612. /// <param name="a">Vector a</param>
  613. /// <param name="b">Vector b</param>
  614. /// <returns>Vector</returns>
  615. [DebuggerStepThrough]
  616. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  617. public static v128 cmpngt_ss(v128 a, v128 b)
  618. {
  619. return cmpnlt_ss(b, a);
  620. }
  621. // _mm_cmpngt_ps
  622. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b" for not-greater-than, and store the results in "dst". </summary>
  623. /// <param name="a">Vector a</param>
  624. /// <param name="b">Vector b</param>
  625. /// <returns>Vector</returns>
  626. [DebuggerStepThrough]
  627. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  628. public static v128 cmpngt_ps(v128 a, v128 b)
  629. {
  630. return cmpnlt_ps(b, a);
  631. }
  632. // _mm_cmpnge_ss
  633. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b" for not-greater-than-or-equal, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  634. /// <param name="a">Vector a</param>
  635. /// <param name="b">Vector b</param>
  636. /// <returns>Vector</returns>
  637. [DebuggerStepThrough]
  638. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  639. public static v128 cmpnge_ss(v128 a, v128 b)
  640. {
  641. return cmpnle_ss(b, a);
  642. }
  643. // _mm_cmpnge_ps
  644. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b" for not-greater-than-or-equal, and store the results in "dst". </summary>
  645. /// <param name="a">Vector a</param>
  646. /// <param name="b">Vector b</param>
  647. /// <returns>Vector</returns>
  648. [DebuggerStepThrough]
  649. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  650. public static v128 cmpnge_ps(v128 a, v128 b)
  651. {
  652. return cmpnle_ps(b, a);
  653. }
  654. // _mm_cmpord_ss
  655. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b" to see if neither is NaN, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  656. /// <param name="a">Vector a</param>
  657. /// <param name="b">Vector b</param>
  658. /// <returns>Vector</returns>
  659. [DebuggerStepThrough]
  660. public static v128 cmpord_ss(v128 a, v128 b)
  661. {
  662. v128 dst = a;
  663. dst.UInt0 = IsNaN(a.UInt0) || IsNaN(b.UInt0) ? 0 : ~0u;
  664. return dst;
  665. }
  666. // _mm_cmpord_ps
  667. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b" to see if neither is NaN, and store the results in "dst". </summary>
  668. /// <param name="a">Vector a</param>
  669. /// <param name="b">Vector b</param>
  670. /// <returns>Vector</returns>
  671. [DebuggerStepThrough]
  672. public static v128 cmpord_ps(v128 a, v128 b)
  673. {
  674. v128 dst = default(v128);
  675. dst.UInt0 = IsNaN(a.UInt0) || IsNaN(b.UInt0) ? 0 : ~0u;
  676. dst.UInt1 = IsNaN(a.UInt1) || IsNaN(b.UInt1) ? 0 : ~0u;
  677. dst.UInt2 = IsNaN(a.UInt2) || IsNaN(b.UInt2) ? 0 : ~0u;
  678. dst.UInt3 = IsNaN(a.UInt3) || IsNaN(b.UInt3) ? 0 : ~0u;
  679. return dst;
  680. }
  681. // _mm_cmpunord_ss
  682. /// <summary> Compare the lower single-precision (32-bit) floating-point elements in "a" and "b" to see if either is NaN, store the result in the lower element of "dst", and copy the upper 3 packed elements from "a" to the upper elements of "dst". </summary>
  683. /// <param name="a">Vector a</param>
  684. /// <param name="b">Vector b</param>
  685. /// <returns>Vector</returns>
  686. [DebuggerStepThrough]
  687. public static v128 cmpunord_ss(v128 a, v128 b)
  688. {
  689. v128 dst = a;
  690. dst.UInt0 = IsNaN(a.UInt0) || IsNaN(b.UInt0) ? ~0u : 0;
  691. return dst;
  692. }
  693. // _mm_cmpunord_ps
  694. /// <summary> Compare packed single-precision (32-bit) floating-point elements in "a" and "b" to see if either is NaN, and store the results in "dst". </summary>
  695. /// <param name="a">Vector a</param>
  696. /// <param name="b">Vector b</param>
  697. /// <returns>Vector</returns>
  698. [DebuggerStepThrough]
  699. public static v128 cmpunord_ps(v128 a, v128 b)
  700. {
  701. v128 dst = default(v128);
  702. dst.UInt0 = IsNaN(a.UInt0) || IsNaN(b.UInt0) ? ~0u : 0;
  703. dst.UInt1 = IsNaN(a.UInt1) || IsNaN(b.UInt1) ? ~0u : 0;
  704. dst.UInt2 = IsNaN(a.UInt2) || IsNaN(b.UInt2) ? ~0u : 0;
  705. dst.UInt3 = IsNaN(a.UInt3) || IsNaN(b.UInt3) ? ~0u : 0;
  706. return dst;
  707. }
  708. // _mm_comieq_ss
  709. /// <summary> Compare the lower single-precision (32-bit) floating-point element in "a" and "b" for equality, and return the boolean result (0 or 1). </summary>
  710. /// <param name="a">Vector a</param>
  711. /// <param name="b">Vector b</param>
  712. /// <returns>Boolean result</returns>
  713. [DebuggerStepThrough]
  714. public static int comieq_ss(v128 a, v128 b)
  715. {
  716. return a.Float0 == b.Float0 ? 1 : 0;
  717. }
  718. // _mm_comilt_ss
  719. /// <summary> Compare the lower single-precision (32-bit) floating-point element in "a" and "b" for less-than, and return the boolean result (0 or 1). </summary>
  720. /// <param name="a">Vector a</param>
  721. /// <param name="b">Vector b</param>
  722. /// <returns>Boolean result</returns>
  723. [DebuggerStepThrough]
  724. public static int comilt_ss(v128 a, v128 b)
  725. {
  726. return a.Float0 < b.Float0 ? 1 : 0;
  727. }
  728. // _mm_comile_ss
  729. /// <summary> Compare the lower single-precision (32-bit) floating-point element in "a" and "b" for less-than-or-equal, and return the boolean result (0 or 1). </summary>
  730. /// <param name="a">Vector a</param>
  731. /// <param name="b">Vector b</param>
  732. /// <returns>Boolean result</returns>
  733. [DebuggerStepThrough]
  734. public static int comile_ss(v128 a, v128 b)
  735. {
  736. return a.Float0 <= b.Float0 ? 1 : 0;
  737. }
  738. // _mm_comigt_ss
  739. /// <summary> Compare the lower single-precision (32-bit) floating-point element in "a" and "b" for greater-than, and return the boolean result (0 or 1). </summary>
  740. /// <param name="a">Vector a</param>
  741. /// <param name="b">Vector b</param>
  742. /// <returns>Boolean result</returns>
  743. [DebuggerStepThrough]
  744. public static int comigt_ss(v128 a, v128 b)
  745. {
  746. return a.Float0 > b.Float0 ? 1 : 0;
  747. }
  748. // _mm_comige_ss
  749. /// <summary> Compare the lower single-precision (32-bit) floating-point element in "a" and "b" for greater-than-or-equal, and return the boolean result (0 or 1). </summary>
  750. /// <param name="a">Vector a</param>
  751. /// <param name="b">Vector b</param>
  752. /// <returns>Boolean result</returns>
  753. [DebuggerStepThrough]
  754. public static int comige_ss(v128 a, v128 b)
  755. {
  756. return a.Float0 >= b.Float0 ? 1 : 0;
  757. }
  758. // _mm_comineq_ss
  759. /// <summary> Compare the lower single-precision (32-bit) floating-point element in "a" and "b" for not-equal, and return the boolean result (0 or 1). </summary>
  760. /// <param name="a">Vector a</param>
  761. /// <param name="b">Vector b</param>
  762. /// <returns>Boolean result</returns>
  763. [DebuggerStepThrough]
  764. public static int comineq_ss(v128 a, v128 b)
  765. {
  766. return a.Float0 != b.Float0 ? 1 : 0;
  767. }
  768. // _mm_ucomieq_ss
  769. /// <summary> Compare the lower single-precision (32-bit) floating-point element in "a" and "b" for equality, and return the boolean result (0 or 1). This instruction will not signal an exception for QNaNs. </summary>
  770. /// <param name="a">Vector a</param>
  771. /// <param name="b">Vector b</param>
  772. /// <returns>Boolean result</returns>
  773. [DebuggerStepThrough]
  774. public static int ucomieq_ss(v128 a, v128 b)
  775. {
  776. return a.Float0 == b.Float0 ? 1 : 0;
  777. }
  778. // _mm_ucomilt_ss
  779. /// <summary> Compare the lower single-precision (32-bit) floating-point element in "a" and "b" for less-than, and return the boolean result (0 or 1). This instruction will not signal an exception for QNaNs. </summary>
  780. /// <param name="a">Vector a</param>
  781. /// <param name="b">Vector b</param>
  782. /// <returns>Boolean result</returns>
  783. [DebuggerStepThrough]
  784. public static int ucomilt_ss(v128 a, v128 b)
  785. {
  786. return a.Float0 < b.Float0 ? 1 : 0;
  787. }
  788. // _mm_ucomile_ss
  789. /// <summary> Compare the lower single-precision (32-bit) floating-point element in "a" and "b" for less-than-or-equal, and return the boolean result (0 or 1). This instruction will not signal an exception for QNaNs. </summary>
  790. /// <param name="a">Vector a</param>
  791. /// <param name="b">Vector b</param>
  792. /// <returns>Boolean result</returns>
  793. [DebuggerStepThrough]
  794. public static int ucomile_ss(v128 a, v128 b)
  795. {
  796. return a.Float0 <= b.Float0 ? 1 : 0;
  797. }
  798. // _mm_ucomigt_ss
  799. /// <summary> Compare the lower single-precision (32-bit) floating-point element in "a" and "b" for greater-than, and return the boolean result (0 or 1). This instruction will not signal an exception for QNaNs. </summary>
  800. /// <param name="a">Vector a</param>
  801. /// <param name="b">Vector b</param>
  802. /// <returns>Boolean result</returns>
  803. [DebuggerStepThrough]
  804. public static int ucomigt_ss(v128 a, v128 b)
  805. {
  806. return a.Float0 > b.Float0 ? 1 : 0;
  807. }
  808. // _mm_ucomige_ss
  809. /// <summary> Compare the lower single-precision (32-bit) floating-point element in "a" and "b" for greater-than-or-equal, and return the boolean result (0 or 1). This instruction will not signal an exception for QNaNs. </summary>
  810. /// <param name="a">Vector a</param>
  811. /// <param name="b">Vector b</param>
  812. /// <returns>Boolean result</returns>
  813. [DebuggerStepThrough]
  814. public static int ucomige_ss(v128 a, v128 b)
  815. {
  816. return a.Float0 >= b.Float0 ? 1 : 0;
  817. }
  818. // _mm_ucomineq_ss
  819. /// <summary> Compare the lower single-precision (32-bit) floating-point element in "a" and "b" for not-equal, and return the boolean result (0 or 1). This instruction will not signal an exception for QNaNs. </summary>
  820. /// <param name="a">Vector a</param>
  821. /// <param name="b">Vector b</param>
  822. /// <returns>Boolean result</returns>
  823. [DebuggerStepThrough]
  824. public static int ucomineq_ss(v128 a, v128 b)
  825. {
  826. return a.Float0 != b.Float0 ? 1 : 0;
  827. }
  828. // _mm_cvtss_si32
  829. /// <summary> Convert the lower single-precision (32-bit) floating-point element in "a" to a 32-bit integer, and store the result in "dst". </summary>
  830. /// <param name="a">Vector a</param>
  831. /// <returns>Integer</returns>
  832. [DebuggerStepThrough]
  833. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  834. public static int cvtss_si32(v128 a)
  835. {
  836. return cvt_ss2si(a);
  837. }
  838. // _mm_cvt_ss2si
  839. /// <summary>
  840. /// Convert the lower single-precision (32-bit) floating-point element in "a" to a 32-bit integer, and store the result in "dst".
  841. /// Follows standard of rounding to nearest, and for midpoint rounding it rounds to even.
  842. /// </summary>
  843. /// <param name="a">Vector a</param>
  844. /// <returns>Integer</returns>
  845. [DebuggerStepThrough]
  846. public static int cvt_ss2si(v128 a)
  847. {
  848. return (int)Math.Round(a.Float0, MidpointRounding.ToEven);
  849. }
  850. // _mm_cvtss_si64
  851. /// <summary>
  852. /// Convert the lower single-precision (32-bit) floating-point element in "a" to a 64-bit integer, and store the result in "dst".
  853. /// Follows standard of rounding to nearest, and for midpoint rounding it rounds to even.
  854. /// </summary>
  855. /// <param name="a">Vector a</param>
  856. /// <returns>64-bit integer</returns>
  857. [DebuggerStepThrough]
  858. public static long cvtss_si64(v128 a)
  859. {
  860. return (long)Math.Round(a.Float0, MidpointRounding.ToEven);
  861. }
  862. // _mm_cvtss_f32
  863. /// <summary> Copy the lower single-precision (32-bit) floating-point element of "a" to "dst". </summary>
  864. /// <param name="a">Vector a</param>
  865. /// <returns>32-bit floating point element</returns>
  866. [DebuggerStepThrough]
  867. public static float cvtss_f32(v128 a)
  868. {
  869. return a.Float0;
  870. }
  871. // _mm_cvttss_si32
  872. /// <summary> Convert the lower single-precision (32-bit) floating-point element in "a" to a 32-bit integer with truncation, and store the result in "dst". </summary>
  873. /// <param name="a">Vector a</param>
  874. /// <returns>32-bit integer</returns>
  875. [DebuggerStepThrough]
  876. public static int cvttss_si32(v128 a)
  877. {
  878. using (var csr = new RoundingScope(MXCSRBits.RoundTowardZero))
  879. {
  880. return (int)a.Float0;
  881. }
  882. }
  883. // _mm_cvtt_ss2si
  884. /// <summary> Convert the lower single-precision (32-bit) floating-point element in "a" to a 32-bit integer with truncation, and store the result in "dst". </summary>
  885. /// <param name="a">Vector a</param>
  886. /// <returns>32-bit integer</returns>
  887. [DebuggerStepThrough]
  888. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  889. public static int cvtt_ss2si(v128 a)
  890. {
  891. return cvttss_si32(a);
  892. }
  893. // _mm_cvttss_si64
  894. /// <summary> Convert the lower single-precision (32-bit) floating-point element in "a" to a 64-bit integer with truncation, and store the result in "dst". </summary>
  895. /// <param name="a">Vector a</param>
  896. /// <returns>64-bit integer</returns>
  897. [DebuggerStepThrough]
  898. public static long cvttss_si64(v128 a)
  899. {
  900. using (var csr = new RoundingScope(MXCSRBits.RoundTowardZero))
  901. {
  902. return (long)a.Float0;
  903. }
  904. }
  905. // _mm_set_ss
  906. /// <summary> Copy single-precision (32-bit) floating-point element "a" to the lower element of "dst", and zero the upper 3 elements. </summary>
  907. /// <param name="a">Floating point element</param>
  908. /// <returns>Vector</returns>
  909. [DebuggerStepThrough]
  910. public static v128 set_ss(float a)
  911. {
  912. return new v128(a, 0.0f, 0.0f, 0.0f);
  913. }
  914. // _mm_set1_ps
  915. /// <summary> Broadcast single-precision (32-bit) floating-point value "a" to all elements of "dst". </summary>
  916. /// <param name="a">Floating point element</param>
  917. /// <returns>Vector</returns>
  918. [DebuggerStepThrough]
  919. public static v128 set1_ps(float a)
  920. {
  921. return new v128(a, a, a, a);
  922. }
  923. // _mm_set_ps1
  924. /// <summary> Broadcast single-precision (32-bit) floating-point value "a" to all elements of "dst". </summary>
  925. /// <param name="a">Floating point element</param>
  926. /// <returns>Vector</returns>
  927. [DebuggerStepThrough]
  928. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  929. public static v128 set_ps1(float a)
  930. {
  931. return set1_ps(a);
  932. }
  933. // _mm_set_ps
  934. /// <summary> Set packed single-precision (32-bit) floating-point elements in "dst" with the supplied values. </summary>
  935. /// <param name="e3">Floating point element 3</param>
  936. /// <param name="e2">Floating point element 2</param>
  937. /// <param name="e1">Floating point element 1</param>
  938. /// <param name="e0">Floating point element 0</param>
  939. /// <returns>Vector</returns>
  940. [DebuggerStepThrough]
  941. public static v128 set_ps(float e3, float e2, float e1, float e0)
  942. {
  943. return new v128(e0, e1, e2, e3);
  944. }
  945. // _mm_setr_ps
  946. /// <summary> Set packed single-precision (32-bit) floating-point elements in "dst" with the supplied values in reverse order. </summary>
  947. /// <param name="e3">Floating point element 3</param>
  948. /// <param name="e2">Floating point element 2</param>
  949. /// <param name="e1">Floating point element 1</param>
  950. /// <param name="e0">Floating point element 0</param>
  951. /// <returns>Vector</returns>
  952. [DebuggerStepThrough]
  953. public static v128 setr_ps(float e3, float e2, float e1, float e0)
  954. {
  955. return new v128(e3, e2, e1, e0);
  956. }
  957. // _mm_move_ss
  958. /// <summary> Move the lower single-precision (32-bit) floating-point element from "b" to the lower element of "dst", and copy the upper 3 elements from "a" to the upper elements of "dst". </summary>
  959. /// <param name="a">Vector a</param>
  960. /// <param name="b">Vector b</param>
  961. /// <returns>Vector</returns>
  962. [DebuggerStepThrough]
  963. public static v128 move_ss(v128 a, v128 b)
  964. {
  965. v128 dst = a;
  966. dst.Float0 = b.Float0;
  967. return dst;
  968. }
  969. // _MM_SHUFFLE macro
  970. /// <summary>
  971. /// Return a shuffle immediate suitable for use with shuffle_ps and similar instructions.
  972. /// </summary>
  973. /// <param name="d">Integer d</param>
  974. /// <param name="c">Integer c</param>
  975. /// <param name="b">Integer b</param>
  976. /// <param name="a">Integer a</param>
  977. /// <returns>Shuffle suitable for use with shuffle_ps</returns>
  978. public static int SHUFFLE(int d, int c, int b, int a)
  979. {
  980. return ((a & 3)) | ((b & 3) << 2) | ((c & 3) << 4) | ((d & 3) << 6);
  981. }
  982. // _mm_shuffle_ps
  983. /// <summary> Shuffle single-precision (32-bit) floating-point elements in "a" using the control in "imm8", and store the results in "dst". </summary>
  984. /// <param name="a">Vector a</param>
  985. /// <param name="b">Vector b</param>
  986. /// <param name="imm8">Control</param>
  987. /// <returns>Vector</returns>
  988. [DebuggerStepThrough]
  989. public static v128 shuffle_ps(v128 a, v128 b, int imm8)
  990. {
  991. v128 dst = default(v128);
  992. // Use integers, rather than floats, because of a Mono bug.
  993. uint* aptr = &a.UInt0;
  994. uint* bptr = &b.UInt0;
  995. dst.UInt0 = aptr[(imm8 >> 0) & 3];
  996. dst.UInt1 = aptr[(imm8 >> 2) & 3];
  997. dst.UInt2 = bptr[(imm8 >> 4) & 3];
  998. dst.UInt3 = bptr[(imm8 >> 6) & 3];
  999. return dst;
  1000. }
  1001. // _mm_unpackhi_ps
  1002. /// <summary> Unpack and interleave single-precision (32-bit) floating-point elements from the high half "a" and "b", and store the results in "dst". </summary>
  1003. /// <param name="a">Vector a</param>
  1004. /// <param name="b">Vector b</param>
  1005. /// <returns>Vector</returns>
  1006. [DebuggerStepThrough]
  1007. public static v128 unpackhi_ps(v128 a, v128 b)
  1008. {
  1009. v128 dst = default(v128);
  1010. dst.Float0 = a.Float2;
  1011. dst.Float1 = b.Float2;
  1012. dst.Float2 = a.Float3;
  1013. dst.Float3 = b.Float3;
  1014. return dst;
  1015. }
  1016. // _mm_unpacklo_ps
  1017. /// <summary> Unpack and interleave single-precision (32-bit) floating-point elements from the low half of "a" and "b", and store the results in "dst". </summary>
  1018. /// <param name="a">Vector a</param>
  1019. /// <param name="b">Vector b</param>
  1020. /// <returns>Vector</returns>
  1021. [DebuggerStepThrough]
  1022. public static v128 unpacklo_ps(v128 a, v128 b)
  1023. {
  1024. v128 dst = default(v128);
  1025. dst.Float0 = a.Float0;
  1026. dst.Float1 = b.Float0;
  1027. dst.Float2 = a.Float1;
  1028. dst.Float3 = b.Float1;
  1029. return dst;
  1030. }
  1031. // _mm_movehl_ps
  1032. /// <summary> Move the upper 2 single-precision (32-bit) floating-point elements from "b" to the lower 2 elements of "dst", and copy the upper 2 elements from "a" to the upper 2 elements of "dst". </summary>
  1033. /// <param name="a">Vector a</param>
  1034. /// <param name="b">Vector b</param>
  1035. /// <returns>Vector</returns>
  1036. [DebuggerStepThrough]
  1037. public static v128 movehl_ps(v128 a, v128 b)
  1038. {
  1039. v128 dst = default(v128);
  1040. dst.Float0 = b.Float2;
  1041. dst.Float1 = b.Float3;
  1042. dst.Float2 = a.Float2;
  1043. dst.Float3 = a.Float3;
  1044. return dst;
  1045. }
  1046. // _mm_movelh_ps
  1047. /// <summary> Move the lower 2 single-precision (32-bit) floating-point elements from "b" to the upper 2 elements of "dst", and copy the lower 2 elements from "a" to the lower 2 elements of "dst". </summary>
  1048. /// <param name="a">Vector a</param>
  1049. /// <param name="b">Vector b</param>
  1050. /// <returns>Vector</returns>
  1051. [DebuggerStepThrough]
  1052. public static v128 movelh_ps(v128 a, v128 b)
  1053. {
  1054. v128 dst = default(v128);
  1055. dst.Float0 = a.Float0;
  1056. dst.Float1 = a.Float1;
  1057. dst.Float2 = b.Float0;
  1058. dst.Float3 = b.Float1;
  1059. return dst;
  1060. }
  1061. // _mm_movemask_ps
  1062. /// <summary> Set each bit of mask "dst" based on the most significant bit of the corresponding packed single-precision (32-bit) floating-point element in "a". </summary>
  1063. /// <param name="a">Vector a</param>
  1064. /// <returns>Integer</returns>
  1065. [DebuggerStepThrough]
  1066. public static int movemask_ps(v128 a)
  1067. {
  1068. int dst = 0;
  1069. if ((a.UInt0 & 0x80000000) != 0) dst |= 1;
  1070. if ((a.UInt1 & 0x80000000) != 0) dst |= 2;
  1071. if ((a.UInt2 & 0x80000000) != 0) dst |= 4;
  1072. if ((a.UInt3 & 0x80000000) != 0) dst |= 8;
  1073. return dst;
  1074. }
  1075. /// <summary>
  1076. /// Transposes a 4x4 matrix of single precision floating point values (_MM_TRANSPOSE4_PS).
  1077. /// </summary>
  1078. /// <remarks>
  1079. /// Arguments row0, row1, row2, and row3 are __m128
  1080. /// values whose elements form the corresponding rows
  1081. /// of a 4x4 matrix. The matrix transpose is returned
  1082. /// in arguments row0, row1, row2, and row3 where row0
  1083. /// now holds column 0 of the original matrix, row1 now
  1084. /// holds column 1 of the original matrix, etc.
  1085. /// </remarks>
  1086. /// <param name="row0">__m128 value on corresponding row</param>
  1087. /// <param name="row1">__m128 value on corresponding row</param>
  1088. /// <param name="row2">__m128 value on corresponding row</param>
  1089. /// <param name="row3">__m128 value on corresponding row</param>
  1090. [DebuggerStepThrough]
  1091. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  1092. public static void TRANSPOSE4_PS(ref v128 row0, ref v128 row1, ref v128 row2, ref v128 row3)
  1093. {
  1094. v128 _Tmp3, _Tmp2, _Tmp1, _Tmp0;
  1095. _Tmp0 = shuffle_ps((row0), (row1), 0x44);
  1096. _Tmp2 = shuffle_ps((row0), (row1), 0xEE);
  1097. _Tmp1 = shuffle_ps((row2), (row3), 0x44);
  1098. _Tmp3 = shuffle_ps((row2), (row3), 0xEE);
  1099. row0 = shuffle_ps(_Tmp0, _Tmp1, 0x88);
  1100. row1 = shuffle_ps(_Tmp0, _Tmp1, 0xDD);
  1101. row2 = shuffle_ps(_Tmp2, _Tmp3, 0x88);
  1102. row3 = shuffle_ps(_Tmp2, _Tmp3, 0xDD);
  1103. }
  1104. /// <summary>
  1105. /// Return vector of type v128 with all elements set to zero.
  1106. /// </summary>
  1107. /// <returns>Vector</returns>
  1108. [DebuggerStepThrough]
  1109. public static v128 setzero_ps()
  1110. {
  1111. return default;
  1112. }
  1113. /// <summary>
  1114. /// Load unaligned 16-bit integer from memory into the first element of dst.
  1115. /// </summary>
  1116. /// <param name="mem_addr">Memory address</param>
  1117. /// <returns>Vector</returns>
  1118. [DebuggerStepThrough]
  1119. public static v128 loadu_si16(void* mem_addr)
  1120. {
  1121. return new v128(*(short*)mem_addr, 0, 0, 0, 0, 0, 0, 0);
  1122. }
  1123. /// <summary>
  1124. /// Store 16-bit integer from the first element of a into memory.
  1125. /// mem_addr does not need to be aligned on any particular
  1126. /// boundary.
  1127. /// </summary>
  1128. /// <param name="mem_addr">Memory address</param>
  1129. /// <param name="a">Vector a</param>
  1130. public static void storeu_si16(void* mem_addr, v128 a)
  1131. {
  1132. *(short*)mem_addr = a.SShort0;
  1133. }
  1134. /// <summary>
  1135. /// Load unaligned 64-bit integer from memory into the first element of dst.
  1136. /// </summary>
  1137. /// <param name="mem_addr">Memory address</param>
  1138. /// <returns>Vector</returns>
  1139. [DebuggerStepThrough]
  1140. public static v128 loadu_si64(void* mem_addr)
  1141. {
  1142. return new v128(*(long*)mem_addr, 0);
  1143. }
  1144. /// <summary>
  1145. /// Store 64-bit integer from the first element of a into memory.
  1146. /// mem_addr does not need to be aligned on any particular
  1147. /// boundary.
  1148. /// </summary>
  1149. /// <param name="mem_addr">Memory address</param>
  1150. /// <param name="a">Vector a</param>
  1151. [DebuggerStepThrough]
  1152. public static void storeu_si64(void* mem_addr, v128 a)
  1153. {
  1154. *(long*)mem_addr = a.SLong0;
  1155. }
  1156. }
  1157. }
  1158. }