暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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> Convert the lower single-precision (32-bit) floating-point element in "a" to a 32-bit integer, and store the result in "dst". </summary>
  840. /// <param name="a">Vector a</param>
  841. /// <returns>Integer</returns>
  842. [DebuggerStepThrough]
  843. public static int cvt_ss2si(v128 a)
  844. {
  845. return (int)a.Float0;
  846. }
  847. // _mm_cvtss_si64
  848. /// <summary> Convert the lower single-precision (32-bit) floating-point element in "a" to a 64-bit integer, and store the result in "dst". </summary>
  849. /// <param name="a">Vector a</param>
  850. /// <returns>64-bit integer</returns>
  851. [DebuggerStepThrough]
  852. public static long cvtss_si64(v128 a)
  853. {
  854. return (long)a.Float0;
  855. }
  856. // _mm_cvtss_f32
  857. /// <summary> Copy the lower single-precision (32-bit) floating-point element of "a" to "dst". </summary>
  858. /// <param name="a">Vector a</param>
  859. /// <returns>32-bit floating point element</returns>
  860. [DebuggerStepThrough]
  861. public static float cvtss_f32(v128 a)
  862. {
  863. return a.Float0;
  864. }
  865. // _mm_cvttss_si32
  866. /// <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>
  867. /// <param name="a">Vector a</param>
  868. /// <returns>32-bit integer</returns>
  869. [DebuggerStepThrough]
  870. public static int cvttss_si32(v128 a)
  871. {
  872. using (var csr = new RoundingScope(MXCSRBits.RoundTowardZero))
  873. {
  874. return (int)a.Float0;
  875. }
  876. }
  877. // _mm_cvtt_ss2si
  878. /// <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>
  879. /// <param name="a">Vector a</param>
  880. /// <returns>32-bit integer</returns>
  881. [DebuggerStepThrough]
  882. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  883. public static int cvtt_ss2si(v128 a)
  884. {
  885. return cvttss_si32(a);
  886. }
  887. // _mm_cvttss_si64
  888. /// <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>
  889. /// <param name="a">Vector a</param>
  890. /// <returns>64-bit integer</returns>
  891. [DebuggerStepThrough]
  892. public static long cvttss_si64(v128 a)
  893. {
  894. using (var csr = new RoundingScope(MXCSRBits.RoundTowardZero))
  895. {
  896. return (long)a.Float0;
  897. }
  898. }
  899. // _mm_set_ss
  900. /// <summary> Copy single-precision (32-bit) floating-point element "a" to the lower element of "dst", and zero the upper 3 elements. </summary>
  901. /// <param name="a">Floating point element</param>
  902. /// <returns>Vector</returns>
  903. [DebuggerStepThrough]
  904. public static v128 set_ss(float a)
  905. {
  906. return new v128(a, 0.0f, 0.0f, 0.0f);
  907. }
  908. // _mm_set1_ps
  909. /// <summary> Broadcast single-precision (32-bit) floating-point value "a" to all elements of "dst". </summary>
  910. /// <param name="a">Floating point element</param>
  911. /// <returns>Vector</returns>
  912. [DebuggerStepThrough]
  913. public static v128 set1_ps(float a)
  914. {
  915. return new v128(a, a, a, a);
  916. }
  917. // _mm_set_ps1
  918. /// <summary> Broadcast single-precision (32-bit) floating-point value "a" to all elements of "dst". </summary>
  919. /// <param name="a">Floating point element</param>
  920. /// <returns>Vector</returns>
  921. [DebuggerStepThrough]
  922. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  923. public static v128 set_ps1(float a)
  924. {
  925. return set1_ps(a);
  926. }
  927. // _mm_set_ps
  928. /// <summary> Set packed single-precision (32-bit) floating-point elements in "dst" with the supplied values. </summary>
  929. /// <param name="e3">Floating point element 3</param>
  930. /// <param name="e2">Floating point element 2</param>
  931. /// <param name="e1">Floating point element 1</param>
  932. /// <param name="e0">Floating point element 0</param>
  933. /// <returns>Vector</returns>
  934. [DebuggerStepThrough]
  935. public static v128 set_ps(float e3, float e2, float e1, float e0)
  936. {
  937. return new v128(e0, e1, e2, e3);
  938. }
  939. // _mm_setr_ps
  940. /// <summary> Set packed single-precision (32-bit) floating-point elements in "dst" with the supplied values in reverse order. </summary>
  941. /// <param name="e3">Floating point element 3</param>
  942. /// <param name="e2">Floating point element 2</param>
  943. /// <param name="e1">Floating point element 1</param>
  944. /// <param name="e0">Floating point element 0</param>
  945. /// <returns>Vector</returns>
  946. [DebuggerStepThrough]
  947. public static v128 setr_ps(float e3, float e2, float e1, float e0)
  948. {
  949. return new v128(e3, e2, e1, e0);
  950. }
  951. // _mm_move_ss
  952. /// <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>
  953. /// <param name="a">Vector a</param>
  954. /// <param name="b">Vector b</param>
  955. /// <returns>Vector</returns>
  956. [DebuggerStepThrough]
  957. public static v128 move_ss(v128 a, v128 b)
  958. {
  959. v128 dst = a;
  960. dst.Float0 = b.Float0;
  961. return dst;
  962. }
  963. // _MM_SHUFFLE macro
  964. /// <summary>
  965. /// Return a shuffle immediate suitable for use with shuffle_ps and similar instructions.
  966. /// </summary>
  967. /// <param name="d">Integer d</param>
  968. /// <param name="c">Integer c</param>
  969. /// <param name="b">Integer b</param>
  970. /// <param name="a">Integer a</param>
  971. /// <returns>Shuffle suitable for use with shuffle_ps</returns>
  972. public static int SHUFFLE(int d, int c, int b, int a)
  973. {
  974. return ((a & 3)) | ((b & 3) << 2) | ((c & 3) << 4) | ((d & 3) << 6);
  975. }
  976. // _mm_shuffle_ps
  977. /// <summary> Shuffle single-precision (32-bit) floating-point elements in "a" using the control in "imm8", and store the results in "dst". </summary>
  978. /// <param name="a">Vector a</param>
  979. /// <param name="b">Vector b</param>
  980. /// <param name="imm8">Control</param>
  981. /// <returns>Vector</returns>
  982. [DebuggerStepThrough]
  983. public static v128 shuffle_ps(v128 a, v128 b, int imm8)
  984. {
  985. v128 dst = default(v128);
  986. float* aptr = &a.Float0;
  987. float* bptr = &b.Float0;
  988. dst.Float0 = aptr[(imm8 >> 0) & 3];
  989. dst.Float1 = aptr[(imm8 >> 2) & 3];
  990. dst.Float2 = bptr[(imm8 >> 4) & 3];
  991. dst.Float3 = bptr[(imm8 >> 6) & 3];
  992. return dst;
  993. }
  994. // _mm_unpackhi_ps
  995. /// <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>
  996. /// <param name="a">Vector a</param>
  997. /// <param name="b">Vector b</param>
  998. /// <returns>Vector</returns>
  999. [DebuggerStepThrough]
  1000. public static v128 unpackhi_ps(v128 a, v128 b)
  1001. {
  1002. v128 dst = default(v128);
  1003. dst.Float0 = a.Float2;
  1004. dst.Float1 = b.Float2;
  1005. dst.Float2 = a.Float3;
  1006. dst.Float3 = b.Float3;
  1007. return dst;
  1008. }
  1009. // _mm_unpacklo_ps
  1010. /// <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>
  1011. /// <param name="a">Vector a</param>
  1012. /// <param name="b">Vector b</param>
  1013. /// <returns>Vector</returns>
  1014. [DebuggerStepThrough]
  1015. public static v128 unpacklo_ps(v128 a, v128 b)
  1016. {
  1017. v128 dst = default(v128);
  1018. dst.Float0 = a.Float0;
  1019. dst.Float1 = b.Float0;
  1020. dst.Float2 = a.Float1;
  1021. dst.Float3 = b.Float1;
  1022. return dst;
  1023. }
  1024. // _mm_movehl_ps
  1025. /// <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>
  1026. /// <param name="a">Vector a</param>
  1027. /// <param name="b">Vector b</param>
  1028. /// <returns>Vector</returns>
  1029. [DebuggerStepThrough]
  1030. public static v128 movehl_ps(v128 a, v128 b)
  1031. {
  1032. v128 dst = default(v128);
  1033. dst.Float0 = b.Float2;
  1034. dst.Float1 = b.Float3;
  1035. dst.Float2 = a.Float2;
  1036. dst.Float3 = a.Float3;
  1037. return dst;
  1038. }
  1039. // _mm_movelh_ps
  1040. /// <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>
  1041. /// <param name="a">Vector a</param>
  1042. /// <param name="b">Vector b</param>
  1043. /// <returns>Vector</returns>
  1044. [DebuggerStepThrough]
  1045. public static v128 movelh_ps(v128 a, v128 b)
  1046. {
  1047. v128 dst = default(v128);
  1048. dst.Float0 = a.Float0;
  1049. dst.Float1 = a.Float1;
  1050. dst.Float2 = b.Float0;
  1051. dst.Float3 = b.Float1;
  1052. return dst;
  1053. }
  1054. // _mm_movemask_ps
  1055. /// <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>
  1056. /// <param name="a">Vector a</param>
  1057. /// <returns>Integer</returns>
  1058. [DebuggerStepThrough]
  1059. public static int movemask_ps(v128 a)
  1060. {
  1061. int dst = 0;
  1062. if ((a.UInt0 & 0x80000000) != 0) dst |= 1;
  1063. if ((a.UInt1 & 0x80000000) != 0) dst |= 2;
  1064. if ((a.UInt2 & 0x80000000) != 0) dst |= 4;
  1065. if ((a.UInt3 & 0x80000000) != 0) dst |= 8;
  1066. return dst;
  1067. }
  1068. /// <summary>
  1069. /// Transposes a 4x4 matrix of single precision floating point values (_MM_TRANSPOSE4_PS).
  1070. /// </summary>
  1071. /// <remarks>
  1072. /// Arguments row0, row1, row2, and row3 are __m128
  1073. /// values whose elements form the corresponding rows
  1074. /// of a 4x4 matrix. The matrix transpose is returned
  1075. /// in arguments row0, row1, row2, and row3 where row0
  1076. /// now holds column 0 of the original matrix, row1 now
  1077. /// holds column 1 of the original matrix, etc.
  1078. /// </remarks>
  1079. /// <param name="row0">__m128 value on corresponding row</param>
  1080. /// <param name="row1">__m128 value on corresponding row</param>
  1081. /// <param name="row2">__m128 value on corresponding row</param>
  1082. /// <param name="row3">__m128 value on corresponding row</param>
  1083. [DebuggerStepThrough]
  1084. [BurstTargetCpu(BurstTargetCpu.X64_SSE2)]
  1085. public static void TRANSPOSE4_PS(ref v128 row0, ref v128 row1, ref v128 row2, ref v128 row3)
  1086. {
  1087. v128 _Tmp3, _Tmp2, _Tmp1, _Tmp0;
  1088. _Tmp0 = shuffle_ps((row0), (row1), 0x44);
  1089. _Tmp2 = shuffle_ps((row0), (row1), 0xEE);
  1090. _Tmp1 = shuffle_ps((row2), (row3), 0x44);
  1091. _Tmp3 = shuffle_ps((row2), (row3), 0xEE);
  1092. row0 = shuffle_ps(_Tmp0, _Tmp1, 0x88);
  1093. row1 = shuffle_ps(_Tmp0, _Tmp1, 0xDD);
  1094. row2 = shuffle_ps(_Tmp2, _Tmp3, 0x88);
  1095. row3 = shuffle_ps(_Tmp2, _Tmp3, 0xDD);
  1096. }
  1097. /// <summary>
  1098. /// Return vector of type v128 with all elements set to zero.
  1099. /// </summary>
  1100. /// <returns>Vector</returns>
  1101. [DebuggerStepThrough]
  1102. public static v128 setzero_ps()
  1103. {
  1104. return default;
  1105. }
  1106. /// <summary>
  1107. /// Load unaligned 16-bit integer from memory into the first element of dst.
  1108. /// </summary>
  1109. /// <param name="mem_addr">Memory address</param>
  1110. /// <returns>Vector</returns>
  1111. [DebuggerStepThrough]
  1112. public static v128 loadu_si16(void* mem_addr)
  1113. {
  1114. return new v128(*(short*)mem_addr, 0, 0, 0, 0, 0, 0, 0);
  1115. }
  1116. /// <summary>
  1117. /// Store 16-bit integer from the first element of a into memory.
  1118. /// mem_addr does not need to be aligned on any particular
  1119. /// boundary.
  1120. /// </summary>
  1121. /// <param name="mem_addr">Memory address</param>
  1122. /// <param name="a">Vector a</param>
  1123. public static void storeu_si16(void* mem_addr, v128 a)
  1124. {
  1125. *(short*)mem_addr = a.SShort0;
  1126. }
  1127. /// <summary>
  1128. /// Load unaligned 64-bit integer from memory into the first element of dst.
  1129. /// </summary>
  1130. /// <param name="mem_addr">Memory address</param>
  1131. /// <returns>Vector</returns>
  1132. [DebuggerStepThrough]
  1133. public static v128 loadu_si64(void* mem_addr)
  1134. {
  1135. return new v128(*(long*)mem_addr, 0);
  1136. }
  1137. /// <summary>
  1138. /// Store 64-bit integer from the first element of a into memory.
  1139. /// mem_addr does not need to be aligned on any particular
  1140. /// boundary.
  1141. /// </summary>
  1142. /// <param name="mem_addr">Memory address</param>
  1143. /// <param name="a">Vector a</param>
  1144. [DebuggerStepThrough]
  1145. public static void storeu_si64(void* mem_addr, v128 a)
  1146. {
  1147. *(long*)mem_addr = a.SLong0;
  1148. }
  1149. }
  1150. }
  1151. }