Beispiel #1
0
 public void Initialize(IntPtr pointer, int totalWords, int activeWords)
 {
     if (totalWords <= 0) throw new InvalidOperationException("A segment cannot be empty");
     this.pointer = (ulong*)pointer;
     this.totalWords = totalWords;
     this.activeWords = activeWords;
 }
 protected override void Reset(bool recycling)
 {
     pointer = (ulong*)0;
     if (view != null)
     {
         view.SafeMemoryMappedViewHandle.ReleasePointer();
         try { view.Dispose(); }
         catch { }
         view = null;
     }
     if (mmFile != null)
     {
         mmFile.Dispose();
         mmFile = null;
     }
     base.Reset(recycling);
 }
Beispiel #3
0
 private static extern unsafe int proc_pidinfo(
     int pid,
     int flavor,
     ulong arg,
     ulong *buffer,
     int bufferSize);
        internal unsafe void CompressBlock(ulong *hPt, ulong *wPt)
        {
            for (int i = 16; i < w.Length; i++)
            {
                wPt[i] = SSIG1(wPt[i - 2]) + wPt[i - 7] + SSIG0(wPt[i - 15]) + wPt[i - 16];
            }

            ulong a = hPt[0];
            ulong b = hPt[1];
            ulong c = hPt[2];
            ulong d = hPt[3];
            ulong e = hPt[4];
            ulong f = hPt[5];
            ulong g = hPt[6];
            ulong h = hPt[7];

            ulong temp, aa, bb, cc, dd, ee, ff, hh, gg;

            fixed(ulong *kPt = &Ks[0])
            {
                for (int j = 0; j < 80;)
                {
                    temp = h + BSIG1(e) + CH(e, f, g) + kPt[j] + wPt[j];
                    ee   = d + temp;
                    aa   = temp + BSIG0(a) + MAJ(a, b, c);
                    j++;

                    temp = g + BSIG1(ee) + CH(ee, e, f) + kPt[j] + wPt[j];
                    ff   = c + temp;
                    bb   = temp + BSIG0(aa) + MAJ(aa, a, b);
                    j++;

                    temp = f + BSIG1(ff) + CH(ff, ee, e) + kPt[j] + wPt[j];
                    gg   = b + temp;
                    cc   = temp + BSIG0(bb) + MAJ(bb, aa, a);
                    j++;

                    temp = e + BSIG1(gg) + CH(gg, ff, ee) + kPt[j] + wPt[j];
                    hh   = a + temp;
                    dd   = temp + BSIG0(cc) + MAJ(cc, bb, aa);
                    j++;

                    temp = ee + BSIG1(hh) + CH(hh, gg, ff) + kPt[j] + wPt[j];
                    h    = aa + temp;
                    d    = temp + BSIG0(dd) + MAJ(dd, cc, bb);
                    j++;

                    temp = ff + BSIG1(h) + CH(h, hh, gg) + kPt[j] + wPt[j];
                    g    = bb + temp;
                    c    = temp + BSIG0(d) + MAJ(d, dd, cc);
                    j++;

                    temp = gg + BSIG1(g) + CH(g, h, hh) + kPt[j] + wPt[j];
                    f    = cc + temp;
                    b    = temp + BSIG0(c) + MAJ(c, d, dd);
                    j++;

                    temp = hh + BSIG1(f) + CH(f, g, h) + kPt[j] + wPt[j];
                    e    = dd + temp;
                    a    = temp + BSIG0(b) + MAJ(b, c, d);
                    j++;
                }
            }

            hPt[0] += a;
            hPt[1] += b;
            hPt[2] += c;
            hPt[3] += d;
            hPt[4] += e;
            hPt[5] += f;
            hPt[6] += g;
            hPt[7] += h;
        }
Beispiel #5
0
 public abstract unsafe void GetUniform([Flow(FlowDirection.In)] uint program, [Flow(FlowDirection.In)] int location, [Count(Computed = "program, location"), Flow(FlowDirection.Out)] ulong * @params);
