using System; namespace Unity.Burst.Intrinsics { /// /// Common intrinsics that are exposed across all Burst targets. /// public static class Common { /// /// Hint that the current thread should pause. /// /// In Burst compiled code this will map to platform specific /// ways to hint that the current thread should be paused as /// it is performing a calculation that would benefit from /// not contending with other threads. Atomic operations in /// tight loops (like spin-locks) can benefit from use of this /// intrinsic. /// /// - On x86 systems this maps to the `pause` instruction. /// - On ARM systems this maps to the `yield` instruction. /// /// Note that this is not an operating system level thread yield, /// it only provides a hint to the CPU that the current thread can /// afford to pause its execution temporarily. /// public static void Pause() { } #if UNITY_BURST_EXPERIMENTAL_PREFETCH_INTRINSIC public enum ReadWrite : int { Read = 0, Write = 1, } public enum Locality : int { NoTemporalLocality = 0, LowTemporalLocality = 1, ModerateTemporalLocality = 2, HighTemporalLocality = 3, } /// /// Prefetch a pointer. /// /// The pointer to prefetch. /// Whether the pointer will be used for reading or writing. /// The cache locality of the pointer. public static unsafe void Prefetch(void* v, ReadWrite rw, Locality locality = Locality.HighTemporalLocality) { } #endif /// /// Return the low half of the multiplication of two numbers, and the high part as an out parameter. /// /// A value to multiply. /// A value to multiply. /// The high-half of the multiplication result. /// The low-half of the multiplication result. public static ulong umul128(ulong x, ulong y, out ulong high) { // Split the inputs into high/low sections. ulong xLo = (uint)x; ulong xHi = x >> 32; ulong yLo = (uint)y; ulong yHi = y >> 32; // We have to use 4 multiples to compute the full range of the result. ulong hi = xHi * yHi; ulong m1 = xHi * yLo; ulong m2 = yHi * xLo; ulong lo = xLo * yLo; ulong m1Lo = (uint)m1; ulong loHi = lo >> 32; ulong m1Hi = m1 >> 32; high = hi + m1Hi + ((loHi + m1Lo + m2) >> 32); return x * y; } } [AttributeUsage(AttributeTargets.Method, Inherited = false)] // expose the type to btests via Unity.Burst.dll #if BURST_INTERNAL public #else internal #endif sealed class BurstTargetCpuAttribute : Attribute { public BurstTargetCpuAttribute(BurstTargetCpu TargetCpu) { this.TargetCpu = TargetCpu; } public readonly BurstTargetCpu TargetCpu; } }