Firstborn/Library/PackageCache/com.unity.burst@1.7.3/Tests/Runtime/Shared/052-TestFixed.cs
Schaken-Mods b486678290 Library -Artifacts
Library -Artifacts
2023-03-28 12:24:16 -05:00

93 lines
2.2 KiB
C#

using UnityBenchShared;
namespace Burst.Compiler.IL.Tests
{
internal class TestFixed
{
public unsafe struct SomeStruct
{
public static readonly int[] Ints = new int[4] { 1, 2, 3, 4 };
public struct OtherStruct
{
public int x;
}
public static readonly OtherStruct[] Structs = new OtherStruct[2] { new OtherStruct { x = 42 }, new OtherStruct { x = 13 } };
public fixed ushort array[42];
public struct Provider : IArgumentProvider
{
public object Value
{
get
{
var s = new SomeStruct();
for (ushort i = 0; i < 42; i++)
{
s.array[i] = i;
}
return s;
}
}
}
}
[TestCompiler]
public static unsafe int ReadInts()
{
fixed (int* ptr = SomeStruct.Ints)
{
return ptr[2];
}
}
[TestCompiler]
public static unsafe int ReadIntsElement()
{
fixed (int* ptr = &SomeStruct.Ints[1])
{
return ptr[0];
}
}
[TestCompiler]
public static unsafe int ReadStructs()
{
fixed (SomeStruct.OtherStruct* ptr = SomeStruct.Structs)
{
return ptr[1].x;
}
}
[TestCompiler]
public static unsafe int ReadStructsElement()
{
fixed (SomeStruct.OtherStruct* ptr = &SomeStruct.Structs[1])
{
return ptr[0].x;
}
}
[TestCompiler(typeof(SomeStruct.Provider))]
public static unsafe ushort ReadFromFixedArray(ref SomeStruct s)
{
fixed (ushort* ptr = s.array)
{
ushort total = 0;
for (ushort i = 0; i < 42; i++)
{
total += ptr[i];
}
return total;
}
}
}
}