internal InstantiateCommandBufferUntyped(Allocator allocator, FixedList64 <ComponentType> componentTypesWithData, int disposeSentinalStackDepth) { int dataPayloadSize = 0; FixedListInt64 typesSizes = new FixedListInt64(); FixedListInt64 typesWithData = new FixedListInt64(); for (int i = 0; i < componentTypesWithData.Length; i++) { var size = TypeManager.GetTypeInfo(componentTypesWithData[i].TypeIndex).ElementSize; dataPayloadSize += size; typesSizes.Add(size); typesWithData.Add(componentTypesWithData[i].TypeIndex); } CheckComponentTypesValid(BuildComponentTypesFromFixedList(typesWithData)); m_prefabSortkeyBlockList = (UnsafeParallelBlockList *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <UnsafeParallelBlockList>(), UnsafeUtility.AlignOf <UnsafeParallelBlockList>(), allocator); m_componentDataBlockList = (UnsafeParallelBlockList *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <UnsafeParallelBlockList>(), UnsafeUtility.AlignOf <UnsafeParallelBlockList>(), allocator); m_state = (State *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <State>(), UnsafeUtility.AlignOf <State>(), allocator); *m_prefabSortkeyBlockList = new UnsafeParallelBlockList(UnsafeUtility.SizeOf <PrefabSortkey>(), 256, allocator); *m_componentDataBlockList = new UnsafeParallelBlockList(dataPayloadSize, 256, allocator); *m_state = new State { typesWithData = typesWithData, tagsToAdd = default,
internal ParallelWriter(UnsafeParallelBlockList *blockList, void *state) { m_blockList = blockList; m_state = (State *)state; m_ThreadIndex = 0; m_Safety = default; }
private static void Deallocate(State *state, UnsafeParallelBlockList *blockList) { var allocator = state->allocator; blockList->Dispose(); UnsafeUtility.Free(blockList, allocator); UnsafeUtility.Free(state, allocator); }
private static void ResetInternal(State *state, ulong seed) { Zero(state, sizeof(State)); state->V1 = seed + Prime64Of1 + Prime64Of2; state->V2 = seed + Prime64Of2; state->V3 = seed + 0; state->V4 = seed - Prime64Of1; }
private static void UpdateInternal(State *state, void *input, int len) { byte *p = (byte *)input; byte *bEnd = p + len; state->TotalLen32 += (uint)len; state->LargeLen |= len >= 16 || state->TotalLen32 >= 16; if (state->MemSize + len < 16) { // fill in tmp buffer Copy((byte *)state->Mem32 + state->MemSize, input, len); state->MemSize += (uint)len; return; } if (state->MemSize > 0) { // some data left from previous update Copy((byte *)state->Mem32 + state->MemSize, input, (int)(16 - state->MemSize)); uint *p32 = state->Mem32; state->V1 = Round(state->V1, Read32(p32 + 0)); state->V2 = Round(state->V2, Read32(p32 + 1)); state->V3 = Round(state->V3, Read32(p32 + 2)); state->V4 = Round(state->V4, Read32(p32 + 3)); p += 16 - state->MemSize; state->MemSize = 0; } if (p <= bEnd - 16) { byte *limit = bEnd - 16; uint v1 = state->V1; uint v2 = state->V2; uint v3 = state->V3; uint v4 = state->V4; do { v1 = Round(v1, Read32(p + 0)); v2 = Round(v2, Read32(p + 4)); v3 = Round(v3, Read32(p + 8)); v4 = Round(v4, Read32(p + 12)); p += 16; }while (p <= limit); state->V1 = v1; state->V2 = v2; state->V3 = v3; state->V4 = v4; } if (p < bEnd) { Copy(state->Mem32, p, (int)(bEnd - p)); state->MemSize = (uint)(bEnd - p); } }
internal ParallelWriter(UnsafeParallelBlockList *blockList, void *state) { m_blockList = blockList; m_state = (State *)state; m_ThreadIndex = 0; #if ENABLE_UNITY_COLLECTIONS_CHECKS m_Safety = default; #endif }
private static void UpdateInternal(State *state, void *input, int len) { byte *p = (byte *)input; byte *bEnd = p + len; state->TotalLen += (ulong)len; if (state->MemSize + len < 32) { // fill in tmp buffer Copy((byte *)state->Mem64 + state->MemSize, input, len); state->MemSize += (uint)len; return; } if (state->MemSize > 0) { // tmp buffer is full Copy((byte *)state->Mem64 + state->MemSize, input, (int)(32 - state->MemSize)); state->V1 = Round(state->V1, Read64(state->Mem64 + 0)); state->V2 = Round(state->V2, Read64(state->Mem64 + 1)); state->V3 = Round(state->V3, Read64(state->Mem64 + 2)); state->V4 = Round(state->V4, Read64(state->Mem64 + 3)); p += 32 - state->MemSize; state->MemSize = 0; } if (p + 32 <= bEnd) { byte *limit = bEnd - 32; ulong v1 = state->V1; ulong v2 = state->V2; ulong v3 = state->V3; ulong v4 = state->V4; do { v1 = Round(v1, Read64(p + 0)); v2 = Round(v2, Read64(p + 8)); v3 = Round(v3, Read64(p + 16)); v4 = Round(v4, Read64(p + 24)); p += 32; }while (p <= limit); state->V1 = v1; state->V2 = v2; state->V3 = v3; state->V4 = v4; } if (p < bEnd) { Copy(state->Mem64, p, (int)(bEnd - p)); state->MemSize = (uint)(bEnd - p); } }
private static ulong DigestInternal(State *state) { byte *p = (byte *)state->Mem64; byte *bEnd = (byte *)state->Mem64 + state->MemSize; ulong h64; if (state->TotalLen >= 32) { ulong v1 = state->V1; ulong v2 = state->V2; ulong v3 = state->V3; ulong v4 = state->V4; h64 = Rotl64(v1, 1) + Rotl64(v2, 7) + Rotl64(v3, 12) + Rotl64(v4, 18); h64 = MergeRound(h64, v1); h64 = MergeRound(h64, v2); h64 = MergeRound(h64, v3); h64 = MergeRound(h64, v4); } else { h64 = state->V3 + Prime64Of5; } h64 += (ulong)state->TotalLen; while (p + 8 <= bEnd) { h64 ^= Round(0, Read64(p)); h64 = Rotl64(h64, 27) * Prime64Of1 + Prime64Of4; p += 8; } if (p + 4 <= bEnd) { h64 ^= Read32(p) * Prime64Of1; h64 = Rotl64(h64, 23) * Prime64Of2 + Prime64Of3; p += 4; } while (p < bEnd) { h64 ^= *p * Prime64Of5; h64 = Rotl64(h64, 11) * Prime64Of1; p++; } h64 ^= h64 >> 33; h64 *= Prime64Of2; h64 ^= h64 >> 29; h64 *= Prime64Of3; h64 ^= h64 >> 32; return(h64); }
public static unsafe int Answer(int numOfServers, int targetServer, int[,] connectionTimeMatrix) { int sz = numOfServers + 10; State *s = stackalloc State[sz]; int * ixs = stackalloc int[sz]; PQ.Init(s, ixs); bool *v = stackalloc bool[sz]; int * sp = stackalloc int[sz]; sp[0] = 0; for (int i = 1; i < numOfServers; i++) { sp[i] = 1 << 30; } PQ.Push(0, 0); int cn, p; while (PQ.edx != 1) { cn = PQ.Pop(out p); if (cn == targetServer) { return(p); } if (v[cn]) { continue; } v[cn] = true; for (int i = 1; i < numOfServers; i++) { if (v[i]) { continue; } int np = sp[cn] + connectionTimeMatrix[cn, i]; if (np < sp[i]) { if (PQ.Contains(i)) { PQ.Update(i, np); } else { PQ.Push(i, np); } sp[i] = np; } } } return(connectionTimeMatrix[0, targetServer]); }
private static uint DigestInternal(State *state) { byte *p = (byte *)state->Mem32; byte *bEnd = (byte *)state->Mem32 + state->MemSize; uint h32; if (state->LargeLen) { h32 = Rotl(state->V1, 1) + Rotl(state->V2, 7) + Rotl(state->V3, 12) + Rotl(state->V4, 18); } else { h32 = state->V3 + Prime32Of5; } h32 += state->TotalLen32; while (p + 4 <= bEnd) { h32 += Read32(p) * Prime32Of3; h32 = Rotl(h32, 17) * Prime32Of4; p += 4; } while (p < bEnd) { h32 += (*p) * Prime32Of5; h32 = Rotl(h32, 11) * Prime32Of1; p++; } h32 ^= h32 >> 15; h32 *= Prime32Of2; h32 ^= h32 >> 13; h32 *= Prime32Of3; h32 ^= h32 >> 16; return(h32); }
internal EntityOperationCommandBuffer(Allocator allocator, int disposeSentinalStackDepth) { m_blockList = (UnsafeParallelBlockList *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <UnsafeParallelBlockList>(), UnsafeUtility.AlignOf <UnsafeParallelBlockList>(), allocator); m_state = (State *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <State>(), UnsafeUtility.AlignOf <State>(), allocator); *m_blockList = new UnsafeParallelBlockList(UnsafeUtility.SizeOf <EntityWithOperation>(), 256, allocator); *m_state = new State { allocator = allocator, }; #if ENABLE_UNITY_COLLECTIONS_CHECKS DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, disposeSentinalStackDepth, allocator); if (s_staticSafetyId.Data == 0) { CreateStaticSafetyId(); } AtomicSafetyHandle.SetStaticSafetyId(ref m_Safety, s_staticSafetyId.Data); #endif }
private static extern void LearnAll(int totalNumInstances, int *instSizes, int **instIndices, float **instValues, float *labels, bool tuneLR, ref float lr, float l2Const, float piw, float *weightVector, ref float bias, int numFeatres, int numPasses, int numThreads, bool tuneNumLocIter, ref int numLocIter, float tolerance, bool needShuffle, bool shouldInitialize, State *state, ChannelCallBack info);
public EbuR128State(AudioFormat format, EbuR128Modes mode) { _state = ebur128_init((uint)format.Channels, (uint)format.SampleRate, mode); _format = format; }
private static extern Error ebur128_loudness_shortterm(State *state, out double loudness);
private static extern Error ebur128_loudness_momentary(State *state, out double loudness);
private static extern Error ebur128_loudness_global(State *state, out double loudness);
private static extern Error ebur128_add_frames_double(State *state, double *src, NativeInt frames);
private static extern Error ebur128_add_frames_float(State *state, float *src, NativeInt frames);
private static extern Error ebur128_add_frames_short(State *state, short *src, NativeInt frames);
private static extern void ebur128_destroy(ref State *state);
private static extern void MapBackWeightVector(float *weightVector, State *state);
public unsafe partial uint GetState(uint dwUserIndex, State *pState);
private static extern void DeallocateSequentially(State *state);
public static void Init(State *_s, int *_ixs) { s = _s; ixs = _ixs; edx = 1; }