Нема описа
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.

054-Peephole.cs 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using Burst.Compiler.IL.Tests.Helpers;
  2. using Unity.Burst.CompilerServices;
  3. using Unity.Mathematics;
  4. namespace Burst.Compiler.IL.Tests
  5. {
  6. internal class Peephole
  7. {
  8. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  9. public static int SqrtEqualFast(float f)
  10. {
  11. return math.sqrt(f) == 2 ? 42 : 13;
  12. }
  13. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  14. public static int SqrtNotEqualFast(float f)
  15. {
  16. return math.sqrt(f) != 2 ? 42 : 13;
  17. }
  18. [TestCompiler(DataRange.ZeroExclusiveTo100)]
  19. public static int SqrtLessThan(float f)
  20. {
  21. return math.sqrt(f) < 2 ? 42 : 13;
  22. }
  23. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  24. public static int SqrtLessThanFast(float f)
  25. {
  26. return math.sqrt(f) < 2 ? 42 : 13;
  27. }
  28. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  29. public static int SqrtLessThanLargeConstant(float f)
  30. {
  31. return math.sqrt(f) < float.MaxValue ? 42 : 13;
  32. }
  33. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  34. public static int SqrtLessThanFastVector(ref float4 f)
  35. {
  36. return math.all(math.sqrt(f) < 2) ? 42 : 13;
  37. }
  38. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  39. public static int SqrtLessThanLargeConstantVector(ref float4 f)
  40. {
  41. return math.all(math.sqrt(f) < new float4(1, 2, 3, float.MaxValue)) ? 42 : 13;
  42. }
  43. [TestCompiler(DataRange.ZeroExclusiveTo100)]
  44. public static int SqrtGreaterThan(float f)
  45. {
  46. return math.sqrt(f) > 2 ? 42 : 13;
  47. }
  48. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  49. public static int SqrtGreaterThanFast(float f)
  50. {
  51. return math.sqrt(f) > 2 ? 42 : 13;
  52. }
  53. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  54. public static int SqrtGreaterThanLargeConstant(float f)
  55. {
  56. return math.sqrt(f) > float.MaxValue ? 42 : 13;
  57. }
  58. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  59. public static int SqrtGreaterThanFastVector(ref float4 f)
  60. {
  61. return math.all(math.sqrt(f) > 2) ? 42 : 13;
  62. }
  63. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  64. public static int SqrtGreaterThanLargeConstantVector(ref float4 f)
  65. {
  66. return math.all(math.sqrt(f) > new float4(1, 2, 3, float.MaxValue)) ? 42 : 13;
  67. }
  68. [TestCompiler(DataRange.ZeroExclusiveTo100)]
  69. public static int SqrtLessThanEqual(float f)
  70. {
  71. return math.sqrt(f) <= 2 ? 42 : 13;
  72. }
  73. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  74. public static int SqrtLessThanEqualFast(float f)
  75. {
  76. return math.sqrt(f) <= 2 ? 42 : 13;
  77. }
  78. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  79. public static int SqrtLessThanEqualLargeConstant(float f)
  80. {
  81. return math.sqrt(f) <= float.MaxValue ? 42 : 13;
  82. }
  83. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  84. public static int SqrtLessThanEqualFastVector(ref float4 f)
  85. {
  86. return math.all(math.sqrt(f) <= 2) ? 42 : 13;
  87. }
  88. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  89. public static int SqrtLessThanEqualLargeConstantVector(ref float4 f)
  90. {
  91. return math.all(math.sqrt(f) <= new float4(1, 2, 3, float.MaxValue)) ? 42 : 13;
  92. }
  93. [TestCompiler(DataRange.ZeroExclusiveTo100)]
  94. public static int SqrtGreaterThanEqual(float f)
  95. {
  96. return math.sqrt(f) >= 2 ? 42 : 13;
  97. }
  98. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  99. public static int SqrtGreaterThanEqualFast(float f)
  100. {
  101. return math.sqrt(f) >= 2 ? 42 : 13;
  102. }
  103. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  104. public static int SqrtGreaterThanEqualLargeConstant(float f)
  105. {
  106. return math.sqrt(f) >= float.MaxValue ? 42 : 13;
  107. }
  108. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  109. public static int SqrtGreaterThanEqualFastVector(ref float4 f)
  110. {
  111. return math.all(math.sqrt(f) >= 2) ? 42 : 13;
  112. }
  113. [TestCompiler(DataRange.ZeroExclusiveTo100, FastMath = true)]
  114. public static int SqrtGreaterThanEqualLargeConstantVector(ref float4 f)
  115. {
  116. return math.all(math.sqrt(f) >= new float4(1, 2, 3, float.MaxValue)) ? 42 : 13;
  117. }
  118. [TestCompiler(DataRange.ZeroExclusiveTo100, DataRange.ZeroExclusiveTo100, FastMath = true)]
  119. public static int SqrtAndSqrtFast(ref float4 a, ref float4 b)
  120. {
  121. return math.all(math.sqrt(a) >= math.sqrt(b)) ? 42 : 13;
  122. }
  123. [TestCompiler(0)]
  124. public static float FloatExp2FromInt(int a)
  125. {
  126. return math.exp2(a);
  127. }
  128. [TestCompiler(0)]
  129. public static double DoubleExp2FromInt(int a)
  130. {
  131. return math.exp2((double)a);
  132. }
  133. [TestCompiler((ushort)0)]
  134. public static float FloatExp2FromUShort(ushort a)
  135. {
  136. return math.exp2(a);
  137. }
  138. [TestCompiler((ushort)0)]
  139. public static double DoubleExp2FromUShort(ushort a)
  140. {
  141. return math.exp2((double)a);
  142. }
  143. [TestCompiler(0)]
  144. public static float FloatPowFromInt(int a)
  145. {
  146. return math.pow(2.0f, a);
  147. }
  148. [TestCompiler(0)]
  149. public static double DoublePowFromInt(int a)
  150. {
  151. return math.pow(2.0, a);
  152. }
  153. [TestCompiler(0u)]
  154. public static float FloatPowFromUInt(uint a)
  155. {
  156. return math.pow(2.0f, a);
  157. }
  158. [TestCompiler(0u)]
  159. public static double DoublePowFromUInt(uint a)
  160. {
  161. return math.pow(2.0, a);
  162. }
  163. [TestCompiler(int.MaxValue)]
  164. public static int AShrToLShr([AssumeRange(0, int.MaxValue)] int a)
  165. {
  166. return a >> 4;
  167. }
  168. }
  169. }