Beispiel #6
0
        public unsafe void CopyTo(Interop.Ole32.IStream pstm, ulong cb, ulong *pcbRead, ulong *pcbWritten)
        {
            byte[] buffer = ArrayPool <byte> .Shared.Rent(4096);

            ulong remaining    = cb;
            ulong totalWritten = 0;
            ulong totalRead    = 0;

            fixed(byte *b = buffer)
            {
                while (remaining > 0)
                {
                    uint read = remaining < (ulong)buffer.Length ? (uint)remaining : (uint)buffer.Length;
                    Read(b, read, &read);
                    remaining -= read;
                    totalRead += read;

                    if (read == 0)
                    {
                        break;
                    }

                    uint written;
                    pstm.Write(b, read, &written);
                    totalWritten += written;
                }
            }

            ArrayPool <byte> .Shared.Return(buffer);

            if (pcbRead != null)
            {
                *pcbRead = totalRead;
            }

            if (pcbWritten != null)
            {
                *pcbWritten = totalWritten;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Resets stream for writing.
        /// Uses internal buffer for writing, it's available as DataPointer.
        /// </summary>
        public void ResetWrite()
        {
            if (m_ownedBuffer == null)
            {
                m_ownedBuffer = (ulong*)(void*)SharpDX.Utilities.AllocateClearedMemory(m_defaultByteSize);
                m_ownedBufferBitLength = m_defaultByteSize * 8;
            }
            else
            {
                SharpDX.Utilities.ClearMemory((IntPtr)(void*)m_ownedBuffer, 0, MyLibraryUtils.GetDivisionCeil(m_ownedBufferBitLength, 8));
            }

            m_buffer = m_ownedBuffer;
            m_bitLength = m_ownedBufferBitLength;
            m_bitPosition = 0;
            m_writing = true;
        }
        private void allocMemoryForCurrentSatate(byte[] currentState)
        {
            freeMemoryForCurrentSatate();

            _currentSatate = (ulong*) Marshal.AllocHGlobal(sizeof (ulong));

            *_currentSatate = 0;
            foreach (var t in currentState)
            {
                *_currentSatate <<= 8;
                *_currentSatate |= t;
            }

            //*_currentSatate = (ulong)(currentState[0] << 24 | currentState[1] << 16 | currentState[2] << 8 | currentState[3]);
            //*_currentSatate = (ulong) (currentState[0] << 40 | currentState[1] << 32 | currentState[2] << 24 | currentState[3] << 16 | currentState[4] << 8 | currentState[5]);

            _index0 = (byte*) _currentSatate;

            if (CoderSatateSize >= CoderSatateSize.Size2)
                _index1 = _index0 + 1;

            if (CoderSatateSize >= CoderSatateSize.Size3)
                _index2 = _index0 + 2;

            if (CoderSatateSize >= CoderSatateSize.Size4)
                _index3 = _index0 + 3;

            if (CoderSatateSize >= CoderSatateSize.Size5)
                _index4 = _index0 + 4;

            if (CoderSatateSize >= CoderSatateSize.Size6)
                _index5 = _index0 + 5;

            if (CoderSatateSize >= CoderSatateSize.Size7)
                _index6 = _index0 + 6;

            if (CoderSatateSize >= CoderSatateSize.Size8)
                _index7 = _index0 + 7;
        }
Beispiel #9
0
        private static void mixAvx2(ulong *sh, ulong *m)
        {
            // Rotate shuffle masks. We can safely convert the ref to a pointer because the compiler guarantees the
            // data is in a fixed location, and the ref itself is converted from a pointer. Same for the IV below.
            byte *prm = (byte *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(rormask));
            var   r24 = Avx2.BroadcastVector128ToVector256(prm);
            var   r16 = Avx2.BroadcastVector128ToVector256(prm + Vector128 <byte> .Count);

            var row1 = Avx.LoadVector256(sh);
            var row2 = Avx.LoadVector256(sh + Vector256 <ulong> .Count);

            ulong *piv  = (ulong *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(ivle));
            var    row3 = Avx.LoadVector256(piv);
            var    row4 = Avx.LoadVector256(piv + Vector256 <ulong> .Count);

            row4 = Avx2.Xor(row4, Avx.LoadVector256(sh + Vector256 <ulong> .Count * 2));           // t[] and f[]

            //ROUND 1
            var m0 = Avx2.BroadcastVector128ToVector256(m);
            var m1 = Avx2.BroadcastVector128ToVector256(m + Vector128 <ulong> .Count);
            var m2 = Avx2.BroadcastVector128ToVector256(m + Vector128 <ulong> .Count * 2);
            var m3 = Avx2.BroadcastVector128ToVector256(m + Vector128 <ulong> .Count * 3);

            var t0 = Avx2.UnpackLow(m0, m1);
            var t1 = Avx2.UnpackLow(m2, m3);
            var b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackHigh(m0, m1);
            t1 = Avx2.UnpackHigh(m2, m3);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //DIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_10_01_00_11);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_00_11_10_01);

            var m4 = Avx2.BroadcastVector128ToVector256(m + Vector128 <ulong> .Count * 4);
            var m5 = Avx2.BroadcastVector128ToVector256(m + Vector128 <ulong> .Count * 5);
            var m6 = Avx2.BroadcastVector128ToVector256(m + Vector128 <ulong> .Count * 6);
            var m7 = Avx2.BroadcastVector128ToVector256(m + Vector128 <ulong> .Count * 7);

            t0 = Avx2.UnpackLow(m4, m5);
            t1 = Avx2.UnpackLow(m6, m7);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackHigh(m4, m5);
            t1 = Avx2.UnpackHigh(m6, m7);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //UNDIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_00_11_10_01);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_10_01_00_11);

            //ROUND 2
            t0 = Avx2.UnpackLow(m7, m2);
            t1 = Avx2.UnpackHigh(m4, m6);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackLow(m5, m4);
            t1 = Avx2.AlignRight(m3, m7, 8);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //DIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_10_01_00_11);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_00_11_10_01);

            t0 = Avx2.Shuffle(m0.AsUInt32(), 0b_01_00_11_10).AsUInt64();
            t1 = Avx2.UnpackHigh(m5, m2);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackLow(m6, m1);
            t1 = Avx2.UnpackHigh(m3, m1);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //UNDIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_00_11_10_01);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_10_01_00_11);

            //ROUND 3
            t0 = Avx2.AlignRight(m6, m5, 8);
            t1 = Avx2.UnpackHigh(m2, m7);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackLow(m4, m0);
            t1 = Avx2.Blend(m1.AsUInt32(), m6.AsUInt32(), 0b_1100_1100).AsUInt64();
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //DIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_10_01_00_11);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_00_11_10_01);

            t0 = Avx2.Blend(m5.AsUInt32(), m1.AsUInt32(), 0b_1100_1100).AsUInt64();
            t1 = Avx2.UnpackHigh(m3, m4);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackLow(m7, m3);
            t1 = Avx2.AlignRight(m2, m0, 8);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //UNDIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_00_11_10_01);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_10_01_00_11);

            //ROUND 4
            t0 = Avx2.UnpackHigh(m3, m1);
            t1 = Avx2.UnpackHigh(m6, m5);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackHigh(m4, m0);
            t1 = Avx2.UnpackLow(m6, m7);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //DIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_10_01_00_11);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_00_11_10_01);

            t0 = Avx2.Blend(m1.AsUInt32(), m2.AsUInt32(), 0b_1100_1100).AsUInt64();
            t1 = Avx2.Blend(m2.AsUInt32(), m7.AsUInt32(), 0b_1100_1100).AsUInt64();
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackLow(m3, m5);
            t1 = Avx2.UnpackLow(m0, m4);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //UNDIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_00_11_10_01);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_10_01_00_11);

            //ROUND 5
            t0 = Avx2.UnpackHigh(m4, m2);
            t1 = Avx2.UnpackLow(m1, m5);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.Blend(m0.AsUInt32(), m3.AsUInt32(), 0b_1100_1100).AsUInt64();
            t1 = Avx2.Blend(m2.AsUInt32(), m7.AsUInt32(), 0b_1100_1100).AsUInt64();
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //DIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_10_01_00_11);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_00_11_10_01);

            t0 = Avx2.Blend(m7.AsUInt32(), m5.AsUInt32(), 0b_1100_1100).AsUInt64();
            t1 = Avx2.Blend(m3.AsUInt32(), m1.AsUInt32(), 0b_1100_1100).AsUInt64();
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.AlignRight(m6, m0, 8);
            t1 = Avx2.Blend(m4.AsUInt32(), m6.AsUInt32(), 0b_1100_1100).AsUInt64();
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //UNDIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_00_11_10_01);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_10_01_00_11);

            //ROUND 6
            t0 = Avx2.UnpackLow(m1, m3);
            t1 = Avx2.UnpackLow(m0, m4);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackLow(m6, m5);
            t1 = Avx2.UnpackHigh(m5, m1);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //DIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_10_01_00_11);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_00_11_10_01);

            t0 = Avx2.Blend(m2.AsUInt32(), m3.AsUInt32(), 0b_1100_1100).AsUInt64();
            t1 = Avx2.UnpackHigh(m7, m0);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackHigh(m6, m2);
            t1 = Avx2.Blend(m7.AsUInt32(), m4.AsUInt32(), 0b_1100_1100).AsUInt64();
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //UNDIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_00_11_10_01);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_10_01_00_11);

            //ROUND 7
            t0 = Avx2.Blend(m6.AsUInt32(), m0.AsUInt32(), 0b_1100_1100).AsUInt64();
            t1 = Avx2.UnpackLow(m7, m2);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackHigh(m2, m7);
            t1 = Avx2.AlignRight(m5, m6, 8);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //DIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_10_01_00_11);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_00_11_10_01);

            t0 = Avx2.UnpackLow(m0, m3);
            t1 = Avx2.Shuffle(m4.AsUInt32(), 0b_01_00_11_10).AsUInt64();
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackHigh(m3, m1);
            t1 = Avx2.Blend(m1.AsUInt32(), m5.AsUInt32(), 0b_1100_1100).AsUInt64();
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //UNDIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_00_11_10_01);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_10_01_00_11);

            //ROUND 8
            t0 = Avx2.UnpackHigh(m6, m3);
            t1 = Avx2.Blend(m6.AsUInt32(), m1.AsUInt32(), 0b_1100_1100).AsUInt64();
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.AlignRight(m7, m5, 8);
            t1 = Avx2.UnpackHigh(m0, m4);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //DIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_10_01_00_11);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_00_11_10_01);

            t0 = Avx2.UnpackHigh(m2, m7);
            t1 = Avx2.UnpackLow(m4, m1);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackLow(m0, m2);
            t1 = Avx2.UnpackLow(m3, m5);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //UNDIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_00_11_10_01);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_10_01_00_11);

            //ROUND 9
            t0 = Avx2.UnpackLow(m3, m7);
            t1 = Avx2.AlignRight(m0, m5, 8);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackHigh(m7, m4);
            t1 = Avx2.AlignRight(m4, m1, 8);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //DIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_10_01_00_11);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_00_11_10_01);

            t0 = m6;
            t1 = Avx2.AlignRight(m5, m0, 8);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.Blend(m1.AsUInt32(), m3.AsUInt32(), 0b_1100_1100).AsUInt64();
            t1 = m2;
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //UNDIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_00_11_10_01);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_10_01_00_11);

            //ROUND 10
            t0 = Avx2.UnpackLow(m5, m4);
            t1 = Avx2.UnpackHigh(m3, m0);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackLow(m1, m2);
            t1 = Avx2.Blend(m3.AsUInt32(), m2.AsUInt32(), 0b_1100_1100).AsUInt64();
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //DIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_10_01_00_11);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_00_11_10_01);

            t0 = Avx2.UnpackHigh(m7, m4);
            t1 = Avx2.UnpackHigh(m1, m6);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.AlignRight(m7, m5, 8);
            t1 = Avx2.UnpackLow(m6, m0);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //UNDIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_00_11_10_01);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_10_01_00_11);

            //ROUND 11
            t0 = Avx2.UnpackLow(m0, m1);
            t1 = Avx2.UnpackLow(m2, m3);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackHigh(m0, m1);
            t1 = Avx2.UnpackHigh(m2, m3);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //DIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_10_01_00_11);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_00_11_10_01);

            t0 = Avx2.UnpackLow(m4, m5);
            t1 = Avx2.UnpackLow(m6, m7);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackHigh(m4, m5);
            t1 = Avx2.UnpackHigh(m6, m7);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //UNDIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_00_11_10_01);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_10_01_00_11);

            //ROUND 12
            t0 = Avx2.UnpackLow(m7, m2);
            t1 = Avx2.UnpackHigh(m4, m6);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackLow(m5, m4);
            t1 = Avx2.AlignRight(m3, m7, 8);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //DIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_10_01_00_11);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_00_11_10_01);

            t0 = Avx2.Shuffle(m0.AsUInt32(), 0b_01_00_11_10).AsUInt64();
            t1 = Avx2.UnpackHigh(m5, m2);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G1
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsUInt32(), 0b_10_11_00_01).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Shuffle(row2.AsByte(), r24).AsUInt64();

            t0 = Avx2.UnpackLow(m6, m1);
            t1 = Avx2.UnpackHigh(m3, m1);
            b0 = Avx2.Blend(t0.AsUInt32(), t1.AsUInt32(), 0b_1111_0000).AsUInt64();

            //G2
            row1 = Avx2.Add(Avx2.Add(row1, b0), row2);
            row4 = Avx2.Xor(row4, row1);
            row4 = Avx2.Shuffle(row4.AsByte(), r16).AsUInt64();

            row3 = Avx2.Add(row3, row4);
            row2 = Avx2.Xor(row2, row3);
            row2 = Avx2.Xor(Avx2.ShiftRightLogical(row2, 63), Avx2.Add(row2, row2));

            //UNDIAGONALIZE
            row4 = Avx2.Permute4x64(row4, 0b_00_11_10_01);
            row3 = Avx2.Permute4x64(row3, 0b_01_00_11_10);
            row2 = Avx2.Permute4x64(row2, 0b_10_01_00_11);

            row1 = Avx2.Xor(row1, row3);
            row2 = Avx2.Xor(row2, row4);
            row1 = Avx2.Xor(row1, Avx.LoadVector256(sh));
            row2 = Avx2.Xor(row2, Avx.LoadVector256(sh + Vector256 <ulong> .Count));

            Avx.Store(sh, row1);
            Avx.Store(sh + Vector256 <ulong> .Count, row2);
        }
 public int SetEventOnMultipleFenceCompletion([NativeTypeName("ID3D12Fence *const *")] ID3D12Fence **ppFences, [NativeTypeName("const UINT64 *")] ulong *pFenceValues, [NativeTypeName("UINT")] uint NumFences, D3D12_MULTIPLE_FENCE_WAIT_FLAGS Flags, [NativeTypeName("HANDLE")] IntPtr hEvent)
 {
     return(((delegate * stdcall <ID3D12Device5 *, ID3D12Fence **, ulong *, uint, D3D12_MULTIPLE_FENCE_WAIT_FLAGS, IntPtr, int>)(lpVtbl[45]))((ID3D12Device5 *)Unsafe.AsPointer(ref this), ppFences, pFenceValues, NumFences, Flags, hEvent));
 }
 public void GetCopyableFootprints([NativeTypeName("const D3D12_RESOURCE_DESC *")] D3D12_RESOURCE_DESC *pResourceDesc, [NativeTypeName("UINT")] uint FirstSubresource, [NativeTypeName("UINT")] uint NumSubresources, [NativeTypeName("UINT64")] ulong BaseOffset, [NativeTypeName("D3D12_PLACED_SUBRESOURCE_FOOTPRINT *")] D3D12_PLACED_SUBRESOURCE_FOOTPRINT *pLayouts, [NativeTypeName("UINT *")] uint *pNumRows, [NativeTypeName("UINT64 *")] ulong *pRowSizeInBytes, [NativeTypeName("UINT64 *")] ulong *pTotalBytes)
 {
     ((delegate * stdcall <ID3D12Device5 *, D3D12_RESOURCE_DESC *, uint, uint, ulong, D3D12_PLACED_SUBRESOURCE_FOOTPRINT *, uint *, ulong *, ulong *, void>)(lpVtbl[38]))((ID3D12Device5 *)Unsafe.AsPointer(ref this), pResourceDesc, FirstSubresource, NumSubresources, BaseOffset, pLayouts, pNumRows, pRowSizeInBytes, pTotalBytes);
 }
        public int Allocate([NativeTypeName("const VIRTUAL_ALLOCATION_DESC*")] D3D12MA_VIRTUAL_ALLOCATION_DESC *pDesc, [NativeTypeName("UINT64 *")] ulong *pOffset)
        {
            if ((pDesc == null) || (pOffset == null) || (pDesc->Size == 0) || !IsPow2(pDesc->Alignment))
            {
                D3D12MA_ASSERT(false); // "Invalid arguments passed to VirtualBlock::Allocate."
                return(E_INVALIDARG);
            }

            *pOffset = UINT64_MAX;

            using var debugGlobalMutexLock = D3D12MA_DEBUG_GLOBAL_MUTEX_LOCK();

            ulong alignment = pDesc->Alignment != 0 ? pDesc->Alignment : 1;
            D3D12MA_AllocationRequest allocRequest = default;

            if (m_Metadata.CreateAllocationRequest(pDesc->Size, alignment, &allocRequest))
            {
                m_Metadata.Alloc(&allocRequest, pDesc->Size, pDesc->pUserData);
                D3D12MA_HEAVY_ASSERT((D3D12MA_DEBUG_LEVEL > 1) && m_Metadata.Validate());
                *pOffset = allocRequest.offset;
                return(S_OK);
            }
            else
            {
                return(E_OUTOFMEMORY);
            }
        }
Beispiel #13
0
 public override void Reset(bool recycling)
 {
     pointer = (ulong*)0;
     activeWords = totalWords = 0;
     base.Reset(recycling);
 }
Beispiel #14
0
        public static void Initialize()
        {
            Module m = typeof(AntiTamperNormal).Module;
            string n = m.FullyQualifiedName;
            bool   f = n.Length > 0 && n[0] == '<';
            var    b = (byte *)Marshal.GetHINSTANCE(m);
            byte * p = b + *(uint *)(b + 0x3c);
            ushort s = *(ushort *)(p + 0x6);
            ushort o = *(ushort *)(p + 0x14);

            uint *e = null;
            uint  l = 0;
            var   r = (uint *)(p + 0x18 + o);
            uint  z = (uint)Mutation.KeyI1, x = (uint)Mutation.KeyI2, c = (uint)Mutation.KeyI3, v = (uint)Mutation.KeyI4;

            for (int i = 0; i < s; i++)
            {
                uint g = (*r++) * (*r++);
                if (g == (uint)Mutation.KeyI0)
                {
                    e = (uint *)(b + (f ? *(r + 3) : *(r + 1)));
                    l = (f ? *(r + 2) : *(r + 0)) >> 2;
                }
                else if (g != 0)
                {
                    var  q = (uint *)(b + (f ? *(r + 3) : *(r + 1)));
                    uint j = *(r + 2) >> 2;
                    for (uint k = 0; k < j; k++)
                    {
                        uint t = (z ^ (*q++)) + x + c * v;
                        z = x;
                        x = c;
                        x = v;
                        v = t;
                    }
                }
                r += 8;
            }

            uint[] y = new uint[0x10], d = new uint[0x10];
            for (int i = 0; i < 0x10; i++)
            {
                y[i] = v;
                d[i] = x;
                z    = (x >> 5) | (x << 27);
                x    = (c >> 3) | (c << 29);
                c    = (v >> 7) | (v << 25);
                v    = (z >> 11) | (z << 21);
            }
            Mutation.Crypt(y, d);

            uint  h = 0;
            uint *u = e;

            VirtualProtect((IntPtr)e, l << 2, 0x40, out z);
            for (uint i = 0; i < l; i++)
            {
                *e ^= y[h & 0xf];
                y[h & 0xf] = (y[h & 0xf] ^ (*e++)) + 0x3dbb2819;
                h++;
            }

            ptr = u + 4;
            len = *ptr++;

            ver4 = Environment.Version.Major == 4;
            ModuleHandle hnd = m.ModuleHandle;

            if (ver4)
            {
                ulong *str = stackalloc ulong[1];
                str[0]    = 0x0061746144705f6d; //m_pData.
                moduleHnd = (IntPtr)m.GetType().GetField(new string((sbyte *)str), BindingFlags.NonPublic | BindingFlags.Instance).GetValue(m);
                ver5      = Environment.Version.Revision > 17020;
            }
            else
            {
                //moduleHnd = *(IntPtr*)(&hnd);
                Marshal.PtrToStructure(moduleHnd, hnd);
            }
            Hook();
        }
Beispiel #15
0
        internal static void MoveNotNull(/*Type[0]*/ ulong /*Type[0]*/[] array, int index, int writeIndex, int count)
        {
#if MONO
            int endIndex = index + count;
            if (index < writeIndex && endIndex > writeIndex)
            {
                fixed(/*Type[0]*/ ulong /*Type[0]*/ *valueFixed = array)
                {
                    for (/*Type[0]*/ ulong /*Type[0]*/ *write = valueFixed + writeIndex + count, start = valueFixed + index, end = valueFixed + endIndex;
                         end != start;
                         *--write = *--end)
                    {
                        ;
                    }
                }
            }
            else
            {
                Array.Copy(array, index, array, writeIndex, count);
            }
#else
            fixed(/*Type[0]*/ ulong /*Type[0]*/ *valueFixed = array) AutoCSer.Win32.Kernel32.RtlMoveMemory(valueFixed + writeIndex, valueFixed + index, count * sizeof(/*Type[0]*/ ulong /*Type[0]*/));
#endif
        }
 public int EndDraw([NativeTypeName("D2D1_TAG *")] ulong *tag1 = null, [NativeTypeName("D2D1_TAG *")] ulong *tag2 = null)
 {
     return(((delegate * stdcall <ID2D1DCRenderTarget *, ulong *, ulong *, int>)(lpVtbl[49]))((ID2D1DCRenderTarget *)Unsafe.AsPointer(ref this), tag1, tag2));
 }
Beispiel #17
0
        /// <summary>
        /// 逆转数组
        /// </summary>
        /// <param name="array">数组数据</param>
        /// <param name="index">起始位置</param>
        /// <param name="length">翻转数据数量</param>
        /// <returns>翻转后的新数组</returns>
        internal static /*Type[0]*/ ulong /*Type[0]*/[] GetReverse(/*Type[0]*/ ulong /*Type[0]*/[] array, int index, int length)
        {
            /*Type[0]*/
            ulong /*Type[0]*/[] newValues = new /*Type[0]*/ ulong /*Type[0]*/[length];
            fixed(/*Type[0]*/ ulong /*Type[0]*/ *valueFixed = array, newValueFixed = newValues)
            {
                for (/*Type[0]*/ ulong /*Type[0]*/ *start = valueFixed + index, end = start + length, wirte = newValueFixed + length; start != end; *--wirte = *start++)
                {
                    ;
                }
            }

            return(newValues);
        }
Beispiel #18
0
 /// <summary>
 /// Resets stream for reading (reads what was written so far).
 /// </summary>
 public void ResetRead()
 {
     m_bitLength = m_bitPosition;
     m_buffer = m_ownedBuffer;
     m_writing = false;
     m_bitPosition = 0;
 }
 public int AddPage([NativeTypeName("ID2D1CommandList *")] ID2D1CommandList *commandList, D2D_SIZE_F pageSize, [NativeTypeName("IStream *")] IStream *pagePrintTicketStream, [NativeTypeName("D2D1_TAG *")] ulong *tag1 = null, [NativeTypeName("D2D1_TAG *")] ulong *tag2 = null)
 {
     return(((delegate * stdcall <ID2D1PrintControl *, ID2D1CommandList *, D2D_SIZE_F, IStream *, ulong *, ulong *, int>)(lpVtbl[3]))((ID2D1PrintControl *)Unsafe.AsPointer(ref this), commandList, pageSize, pagePrintTicketStream, tag1, tag2));
 }
Beispiel #20
0
        void Resize(int bitSize)
        {
            if (!OwnsBuffer)
                throw new BitStreamException("BitStream cannot write more data. Buffer is full and it's not owned by BitStream", new System.IO.EndOfStreamException());

            // Always at least double the size
            int newBitSize = Math.Max(m_bitLength * 2, bitSize);
            int newByteLen = MyLibraryUtils.GetDivisionCeil(newBitSize, 64) * 8;

            var newBuffer = SharpDX.Utilities.AllocateClearedMemory(newByteLen);
            SharpDX.Utilities.CopyMemory(newBuffer, (IntPtr)(void*)m_buffer, BytePosition);
            SharpDX.Utilities.FreeMemory((IntPtr)(void*)m_buffer);

            m_buffer = (ulong*)(void*)newBuffer;
            m_bitLength = newBitSize;

            m_ownedBuffer = m_buffer;
            m_ownedBufferBitLength = m_bitLength;
        }
Beispiel #21
0
 public HRESULT get_domainLookupStart([NativeTypeName("ULONGLONG *")] ulong *p)
 {
     return(((delegate * unmanaged <IHTMLPerformanceTiming *, ulong *, int>)(lpVtbl[13]))((IHTMLPerformanceTiming *)Unsafe.AsPointer(ref this), p));
 }
Beispiel #22
0
 protected void FreePointer()
 {
     if (pointer != (ulong*)0) Marshal.FreeHGlobal(new IntPtr(pointer));
     pointer = (ulong*)0;
 }
Beispiel #23
0
 public HRESULT get_unloadEventEnd([NativeTypeName("ULONGLONG *")] ulong *p)
 {
     return(((delegate * unmanaged <IHTMLPerformanceTiming *, ulong *, int>)(lpVtbl[9]))((IHTMLPerformanceTiming *)Unsafe.AsPointer(ref this), p));
 }
Beispiel #24
0
 private static unsafe partial int proc_pidinfo(
     int pid,
     int flavor,
     ulong arg,
     ulong *buffer,
     int bufferSize);
Beispiel #25
0
        public override unsafe void RenderGlyphs(RenderingTextureAllocator textureAllocator, List <RenderingFont.GlyphRenderInfo> glyphRenderInfos, List <RectangleInt2> overlays)
        {
            Vector2 posScaling     = new Vector2(1.0f) / (Size / 2); // Divide the integer coordinates to avoid pixel mishmash.
            Vector2 posOffset      = VectorInt2.FromRounded(posScaling * 0.5f);
            Vector2 textureScaling = new Vector2(16777216.0f) / new Vector2(textureAllocator.Size.X, textureAllocator.Size.Y);

            // Build vertex buffer
            int vertexCount = glyphRenderInfos.Count * 6 + overlays.Count * 6;
            int bufferSize  = vertexCount * (sizeof(Vector2) + sizeof(ulong));

            fixed(byte *data = new byte[bufferSize])
            {
                Vector2 *positions = (Vector2 *)(data);
                ulong *  uvws      = (ulong *)(data + vertexCount * sizeof(Vector2));

                // Setup vertices
                int c = 0;

                for (int i = 0; i < overlays.Count; ++i, ++c)
                {
                    var     overlay  = overlays[i];
                    Vector2 posStart = overlay.Start * posScaling + posOffset;
                    Vector2 posEnd   = (overlay.End - new Vector2(1)) * posScaling + posOffset;

                    positions[c * 6 + 0] = new Vector2(posStart.X, posStart.Y);
                    positions[c * 6 + 2] = positions[c * 6 + 3] = new Vector2(posEnd.X, posStart.Y);
                    positions[c * 6 + 1] = positions[c * 6 + 4] = new Vector2(posStart.X, posEnd.Y);
                    positions[c * 6 + 5] = new Vector2(posEnd.X, posEnd.Y);

                    uvws[c * 6 + 2]         = uvws[c * 6 + 3] =
                        uvws[c * 6 + 1]     = uvws[c * 6 + 4] =
                            uvws[c * 6 + 5] = uvws[c * 6 + 0] = Dx11RenderingDevice.CompressUvw(VectorInt3.Zero, Vector2.Zero, Vector2.Zero, 1);
                }

                for (int i = 0; i < glyphRenderInfos.Count; ++i, ++c)
                {
                    RenderingFont.GlyphRenderInfo info = glyphRenderInfos[i];
                    Vector2 posStart = info.PosStart * posScaling + posOffset;
                    Vector2 posEnd   = (info.PosEnd - new Vector2(1)) * posScaling + posOffset;

                    positions[c * 6 + 0] = new Vector2(posStart.X, posStart.Y);
                    positions[c * 6 + 2] = positions[c * 6 + 3] = new Vector2(posEnd.X, posStart.Y);
                    positions[c * 6 + 1] = positions[c * 6 + 4] = new Vector2(posStart.X, posEnd.Y);
                    positions[c * 6 + 5] = new Vector2(posEnd.X, posEnd.Y);

                    uvws[c * 6 + 0] = Dx11RenderingDevice.CompressUvw(info.TexStart, textureScaling, new Vector2(0.5f, 0.5f));
                    uvws[c * 6 + 2] = uvws[c * 6 + 3] = Dx11RenderingDevice.CompressUvw(info.TexStart, textureScaling, new Vector2(info.TexSize.X - 0.5f, 0.5f));
                    uvws[c * 6 + 1] = uvws[c * 6 + 4] = Dx11RenderingDevice.CompressUvw(info.TexStart, textureScaling, new Vector2(0.5f, info.TexSize.Y - 0.5f));
                    uvws[c * 6 + 5] = Dx11RenderingDevice.CompressUvw(info.TexStart, textureScaling, new Vector2(info.TexSize.X - 0.5f, info.TexSize.Y - 0.5f));
                }

                // Create GPU resources
                using (var VertexBuffer = new Buffer(Device.Device, new IntPtr(data),
                                                     new BufferDescription(bufferSize, ResourceUsage.Immutable, BindFlags.VertexBuffer,
                                                                           CpuAccessFlags.None, ResourceOptionFlags.None, 0)))
                {
                    var VertexBufferBindings = new VertexBufferBinding[] {
                        new VertexBufferBinding(VertexBuffer, sizeof(Vector2), (int)((byte *)positions - data)),
                        new VertexBufferBinding(VertexBuffer, sizeof(ulong), (int)((byte *)uvws - data))
                    };

                    // Render
                    Bind();
                    Device.TextShader.Apply(Device.Context);
                    Device.Context.PixelShader.SetSampler(0, Device.SamplerDefault);
                    Device.Context.PixelShader.SetShaderResources(0, ((Dx11RenderingTextureAllocator)(textureAllocator)).TextureView);
                    Device.Context.InputAssembler.SetVertexBuffers(0, VertexBufferBindings);
                    Device.Context.OutputMerger.SetDepthStencilState(Device.DepthStencilNoZBuffer);

                    // Render
                    Device.Context.Draw(vertexCount, 0);

                    // Reset state
                    Device.Context.OutputMerger.SetDepthStencilState(Device.DepthStencilDefault);
                }
            }
        }
Beispiel #26
0
 public abstract unsafe void ProgramUniform2([Flow(FlowDirection.In)] uint program, [Flow(FlowDirection.In)] int location, [Flow(FlowDirection.In)] uint count, [Count(Parameter = "count"), Flow(FlowDirection.In)] ulong *value);
Beispiel #27
0
 public static bool mul_overflow(ulong value1, ulong value2, ulong *result)
 {
     throw new NotImplementedException(":("); // same here - _umul128
 }
 /// <summary>
 /// unsigned __int64 _mulx_u64 (unsigned __int64 a, unsigned __int64 b, unsigned __int64* hi)
 ///   MULX r64a, r64b, reg/m64
 /// The above native signature does not directly correspond to the managed signature.
 /// This intrinsic is only available on 64-bit processes
 /// </summary>
 public static unsafe ulong MultiplyNoFlags(ulong left, ulong right, ulong *low)
 {
     throw new PlatformNotSupportedException();
 }
 public int GetFrequency([NativeTypeName("UINT64 *")] ulong *pu64Frequency)
 {
     return(((delegate * stdcall <IAudioClock *, ulong *, int>)(lpVtbl[3]))((IAudioClock *)Unsafe.AsPointer(ref this), pu64Frequency));
 }
Beispiel #30
0
 public int GetBuffer([NativeTypeName("BYTE **")] byte **ppData, [NativeTypeName("UINT32 *")] uint *pNumFramesToRead, [NativeTypeName("DWORD *")] uint *pdwFlags, [NativeTypeName("UINT64 *")] ulong *pu64DevicePosition, [NativeTypeName("UINT64 *")] ulong *pu64QPCPosition)
 {
     return(((delegate * stdcall <IAudioCaptureClient *, byte **, uint *, uint *, ulong *, ulong *, int>)(lpVtbl[3]))((IAudioCaptureClient *)Unsafe.AsPointer(ref this), ppData, pNumFramesToRead, pdwFlags, pu64DevicePosition, pu64QPCPosition));
 }
 public int GetPosition([NativeTypeName("UINT64 *")] ulong *pu64Position, [NativeTypeName("UINT64 *")] ulong *pu64QPCPosition)
 {
     return(((delegate * stdcall <IAudioClock *, ulong *, ulong *, int>)(lpVtbl[4]))((IAudioClock *)Unsafe.AsPointer(ref this), pu64Position, pu64QPCPosition));
 }
 public void GetTags([NativeTypeName("D2D1_TAG *")] ulong *tag1 = null, [NativeTypeName("D2D1_TAG *")] ulong *tag2 = null)
 {
     ((delegate * stdcall <ID2D1DCRenderTarget *, ulong *, ulong *, void>)(lpVtbl[39]))((ID2D1DCRenderTarget *)Unsafe.AsPointer(ref this), tag1, tag2);
 }
Beispiel #33
0
 public HRESULT get_WindowSize([NativeTypeName("DWORDLONG *")] ulong *pWindowSize)
 {
     return(((delegate * unmanaged <IAMVideoCompression *, ulong *, int>)(lpVtbl[10]))((IAMVideoCompression *)Unsafe.AsPointer(ref this), pWindowSize));
 }
		/// <summary>
		/// Creates a new CudaRegisteredHostMemory_ulong from an existing IntPtr. IntPtr must be page size aligned (4KBytes)!
		/// </summary>
		/// <param name="hostPointer">must be page size aligned (4KBytes)</param>
		/// <param name="size">In elements</param>
		public CudaRegisteredHostMemory_ulong(IntPtr hostPointer, SizeT size)
		{
			_intPtr = hostPointer;
			_size = size;
			_typeSize = (SizeT)Marshal.SizeOf(typeof(ulong));
			_ptr = (ulong*)_intPtr;
		}
Beispiel #35
0
 private static extern bool WinUsb_GetDescriptor(IntPtr InterfaceHandle, byte DescriptorType, byte Index, ushort LanguageID, out byte *Buffer, ulong BufferLength, out ulong *LengthTransferred);
Beispiel #36
0
 public void ReleaseInternalBuffer()
 {
     if (m_ownedBuffer != null)
     {
         if (m_buffer == m_ownedBuffer)
         {
             m_buffer = null;
             m_bitLength = 0;
         }
         SharpDX.Utilities.FreeMemory((IntPtr)(void*)m_ownedBuffer);
         m_ownedBuffer = null;
         m_ownedBufferBitLength = 0;
     }
 }
Beispiel #37
0
 private static extern bool WinUsb_GetInterfacePowerPolicy(IntPtr InterfaceHandle, ulong PolicyType, out ulong *ValueLength, out void *Value); // raro
Beispiel #38
0
        /// <summary>
        /// Resets stream for reading.
        /// </summary>
        public void ResetRead(IntPtr buffer, int bitLength, bool copy)
        {
            if (copy)
            {
                int byteLen = MyLibraryUtils.GetDivisionCeil(bitLength, 8);
                int allocByteSize = Math.Max(byteLen, m_defaultByteSize);

                if (m_ownedBuffer == null)
                {
                    m_ownedBuffer = (ulong*)(void*)SharpDX.Utilities.AllocateClearedMemory(allocByteSize);
                    m_ownedBufferBitLength = allocByteSize * 8;
                }
                else if (m_ownedBufferBitLength < bitLength)
                {
                    SharpDX.Utilities.FreeMemory((IntPtr)(void*)m_ownedBuffer);
                    m_ownedBuffer = (ulong*)(void*)SharpDX.Utilities.AllocateClearedMemory(allocByteSize);
                    m_ownedBufferBitLength = allocByteSize * 8;
                }
                SharpDX.Utilities.CopyMemory((IntPtr)(void*)m_ownedBuffer, buffer, byteLen);

                m_buffer = m_ownedBuffer;
                m_bitLength = bitLength;
                m_bitPosition = 0;
                m_writing = false;
            }
            else
            {
                m_buffer = (ulong*)(void*)buffer;
                m_bitLength = bitLength;
                m_bitPosition = 0;
                m_writing = false;
            }
        }
Beispiel #39
0
 private static extern bool WinUsb_GetPipePolicy(IntPtr DeviceHandle, byte PipeID, ulong PolicyType, out ulong *ValueLength, out void *Value); // raroo
Beispiel #40
0
 public void ResetWrite(BitStream stream)
 {
     int bitLength = stream.m_writing ? stream.m_bitPosition : stream.BitLength;
     if (m_ownedBuffer != null && m_ownedBufferBitLength < bitLength)
     {
         SharpDX.Utilities.FreeMemory((IntPtr)(void*)m_ownedBuffer);
         m_ownedBuffer = null;
     }
     if (m_ownedBuffer == null)
     {
         int byteSize = Math.Max(MyLibraryUtils.GetDivisionCeil(bitLength, 64) * 8, m_defaultByteSize);
         m_ownedBuffer = (ulong*)(void*)SharpDX.Utilities.AllocateClearedMemory(byteSize);
         m_ownedBufferBitLength = byteSize * 8;
     }
     m_buffer = m_ownedBuffer;
     m_bitLength = m_ownedBufferBitLength;
     SharpDX.Utilities.CopyMemory(DataPointer, stream.DataPointer, MyLibraryUtils.GetDivisionCeil(bitLength, 8));
     m_bitPosition = bitLength;
     m_writing = true;
 }
 public HRESULT GetUINT64([NativeTypeName("const GUID &")] Guid *guidKey, [NativeTypeName("UINT64 *")] ulong *punValue)
 {
     return(((delegate * unmanaged <IMFSample *, Guid *, ulong *, int>)(lpVtbl[8]))((IMFSample *)Unsafe.AsPointer(ref this), guidKey, punValue));
 }
        private void Init(MemoryMappedFile file, long offsetBytes, long lengthBytes, MemoryMappedFileAccess access, int defaultSegmentWords, bool leaveOpen = false)
        {
            base.Init(defaultSegmentWords);

            MemoryMappedViewAccessor view = null;
            byte* ptr = (byte*)0;
            try
            {
                if(lengthBytes < 0) lengthBytes = 0;
                view = file.CreateViewAccessor(offsetBytes, lengthBytes, access);
                lengthBytes = view.Capacity;
                view.SafeMemoryMappedViewHandle.AcquirePointer(ref ptr);
                this.pointer = (ulong*)&ptr[offsetBytes];
                this.view = view;
                if (!leaveOpen) this.mmFile = file;
                view = null;
                this.totalWords = lengthBytes >> 3;
            }
            finally
            {
                if (view != null)
                {
                    if (ptr != (byte*)0) view.SafeMemoryMappedViewHandle.ReleasePointer();
                    view.Dispose();
                }

            }
        }
Beispiel #43
0
        public unsafe void Seek(long dlibMove, SeekOrigin dwOrigin, ulong *plibNewPosition)
        {
            long position = _virtualPosition;

            if (_virtualPosition == -1)
            {
                position = _dataStream.Position;
            }

            long length = _dataStream.Length;

            switch (dwOrigin)
            {
            case SeekOrigin.Begin:
                if (dlibMove <= length)
                {
                    _dataStream.Position = dlibMove;
                    _virtualPosition     = -1;
                }
                else
                {
                    _virtualPosition = dlibMove;
                }
                break;

            case SeekOrigin.End:
                if (dlibMove <= 0)
                {
                    _dataStream.Position = length + dlibMove;
                    _virtualPosition     = -1;
                }
                else
                {
                    _virtualPosition = length + dlibMove;
                }
                break;

            case SeekOrigin.Current:
                if (dlibMove + position <= length)
                {
                    _dataStream.Position = position + dlibMove;
                    _virtualPosition     = -1;
                }
                else
                {
                    _virtualPosition = dlibMove + position;
                }
                break;
            }

            if (plibNewPosition == null)
            {
                return;
            }

            if (_virtualPosition != -1)
            {
                *plibNewPosition = (ulong)_virtualPosition;
            }
            else
            {
                *plibNewPosition = (ulong)_dataStream.Position;
            }
        }
Beispiel #44
0
    /// <summary>
    /// erstellt einen neuen Hash-Eintrag (darf noch nicht vorhanden sein)
    /// </summary>
    /// <param name="code">Hash-Code, welcher eintragen werden soll</param>
    /// <param name="tiefe">entsprechende Zugtiefe</param>
    public void Add(ulong code, int tiefe)
    {
#if multiHash
      var hash = hashes[code & hashesBits];
#endif
      hash.Add(code, (ushort)tiefe);

      if (hash.Count > dictionaryLimit)
      {
#if Index0
        Array.Resize(ref weitere, weitere.Length + 1);
        for (int i = weitere.Length - 1; i > 0; i--) weitere[i] = weitere[i - 1];
        weitere[0] = hash;
        hash = new Dictionary<ulong, ushort>();
#endif

#if Index16
        if (archivAnzahl == 0)
        {
          #region # // --- Archiv das erste mal erstellen ---
          // --- Archiv vorbereiten ---
#if multiHash
          archivAnzahl = hashes.Sum(x => x.Count);
#else
          archivAnzahl = hash.Count;
#endif

          archivDataPointer = Marshal.AllocHGlobal((IntPtr)((long)archivAnzahl * 8L));
          if (archivDataPointer == IntPtr.Zero) throw new Exception("Speicher konnte nicht reserviert werden (" + (((long)archivAnzahl * 8L) / 1048576L) + " MB)");
          archivData = (ulong*)archivDataPointer.ToPointer();

          uint[] zähler = new uint[1 << 16];
#if multiHash
          foreach (var h in hashes)
          {
            h.Select(x => zähler[x.Key & 0xffff]++).Count();
          }
#else
          hash.Select(x => zähler[x.Key & 0xffff]++).Count();
#endif
          uint[] posis = new uint[1 << 16];
          uint pos = 0;
          for (int i = 1; i < (1 << 16); i++)
          {
            pos += zähler[i - 1];
            posis[i] = pos;
          }

          // --- Archiv befüllen ---
#if multiHash
          foreach (var h in hashes) foreach (var satz in h)
#else
          foreach (var satz in hash)
#endif
            {
              int indexPos = (int)(satz.Key & 0xffff);
              archivData[posis[indexPos]++] = (satz.Key & 0xffffffffffff0000) | (ulong)satz.Value;
            }

          // --- Positionen neu berechnen ---
          posis[0] = pos = 0;
          for (int i = 1; i < (1 << 16); i++)
          {
            pos += zähler[i - 1];
            posis[i] = pos;
          }

          // --- Archiv sortieren (Multi-Threaded) ---
          ParallelEnumerable.Range(0, 1 << 16).Select(i =>
          {
            Sort.Quick(&archivData[posis[i]], (int)zähler[i]);
            return i;
          }).Count();

          // --- 16 Bit-Index erstellen ---
          uint[] indexTemp = Enumerable.Range(0, (1 << 16) * 2).Select(i => (i & 1) == 0 ? zähler[i >> 1] : posis[i >> 1]).ToArray();

          for (int i = 0; i < indexTemp.Length; i++) archivIndex[i] = indexTemp[i];
          #endregion
        }
        else
        {
          #region # // --- Archiv erweitern ---
          // --- Neue Daten vorbereiten ---
          int dazuAnzahl = hash.Count;
          ulong[] dazuData = new ulong[dazuAnzahl];
          uint[] zähler = new uint[1 << 16];
          hash.Select(x => zähler[x.Key & 0xffff]++).Count();
          uint[] posis = new uint[1 << 16];
          uint pos = 0;
          for (int i = 1; i < (1 << 16); i++)
          {
            pos += zähler[i - 1];
            posis[i] = pos;
          }

          // --- Neue Daten befüllen ---
          foreach (var satz in hash)
          {
            int indexPos = (int)(satz.Key & 0xffff);
            dazuData[posis[indexPos]++] = (satz.Key & 0xffffffffffff0000) | (ulong)satz.Value;
          }

          // --- Positionen neu berechnen ---
          posis[0] = pos = 0;
          for (int i = 1; i < (1 << 16); i++)
          {
            pos += zähler[i - 1];
            posis[i] = pos;
          }

          // --- Neue Daten sortieren (Multi-Threaded) ---
          ParallelEnumerable.Range(0, (1 << 16)).Select(i =>
          {
            Array.Sort(dazuData, (int)posis[i], (int)zähler[i]);
            return i;
          }).Count();

          // --- Neues Array erstellen ---
          ulong* altData = archivData;
          IntPtr altPointer = archivDataPointer;
          archivDataPointer = Marshal.AllocHGlobal((IntPtr)((long)(archivAnzahl + dazuAnzahl) * 8L));
          if (archivDataPointer == IntPtr.Zero) throw new Exception("Speicher konnte nicht reserviert werden (" + (((long)(archivAnzahl + dazuAnzahl) * 8L) / 1048576L) + " MB)");
          archivData = (ulong*)archivDataPointer.ToPointer();

          // --- alte Archiv-Daten kopieren und zusammen mit den neuen Daten verschmelzen ---
          pos = 0;
          for (int index = 0; index < (1 << 16); index++)
          {
            uint posAlt = archivIndex[(index << 1) + 1];
            uint countAlt = archivIndex[index << 1];
            uint posNeu = posis[index];
            uint countNeu = zähler[index];
            uint dazu = 0;

            while (countAlt > 0 && countNeu > 0) // beide Tabellen verzahnen und ins neue Archiv speichern
            {
              if (altData[posAlt] < dazuData[posNeu])
              {
                archivData[pos] = altData[posAlt++];
                countAlt--;
              }
              else
              {
                archivData[pos] = dazuData[posNeu++];
                countNeu--;
              }
              pos++;
              dazu++;
            }
            while (countAlt > 0) // Reste der alten Tabelle übertragen
            {
              archivData[pos++] = altData[posAlt++];
              dazu++;
              countAlt--;
            }
            while (countNeu > 0) // Reste der neuen Tabelle übertragen
            {
              archivData[pos++] = dazuData[posNeu++];
              dazu++;
              countNeu--;
            }

            // Index anpassen
            archivIndex[index << 1] = dazu;
            archivIndex[(index << 1) + 1] = pos - dazu;
          }

          archivAnzahl = pos;

          Marshal.FreeHGlobal(altPointer);

          dazuData = null;
          #endregion
        }
#endif

#if Index24
        if (archivAnzahl == 0)
        {
        #region # // --- Archiv das erste mal erstellen ---
          // --- Archiv vorbereiten ---
#if multiHash
          archivAnzahl = hashes.Sum(x => (long)x.Count);
#else
          archivAnzahl = hash.Count;
#endif

          archivDataPointer = Marshal.AllocHGlobal((IntPtr)((long)archivAnzahl * 7L + 1L));
          if (archivDataPointer == IntPtr.Zero) throw new Exception("Speicher konnte nicht reserviert werden (" + (((long)archivAnzahl * 7L + 1L) / 1048576L) + " MB)");
          archivData = (long)archivDataPointer.ToPointer();
#if DEBUG
          byte* zerofill = (byte*)archivData;
          for (int i = 0; i < archivAnzahl * 7 + 1; i++) zerofill[i] = 0x00;
#endif

          uint[] zähler = new uint[1 << 24];
#if multiHash
          foreach (var h in hashes)
          {
            h.Select(x => zähler[x.Key & 0xffffff]++).Count();
          }
#else
          hash.Select(x => zähler[x.Key & 0xffffff]++).Count();
#endif
          uint[] posis = new uint[1 << 24];
          uint pos = 0;
          for (int i = 1; i < (1 << 24); i++)
          {
            pos += zähler[i - 1];
            posis[i] = pos;
          }

          // --- Archiv befüllen ---
#if multiHash
          foreach (var h in hashes) foreach (var satz in h)
#else
          foreach (var satz in hash)
#endif
            {
              int indexPos = (int)(satz.Key & 0xffffff);
              ulong* p = (ulong*)(archivData + (long)(posis[indexPos]++) * 7L);
              *p = (*p & 0xff00000000000000) | ((satz.Key >> 8) & 0x00ffffffffff0000) | (ulong)satz.Value;
            }

          // --- Positionen neu berechnen ---
          posis[0] = pos = 0;
          for (int i = 1; i < (1 << 24); i++)
          {
            pos += zähler[i - 1];
            posis[i] = pos;
          }

          // --- Archiv sortieren (Multi-Threaded) ---
          ParallelEnumerable.Range(0, 1 << 24).Select(i =>
          {
            ulong[] tmp = new ulong[zähler[i]];
            long offset = (long)posis[i] * 7L + archivData;
            for (int x = 0; x < tmp.Length; x++)
            {
              tmp[x] = *(ulong*)(offset + (long)(x * 7)) & 0x00ffffffffffffff;
            }

            Sort.Quick(tmp);

            for (int x = 0; x < tmp.Length; x++)
            {
              ulong w = *(ulong*)(offset + (long)(x * 7)) & 0xff00000000000000;
              *(ulong*)(offset + (long)(x * 7)) = w | tmp[x];
            }
            return i;
          }).Count();

          // --- 24 Bit-Index erstellen ---
          uint[] indexTemp = Enumerable.Range(0, (1 << 24) * 2).Select(i => (i & 1) == 0 ? zähler[i >> 1] : posis[i >> 1]).ToArray();

          for (int i = 0; i < indexTemp.Length; i++) archivIndex[i] = indexTemp[i];
          #endregion
        }
        else
        {
        #region # // --- Archiv erweitern ---
          // --- Neue Daten vorbereiten ---
          int dazuAnzahl = hash.Count;
          ulong[] dazuData = new ulong[dazuAnzahl];
          uint[] zähler = new uint[1 << 24];
          hash.Select(x => zähler[x.Key & 0xffffff]++).Count();
          uint[] posis = new uint[1 << 24];
          uint pos = 0;
          for (int i = 1; i < (1 << 24); i++)
          {
            pos += zähler[i - 1];
            posis[i] = pos;
          }

          // --- Neue Daten befüllen ---
          foreach (var satz in hash)
          {
            int indexPos = (int)(satz.Key & 0xffffff);
            dazuData[posis[indexPos]++] = ((satz.Key >> 8) & 0x00ffffffffff0000) | (ulong)satz.Value;
          }

          // --- Positionen neu berechnen ---
          posis[0] = pos = 0;
          for (int i = 1; i < (1 << 24); i++)
          {
            pos += zähler[i - 1];
            posis[i] = pos;
          }

          // --- Neue Daten sortieren (Multi-Threaded) ---
          ParallelEnumerable.Range(0, (1 << 24)).Select(i =>
          {
            Array.Sort(dazuData, (int)posis[i], (int)zähler[i]);
            return i;
          }).Count();

          // --- Neues Array erstellen ---
          long altData = archivData;
          IntPtr altPointer = archivDataPointer;
          archivDataPointer = Marshal.AllocHGlobal((IntPtr)((long)(archivAnzahl + dazuAnzahl) * 7L + 1L));
          if (archivDataPointer == IntPtr.Zero) throw new Exception("Speicher konnte nicht reserviert werden (" + (((long)(archivAnzahl + dazuAnzahl) * 7L + 1L) / 1048576L) + " MB)");
          archivData = (long)archivDataPointer.ToPointer();

          // --- alte Archiv-Daten kopieren und zusammen mit den neuen Daten verschmelzen ---
          pos = 0;
          for (int index = 0; index < (1 << 24); index++)
          {
            uint posAlt = archivIndex[(index << 1) + 1];
            uint countAlt = archivIndex[index << 1];
            uint posNeu = posis[index];
            uint countNeu = zähler[index];
            uint dazu = 0;

            while (countAlt > 0 && countNeu > 0) // beide Tabellen verzahnen und ins neue Archiv speichern
            {
              if (((*(ulong*)(altData + (long)posAlt * 7L)) & 0x00ffffffffffffff) < dazuData[posNeu])
              {
                *(ulong*)(archivData + (long)pos * 7L) = ((*(ulong*)(archivData + (long)pos * 7L)) & 0xff00000000000000) | ((*(ulong*)(altData + (long)posAlt * 7L)) & 0x00ffffffffffffff);
                posAlt++;
                countAlt--;
              }
              else
              {
                *(ulong*)(archivData + (long)pos * 7L) = ((*(ulong*)(archivData + (long)pos * 7L)) & 0xff00000000000000) | dazuData[posNeu++];
                countNeu--;
              }
              pos++;
              dazu++;
            }
            while (countAlt > 0) // Reste der alten Tabelle übertragen
            {
              *(ulong*)(archivData + (long)pos * 7L) = ((*(ulong*)(archivData + (long)pos * 7L)) & 0xff00000000000000) | ((*(ulong*)(altData + (long)posAlt * 7L)) & 0x00ffffffffffffff);
              pos++;
              posAlt++;
              dazu++;
              countAlt--;
            }
            while (countNeu > 0) // Reste der neuen Tabelle übertragen
            {
              *(ulong*)(archivData + (long)pos * 7L) = ((*(ulong*)(archivData + (long)pos * 7L)) & 0xff00000000000000) | dazuData[posNeu++];
              pos++;
              dazu++;
              countNeu--;
            }

            // Index anpassen
            archivIndex[index << 1] = dazu;
            archivIndex[(index << 1) + 1] = pos - dazu;
          }

          archivAnzahl = pos;

          Marshal.FreeHGlobal(altPointer);

          dazuData = null;
          #endregion
        }
#endif

#if (Index16 || Index24)
#if multiHash
        for (int i = 0; i < hashes.Length; i++)
        {
          hashes[i] = null; // Hash aufräumen
        }
        hashes = new[] { new Dictionary<ulong, ushort>() };
        hashesBits = 0;
#else
        hash = new Dictionary<ulong, ushort>(); // Hash aufräumen
#endif

        GC.Collect();
#endif
      }
    }
 public void Reset(IntPtr data, int bitLength)
 {
     m_buffer = (ulong*)(void*)data;
     m_bitLength = bitLength;
     BitPosition = 0;
 }