Geen omschrijving
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.

Common.cs 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. namespace Unity.Burst.Intrinsics
  3. {
  4. /// <summary>
  5. /// Common intrinsics that are exposed across all Burst targets.
  6. /// </summary>
  7. public static class Common
  8. {
  9. /// <summary>
  10. /// Hint that the current thread should pause.
  11. ///
  12. /// In Burst compiled code this will map to platform specific
  13. /// ways to hint that the current thread should be paused as
  14. /// it is performing a calculation that would benefit from
  15. /// not contending with other threads. Atomic operations in
  16. /// tight loops (like spin-locks) can benefit from use of this
  17. /// intrinsic.
  18. ///
  19. /// - On x86 systems this maps to the `pause` instruction.
  20. /// - On ARM systems this maps to the `yield` instruction.
  21. ///
  22. /// Note that this is not an operating system level thread yield,
  23. /// it only provides a hint to the CPU that the current thread can
  24. /// afford to pause its execution temporarily.
  25. /// </summary>
  26. public static void Pause() { }
  27. #if UNITY_BURST_EXPERIMENTAL_PREFETCH_INTRINSIC
  28. public enum ReadWrite : int
  29. {
  30. Read = 0,
  31. Write = 1,
  32. }
  33. public enum Locality : int
  34. {
  35. NoTemporalLocality = 0,
  36. LowTemporalLocality = 1,
  37. ModerateTemporalLocality = 2,
  38. HighTemporalLocality = 3,
  39. }
  40. /// <summary>
  41. /// Prefetch a pointer.
  42. /// </summary>
  43. /// <param name="v">The pointer to prefetch.</param>
  44. /// <param name="rw">Whether the pointer will be used for reading or writing.</param>
  45. /// <param name="locality">The cache locality of the pointer.</param>
  46. public static unsafe void Prefetch(void* v, ReadWrite rw, Locality locality = Locality.HighTemporalLocality) { }
  47. #endif
  48. /// <summary>
  49. /// Return the low half of the multiplication of two numbers, and the high part as an out parameter.
  50. /// </summary>
  51. /// <param name="x">A value to multiply.</param>
  52. /// <param name="y">A value to multiply.</param>
  53. /// <param name="high">The high-half of the multiplication result.</param>
  54. /// <returns>The low-half of the multiplication result.</returns>
  55. public static ulong umul128(ulong x, ulong y, out ulong high)
  56. {
  57. // Split the inputs into high/low sections.
  58. ulong xLo = (uint)x;
  59. ulong xHi = x >> 32;
  60. ulong yLo = (uint)y;
  61. ulong yHi = y >> 32;
  62. // We have to use 4 multiples to compute the full range of the result.
  63. ulong hi = xHi * yHi;
  64. ulong m1 = xHi * yLo;
  65. ulong m2 = yHi * xLo;
  66. ulong lo = xLo * yLo;
  67. ulong m1Lo = (uint)m1;
  68. ulong loHi = lo >> 32;
  69. ulong m1Hi = m1 >> 32;
  70. high = hi + m1Hi + ((loHi + m1Lo + m2) >> 32);
  71. return x * y;
  72. }
  73. }
  74. [AttributeUsage(AttributeTargets.Method, Inherited = false)]
  75. // expose the type to btests via Unity.Burst.dll
  76. #if BURST_INTERNAL
  77. public
  78. #else
  79. internal
  80. #endif
  81. sealed class BurstTargetCpuAttribute : Attribute
  82. {
  83. public BurstTargetCpuAttribute(BurstTargetCpu TargetCpu)
  84. {
  85. this.TargetCpu = TargetCpu;
  86. }
  87. public readonly BurstTargetCpu TargetCpu;
  88. }
  89. }