Ei kuvausta
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 42KB

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