Firstborn/Library/PackageCache/com.unity.burst@1.8.4/Tests/Runtime/Shared/084-Hint.cs

66 lines
1.5 KiB
C#
Raw Normal View History

2023-03-28 13:24:16 -04:00
using System;
using static Unity.Burst.CompilerServices.Hint;
namespace Burst.Compiler.IL.Tests
{
internal class Hint
{
[TestCompiler(42)]
public static unsafe double CheckLikely(int val)
{
if (Likely(val < 42))
{
return Math.Pow(Math.Tan(val), 42.42);
}
else
{
return Math.Cos(val);
}
}
[TestCompiler(42)]
public static unsafe double CheckUnlikely(int val)
{
if (Unlikely(val < 42))
{
return Math.Pow(Math.Tan(val), 42.42);
}
else
{
return Math.Cos(val);
}
}
[TestCompiler(42)]
public static unsafe double CheckAssume(int val)
{
Assume(val >= 42);
if (val < 42)
{
return Math.Pow(Math.Tan(val), 42.42);
}
else
{
return Math.Cos(val);
}
}
[TestCompiler(0)]
[TestCompiler(1)]
public static int CheckLikelyMatches(int val)
{
var cond = val == 0;
return cond == Likely(cond) ? 1 : 0;
}
[TestCompiler(0)]
[TestCompiler(1)]
public static int CheckUnlikelyMatches(int val)
{
var cond = val == 0;
return cond == Unlikely(cond) ? 1 : 0;
}
}
}