StructArrayHelpers.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Ryujinx.Common.Memory
  4. {
  5. public struct Array1<T> : IArray<T> where T : unmanaged
  6. {
  7. T _e0;
  8. public int Length => 1;
  9. public ref T this[int index] => ref ToSpan()[index];
  10. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 1);
  11. }
  12. public struct Array2<T> : IArray<T> where T : unmanaged
  13. {
  14. T _e0;
  15. Array1<T> _other;
  16. public int Length => 2;
  17. public ref T this[int index] => ref ToSpan()[index];
  18. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 2);
  19. }
  20. public struct Array3<T> : IArray<T> where T : unmanaged
  21. {
  22. T _e0;
  23. Array2<T> _other;
  24. public int Length => 3;
  25. public ref T this[int index] => ref ToSpan()[index];
  26. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 3);
  27. }
  28. public struct Array4<T> : IArray<T> where T : unmanaged
  29. {
  30. T _e0;
  31. Array3<T> _other;
  32. public int Length => 4;
  33. public ref T this[int index] => ref ToSpan()[index];
  34. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 4);
  35. }
  36. public struct Array5<T> : IArray<T> where T : unmanaged
  37. {
  38. T _e0;
  39. Array4<T> _other;
  40. public int Length => 5;
  41. public ref T this[int index] => ref ToSpan()[index];
  42. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 5);
  43. }
  44. public struct Array6<T> : IArray<T> where T : unmanaged
  45. {
  46. T _e0;
  47. Array5<T> _other;
  48. public int Length => 6;
  49. public ref T this[int index] => ref ToSpan()[index];
  50. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 6);
  51. }
  52. public struct Array7<T> : IArray<T> where T : unmanaged
  53. {
  54. T _e0;
  55. Array6<T> _other;
  56. public int Length => 7;
  57. public ref T this[int index] => ref ToSpan()[index];
  58. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 7);
  59. }
  60. public struct Array8<T> : IArray<T> where T : unmanaged
  61. {
  62. T _e0;
  63. Array7<T> _other;
  64. public int Length => 8;
  65. public ref T this[int index] => ref ToSpan()[index];
  66. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 8);
  67. }
  68. public struct Array9<T> : IArray<T> where T : unmanaged
  69. {
  70. T _e0;
  71. Array8<T> _other;
  72. public int Length => 9;
  73. public ref T this[int index] => ref ToSpan()[index];
  74. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 9);
  75. }
  76. public struct Array10<T> : IArray<T> where T : unmanaged
  77. {
  78. T _e0;
  79. Array9<T> _other;
  80. public int Length => 10;
  81. public ref T this[int index] => ref ToSpan()[index];
  82. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 10);
  83. }
  84. public struct Array11<T> : IArray<T> where T : unmanaged
  85. {
  86. T _e0;
  87. Array10<T> _other;
  88. public int Length => 11;
  89. public ref T this[int index] => ref ToSpan()[index];
  90. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 11);
  91. }
  92. public struct Array12<T> : IArray<T> where T : unmanaged
  93. {
  94. T _e0;
  95. Array11<T> _other;
  96. public int Length => 12;
  97. public ref T this[int index] => ref ToSpan()[index];
  98. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 12);
  99. }
  100. public struct Array13<T> : IArray<T> where T : unmanaged
  101. {
  102. T _e0;
  103. Array12<T> _other;
  104. public int Length => 13;
  105. public ref T this[int index] => ref ToSpan()[index];
  106. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 13);
  107. }
  108. public struct Array14<T> : IArray<T> where T : unmanaged
  109. {
  110. T _e0;
  111. Array13<T> _other;
  112. public int Length => 14;
  113. public ref T this[int index] => ref ToSpan()[index];
  114. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 14);
  115. }
  116. public struct Array15<T> : IArray<T> where T : unmanaged
  117. {
  118. T _e0;
  119. Array14<T> _other;
  120. public int Length => 15;
  121. public ref T this[int index] => ref ToSpan()[index];
  122. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 15);
  123. }
  124. public struct Array16<T> : IArray<T> where T : unmanaged
  125. {
  126. T _e0;
  127. Array15<T> _other;
  128. public int Length => 16;
  129. public ref T this[int index] => ref ToSpan()[index];
  130. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 16);
  131. }
  132. public struct Array17<T> : IArray<T> where T : unmanaged
  133. {
  134. T _e0;
  135. Array16<T> _other;
  136. public int Length => 17;
  137. public ref T this[int index] => ref ToSpan()[index];
  138. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 17);
  139. }
  140. public struct Array18<T> : IArray<T> where T : unmanaged
  141. {
  142. T _e0;
  143. Array17<T> _other;
  144. public int Length => 18;
  145. public ref T this[int index] => ref ToSpan()[index];
  146. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 18);
  147. }
  148. public struct Array19<T> : IArray<T> where T : unmanaged
  149. {
  150. T _e0;
  151. Array18<T> _other;
  152. public int Length => 19;
  153. public ref T this[int index] => ref ToSpan()[index];
  154. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 19);
  155. }
  156. public struct Array20<T> : IArray<T> where T : unmanaged
  157. {
  158. T _e0;
  159. Array19<T> _other;
  160. public int Length => 20;
  161. public ref T this[int index] => ref ToSpan()[index];
  162. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 20);
  163. }
  164. public struct Array21<T> : IArray<T> where T : unmanaged
  165. {
  166. T _e0;
  167. Array20<T> _other;
  168. public int Length => 21;
  169. public ref T this[int index] => ref ToSpan()[index];
  170. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 21);
  171. }
  172. public struct Array22<T> : IArray<T> where T : unmanaged
  173. {
  174. T _e0;
  175. Array21<T> _other;
  176. public int Length => 22;
  177. public ref T this[int index] => ref ToSpan()[index];
  178. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 22);
  179. }
  180. public struct Array23<T> : IArray<T> where T : unmanaged
  181. {
  182. T _e0;
  183. Array22<T> _other;
  184. public int Length => 23;
  185. public ref T this[int index] => ref ToSpan()[index];
  186. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 23);
  187. }
  188. public struct Array24<T> : IArray<T> where T : unmanaged
  189. {
  190. T _e0;
  191. Array23<T> _other;
  192. public int Length => 24;
  193. public ref T this[int index] => ref ToSpan()[index];
  194. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 24);
  195. }
  196. public struct Array25<T> : IArray<T> where T : unmanaged
  197. {
  198. T _e0;
  199. Array24<T> _other;
  200. public int Length => 25;
  201. public ref T this[int index] => ref ToSpan()[index];
  202. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 25);
  203. }
  204. public struct Array26<T> : IArray<T> where T : unmanaged
  205. {
  206. T _e0;
  207. Array25<T> _other;
  208. public int Length => 26;
  209. public ref T this[int index] => ref ToSpan()[index];
  210. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 26);
  211. }
  212. public struct Array27<T> : IArray<T> where T : unmanaged
  213. {
  214. T _e0;
  215. Array26<T> _other;
  216. public int Length => 27;
  217. public ref T this[int index] => ref ToSpan()[index];
  218. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 27);
  219. }
  220. public struct Array28<T> : IArray<T> where T : unmanaged
  221. {
  222. T _e0;
  223. Array27<T> _other;
  224. public int Length => 28;
  225. public ref T this[int index] => ref ToSpan()[index];
  226. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 28);
  227. }
  228. public struct Array29<T> : IArray<T> where T : unmanaged
  229. {
  230. T _e0;
  231. Array28<T> _other;
  232. public int Length => 29;
  233. public ref T this[int index] => ref ToSpan()[index];
  234. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 29);
  235. }
  236. public struct Array30<T> : IArray<T> where T : unmanaged
  237. {
  238. T _e0;
  239. Array29<T> _other;
  240. public int Length => 30;
  241. public ref T this[int index] => ref ToSpan()[index];
  242. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 30);
  243. }
  244. public struct Array31<T> : IArray<T> where T : unmanaged
  245. {
  246. T _e0;
  247. Array30<T> _other;
  248. public int Length => 31;
  249. public ref T this[int index] => ref ToSpan()[index];
  250. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 31);
  251. }
  252. public struct Array32<T> : IArray<T> where T : unmanaged
  253. {
  254. T _e0;
  255. Array31<T> _other;
  256. public int Length => 32;
  257. public ref T this[int index] => ref ToSpan()[index];
  258. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 32);
  259. }
  260. public struct Array33<T> : IArray<T> where T : unmanaged
  261. {
  262. T _e0;
  263. Array32<T> _other;
  264. public int Length => 33;
  265. public ref T this[int index] => ref ToSpan()[index];
  266. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 33);
  267. }
  268. public struct Array34<T> : IArray<T> where T : unmanaged
  269. {
  270. T _e0;
  271. Array33<T> _other;
  272. public int Length => 34;
  273. public ref T this[int index] => ref ToSpan()[index];
  274. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 34);
  275. }
  276. public struct Array35<T> : IArray<T> where T : unmanaged
  277. {
  278. T _e0;
  279. Array34<T> _other;
  280. public int Length => 35;
  281. public ref T this[int index] => ref ToSpan()[index];
  282. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 35);
  283. }
  284. public struct Array36<T> : IArray<T> where T : unmanaged
  285. {
  286. T _e0;
  287. Array35<T> _other;
  288. public int Length => 36;
  289. public ref T this[int index] => ref ToSpan()[index];
  290. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 36);
  291. }
  292. public struct Array37<T> : IArray<T> where T : unmanaged
  293. {
  294. T _e0;
  295. Array36<T> _other;
  296. public int Length => 37;
  297. public ref T this[int index] => ref ToSpan()[index];
  298. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 37);
  299. }
  300. public struct Array38<T> : IArray<T> where T : unmanaged
  301. {
  302. T _e0;
  303. Array37<T> _other;
  304. public int Length => 38;
  305. public ref T this[int index] => ref ToSpan()[index];
  306. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 38);
  307. }
  308. public struct Array39<T> : IArray<T> where T : unmanaged
  309. {
  310. T _e0;
  311. Array38<T> _other;
  312. public int Length => 39;
  313. public ref T this[int index] => ref ToSpan()[index];
  314. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 39);
  315. }
  316. public struct Array40<T> : IArray<T> where T : unmanaged
  317. {
  318. T _e0;
  319. Array39<T> _other;
  320. public int Length => 40;
  321. public ref T this[int index] => ref ToSpan()[index];
  322. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 40);
  323. }
  324. public struct Array41<T> : IArray<T> where T : unmanaged
  325. {
  326. T _e0;
  327. Array40<T> _other;
  328. public int Length => 41;
  329. public ref T this[int index] => ref ToSpan()[index];
  330. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 41);
  331. }
  332. public struct Array42<T> : IArray<T> where T : unmanaged
  333. {
  334. T _e0;
  335. Array41<T> _other;
  336. public int Length => 42;
  337. public ref T this[int index] => ref ToSpan()[index];
  338. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 42);
  339. }
  340. public struct Array43<T> : IArray<T> where T : unmanaged
  341. {
  342. T _e0;
  343. Array42<T> _other;
  344. public int Length => 43;
  345. public ref T this[int index] => ref ToSpan()[index];
  346. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 43);
  347. }
  348. public struct Array44<T> : IArray<T> where T : unmanaged
  349. {
  350. T _e0;
  351. Array43<T> _other;
  352. public int Length => 44;
  353. public ref T this[int index] => ref ToSpan()[index];
  354. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 44);
  355. }
  356. public struct Array45<T> : IArray<T> where T : unmanaged
  357. {
  358. T _e0;
  359. Array44<T> _other;
  360. public int Length => 45;
  361. public ref T this[int index] => ref ToSpan()[index];
  362. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 45);
  363. }
  364. public struct Array46<T> : IArray<T> where T : unmanaged
  365. {
  366. T _e0;
  367. Array45<T> _other;
  368. public int Length => 46;
  369. public ref T this[int index] => ref ToSpan()[index];
  370. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 46);
  371. }
  372. public struct Array47<T> : IArray<T> where T : unmanaged
  373. {
  374. T _e0;
  375. Array46<T> _other;
  376. public int Length => 47;
  377. public ref T this[int index] => ref ToSpan()[index];
  378. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 47);
  379. }
  380. public struct Array48<T> : IArray<T> where T : unmanaged
  381. {
  382. T _e0;
  383. Array47<T> _other;
  384. public int Length => 48;
  385. public ref T this[int index] => ref ToSpan()[index];
  386. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 48);
  387. }
  388. public struct Array49<T> : IArray<T> where T : unmanaged
  389. {
  390. T _e0;
  391. Array48<T> _other;
  392. public int Length => 49;
  393. public ref T this[int index] => ref ToSpan()[index];
  394. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 49);
  395. }
  396. public struct Array50<T> : IArray<T> where T : unmanaged
  397. {
  398. T _e0;
  399. Array49<T> _other;
  400. public int Length => 50;
  401. public ref T this[int index] => ref ToSpan()[index];
  402. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 50);
  403. }
  404. public struct Array51<T> : IArray<T> where T : unmanaged
  405. {
  406. T _e0;
  407. Array50<T> _other;
  408. public int Length => 51;
  409. public ref T this[int index] => ref ToSpan()[index];
  410. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 51);
  411. }
  412. public struct Array52<T> : IArray<T> where T : unmanaged
  413. {
  414. T _e0;
  415. Array51<T> _other;
  416. public int Length => 52;
  417. public ref T this[int index] => ref ToSpan()[index];
  418. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 52);
  419. }
  420. public struct Array53<T> : IArray<T> where T : unmanaged
  421. {
  422. T _e0;
  423. Array52<T> _other;
  424. public int Length => 53;
  425. public ref T this[int index] => ref ToSpan()[index];
  426. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 53);
  427. }
  428. public struct Array54<T> : IArray<T> where T : unmanaged
  429. {
  430. T _e0;
  431. Array53<T> _other;
  432. public int Length => 54;
  433. public ref T this[int index] => ref ToSpan()[index];
  434. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 54);
  435. }
  436. public struct Array55<T> : IArray<T> where T : unmanaged
  437. {
  438. T _e0;
  439. Array54<T> _other;
  440. public int Length => 55;
  441. public ref T this[int index] => ref ToSpan()[index];
  442. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 55);
  443. }
  444. public struct Array56<T> : IArray<T> where T : unmanaged
  445. {
  446. T _e0;
  447. Array55<T> _other;
  448. public int Length => 56;
  449. public ref T this[int index] => ref ToSpan()[index];
  450. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 56);
  451. }
  452. public struct Array57<T> : IArray<T> where T : unmanaged
  453. {
  454. T _e0;
  455. Array56<T> _other;
  456. public int Length => 57;
  457. public ref T this[int index] => ref ToSpan()[index];
  458. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 57);
  459. }
  460. public struct Array58<T> : IArray<T> where T : unmanaged
  461. {
  462. T _e0;
  463. Array57<T> _other;
  464. public int Length => 58;
  465. public ref T this[int index] => ref ToSpan()[index];
  466. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 58);
  467. }
  468. public struct Array59<T> : IArray<T> where T : unmanaged
  469. {
  470. T _e0;
  471. Array58<T> _other;
  472. public int Length => 59;
  473. public ref T this[int index] => ref ToSpan()[index];
  474. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 59);
  475. }
  476. public struct Array60<T> : IArray<T> where T : unmanaged
  477. {
  478. T _e0;
  479. Array59<T> _other;
  480. public int Length => 60;
  481. public ref T this[int index] => ref ToSpan()[index];
  482. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 60);
  483. }
  484. public struct Array61<T> : IArray<T> where T : unmanaged
  485. {
  486. T _e0;
  487. Array60<T> _other;
  488. public int Length => 61;
  489. public ref T this[int index] => ref ToSpan()[index];
  490. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 61);
  491. }
  492. public struct Array62<T> : IArray<T> where T : unmanaged
  493. {
  494. T _e0;
  495. Array61<T> _other;
  496. public int Length => 62;
  497. public ref T this[int index] => ref ToSpan()[index];
  498. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 62);
  499. }
  500. public struct Array63<T> : IArray<T> where T : unmanaged
  501. {
  502. T _e0;
  503. Array62<T> _other;
  504. public int Length => 63;
  505. public ref T this[int index] => ref ToSpan()[index];
  506. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 63);
  507. }
  508. public struct Array64<T> : IArray<T> where T : unmanaged
  509. {
  510. T _e0;
  511. Array63<T> _other;
  512. public int Length => 64;
  513. public ref T this[int index] => ref ToSpan()[index];
  514. public Span<T> ToSpan() => MemoryMarshal.CreateSpan(ref _e0, 64);
  515. }
  516. }