暫無描述
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.

030-Expressions.cs 48KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using Burst.Compiler.IL.Tests.Helpers;
  4. using NUnit.Framework;
  5. using Unity.Mathematics;
  6. namespace Burst.Compiler.IL.Tests
  7. {
  8. internal partial class Expressions
  9. {
  10. [TestCompiler((uint)(1 << 20))]
  11. [TestCompiler((uint)(1 << 15))]
  12. [TestCompiler(UInt32.MaxValue)]
  13. public static float ConvertUIntToFloat(uint rx)
  14. {
  15. var x = 2 * ((float)rx / uint.MaxValue - 0.5f);
  16. return x;
  17. }
  18. [TestCompiler((int)(1 << 20))]
  19. [TestCompiler((int)(1 << 15))]
  20. [TestCompiler(int.MinValue)]
  21. [TestCompiler(int.MaxValue)]
  22. public static float ConvertIntToFloat(int rx)
  23. {
  24. return (float) rx / -((float) int.MinValue);
  25. }
  26. [TestCompiler((uint)(1 << 20))]
  27. [TestCompiler((uint)(1 << 15))]
  28. [TestCompiler(UInt32.MaxValue)]
  29. public static float ConvertIntToFloat2(uint rx)
  30. {
  31. return 4.656613E-10f * (float)(int)rx;
  32. }
  33. [TestCompiler((uint)(1 << 20))]
  34. [TestCompiler((uint)(1 << 15))]
  35. [TestCompiler(UInt32.MaxValue)]
  36. public static float ConvertUIntToFloat2(uint rx)
  37. {
  38. return 4.656613E-10f * (float)rx;
  39. }
  40. [TestCompiler((int)-1, (uint)17)]
  41. [TestCompiler((int)(1 << 20), (uint)17)]
  42. [TestCompiler((int)(1 << 15), (uint)17)]
  43. [TestCompiler(int.MinValue, (uint)17)]
  44. [TestCompiler(int.MaxValue, (uint)17)]
  45. public static double ConvertIntToDouble(int rx, uint ry)
  46. {
  47. return (double)(rx + (int)ry) * 0.5;
  48. }
  49. [TestCompiler((int)-1, (uint)17)]
  50. [TestCompiler((int)(1 << 20), (uint)17)]
  51. [TestCompiler((int)(1 << 15), (uint)17)]
  52. [TestCompiler(int.MinValue, (uint)17)]
  53. [TestCompiler(int.MaxValue, (uint)17)]
  54. public static double ConvertIntToDouble2(int rx, uint ry)
  55. {
  56. return (double)((uint)rx + ry) * 0.5;
  57. }
  58. [TestCompiler(int.MinValue)]
  59. [TestCompiler(-15)]
  60. [TestCompiler(-1)]
  61. [TestCompiler(1)]
  62. [TestCompiler(15)]
  63. [TestCompiler(int.MaxValue)]
  64. public static long ConvertIntToLong(int value)
  65. {
  66. return value;
  67. }
  68. [TestCompiler(int.MinValue)]
  69. [TestCompiler(-15)]
  70. [TestCompiler(-1)]
  71. [TestCompiler(1)]
  72. [TestCompiler(15)]
  73. [TestCompiler(int.MaxValue)]
  74. public static ulong ConvertIntToULong(int value)
  75. {
  76. return (ulong)value;
  77. }
  78. [TestCompiler]
  79. public static ulong ConvertIntToLongConst()
  80. {
  81. return int.MaxValue;
  82. }
  83. [TestCompiler(1U)]
  84. [TestCompiler(15U)]
  85. [TestCompiler(uint.MaxValue)]
  86. public static long ConvertUIntToLong(uint value)
  87. {
  88. return value;
  89. }
  90. [TestCompiler]
  91. public static ulong ConvertUIntToLongConst()
  92. {
  93. return uint.MaxValue;
  94. }
  95. [TestCompiler(1U)]
  96. [TestCompiler(15U)]
  97. [TestCompiler(uint.MaxValue)]
  98. public static ulong ConvertUIntToULong(uint value)
  99. {
  100. return value;
  101. }
  102. [TestCompiler]
  103. public static ulong ConvertUIntToULongConst()
  104. {
  105. return uint.MaxValue;
  106. }
  107. [TestCompiler((uint)10)]
  108. [TestCompiler((uint)0xFFFFFFF6)]
  109. public static float NegateUIntToFloat(uint val)
  110. {
  111. return (float)-val;
  112. }
  113. [TestCompiler((uint)10)]
  114. [TestCompiler((uint)0xFFFFFFF6)]
  115. public static double NegateUIntToDouble(uint val)
  116. {
  117. return (double)-val;
  118. }
  119. [TestCompiler((ushort)10)]
  120. [TestCompiler((ushort)0xFFF6)]
  121. public static float NegateUInt16ToFloat(ushort val)
  122. {
  123. return (float)-val;
  124. }
  125. [TestCompiler((ushort)10)]
  126. [TestCompiler((ushort)0xFFF6)]
  127. public static double NegateUInt16ToDouble(ushort val)
  128. {
  129. return (double)-val;
  130. }
  131. [TestCompiler((Byte)100)]
  132. [TestCompiler((Byte)1)]
  133. [TestCompiler((Byte)0xF6)]
  134. public static float NegateByteToFloat(Byte val)
  135. {
  136. return (float)-val;
  137. }
  138. [TestCompiler((Byte)100)]
  139. [TestCompiler((Byte)1)]
  140. [TestCompiler((Byte)0xF6)]
  141. public static double NegateByteToDouble(Byte val)
  142. {
  143. return (double)-val;
  144. }
  145. [TestCompiler((Byte)'a')]
  146. [TestCompiler((Byte)0xF6)]
  147. public static float NegateCharToFloat(Byte val)
  148. {
  149. return (float)(-(char)val);
  150. }
  151. [TestCompiler((Byte)'a')]
  152. [TestCompiler((Byte)0xF6)]
  153. public static double NegateCharToDouble(Byte val)
  154. {
  155. return (double)-((char)val);
  156. }
  157. [TestCompiler((Byte)100)]
  158. [TestCompiler((Byte)1)]
  159. public static float RandomFloatFromByte(Byte deviation) =>
  160. new Unity.Mathematics.Random(8189782u)
  161. .NextFloat(-deviation, deviation);
  162. [TestCompiler(short.MinValue)]
  163. [TestCompiler((short)-15)]
  164. [TestCompiler((short)-1)]
  165. [TestCompiler((short)1)]
  166. [TestCompiler((short)15)]
  167. [TestCompiler(short.MaxValue)]
  168. public static int ConvertShortToInt(short value)
  169. {
  170. return value;
  171. }
  172. [TestCompiler]
  173. public static int ConvertShortToIntConstMin()
  174. {
  175. return short.MinValue;
  176. }
  177. [TestCompiler]
  178. public static int ConvertShortToIntConstMax()
  179. {
  180. return short.MaxValue;
  181. }
  182. [TestCompiler]
  183. public static int ConvertUShortToIntConstMax()
  184. {
  185. return ushort.MaxValue;
  186. }
  187. [TestCompiler]
  188. public static uint ConvertUShortToUIntConstMax()
  189. {
  190. return ushort.MaxValue;
  191. }
  192. [TestCompiler(short.MinValue)]
  193. [TestCompiler((short)-15)]
  194. [TestCompiler((short)-1)]
  195. [TestCompiler((short)1)]
  196. [TestCompiler((short)15)]
  197. [TestCompiler(short.MaxValue)]
  198. public static long ConvertShortToLong(short value)
  199. {
  200. return value;
  201. }
  202. [TestCompiler]
  203. public static long ConvertShortToLongConstMin()
  204. {
  205. return short.MinValue;
  206. }
  207. [TestCompiler]
  208. public static long ConvertShortToLongConstMax()
  209. {
  210. return short.MaxValue;
  211. }
  212. [TestCompiler(short.MinValue)]
  213. [TestCompiler((short)-15)]
  214. [TestCompiler((short)-1)]
  215. [TestCompiler((short)1)]
  216. [TestCompiler((short)15)]
  217. [TestCompiler(short.MaxValue)]
  218. public static ulong ConvertShortToULong(short value)
  219. {
  220. return (ulong)value;
  221. }
  222. [TestCompiler]
  223. public static ulong ConvertShortToULongConstMin()
  224. {
  225. return unchecked((ulong)short.MinValue);
  226. }
  227. [TestCompiler]
  228. public static ulong ConvertShortToULongConstMax()
  229. {
  230. return (ulong)short.MaxValue;
  231. }
  232. [TestCompiler(sbyte.MinValue)]
  233. [TestCompiler((sbyte)-15)]
  234. [TestCompiler((sbyte)-1)]
  235. [TestCompiler((sbyte)1)]
  236. [TestCompiler((sbyte)15)]
  237. [TestCompiler(sbyte.MaxValue)]
  238. public static long ConvertSbyteToLong(sbyte value)
  239. {
  240. return value;
  241. }
  242. [TestCompiler]
  243. public static long ConvertSbyteToLongConstMin()
  244. {
  245. return sbyte.MinValue;
  246. }
  247. [TestCompiler]
  248. public static long ConvertSbyteToLongConstMax()
  249. {
  250. return sbyte.MinValue;
  251. }
  252. [TestCompiler(sbyte.MinValue)]
  253. [TestCompiler((sbyte)-15)]
  254. [TestCompiler((sbyte)-1)]
  255. [TestCompiler((sbyte)1)]
  256. [TestCompiler((sbyte)15)]
  257. [TestCompiler(sbyte.MaxValue)]
  258. public static uint ConvertSbyteToUInt(sbyte value)
  259. {
  260. return (uint)value;
  261. }
  262. [TestCompiler]
  263. public static uint ConvertSbyteToUIntConstMin()
  264. {
  265. return unchecked((uint)sbyte.MinValue);
  266. }
  267. [TestCompiler]
  268. public static uint ConvertSbyteToUIntConstMax()
  269. {
  270. return unchecked((uint)sbyte.MinValue);
  271. }
  272. [Ignore("Incorrect results in mono")]
  273. [TestCompiler(0.0f)]
  274. [TestCompiler(1.0f)]
  275. [TestCompiler(0.5f)]
  276. [TestCompiler(0.1f)]
  277. [TestCompiler(0.9f, OverrideResultOnMono = 135)]
  278. public static byte ConvertFloatToByte(float value)
  279. {
  280. return (byte) (150 * value);
  281. }
  282. [TestCompiler(true, true)]
  283. [TestCompiler(true, false)]
  284. [TestCompiler(false, true)]
  285. [TestCompiler(false, false)]
  286. public static bool CompareEqualBool(bool left, bool right)
  287. {
  288. return left == right;
  289. }
  290. [TestCompiler(true, true)]
  291. [TestCompiler(true, false)]
  292. [TestCompiler(false, true)]
  293. [TestCompiler(false, false)]
  294. public static bool CompareNotEqualBool(bool left, bool right)
  295. {
  296. return left != right;
  297. }
  298. [TestCompiler(true)]
  299. [TestCompiler(false)]
  300. public static bool CompareBoolWithConst(bool left)
  301. {
  302. return left == false;
  303. }
  304. [TestCompiler(1, 1)]
  305. [TestCompiler(0, -1)]
  306. [TestCompiler(-1, -1)]
  307. [TestCompiler(0, 0)]
  308. public static bool CompareEqualInt32(int left, int right)
  309. {
  310. return left == right;
  311. }
  312. [TestCompiler(1)]
  313. [TestCompiler(0)]
  314. [TestCompiler(-1)]
  315. public static bool CompareEqualInt32WithConst(int left)
  316. {
  317. return left == -1;
  318. }
  319. [TestCompiler(1, 1)]
  320. [TestCompiler(0, -1)]
  321. [TestCompiler(-1, -1)]
  322. [TestCompiler(0, 0)]
  323. public static bool CompareNotEqualInt32(int left, int right)
  324. {
  325. return left != right;
  326. }
  327. [TestCompiler(1, 5)]
  328. [TestCompiler(1, 1)]
  329. [TestCompiler(0, -1)]
  330. [TestCompiler(-1, 1)]
  331. [TestCompiler(0, 1)]
  332. public static bool CompareLessThanInt32(int left, int right)
  333. {
  334. return left < right;
  335. }
  336. [TestCompiler(1L, 5)]
  337. [TestCompiler(1L, 1)]
  338. [TestCompiler(0L, -1)]
  339. [TestCompiler(-1L, 1)]
  340. [TestCompiler(0L, 1)]
  341. public static bool CompareLessThanInt64Int32(long left, int right)
  342. {
  343. return left < right;
  344. }
  345. [TestCompiler(1U, 5)]
  346. [TestCompiler(1U, 1)]
  347. [TestCompiler(0U, -1)]
  348. [TestCompiler(0x80000000U, 1)]
  349. [TestCompiler(0xFFFFFFFFU, 1)]
  350. [TestCompiler(0U, 1)]
  351. public static bool CompareLessThanUInt32Int32(uint left, int right)
  352. {
  353. return left < right;
  354. }
  355. [TestCompiler(1U, 5)]
  356. [TestCompiler(1U, 1)]
  357. [TestCompiler(0U, -1)]
  358. [TestCompiler(0x80000000U, 1)]
  359. [TestCompiler(0xFFFFFFFFU, 1)]
  360. [TestCompiler(0U, 1)]
  361. public static bool CompareGreaterThanUInt32Int32(uint left, int right)
  362. {
  363. return left > right;
  364. }
  365. [TestCompiler(5, 1U)]
  366. [TestCompiler(1, 1U)]
  367. [TestCompiler(-1, 0U)]
  368. [TestCompiler(1, 0x80000000U)]
  369. [TestCompiler(1, 0xFFFFFFFFU)]
  370. [TestCompiler(1, 0U)]
  371. public static bool CompareLessThanInt32UInt32(int left, uint right)
  372. {
  373. return left < right;
  374. }
  375. [TestCompiler(5, 1U)]
  376. [TestCompiler(1, 1U)]
  377. [TestCompiler(-1, 0U)]
  378. [TestCompiler(1, 0x80000000U)]
  379. [TestCompiler(1, 0xFFFFFFFFU)]
  380. [TestCompiler(1, 0U)]
  381. public static bool CompareGreaterThanInt32UInt32(int left, uint right)
  382. {
  383. return left > right;
  384. }
  385. [TestCompiler(1, 5)]
  386. [TestCompiler(1, 1)]
  387. [TestCompiler(0, -1)]
  388. [TestCompiler(-1, 1)]
  389. [TestCompiler(0, 1)]
  390. public static bool CompareGreaterThanInt32(int left, int right)
  391. {
  392. return left > right;
  393. }
  394. [TestCompiler(1, 5)]
  395. [TestCompiler(1, 1)]
  396. [TestCompiler(0, -1)]
  397. [TestCompiler(40, -1)]
  398. [TestCompiler(-10, 3)]
  399. [TestCompiler(0, 13)]
  400. [TestCompiler(4, 7)]
  401. [TestCompiler(125, 7)]
  402. public static bool CompareGreaterOrEqualInt32(int left, int right)
  403. {
  404. return left >= right;
  405. }
  406. [TestCompiler(1, 5)]
  407. [TestCompiler(1, 1)]
  408. [TestCompiler(0, -1)]
  409. [TestCompiler(40, -1)]
  410. [TestCompiler(-10, 3)]
  411. [TestCompiler(0, 13)]
  412. [TestCompiler(4, 7)]
  413. [TestCompiler(125, 7)]
  414. public static bool CompareLessOrEqualInt32(int left, int right)
  415. {
  416. return left <= right;
  417. }
  418. [TestCompiler]
  419. public static bool CompareEqualFloatConstant()
  420. {
  421. return 0 == float.NaN;
  422. }
  423. [TestCompiler]
  424. public static bool CompareNotEqualFloatConstant()
  425. {
  426. return 0 != float.NaN;
  427. }
  428. [TestCompiler]
  429. public static bool CompareLessThanFloatConstant()
  430. {
  431. return 0 < float.NaN;
  432. }
  433. [TestCompiler]
  434. public static bool CompareLessThanEqualFloatConstant()
  435. {
  436. return 0 <= float.NaN;
  437. }
  438. [TestCompiler]
  439. public static bool CompareGreaterThanFloatConstant()
  440. {
  441. return 0 > float.NaN;
  442. }
  443. [TestCompiler]
  444. public static bool CompareLGreaterThanEqualFloatConstant()
  445. {
  446. return 0 >= float.NaN;
  447. }
  448. [TestCompiler(DataRange.Minus100To100, DataRange.Minus100To100)]
  449. [TestCompiler(0, float.NaN)]
  450. [TestCompiler(float.NaN, float.NaN)]
  451. [TestCompiler(float.PositiveInfinity, float.NegativeInfinity)]
  452. [TestCompiler(float.PositiveInfinity, float.PositiveInfinity)]
  453. [TestCompiler(float.NegativeInfinity, float.NegativeInfinity)]
  454. public static bool CompareEqualFloat(float left, float right)
  455. {
  456. return left == right;
  457. }
  458. [TestCompiler(DataRange.Minus100To100, DataRange.Minus100To100)]
  459. [TestCompiler(0, -0)]
  460. [TestCompiler(0, float.NaN)]
  461. [TestCompiler(float.NaN, float.NaN)]
  462. [TestCompiler(float.PositiveInfinity, float.NegativeInfinity)]
  463. [TestCompiler(float.PositiveInfinity, float.PositiveInfinity)]
  464. [TestCompiler(float.NegativeInfinity, float.NegativeInfinity)]
  465. public static bool CompareNotEqualFloat(float left, float right)
  466. {
  467. return left != right;
  468. }
  469. [TestCompiler(DataRange.Minus100To100, DataRange.Minus100To100)]
  470. [TestCompiler(0, -0)]
  471. [TestCompiler(0, float.NaN)]
  472. [TestCompiler(float.NaN, float.NaN)]
  473. [TestCompiler(float.PositiveInfinity, float.NegativeInfinity)]
  474. [TestCompiler(float.PositiveInfinity, float.PositiveInfinity)]
  475. [TestCompiler(float.NegativeInfinity, float.NegativeInfinity)]
  476. public static bool CompareLessThanFloat(float left, float right)
  477. {
  478. return left < right;
  479. }
  480. [TestCompiler(DataRange.Minus100To100, DataRange.Minus100To100)]
  481. [TestCompiler(0, -0)]
  482. [TestCompiler(0, float.NaN)]
  483. [TestCompiler(float.NaN, float.NaN)]
  484. [TestCompiler(float.PositiveInfinity, float.NegativeInfinity)]
  485. [TestCompiler(float.PositiveInfinity, float.PositiveInfinity)]
  486. [TestCompiler(float.NegativeInfinity, float.NegativeInfinity)]
  487. public static bool CompareLessThanEqualFloat(float left, float right)
  488. {
  489. return left <= right;
  490. }
  491. [TestCompiler(DataRange.Minus100To100, DataRange.Minus100To100)]
  492. [TestCompiler(0, -0)]
  493. [TestCompiler(0, float.NaN)]
  494. [TestCompiler(float.NaN, float.NaN)]
  495. [TestCompiler(float.PositiveInfinity, float.NegativeInfinity)]
  496. [TestCompiler(float.PositiveInfinity, float.PositiveInfinity)]
  497. [TestCompiler(float.NegativeInfinity, float.NegativeInfinity)]
  498. public static bool CompareGreaterThanFloat(float left, float right)
  499. {
  500. return left > right;
  501. }
  502. [TestCompiler(DataRange.Minus100To100, DataRange.Minus100To100)]
  503. [TestCompiler(0, -0)]
  504. [TestCompiler(0, float.NaN)]
  505. [TestCompiler(float.NaN, float.NaN)]
  506. [TestCompiler(float.PositiveInfinity, float.NegativeInfinity)]
  507. [TestCompiler(float.PositiveInfinity, float.PositiveInfinity)]
  508. [TestCompiler(float.NegativeInfinity, float.NegativeInfinity)]
  509. public static bool CompareGreaterThanEqualFloat(float left, float right)
  510. {
  511. return left >= right;
  512. }
  513. #if UNITY_2021_3_OR_NEWER
  514. [TestCompiler(12321)]
  515. public static nint BitwiseNotNInt(int x)
  516. {
  517. var y = (nint)x;
  518. return ~y;
  519. }
  520. [TestCompiler(0x3213522U)]
  521. public static nuint BitwiseNUint(uint x)
  522. {
  523. var y = (nuint)x;
  524. return ~y;
  525. }
  526. [TestCompiler(12321)]
  527. public static nint NegateNInt(int x)
  528. {
  529. var y = (nint)x;
  530. return -y;
  531. }
  532. #if !ENABLE_IL2CPP
  533. [TestCompiler(0x3213522U)]
  534. public static unsafe uint NotNintToPtr(uint x)
  535. {
  536. var ptr = (void*)x;
  537. static void* Op(void* ptr) => (void*)~(nint)ptr;
  538. return (uint)Op(ptr);
  539. }
  540. [TestCompiler(0x3213522U)]
  541. public static unsafe uint NotNUintToPtr(uint x)
  542. {
  543. var ptr = (void*)x;
  544. static void* Op(void* ptr) => (void*)~(nuint)ptr;
  545. return (uint)Op(ptr);
  546. }
  547. [TestCompiler(0x3213522U)]
  548. public static unsafe uint NegateNintToPtr(uint x)
  549. {
  550. var ptr = (void*)x;
  551. static void* Op(void* ptr) => (void*)-(nint)ptr;
  552. return (uint)Op(ptr);
  553. }
  554. [TestCompiler(0x3213522U, 0x3221312U)]
  555. public static unsafe uint AddNintToPtr(uint x, uint y)
  556. {
  557. var ptr = (void*)x;
  558. static void* Op(void* ptr, uint y) => (void*)((nint)ptr + (nint)y);
  559. return (uint)Op(ptr, y);
  560. }
  561. [TestCompiler(0x3213522U, 0x3221312U)]
  562. public static unsafe uint SubNintToPtr(uint x, uint y)
  563. {
  564. var ptr = (void*)x;
  565. static void* Op(void* ptr, uint y) => (void*)((nint)ptr - (nint)y);
  566. return (uint)Op(ptr, y);
  567. }
  568. #endif
  569. #endif
  570. [TestCompiler(1, 5)]
  571. [TestCompiler(1, 1)]
  572. [TestCompiler(0, -1)]
  573. [TestCompiler(40, -1)]
  574. [TestCompiler(-10, 3)]
  575. [TestCompiler(0, 13)]
  576. [TestCompiler(4, 7)]
  577. [TestCompiler(125, 7)]
  578. public static int BinaryNumericAdd(int left, int right)
  579. {
  580. return left + right;
  581. }
  582. [TestCompiler(1, 5)]
  583. [TestCompiler(1, 1)]
  584. [TestCompiler(0, -1)]
  585. [TestCompiler(40, -1)]
  586. [TestCompiler(-10, 3)]
  587. [TestCompiler(0, 13)]
  588. [TestCompiler(4, 7)]
  589. [TestCompiler(125, 7)]
  590. public static int BinaryNumericSub(int left, int right)
  591. {
  592. return left - right;
  593. }
  594. [TestCompiler(1, 5)]
  595. [TestCompiler(1, 1)]
  596. [TestCompiler(0, -1)]
  597. [TestCompiler(40, -1)]
  598. [TestCompiler(-10, 3)]
  599. [TestCompiler(0, 13)]
  600. [TestCompiler(4, 7)]
  601. [TestCompiler(125, 7)]
  602. public static int BinaryNumericDiv(int left, int right)
  603. {
  604. return left / right;
  605. }
  606. [TestCompiler(1L, 5)]
  607. [TestCompiler(1L, 1)]
  608. [TestCompiler(0L, -1)]
  609. [TestCompiler(40L, -1)]
  610. [TestCompiler(-10L, 3)]
  611. [TestCompiler(0L, 13)]
  612. [TestCompiler(4L, 7)]
  613. [TestCompiler(125L, 7)]
  614. public static long BinaryNumericDiv64(long left, int right)
  615. {
  616. return left / right;
  617. }
  618. [TestCompiler(1, 5)]
  619. [TestCompiler(1, 1)]
  620. [TestCompiler(0, -1)]
  621. [TestCompiler(40, -1)]
  622. [TestCompiler(-10, 3)]
  623. [TestCompiler(0, 13)]
  624. [TestCompiler(4, 7)]
  625. [TestCompiler(125, 7)]
  626. public static int BinaryNumericRem(int left, int right)
  627. {
  628. return left % right;
  629. }
  630. [TestCompiler(1, 5)]
  631. [TestCompiler(1, 1)]
  632. [TestCompiler(0, -1)]
  633. [TestCompiler(40, -1)]
  634. [TestCompiler(-10, 3)]
  635. [TestCompiler(0, 13)]
  636. [TestCompiler(4, 7)]
  637. [TestCompiler(125, 7)]
  638. public static int BinaryNumericMul(int left, int right)
  639. {
  640. return left * right;
  641. }
  642. [TestCompiler(1, 5)]
  643. [TestCompiler(1, 1)]
  644. [TestCompiler(0, -1)]
  645. [TestCompiler(40, -1)]
  646. [TestCompiler(-10, 3)]
  647. [TestCompiler(0, 13)]
  648. [TestCompiler(4, 7)]
  649. [TestCompiler(125, 7)]
  650. public static int BinaryNumericAnd(int left, int right)
  651. {
  652. return left & right;
  653. }
  654. [TestCompiler(1, 5)]
  655. [TestCompiler(1, 1)]
  656. [TestCompiler(0, -1)]
  657. [TestCompiler(40, -1)]
  658. [TestCompiler(-10, 3)]
  659. [TestCompiler(0, 13)]
  660. [TestCompiler(4, 7)]
  661. [TestCompiler(125, 7)]
  662. public static int BinaryNumericOr(int left, int right)
  663. {
  664. return left | right;
  665. }
  666. [TestCompiler(1, 5)]
  667. [TestCompiler(1, 1)]
  668. [TestCompiler(0, -1)]
  669. [TestCompiler(40, -1)]
  670. [TestCompiler(-10, 3)]
  671. [TestCompiler(0, 13)]
  672. [TestCompiler(4, 7)]
  673. [TestCompiler(125, 7)]
  674. public static int BinaryNumericXor(int left, int right)
  675. {
  676. return left ^ right;
  677. }
  678. [TestCompiler(1, 0)]
  679. [TestCompiler(1, 5)]
  680. [TestCompiler(7, 10)]
  681. [TestCompiler(-1, 1)]
  682. public static int BinaryNumericShiftLeft(int left, int right)
  683. {
  684. return left << right;
  685. }
  686. [TestCompiler(1, 0)]
  687. [TestCompiler(1, 5)]
  688. [TestCompiler(7, 10)]
  689. [TestCompiler(-1, 1)]
  690. public static int BinaryNumericShiftRight(int left, int right)
  691. {
  692. return left >> right;
  693. }
  694. [TestCompiler(1U, 0)]
  695. [TestCompiler(1U, 5)]
  696. [TestCompiler(7U, 10)]
  697. [TestCompiler(0xFFFFFFFFU, 1)]
  698. public static uint BinaryNumericShiftLeftUInt32(uint left, int right)
  699. {
  700. return left << right;
  701. }
  702. [TestCompiler(1U, 0)]
  703. [TestCompiler(1U, 5)]
  704. [TestCompiler(7U, 10)]
  705. [TestCompiler(0x80000000U, 1)]
  706. [TestCompiler(0xFFFFFFFFU, 1)]
  707. public static uint BinaryNumericShiftRightUInt32(uint left, int right)
  708. {
  709. return left >> right;
  710. }
  711. [TestCompiler(1U, 0)]
  712. [TestCompiler(1U, 5)]
  713. [TestCompiler(7U, 10)]
  714. [TestCompiler(0x80000000U, 1)]
  715. [TestCompiler(0xFFFFFFFFU, 1)]
  716. public static int BinaryNumericShiftRightUIntToInt32(uint left, int right)
  717. {
  718. return ((int)left) >> right;
  719. }
  720. #if UNITY_2021_3_OR_NEWER
  721. [TestCompiler(0U)]
  722. [TestCompiler(1U)]
  723. [TestCompiler(0x212412U)]
  724. public static nuint UnderflowNUInt(uint i)
  725. {
  726. return Not((nuint)i);
  727. [MethodImpl(MethodImplOptions.NoInlining)]
  728. static nuint Not(nuint n) => 0 - n - 1;
  729. }
  730. [TestCompiler(0)]
  731. [TestCompiler(1)]
  732. [TestCompiler(0x212412)]
  733. public static nint UnderflowNInt(int i)
  734. {
  735. return Not((nint)i);
  736. [MethodImpl(MethodImplOptions.NoInlining)]
  737. static nint Not(nint n) => 0 - n - 1;
  738. }
  739. [TestCompiler(2, 3)]
  740. [TestCompiler(5, -2)]
  741. public static nint BinaryNInt(int i, int j)
  742. {
  743. var m = (nint)i;
  744. var n = (nint)j;
  745. var r = ((m + n) << 0) + ((m * n) << 4) + ((m / n) << 8) + ((m - n) << 12) + ((m % n) << 16) +
  746. ((m | n) << 20) + ((m & n) << 24) + ((m ^ n) << 28);
  747. return r;
  748. }
  749. [TestCompiler(2U, 3U)]
  750. [TestCompiler(5U, 2U)]
  751. public static nuint BinaryNUInt(uint i, uint j)
  752. {
  753. var m = (nuint)i;
  754. var n = (nuint)j;
  755. var r = ((m + n) << 0) + ((m * n) << 4) + ((m / n) << 8) + ((m - n) << 12) + ((m % n) << 16) +
  756. ((m | n) << 20) + ((m & n) << 24) + ((m ^ n) << 28);
  757. return r;
  758. }
  759. #endif
  760. [TestCompiler]
  761. public static int ConstantMinus1()
  762. {
  763. return -1;
  764. }
  765. [TestCompiler]
  766. public static int Constant1()
  767. {
  768. return 1;
  769. }
  770. [TestCompiler]
  771. public static int Constant2()
  772. {
  773. return 2;
  774. }
  775. [TestCompiler]
  776. public static int Constant3()
  777. {
  778. return 3;
  779. }
  780. [TestCompiler]
  781. public static int Constant4()
  782. {
  783. return 4;
  784. }
  785. [TestCompiler]
  786. public static int Constant5()
  787. {
  788. return 5;
  789. }
  790. [TestCompiler]
  791. public static int Constant6()
  792. {
  793. return 6;
  794. }
  795. [TestCompiler]
  796. public static int Constant7()
  797. {
  798. return 7;
  799. }
  800. [TestCompiler]
  801. public static int Constant8()
  802. {
  803. return 8;
  804. }
  805. [TestCompiler]
  806. public static int Constant121()
  807. {
  808. return 121;
  809. }
  810. [TestCompiler]
  811. public static bool ReturnBoolTrue()
  812. {
  813. return true;
  814. }
  815. [TestCompiler]
  816. public static bool ReturnBoolFalse()
  817. {
  818. return false;
  819. }
  820. [TestCompiler((int)0x10203040)]
  821. [TestCompiler((int)0x20203040)]
  822. [TestCompiler((int)0x30203040)]
  823. [TestCompiler((int)0x40203040)]
  824. [TestCompiler((int)0x50203040)]
  825. [TestCompiler((int)0x60203040)]
  826. [TestCompiler((int)0x70203040)]
  827. public static int AddOverflowInt(int x)
  828. {
  829. x += 0x70506070;
  830. return x;
  831. }
  832. [TestCompiler]
  833. public static int test_expr_add_one_to_zero()
  834. {
  835. var x = 0;
  836. x++;
  837. return x;
  838. }
  839. [TestCompiler(1f)]
  840. public static float test_expr_add_multiples(float a)
  841. {
  842. return a + a + a + a;
  843. }
  844. [TestCompiler(1f, 2f)]
  845. public static float test_expr_add_two_arguments(float a, float b)
  846. {
  847. return a + b;
  848. }
  849. [TestCompiler(3f, 4f)]
  850. public static float test_expr_multiply_two_arguments(float a, float b)
  851. {
  852. return a * b;
  853. }
  854. [TestCompiler(3f)]
  855. [TestCompiler(-4f)]
  856. [TestCompiler(0f)]
  857. public static float test_expr_negateResult_float(float a)
  858. {
  859. return -a;
  860. }
  861. [TestCompiler((sbyte)3)]
  862. [TestCompiler((sbyte)-4)]
  863. [TestCompiler((sbyte)0)]
  864. [TestCompiler(sbyte.MinValue)]
  865. [TestCompiler(sbyte.MaxValue)]
  866. public static int test_expr_negateResult_sbyte(sbyte a)
  867. {
  868. return -a;
  869. }
  870. [TestCompiler((byte)3)]
  871. [TestCompiler((byte)0)]
  872. [TestCompiler(byte.MaxValue, OverrideManagedResult = -255)] // TODO: IL2CPP on macOS currently produces incorrect result of "1". Remove this OverrideManagedResult when that bug is fixed.
  873. public static int test_expr_negateResult_byte(byte a)
  874. {
  875. return -a;
  876. }
  877. [TestCompiler((short)3)]
  878. [TestCompiler((short)-4)]
  879. [TestCompiler((short)0)]
  880. [TestCompiler(short.MinValue)]
  881. [TestCompiler(short.MaxValue)]
  882. public static int test_expr_negateResult_short(short a)
  883. {
  884. return -a;
  885. }
  886. [TestCompiler((ushort)3)]
  887. [TestCompiler((ushort)0)]
  888. [TestCompiler(ushort.MaxValue, OverrideManagedResult = -65535)] // TODO: IL2CPP on macOS currently produces incorrect result of "1". Remove this OverrideManagedResult when that bug is fixed.
  889. public static int test_expr_negateResult_ushort(ushort a)
  890. {
  891. return -a;
  892. }
  893. [TestCompiler(3)]
  894. [TestCompiler(-4)]
  895. [TestCompiler(0)]
  896. [TestCompiler(int.MinValue)]
  897. [TestCompiler(int.MaxValue)]
  898. public static int test_expr_negateResult_int(int a)
  899. {
  900. return -a;
  901. }
  902. [TestCompiler(3u)]
  903. [TestCompiler(0u)]
  904. [TestCompiler(uint.MaxValue)]
  905. public static long test_expr_negateResult_uint(uint a)
  906. {
  907. return -a;
  908. }
  909. [TestCompiler((long)3)]
  910. [TestCompiler((long)-4)]
  911. [TestCompiler((long)0)]
  912. [TestCompiler(long.MinValue)]
  913. [TestCompiler(long.MaxValue)]
  914. public static long test_expr_negateResult_long(long a)
  915. {
  916. return -a;
  917. }
  918. [TestCompiler]
  919. public static float test_expr_return_constant()
  920. {
  921. return 12f;
  922. }
  923. [TestCompiler]
  924. public static float test_multiple_assigment()
  925. {
  926. float x, y, z;
  927. x = y = z = 5.0F;
  928. return x + y + z;
  929. }
  930. [TestCompiler(4f, 9f)]
  931. public static float test_expr_various_math(float a, float b)
  932. {
  933. return (a + b) * b * b * 0.4f / (a + a + a * 0.2f);
  934. }
  935. [TestCompiler(4.1f)]
  936. public static float test_expr_multiply_int_by_float(float a)
  937. {
  938. var i = 18;
  939. return i * a;
  940. }
  941. [TestCompiler(4f)]
  942. public static int test_expr_cast_float_to_int(float a)
  943. {
  944. return (int)a;
  945. }
  946. [TestCompiler(4)]
  947. public static float test_expr_cast_int_to_float(int a)
  948. {
  949. return a;
  950. }
  951. [TestCompiler(5)]
  952. public static int test_expr_assign_to_argument(int a)
  953. {
  954. a = a * a;
  955. return a;
  956. }
  957. [TestCompiler(7)]
  958. public static int test_expr_postincrement(int input)
  959. {
  960. var a = input++;
  961. return a + input;
  962. }
  963. [TestCompiler(2)]
  964. [TestCompiler(3)]
  965. public static int test_expr_mod(int input)
  966. {
  967. return input % 2;
  968. }
  969. [TestCompiler(0, 0)]
  970. [TestCompiler(0, 1)]
  971. [TestCompiler(1, 0)]
  972. [TestCompiler(1, 1)]
  973. public static int test_expr_xor(int a, int b)
  974. {
  975. return a ^ b;
  976. }
  977. [TestCompiler(1, 2)]
  978. [TestCompiler(0, 0)]
  979. [TestCompiler(1, 0)]
  980. [TestCompiler(1, 1)]
  981. public static int test_expr_or(int a, int b)
  982. {
  983. return a | b;
  984. }
  985. [TestCompiler(1, 3)]
  986. [TestCompiler(0, 0)]
  987. [TestCompiler(1, 0)]
  988. [TestCompiler(1, 1)]
  989. public static int test_expr_and(int a, int b)
  990. {
  991. return a & b;
  992. }
  993. [TestCompiler(-100000.0F)]
  994. public static float test_math_large_values(float a)
  995. {
  996. return (a * a) + ((a + 3.0F) * a);
  997. }
  998. [TestCompiler(1)]
  999. [TestCompiler(150)]
  1000. [TestCompiler(-1)]
  1001. [TestCompiler(-150)]
  1002. public static int test_expr_shift_right(int n)
  1003. {
  1004. return n >> 3;
  1005. }
  1006. [TestCompiler(1)]
  1007. [TestCompiler(31)]
  1008. public static int test_expr_shift(int n)
  1009. {
  1010. int a = 5;
  1011. a <<= n;
  1012. a += (a >> 31);
  1013. return a;
  1014. }
  1015. [TestCompiler(2)]
  1016. [TestCompiler(-3)]
  1017. public static int test_expr_complement(int input)
  1018. {
  1019. return ~input;
  1020. }
  1021. [TestCompiler]
  1022. public static int test_expr_sizeof_int()
  1023. {
  1024. return sizeof(int);
  1025. }
  1026. [TestCompiler(-1)]
  1027. [TestCompiler(0)]
  1028. [TestCompiler(12)]
  1029. public static int test_expr_generic_equatable(int a)
  1030. {
  1031. if (EqualityTester<int>.Check(a, 12))
  1032. return 1;
  1033. else
  1034. return 0;
  1035. }
  1036. struct EqualityTester<TKey> where TKey : IEquatable<TKey>
  1037. {
  1038. public static bool Check(TKey value1, TKey value2)
  1039. {
  1040. return value1.Equals(value2);
  1041. }
  1042. }
  1043. [TestCompiler(0)]
  1044. [TestCompiler(1)]
  1045. [TestCompiler(-1)]
  1046. public static bool test_expr_bool_passing(int a)
  1047. {
  1048. return a == 0;
  1049. }
  1050. const int ConstValue = 5;
  1051. [TestCompiler]
  1052. public static int test_expr_load_static_constant()
  1053. {
  1054. return ConstValue;
  1055. }
  1056. [TestCompiler(1)]
  1057. [TestCompiler(-1)]
  1058. public static int OutInt32(int a)
  1059. {
  1060. int b;
  1061. OutputInt32(out b);
  1062. return a + b;
  1063. }
  1064. [TestCompiler(-1)]
  1065. [TestCompiler(1)]
  1066. public static int CallPushAndPop(int a)
  1067. {
  1068. int result = 0;
  1069. int value;
  1070. TryAdd(a, out value);
  1071. result += value * 10;
  1072. TryAdd(a * 2, out value);
  1073. result += value * 10;
  1074. TryAdd(a * 3, out value);
  1075. result += value * 10;
  1076. TryAdd(a * 4, out value);
  1077. result += value * 10;
  1078. return result;
  1079. }
  1080. private static readonly Yoyo[] StaticArray2 = new Yoyo[5];
  1081. struct Yoyo
  1082. {
  1083. #pragma warning disable 0169, 0649
  1084. public int a;
  1085. private int b;
  1086. #pragma warning restore 0169, 0649
  1087. }
  1088. private static bool TryAdd(int a, out int result)
  1089. {
  1090. result = a + 5;
  1091. return true;
  1092. }
  1093. public static void OutputInt32(out int value)
  1094. {
  1095. value = 5;
  1096. }
  1097. [TestCompiler]
  1098. public static long TypeConversionAndOverflow()
  1099. {
  1100. byte ba = 0xFF;
  1101. byte bb = 1;
  1102. sbyte sba = 127;
  1103. sbyte sbb = 1;
  1104. short sa = 0x7FFF;
  1105. short sb = 1;
  1106. ushort usa = 0xFFFF;
  1107. ushort usb = 1;
  1108. uint x = 0xFFFFFFFF;
  1109. int y = 1;
  1110. long z = 1;
  1111. return (ba + bb) + (sba + sbb) + (sa + sb) + (usa + usb) + (x + y) + (x + z);
  1112. }
  1113. private static void AssignValue(int switchValue, ref float value)
  1114. {
  1115. value = 0.0F;
  1116. if (switchValue == 0)
  1117. return;
  1118. value = 1.0F;
  1119. if (switchValue == 1)
  1120. return;
  1121. value = 2.0F;
  1122. return;
  1123. }
  1124. [TestCompiler(0)]
  1125. [TestCompiler(1)]
  1126. [TestCompiler(2)]
  1127. public static float test_expr_return_from_branch(int test)
  1128. {
  1129. float ret_val = -1.0F;
  1130. AssignValue(test, ref ret_val);
  1131. return ret_val;
  1132. }
  1133. [TestCompiler(DataRange.Standard, DataRange.Standard)]
  1134. public static bool BoolOrFunction(bool left, int x)
  1135. {
  1136. return left | ReturnBool(x);
  1137. }
  1138. private static bool ReturnBool(int x)
  1139. {
  1140. return x > 5;
  1141. }
  1142. [TestCompiler]
  1143. public static unsafe uint TestStackAlloc()
  1144. {
  1145. uint* result = stackalloc uint[4];
  1146. for (uint i = 0; i < 4; i++)
  1147. {
  1148. result[i] = i + 1;
  1149. }
  1150. uint sum = 0;
  1151. for (uint i = 0; i < 4; i++)
  1152. {
  1153. sum += result[i];
  1154. }
  1155. return sum;
  1156. }
  1157. public static int BoolRefUser(ref bool isDone)
  1158. {
  1159. return 1;
  1160. }
  1161. [TestCompiler]
  1162. public static int LocalBoolPassedByRef()
  1163. {
  1164. var isDone = false;
  1165. return BoolRefUser(ref isDone);
  1166. }
  1167. public enum TestEnum
  1168. {
  1169. v0 = 0,
  1170. v1 = 1,
  1171. v2 = 2,
  1172. v3 = 3,
  1173. v4 = 4,
  1174. v5 = 5,
  1175. v6 = 6,
  1176. }
  1177. public static float SameCode(TestEnum val1, TestEnum val2)
  1178. {
  1179. float diff = val2 - val1;
  1180. return diff;
  1181. }
  1182. [TestCompiler]
  1183. public static float EnumToFloatConversion()
  1184. {
  1185. return SameCode(TestEnum.v6, TestEnum.v0);
  1186. }
  1187. public enum SByteEnum : sbyte
  1188. {
  1189. A = 0, B = 6, C = -128
  1190. }
  1191. [TestCompiler(SByteEnum.C)]
  1192. public static float TestSByteEnum(SByteEnum a)
  1193. {
  1194. return (float) a;
  1195. }
  1196. public enum UnsignedEnum : uint
  1197. {
  1198. A = 0, B = 6, C = 0xFFFFFFFF
  1199. }
  1200. [TestCompiler(UnsignedEnum.C)]
  1201. public static float TestUnsignedEnum(UnsignedEnum a)
  1202. {
  1203. return (float) a;
  1204. }
  1205. [TestCompiler(1)]
  1206. public static int AddOvf(int x)
  1207. {
  1208. return checked(x + 1);
  1209. }
  1210. [TestCompiler(1)]
  1211. public static int MulOvf(int x)
  1212. {
  1213. return checked(x * 2);
  1214. }
  1215. [TestCompiler(1)]
  1216. public static int SubOvf(int x)
  1217. {
  1218. return checked(x - 1);
  1219. }
  1220. [TestCompiler(1u)]
  1221. public static uint SubOvfUn(uint x)
  1222. {
  1223. return checked(x - 1);
  1224. }
  1225. [TestCompiler(1u)]
  1226. public static uint BgeUn(uint x)
  1227. {
  1228. // We need a non-short opcode, therefore the branch has to be big enough for the offset to not fit in a byte:
  1229. return x >= 1 ? 1 : x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1230. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1231. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1232. x * x * x * x;
  1233. }
  1234. [TestCompiler(1)]
  1235. public static int Bgt(int x)
  1236. {
  1237. // We need a non-short opcode, therefore the branch has to be big enough for the offset to not fit in a byte:
  1238. return x > 1 ? 1 : x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1239. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1240. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1241. x * x * x * x;
  1242. }
  1243. [TestCompiler(1)]
  1244. public static int Beq(int x)
  1245. {
  1246. // We need a non-short opcode, therefore the branch has to be big enough for the offset to not fit in a byte:
  1247. return x == 1 ? 1 : x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1248. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1249. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1250. x * x * x * x;
  1251. }
  1252. [TestCompiler(1)]
  1253. public static int Bge(int x)
  1254. {
  1255. // We need a non-short opcode, therefore the branch has to be big enough for the offset to not fit in a byte:
  1256. return x >= 1 ? 1 : x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1257. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1258. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1259. x * x * x * x;
  1260. }
  1261. [TestCompiler(1)]
  1262. public static int Ble(int x)
  1263. {
  1264. // We need a non-short opcode, therefore the branch has to be big enough for the offset to not fit in a byte:
  1265. return x <= 1 ? 1 : x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1266. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1267. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1268. x * x * x * x;
  1269. }
  1270. [TestCompiler(1)]
  1271. public static int Blt(int x)
  1272. {
  1273. // We need a non-short opcode, therefore the branch has to be big enough for the offset to not fit in a byte:
  1274. return x < 1 ? 1 : x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1275. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1276. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1277. x * x * x * x;
  1278. }
  1279. [TestCompiler(1u)]
  1280. public static uint BgtUn(uint x)
  1281. {
  1282. // We need a non-short opcode, therefore the branch has to be big enough for the offset to not fit in a byte:
  1283. return x > 1 ? 1 : x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1284. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1285. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1286. x * x * x * x;
  1287. }
  1288. [TestCompiler(1u)]
  1289. public static uint BgtUnS(uint x)
  1290. {
  1291. return x > 1 ? 1 : x;
  1292. }
  1293. [TestCompiler(1u)]
  1294. public static uint BleUn(uint x)
  1295. {
  1296. // We need a non-short opcode, therefore the branch has to be big enough for the offset to not fit in a byte:
  1297. return x <= 1 ? 1 : x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1298. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1299. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1300. x * x * x * x;
  1301. }
  1302. [TestCompiler(1u)]
  1303. public static uint BltUn(uint x)
  1304. {
  1305. // We need a non-short opcode, therefore the branch has to be big enough for the offset to not fit in a byte:
  1306. return x < 1 ? 1 : x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1307. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1308. x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x *
  1309. x * x * x * x;
  1310. }
  1311. [TestCompiler(1u)]
  1312. public static uint BltUnS(uint x)
  1313. {
  1314. // We need a non-short opcode, therefore the branch has to be big enough for the offset to not fit in a byte:
  1315. return x < 1 ? 1 : 0u;
  1316. }
  1317. [TestCompiler(true)]
  1318. public static int Brtrue(bool x)
  1319. {
  1320. return x ? 1 : 0;
  1321. }
  1322. [TestCompiler(false)]
  1323. public static int Brfalse(bool x)
  1324. {
  1325. return !x ? 1 : 0;
  1326. }
  1327. [TestCompiler(1)]
  1328. public static sbyte ConvI1(int x)
  1329. {
  1330. return (sbyte) x;
  1331. }
  1332. [TestCompiler(1)]
  1333. public static short ConvI2(int x)
  1334. {
  1335. return (short) x;
  1336. }
  1337. [TestCompiler(1u)]
  1338. public static sbyte ConvOvfI1Un(uint x)
  1339. {
  1340. return checked((sbyte) x);
  1341. }
  1342. [TestCompiler(1u)]
  1343. public static short ConvOvfI2Un(uint x)
  1344. {
  1345. return checked((short) x);
  1346. }
  1347. [TestCompiler(1u)]
  1348. public static int ConvOvfI4Un(uint x)
  1349. {
  1350. return checked((int) x);
  1351. }
  1352. [TestCompiler(1ul)]
  1353. public static long ConvOvfI8Un(ulong x)
  1354. {
  1355. return checked((long) x);
  1356. }
  1357. [TestCompiler(1u)]
  1358. public static byte ConvOvfU1Un(uint x)
  1359. {
  1360. return checked((byte) x);
  1361. }
  1362. [TestCompiler(1u)]
  1363. public static ushort ConvOvfU2Un(uint x)
  1364. {
  1365. return checked((ushort) x);
  1366. }
  1367. [TestCompiler(1ul)]
  1368. public static uint ConvOvfU4Un(ulong x)
  1369. {
  1370. return checked((uint) x);
  1371. }
  1372. [TestCompiler(1)]
  1373. public static sbyte ConvOvfI1(int x)
  1374. {
  1375. return checked((sbyte) x);
  1376. }
  1377. [TestCompiler(1)]
  1378. public static short ConvOvfI2(int x)
  1379. {
  1380. return checked((short) x);
  1381. }
  1382. [TestCompiler(1)]
  1383. public static int ConvOvfI4(long x)
  1384. {
  1385. return checked((int) x);
  1386. }
  1387. [TestCompiler(1)]
  1388. public static long ConvOvfI8(double x)
  1389. {
  1390. return checked((long) x);
  1391. }
  1392. [TestCompiler(1)]
  1393. public static byte ConvOvfU1(int x)
  1394. {
  1395. return checked((byte) x);
  1396. }
  1397. [TestCompiler(1)]
  1398. public static ushort ConvOvfU2(int x)
  1399. {
  1400. return checked((ushort) x);
  1401. }
  1402. [TestCompiler(1)]
  1403. public static uint ConvOvfU4(int x)
  1404. {
  1405. return checked((uint) x);
  1406. }
  1407. [TestCompiler(1)]
  1408. public static ulong ConvOvfU8(double x)
  1409. {
  1410. return checked((ulong) x);
  1411. }
  1412. private static readonly int[] MyArray = { 0, 1, 2 };
  1413. [TestCompiler((byte)0)]
  1414. public static int LdelemByte(byte index) => MyArray[index];
  1415. [TestCompiler((ushort)0)]
  1416. public static int LdelemUInt16(ushort index) => MyArray[index];
  1417. [TestCompiler((uint)0)]
  1418. public static int LdelemUInt32(uint index) => MyArray[index];
  1419. [TestCompiler((ulong)0)]
  1420. public static int LdelemUInt64(ulong index) => MyArray[index];
  1421. [TestCompiler((short)0)]
  1422. public static int LdelemInt16(short index) => MyArray[index];
  1423. [TestCompiler(0)]
  1424. public static int LdelemInt32(int index) => MyArray[index];
  1425. [TestCompiler((long)0)]
  1426. public static int LdelemInt64(long index) => MyArray[index];
  1427. [TestCompiler(1.0f)]
  1428. public static float FSubByDenormBecomesFAdd(float x)
  1429. {
  1430. return x - 1.40129846432481707092e-45f;
  1431. }
  1432. [TestCompiler(1.0f)]
  1433. public static float FSubByDenormBecomesFAddWithVec(float x)
  1434. {
  1435. var r = x - new float2(1.40129846432481707092e-45f, -1.40129846432481707092e-45f);
  1436. return r.x * r.y;
  1437. }
  1438. private struct SomeStructWithCasts
  1439. {
  1440. public int I;
  1441. public static implicit operator int(SomeStructWithCasts s)
  1442. {
  1443. return s.I;
  1444. }
  1445. public static implicit operator int4x4(SomeStructWithCasts s)
  1446. {
  1447. return s.I;
  1448. }
  1449. public static explicit operator double(SomeStructWithCasts s)
  1450. {
  1451. return s.I;
  1452. }
  1453. public static explicit operator double4x4(SomeStructWithCasts s)
  1454. {
  1455. return s.I;
  1456. }
  1457. }
  1458. [TestCompiler(0)]
  1459. public static int ImplicitCastsWork(int i)
  1460. {
  1461. var something = new SomeStructWithCasts { I = i };
  1462. if (i < 0)
  1463. {
  1464. return something;
  1465. }
  1466. else
  1467. {
  1468. int4x4 s = something;
  1469. return s.c0.x;
  1470. }
  1471. }
  1472. [TestCompiler(0)]
  1473. public static double ExplicitCastsWork(int i)
  1474. {
  1475. var something = new SomeStructWithCasts { I = i };
  1476. if (i < 0)
  1477. {
  1478. return (double)something;
  1479. }
  1480. else
  1481. {
  1482. var s = (double4x4)something;
  1483. return s.c0.x;
  1484. }
  1485. }
  1486. }
  1487. }