No Description
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.

084-Hint.cs 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using static Unity.Burst.CompilerServices.Hint;
  3. namespace Burst.Compiler.IL.Tests
  4. {
  5. internal class Hint
  6. {
  7. [TestCompiler(42)]
  8. public static unsafe double CheckLikely(int val)
  9. {
  10. if (Likely(val < 42))
  11. {
  12. return Math.Pow(Math.Tan(val), 42.42);
  13. }
  14. else
  15. {
  16. return Math.Cos(val);
  17. }
  18. }
  19. [TestCompiler(42)]
  20. public static unsafe double CheckUnlikely(int val)
  21. {
  22. if (Unlikely(val < 42))
  23. {
  24. return Math.Pow(Math.Tan(val), 42.42);
  25. }
  26. else
  27. {
  28. return Math.Cos(val);
  29. }
  30. }
  31. [TestCompiler(42)]
  32. public static unsafe double CheckAssume(int val)
  33. {
  34. Assume(val >= 42);
  35. if (val < 42)
  36. {
  37. return Math.Pow(Math.Tan(val), 42.42);
  38. }
  39. else
  40. {
  41. return Math.Cos(val);
  42. }
  43. }
  44. [TestCompiler(0)]
  45. [TestCompiler(1)]
  46. public static int CheckLikelyMatches(int val)
  47. {
  48. var cond = val == 0;
  49. return cond == Likely(cond) ? 1 : 0;
  50. }
  51. [TestCompiler(0)]
  52. [TestCompiler(1)]
  53. public static int CheckUnlikelyMatches(int val)
  54. {
  55. var cond = val == 0;
  56. return cond == Unlikely(cond) ? 1 : 0;
  57. }
  58. }
  59. }