Brak opisu
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.

052-TestFixed.cs 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using UnityBenchShared;
  2. namespace Burst.Compiler.IL.Tests
  3. {
  4. internal class TestFixed
  5. {
  6. public unsafe struct SomeStruct
  7. {
  8. public static readonly int[] Ints = new int[4] { 1, 2, 3, 4 };
  9. public struct OtherStruct
  10. {
  11. public int x;
  12. }
  13. public static readonly OtherStruct[] Structs = new OtherStruct[2] { new OtherStruct { x = 42 }, new OtherStruct { x = 13 } };
  14. public fixed ushort array[42];
  15. public struct Provider : IArgumentProvider
  16. {
  17. public object Value
  18. {
  19. get
  20. {
  21. var s = new SomeStruct();
  22. for (ushort i = 0; i < 42; i++)
  23. {
  24. s.array[i] = i;
  25. }
  26. return s;
  27. }
  28. }
  29. }
  30. }
  31. [TestCompiler]
  32. public static unsafe int ReadInts()
  33. {
  34. fixed (int* ptr = SomeStruct.Ints)
  35. {
  36. return ptr[2];
  37. }
  38. }
  39. [TestCompiler]
  40. public static unsafe int ReadIntsElement()
  41. {
  42. fixed (int* ptr = &SomeStruct.Ints[1])
  43. {
  44. return ptr[0];
  45. }
  46. }
  47. [TestCompiler]
  48. public static unsafe int ReadStructs()
  49. {
  50. fixed (SomeStruct.OtherStruct* ptr = SomeStruct.Structs)
  51. {
  52. return ptr[1].x;
  53. }
  54. }
  55. [TestCompiler]
  56. public static unsafe int ReadStructsElement()
  57. {
  58. fixed (SomeStruct.OtherStruct* ptr = &SomeStruct.Structs[1])
  59. {
  60. return ptr[0].x;
  61. }
  62. }
  63. [TestCompiler(typeof(SomeStruct.Provider))]
  64. public static unsafe ushort ReadFromFixedArray(ref SomeStruct s)
  65. {
  66. fixed (ushort* ptr = s.array)
  67. {
  68. ushort total = 0;
  69. for (ushort i = 0; i < 42; i++)
  70. {
  71. total += ptr[i];
  72. }
  73. return total;
  74. }
  75. }
  76. }
  77. }